Пример #1
0
        public AIObjectiveCombat(Character character, Character enemy, CombatMode mode, AIObjectiveManager objectiveManager, float priorityModifier = 1, float coolDown = 10.0f) 
            : base(character, objectiveManager, priorityModifier)
        {
            if (mode == CombatMode.None)
            {
#if DEBUG
                DebugConsole.ThrowError("Combat mode == None");
#endif
                return;
            }
            Enemy = enemy;
            coolDownTimer = coolDown;
            findSafety = objectiveManager.GetObjective<AIObjectiveFindSafety>();
            if (findSafety != null)
            {
                findSafety.Priority = 0;
                HumanAIController.UnreachableHulls.Clear();
            }
            Mode = mode;
            initialMode = Mode;
            if (Enemy == null)
            {
                Mode = CombatMode.Retreat;
            }
        }
Пример #2
0
        private void Escape(float deltaTime)
        {
            if (escapeObjective == null)
            {
                escapeObjective = new AIObjectiveFindSafety(character);
            }

            if (enemy.AnimController.CurrentHull == character.AnimController.CurrentHull)
            {
                escapeObjective.OverrideCurrentHullSafety = 0.0f;
            }
            else
            {
                escapeObjective.OverrideCurrentHullSafety = null;
            }

            escapeObjective.TryComplete(deltaTime);

            //if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
            //{
            //    character.AIController.SteeringManager.SteeringManual(deltaTime,
            //        new Vector2(Math.Sign(character.SimPosition.X - enemy.SimPosition.X), 0.0f));
            //    coolDownTimer = CoolDown;
            //}
        }
Пример #3
0
 private void GetRescueTargets()
 {
     rescueTargets = Character.CharacterList.FindAll(c =>
                                                     c.AIController is HumanAIController &&
                                                     c != character &&
                                                     (c.IsDead || c.IsUnconscious) &&
                                                     c.AnimController.CurrentHull != null &&
                                                     AIObjectiveFindSafety.GetHullSafety(c.AnimController.CurrentHull, c) < 50.0f);
 }
 public AIObjectiveCombat(Character character, Character enemy, CombatMode mode) : base(character, "")
 {
     Enemy               = enemy;
     coolDownTimer       = CoolDown;
     findSafety          = HumanAIController.ObjectiveManager.GetObjective <AIObjectiveFindSafety>();
     findSafety.Priority = 0;
     findSafety.unreachable.Clear();
     Mode = mode;
     if (Enemy == null)
     {
         Mode = CombatMode.Retreat;
     }
 }
Пример #5
0
        private void Escape(float deltaTime)
        {
            if (escapeObjective == null)
            {
                escapeObjective = new AIObjectiveFindSafety(character);
            }

            if (enemy.AnimController.CurrentHull == character.AnimController.CurrentHull)
            {
                escapeObjective.OverrideCurrentHullSafety = 0.0f;
            }
            else
            {
                escapeObjective.OverrideCurrentHullSafety = null;
            }

            escapeObjective.TryComplete(deltaTime);
        }
Пример #6
0
 public AIObjectiveCombat(Character character, Character enemy, CombatMode mode, AIObjectiveManager objectiveManager, float priorityModifier = 1)
     : base(character, objectiveManager, priorityModifier)
 {
     Enemy         = enemy;
     coolDownTimer = coolDown;
     findSafety    = objectiveManager.GetObjective <AIObjectiveFindSafety>();
     if (findSafety != null)
     {
         findSafety.Priority = 0;
         HumanAIController.UnreachableHulls.Clear();
     }
     Mode        = mode;
     initialMode = Mode;
     if (Enemy == null)
     {
         Mode = CombatMode.Retreat;
     }
 }
Пример #7
0
        protected override void Act(float deltaTime)
        {
            if (targetCharacter == null || targetCharacter.Removed)
            {
                return;
            }

            // Unconcious target is not in a safe place -> Move to a safe place first
            if (targetCharacter.IsUnconscious && HumanAIController.GetHullSafety(targetCharacter.CurrentHull, targetCharacter) < HumanAIController.HULL_SAFETY_THRESHOLD)
            {
                if (character.SelectedCharacter != targetCharacter)
                {
                    character.Speak(TextManager.GetWithVariables("DialogFoundUnconsciousTarget", new string[2] {
                        "[targetname]", "[roomname]"
                    },
                                                                 new string[2] {
                        targetCharacter.Name, targetCharacter.CurrentHull.DisplayName
                    }, new bool[2] {
                        false, true
                    }),
                                    null, 1.0f, "foundunconscioustarget" + targetCharacter.Name, 60.0f);

                    // Go to the target and select it
                    if (!character.CanInteractWith(targetCharacter))
                    {
                        if (goToObjective != null && goToObjective.Target != targetCharacter)
                        {
                            goToObjective = null;
                        }
                        TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(targetCharacter, character, objectiveManager));
                    }
                    else
                    {
                        character.SelectCharacter(targetCharacter);
                    }
                }
                else
                {
                    // Drag the character into safety
                    if (goToObjective != null && goToObjective.Target == targetCharacter)
                    {
                        goToObjective = null;
                    }
                    if (safeHull == null)
                    {
                        var findSafety = objectiveManager.GetObjective <AIObjectiveFindSafety>();
                        if (findSafety == null)
                        {
                            // Ensure that we have the find safety objective (should always be the case)
                            findSafety = new AIObjectiveFindSafety(character, objectiveManager);
                            objectiveManager.AddObjective(findSafety);
                        }
                        safeHull = findSafety.FindBestHull(HumanAIController.VisibleHulls);
                    }
                    if (character.CurrentHull != safeHull)
                    {
                        TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(safeHull, character, objectiveManager));
                    }
                }
            }

            if (subObjectives.Any())
            {
                return;
            }

            if (!character.CanInteractWith(targetCharacter))
            {
                // Go to the target and select it
                TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(targetCharacter, character, objectiveManager));
            }
            else
            {
                // We can start applying treatment
                if (character.SelectedCharacter != targetCharacter)
                {
                    character.Speak(TextManager.GetWithVariables("DialogFoundWoundedTarget", new string[2] {
                        "[targetname]", "[roomname]"
                    },
                                                                 new string[2] {
                        targetCharacter.Name, targetCharacter.CurrentHull.DisplayName
                    }, new bool[2] {
                        false, true
                    }),
                                    null, 1.0f, "foundwoundedtarget" + targetCharacter.Name, 60.0f);

                    character.SelectCharacter(targetCharacter);
                }
                GiveTreatment(deltaTime);
            }
        }
Пример #8
0
        protected override void Act(float deltaTime)
        {
            var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;

            if (pathSteering == null)
            {
                return;
            }

            if (character.AnimController.InWater)
            {
                //attempt to find a safer place if in water
                if (findSafety == null)
                {
                    findSafety = new AIObjectiveFindSafety(character);
                }
                findSafety.TryComplete(deltaTime);
                return;
            }

            if (newTargetTimer <= 0.0f)
            {
                currentTarget = FindRandomTarget();

                if (currentTarget != null)
                {
                    Vector2 pos = character.SimPosition;
                    if (character != null && character.Submarine == null)
                    {
                        pos -= Submarine.MainSub.SimPosition;
                    }

                    var path = pathSteering.PathFinder.FindPath(pos, currentTarget.SimPosition);
                    if (path.Cost > 200.0f && character.AnimController.CurrentHull != null)
                    {
                        return;
                    }

                    pathSteering.SetPath(path);
                }


                newTargetTimer = currentTarget == null ? 5.0f : 15.0f;
            }

            newTargetTimer -= deltaTime;


            //wander randomly
            // - if reached the end of the path
            // - if the target is unreachable
            // - if the path requires going outside
            if (pathSteering == null || (pathSteering.CurrentPath != null &&
                                         (pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable || pathSteering.CurrentPath.HasOutdoorsNodes)))
            {
                //steer away from edges of the hull
                if (character.AnimController.CurrentHull != null)
                {
                    float leftDist  = character.Position.X - character.AnimController.CurrentHull.Rect.X;
                    float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X;

                    if (leftDist < WallAvoidDistance && rightDist < WallAvoidDistance)
                    {
                        if (Math.Abs(rightDist - leftDist) > WallAvoidDistance / 2)
                        {
                            pathSteering.SteeringManual(deltaTime, Vector2.UnitX * Math.Sign(rightDist - leftDist));
                        }
                        else
                        {
                            pathSteering.Reset();
                            return;
                        }
                    }
                    else if (leftDist < WallAvoidDistance)
                    {
                        pathSteering.SteeringManual(deltaTime, Vector2.UnitX * (WallAvoidDistance - leftDist) / WallAvoidDistance);
                        pathSteering.WanderAngle = 0.0f;
                        return;
                    }
                    else if (rightDist < WallAvoidDistance)
                    {
                        pathSteering.SteeringManual(deltaTime, -Vector2.UnitX * (WallAvoidDistance - rightDist) / WallAvoidDistance);
                        pathSteering.WanderAngle = MathHelper.Pi;
                        return;
                    }
                }

                character.AIController.SteeringManager.SteeringWander();
                //reset vertical steering to prevent dropping down from platforms etc
                character.AIController.SteeringManager.ResetY();

                return;
            }

            if (currentTarget?.Entity == null)
            {
                return;
            }
            if (currentTarget.Entity.Removed)
            {
                currentTarget = null;
                return;
            }
            character.AIController.SteeringManager.SteeringSeek(currentTarget.SimPosition, 2.0f);
        }