Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_DataCollectorBasicActionsModule.c
Go to the documentation of this file.
1
[
BaseContainerProps
()]
2
class
SCR_DataCollectorBasicActionsModule
:
SCR_DataCollectorModule
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
instigator, notnull
SCR_InstigatorContextData
instigatorContextData)
125
{
126
super.OnPlayerKilled(playerId, playerEntity, killerEntity, instigator, instigatorContextData);
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
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
BaseContainerProps
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Definition
SCR_AIAnimationWaypoint.c:14
SCR_EDataStats
SCR_EDataStats
Definition
SCR_PlayerData.c:919
BaseCompartmentManagerComponent
Definition
BaseCompartmentManagerComponent.c:13
BaseCompartmentSlot
Definition
BaseCompartmentSlot.c:2
IEntity
Definition
IEntity.c:13
IEntity::GetPhysics
proto external Physics GetPhysics()
Instigator
Definition
Instigator.c:13
Physics
Definition
Physics.c:22
PlayerManager
Definition
PlayerManager.c:13
SCR_CompartmentAccessComponent
Definition
SCR_CompartmentAccessComponent.c:16
SCR_CompartmentAccessComponent::GetOnCompartmentEntered
ScriptInvoker GetOnCompartmentEntered(bool createNew=true)
Definition
SCR_CompartmentAccessComponent.c:30
SCR_CompartmentAccessComponent::GetOnCompartmentLeft
ScriptInvoker GetOnCompartmentLeft(bool createNew=true)
Definition
SCR_CompartmentAccessComponent.c:38
SCR_DataCollectorBasicActionsModule
Definition
SCR_DataCollectorBasicActionsModule.c:3
SCR_DataCollectorBasicActionsModule::OnCompartmentLeft
void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
Definition
SCR_DataCollectorBasicActionsModule.c:68
SCR_DataCollectorBasicActionsModule::LIMIT_WALKING_SPEED_PER_SECOND
const int LIMIT_WALKING_SPEED_PER_SECOND
Definition
SCR_DataCollectorBasicActionsModule.c:5
SCR_DataCollectorBasicActionsModule::m_iMaxWalkingDistancePerSecond
int m_iMaxWalkingDistancePerSecond
Definition
SCR_DataCollectorBasicActionsModule.c:6
SCR_DataCollectorBasicActionsModule::OnPlayerSpawned
override void OnPlayerSpawned(int playerID, IEntity controlledEntity)
Definition
SCR_DataCollectorBasicActionsModule.c:98
SCR_DataCollectorBasicActionsModule::Update
override void Update(float timeTick)
Definition
SCR_DataCollectorBasicActionsModule.c:131
SCR_DataCollectorBasicActionsModule::OnCompartmentEntered
void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
Definition
SCR_DataCollectorBasicActionsModule.c:49
SCR_DataCollectorBasicActionsModule::m_mTrackedPlayers
ref map< int, IEntity > m_mTrackedPlayers
Definition
SCR_DataCollectorBasicActionsModule.c:4
SCR_DataCollectorBasicActionsModule::OnPlayerKilled
override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
Definition
SCR_DataCollectorBasicActionsModule.c:124
SCR_DataCollectorBasicActionsModule::AddInvokers
override void AddInvokers(IEntity player)
Definition
SCR_DataCollectorBasicActionsModule.c:9
SCR_DataCollectorBasicActionsModule::RemoveInvokers
override void RemoveInvokers(IEntity player)
Definition
SCR_DataCollectorBasicActionsModule.c:29
SCR_DataCollectorBasicActionsModule::OnPlayerDisconnected
override void OnPlayerDisconnected(int playerID, IEntity controlledEntity=null)
Definition
SCR_DataCollectorBasicActionsModule.c:89
SCR_DataCollectorModule
Definition
SCR_DataCollectorModule.c:3
SCR_DataCollectorModule::m_fUpdatePeriod
float m_fUpdatePeriod
Definition
SCR_DataCollectorModule.c:8
SCR_DataCollectorModule::OnControlledEntityChanged
void OnControlledEntityChanged(IEntity from, IEntity to)
Definition
SCR_DataCollectorModule.c:68
SCR_DataCollectorModule::m_fTimeSinceUpdate
float m_fTimeSinceUpdate
Definition
SCR_DataCollectorModule.c:6
SCR_DataCollectorModule::m_StatsVisualization
ref map< int, TextWidget > m_StatsVisualization
Definition
SCR_DataCollectorModule.c:4
SCR_InstigatorContextData
Definition
SCR_InstigatorContextData.c:2
SCR_PlayerData
Definition
SCR_PlayerData.c:3
SCR_PlayerData::AddStat
void AddStat(SCR_EDataStats stat, float amount=1, bool temp=true)
Definition
SCR_PlayerData.c:785
SCR_PlayerData::GetStat
float GetStat(SCR_EDataStats stat, bool newStat=true)
Definition
SCR_PlayerData.c:816
SCR_PlayerData::GetPlayerData
static SCR_PlayerData GetPlayerData(int playerID)
Definition
SCR_PlayerData.c:131
map
Definition
Types.c:486
scripts
Game
DataCollection
DataCollectorModules
SCR_DataCollectorBasicActionsModule.c
Generated by
1.17.0