Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DataCollectorSupplyTruckDriverModule.c
Go to the documentation of this file.
3 {
4  /* Currently unused
5  protected ref map<int, IEntity> m_mTrackedDrivers = new map<int, IEntity>();
6 
7  //------------------------------------------------------------------------------------------------
8  protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
9  {
10  BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
11  if (!compartment)
12  return;
13 
14  IEntity playerEntity = compartment.GetOccupant();
15  if (!playerEntity)
16  return;
17 
18  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(playerEntity);
19  if (playerID == 0) // Non-player character
20  return;
21 
22  SlotManagerComponent slotManagerComponent = SlotManagerComponent.Cast(targetEntity.FindComponent(SlotManagerComponent));
23  if (!slotManagerComponent)
24  return;
25 
26  array<EntitySlotInfo> infos = {};
27 
28  for (int i = 0, count = slotManagerComponent.GetSlotInfos(infos); i < count; i++)
29  {
30  IEntity attachedEntity = infos[i].GetAttachedEntity();
31  if (!attachedEntity)
32  continue;
33 
34  SCR_CampaignSuppliesComponent suppliesComponent = SCR_CampaignSuppliesComponent.Cast(attachedEntity.FindComponent(SCR_CampaignSuppliesComponent));
35  if (suppliesComponent)
36  {
37  //Player playerID is a driver of a vehicle with supplies
38  m_mTrackedDrivers.Insert(playerID, playerEntity);
39  return;
40  }
41  }
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
46  {
47  BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
48  if (!compartment)
49  return;
50 
51  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(compartment.GetOccupant());
52  if (playerID == 0) // Non-player character
53  return;
54 
55  m_mTrackedDrivers.Remove(playerID);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  protected override void AddInvokers(IEntity player, bool spawned = true)
60  {
61  super.AddInvokers(player, spawned);
62  if (!player)
63  return;
64 
65  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(player.FindComponent(SCR_CompartmentAccessComponent));
66 
67  compartmentAccessComponent.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
68  compartmentAccessComponent.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  protected override void RemoveInvokers(IEntity player)
73  {
74  super.RemoveInvokers(player);
75  if (!player)
76  return;
77 
78  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(player.FindComponent(SCR_CompartmentAccessComponent));
79 
80  if (!compartmentAccessComponent)
81  return;
82 
83  compartmentAccessComponent.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
84  compartmentAccessComponent.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  override void OnPlayerDisconnected(int playerID, IEntity controlledEntity = null)
89  {
90  if (!controlledEntity)
91  controlledEntity = m_mTrackedDrivers.Get(playerID);
92 
93  super.OnPlayerDisconnected(playerID, controlledEntity);
94  m_mTrackedDrivers.Remove(playerID);
95  }
96 
97 #ifdef ENABLE_DIAG
98  //------------------------------------------------------------------------------------------------
99  override void OnControlledEntityChanged(IEntity from, IEntity to)
100  {
101  super.OnControlledEntityChanged(from, to);
102 
103  int playerID;
104  if (from)
105  {
106  playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(from);
107  m_mTrackedDrivers.Remove(playerID);
108  }
109 
110  if (to)
111  {
112  playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(to);
113  m_mTrackedDrivers.Insert(playerID, to);
114  }
115  }
116 #endif
117 
118  //------------------------------------------------------------------------------------------------
119  override void Update(IEntity owner, float timeTick)
120  {
121  //If there's no data collector, do nothing
122  if (!GetGame().GetDataCollector())
123  return;
124 
125  m_fTimeSinceUpdate += timeTick;
126 
127  if (m_fTimeSinceUpdate<m_fTimeToUpdate)
128  return;
129 
130  IEntity playerEntity;
131  IEntity vehicle;
132  Physics physics;
133  float distanceTraveled;
134  int playerId;
135  SCR_PlayerData playerData;
136 
137  for (int i = m_mTrackedDrivers.Count() - 1; i >= 0; i--)
138  {
139  playerEntity = m_mTrackedDrivers.GetElement(i);
140  vehicle = CompartmentAccessComponent.GetVehicleIn(playerEntity);
141  if (!vehicle)
142  continue;
143 
144  physics = vehicle.GetPhysics();
145  if (!physics)
146  continue;
147 
148  distanceTraveled = physics.GetVelocity().Length() * timeTick;
149  playerId = m_mTrackedDrivers.GetKey(i);
150 
151  playerData = GetGame().GetDataCollector().GetPlayerData(playerId);
152  playerData.AddTraveledDistanceSupplyVehicle(distanceTraveled);
153  playerData.AddTraveledTimeSupplyVehicle(timeTick);
154 
155  //DEBUG display
156  if (m_StatsVisualization)
157  {
158  m_StatsVisualization.Get(SCR_ESupplyTruckDriverModuleStats.METERSDRIVENSUPPLYVEHICLE).SetText(playerData.GetCurrentTraveledDistanceSupplyVehicle().ToString());
159  m_StatsVisualization.Get(SCR_ESupplyTruckDriverModuleStats.TIMEDRIVENSUPPLYVEHICLE).SetText(playerData.GetCurrentTraveledTimeSupplyVehicle().ToString());
160  }
161  }
162  m_fTimeSinceUpdate = 0;
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  override void CreateVisualization()
167  {
168  super.CreateVisualization();
169  if (!m_StatsVisualization)
170  return;
171 
172  CreateEntry("Meters driven w Supply Vehicle: ", 0, SCR_ESupplyTruckDriverModuleStats.METERSDRIVENSUPPLYVEHICLE);
173  CreateEntry("Time driving Supply Vehicle: ", 0, SCR_ESupplyTruckDriverModuleStats.TIMEDRIVENSUPPLYVEHICLE);
174  }
175  */
176 };
177 /*
178 enum SCR_ESupplyTruckDriverModuleStats
179 {
180  METERSDRIVENSUPPLYVEHICLE,
181  TIMEDRIVENSUPPLYVEHICLE
182 };
183 */
SCR_DataCollectorSupplyTruckDriverModule
Definition: SCR_DataCollectorSupplyTruckDriverModule.c:2
SCR_DataCollectorModule
Definition: SCR_DataCollectorModule.c:2
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468