public override void DebugDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (selectedAiTarget != null)
            {
                GUI.DrawLine(spriteBatch,
                             new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
                             new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);
            }

            IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;

            if (pathSteering == null || pathSteering.CurrentPath == null || pathSteering.CurrentPath.CurrentNode == null)
            {
                return;
            }

            GUI.DrawLine(spriteBatch,
                         new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
                         new Vector2(pathSteering.CurrentPath.CurrentNode.DrawPosition.X, -pathSteering.CurrentPath.CurrentNode.DrawPosition.Y),
                         Color.LightGreen);


            for (int i = 1; i < pathSteering.CurrentPath.Nodes.Count; i++)
            {
                GUI.DrawLine(spriteBatch,
                             new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y),
                             new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y),
                             Color.LightGreen);

                GUI.SmallFont.DrawString(spriteBatch,
                                         pathSteering.CurrentPath.Nodes[i].ID.ToString(),
                                         new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10),
                                         Color.LightGreen);
            }
        }
 public HumanAIController(Character c) : base(c)
 {
     insideSteering      = new IndoorsSteeringManager(this, true, false);
     outsideSteering     = new SteeringManager(this);
     objectiveManager    = new AIObjectiveManager(c);
     reactTimer          = Rand.Range(0f, reactionTime);
     sortTimer           = Rand.Range(0f, sortObjectiveInterval);
     hullVisibilityTimer = Rand.Range(0f, hullVisibilityTimer);
     InitProjSpecific();
 }
        public override void DebugDraw(SpriteBatch spriteBatch)
        {
            if (Character.IsDead)
            {
                return;
            }

            Vector2 pos = Character.WorldPosition;

            pos.Y = -pos.Y;

            if (selectedAiTarget?.Entity != null)
            {
                GUI.DrawLine(spriteBatch, pos, new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red);

                if (wallAttackPos != Vector2.Zero)
                {
                    GUI.DrawRectangle(spriteBatch, ConvertUnits.ToDisplayUnits(new Vector2(wallAttackPos.X, -wallAttackPos.Y)) - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Red, false);
                }

                GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY * 20.0f, Color.Red);
            }

            GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, Color.Red);

            GUI.Font.DrawString(spriteBatch, "updatetargets: " + updateTargetsTimer, pos - Vector2.UnitY * 100.0f, Color.Red);
            GUI.Font.DrawString(spriteBatch, "cooldown: " + coolDownTimer, pos - Vector2.UnitY * 120.0f, Color.Red);


            IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;

            if (pathSteering == null || pathSteering.CurrentPath == null || pathSteering.CurrentPath.CurrentNode == null)
            {
                return;
            }

            GUI.DrawLine(spriteBatch,
                         new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
                         new Vector2(pathSteering.CurrentPath.CurrentNode.DrawPosition.X, -pathSteering.CurrentPath.CurrentNode.DrawPosition.Y),
                         Color.LightGreen);


            for (int i = 1; i < pathSteering.CurrentPath.Nodes.Count; i++)
            {
                GUI.DrawLine(spriteBatch,
                             new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y),
                             new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y),
                             Color.LightGreen);

                GUI.SmallFont.DrawString(spriteBatch,
                                         pathSteering.CurrentPath.Nodes[i].ID.ToString(),
                                         new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10),
                                         Color.LightGreen);
            }
        }
Exemple #4
0
        public HumanAIController(Character c) : base(c)
        {
            steeringManager = new IndoorsSteeringManager(this, true);

            objectiveManager = new AIObjectiveManager(c);
            objectiveManager.AddObjective(new AIObjectiveFindSafety(c));
            objectiveManager.AddObjective(new AIObjectiveIdle(c));

            updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);

            InitProjSpecific();
        }
Exemple #5
0
 public HumanAIController(Character c) : base(c)
 {
     if (!c.IsHuman)
     {
         throw new System.Exception($"Tried to create a human ai controller for a non-human: {c.SpeciesName}!");
     }
     insideSteering   = new IndoorsSteeringManager(this, true, false);
     outsideSteering  = new SteeringManager(this);
     objectiveManager = new AIObjectiveManager(c);
     reactTimer       = Rand.Range(0f, reactionTime);
     sortTimer        = Rand.Range(0f, sortObjectiveInterval);
     InitProjSpecific();
 }
Exemple #6
0
        public HumanAIController(Character c) : base(c)
        {
            steeringManager = new IndoorsSteeringManager(this, true);

            objectiveManager = new AIObjectiveManager(c);
            objectiveManager.AddObjective(new AIObjectiveFindSafety(c));
            objectiveManager.AddObjective(new AIObjectiveIdle(c));

            updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval);

            if (GameMain.GameSession != null && GameMain.GameSession.CrewManager != null)
            {
                CurrentOrder = Order.PrefabList.Find(o => o.Name.ToLowerInvariant() == "dismissed");
                objectiveManager.SetOrder(CurrentOrder, "");
                GameMain.GameSession.CrewManager.SetCharacterOrder(Character, CurrentOrder);
            }
        }
Exemple #7
0
        public EnemyAIController(Character c, string file) : base(c)
        {
            targetMemories = new Dictionary <AITarget, AITargetMemory>();

            XDocument doc = ToolBox.TryLoadXml(file);

            if (doc == null || doc.Root == null)
            {
                return;
            }

            XElement aiElement = doc.Root.Element("ai");

            if (aiElement == null)
            {
                return;
            }

            attackRooms     = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackrooms", "attackpriorityrooms") / 100.0f;
            attackHumans    = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackhumans", "attackpriorityhumans") / 100.0f;
            attackWeaker    = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackweaker", "attackpriorityweaker") / 100.0f;
            attackStronger  = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackstronger", "attackprioritystronger") / 100.0f;
            eatDeadPriority = ToolBox.GetAttributeFloat(aiElement, "eatpriority", 0.0f) / 100.0f;

            combatStrength = ToolBox.GetAttributeFloat(aiElement, "combatstrength", 1.0f);

            attackCoolDown = ToolBox.GetAttributeFloat(aiElement, "attackcooldown", 5.0f);

            sight   = ToolBox.GetAttributeFloat(aiElement, "sight", 0.0f);
            hearing = ToolBox.GetAttributeFloat(aiElement, "hearing", 0.0f);

            attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false);

            fleeHealthThreshold = ToolBox.GetAttributeFloat(aiElement, "fleehealththreshold", 0.0f);

            attachToWalls = ToolBox.GetAttributeBool(aiElement, "attachtowalls", false);

            outsideSteering = new SteeringManager(this);
            insideSteering  = new IndoorsSteeringManager(this, false);

            steeringManager = outsideSteering;

            state = AIState.None;
        }
        public EnemyAIController(Character c, string file) : base(c)
        {
            targetMemories = new Dictionary <AITarget, AITargetMemory>();

            XDocument doc = ToolBox.TryLoadXml(file);

            if (doc == null || doc.Root == null)
            {
                return;
            }

            XElement aiElement = doc.Root.Element("ai");

            if (aiElement == null)
            {
                return;
            }

            attackRooms    = ToolBox.GetAttributeFloat(aiElement, "attackrooms", 0.0f) / 100.0f;
            attackHumans   = ToolBox.GetAttributeFloat(aiElement, "attackhumans", 0.0f) / 100.0f;
            attackWeaker   = ToolBox.GetAttributeFloat(aiElement, "attackweaker", 0.0f) / 100.0f;
            attackStronger = ToolBox.GetAttributeFloat(aiElement, "attackstronger", 0.0f) / 100.0f;

            attackCoolDown = ToolBox.GetAttributeFloat(aiElement, "attackcooldown", 5.0f);

            sight   = ToolBox.GetAttributeFloat(aiElement, "sight", 0.0f);
            hearing = ToolBox.GetAttributeFloat(aiElement, "hearing", 0.0f);

            attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false);

            outsideSteering = new SteeringManager(this);
            insideSteering  = new IndoorsSteeringManager(this, false);

            steeringManager = outsideSteering;

            state = AiState.None;
        }
        public override void DebugDraw(SpriteBatch spriteBatch)
        {
            if (Character.IsDead)
            {
                return;
            }

            Vector2 pos = Character.WorldPosition;

            pos.Y = -pos.Y;

            if (selectedAiTarget?.Entity != null)
            {
                GUI.DrawLine(spriteBatch, pos, new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red * 0.3f, 0, 5);

                if (wallTarget != null)
                {
                    Vector2 wallTargetPos = wallTarget.Position;
                    if (wallTarget.Structure.Submarine != null)
                    {
                        wallTargetPos += wallTarget.Structure.Submarine.Position;
                    }
                    wallTargetPos.Y = -wallTargetPos.Y;
                    GUI.DrawRectangle(spriteBatch, wallTargetPos - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Red, false);
                    GUI.DrawLine(spriteBatch, pos, wallTargetPos, Color.Orange * 0.5f, 0, 5);
                }

                GUI.Font.DrawString(spriteBatch, $"{selectedAiTarget.Entity.ToString()} ({targetValue.ToString()})", pos - Vector2.UnitY * 20.0f, Color.Red);
            }

            /*GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, Color.Red);
             * GUI.Font.DrawString(spriteBatch, "updatetargets: " + MathUtils.Round(updateTargetsTimer, 0.1f), pos - Vector2.UnitY * 100.0f, Color.Red);
             * GUI.Font.DrawString(spriteBatch, "cooldown: " + MathUtils.Round(coolDownTimer, 0.1f), pos - Vector2.UnitY * 120.0f, Color.Red);*/

            Color stateColor = Color.White;

            switch (State)
            {
            case AIState.Attack:
                stateColor = IsCoolDownRunning ? Color.Orange : Color.Red;
                break;

            case AIState.Escape:
                stateColor = Color.LightBlue;
                break;

            case AIState.Eat:
                stateColor = Color.Brown;
                break;

            case AIState.GoTo:
                stateColor = Color.Magenta;
                break;
            }
            GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 80.0f, State.ToString(), stateColor, Color.Black);

            if (latchOntoAI != null)
            {
                foreach (Joint attachJoint in latchOntoAI.AttachJoints)
                {
                    GUI.DrawLine(spriteBatch,
                                 ConvertUnits.ToDisplayUnits(new Vector2(attachJoint.WorldAnchorA.X, -attachJoint.WorldAnchorA.Y)),
                                 ConvertUnits.ToDisplayUnits(new Vector2(attachJoint.WorldAnchorB.X, -attachJoint.WorldAnchorB.Y)), Color.Orange * 0.6f, 0, 5);
                }

                if (latchOntoAI.WallAttachPos.HasValue)
                {
                    GUI.DrawLine(spriteBatch, pos,
                                 ConvertUnits.ToDisplayUnits(new Vector2(latchOntoAI.WallAttachPos.Value.X, -latchOntoAI.WallAttachPos.Value.Y)), Color.Orange * 0.6f, 0, 3);
                }
            }

            IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager;

            if (pathSteering == null || pathSteering.CurrentPath == null || pathSteering.CurrentPath.CurrentNode == null)
            {
                return;
            }

            GUI.DrawLine(spriteBatch,
                         new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y),
                         new Vector2(pathSteering.CurrentPath.CurrentNode.DrawPosition.X, -pathSteering.CurrentPath.CurrentNode.DrawPosition.Y),
                         Color.Orange * 0.6f, 0, 3);

            for (int i = 1; i < pathSteering.CurrentPath.Nodes.Count; i++)
            {
                GUI.DrawLine(spriteBatch,
                             new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y),
                             new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y),
                             Color.Orange * 0.6f, 0, 3);

                GUI.SmallFont.DrawString(spriteBatch,
                                         pathSteering.CurrentPath.Nodes[i].ID.ToString(),
                                         new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10),
                                         Color.LightGreen);
            }
        }