Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FuelNode.c
Go to the documentation of this file.
1 //~ Incoming liters per minute
3 {
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
13 enum 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
24 enum SCR_EFuelNodeTypeFlag
25 {
26  CAN_RECEIVE_FUEL = 1 << 0,
27  CAN_PROVIDE_FUEL = 1 << 1,
28  CAN_BE_DRAINED = 1 << 2,
29 
30  IS_FUEL_STORAGE = 1 << 3,
31 }
32 
33 class 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 
62  protected SignalsManagerComponent m_SignalManagerComp;
63 
64  protected int m_iSignalFuelStateIdx;
65  protected int m_iSignalIndexFuelTank;
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  //------------------------------------------------------------------------------------------------
128  IEntity GetOwner()
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 
162  if (m_fTimeSkip < TIME_STEP)
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  //------------------------------------------------------------------------------------------------
187  {
188  if (!m_OnFuelChanged)
190 
191  return m_OnFuelChanged;
192  }
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  {
212  return m_MaxFlowCapacityOut;
213  }
214 
215  //------------------------------------------------------------------------------------------------
218  {
219  return m_MaxFlowCapacityIn;
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  override void OnInit(IEntity owner)
224  {
225  m_Owner = owner;
226 
228  #ifdef DEBUG_FUELSYSTEM
229  PrintFormat( "FUELSYSTEM: Inserting %1", this );
230  #endif
231 
232  m_SignalManagerComp = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
234  {
236 
237  #ifdef DEBUG_FUELSYSTEM
238  PrintFormat( "FUELSYSTEM: signal registered: %1 and set to: %2", m_sSignalFuelState, m_SignalManagerComp.GetSignalValue( m_iSignalFuelStateIdx ) );
239  #endif
240  }
241 
242  SetFuel(m_fInitialFuelTankState);
243  }
244 
245  #else
246 
247  //------------------------------------------------------------------------------------------------
249  // Keeping just the declarations of function when the system is disabled
250  bool CanReceiveFuel();
251 
252  //------------------------------------------------------------------------------------------------
254  bool CanProvideFuel();
255 
256  //------------------------------------------------------------------------------------------------
258  int GetFuelTankID();
259 
260  //------------------------------------------------------------------------------------------------
262  IEntity GetOwner();
263 
264  //------------------------------------------------------------------------------------------------
266  void SetHealth(float health);
267 
268  //------------------------------------------------------------------------------------------------
269  override void OnFixedFrame(IEntity owner, float timeSlice);
270 
271  //------------------------------------------------------------------------------------------------
272  protected void OnFuelChanged();
273 
274  //------------------------------------------------------------------------------------------------
276  float GetLeakableFuel();
277 
278  //------------------------------------------------------------------------------------------------
279  override void OnInit(IEntity owner);
280  #endif
281 }
CAN_PROVIDE_FUEL
enum EFuelFlowCapacityIn CAN_PROVIDE_FUEL
Can the fuel node provide fuel to other fuel nodes.
CAN_BE_DRAINED
enum EFuelFlowCapacityIn CAN_BE_DRAINED
If the fuel node can be drained with user action.
SCR_Enum
Definition: SCR_Enum.c:1
HasExactTypeFlags
bool HasExactTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
Definition: SCR_FuelNode.c:96
m_fHealth
protected float m_fHealth
Definition: SCR_FuelNode.c:60
BaseFuelNode
Definition: BaseFuelNode.c:12
IS_FUEL_STORAGE
enum EFuelFlowCapacityIn IS_FUEL_STORAGE
Any fuel nodes such as fuel tanker and in world refuel points.
VEHICLE_BIG
enum EFuelFlowCapacityIn VEHICLE_BIG
Definition: SCR_FuelNode.c:5
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
m_sSignalFuelState
protected string m_sSignalFuelState
Definition: SCR_FuelNode.c:66
CanProvideFuel
bool CanProvideFuel()
Definition: SCR_FuelNode.c:87
SetHealth
void SetHealth(float health)
Definition: SCR_FuelNode.c:135
m_OnFuelChanged
protected ref ScriptInvokerFloat m_OnFuelChanged
Definition: SCR_FuelNode.c:54
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
MANUAL
enum EFuelFlowCapacityIn MANUAL
Definition: SCR_FuelNode.c:2
SIGNAL_FUEL_TANK_ID
const protected string SIGNAL_FUEL_TANK_ID
Definition: SCR_FuelNode.c:68
m_MaxFlowCapacityIn
protected EFuelFlowCapacityIn m_MaxFlowCapacityIn
Definition: SCR_FuelNode.c:42
m_iFuelLeakSpeed
protected int m_iFuelLeakSpeed
Definition: SCR_FuelNode.c:45
m_eFuelNodeType
protected SCR_EFuelNodeTypeFlag m_eFuelNodeType
Definition: SCR_FuelNode.c:48
VEHICLE_MEDIUM
enum EFuelFlowCapacityIn VEHICLE_MEDIUM
Definition: SCR_FuelNode.c:4
OnFuelChanged
override protected void OnFuelChanged(float newFuel)
Definition: SCR_FuelNode.c:175
VEHICLE_SMALL
enum EFuelFlowCapacityIn VEHICLE_SMALL
Definition: SCR_FuelNode.c:3
GetHealth
float GetHealth()
Definition: SCR_FuelNode.c:196
m_iSignalFuelStateIdx
protected int m_iSignalFuelStateIdx
Definition: SCR_FuelNode.c:64
ScriptInvokerFloat
ScriptInvokerBase< ScriptInvokerFloatMethod > ScriptInvokerFloat
Definition: SCR_ScriptInvokerHelper.c:58
CAN_RECEIVE_FUEL
enum EFuelFlowCapacityIn CAN_RECEIVE_FUEL
Can the fuel node receive fuel from other fuel nodes.
GetLeakableFuel
float GetLeakableFuel()
Definition: SCR_FuelNode.c:203
GetFuelTankID
int GetFuelTankID()
Assigned fuel tank ID.
Definition: SCR_FuelNode.c:121
EFuelFlowCapacityIn
EFuelFlowCapacityIn
Definition: SCR_FuelNode.c:2
m_iSignalIndexFuelTank
protected int m_iSignalIndexFuelTank
Definition: SCR_FuelNode.c:65
FUEL_CARGO
enum EFuelFlowCapacityIn FUEL_CARGO
Definition: SCR_FuelNode.c:7
GetOnFuelChanged
ScriptInvokerFloat GetOnFuelChanged()
Definition: SCR_FuelNode.c:186
OnFixedFrame
override void OnFixedFrame(IEntity owner, float timeSlice)
Definition: SCR_FuelNode.c:150
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
HasAllTypeFlags
bool HasAllTypeFlags(SCR_EFuelNodeTypeFlag typeFlag)
Definition: SCR_FuelNode.c:105
SIGNAL_FUEL_TANK_PREFIX
const protected string SIGNAL_FUEL_TANK_PREFIX
Definition: SCR_FuelNode.c:67
m_iFuelTankID
protected int m_iFuelTankID
Definition: SCR_FuelNode.c:51
m_MaxFlowCapacityOut
protected EFuelFlowCapacityOut m_MaxFlowCapacityOut
Definition: SCR_FuelNode.c:39
m_fTimeSkip
protected float m_fTimeSkip
Definition: SCR_FuelNode.c:58
VEHICLE_HELICOPTER
enum EFuelFlowCapacityIn VEHICLE_HELICOPTER
Definition: SCR_FuelNode.c:6
m_SignalManagerComp
protected SignalsManagerComponent m_SignalManagerComp
Definition: SCR_FuelNode.c:62
GetMaxFlowCapacityOut
EFuelFlowCapacityOut GetMaxFlowCapacityOut()
Definition: SCR_FuelNode.c:210
CanReceiveFuel
bool CanReceiveFuel()
Definition: SCR_FuelNode.c:80
Attribute
enum EFuelFlowCapacityIn Attribute(defvalue:"1", uiwidget:UIWidgets.EditBox, desc:"Initial fuel level")] protected float m_fInitialFuelTankState
TIME_STEP
const protected float TIME_STEP
Definition: SCR_FuelNode.c:57
OnInit
override void OnInit(IEntity owner)
Definition: SCR_FuelNode.c:223
GetMaxFlowCapacityIn
EFuelFlowCapacityIn GetMaxFlowCapacityIn()
Definition: SCR_FuelNode.c:217
HasAnyTypeFlag
bool HasAnyTypeFlag(SCR_EFuelNodeTypeFlag typeFlag)
Definition: SCR_FuelNode.c:114
m_Owner
protected IEntity m_Owner
Definition: SCR_FuelNode.c:59