Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Characters/AI/EnemyAIController.cs
1 using FarseerPhysics;
2 using FarseerPhysics.Dynamics.Joints;
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
5 
6 namespace Barotrauma
7 {
8  partial class EnemyAIController : AIController
9  {
10  public override void DebugDraw(SpriteBatch spriteBatch)
11  {
12  if (Character.IsUnconscious || !Character.Enabled || !Enabled) { return; }
13 
14  Vector2 pos = Character.DrawPosition;
15  pos.Y = -pos.Y;
16 
17  if (State == AIState.Idle && PreviousState == AIState.Attack)
18  {
19  var target = _selectedAiTarget ?? _lastAiTarget;
20  if (target != null && target.Entity != null)
21  {
22  var memory = GetTargetMemory(target);
23  if (memory != null)
24  {
25  Vector2 targetPos = memory.Location;
26  targetPos.Y = -targetPos.Y;
27  GUI.DrawLine(spriteBatch, pos, targetPos, Color.White * 0.5f, 0, 4);
28  GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 60.0f, $"{target.Entity} ({memory.Priority.FormatZeroDecimal()})", Color.White, Color.Black);
29  }
30  }
31  }
32  else if (SelectedAiTarget?.Entity != null)
33  {
34  Vector2 targetPos = SelectedAiTarget.Entity.DrawPosition;
35  if (State == AIState.Attack)
36  {
37  targetPos = attackWorldPos;
38  }
39  targetPos.Y = -targetPos.Y;
40 
41  GUI.DrawLine(spriteBatch, pos, targetPos, GUIStyle.Red * 0.5f, 0, 4);
42  if (wallTarget != null && !IsCoolDownRunning)
43  {
44  Vector2 wallTargetPos = wallTarget.Position;
45  if (wallTarget.Structure.Submarine != null) { wallTargetPos += wallTarget.Structure.Submarine.Position; }
46  wallTargetPos.Y = -wallTargetPos.Y;
47  GUI.DrawRectangle(spriteBatch, wallTargetPos - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Orange, false);
48  GUI.DrawLine(spriteBatch, pos, wallTargetPos, Color.Orange * 0.5f, 0, 5);
49  }
50  GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 60.0f, $"{SelectedAiTarget.Entity}", GUIStyle.Red, Color.Black);
51  GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 40.0f, $"{targetValue.FormatZeroDecimal()} (M: {SelectedTargetMemory?.Priority.FormatZeroDecimal()}, P: {SelectedTargetingParams?.Priority.FormatZeroDecimal()})", GUIStyle.Red, Color.Black);
52  }
53 
54  /*GUIStyle.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, GUIStyle.Red);
55  GUIStyle.Font.DrawString(spriteBatch, "updatetargets: " + MathUtils.Round(updateTargetsTimer, 0.1f), pos - Vector2.UnitY * 100.0f, GUIStyle.Red);
56  GUIStyle.Font.DrawString(spriteBatch, "cooldown: " + MathUtils.Round(coolDownTimer, 0.1f), pos - Vector2.UnitY * 120.0f, GUIStyle.Red);*/
57 
58  Color stateColor = Color.White;
59  switch (State)
60  {
61  case AIState.Attack:
62  stateColor = IsCoolDownRunning ? Color.Orange : GUIStyle.Red;
63  break;
64  case AIState.Escape:
65  stateColor = Color.LightBlue;
66  break;
67  case AIState.Flee:
68  stateColor = Color.White;
69  break;
70  case AIState.Eat:
71  stateColor = Color.Brown;
72  break;
73  }
74  GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 80.0f, State.ToString(), stateColor, Color.Black);
75 
76  if (State == AIState.Attack && selectedTargetingParams != null && selectedTargetingParams.AttackPattern == AttackPattern.Circle)
77  {
78  GUI.DrawString(spriteBatch, pos - Vector2.UnitY * 100.0f, CirclePhase.ToString(), stateColor, Color.Black);
79  }
80 
81  if (LatchOntoAI != null && (State == AIState.Idle || LatchOntoAI.IsAttachedToSub))
82  {
83  foreach (Joint attachJoint in LatchOntoAI.AttachJoints)
84  {
85  GUI.DrawLine(spriteBatch,
86  ConvertUnits.ToDisplayUnits(new Vector2(attachJoint.WorldAnchorA.X, -attachJoint.WorldAnchorA.Y)),
87  ConvertUnits.ToDisplayUnits(new Vector2(attachJoint.WorldAnchorB.X, -attachJoint.WorldAnchorB.Y)), GUIStyle.Green, 0, 4);
88  }
89 
90  if (LatchOntoAI.AttachPos.HasValue)
91  {
92  GUI.DrawLine(spriteBatch, pos,
93  ConvertUnits.ToDisplayUnits(new Vector2(LatchOntoAI.AttachPos.Value.X, -LatchOntoAI.AttachPos.Value.Y)), GUIStyle.Green, 0, 3);
94  }
95  }
96 
97  if (steeringManager is IndoorsSteeringManager pathSteering)
98  {
99  var path = pathSteering.CurrentPath;
100  if (path != null)
101  {
102  if (path.CurrentNode != null)
103  {
104  GUI.DrawLine(spriteBatch, pos,
105  new Vector2(path.CurrentNode.DrawPosition.X, -path.CurrentNode.DrawPosition.Y),
106  Color.DarkViolet, 0, 3);
107 
108  GUI.DrawString(spriteBatch, pos - new Vector2(0, 100), "Path cost: " + path.Cost.FormatZeroDecimal(), Color.White, Color.Black * 0.5f);
109  }
110  for (int i = 1; i < path.Nodes.Count; i++)
111  {
112  var previousNode = path.Nodes[i - 1];
113  var currentNode = path.Nodes[i];
114  GUI.DrawLine(spriteBatch,
115  new Vector2(currentNode.DrawPosition.X, -currentNode.DrawPosition.Y),
116  new Vector2(previousNode.DrawPosition.X, -previousNode.DrawPosition.Y),
117  GUIStyle.Red * 0.5f, 0, 3);
118 
119  GUIStyle.SmallFont.DrawString(spriteBatch,
120  currentNode.ID.ToString(),
121  new Vector2(currentNode.DrawPosition.X - 10, -currentNode.DrawPosition.Y - 30),
122  GUIStyle.Red);
123  }
124  }
125  }
126  else
127  {
128  if (steeringManager.AvoidDir.LengthSquared() > 0.0001f)
129  {
130  Vector2 hitPos = ConvertUnits.ToDisplayUnits(steeringManager.AvoidRayCastHitPosition);
131  hitPos.Y = -hitPos.Y;
132 
133  GUI.DrawLine(spriteBatch, hitPos, hitPos + new Vector2(steeringManager.AvoidDir.X, -steeringManager.AvoidDir.Y) * 100, GUIStyle.Red, width: 5);
134  //GUI.DrawLine(spriteBatch, pos, ConvertUnits.ToDisplayUnits(steeringManager.AvoidLookAheadPos.X, -steeringManager.AvoidLookAheadPos.Y), Color.Orange, width: 4);
135  }
136  }
137  GUI.DrawLine(spriteBatch, pos, pos + ConvertUnits.ToDisplayUnits(new Vector2(Character.AnimController.TargetMovement.X, -Character.AnimController.TargetMovement.Y)), Color.SteelBlue, width: 2);
138  GUI.DrawLine(spriteBatch, pos, pos + ConvertUnits.ToDisplayUnits(new Vector2(Steering.X, -Steering.Y)), Color.Blue, width: 3);
139  }
140  }
141 }
virtual Vector2 DrawPosition
Definition: Entity.cs:51
List< Joint > AttachJoints
Definition: LatchOntoAI.cs:51