示例#1
0
 def _near_enough_to_use(self, target):
     if self.is_an_enemy(target):
         if self.range and target.place is self.place:
             d = target.use_range(self)
             return square_of_distance(self.x, self.y, target.x, target.y) < d * d
         elif self.is_ballistic or self.special_range:
             return self.can_attack(target)
     elif target.place is self.place:
         d = target.use_range(self)
         return square_of_distance(self.x, self.y, target.x, target.y) < d * d
示例#2
0
 def flee(self, someone=None):
     self.notify("flee")
     self.player.on_unit_flee(self)
     self.orders = []
     if someone is None:
         exits = [[(square_of_distance(e.x, e.y, self.x, self.y), e.id), e] for e in self.place.exits]
     else:
         exits = [[(self.door_menace(e), - square_of_distance(e.x, e.y, someone.x, someone.y), e.id), e] for e in self.place.exits]
     exits.sort()
     if len(exits) > 0:
         self.action_target = exits[0][1]
     self.is_fleeing = True
示例#3
0
 def _near_enough_to_use(self, target):
     if self.is_an_enemy(target):
         # Melee units (range <= 2) shouldn't attack units
         # on the other side of a wall.
         if not self._can_go(target.x, target.y) \
             and self.range <= 2 * PRECISION \
             and not target.blocked_exit:
                 return False
         if self.minimal_range and square_of_distance(self.x, self.y, target.x, target.y) < self.minimal_range * self.minimal_range:
             return False
         d = target.use_range(self)
         return square_of_distance(self.x, self.y, target.x, target.y) < d * d
     elif target.place is self.place:
         d = target.use_range(self)
         return square_of_distance(self.x, self.y, target.x, target.y) < d * d
 def object_from_mousepos(self, pos):
     self._update_coefs()
     x, y = pos
     for o in self.interface.dobjets.values():
         xo, yo = self.object_coords(o)
         if square_of_distance(x, y, xo, yo) <= R2 + 1: # XXX + 1 ?
             return o
示例#5
0
 def _already_walked(self, x, y):
     n = 0
     radius_2 = self.radius * self.radius
     for lw, xw, yw, weight in self.walked:
         if self.place is lw and square_of_distance(x, y, xw, yw) < radius_2:
             n += weight
     return n
 def object_from_mousepos(self, pos):
     self._update_coefs()
     x, y = pos
     for o in self.interface.dobjets.values():
         xo, yo = self.object_coords(o)
         if square_of_distance(x, y, xo, yo) <= R2 + 1:  # XXX + 1 ?
             return o
示例#7
0
 def _choose_enemy(self, place):
     known = self.player.known_enemies(place)
     reachable_enemies = [x for x in known if self.can_attack(x)]
     if reachable_enemies:
         reachable_enemies.sort(key=lambda x: (- x.value, square_of_distance(self.x, self.y, x.x, x.y), x.id))
         self.action_target = reachable_enemies[0] # attack nearest
         self.notify("attack") # XXX move this into set_action_target()?
         return True
示例#8
0
 def _already_walked(self, x, y):
     n = 0
     radius_2 = self.radius * self.radius
     for lw, xw, yw, weight in self.walked:
         if self.place is lw and square_of_distance(x, y, xw,
                                                    yw) < radius_2:
             n += weight
     return n
示例#9
0
 def splash_aim(self, target):
     damage_radius_2 = self.damage_radius * self.damage_radius
     for o in target.place.objects[:]:
         if not self.is_an_enemy(o):
             pass  # no friendly fire
         elif isinstance(o, Creature) \
            and square_of_distance(o.x, o.y, target.x, target.y) <= damage_radius_2 \
            and self.can_attack_if_in_range(o):
             self.hit(o)
示例#10
0
 def splash_aim(self, target):
     damage_radius_2 = self.damage_radius * self.damage_radius
     for o in target.place.objects[:]:
         if not self.is_an_enemy(o):
             pass  # no friendly fire
         elif isinstance(o, Creature) \
            and square_of_distance(o.x, o.y, target.x, target.y) <= damage_radius_2 \
            and self.can_attack_if_in_range(o):
             self.hit(o)
示例#11
0
 def _choose_enemy(self, place):
     known = self.player.known_enemies(place)
     reachable_enemies = [x for x in known if self.can_attack(x)]
     if reachable_enemies:
         reachable_enemies.sort(key=lambda x: (
             -x.value, square_of_distance(self.x, self.y, x.x, x.y), x.id))
         self.action_target = reachable_enemies[0]  # attack nearest
         self.notify("attack")  # XXX move this into set_action_target()?
         return True
示例#12
0
 def _near_enough_to_use(self, target):
     if self.is_an_enemy(target):
         # Melee units (range <= 2) shouldn't attack units
         # on the other side of a wall.
         if not self._can_go(target.x, target.y) \
             and self.range <= 2 * PRECISION \
             and not target.blocked_exit:
             return False
         if self.minimal_range and square_of_distance(
                 self.x, self.y, target.x,
                 target.y) < self.minimal_range * self.minimal_range:
             return False
         d = target.use_range(self)
         return square_of_distance(self.x, self.y, target.x,
                                   target.y) < d * d
     elif target.place is self.place:
         d = target.use_range(self)
         return square_of_distance(self.x, self.y, target.x,
                                   target.y) < d * d