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_SupportStationManagerComponent.c
Go to the documentation of this file.
1
[
ComponentEditorProps
(
category
:
"GameScripted/GameMode/Components"
, description:
"Manager that holds a reference to all Support Stations."
)]
2
class
SCR_SupportStationManagerComponentClass
:
ScriptComponentClass
3
{
4
}
5
6
//~ ScriptInvokers
7
void
SupportStation_OnSupportStationExecuted
(SCR_BaseSupportStationComponent supportStation,
ESupportStationType
supportStationType,
IEntity
actionOwner,
IEntity
actionUser,
SCR_BaseUseSupportStationAction
action);
8
typedef
func
SupportStation_OnSupportStationExecuted
;
9
10
class
SCR_SupportStationManagerComponent
:
ScriptComponent
11
{
12
// List of all support stations with range
13
protected
ref
map<ESupportStationType, ref array<SCR_BaseSupportStationComponent>
>
m_mSupportStations
=
new
map<ESupportStationType, ref array<SCR_BaseSupportStationComponent>
>();
14
15
protected
static
SCR_SupportStationManagerComponent
s_Instance
;
16
17
//~ Script invoker
18
protected
ref ScriptInvokerBase<SupportStation_OnSupportStationExecuted>
m_OnSupportStationExecutedSuccessfully
=
new
ScriptInvokerBase<SupportStation_OnSupportStationExecuted>();
19
20
//------------------------------------------------------------------------------------------------
23
static
SCR_SupportStationManagerComponent
GetInstance
()
24
{
25
return
s_Instance
;
26
}
27
28
//------------------------------------------------------------------------------------------------
35
static
void
OnSupportStationExecutedSuccessfully
(notnull SCR_BaseSupportStationComponent supportStation,
ESupportStationType
supportStationType,
IEntity
actionUser,
IEntity
actionOwner,
SCR_BaseUseSupportStationAction
action)
36
{
37
SCR_SupportStationManagerComponent
instance =
GetInstance
();
38
if
(!instance)
39
return
;
40
41
instance.
GetOnSupportStationExecutedSuccessfully
().Invoke(supportStation, supportStationType, actionOwner, actionUser, action);
42
}
43
44
//------------------------------------------------------------------------------------------------
48
ScriptInvokerBase<SupportStation_OnSupportStationExecuted>
GetOnSupportStationExecutedSuccessfully
()
49
{
50
return
m_OnSupportStationExecutedSuccessfully
;
51
}
52
53
//------------------------------------------------------------------------------------------------
54
//~ Get array of all Support stations of given type
55
protected
int
GetArrayOfSupportStationType
(
ESupportStationType
type
, notnull out array<SCR_BaseSupportStationComponent> supportStations)
56
{
57
supportStations.Clear();
58
59
//~ Add new type to make sure it is never null
60
if
(!
m_mSupportStations
.Find(
type
, supportStations))
61
{
62
m_mSupportStations
.Insert(
type
, {});
63
supportStations =
m_mSupportStations
[
type
];
64
}
65
66
return
supportStations.Count();
67
}
68
69
//------------------------------------------------------------------------------------------------
79
SCR_BaseSupportStationComponent
GetClosestValidSupportStation
(
ESupportStationType
type
, notnull
IEntity
actionUser, notnull
IEntity
actionOwner,
SCR_BaseUseSupportStationAction
action,
vector
actionPosition, out
ESupportStationReasonInvalid
reasonInvalid, out
int
supplyCost)
80
{
81
array<SCR_BaseSupportStationComponent> supportStations = {};
82
83
GetArrayOfSupportStationType
(
type
, supportStations);
84
85
reasonInvalid =
ESupportStationReasonInvalid
.NOT_IN_RANGE;
86
ESupportStationReasonInvalid
newReasonInvalid;
87
88
SCR_BaseSupportStationComponent closestSupportStation = null;
89
ESupportStationPriority
validPriority = -1;
90
float
closestDistance =
float
.MAX;
91
int
minSuppliesRequired =
int
.MAX;
92
int
suppliesRequired, validSupplyCost;
93
94
foreach
(SCR_BaseSupportStationComponent station : supportStations)
95
{
96
if
(!station)
97
continue
;
98
99
//~ Found all support stations of same priority and closest support station is already set
100
if
(closestSupportStation != null && station.GetSupportStationPriority() < validPriority)
101
break
;
102
103
//~ Check if support station is valid
104
if
(station.IsValid(actionOwner, actionUser, action, actionPosition, newReasonInvalid, suppliesRequired))
105
{
106
//~ station is valid so make sure to save the priority level which makes sure on the same priority stations are ever checked
107
if
(validPriority < 0)
108
validPriority = station.GetSupportStationPriority();
109
110
//~ Get distance to user
111
float
distancesq =
vector
.DistanceSq(actionPosition, station.GetPosition());
112
113
//~ Support station is closer to user so set this as valid return
114
if
(distancesq < closestDistance)
115
{
116
closestDistance = distancesq;
117
closestSupportStation = station;
118
validSupplyCost = suppliesRequired;
119
}
120
}
121
//~ Support station was invalid set new invalid reason if it has an higher priority
122
else
if
(newReasonInvalid > reasonInvalid)
123
{
124
reasonInvalid = newReasonInvalid;
125
}
126
127
//~ Supply station was valid but not enough supplies
128
if
(newReasonInvalid ==
ESupportStationReasonInvalid
.NO_SUPPLIES && minSuppliesRequired > suppliesRequired)
129
minSuppliesRequired = suppliesRequired;
130
}
131
132
//~ Set supply cost to closest station cost
133
if
(closestSupportStation)
134
supplyCost = validSupplyCost;
135
//~ No valid supply station as not enough supplies to execute. Still set min supplies needed to execute
136
else
if
(newReasonInvalid ==
ESupportStationReasonInvalid
.NO_SUPPLIES)
137
supplyCost = minSuppliesRequired;
138
//~ No valid supply station and reason was not lack of supplies
139
else
140
supplyCost = -1;
141
142
return
closestSupportStation;
143
}
144
145
//------------------------------------------------------------------------------------------------
148
void
AddSupportStation
(SCR_BaseSupportStationComponent supportStation)
149
{
150
if
(!supportStation)
151
return
;
152
153
if
(supportStation.GetSupportStationType() ==
ESupportStationType
.NONE)
154
{
155
Print
(
"Cannot add SupportStation of type NONE! Make sure to overwrite GetSupportStationType() in inherited class."
,
LogLevel
.ERROR);
156
return
;
157
}
158
159
array<SCR_BaseSupportStationComponent> supportStations = {};
160
GetArrayOfSupportStationType
(supportStation.GetSupportStationType(), supportStations);
161
162
//~ Already in list
163
if
(supportStations.Contains(supportStation))
164
return
;
165
166
for
(
int
i = 0, count = supportStations.Count(); i < count; i++)
167
{
168
//~ Make sure it is added near the at priority in the array
169
if
(supportStation.GetSupportStationPriority() >= supportStations[i].GetSupportStationPriority())
170
{
171
//~ Insert in list at the correct location
172
m_mSupportStations
[supportStation.GetSupportStationType()].InsertAt(supportStation, i);
173
return
;
174
}
175
}
176
177
//~ Add to last position in array as loop above did not add it
178
m_mSupportStations
[supportStation.GetSupportStationType()].Insert(supportStation);
179
}
180
181
//------------------------------------------------------------------------------------------------
184
void
RemoveSupportStation
(SCR_BaseSupportStationComponent supportStation)
185
{
186
if
(!supportStation || supportStation.GetSupportStationType() ==
ESupportStationType
.NONE)
187
return
;
188
189
array<SCR_BaseSupportStationComponent> supportStations = {};
190
GetArrayOfSupportStationType
(supportStation.GetSupportStationType(), supportStations);
191
192
int
index
= supportStations.Find(supportStation);
193
194
//~ Not in list
195
if
(
index
< 0)
196
return
;
197
198
//~ Remove from list
199
m_mSupportStations
[supportStation.GetSupportStationType()].RemoveOrdered(
index
);
200
}
201
202
//------------------------------------------------------------------------------------------------
210
static
void
GetCombinedHitZonesStateForDamageSupportStation
(notnull SCR_DamageManagerComponent damageManagerComponent, notnull array<HitZone> hitZones,
float
maxHealPercentage, out
float
roughHealPercentageStatus, out
bool
allHitZonesMaxHealth =
true
)
211
{
212
HitZone
defaultHitZone = damageManagerComponent.GetDefaultHitZone();
213
214
//~ Out values
215
allHitZonesMaxHealth =
true
;
216
roughHealPercentageStatus = 0;
217
218
int
hitZonesChecked = 0;
219
bool
defaultHitZoneIncluded =
false
;
220
221
foreach
(
HitZone
hitZone : hitZones)
222
{
223
if
(defaultHitZone == hitZone)
224
{
225
defaultHitZoneIncluded =
true
;
226
continue
;
227
}
228
229
//~ Get percentage of hitZone and add it to the pool
230
hitZonesChecked++;
231
roughHealPercentageStatus += hitZone.GetHealthScaled();
232
233
//~ Check if entity can be healed more by this support station if not yet set false
234
if
(allHitZonesMaxHealth && hitZone.GetHealthScaled() < maxHealPercentage)
235
allHitZonesMaxHealth =
false
;
236
}
237
238
//~ Get average health of all hitZones that can be healed
239
if
(hitZonesChecked > 0)
240
roughHealPercentageStatus = roughHealPercentageStatus / hitZonesChecked;
241
else
242
roughHealPercentageStatus = 1;
243
244
if
(defaultHitZoneIncluded && defaultHitZone)
245
{
246
//~ If parts heal is higher than defualt hitZone health use default hitZone instead
247
if
(roughHealPercentageStatus > defaultHitZone.GetHealthScaled())
248
roughHealPercentageStatus = defaultHitZone.GetHealthScaled();
249
}
250
}
251
252
//------------------------------------------------------------------------------------------------
253
override
void
OnPostInit
(
IEntity
owner)
254
{
255
if
(
s_Instance
)
256
return
;
257
258
BaseGameMode gameMode =
GetGame
().GetGameMode();
259
if
(!gameMode)
260
return
;
261
262
s_Instance
=
SCR_SupportStationManagerComponent
.Cast(gameMode.FindComponent(
SCR_SupportStationManagerComponent
));
263
}
264
}
ESupportStationPriority
ESupportStationPriority
Definition
ESupportStationPriority.c:3
ESupportStationReasonInvalid
ESupportStationReasonInvalid
Definition
ESupportStationReasonInvalid.c:4
ESupportStationType
ESupportStationType
Definition
ESupportStationType.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
ComponentEditorProps
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
Definition
SCR_AIGroupUtilityComponent.c:12
func
func
Definition
SCR_AIThreatSystem.c:6
type
EDamageType type
Definition
SCR_DestructibleTreeV2.c:32
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition
SCR_DestructionSynchronizationComponent.c:17
SupportStation_OnSupportStationExecuted
func SupportStation_OnSupportStationExecuted
Definition
SCR_SupportStationManagerComponent.c:8
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
HitZone
Definition
HitZone.c:13
IEntity
Definition
IEntity.c:13
SCR_BaseUseSupportStationAction
Definition
SCR_BaseUseSupportStationAction.c:2
SCR_SupportStationManagerComponentClass
Definition
SCR_SupportStationManagerComponent.c:3
SCR_SupportStationManagerComponent
Definition
SCR_SupportStationManagerComponent.c:11
SCR_SupportStationManagerComponent::m_OnSupportStationExecutedSuccessfully
ref ScriptInvokerBase< SupportStation_OnSupportStationExecuted > m_OnSupportStationExecutedSuccessfully
Definition
SCR_SupportStationManagerComponent.c:18
SCR_SupportStationManagerComponent::GetOnSupportStationExecutedSuccessfully
ScriptInvokerBase< SupportStation_OnSupportStationExecuted > GetOnSupportStationExecutedSuccessfully()
Definition
SCR_SupportStationManagerComponent.c:48
SCR_SupportStationManagerComponent::m_mSupportStations
ref map< ESupportStationType, ref array< SCR_BaseSupportStationComponent > > m_mSupportStations
Definition
SCR_SupportStationManagerComponent.c:13
SCR_SupportStationManagerComponent::GetClosestValidSupportStation
SCR_BaseSupportStationComponent GetClosestValidSupportStation(ESupportStationType type, notnull IEntity actionUser, notnull IEntity actionOwner, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyCost)
Definition
SCR_SupportStationManagerComponent.c:79
SCR_SupportStationManagerComponent::GetCombinedHitZonesStateForDamageSupportStation
static void GetCombinedHitZonesStateForDamageSupportStation(notnull SCR_DamageManagerComponent damageManagerComponent, notnull array< HitZone > hitZones, float maxHealPercentage, out float roughHealPercentageStatus, out bool allHitZonesMaxHealth=true)
Definition
SCR_SupportStationManagerComponent.c:210
SCR_SupportStationManagerComponent::RemoveSupportStation
void RemoveSupportStation(SCR_BaseSupportStationComponent supportStation)
Definition
SCR_SupportStationManagerComponent.c:184
SCR_SupportStationManagerComponent::OnPostInit
override void OnPostInit(IEntity owner)
Definition
SCR_SupportStationManagerComponent.c:253
SCR_SupportStationManagerComponent::s_Instance
static SCR_SupportStationManagerComponent s_Instance
Definition
SCR_SupportStationManagerComponent.c:15
SCR_SupportStationManagerComponent::AddSupportStation
void AddSupportStation(SCR_BaseSupportStationComponent supportStation)
Definition
SCR_SupportStationManagerComponent.c:148
SCR_SupportStationManagerComponent::GetArrayOfSupportStationType
int GetArrayOfSupportStationType(ESupportStationType type, notnull out array< SCR_BaseSupportStationComponent > supportStations)
Definition
SCR_SupportStationManagerComponent.c:55
SCR_SupportStationManagerComponent::OnSupportStationExecutedSuccessfully
static void OnSupportStationExecutedSuccessfully(notnull SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionUser, IEntity actionOwner, SCR_BaseUseSupportStationAction action)
Definition
SCR_SupportStationManagerComponent.c:35
SCR_SupportStationManagerComponent::GetInstance
static SCR_SupportStationManagerComponent GetInstance()
Definition
SCR_SupportStationManagerComponent.c:23
ScriptComponentClass
Definition
ScriptComponentClass.c:8
ScriptComponent
Definition
ScriptComponent.c:24
map
Definition
Types.c:486
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
scripts
Game
Components
SupportStation
SCR_SupportStationManagerComponent.c
Generated by
1.17.0