Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DataCollectorBasicActionsModule.c
Go to the documentation of this file.
3 {
4  protected ref map<int, IEntity> m_mTrackedPlayers = new map<int, IEntity>();
5  const int LIMIT_WALKING_SPEED_PER_SECOND = 5;
6  protected int m_iMaxWalkingDistancePerSecond = LIMIT_WALKING_SPEED_PER_SECOND * m_fUpdatePeriod;
7 
8  //------------------------------------------------------------------------------------------------
9  protected override void AddInvokers(IEntity player)
10  {
11  super.AddInvokers(player);
12 
13  if (!player)
14  return;
15 
16  SCR_ChimeraCharacter chimeraPlayer = SCR_ChimeraCharacter.Cast(player);
17  if (!chimeraPlayer)
18  return;
19 
20  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(chimeraPlayer.GetCompartmentAccessComponent());
21  if (!compartmentAccessComponent)
22  return;
23 
24  compartmentAccessComponent.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
25  compartmentAccessComponent.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  protected override void RemoveInvokers(IEntity player)
30  {
31  super.RemoveInvokers(player);
32 
33  if (!player)
34  return;
35 
36  SCR_ChimeraCharacter chimeraPlayer = SCR_ChimeraCharacter.Cast(player);
37  if (!chimeraPlayer)
38  return;
39 
40  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(chimeraPlayer.GetCompartmentAccessComponent());
41  if (!compartmentAccessComponent)
42  return;
43 
44  compartmentAccessComponent.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
45  compartmentAccessComponent.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
50  {
51  BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
52  if (!compartment)
53  return;
54 
55  PlayerManager playerManager = GetGame().GetPlayerManager();
56 
57  if (!playerManager)
58  return;
59 
60  int playerID = playerManager.GetPlayerIdFromControlledEntity(compartment.GetOccupant());
61  if (playerID == 0) // Non-player character
62  return;
63 
64  m_mTrackedPlayers.Remove(playerID);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
69  {
70  BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
71  if (!compartment)
72  return;
73 
74  IEntity playerEntity = compartment.GetOccupant();
75 
76  if (!playerEntity)
77  return;
78 
79  PlayerManager playerManager = GetGame().GetPlayerManager();
80 
81  int playerID = playerManager.GetPlayerIdFromControlledEntity(playerEntity);
82  if (playerID == 0) // Non-player character or non-pilot
83  return;
84 
85  m_mTrackedPlayers.Insert(playerID, playerEntity);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void OnPlayerDisconnected(int playerID, IEntity controlledEntity = null)
90  {
91  controlledEntity = m_mTrackedPlayers.Get(playerID);
92  super.OnPlayerDisconnected(playerID, controlledEntity);
93 
94  m_mTrackedPlayers.Remove(playerID);
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  override void OnPlayerSpawned(int playerID, IEntity controlledEntity)
99  {
100  super.OnPlayerSpawned(playerID, controlledEntity);
101  m_mTrackedPlayers.Insert(playerID, controlledEntity);
102  }
103 
104 #ifdef ENABLE_DIAG
105  //------------------------------------------------------------------------------------------------
106  override void OnControlledEntityChanged(IEntity from, IEntity to)
107  {
108  super.OnControlledEntityChanged(from, to);
109 
110  if (to)
111  {
112  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(to);
113  m_mTrackedPlayers.Insert(playerID, to);
114  }
115  else if (from)
116  {
117  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(from);
118  m_mTrackedPlayers.Remove(playerID);
119  }
120  }
121 #endif
122 
123  //------------------------------------------------------------------------------------------------
124  override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
125  {
126  super.OnPlayerKilled(playerId, playerEntity, killerEntity, killer);
127  m_mTrackedPlayers.Remove(playerId);
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  override void Update(float timeTick)
132  {
133  m_fTimeSinceUpdate += timeTick;
134 
135  if (m_fTimeSinceUpdate < m_fUpdatePeriod)
136  return;
137 
138  Physics physics;
139  float distanceTraveled;
140  int playerId;
141  SCR_PlayerData playerData;
142  IEntity currentEntity;
143 
144  for (int i = m_mTrackedPlayers.Count() - 1; i >= 0; i--)
145  {
146  currentEntity = m_mTrackedPlayers.GetElement(i);
147  if (!currentEntity)
148  continue;
149 
150  physics = currentEntity.GetPhysics();
151  if (!physics)
152  continue;
153 
154  playerId = m_mTrackedPlayers.GetKey(i);
155  playerData = GetGame().GetDataCollector().GetPlayerData(playerId);
156 
157  //We take current velocity and assume it was the same for the whole m_fTimeSinceUpdate timeframe
158  distanceTraveled = physics.GetVelocity().Length() * m_fTimeSinceUpdate;
159 
160  //Safety measure
161  if (distanceTraveled > m_iMaxWalkingDistancePerSecond)
162  distanceTraveled = m_iMaxWalkingDistancePerSecond;
163 
164  playerData.AddStat(SCR_EDataStats.DISTANCE_WALKED, distanceTraveled);
165 
166  //DEBUG display
167 
168 #ifdef ENABLE_DIAG
169  if (m_StatsVisualization)
170  m_StatsVisualization.Get(EBasicActionsModuleStats.DistanceWalked).SetText(playerData.GetStat(SCR_EDataStats.DISTANCE_WALKED).ToString());
171 #endif
172  }
173  m_fTimeSinceUpdate = 0;
174  }
175 
176 #ifdef ENABLE_DIAG
177  //------------------------------------------------------------------------------------------------
178  override void CreateVisualization()
179  {
180  super.CreateVisualization();
181  if (!m_StatsVisualization)
182  return;
183 
184  CreateEntry("Distance Walked: ", 0, EBasicActionsModuleStats.DistanceWalked);
185  }
186 #endif
187 };
188 
189 
190 #ifdef ENABLE_DIAG
191 enum EBasicActionsModuleStats
192 {
193  DistanceWalked
194 };
195 #endif
SCR_CompartmentAccessComponent
Definition: SCR_CompartmentAccessComponent.c:15
m_fTimeSinceUpdate
protected float m_fTimeSinceUpdate
Definition: SCR_RestrictedDeployableSpawnPointComponent.c:89
OnControlledEntityChanged
protected void OnControlledEntityChanged(IEntity from, IEntity to)
Runs every time the controlled entity has been changed.
Definition: SCR_ItemPlacementComponent.c:113
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PlayerData
Definition: SCR_PlayerData.c:2
Instigator
Definition: Instigator.c:6
SCR_EDataStats
SCR_EDataStats
Definition: SCR_PlayerData.c:950
SCR_DataCollectorBasicActionsModule
Definition: SCR_DataCollectorBasicActionsModule.c:2
PlayerManager
Definition: PlayerManager.c:12
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