def heal(self, source, amount): #source, amount = self.run_hook('pre-heal', source, amount) if source and amount: for x in self.units: if friendly(self, x): x.heal(source, amount) # self.run_hook('post-heal', source, amount) return source, amount
def move_creatures(player, creatures, building): """ Move all of @creatures to @building.""" if any(getattr(c, 'owner', None) != player): raise IllegalMovement("Player does control all creatues") is_attack = not friendly(building, creatures[0]) # To move to a opposing building a free pad is required if is_attack and not len(building.free_pads()) > 0: raise IllegalMovement("No free pads") # Should the entire movement be aborted if one creature fails its pre-move check? creatures = [x for x in creatures if x.run_hook('pre-move', building)[0]] creatures = filter(None, map(lambda x: x.position.remove_creature(x), creatures)) creatures = filter(None, map(lambda x: building.add_creature(x), creatures)) for x in creatures: x.position = building
def is_battle_zone(self): return any(not friendly(self, x) for x in self.units)
def get_attackers(self): attackers = [x for x in self.units if not friendly(self, x)] (attackers,) = self.run_hook('pre-attackers', attackers) self.run_hook('post-attackers', attackers) return attackers
def get_defenders(self): # Maybe allow some teleport dude to defend at all buildings.. defenders = [x for x in self.units if friendly(self, x)] (defenders,) = self.run_hook('pre-defenders', defenders) self.run_hook('post-defenders', defenders) return defenders