Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FuelTankInfo.c
Go to the documentation of this file.
1 //#define SHOW_DMG_INDICATORS_WARNING
2 //#define SHOW_DMG_INDICATORS_ERROR
3 
5 {
6  [Attribute(uiwidget: UIWidgets.Auto, desc: "Fuel Tank IDs\nLeave empty to collect total fuel")]
7  protected ref array<int> m_aFuelTankIDs;
8 
9  [Attribute(defvalue: "10", uiwidget: UIWidgets.Auto, desc: "Reserve fuel error level\n[%]", params: "0 100 0")]
10  protected float m_fReserveFuelLevel;
11 
12  [Attribute(defvalue: "25", uiwidget: UIWidgets.Auto, desc: "Low fuel warning level\n[%]", params: "0 100 0")]
13  protected float m_fLowFuelLevel;
14 
15  // TODO: Specific fuel tank IDs, -1 for total fuel - can track fuel leaks when IDs are provided.
16  protected FuelManagerComponent m_pFuelManager;
17  protected ref array<BaseFuelNode> m_aFuelTanks = {};
18 
19  //------------------------------------------------------------------------------------------------
21  override bool IsBlinking()
22  {
23  SCR_FuelNode scrFuelTank;
24  foreach (BaseFuelNode fuelTank : m_aFuelTanks)
25  {
26  scrFuelTank = SCR_FuelNode.Cast(fuelTank);
27  if (scrFuelTank && scrFuelTank.GetLeakableFuel() > 0)
28  return true;
29  }
30  return false;
31  }
32 
33  //------------------------------------------------------------------------------------------------
35  override EVehicleInfoState GetState()
36  {
37  #ifdef SHOW_DMG_INDICATORS_ERROR
38  return EVehicleInfoState.ERROR;
39  #endif
40 
41  #ifdef SHOW_DMG_INDICATORS_WARNING
42  return EVehicleInfoState.WARNING;
43  #endif
44 
45  if (!m_pFuelManager)
46  return EVehicleInfoState.DISABLED;
47 
48  // BLINKING: currently leaking
49  // register to an event. If leaking, return blinking
50 
51  float fuel = 1;
52  float maxFuel;
53  if (m_aFuelTanks.IsEmpty())
54  {
55  fuel = m_pFuelManager.GetTotalFuel();
56  maxFuel = m_pFuelManager.GetTotalMaxFuel();
57  }
58  else
59  {
60  // Analyze all connected fuel tanks
61  foreach (BaseFuelNode fuelTank : m_aFuelTanks)
62  {
63  fuel += fuelTank.GetFuel();
64  maxFuel += fuelTank.GetMaxFuel();
65  }
66  }
67 
68  if (maxFuel > 0)
69  fuel /= maxFuel;
70 
71  // ERROR: < reserve fuel
72  // WARNING: < low fuel or leaking
73  if (fuel <= m_fReserveFuelLevel * 0.01)
74  return EVehicleInfoState.ERROR;
75  else if (fuel <= m_fLowFuelLevel * 0.01)
76  return EVehicleInfoState.WARNING;
77  else if (IsBlinking())
78  return EVehicleInfoState.WARNING;
79 
80  return EVehicleInfoState.DISABLED;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  override bool DisplayStartDrawInit(IEntity owner)
85  {
86  // Terminate if there is no fuel manager
87  if (!m_pFuelManager)
88  return false;
89 
90  return super.DisplayStartDrawInit(owner);
91  }
92 
93  //------------------------------------------------------------------------------------------------
95  override void DisplayInit(IEntity owner)
96  {
97  super.DisplayInit(owner);
98 
99  m_pFuelManager = FuelManagerComponent.Cast(owner.FindComponent(FuelManagerComponent));
100 
101  array<BaseFuelNode> fuelTanks = {};
102  int count = m_pFuelManager.GetFuelNodesList(fuelTanks);
103 
104  if (m_aFuelTankIDs.IsEmpty())
105  {
106  m_aFuelTanks.InsertAll(fuelTanks);
107  return;
108  }
109 
110  foreach (int fuelTankID : m_aFuelTankIDs)
111  {
112  if (fuelTanks.IsIndexValid(fuelTankID))
113  m_aFuelTanks.Insert(fuelTanks[fuelTankID]);
114  }
115  }
116 };
SCR_BaseVehicleInfo
Base class for all vehicle UI state and damage indicators.
Definition: SCR_BaseVehicleInfo.c:28
BaseFuelNode
Definition: BaseFuelNode.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
EVehicleInfoState
EVehicleInfoState
UI indicator state, controlling colors and opacity.
Definition: SCR_BaseVehicleInfo.c:5
SCR_FuelTankInfo
Definition: SCR_FuelTankInfo.c:4