Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AnalyticsDataCollectionTransferSuppliesModule.c
Go to the documentation of this file.
9
11{
15 string m_sToType;
17 string m_sToPosition
19 string m_sFaction;
20 float m_fValue;
21
22 // constructor
29 void SCR_TransferSuppliesInteraction(ResourceName from, ResourceName to, string fromType, string toType, float value, string fromPos, string toPos, string playerId, string faction)
30 {
31 m_sFromPrefab = from;
32 m_sToPrefab = to;
33 m_sFromType = fromType;
34 m_sToType = toType;
35 m_sFromPosition = fromPos;
36 m_sToPosition = toPos;
37 m_sPlayerId = playerId;
38 m_fValue = value;
39 m_sFaction = faction;
40 }
41}
42
45{
46 protected ref array<ref SCR_TransferSuppliesInteraction> m_Interactions = new array<ref SCR_TransferSuppliesInteraction>();
47 protected static const string BASE = "BASE";
48 // SessionMeasures fires every 900 s; cap prevents unbounded growth between flushes
49 protected static const int MAX_INTERACTIONS = 2000;
50
51 //------------------------------------------------------------------------------------------------
52 protected override void Enable()
53 {
55 SCR_SuppliesTransferWaypointState.GetOnAITransferedSupplies().Insert(OnTransferSuppliesByAI);
56 super.Enable();
57 }
58
59 //------------------------------------------------------------------------------------------------
60 protected override void Disable()
61 {
63 SCR_SuppliesTransferWaypointState.GetOnAITransferedSupplies().Remove(OnTransferSuppliesByAI);
64 super.Disable();
65 }
66
67 //------------------------------------------------------------------------------------------------
68 protected override void OnGameModeEnd()
69 {
70 // Game ends and so we need to record the latest data which will be send alongside missionEnd event
72 }
73
74 //------------------------------------------------------------------------------------------------
77 protected string GetTypeFromResourceComponent(SCR_ResourceComponent resourceComponent)
78 {
79 IEntity parent = resourceComponent.GetOwner().GetRootParent();
80
81 // Check first by Entity type
82 if (ChimeraCharacter.Cast(parent))
83 return typename.EnumToString(SCR_EAnalyticalStorageType, SCR_EAnalyticalStorageType.CHARACTER);
84
85 Vehicle vehicle = Vehicle.Cast(parent);
86 if (!vehicle)
87 {
88 // Once the other entities are discarded, check if the component comes from a base or is orphan
89 // True means it is a BASE
90 if(DistinguishOrphanAndBase(resourceComponent, parent))
91 return typename.EnumToString(SCR_EAnalyticalStorageType, SCR_EAnalyticalStorageType.BASE);
92
93 return typename.EnumToString(SCR_EAnalyticalStorageType, SCR_EAnalyticalStorageType.ORPHAN);
94 }
95
96 if (SCR_HelicopterControllerComponent.Cast(vehicle.GetVehicleController()))
97 return typename.EnumToString(SCR_EAnalyticalStorageType, SCR_EAnalyticalStorageType.HELICOPTER);
98
99 return typename.EnumToString(EVehicleType, vehicle.m_eVehicleType);
100 }
101
102 //------------------------------------------------------------------------------------------------
106 protected bool DistinguishOrphanAndBase(SCR_ResourceComponent resourceComponent, IEntity parent)
107 {
108 SCR_ResourceContainer containerToCheck = resourceComponent.GetContainer(EResourceType.SUPPLIES);
109 bool areContainersOrphans = containerToCheck && containerToCheck.GetStorageType() == EResourceContainerStorageType.ORPHAN;
110 bool missingInventoryComponent = !parent || (parent && !parent.FindComponent(InventoryItemComponent));
111
112 if (areContainersOrphans || missingInventoryComponent)
113 return false; // It is an ORPHAN
114
115 return true; // It is a BASE
116 }
117
118 //------------------------------------------------------------------------------------------------
125 string GetDestinationPosition(string type, SCR_ResourceComponent resource, PlayerController playerController, SCR_AIGroupUtilityComponent utility)
126 {
127 string ownerPos = resource.GetOwner().GetOrigin().ToString();
128 IEntity resourceOwner = resource.GetOwner();
129 if (!resourceOwner)
130 return ownerPos;
131
132 if (type != BASE)
133 {
134 if (!playerController)
135 return utility.GetAIAgent().GetOrigin().ToString();
136
137 PlayerId transferingPlayerId = playerController.GetPlayerId();
138
139 IEntity playerEntity = SCR_PossessingManagerComponent.GetPlayerMainEntity(transferingPlayerId);
140 if (playerEntity)
141 return playerEntity.GetOrigin().ToString();
142 }
143
145 if (!GetMilitaryBase(resourceOwner, base))
146 return ownerPos;
147
148 if (!base.GetOwner())
149 return ownerPos;
150
151 return base.GetOwner().GetOrigin().ToString();
152 }
153
154 //------------------------------------------------------------------------------------------------
160 {
161 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
162 if (!campaign)
163 return false;
164
165 SCR_CampaignMilitaryBaseManager manager = campaign.GetBaseManager();
166 if (!manager)
167 return false;
168
170 if (!base)
171 return false;
172
173 outBase = base;
174 return true;
175 }
176
177 //------------------------------------------------------------------------------------------------
180 string GetTransferingPlayerFaction(PlayerController playerController)
181 {
182 IEntity controlledEntity = playerController.GetControlledEntity();
183 if (!controlledEntity)
184 return "";
185
186 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(controlledEntity.FindComponent(FactionAffiliationComponent));
187 if (factionAffiliation)
188 return factionAffiliation.GetAffiliatedFaction().GetFactionKey();
189 else
190 return "";
191 }
192
193 //------------------------------------------------------------------------------------------------
197 {
198 SCR_AIGroup aiGroup = utility.m_Owner;
199 if (!aiGroup)
200 return "";
201
202 return aiGroup.GetFaction().GetFactionKey();
203 }
204
205 //------------------------------------------------------------------------------------------------
208 string GetCharacterUniqueId(notnull PlayerController playerController)
209 {
210 PlayerId playerid = playerController.GetPlayerId();
211
212 return SCR_PlayerIdentityUtils.GetPlayerIdentityId(playerid);
213 }
214
215 //------------------------------------------------------------------------------------------------
216 protected ResourceName GetPrefabName(SCR_ResourceComponent resourceComponent)
217 {
218 return resourceComponent.GetOwner().GetRootParent().GetPrefabData().GetPrefabName();
219 }
220
221 //------------------------------------------------------------------------------------------------
223 {
224 AIGroup group = AIGroup.Cast(utility.GetAIAgent());
225 if (!group)
226 return "";
227
228 AIAgent leaderAgent = group.GetLeaderAgent();
229 if (!leaderAgent)
230 return "";
231
232 ChimeraCharacter character = ChimeraCharacter.Cast(leaderAgent.GetControlledEntity());
233 if (!character)
234 return "";
235
236 CompartmentAccessComponent compartment = character.GetCompartmentAccessComponent();
237 if (!compartment)
238 return "";
239
240 return compartment.GetVehicleIn(character).GetPrefabData().GetPrefabName();
241 }
242
243 //------------------------------------------------------------------------------------------------
244 protected ResourceName SetPrefabName(bool isPlayer, string resourceType, SCR_ResourceComponent resourceComponent, SCR_AIGroupUtilityComponent utility)
245 {
246 if(!isPlayer && resourceType == "SUPPLY_TRUCK")
247 return GetPrefabNameFromAITruck(utility);
248 else
249 return GetPrefabName(resourceComponent);
250 }
251
252 //------------------------------------------------------------------------------------------------
253 protected void OnTransferSuppliesByPlayer(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, PlayerController playerController)
254 {
255 OnTransferSupplies(interactionType, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue, playerController, null);
256 }
257
258 //------------------------------------------------------------------------------------------------
259 protected void OnTransferSuppliesByAI(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, SCR_AIGroupUtilityComponent utility)
260 {
261 OnTransferSupplies(interactionType, resourceComponentFrom, resourceComponentTo, resourceType, resourceValue, null, utility);
262 }
263
264 //------------------------------------------------------------------------------------------------
265 protected void OnTransferSupplies(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, PlayerController playerController, SCR_AIGroupUtilityComponent utility)
266 {
267 if (resourceValue <= 0)
268 return;
269
270 if (m_Interactions.Count() >= MAX_INTERACTIONS)
271 {
272 Print("SCR_AnalyticsDataCollectionTransferSuppliesModule: interaction cap reached, dropping entry", LogLevel.WARNING);
273 return;
274 }
275
276 bool isPlayer = playerController;
277
278 ResourceName fromPrefab;
279 string fromType;
280 string fromPos;
281 if (interactionType == EResourcePlayerInteractionType.VEHICLE_LOAD)
282 {
283 fromPrefab = "-";
284 fromType = BASE;
285 fromPos = GetMilitaryBasePosition(resourceComponentTo);
286 }
287 else
288 {
289 fromType = GetPrefabType(resourceComponentFrom, isPlayer);
290 fromPos = GetDestinationPosition(fromType, resourceComponentFrom, playerController, utility);
291 fromPrefab = SetPrefabName(isPlayer, fromType, resourceComponentFrom, utility);
292 }
293
294 ResourceName toPrefab;
295 string toType;
296 string toPos;
297 if (interactionType == EResourcePlayerInteractionType.VEHICLE_UNLOAD)
298 {
299 toPrefab = "-";
300 toType = BASE;
301 toPos = GetMilitaryBasePosition(resourceComponentFrom);
302 }
303 else
304 {
305 toType = GetPrefabType(resourceComponentTo, isPlayer);
306 toPos = GetDestinationPosition(toType, resourceComponentTo, playerController, utility);
307 toPrefab = SetPrefabName(isPlayer, toType, resourceComponentTo, utility);
308 }
309
310 string tranferFactionName;
311 if (isPlayer)
312 tranferFactionName = GetTransferingPlayerFaction(playerController);
313 else
314 tranferFactionName = GetTransferingAIFaction(utility);
315
316 string characterName;
317 if (isPlayer)
318 characterName = GetCharacterUniqueId(playerController);
319 else
320 characterName = "AI";
321
322 PrintFormat("SCR_AnalyticsDataCollectionTransferSuppliesModule: Transferring %1 supplies from %2 (%3) to %4 (%5) \n Faction is: %6 , and it is moved from %7 to %8", resourceValue, fromPrefab, fromType, toPrefab, toType, tranferFactionName, fromPos, toPos, level: LogLevel.DEBUG);
323 m_Interactions.Insert(new SCR_TransferSuppliesInteraction(fromPrefab, toPrefab, fromType, toType, resourceValue, fromPos, toPos, characterName, tranferFactionName));
324 }
325
326 //------------------------------------------------------------------------------------------------
327 protected string GetPrefabType(SCR_ResourceComponent resourceComponent, bool isPlayer)
328 {
329 string type = GetTypeFromResourceComponent(resourceComponent);
330
331 if (!isPlayer && type != BASE)
332 type = "SUPPLY_TRUCK";
333
334 return type;
335 }
336
337 //------------------------------------------------------------------------------------------------
338 protected string GetMilitaryBasePosition(SCR_ResourceComponent resourceComponent)
339 {
340 string position;
342
343 if (GetMilitaryBase(resourceComponent.GetOwner(), base))
344 position = base.GetOwner().GetOrigin().ToString();
345
346 return position;
347 }
348
349 //------------------------------------------------------------------------------------------------
350 override void SessionMeasures()
351 {
352 if (!m_bIsEnabled)
353 return;
354
355 SCR_SessionDataEvent sessionDataEvent = GetSessionDataEvent();
356 if (!sessionDataEvent)
357 return;
358
359 sessionDataEvent.array_supplies_from_prefab = "[";
360 sessionDataEvent.array_supplies_to_prefab = "[";
361 sessionDataEvent.array_supplies_from_type = "[";
362 sessionDataEvent.array_supplies_to_type = "[";
363 sessionDataEvent.array_supplies_values = "[";
364 sessionDataEvent.array_supplies_by_player = "[";
365 sessionDataEvent.array_supplies_from_pos = "[";
366 sessionDataEvent.array_supplies_to_pos = "[";
367 sessionDataEvent.array_supplies_faction = "[";
368
369 foreach (int i, SCR_TransferSuppliesInteraction interaction : m_Interactions)
370 {
371 if (i != 0)
372 {
373 sessionDataEvent.array_supplies_from_prefab += ",";
374 sessionDataEvent.array_supplies_to_prefab += ",";
375 sessionDataEvent.array_supplies_from_type += ",";
376 sessionDataEvent.array_supplies_to_type += ",";
377 sessionDataEvent.array_supplies_values += ",";
378 sessionDataEvent.array_supplies_by_player += ",";
379 sessionDataEvent.array_supplies_from_pos += ",";
380 sessionDataEvent.array_supplies_to_pos += ",";
381 sessionDataEvent.array_supplies_faction += ",";
382 }
383
384 sessionDataEvent.array_supplies_from_prefab += "\"" + interaction.m_sFromPrefab + "\"";
385 sessionDataEvent.array_supplies_to_prefab += "\"" + interaction.m_sToPrefab + "\"";
386 sessionDataEvent.array_supplies_from_type += "\"" + interaction.m_sFromType + "\"";
387 sessionDataEvent.array_supplies_to_type += "\"" + interaction.m_sToType + "\"";
388 sessionDataEvent.array_supplies_values += "\"" + interaction.m_fValue.ToString() + "\"";
389 sessionDataEvent.array_supplies_by_player += "\"" + interaction.m_sPlayerId + "\"";
390 sessionDataEvent.array_supplies_from_pos += "\"" + interaction.m_sFromPosition + "\"";
391 sessionDataEvent.array_supplies_to_pos += "\"" + interaction.m_sToPosition + "\"";
392 sessionDataEvent.array_supplies_faction += "\"" + interaction.m_sFaction + "\"";
393 }
394
395 sessionDataEvent.array_supplies_from_prefab += "]";
396 sessionDataEvent.array_supplies_to_prefab += "]";
397 sessionDataEvent.array_supplies_from_type += "]";
398 sessionDataEvent.array_supplies_to_type += "]";
399 sessionDataEvent.array_supplies_values += "]";
400 sessionDataEvent.array_supplies_by_player += "]";
401 sessionDataEvent.array_supplies_from_pos += "]";
402 sessionDataEvent.array_supplies_to_pos += "]";
403 sessionDataEvent.array_supplies_faction += "]";
404
405 m_Interactions.Clear();
406 }
407}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
enum SCR_EAICombatMoveRequestType CHARACTER
void SCR_TransferSuppliesInteraction(ResourceName from, ResourceName to, string fromType, string toType, float value, string fromPos, string toPos, string playerId, string faction)
string m_sToPosition string m_sPlayerId
enum SCR_EAnalyticalStorageType m_sFromPrefab
SCR_CampaignMilitaryBaseComponent GetMilitaryBase()
EDamageType type
vector position
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
EResourceContainerStorageType
EVehicleType
Definition Vehicle.c:4
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external IEntity GetRootParent()
Faction GetFaction()
bool DistinguishOrphanAndBase(SCR_ResourceComponent resourceComponent, IEntity parent)
ResourceName SetPrefabName(bool isPlayer, string resourceType, SCR_ResourceComponent resourceComponent, SCR_AIGroupUtilityComponent utility)
void OnTransferSupplies(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, PlayerController playerController, SCR_AIGroupUtilityComponent utility)
string GetDestinationPosition(string type, SCR_ResourceComponent resource, PlayerController playerController, SCR_AIGroupUtilityComponent utility)
void OnTransferSuppliesByAI(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, SCR_AIGroupUtilityComponent utility)
void OnTransferSuppliesByPlayer(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, PlayerController playerController)
string GetPrefabType(SCR_ResourceComponent resourceComponent, bool isPlayer)
bool GetMilitaryBase(IEntity resourceOwner, out SCR_CampaignMilitaryBaseComponent outBase)
SCR_CampaignMilitaryBaseComponent FindClosestBase(vector position, SCR_ECampaignBaseType searchedType=-1)
Takes care of Campaign-specific server <> client communication and requests.
static ScriptInvokerTransferSupplies GetOnTransferSupplies()
EResourceContainerStorageType GetStorageType()
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)