25 static const float MAX_NAVMESH_REBUILD_SIZE = 100 * 100;
27 static ref ScriptInvoker s_OnAgentSpawned =
new ScriptInvoker();
28 static ref ScriptInvoker s_OnAgentRemoved =
new ScriptInvoker();
29 static bool s_bDiagRegistered;
32 ref array<ref SCR_AIMessageGoal> m_aGoalMessages;
33 ref array<ref SCR_AIMessageGoal> m_aGoalMessagesPacked =
new array<ref SCR_AIMessageGoal>();
36 ref array<ref SCR_AIMessageInfo> m_aInfoMessages;
37 ref array<ref SCR_AIMessageInfo> m_aInfoMessagesPacked =
new array<ref SCR_AIMessageInfo>();
40 ref array<ref SCR_AIOrderBase> m_aOrders;
41 ref array<ref SCR_AIOrderBase> m_aOrdersPacked =
new array<ref SCR_AIOrderBase>();
45 #ifdef DEBUG_NAVMESH_REBUILD_AREAS
46 protected ref array<ref Shape> m_DebugNavmeshRebuildAreas =
new array<ref Shape>;
48 [
Attribute(
"200", UIWidgets.EditBox,
"Amount of AIs that can be in simulation",
"0 1000 1",
NULL,
"AILimits")]
49 protected int m_iActiveAILimit;
58 return m_OnControlModeChanged;
61 protected void RegisterDbgCategory()
70 DiagMenu.RegisterItem(
SCR_DebugMenuID.DEBUGUI_AI_DEBUG_CATEGORY,
"",
"AI Debug Category",
"AIScript", categories);
77 override void EOnInit (IEntity owner)
79 if (!s_bDiagRegistered)
81 DiagMenu.RegisterMenu(
SCR_DebugMenuID.DEBUGUI_AI_SCRIPT,
"AIScript",
"AI");
83 RegisterDbgCategory();
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");
102 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_AI_SEND_MESSAGE,
"",
"Show Send Message Menu",
"AIScript");
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");
110 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_AI_SHOW_GRENADE_TRACE,
"",
"Show Grenade Trace",
"AIScript");
113 s_bDiagRegistered =
true;
120 m_aGoalMessagesPacked.Resize(type_EMessageType_Goal.GetVariableCount());
124 m_aGoalMessagesPacked[message.m_eUIType] = message;
127 m_aInfoMessagesPacked.Resize(type_EMessageType_Info.GetVariableCount());
131 m_aInfoMessagesPacked[message.m_eUIType] = message;
134 m_aOrdersPacked.Resize(type_EOrderType_Character.GetVariableCount());
138 m_aOrdersPacked[order.m_eUIType] = order;
141 SetLimitOfActiveAIs(m_iActiveAILimit);
150 override void OnDebugAgentTeleport(AIAgent agent)
152 PrintFormat(
"Focused AI agent: %1", agent);
154 IEntity agentEntity = agent.GetControlledEntity();
155 if (!agentEntity)
return;
158 if (editorCameraManager)
164 if (teleportComponent)
166 teleportComponent.TeleportCamera(agentEntity.GetWorldTransformAxis(3));
173 override void AddedAIAgent(AIAgent agent)
175 s_OnAgentSpawned.Invoke(agent);
179 override void RemovingAIAgent(AIAgent agent)
181 s_OnAgentRemoved.Invoke(agent);
187 return m_aGoalMessagesPacked[eventType].Type();
192 return m_aInfoMessagesPacked[eventType].Type();
197 return m_aOrdersPacked[eventType].Type();
204 void RequestNavmeshRebuildAreas(notnull array<ref Tuple2<vector, vector>> areas, notnull array<bool> redoRoads)
206 #ifdef DEBUG_NAVMESH_REBUILD_AREAS
208 m_DebugNavmeshRebuildAreas.Clear();
211 foreach (Tuple2<vector, vector> area: areas)
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));
225 void RequestNavmeshRebuildEntity(IEntity entity)
227 array<ref Tuple2<vector, vector>> areas =
new array<ref Tuple2<vector, vector>>;
228 array<bool> redoRoads =
new array<bool>;
229 GetNavmeshRebuildAreas(entity, areas, redoRoads);
230 RequestNavmeshRebuildAreas(areas, redoRoads);
236 void GetNavmeshRebuildAreas(IEntity entity, out notnull array<ref Tuple2<vector, vector>> outAreas, out notnull array<bool> redoRoads)
243 if (entity.GetVObject() && entity.GetPhysics())
246 if (!(entity.GetPhysics().GetInteractionLayer() & (EPhysicsLayerDefs.Navmesh | EPhysicsLayerDefs.NavmeshVehicle)))
250 vector boundMin, boundMax;
251 entity.GetWorldBounds(boundMin, boundMax);
255 foreach (Tuple2<vector, vector> area: outAreas)
257 if (vector.DistanceSqXZ(GetAreaCenter(boundMin, boundMax), GetAreaCenter(area.param1, area.param2)) < MAX_NAVMESH_REBUILD_SIZE)
259 area.param1 =
SCR_Math3D.Min(area.param1, boundMin);
260 area.param2 =
SCR_Math3D.Max(area.param2, boundMax);
268 outAreas.Insert(
new Tuple2<vector, vector>(boundMin, boundMax));
271 NavmeshCustomLinkComponent hasNavlink = NavmeshCustomLinkComponent.Cast(entity.FindComponent(NavmeshCustomLinkComponent));
274 value = hasNavlink.HasLinkOfNavmeshType(
"BTRlike");
275 redoRoads.Insert(!value);
279 IEntity child = entity.GetChildren();
282 GetNavmeshRebuildAreas(child, outAreas, redoRoads);
283 child = child.GetSibling();
286 protected vector GetAreaCenter(vector min, vector max)
288 return min + (max - min) / 2;