コード例 #1
0
    def execute(self, agent):
        # If ladder is already placed here:
        if agent.wall.is_ladder(agent.current_ladder):
            d4 = roll_int(1,4)
            if d4 < 3:
                agent.fsm.change_state(AttackerClimb())
            else:
                # Find a spot for another ladder
                print("%s : Trying to place another ladder..." % agent.name)
                ladder_loc = agent.wall.get_empty_ladder_space()
                if ladder_loc is not None:
                    agent.current_ladder = ladder_loc
                    print("%s : ...found an empty space at %d." % (agent.name, ladder_loc))
                    agent.fsm.change_state(AttackerHoist())
                    return True
                else: # No free space for ladder, wait 3 turns...
                    print("%s : ...but no empty spaces! Will climb this one!" % agent.name)
                    agent.fsm.change_state(AttackerClimb())
                    return True

        # Otherwise, try to place the ladder
        elif agent.wall.place_ladder(agent.current_ladder):
            # TODO: Should the wall post this message instead?
            agent.postoffice.post_msg(0, ATTACKER, DEFENDER, LADDER_PLACED, agent.current_ladder)
        else:
            agent.fsm.change_state(AttackerWait())
コード例 #2
0
    def execute(self, agent):
        # Check for fatigue first
        if agent.fatigue >= Sentry.FATIGUE_HEAVY:
            agent.fsm.change_state(SentryRest())
            return

        ladder = agent.wall.get_nearest_ladder(agent.location, Sentry.SIGHT_PATROL)
        if ladder is not None:
            agent.add_task_to_queue(ladder)
            agent.fsm.change_state(SentryRepel())
            return

        # Otherwise, continue patrol

        # PigSupreme added this to handle end-of-wall locations:
        ########################################################
        if agent.location == 0:
            if agent.direction == 1:
                agent.move(1)
            else:
                agent.about_face()
        if agent.location == WALL_MAX:
            if agent.direction == -1:
                agent.move(1)
            else:
                agent.about_face()
        ########################################################

        # We do something different if within 1 space of end of wall:
        # PigSupreme cleaned this up to work with end-of-wall code above.
        # TODO: Consider fixing this, sentries seem to linger too long.
        if agent.location == 1:
            d4 = roll_int(1, 4)
            if d4 > 1 and agent.direction == -1:
                agent.about_face()
        elif agent.location == WALL_MAX - 1:
            d4 = roll_int(1, 4)
            if d4 > 1 and agent.direction == 1:
                agent.about_face()
        else:
            d5 = roll_int(1, 5)
            if d5 == 2:
                agent.about_face()
            elif d5 > 2:
                agent.move(1)
コード例 #3
0
 def get_empty_ladder_space(self): #, space=WALL_MAX/2, dist=WALL_MAX):
     """Location of the nearest space that can hold a ladder,
     optionally within some distance."""
     empties = [x for x in self.ladders_allowed if self.spaces[x] == Wall.SPC_READY]
     print("%s : Empty spaces are %s" % (self.name, str(empties)))
     if empties == []:
         return None
     else:
         return empties[roll_int(0,len(empties)-1)]
コード例 #4
0
 def enter(self, agent):
     print("%s : Now awaiting orders!" % agent.name)
     agent.postoffice.post_msg(roll_int(2,5), ATTACKER, ATTACKER, LOOK_FOR_SPACE)