def execute(self): # check if the target has disappeared self.update_target() if self.target is None: self.mark_as_impossible() return # ignore silently if it is not necessary if getattr(self, "%s_is_not_necessary" % self.type.effect[0])(): self.mark_as_complete() # ignore silently (to save mana when giving the same order to many casters) return # move closer eventually if square_of_distance(self.target.x, self.target.y, self.unit.x, self.unit.y) > self.type.effect_range * self.type.effect_range: self.move_to_or_fail(self.target) return # the target is close enough, but is the target real? if self.type.effect[0] == "conversion" and self.target.is_memory: self.mark_as_impossible() return # check cost if self.unit.mana < self.type.mana_cost: self.mark_as_impossible("not_enough_mana") return # execute order getattr(self, "execute_%s" % self.type.effect[0])() self.unit.mana -= self.type.mana_cost self.unit.notify("use_complete,%s" % self.type.type_name, universal=self.type.universal_notification) self.mark_as_complete()
def execute(self): self.update_target() if self.target is None: # target has disappeared self.mark_as_impossible() return if getattr(self, "%s_is_not_necessary" % self.type.effect[0])(): # ignore silently (to save mana when giving the same order to many casters) self.mark_as_complete() return if ( square_of_distance(self.target.x, self.target.y, self.unit.x, self.unit.y) > self.type.effect_range * self.type.effect_range ): self.move_to_or_fail(self.target) # move closer return self.unit.stop() if self.type.effect[0] == "conversion" and self.target.is_memory: self.mark_as_impossible() return if self.unit.mana < self.type.mana_cost: self.mark_as_impossible("not_enough_mana") return getattr(self, "execute_%s" % self.type.effect[0])() self.unit.mana -= self.type.mana_cost self.unit.notify( "use_complete,%s" % self.type.type_name, universal=self.type.universal_notification, ) self.mark_as_complete()
def execute(self): # check if the target has disappeared self.update_target() if self.target is None: self.mark_as_impossible() return # ignore silently if it is not necessary if getattr(self, "%s_is_not_necessary" % self.type.effect[0])(): self.mark_as_complete( ) # ignore silently (to save mana when giving the same order to many casters) return # move closer eventually if square_of_distance( self.target.x, self.target.y, self.unit.x, self.unit.y) > self.type.effect_range * self.type.effect_range: self.move_to_or_fail(self.target) return # the target is close enough, but is the target real? if self.type.effect[0] == "conversion" and self.target.is_memory: self.mark_as_impossible() return # check cost if self.unit.mana < self.type.mana_cost: self.mark_as_impossible("not_enough_mana") return # execute order getattr(self, "execute_%s" % self.type.effect[0])() self.unit.mana -= self.type.mana_cost self.unit.notify("use_complete,%s" % self.type.type_name, universal=self.type.universal_notification) self.mark_as_complete()
def get_objects(self, x, y, radius, filter=lambda x: True): radius_2 = radius * radius return [ o for z in self.squares for o in z.objects if filter(o) and square_of_distance(x, y, o.x, o.y) <= radius_2 ]
def get_objects2(self, x, y, radius, filter=lambda x: True, players=None): if not players: players = self.players radius_2 = radius * radius return [ o for p in players for o in p._potential_neighbors(x, y) if filter(o) and square_of_distance(x, y, o.x, o.y) <= radius_2 ]
def execute_raise_dead(self): corpses = sorted(self.raise_dead_targets(), key=lambda o: square_of_distance(self.target.x, self.target.y, o.x, o.y)) self.unit.player.lang_add_units( self.type.effect[2:], decay=to_int(self.type.effect[1]), from_corpse=True, corpses=corpses, notify=False)
def execute_raise_dead(self): corpses = sorted(self.raise_dead_targets(), key=lambda o: square_of_distance( self.target.x, self.target.y, o.x, o.y)) self.unit.player.lang_add_units(self.type.effect[2:], decay=to_int(self.type.effect[1]), from_corpse=True, corpses=corpses, notify=False)
def _update_cloaking(self): for p in self.players: for u in p.units: if u.is_cloakable: u.is_cloaked = False for p in self.players: for u in p.units: if u.is_a_cloaker: radius2 = u.cloaking_range * u.cloaking_range for vp in p.allied: for vu in vp._potential_neighbors(u.x, u.y): if not vu.is_cloakable or vu.is_cloaked: continue if square_of_distance(vu.x, vu.y, u.x, u.y) < radius2: vu.is_cloaked = True continue
def _update_detection(self): for p in self.players: p.detected_units = set() for p in self.players: for u in p.units: if u.is_a_detector: radius2 = u.detection_range * u.detection_range for e in self.players: if e in p.allied: continue for iu in e._potential_neighbors(u.x, u.y): if not (iu.is_invisible or iu.is_cloaked): continue if iu in p.detected_units: continue if square_of_distance(iu.x, iu.y, u.x, u.y) < radius2: for a in p.allied_vision: a.detected_units.add(iu) continue
def execute_resurrection(self): corpses = sorted(self.resurrection_targets(), key=lambda o: square_of_distance(self.target.x, self.target.y, o.x, o.y)) for _ in range(int(self.type.effect[1])): if corpses: c = corpses.pop(0) u = c.unit if not self.player.check_count_limit(u.type_name): continue u.player = None u.place = None u.id = None # so the unit will be added to world.active_objects u.hp = u.hp_max / 3 u.set_player(self.unit.player) u.move_to(c.place, c.x, c.y) if u.decay: u.time_limit = u.world.time + u.decay c.delete() else: break
def execute_resurrection(self): corpses = sorted(self.resurrection_targets(), key=lambda o: square_of_distance( self.target.x, self.target.y, o.x, o.y)) for _ in range(int(self.type.effect[1])): if corpses: c = corpses.pop(0) u = c.unit if not self.player.check_count_limit(u.type_name): continue u.player = None u.place = None u.id = None # so the unit will be added to world.active_objects u.hp = u.hp_max / 3 u.set_player(self.unit.player) u.move_to(c.place, c.x, c.y) if u.decay: u.time_limit = u.world.time + u.decay c.delete() else: break
def get_objects2(self, x, y, radius, filter=lambda x: True, players=None): if not players: players = self.players radius_2 = radius * radius return [o for p in players for o in p._potential_neighbors(x, y) if filter(o) and square_of_distance(x, y, o.x, o.y) <= radius_2]
def get_objects(self, x, y, radius, filter=lambda x: True): radius_2 = radius * radius return [o for z in self.squares for o in z.objects if filter(o) and square_of_distance(x, y, o.x, o.y) <= radius_2]
def nearest_exit(u): result = sorted( u.place.exits, key=lambda e: square_of_distance(u.x, u.y, e.x, e.y)) if result: return result[0]