Ejemplo n.º 1
0
    def enter(self, last_state):
        self.enter_timer.begin(gauss(self.ai.STAY_TIME_MU, self.ai.STAY_TIME_SIGMA))
        # turn for a random direction if the last state is the same "stay"
        if last_state and last_state.id == cfg.SpriteState.STAY \
            and happen(self.ai.STAY_CHANGE_DIRECTION_PROB):
            self.sprite.direction = choice(cfg.Direction.ALL)   # a random direction from "all"

        if happen(self.ai.EMOTION_SILENT_PROB):
            self.sprite.set_emotion(cfg.SpriteEmotion.SILENT)
Ejemplo n.º 2
0
    def check_conditions(self):
        sp = self.sprite
        if self.enter_timer.exceed():
            if happen(self.ai.DEFENCE_TO_OFFENCE_PROB) and sp.attacker.chance(sp.brain.target):
                return cfg.SpriteState.OFFENCE

            distance_to_target = sp.pos.get_distance_to(sp.brain.target.pos)
            if happen(self.ai.DEFENCE_TO_CHASE_PROB) and distance_to_target <= self.ai.CHASE_RANGE :
                return cfg.SpriteState.CHASE

            if distance_to_target > self.ai.CHASE_RANGE:
                sp.brain.target = None
                return cfg.SpriteState.STAY

            return cfg.SpriteState.DEFENCE

        else:
            sp.direction = cal_face_direct(sp.pos.as_tuple(), sp.brain.target.pos.as_tuple())
Ejemplo n.º 3
0
    def check_conditions(self):
        sp = self.sprite
        if sp.brain.target is not None:
            sp.set_emotion(cfg.SpriteEmotion.ALERT)
            # discover a target
            if happen(self.ai.STAY_TO_OFFENCE_PROB) and sp.attacker.chance(sp.brain.target):
                #print "to attack"
                return cfg.SpriteState.OFFENCE

            if happen(self.ai.STAY_TO_CHASE_PROB):
                return cfg.SpriteState.CHASE

            return cfg.SpriteState.DEFENCE

        if self.enter_timer.exceed():
            if happen(self.ai.STAY_TO_PATROL_PROB):
                #print "stay to patrol"
                return cfg.SpriteState.PATROL
            else:
                return cfg.SpriteState.STAY
Ejemplo n.º 4
0
    def check_conditions(self):
        sp = self.sprite
        if sp.brain.persistent:
            return 

        if sp.attacker.chance(sp.brain.target):
            return cfg.SpriteState.OFFENCE

        if happen(self.ai.OFFENCE_TO_CHASE_PROB):
            return cfg.SpriteState.CHASE

        return cfg.SpriteState.DEFENCE
Ejemplo n.º 5
0
    def check_conditions(self):
        sp = self.sprite

        if happen(self.ai.CHASE_TO_OFFENCE_PROB) and sp.attacker.chance(sp.brain.target):
            #print "to attack"
            return cfg.SpriteState.OFFENCE

        if (not self.steerer.is_ok) or happen(self.ai.CHASE_TO_DEFENCE_PROB):
            return cfg.SpriteState.DEFENCE

        distance_to_target = sp.pos.get_distance_to(sp.brain.target.pos)
        if distance_to_target <= self.ai.CHASE_RANGE:
            target_move = sp.brain.destination.get_distance_to(sp.brain.target.pos)
            if target_move > self.target_move_threshold or self.steerer.is_end:
                #print "chase to chase"
                return cfg.SpriteState.CHASE
        else:
            # lose target
            #print "lose target"
            sp.brain.target = None
            sp.set_emotion(cfg.SpriteEmotion.CHAOS)
            return cfg.SpriteState.STAY
Ejemplo n.º 6
0
    def check_conditions(self):
        sp = self.sprite
        if sp.brain.target is not None:
            sp.set_emotion(cfg.SpriteEmotion.ALERT)
            if sp.attacker.chance(sp.brain.target):
                #print "patrol to attack"
                return cfg.SpriteState.OFFENCE

            if happen(self.ai.PATROL_TO_CHASE_PROB):
                #print "patrol to chase"
                return cfg.SpriteState.CHASE

            return cfg.SpriteState.DEFENCE

        if sp.brain.interrupt:
            sp.brain.interrupt = False
            return cfg.SpriteState.STAY

        if self.enter_timer.exceed():
            return cfg.SpriteState.STAY