Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FuelNode.c
Go to the documentation of this file.
1//~ Incoming liters per minute
4 MANUAL = 50,
5 VEHICLE_SMALL = 250, //standard rate
6 VEHICLE_MEDIUM = 700, //usually trucks rate
7 VEHICLE_BIG = 1400, //airplanes
8 VEHICLE_HELICOPTER = 2500, //helicopter
9 FUEL_CARGO = 4500, //Fuel Cargo like fuel tanks on truck
10}
11
12//~ Outgoing liters per minute
13enum EFuelFlowCapacityOut
14{
15 MANUAL = 50,
16 VEHICLE_SMALL = 250, //standard rate
17 VEHICLE_MEDIUM = 700, //usually trucks rate
18 VEHICLE_BIG = 1400, //airplanes
19 VEHICLE_HELICOPTER = 2500, //helicopter
20 FUEL_CARGO = 4500, //Fuel Cargo like fuel tanks on truck
21}
22
23//~ Fuel node type flags
24enum SCR_EFuelNodeTypeFlag
25{
28 CAN_BE_DRAINED = 1 << 2,
29
30 IS_FUEL_STORAGE = 1 << 3,
31}
32
33class SCR_FuelNode : BaseFuelNode
34{
35 [Attribute( defvalue: "1", uiwidget: UIWidgets.EditBox, desc: "Initial fuel level" )]
36 protected float m_fInitialFuelTankState; //tank state of the entity after it's created
37
38 [Attribute(defvalue: EFuelFlowCapacityOut.MANUAL.ToString(), uiwidget: UIWidgets.SearchComboBox, desc: "Maximum Flow Capacity out eg: When draining the fuel tank to refuel another vehicle. Liters per minutes", enums: ParamEnumArray.FromEnum( EFuelFlowCapacityOut ) )]
39 protected EFuelFlowCapacityOut m_MaxFlowCapacityOut;
40
41 [Attribute(defvalue: EFuelFlowCapacityIn.VEHICLE_SMALL.ToString(), uiwidget: UIWidgets.SearchComboBox, desc: "Maximum Flow Capacity in eg: When filling the fuel tank. Liters per minutes", enums: ParamEnumArray.FromEnum( EFuelFlowCapacityIn ) )]
43
44 [Attribute( defvalue: "20", uiwidget: UIWidgets.CheckBox, desc: "Maximum Leak Speed\n[l/min]" )]
45 protected int m_iFuelLeakSpeed;
46
47 [Attribute(SCR_EFuelNodeTypeFlag.CAN_RECEIVE_FUEL.ToString(), desc: "What type of fuel node is it? Can it provide and receive fuel? Maybe the fuel node is part of a fuel storage etc", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(SCR_EFuelNodeTypeFlag))]
48 protected SCR_EFuelNodeTypeFlag m_eFuelNodeType;
49
50 [Attribute( defvalue: "1", uiwidget: UIWidgets.EditBox, desc: "Fuel tank ID (user action and hitzone)" )]
51 protected int m_iFuelTankID; //for pairing with the user action
52
53 static ref ScriptInvoker s_OnRefuelingFinished = new ScriptInvoker();
55
56 #ifndef DISABLE_FUEL
57 protected const float TIME_STEP = 1;
58 protected float m_fTimeSkip; // Just for not overloading the onFrame each frame
59 protected IEntity m_Owner; // Parent entity
60 protected float m_fHealth = 1; // Damage of fuel tank, reduces capacity
61
63
64 protected int m_iSignalFuelStateIdx;
66 protected string m_sSignalFuelState;
67 protected const string SIGNAL_FUEL_TANK_PREFIX = "fuel";
68 protected const string SIGNAL_FUEL_TANK_ID = "fueltank";
69
70 #ifdef DEBUG_FUELSYSTEM
71 private float m_fTestFuel = 0.0;
72 private float m_fTestWorldTime = 0.0;
73 [RplProp(condition: RplCondition.NoOwner, onRplName: "OnTestChanged")]
74 private float m_fDebugTankState = 0.0;
75 private bool m_bFuelTankHUDAllowed = true;
76 #endif
77
78 //------------------------------------------------------------------------------------------------
81 {
82 return SCR_Enum.HasFlag(m_eFuelNodeType, SCR_EFuelNodeTypeFlag.CAN_RECEIVE_FUEL);
83 }
84
85 //------------------------------------------------------------------------------------------------
88 {
89 return SCR_Enum.HasFlag(m_eFuelNodeType, SCR_EFuelNodeTypeFlag.CAN_PROVIDE_FUEL);
90 }
91
92 //------------------------------------------------------------------------------------------------
96 bool HasExactTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
97 {
98 return typeFlag == m_eFuelNodeType;
99 }
100
101 //------------------------------------------------------------------------------------------------
105 bool HasAllTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
106 {
107 return SCR_Enum.HasFlag(m_eFuelNodeType, typeFlag);
108 }
109
110 //------------------------------------------------------------------------------------------------
114 bool HasAnyTypeFlag(SCR_EFuelNodeTypeFlag typeFlag)
115 {
116 return SCR_Enum.HasPartialFlag(m_eFuelNodeType, typeFlag);
117 }
118
119 //------------------------------------------------------------------------------------------------
122 {
123 return m_iFuelTankID;
124 }
125
126 //------------------------------------------------------------------------------------------------
129 {
130 return m_Owner;
131 }
132
133 //------------------------------------------------------------------------------------------------
135 void SetHealth(float health)
136 {
137 m_fHealth = Math.Clamp(health, 0, 1);
138
139 if (m_fHealth == 1)
140 return;
141
142 if (ShouldSimulate())
143 return;
144
145 SetShouldSimulate(true);
146 m_fTimeSkip = 0;
147 }
148
149 //------------------------------------------------------------------------------------------------
150 override void OnFixedFrame(IEntity owner, float timeSlice)
151 {
152 // Work 1 time per second at most
153 float leakableFuel;
154 if (m_fHealth < 1)
155 leakableFuel = GetLeakableFuel();
156
157 if (leakableFuel > 0)
158 m_fTimeSkip += timeSlice;
159 else
160 m_fTimeSkip = 0;
161
163 return;
164
165 // Reduce capacity of fuel tank by its damage
166 // The fuel over reliable capacity will leak gradually
167 float leak = Math.Min(leakableFuel, ((1 - m_fHealth) * m_iFuelLeakSpeed / 60) * m_fTimeSkip);
168
169 SetFuel(GetFuel() - leak);
170
171 m_fTimeSkip = 0;
172 }
173
174 //------------------------------------------------------------------------------------------------
175 override protected void OnFuelChanged(float newFuel)
176 {
178 m_SignalManagerComp.SetSignalValue(m_iSignalFuelStateIdx, newFuel);
179
180 if (m_OnFuelChanged)
181 m_OnFuelChanged.Invoke(newFuel);
182 }
183
184 //------------------------------------------------------------------------------------------------
193
194 //------------------------------------------------------------------------------------------------
196 float GetHealth()
197 {
198 return m_fHealth;
199 }
200
201 //------------------------------------------------------------------------------------------------
204 {
205 return GetFuel() - GetMaxFuel() * m_fHealth;
206 }
207
208 //------------------------------------------------------------------------------------------------
210 EFuelFlowCapacityOut GetMaxFlowCapacityOut()
211 {
213 }
214
215 //------------------------------------------------------------------------------------------------
217 {
218 return m_fInitialFuelTankState;
219 }
220
221 //------------------------------------------------------------------------------------------------
227
228 //------------------------------------------------------------------------------------------------
229 override void OnInit(IEntity owner)
230 {
231 m_Owner = owner;
232
234 #ifdef DEBUG_FUELSYSTEM
235 PrintFormat( "FUELSYSTEM: Inserting %1", this );
236 #endif
237
240 {
242
243 #ifdef DEBUG_FUELSYSTEM
244 PrintFormat( "FUELSYSTEM: signal registered: %1 and set to: %2", m_sSignalFuelState, m_SignalManagerComp.GetSignalValue( m_iSignalFuelStateIdx ) );
245 #endif
246 }
247
248 SetFuel(m_fInitialFuelTankState);
249 }
250
251 #else
252
253 //------------------------------------------------------------------------------------------------
255 // Keeping just the declarations of function when the system is disabled
256 bool CanReceiveFuel();
257
258 //------------------------------------------------------------------------------------------------
260 bool CanProvideFuel();
261
262 //------------------------------------------------------------------------------------------------
264 int GetFuelTankID();
265
266 //------------------------------------------------------------------------------------------------
269
270 //------------------------------------------------------------------------------------------------
272 void SetHealth(float health);
273
274 //------------------------------------------------------------------------------------------------
275 override void OnFixedFrame(IEntity owner, float timeSlice);
276
277 //------------------------------------------------------------------------------------------------
278 protected void OnFuelChanged();
279
280 //------------------------------------------------------------------------------------------------
282 float GetLeakableFuel();
283
284 //------------------------------------------------------------------------------------------------
285 override void OnInit(IEntity owner);
286 #endif
287}
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
const float TIME_STEP
SCR_FuelManagerComponentClass m_OnFuelChanged
ScriptInvokerFloat GetOnFuelChanged()
enum EFuelFlowCapacityIn VEHICLE_HELICOPTER
Definition SCR_FuelNode.c:4
bool HasAnyTypeFlag(SCR_EFuelNodeTypeFlag typeFlag)
enum EFuelFlowCapacityIn VEHICLE_SMALL
Definition SCR_FuelNode.c:1
string m_sSignalFuelState
EFuelFlowCapacityOut GetMaxFlowCapacityOut()
bool CanProvideFuel()
float GetInitialFuelTankState()
enum EFuelFlowCapacityIn CAN_RECEIVE_FUEL
Can the fuel node receive fuel from other fuel nodes.
float m_fTimeSkip
enum EFuelFlowCapacityIn VEHICLE_BIG
Definition SCR_FuelNode.c:3
float GetHealth()
void SetHealth(float health)
enum EFuelFlowCapacityIn IS_FUEL_STORAGE
Any fuel nodes such as fuel tanker and in world refuel points.
enum EFuelFlowCapacityIn CAN_PROVIDE_FUEL
Can the fuel node provide fuel to other fuel nodes.
bool HasAllTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
EFuelFlowCapacityIn GetMaxFlowCapacityIn()
bool HasExactTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
float GetLeakableFuel()
enum EFuelFlowCapacityIn FUEL_CARGO
Definition SCR_FuelNode.c:5
SignalsManagerComponent m_SignalManagerComp
enum EFuelFlowCapacityIn CAN_BE_DRAINED
If the fuel node can be drained with user action.
EFuelFlowCapacityIn
Definition SCR_FuelNode.c:3
enum EFuelFlowCapacityIn MANUAL
User initiated.
Definition SCR_FuelNode.c:0
SCR_EFuelNodeTypeFlag m_eFuelNodeType
int m_iFuelTankID
const string SIGNAL_FUEL_TANK_ID
int m_iFuelLeakSpeed
const string SIGNAL_FUEL_TANK_PREFIX
int m_iSignalIndexFuelTank
EFuelFlowCapacityIn m_MaxFlowCapacityIn
int m_iSignalFuelStateIdx
int GetFuelTankID()
Assigned fuel tank ID.
float m_fHealth
bool CanReceiveFuel()
EFuelFlowCapacityOut m_MaxFlowCapacityOut
enum EFuelFlowCapacityIn VEHICLE_MEDIUM
Definition SCR_FuelNode.c:2
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerFloatMethod > ScriptInvokerFloat
enum EVehicleType IEntity
void OnFixedFrame(IEntity owner, float timeSlice)
Fixed Frame Call in script.
void OnFuelChanged(float newFuel)
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
IEntity GetOwner()
Owner entity of the fuel tank.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
RplCondition
Conditional replication rule. Fine grained selection of receivers.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134