示例#1
0
    def _tick(self):
        if self.cancelled:
            self.status = Status.failure
            return
        if not self.player in self.world.entities.players:
            return
        eid = self.world.entities.players[self.player]
        entity = self.world.entities.get_entity(eid)
        bot_object = self.world.bot.bot_object
        bb = AABB.from_player_coords(entity.position)
        block = self.world.grid.standing_on_block(bb)
        if block is None:
            block = self.world.grid.actual_block(bb)
#        #block = self.world.grid.downward_block(bb)
        distance = bot_object.position.distance(entity.position)
        delay = distance * self.recalc_multiplier
        #don't auto-recalculate more than once a second.
        delay = delay if delay > 1 else 1
        if (self.last_block != block
#          or distance > config.PATHFIND_MAX * 0.5  #actual path may be crooked
          or time() - self.last_attempt > delay):
          #or self.last_position != self.bot.bot_object.position_grid):
            log.msg('recalculating move..')
            # Cancel any other running behaviours we're doing
            self.manager.cancel_running(priority=self.priority - 1)
            self.last_position = self.bot.bot_object.position_grid
            self.last_attempt = time()
            self.last_block = block
            self.add_subbehaviour(TravelToBehaviour, coords=block.coords,
                                  shorten_path_by=2, estimate=True)
示例#2
0
 def _tick(self):
     if not self.world.commander.in_game:
         return
     entity = self.world.entities.get_entity(self.world.commander.eid)
     block = self.world.grid.standing_on_block(AABB.from_player_coords(entity.position))
     if block is None:
         return
     if self.last_block != block or self.last_position != self.bot.bot_object.position_grid:
         self.last_position = self.bot.bot_object.position_grid
         self.last_block = block
         self.add_subbehaviour(TravelToBehaviour, coords=block.coords, shorten_path_by=2)
示例#3
0
 def maybe_commander(self, entity):
     if self.world.commander.eid != entity.eid:
         return
     gpos = entity.grid_position
     block = self.dimension.grid.standing_on_block(AABB.from_player_coords(entity.position))
     if block is None:
         return
     if self.world.commander.last_block is not None and self.world.commander.last_block == block:
         return
     self.world.commander.last_block = block
     #TODO put some nice debug code here
     self.world.commander.last_possition = gpos
示例#4
0
    def maybe_commander(self, entity):
        if self.world.commander.eid != entity.eid:
            return
        gpos = entity.grid_position
        block = self.world.grid.standing_on_block(
            AABB.from_player_coords(entity.position))
        if block is None:
            return
        if self.world.commander.last_block is not None and self.world.commander.last_block == block:
            return
        self.world.commander.last_block = block
        lpos = self.world.commander.last_possition
        in_nodes = self.world.navgrid.graph.has_node(block.coords)
        gs = GridSpace(self.world.grid, block=block)
        msg = "P in nm %s nm nodes %d\n" % \
            (in_nodes, self.world.navgrid.graph.node_count)
        msg += "gs_stand %s\n" % str(gs.bb_stand)
        msg += str(block) + '\n'
        msg += str(block.grid_bounding_box)
        try:
            msg += "\nsucessors %s" % str(self.world.navgrid.graph.get_succ(block.coords))
        except:
            pass
        if lpos is not None:
            gsl = GridSpace(self.world.grid, coords=lpos)
            if gsl.can_stand_on:
                pass
            else:
                gsl = GridSpace(
                    self.world.grid, coords=(lpos[0], lpos[1] - 1, lpos[2]))
                if gsl.can_stand_on:
                    lpos = gsl.coords
            if not(gsl.bb_stand is None or gs.bb_stand is None):
                msg += "\ncost from %s to %s %s\n" % \
                    (lpos, block.coords,
                     self.world.navgrid.graph.get_edge(lpos, block.coords))
                msg += "last stand %s now stand %s from %s to %s\n" % \
                    (gsl.can_stand_on, gs.can_stand_on,
                     gsl.bb_stand, gs.bb_stand)
                if gsl.can_go_between(gs, debug=True):
                    msg += "can go True with cost %s\n" % gsl.edge_cost
                else:
                    msg += "can go False\n"
                msg += "can stand between %s intersection %s" % (
                    gsl.can_stand_between(gs, debug=True), gsl.intersection)

        log.msg(msg)
        self.world.commander.last_possition = gpos
示例#5
0
 def set_xyz(self, x, y, z):
     self._x = x
     self._y = y
     self._z = z
     self._aabb = AABB.from_player_coords(self.position)
示例#6
0
 def aabb(self):
     return AABB.from_player_coords(self.position)
示例#7
0
 def set_xyz(self, x, y, z):
     self._x = x
     self._y = y
     self._z = z
     self._aabb = AABB.from_player_coords(self.position)