def move_by(self, delta_x, delta_y): # guard against anyone but the main program or _move_to calling me callername.caller_name_match(r"__main__|\._move_to$", abort = True, debug = agentsim.debug.get(256)) if self._move_limit is not None: delta_d = (delta_x * delta_x + delta_y * delta_y) ** 0.5 if delta_d > self._move_limit: delta_x = delta_x * self._move_limit / delta_d delta_y = delta_y * self._move_limit / delta_d # Don't allow you to move onto another person. This means that if # you are already on a person, you have to jump off by making a big # move. no_collision = True; # only collide with someone present for p in Person.get_all_present_instances(): # would we collide with p? if self.is_near_after_move(p, delta_x, delta_y): if agentsim.debug.get(16): print("MoveEnhanced.move_by", self.get_name(), "would collide with", p.get_name(), delta_x, delta_y) no_collision = False break # make the move if no collision if no_collision: if agentsim.debug.get(16): print("MoveEnhanced.move_by", self.get_name(), "moving by", delta_x, delta_y) super(MoveEnhanced, self).move_by(delta_x, delta_y)
def set_size(self, size): # only let callers of the same type as me set my size my_name = callername.caller_name(level = 0) # get back module.class.method, match just the invoking class my_name_parts = my_name.split(".") my_class = my_name_parts[1] pattern = r"\." + my_class + r"\." callername.caller_name_match(pattern, abort = True, debug = agentsim.debug.get(256)) # ok, we can our size, but not too big super(MoveEnhanced, self).set_size(min(size, self.get_max_size())) # when you set your size, also change the move limit # nominal move limit is 10, range it from 5 to 15 min_size = self.get_min_size() adjust = 10 * ( (self.get_size() - min_size) / (self.get_max_size() - min_size) ) if my_class == "Normal": # normals are slow when small, fast when big self._move_limit = 5 + adjust elif my_class == "Zombie": # normals are fast when small, slow when big self._move_limit = 15 - adjust
def _move_to(self, x, y): # guard against anyone but the main program or teleport calling me callername.caller_name_match( "__main__|^moveenhanced.Defender.teleport$", abort = True, debug = agentsim.debug.get(256)) old_move_limit = self._move_limit self._move_limit = None self.move_by(x - self.get_xpos(), y - self.get_ypos()) self._move_limit = old_move_limit
def B(): callername.caller_name_match(".", abort=abf, debug=dbf) A()
def A(): callername.caller_name_match("^t2m.fn$|^__main__\.B$", abort=abf, debug=dbf)