예제 #1
0
def ep_player_by_id(uid):
    return GEPlayer.ToMPPlayer(GEEntity.GetEntByUniqueId(uid))
예제 #2
0
    def GatherConditions(self):
        self.ClearCondition(Cond.NO_PRIMARY_AMMO)
        self.ClearCondition(Cond.LOW_PRIMARY_AMMO)
        self.ClearCondition(Cond.GES_LOW_AMMO)
        self.ClearCondition(Cond.GES_ENEMY_FAR)
        self.ClearCondition(Cond.GES_ENEMY_CLOSE)
        self.ClearCondition(Cond.GES_CAN_SEEK_ARMOR)
        self.ClearCondition(Cond.GES_CAN_NOT_SEEK_ARMOR)
        self.ClearCondition(Cond.GES_CLOSE_TO_ARMOR)
        self.ClearCondition(Cond.GES_NO_TARGET)

        if self.HasCondition(Cond.TOO_CLOSE_TO_ATTACK):
            self.SetCondition(Cond.CAN_RANGE_ATTACK1)
            self.ClearCondition(
                Cond.TOO_CLOSE_TO_ATTACK
            )  #TODO: DONT CLEAR IF CURRENT WEAPON IS EXPLOSIVE

        memory = self.GetSystem(AiSystems.MEMORY)

        if self.GetTarget() is None:
            if self.time_ignore_no_target_until <= GEUtil.GetTime():
                self.SetCondition(Cond.GES_NO_TARGET)

        if self.GetEnemy() is not None:
            # Set condition of enemy distance
            dist_to_enemy = self.GetEnemy().GetAbsOrigin().DistTo(
                self.GetAbsOrigin())
            if dist_to_enemy > 800:
                self.SetCondition(Cond.GES_ENEMY_FAR)
            elif dist_to_enemy < 200:
                self.SetCondition(Cond.GES_ENEMY_CLOSE)

            # Set condition of enemy "strength"
            try:
                enemy_weapon = self.GetEnemy().GetActiveWeapon()
                if enemy_weapon and enemy_weapon.GetWeight() > max(
                        Weapons.Weight.MEDIUM, self._max_weap_weight - 1):
                    self.SetCondition(Cond.GES_ENEMY_DANGEROUS)
                elif enemy_weapon and enemy_weapon.IsMeleeWeapon():
                    self.SetCondition(Cond.GES_ENEMY_UNARMED)
            except:
                pass

            # Should we switch enemies?
            if self.time_ignore_new_target_until < GEUtil.GetTime():
                self.ClearCondition(Cond.NEW_ENEMY)
                self.time_ignore_new_target_until = GEUtil.GetTime() + 1

                seen = self.GetSeenEntities()

                if self.GetEnemy() != None and not self.GetEnemy().IsAlive():
                    self.SetEnemy(None)

                closestEnemy = None
                for ent in seen:
                    player = GEPlayer.ToMPPlayer(ent)
                    if player != None and player.IsAlive():
                        if not GERules.IsTeamplay(
                        ) or player.GetTeamNumber() != self.GetTeamNumber():
                            if closestEnemy == None:
                                closestEnemy = player
                            elif self.GetAbsOrigin().DistTo(
                                    player.GetAbsOrigin()) < self.GetAbsOrigin(
                                    ).DistTo(closestEnemy.GetAbsOrigin()):
                                closestEnemy = player

                closestContact = None
                contacts = [
                    c for c in GERules.GetRadar().ListContactsNear(
                        self.GetAbsOrigin())
                    if c["type"] == Glb.RADAR_TYPE_PLAYER
                ]
                for contact in contacts:
                    player = GEPlayer.ToMPPlayer(
                        GEEntity.GetEntByUniqueId(
                            contact["ent_handle"].GetUID()))
                    if player != None and player.IsAlive():
                        if not GERules.IsTeamplay(
                        ) or player.GetTeamNumber() != self.GetTeamNumber():
                            if closestContact == None:
                                closestContact = player
                            elif self.GetAbsOrigin().DistTo(
                                    player.GetAbsOrigin()) < self.GetAbsOrigin(
                                    ).DistTo(closestContact.GetAbsOrigin()):
                                closestContact = player

                if closestContact != None:
                    if closestEnemy == None:
                        closestEnemy = closestContact
                    elif self.GetAbsOrigin().DistTo(
                            closestContact.GetAbsOrigin()) < self.GetAbsOrigin(
                            ).DistTo(closestEnemy.GetAbsOrigin()) * 0.6:
                        closestEnemy = closestContact

                newEnemy = False
                if closestEnemy != None:
                    if self.GetEnemy() == None \
                        or self.GetAbsOrigin().DistTo( closestEnemy.GetAbsOrigin() ) < self.GetAbsOrigin().DistTo( self.GetEnemy().GetAbsOrigin() ) * 0.8:
                        self.SetEnemy(closestEnemy)
                        self.time_ignore_new_target_until = GEUtil.GetTime(
                        ) + 5
                        newEnemy = True

                self.ClearCondition(Cond.SEE_ENEMY)
                if self.GetEnemy() != None and self.GetEnemy() in seen:
                    self.SetCondition(Cond.SEE_ENEMY)
                    if newEnemy:
                        self.SetCondition(Cond.NEW_ENEMY)

        # Ammo Checks
        currWeap = self.GetActiveWeapon()
        assert isinstance(currWeap, GEWeapon.CGEWeapon)
        if currWeap and not currWeap.IsMeleeWeapon(
        ) and currWeap.GetWeaponId() != Glb.WEAPON_MOONRAKER:

            if ( currWeap.GetMaxClip() > 0 and currWeap.GetAmmoCount() < ( currWeap.GetMaxClip() * 2 ) ) \
                or currWeap.GetAmmoCount() <= currWeap.GetMaxAmmoCount() / 4.0:
                self.SetCondition(Cond.GES_LOW_AMMO)

            if currWeap.GetAmmoCount() <= currWeap.GetMaxAmmoCount() / 100:
                # We have very little ammo left for this weapon
                self.SetCondition(Cond.NO_PRIMARY_AMMO)
            elif currWeap.GetMaxClip() > 0 and currWeap.GetClip() < (
                    currWeap.GetMaxClip() / 8.0):
                # We are running out of our clip
                self.SetCondition(Cond.LOW_PRIMARY_AMMO)

        if currWeap and currWeap.GetWeight() < self._medium_weap_weight:
            self.SetCondition(Cond.LOW_WEAPON_WEIGHT)

        # Armor checks
        from GEGamePlay import GetScenario
        from GEGamePlay import CBaseScenario
        armorvests = GetScenario().itemTracker.armorvests
        if len(armorvests) > 0:
            if self.GetArmor() < self.GetMaxArmor():
                self.SetCondition(Cond.GES_CAN_SEEK_ARMOR)
            else:
                self.SetCondition(Cond.GES_CAN_NOT_SEEK_ARMOR)

            # find close armor
            for armor in armorvests:
                if self.GetAbsOrigin().DistTo(armor.GetAbsOrigin()) < 512:
                    self.SetCondition(Cond.GES_CLOSE_TO_ARMOR)
                    break
        else:
            self.SetCondition(Cond.GES_CAN_NOT_SEEK_ARMOR)