def doFires(fires): if len(fires) == 0: return (None, None) suitFiresDict = { } for fire in fires: suitId = fire['target']['suit'].doId if suitFiresDict.has_key(suitId): suitFiresDict[suitId].append(fire) continue suitFiresDict[suitId] = [ fire] suitFires = suitFiresDict.values() def compFunc(a, b): if len(a) > len(b): return 1 elif len(a) < len(b): return -1 return 0 suitFires.sort(compFunc) totalHitDict = { } singleHitDict = { } groupHitDict = { } for fire in fires: suitId = fire['target']['suit'].doId if fire['target']['hp'] > 0: addHit(singleHitDict, suitId, 1) addHit(totalHitDict, suitId, 1) else: addHit(singleHitDict, suitId, 0) addHit(totalHitDict, suitId, 0) fire['target']['hp'] > 0 notify.debug('singleHitDict = %s' % singleHitDict) notify.debug('groupHitDict = %s' % groupHitDict) notify.debug('totalHitDict = %s' % totalHitDict) delay = 0.0 mtrack = Parallel() firedTargets = [] for sf in suitFires: if len(sf) > 0: ival = __doSuitFires(sf) if ival: mtrack.append(Sequence(Wait(delay), ival)) delay = delay + TOON_FIRE_SUIT_DELAY continue retTrack = Sequence() retTrack.append(mtrack) camDuration = retTrack.getDuration() camTrack = MovieCamera.chooseFireShot(fires, suitFiresDict, camDuration) return (retTrack, camTrack)
def doFires(fires): """ Throws occur in the following order: a) by suit, in order of increasing number of throws per suit 1) level 1 throws, right to left, (TOON_THROW_DELAY later) 2) level 2 throws, right to left, (TOON_THROW_DELAY later) 3) level 3 throws, right to left, (TOON_THROW_DELAY later) etc. b) next suit, (TOON_THROW_SUIT_DELAY later) """ #import pdb; pdb.set_trace() if (len(fires) == 0): return (None, None) # Group the throws by targeted suit suitFiresDict = {} # throw['toon'] is the thrower. for fire in fires: suitId = fire['target']['suit'].doId if (suitFiresDict.has_key(suitId)): suitFiresDict[suitId].append(fire) else: suitFiresDict[suitId] = [fire] # A list of lists of throws grouped by suit suitFires = suitFiresDict.values() # Sort the suits based on the number of throws per suit def compFunc(a, b): if (len(a) > len(b)): return 1 elif (len(a) < len(b)): return -1 return 0 suitFires.sort(compFunc) #since we have group throws now, we calculate how #many times each suit gets hit over here totalHitDict = {} singleHitDict = {} groupHitDict = {} for fire in fires: if 1: suitId = fire['target']['suit'].doId if fire['target']['hp'] > 0: addHit(singleHitDict,suitId,1) addHit(totalHitDict,suitId,1) else: addHit(singleHitDict,suitId,0) addHit(totalHitDict,suitId,0) notify.debug('singleHitDict = %s' % singleHitDict) notify.debug('groupHitDict = %s' % groupHitDict) notify.debug('totalHitDict = %s' % totalHitDict) # Apply attacks in order delay = 0.0 mtrack = Parallel() firedTargets = [] for sf in suitFires: if (len(sf) > 0): ival = __doSuitFires(sf) if (ival): mtrack.append(Sequence(Wait(delay), ival)) delay = delay + TOON_FIRE_SUIT_DELAY retTrack = Sequence() retTrack.append(mtrack) camDuration = retTrack.getDuration() camTrack = MovieCamera.chooseFireShot(fires, suitFiresDict, camDuration) return (retTrack, camTrack)