Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AISearchAndDestroyActivity.c
Go to the documentation of this file.
2{
3 protected ref SCR_BTParamAssignable<vector> m_vPosition = new SCR_BTParamAssignable<vector>(SCR_AIActionTask.POSITION_PORT);
4 protected ref SCR_BTParam<IEntity> m_Entity = new SCR_BTParam<IEntity>(SCR_AIActionTask.ENTITY_PORT);
5
7 protected const float m_fBehaviorRadius = 3;
8
10 protected AIPathfindingComponent m_pathFindindingComp;
12 protected ref array<vector> m_aTiles = {};
13 protected bool m_bAllTilesLoaded;
14
15 protected ref array<vector> m_aCorrectedPositions = {};
16 protected ref array<vector> m_aAvailablePositions = {};
17 protected ref array<vector> m_aAssignedPositions = {};
18
19 protected float m_fHoldingTime = 600.0;
20 protected float m_fStartTime;
21 protected float m_fTimeStamp;
22
23#ifdef WORKBENCH
24 protected ref array<ref Shape> m_aDbgShape = {};
25#endif
26
27 //------------------------------------------------------------------------------------------------
29 {
30 m_vPosition.Init(this, position);
31 m_vPosition.m_AssignedOut = (position != vector.Zero);
32 m_Entity.Init(this, entity);
33 }
34
35 //------------------------------------------------------------------------------------------------
36 void SCR_AISearchAndDestroyActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector pos, IEntity ent, EMovementType movementType = EMovementType.RUN, bool useVehicles = false, float priority = PRIORITY_ACTIVITY_SEEK_AND_DESTROY, float priorityLevel = PRIORITY_LEVEL_NORMAL)
37 {
38 InitParameters(pos, ent);
39 SetPriority(priority);
40
41 m_Group = SCR_AIGroup.Cast(m_Utility.GetAIAgent());
42 if (!m_Group)
43 return;
44 m_pathFindindingComp = AIPathfindingComponent.Cast(m_Group.FindComponent(AIPathfindingComponent));
45 m_vGridOrigin = pos;
46
47 AIWaypoint wp = relatedWaypoint;
48 if (wp)
50
51 m_fStartTime = GetGame().GetWorld().GetWorldTime();
52 if (m_WP)
53 m_fHoldingTime = m_WP.GetHoldingTime();
55 }
56
57 //------------------------------------------------------------------------------------------------
58 override void OnActionSelected()
59 {
60 super.OnActionSelected();
62
63 if (m_WP)
64 m_WP.GetOnWaypointPropertiesChanged().Insert(OnWaypointPropertiesChanged);
65 }
66
67 //------------------------------------------------------------------------------------------------
68 override float CustomEvaluate()
69 {
70 float currentTime = GetGame().GetWorld().GetWorldTime();
71
72 if (GetActionState() == EAIActionState.RUNNING)
73 {
74 // check every 2s if all tiles are loaded and proceed w/ activity
75 if (!m_bAllTilesLoaded && currentTime - m_fTimeStamp > 2)
76 {
77 if (LoadTiles())
78 {
80
81 // assign first available position to all fireteams
82 ref array<SCR_AIGroupFireteam> fireTeams = {};
83 m_Utility.m_FireteamMgr.GetFreeFireteams(fireTeams, SCR_AIGroupFireteam);
84
85 foreach (SCR_AIGroupFireteam ft : fireTeams)
87
88 m_bAllTilesLoaded = true;
89 }
90
91 m_fTimeStamp = currentTime;
92 }
93 }
94
95 return GetPriority();
96 }
97
98 //------------------------------------------------------------------------------------------------
99 // on investigation finished, assign another investigation position
100 override void OnChildBehaviorFinished(SCR_AIBehaviorBase childBehavior)
101 {
102
104 if (!childBehavior || !behavior)
105 return;
106 if (m_aAssignedPositions.Contains(behavior.m_vPosition.m_Value) < 0)
107 return;
108
109 m_aAssignedPositions.RemoveItem(behavior.m_vPosition.m_Value);
110
111 AIAgent agent = childBehavior.m_Utility.GetOwner();
112 if (!agent)
113 return;
114 SCR_AIGroupFireteam ft = m_Utility.m_FireteamMgr.FindFireteam(agent);
115 if (!ft)
116 return;
117
118 if (behavior.GetActionState() != EAIActionState.FAILED)
120
121 // Fail behavior when WP holding time is up
122 if (m_WP)
123 {
124 float currentTime = GetGame().GetWorld().GetWorldTime();
125 if (currentTime - m_fStartTime > m_fHoldingTime)
126 behavior.Fail();
127 }
128 }
129
130 //------------------------------------------------------------------------------------------------
132 {
133 float actionRadius = 20.0;
134 float tileSize;
135 vector tileCenterPos;
136 vector XOffset;
137 vector XZOffset;
138
139 m_aTiles.Clear();
140
141 if (m_WP)
142 {
143 actionRadius = m_WP.GetCompletionRadius();
144 m_vGridOrigin = m_WP.GetOrigin() + Vector(-actionRadius, 0, -actionRadius);
145 }
146
147 // get fireteam x tile ratio
148 int fireteamCount = m_Utility.m_FireteamMgr.GetFireteamCount();
149 if (fireteamCount == 0)
150 return;
151 const int maxFireteam = 8;
152 float fireteamTileRatio = (maxFireteam - fireteamCount) / 10;
153
154 tileSize = Math.Clamp(fireteamTileRatio * actionRadius, 5, 20);
155 vector addedTileSize = Vector(tileSize, tileSize, tileSize);
156
157 int tileCount = (actionRadius * 2) / tileSize;
158
159 for (int x = 0; x < tileCount; x++)
160 {
161 for (int z = 0; z < tileCount; z++)
162 {
163 // calculate tile vector of its X and XZ
164 vector vectorX = Vector(x * tileSize, 0, z * tileSize);
165 vector vectorXZ = vectorX + addedTileSize;
166 // add offset of WP origin
167 XOffset = vectorX + m_vGridOrigin;
168 XZOffset = vectorXZ + m_vGridOrigin;
169 // get center position
170 tileCenterPos = XZOffset / 2 + XOffset / 2;
171 m_aTiles.Insert(tileCenterPos);
172
173#ifdef WORKBENCH
174 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_SEARCH_AND_DESTROY))
175 {
176 m_aDbgShape.Insert(Shape.Create(ShapeType.BBOX, Color.DARK_CYAN, ShapeFlags.WIREFRAME, XOffset, XZOffset));
177 }
178#endif
179 }
180 }
181 }
182
183 //-----------------------------------------------------------------------------------------------------
184 // are grid tiles loaded?
185 protected bool LoadTiles()
186 {
187 bool allTilesLoaded = true;
188
190 return false;
191 NavmeshWorldComponent navmesh = m_pathFindindingComp.GetNavmeshComponent();
192 if (!navmesh)
193 return false;
194
195 foreach (vector tile : m_aTiles)
196 {
197 if (!navmesh.IsTileLoaded(tile))
198 {
199 navmesh.LoadTileIn(tile);
200 allTilesLoaded = false;
201 }
202 }
203
204 return allTilesLoaded;
205 }
206
207 //------------------------------------------------------------------------------------------------
208 // adjust investigation positions vis-a-vis navmesh
210 {
211 vector correctedPosition;
212 m_aCorrectedPositions.Clear();
213
214 foreach (vector tile : m_aTiles)
215 {
216 m_pathFindindingComp.GetClosestPositionOnNavmesh(tile, "15 15 15", correctedPosition);
217
218 if (!m_aCorrectedPositions.Contains(correctedPosition))
219 {
220#ifdef WORKBENCH
221 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_SEARCH_AND_DESTROY))
222 {
223 m_aDbgShape.Insert(Shape.CreateSphere(Color.RED, ShapeFlags.NOZWRITE, correctedPosition, 0.5));
224 }
225#endif
226 m_aCorrectedPositions.Insert(correctedPosition);
227 }
228 }
229
231 }
232
233 //------------------------------------------------------------------------------------------------
235 {
236 array<AIAgent> agents = {};
237 ft.GetMembers(agents);
238 foreach (AIAgent ag : agents)
239 {
241 m_Utility.m_Mailbox.RequestBroadcast(msg,ag);
242 }
243
244#ifdef WORKBENCH
245 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_SEARCH_AND_DESTROY))
246 {
247 m_aDbgShape.Insert(Shape.CreateSphere(Color.GREEN, ShapeFlags.NOZWRITE, m_aAvailablePositions[0], 1.5));
248 }
249#endif
250
252 m_aAvailablePositions.Remove(0);
253
254 if (!m_aAvailablePositions.IsIndexValid(0))
255 {
256#ifdef WORKBENCH
257 ClearDebug();
258#endif
260 }
261 }
262
263 //------------------------------------------------------------------------------------------------
265 {
267 m_bAllTilesLoaded = false;
268 }
269
270 //------------------------------------------------------------------------------------------------
271 override void OnActionFailed()
272 {
273 super.OnActionFailed();
275 }
276
277 //------------------------------------------------------------------------------------------------
278 override void OnActionDeselected()
279 {
280 super.OnActionDeselected();
282
283 if (m_WP)
284 m_WP.GetOnWaypointPropertiesChanged().Remove(OnWaypointPropertiesChanged);
285 }
286
287 //------------------------------------------------------------------------------------------------
288 override string GetActionDebugInfo()
289 {
290 return this.ToString() + " seek and destroy around" + m_Entity.m_Value.ToString();
291 }
292
293 //-----------------------------------------------------------------------------------------------
294#ifdef WORKBENCH
295 private void ClearDebug()
296 {
297 m_aDbgShape.Clear();
298 }
299#endif
300};
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
void SendCancelMessagesToAllAgents()
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
vector position
Definition Color.c:13
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Math.c:13
void GetMembers(notnull array< AIAgent > outAgents)
void InitParameters(vector position, IEntity entity)
void SCR_AISearchAndDestroyActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector pos, IEntity ent, EMovementType movementType=EMovementType.RUN, bool useVehicles=false, float priority=PRIORITY_ACTIVITY_SEEK_AND_DESTROY, float priorityLevel=PRIORITY_LEVEL_NORMAL)
override void OnChildBehaviorFinished(SCR_AIBehaviorBase childBehavior)
void AssignInvestigationPositions(SCR_AIGroupFireteam ft)
ref SCR_BTParamAssignable< vector > m_vPosition
Instance of created debug visualizer.
Definition Shape.c:14
EAIActionState
EAIUnitType
Definition EAIUnitType.c:13
EMovementType
ShapeType
Definition ShapeType.c:13
ShapeFlags
Definition ShapeFlags.c:13
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
proto native vector Vector(float x, float y, float z)