Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Characters/AI/HumanAIController.cs
1 using Microsoft.Xna.Framework;
2 using FarseerPhysics;
3 using System;
4 using System.Linq;
5 
6 namespace Barotrauma
7 {
8  partial class HumanAIController : AIController
9  {
10  public override void DebugDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
11  {
12  if (Character == Character.Controlled) { return; }
13  if (!DebugAI) { return; }
14  Vector2 pos = Character.WorldPosition;
15  pos.Y = -pos.Y;
16  Vector2 textOffset = new Vector2(-40, -160);
17  textOffset.Y -= Math.Max(ObjectiveManager.CurrentOrders.Count - 1, 0) * 20;
18 
19  if (SelectedAiTarget?.Entity != null)
20  {
21  //GUI.DrawLine(spriteBatch, pos, new Vector2(SelectedAiTarget.WorldPosition.X, -SelectedAiTarget.WorldPosition.Y), GUIStyle.Red);
22  //GUI.DrawString(spriteBatch, pos + textOffset, $"AI TARGET: {SelectedAiTarget.Entity.ToString()}", Color.White, Color.Black);
23  }
24 
25  Vector2 stringDrawPos = pos + textOffset;
26  GUI.DrawString(spriteBatch, stringDrawPos, Character.Name, Color.White, Color.Black);
27 
28  var currentOrder = ObjectiveManager.CurrentOrder;
30  {
31  var currentOrders = ObjectiveManager.CurrentOrders;
32  currentOrders.Sort((x, y) => y.ManualPriority.CompareTo(x.ManualPriority));
33  for (int i = 0; i < currentOrders.Count; i++)
34  {
35  stringDrawPos += new Vector2(0, 20);
36  var order = currentOrders[i];
37  GUI.DrawString(spriteBatch, stringDrawPos, $"ORDER {i + 1}: {order.Objective.DebugTag} ({order.Objective.Priority.FormatZeroDecimal()})", Color.White, Color.Black);
38  }
39  }
40  else if (ObjectiveManager.WaitTimer > 0)
41  {
42  stringDrawPos += new Vector2(0, 20);
43  GUI.DrawString(spriteBatch, stringDrawPos - textOffset, $"Waiting... {ObjectiveManager.WaitTimer.FormatZeroDecimal()}", Color.White, Color.Black);
44  }
45  var currentObjective = ObjectiveManager.CurrentObjective;
46  if (currentObjective != null)
47  {
48  int offset = currentOrder != null ? 20 + ((ObjectiveManager.CurrentOrders.Count - 1) * 20) : 0;
49  if (currentOrder == null || currentOrder.Priority <= 0)
50  {
51  stringDrawPos += new Vector2(0, 20);
52  GUI.DrawString(spriteBatch, stringDrawPos, $"MAIN OBJECTIVE: {currentObjective.DebugTag} ({currentObjective.Priority.FormatZeroDecimal()})", Color.White, Color.Black);
53  }
54  var subObjective = currentObjective.CurrentSubObjective;
55  if (subObjective != null)
56  {
57  stringDrawPos += new Vector2(0, 20);
58  GUI.DrawString(spriteBatch, stringDrawPos, $"SUBOBJECTIVE: {subObjective.DebugTag} ({subObjective.Priority.FormatZeroDecimal()})", Color.White, Color.Black);
59  }
60  var activeObjective = ObjectiveManager.GetActiveObjective();
61  if (activeObjective != null)
62  {
63  stringDrawPos += new Vector2(0, 20);
64  GUI.DrawString(spriteBatch, stringDrawPos, $"ACTIVE OBJECTIVE: {activeObjective.DebugTag} ({activeObjective.Priority.FormatZeroDecimal()})", Color.White, Color.Black);
65  }
66  }
67 
68  Vector2 objectiveStringDrawPos = stringDrawPos + new Vector2(120, 40);
69  for (int i = 0; i < ObjectiveManager.Objectives.Count; i++)
70  {
71  var objective = ObjectiveManager.Objectives[i];
72  GUI.DrawString(spriteBatch, objectiveStringDrawPos, $"{objective.DebugTag} ({objective.Priority.FormatZeroDecimal()})", Color.White, Color.Black * 0.5f);
73  objectiveStringDrawPos += new Vector2(0, 18);
74  }
75 
76  if (steeringManager is IndoorsSteeringManager pathSteering)
77  {
78  var path = pathSteering.CurrentPath;
79  if (path != null)
80  {
81  for (int i = 1; i < path.Nodes.Count; i++)
82  {
83  var previousNode = path.Nodes[i - 1];
84  var currentNode = path.Nodes[i];
85  bool isPathActive = !path.Finished && !path.IsAtEndNode;
86  Color pathColor = isPathActive ? Color.Blue * 0.5f : Color.Gray;
87  GUI.DrawLine(spriteBatch,
88  new Vector2(currentNode.DrawPosition.X, -currentNode.DrawPosition.Y),
89  new Vector2(previousNode.DrawPosition.X, -previousNode.DrawPosition.Y),
90  pathColor, 0, 3);
91 
92  if (isPathActive)
93  {
94  GUIStyle.SmallFont.DrawString(spriteBatch,
95  currentNode.ID.ToString(),
96  new Vector2(currentNode.DrawPosition.X - 10, -currentNode.DrawPosition.Y - 30),
97  Color.Blue);
98  }
99  }
100  if (path.CurrentNode != null)
101  {
102  GUI.DrawLine(spriteBatch, pos,
103  new Vector2(path.CurrentNode.DrawPosition.X, -path.CurrentNode.DrawPosition.Y),
104  Color.BlueViolet, 0, 3);
105 
106  GUI.DrawString(spriteBatch, stringDrawPos + new Vector2(0, 40), "Path cost: " + path.Cost.FormatZeroDecimal(), Color.White, Color.Black * 0.5f);
107  }
108  }
109  }
110  GUI.DrawLine(spriteBatch, pos, pos + ConvertUnits.ToDisplayUnits(new Vector2(Character.AnimController.TargetMovement.X, -Character.AnimController.TargetMovement.Y)), Color.SteelBlue, width: 2);
111  GUI.DrawLine(spriteBatch, pos, pos + ConvertUnits.ToDisplayUnits(new Vector2(Steering.X, -Steering.Y)), Color.Blue, width: 3);
112 
113  if (Character.AnimController.InWater && objectiveManager.GetActiveObjective() is AIObjectiveGoTo gotoObjective && gotoObjective.TargetGap != null)
114  {
115  Vector2 gapPosition = gotoObjective.TargetGap.WorldPosition;
116  gapPosition.Y = -gapPosition.Y;
117  GUI.DrawRectangle(spriteBatch, gapPosition - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Orange, false);
118  GUI.DrawLine(spriteBatch, pos, gapPosition, Color.Orange * 0.5f, 0, 5);
119  }
120 
121  //if (Character.IsKeyDown(InputType.Aim))
122  //{
123  // GUI.DrawLine(spriteBatch, pos, new Vector2(Character.CursorWorldPosition.X, -Character.CursorWorldPosition.Y), Color.Yellow, width: 4);
124  //}
125  }
126  }
127 }
AIObjective GetActiveObjective()
List< AIObjective > Objectives
Excluding the current order.
AIObjective CurrentObjective
Includes orders.
AIObjective?? CurrentOrder
The AIObjective in CurrentOrders with the highest AIObjective.Priority
float? WaitTimer
When set above zero, the character will stand still doing nothing until the timer runs out....
virtual Vector2 WorldPosition
Definition: Entity.cs:49
override void DebugDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)