Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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.")]
5
6//~ ScriptInvokers
7void SupportStation_OnSupportStationExecuted(SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionOwner, IEntity actionUser, SCR_BaseUseSupportStationAction action);
9
11{
12 // List of all support stations with range
14
16
17 //~ Script invoker
18 protected ref ScriptInvokerBase<SupportStation_OnSupportStationExecuted> m_OnSupportStationExecutedSuccessfully = new ScriptInvokerBase<SupportStation_OnSupportStationExecuted>();
19
20 //------------------------------------------------------------------------------------------------
27
28 //------------------------------------------------------------------------------------------------
35 static void OnSupportStationExecutedSuccessfully(notnull SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionUser, IEntity actionOwner, SCR_BaseUseSupportStationAction action)
36 {
38 if (!instance)
39 return;
40
41 instance.GetOnSupportStationExecutedSuccessfully().Invoke(supportStation, supportStationType, actionOwner, actionUser, action);
42 }
43
44 //------------------------------------------------------------------------------------------------
48 ScriptInvokerBase<SupportStation_OnSupportStationExecuted> GetOnSupportStationExecutedSuccessfully()
49 {
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
263 }
264}
ESupportStationPriority
ESupportStationType
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
EDamageType type
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
func SupportStation_OnSupportStationExecuted
ref ScriptInvokerBase< SupportStation_OnSupportStationExecuted > m_OnSupportStationExecutedSuccessfully
ScriptInvokerBase< SupportStation_OnSupportStationExecuted > GetOnSupportStationExecutedSuccessfully()
ref map< ESupportStationType, ref array< SCR_BaseSupportStationComponent > > m_mSupportStations
SCR_BaseSupportStationComponent GetClosestValidSupportStation(ESupportStationType type, notnull IEntity actionUser, notnull IEntity actionOwner, SCR_BaseUseSupportStationAction action, vector actionPosition, out ESupportStationReasonInvalid reasonInvalid, out int supplyCost)
static void GetCombinedHitZonesStateForDamageSupportStation(notnull SCR_DamageManagerComponent damageManagerComponent, notnull array< HitZone > hitZones, float maxHealPercentage, out float roughHealPercentageStatus, out bool allHitZonesMaxHealth=true)
void RemoveSupportStation(SCR_BaseSupportStationComponent supportStation)
static SCR_SupportStationManagerComponent s_Instance
void AddSupportStation(SCR_BaseSupportStationComponent supportStation)
int GetArrayOfSupportStationType(ESupportStationType type, notnull out array< SCR_BaseSupportStationComponent > supportStations)
static void OnSupportStationExecutedSuccessfully(notnull SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionUser, IEntity actionOwner, SCR_BaseUseSupportStationAction action)
static SCR_SupportStationManagerComponent GetInstance()
Definition Types.c:486
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