def doThrows(throws): if len(throws) == 0: return (None, None) suitThrowsDict = {} for throw in throws: suitId = throw['target']['suit'].doId if suitThrowsDict.has_key(suitId): suitThrowsDict[suitId].append(throw) else: suitThrowsDict[suitId] = [ throw] suitThrows = suitThrowsDict.values() def compFunc(a, b): if len(a) > len(b): return 1 else: if len(a) < len(b): return -1 return 0 suitThrows.sort(compFunc) delay = 0.0 tracks = [] for st in suitThrows: if len(st) > 0: ival = __doSuitThrows(st) if ival: tracks.append(Track([(delay, ival)])) delay = delay + TOON_THROW_SUIT_DELAY mtrack = MultiTrack(tracks) camDuration = mtrack.getDuration() camTrack = MovieCamera.chooseThrowShot(throws, suitThrowsDict, camDuration) return ( mtrack, camTrack) return
def doThrows(throws): if len(throws) == 0: return None, None suitThrowsDict = {} for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): pass else: suitId = throw['target']['suit'].doId if suitId in suitThrowsDict: suitThrowsDict[suitId].append(throw) else: suitThrowsDict[suitId] = [throw] suitThrows = suitThrowsDict.values() def compFunc(a, b): if len(a) > len(b): return 1 elif len(a) < len(b): return -1 return 0 suitThrows.sort(compFunc) totalHitDict = {} singleHitDict = {} groupHitDict = {} for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): for i in range(len(throw['target'])): target = throw['target'][i] suitId = target['suit'].doId if target['hp'] > 0: addHit(groupHitDict, suitId, 1) addHit(totalHitDict, suitId, 1) else: addHit(groupHitDict, suitId, 0) addHit(totalHitDict, suitId, 0) else: suitId = throw['target']['suit'].doId if throw['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) delay = 0.0 mtrack = Parallel() for st in suitThrows: if len(st) > 0: ival = __doSuitThrows(st) if ival: mtrack.append(Sequence(Wait(delay), ival)) delay = delay + TOON_THROW_SUIT_DELAY retTrack = Sequence() retTrack.append(mtrack) groupThrowIvals = Parallel() groupThrows = [] for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): groupThrows.append(throw) for throw in groupThrows: tracks = None tracks = __throwGroupPie(throw, 0, groupHitDict) if tracks: for track in tracks: groupThrowIvals.append(track) retTrack.append(groupThrowIvals) camDuration = retTrack.getDuration() camTrack = MovieCamera.chooseThrowShot(throws, suitThrowsDict, camDuration) return retTrack, camTrack
def doThrows(throws): if len(throws) == 0: return (None, None) suitThrowsDict = {} for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): pass else: suitId = throw['target']['suit'].doId if suitId in suitThrowsDict: suitThrowsDict[suitId].append(throw) else: suitThrowsDict[suitId] = [throw] suitThrows = suitThrowsDict.values() def compFunc(a, b): if len(a) > len(b): return 1 elif len(a) < len(b): return -1 return 0 suitThrows.sort(compFunc) totalHitDict = {} singleHitDict = {} groupHitDict = {} for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): for i in xrange(len(throw['target'])): target = throw['target'][i] suitId = target['suit'].doId if target['hp'] > 0: addHit(groupHitDict, suitId, 1) addHit(totalHitDict, suitId, 1) else: addHit(groupHitDict, suitId, 0) addHit(totalHitDict, suitId, 0) else: suitId = throw['target']['suit'].doId if throw['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) delay = 0.0 mtrack = Parallel() for st in suitThrows: if len(st) > 0: ival = __doSuitThrows(st) if ival: mtrack.append(Sequence(Wait(delay), ival)) delay = delay + TOON_THROW_SUIT_DELAY retTrack = Sequence() retTrack.append(mtrack) groupThrowIvals = Parallel() groupThrows = [] for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): groupThrows.append(throw) for throw in groupThrows: tracks = None tracks = __throwGroupPie(throw, 0, groupHitDict) if tracks: for track in tracks: groupThrowIvals.append(track) retTrack.append(groupThrowIvals) camDuration = retTrack.getDuration() camTrack = MovieCamera.chooseThrowShot(throws, suitThrowsDict, camDuration) return (retTrack, camTrack)
def doThrows(throws): """ 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(throws) == 0): return (None, None) # Group the throws by targeted suit suitThrowsDict = {} # throw['toon'] is the thrower. for throw in throws: # TODO: Count suits, and if there is only one, save that variable. if attackAffectsGroup(throw['track'], throw['level']): #hmmm lets try throwing at all of them #for target in throw['target']: # suitId = targett['suit'].doId # if (suitThrowsDict.has_key(suitId)): # suitThrowsDict[suitId].append(throw) # else: # suitThrowsDict[suitId] = [throw] pass else: suitId = throw['target']['suit'].doId if (suitThrowsDict.has_key(suitId)): suitThrowsDict[suitId].append(throw) else: suitThrowsDict[suitId] = [throw] # A list of lists of throws grouped by suit suitThrows = suitThrowsDict.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 suitThrows.sort(compFunc) #since we have group throws now, we calculate how #many times each suit gets hit over here totalHitDict = {} singleHitDict = {} groupHitDict = {} for throw in throws: if attackAffectsGroup(throw['track'], throw['level']): for i in range(len(throw['target'])): target = throw['target'][i] suitId = target['suit'].doId if target['hp'] > 0: addHit(groupHitDict, suitId, 1) addHit(totalHitDict, suitId, 1) else: addHit(groupHitDict, suitId, 0) addHit(totalHitDict, suitId, 0) else: suitId = throw['target']['suit'].doId if throw['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() for st in suitThrows: if (len(st) > 0): ival = __doSuitThrows(st) if (ival): mtrack.append(Sequence(Wait(delay), ival)) delay = delay + TOON_THROW_SUIT_DELAY retTrack = Sequence() retTrack.append(mtrack) #we've done the single target throws, handle the group throws groupThrowIvals = Parallel() groupThrows = [] for throw in throws: # TODO: Count suits, and if there is only one, save that variable. if attackAffectsGroup(throw['track'], throw['level']): groupThrows.append(throw) for throw in groupThrows: tracks = None tracks = __throwGroupPie(throw, 0, groupHitDict) if (tracks): #groupThrowIvals.append(Sequence(Wait(delay), ival)) for track in tracks: groupThrowIvals.append(track) #delay = delay + TOON_THROW_SUIT_DELAY retTrack.append(groupThrowIvals) camDuration = retTrack.getDuration() camTrack = MovieCamera.chooseThrowShot(throws, suitThrowsDict, camDuration) return (retTrack, camTrack)