Пример #1
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;
            //}
        }
Пример #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);
        }
Пример #3
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);
        }