Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIWorld.c
Go to the documentation of this file.
1 void ScriptInvoker_AIWorldControlModeChangedMethod(AIGroup group, EGroupControlMode mode);
3 typedef ScriptInvokerBase<ScriptInvoker_AIWorldControlModeChangedMethod> ScriptInvoker_AIWorldControlModeChanged;
4 
5 //#define DEBUG_NAVMESH_REBUILD_AREAS //--- Show bounds of recalculated navmesh areas
6 
7 class SCR_AIWorldClass: AIWorldClass
8 {
9 };
10 
12 {
21 };
22 
23 class SCR_AIWorld : AIWorld
24 {
25  static const float MAX_NAVMESH_REBUILD_SIZE = 100 * 100; //--- Squared value
26 
27  static ref ScriptInvoker s_OnAgentSpawned = new ScriptInvoker();
28  static ref ScriptInvoker s_OnAgentRemoved = new ScriptInvoker();
29  static bool s_bDiagRegistered;
30 
31  [Attribute("", UIWidgets.Object)]
32  ref array<ref SCR_AIMessageGoal> m_aGoalMessages;
33  ref array<ref SCR_AIMessageGoal> m_aGoalMessagesPacked = new array<ref SCR_AIMessageGoal>();
34 
35  [Attribute("", UIWidgets.Object)]
36  ref array<ref SCR_AIMessageInfo> m_aInfoMessages;
37  ref array<ref SCR_AIMessageInfo> m_aInfoMessagesPacked = new array<ref SCR_AIMessageInfo>();
38 
39  [Attribute("", UIWidgets.Object)]
40  ref array<ref SCR_AIOrderBase> m_aOrders;
41  ref array<ref SCR_AIOrderBase> m_aOrdersPacked = new array<ref SCR_AIOrderBase>();
42 
43  protected ref ScriptInvoker_AIWorldControlModeChanged m_OnControlModeChanged = new ScriptInvoker_AIWorldControlModeChanged();
44 
45 #ifdef DEBUG_NAVMESH_REBUILD_AREAS
46  protected ref array<ref Shape> m_DebugNavmeshRebuildAreas = new array<ref Shape>;
47 #endif
48  [Attribute("200", UIWidgets.EditBox, "Amount of AIs that can be in simulation", "0 1000 1", NULL, "AILimits")]
49  protected int m_iActiveAILimit;
50  //------------------------------------------------------------------------------------------------
56  ScriptInvoker_AIWorldControlModeChanged GetOnControlModeChanged()
57  {
58  return m_OnControlModeChanged;
59  }
60 
61  protected void RegisterDbgCategory()
62  {
63  string categories;
64  for (int i = 0; i < EAIDebugCategory.LAST-1; i++)
65  {
66  categories += typename.EnumToString(EAIDebugCategory, i)+",";
67  }
68  categories += typename.EnumToString(EAIDebugCategory, EAIDebugCategory.LAST-1);
69 
70  DiagMenu.RegisterItem(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY, "", "AI Debug Category", "AIScript", categories);
71 #ifdef AI_DEBUG
72  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY,EAIDebugCategory.BEHAVIOR);
73 #endif
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  override void EOnInit (IEntity owner)
78  {
79  if (!s_bDiagRegistered)
80  {
81  DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_AI_SCRIPT, "AIScript", "AI");
82  //this add AI categories inside to DiagMenu
83  RegisterDbgCategory();
84 
85  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SET_BT_BREAKPOINT, "", "Set BT Breakpoint", "AIScript");
86  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_PRINT_DEBUG,"","Print debug from BTs","AIScript");
87  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_PRINT_GROUP_INFO,"","Print init of groups","AIScript");
88  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_FIRETEAMS, "", "Show fireteams", "AIScript");
89  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_TARGET_CLUSTERS, "", "Show target clusters", "AIScript");
90  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_PRINT_SHOT_STATISTICS,"","Print stats for aiming","AIScript");
91  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_PRINT_ACTIVITY,"","Print new activity","AIScript");
92  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_DEBUG_SHAPES,"","Show debug shapes from BTs","AIScript");
93  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_FRIENDLY_IN_AIM,"","Show fiendly in aim","AIScript");
94  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_TARGET_LASTSEEN,"","Show target last seen","AIScript");
95  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SELECT_FIXED_AGENT,"","Select fixed AIAgent","AIScript");
96  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_COVERS,"","Debug cover search","AIScript");
97  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_COMMS_HANDLERS,"", "Show Comms Handlers","AIScript");
98  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_PERCEPTION_PANEL,"","Show perception panel","AIScript");
99  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_SMOKE_COVER_POSITIONS,"","Show smoke cover positions","AIScript");
100 
101 #ifdef AI_DEBUG
102  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SEND_MESSAGE, "", "Show Send Message Menu","AIScript");
103  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AI_PRINT_DEBUG,true);
104  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_AI_PRINT_GROUP_INFO,true);
105 
106  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_TARGET_AIMPOINT,"", "Show target aimpoint", "Aiming");
107  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_TARGET_PROJECTED_SIZE,"", "Show target projected size", "Aiming");
108  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_OPEN_DEBUG_PANEL, "", "Open Debug Panel", "AIScript");
109 
110  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_GRENADE_TRACE, "", "Show Grenade Trace", "AIScript");
111 #endif
112 
113  s_bDiagRegistered = true;
114  }
115 
116  typename type_EMessageType_Goal = EMessageType_Goal;
117  typename type_EMessageType_Info = EMessageType_Info;
118  typename type_EOrderType_Character = EOrderType_Character;
119 
120  m_aGoalMessagesPacked.Resize(type_EMessageType_Goal.GetVariableCount());
121  foreach (SCR_AIMessageGoal message : m_aGoalMessages)
122  {
123  if(message.m_eUIType != EMessageType_Goal.NONE)
124  m_aGoalMessagesPacked[message.m_eUIType] = message;
125  }
126 
127  m_aInfoMessagesPacked.Resize(type_EMessageType_Info.GetVariableCount());
128  foreach (SCR_AIMessageInfo message : m_aInfoMessages)
129  {
130  if(message.m_eUIType != EMessageType_Info.NONE)
131  m_aInfoMessagesPacked[message.m_eUIType] = message;
132  }
133 
134  m_aOrdersPacked.Resize(type_EOrderType_Character.GetVariableCount());
135  foreach (SCR_AIOrderBase order : m_aOrders)
136  {
137  if(order.m_eUIType != EOrderType_Character.NONE)
138  m_aOrdersPacked[order.m_eUIType] = order;
139  }
140 
141  SetLimitOfActiveAIs(m_iActiveAILimit);
142 
143 #ifdef AI_DEBUG
146 #endif
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  override void OnDebugAgentTeleport(AIAgent agent)
151  {
152  PrintFormat("Focused AI agent: %1", agent);
153 
154  IEntity agentEntity = agent.GetControlledEntity();
155  if (!agentEntity) return;
156 
158  if (editorCameraManager)
159  {
160  SCR_ManualCamera editorCamera = editorCameraManager.GetCamera();
161  if (editorCamera)
162  {
164  if (teleportComponent)
165  {
166  teleportComponent.TeleportCamera(agentEntity.GetWorldTransformAxis(3));
167  }
168  }
169  }
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  override void AddedAIAgent(AIAgent agent)
174  {
175  s_OnAgentSpawned.Invoke(agent);
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  override void RemovingAIAgent(AIAgent agent)
180  {
181  s_OnAgentRemoved.Invoke(agent);
182  }
183 
184  //----------Used for translating enum to message type, confirugable in editor---------------------
185  typename GetGoalMessageOfType(EMessageType_Goal eventType)
186  {
187  return m_aGoalMessagesPacked[eventType].Type();
188  }
189 
190  typename GetInfoMessageOfType(EMessageType_Info eventType)
191  {
192  return m_aInfoMessagesPacked[eventType].Type();
193  }
194 
195  typename GetOrderMessageOfType(EOrderType_Character eventType)
196  {
197  return m_aOrdersPacked[eventType].Type();
198  }
199 
204  void RequestNavmeshRebuildAreas(notnull array<ref Tuple2<vector, vector>> areas, notnull array<bool> redoRoads)
205  {
206 #ifdef DEBUG_NAVMESH_REBUILD_AREAS
207  vector points[19];
208  m_DebugNavmeshRebuildAreas.Clear();
209 #endif
210  int i = 0;
211  foreach (Tuple2<vector, vector> area: areas)
212  {
213  RequestNavmeshRebuild(area.param1, area.param2, redoRoads[i]);
214 #ifdef DEBUG_NAVMESH_REBUILD_AREAS
215  SCR_Shape.GetBoundsPoints(area.param1, area.param2, points);
216  m_DebugNavmeshRebuildAreas.Insert(Shape.CreateLines(Color.BLUE, ShapeFlags.NOZBUFFER, points, 19));
217 #endif
218  ++i;
219  }
220  }
225  void RequestNavmeshRebuildEntity(IEntity entity)
226  {
227  array<ref Tuple2<vector, vector>> areas = new array<ref Tuple2<vector, vector>>; //--- Min, max
228  array<bool> redoRoads = new array<bool>;
229  GetNavmeshRebuildAreas(entity, areas, redoRoads);
230  RequestNavmeshRebuildAreas(areas, redoRoads);
231  }
236  void GetNavmeshRebuildAreas(IEntity entity, out notnull array<ref Tuple2<vector, vector>> outAreas, out notnull array<bool> redoRoads)
237  {
238  //--- No entity, no rebuild needed
239  if (!entity)
240  return;
241 
242  //--- Skip entities without physics and mesh (but process their children; e.g., compositions)
243  if (entity.GetVObject() && entity.GetPhysics())
244  {
245  //--- Skip objects not marked for update (ignore their children as well; e.g., soldiers or vehicles)
246  if (!(entity.GetPhysics().GetInteractionLayer() & (EPhysicsLayerDefs.Navmesh | EPhysicsLayerDefs.NavmeshVehicle)))
247  return;
248 
249  //--- Get single entity mesh bounds
250  vector boundMin, boundMax;
251  entity.GetWorldBounds(boundMin, boundMax);
252 
253  //--- Find the closest bounds
254  bool found = false;
255  foreach (Tuple2<vector, vector> area: outAreas)
256  {
257  if (vector.DistanceSqXZ(GetAreaCenter(boundMin, boundMax), GetAreaCenter(area.param1, area.param2)) < MAX_NAVMESH_REBUILD_SIZE)
258  {
259  area.param1 = SCR_Math3D.Min(area.param1, boundMin);
260  area.param2 = SCR_Math3D.Max(area.param2, boundMax);
261  found = true;
262  }
263  }
264 
265  //--- No suitable bounds found, create new ones
266  if (!found)
267  {
268  outAreas.Insert(new Tuple2<vector, vector>(boundMin, boundMax));
269 
270  //Check if the entity has a navlink and it has a link that applies to vehicles
271  NavmeshCustomLinkComponent hasNavlink = NavmeshCustomLinkComponent.Cast(entity.FindComponent(NavmeshCustomLinkComponent));
272  bool value = false;
273  if (hasNavlink)
274  value = hasNavlink.HasLinkOfNavmeshType("BTRlike");
275  redoRoads.Insert(!value);
276  }
277  }
278  //--- Process children
279  IEntity child = entity.GetChildren();
280  while (child)
281  {
282  GetNavmeshRebuildAreas(child, outAreas, redoRoads);
283  child = child.GetSibling();
284  }
285  }
286  protected vector GetAreaCenter(vector min, vector max)
287  {
288  return min + (max - min) / 2;
289  }
290 };
SCR_AIOrderBase
Definition: SCR_AIOrder.c:14
SCR_AIDebugVisualization
Definition: SCR_AIDebugVisualization.c:9
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
LAST
@ LAST
Definition: SCR_AIWorld.c:20
ORDER
@ ORDER
Definition: SCR_AIWorld.c:18
SCR_AISendMessageDebugUI
Definition: SCR_AISendMessageDebugUI.c:10
EOrderType_Character
EOrderType_Character
Definition: SCR_AIOrder.c:1
SCR_CameraEditorComponent
Definition: SCR_CameraEditorComponent.c:13
EMessageType_Info
EMessageType_Info
Definition: SCR_AIMessage.c:1
SCR_AIWorldClass
Definition: SCR_AIWorld.c:7
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_AIMessageGoal
Definition: SCR_AIMessage.c:69
SCR_Math3D
Contains various scripted 3D math functions.
Definition: SCR_Math3D.c:2
THREAT
@ THREAT
Definition: SCR_AIWorld.c:16
SCR_AIWorld
Definition: SCR_AIWorld.c:23
EAIDebugCategory
EAIDebugCategory
Definition: SCR_AIWorld.c:11
Attribute
typedef Attribute
Post-process effect of scripted camera.
NULL
PauseMenuUI NULL
NONE
@ NONE
Definition: SCR_AIWorld.c:13
ScriptInvoker_AIWorldControlModeChangedMethod
func ScriptInvoker_AIWorldControlModeChangedMethod
Definition: SCR_AIWorld.c:2
SCR_Shape
Definition: SCR_Shape.c:1
ScriptInvoker_AIWorldControlModeChanged
ScriptInvokerBase< ScriptInvoker_AIWorldControlModeChangedMethod > ScriptInvoker_AIWorldControlModeChanged
Definition: SCR_AIWorld.c:3
EMessageType_Goal
EMessageType_Goal
Definition: SCR_AIMessage.c:15
BEHAVIOR
@ BEHAVIOR
Definition: SCR_AIWorld.c:14
SCR_AIMessageInfo
Definition: SCR_AIMessage.c:95
SCR_TeleportToCursorManualCameraComponent
Teleport the camera to the cursor's world position.
Definition: SCR_TeleportToCursorManualCameraComponent.c:5
DANGER
@ DANGER
Definition: SCR_AIWorld.c:15
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
COMBAT
@ COMBAT
Definition: SCR_AIWorld.c:19
INFO
@ INFO
Definition: SCR_AIWorld.c:17