Ejemplo n.º 1
0
    def move_random(self, start_position, radius, speed=config.Unit.Defaults.walk_speed):
        random_point = start_position.get_random_point_in_radius(radius, map_id=self.unit.map_)
        # TODO: Below check might not be needed once better path finding is implemented
        # Don't move if we were unable to calculate new Z by using map files.
        if random_point.z_locked:
            return

        # Don't move if the destination is not an active cell.
        new_cell_coords = GridManager.get_cell_key(random_point.x, random_point.y, self.unit.map_)
        if self.unit.current_cell != new_cell_coords and not \
                MapManager.get_grid_manager_by_map_id(self.unit.map_).is_active_cell(new_cell_coords):
            return

        self.send_move_normal([random_point], speed, SplineFlags.SPLINEFLAG_RUNMODE)
Ejemplo n.º 2
0
    def move_random(self,
                    start_position,
                    radius,
                    speed=config.Unit.Defaults.walk_speed):
        random_point = start_position.get_random_point_in_radius(
            radius, map_id=self.unit.map_)
        # TODO: Below check might not be needed once better path finding is implemented
        # Don't move if the new Z is very different to original Z.
        if math.fabs(start_position.z - random_point.z) > 1.5:
            return

        # Don't move if the destination is not an active cell.
        new_cell_coords = GridManager.get_cell_key(random_point.x,
                                                   random_point.y,
                                                   self.unit.map_)
        if self.unit.current_cell != new_cell_coords and not \
                MapManager.get_grid_manager_by_map_id(self.unit.map_).is_active_cell(new_cell_coords):
            return

        self.send_move_normal([random_point], speed,
                              SplineFlags.SPLINEFLAG_RUNMODE)