예제 #1
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
예제 #2
0
 def check_status(self, b_obj):
     bb_stand = self.target_space.bb_stand
     elev = bb_stand.min_y - b_obj.aabb.min_y
     gs = GridSpace(self.world.grid, bb=b_obj.aabb)
     if not self.target_space._can_stand_on():
         self.world.grid.navgrid.delete_node(self.target_space.coords)
         log.msg('CANNOT STAND ON %s' % self.target_space)
         return Status.failure
     if b_obj.horizontally_blocked and not gs.can_go_between(self.target_space, debug=True):
         log.msg('CANNOT GO BETWEEN %s AND %s' % (b_obj.aabb, self.target_space))
         return Status.failure
     if self.bot.is_on_ladder(b_obj) or self.bot.is_in_water(b_obj):
         if b_obj.position_grid == self.target_space.coords:
             return Status.success
     if b_obj.aabb.horizontal_distance(bb_stand) < self.bot.current_motion(b_obj):
         self.was_at_target = True
         if fops.eq(elev, 0):
             return Status.success
     if b_obj.horizontally_blocked and b_obj.on_ground:
         if not gs.can_go(self.target_space):
             log.msg("I am stuck, let's try again? vels %s" %
                     str(b_obj.velocities))
             return Status.failure
     return Status.running