Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RefuelAtSupportStationAction.c
Go to the documentation of this file.
2 {
3  [Attribute("#AR-SupportStation_Fuel_ActionInvalid_FuelFull", desc: "Text shown on action if fuel tank already full", uiwidget: UIWidgets.LocaleEditBox)]
4  protected LocalizedString m_sInvalidFullTank;
5 
6  [Attribute("#AR-SupportStation_Fuel_ActionInvalid_FuelProviderNoFuel", desc: "There are fuel refuel stations near by but non have fuel in their tank", uiwidget: UIWidgets.LocaleEditBox)]
7  protected LocalizedString m_sInvalidFuelActionReason;
8 
9  [Attribute("#AR-SupportStation_Fuel_ActionInvalid_FuelCanisterEmpty", desc: "The player is holding a fuel canister but cannot refuel as it is empty", uiwidget: UIWidgets.LocaleEditBox)]
10  protected LocalizedString m_sInvalidReasonFuelCanisterEmpty;
11 
12  [Attribute(desc: "IDs of fuel tanks linked to this refuel action. Leave empty if all fuel tanks are valid")];
13  protected ref array<int> m_aFuelTankIDs;
14 
15  [Attribute("1", desc: "Decimal count of action percentage. Put on 2 if the entity has a large fuel tank", params: "0 2")]
16  protected int m_iActionDecimalCount;
17 
18  protected SCR_FuelManagerComponent m_FuelManager;
19 
20  //------------------------------------------------------------------------------------------------
21  protected override ESupportStationType GetSupportStationType()
22  {
23  return ESupportStationType.FUEL;
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  void GetFuelTankIDs(array<int> fuelTankIDs)
28  {
29  fuelTankIDs.Copy(m_aFuelTankIDs);
30  }
31 
32  //------------------------------------------------------------------------------------------------
38  bool CheckIfFuelNodeIsValid(SCR_FuelNode fuelNode)
39  {
40  return !fuelNode || m_aFuelTankIDs.IsEmpty() || m_aFuelTankIDs.Contains(fuelNode.GetFuelTankID());
41  }
42 
43  //------------------------------------------------------------------------------------------------
47  int GetValidFuelNodesCount()
48  {
49  return m_aFuelTankIDs.Count();
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
54  {
55  m_FuelManager = SCR_FuelManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_FuelManagerComponent));
56  if (!m_FuelManager)
57  Print("'SCR_RefuelAtSupportStationAction': '" + pOwnerEntity.GetName() + "' is missing SCR_FuelManager!", LogLevel.WARNING);
58 
59  super.Init(pOwnerEntity, pManagerComponent);
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected override LocalizedString GetInvalidPerformReasonString(ESupportStationReasonInvalid reasonInvalid)
64  {
65  //~ Fuel station out of fuel
66  if (reasonInvalid == ESupportStationReasonInvalid.NO_FUEL_TO_GIVE)
67  return m_sInvalidFuelActionReason;
68  else if (reasonInvalid == ESupportStationReasonInvalid.FUEL_TANK_FULL)
69  return m_sInvalidFullTank;
70  else if (reasonInvalid == ESupportStationReasonInvalid.FUEL_CANISTER_EMPTY)
71  return m_sInvalidReasonFuelCanisterEmpty;
72 
73  return super.GetInvalidPerformReasonString(reasonInvalid);
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  override bool CanBeShownScript(IEntity user)
78  {
79  if (!m_FuelManager)
80  return false;
81 
82  return super.CanBeShownScript(user);
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  //~ TODO: Overwrite GetClosestValidSupportStation and simply return the support station from which the player is holding the nozzle!
87  //~ This way all the same functions and checks can be used and you don't need to create a whole new system for nozzle interaction
88  //~ Make sure the GetNozzle action sets a reference somewhere to the Fuel SupportStation that is attached and pass it here!
89  //~ Would advice to simply use the same functions as supply cost and things like flow, notifications, players in vehicle and all that has already been taken care of!
90  //~ Add new ESupportStationReasonInvalid for: NO_NOZZLE if not holding any and potentially, INCORRECT FUEL TYPE
91  //~ Update the GetInvalidPerformReasonString() and by extention ESupportStationReasonInvalid to include the two new ReasonInvalid and all is taken care of
92  /*
93  protected override SCR_BaseSupportStationComponent GetClosestValidSupportStation(IEntity actionOwner, IEntity actionUser, out ESupportStationReasonInvalid reasonInvalid = 0)
94  {
95  Use this function to get the SCR_FuelSupportStationComponent from which the player holds the nozzle
96 
97  Call: SCR_FuelSupportStationComponent.IsValid();
98 
99  You can also potentially check here if fuel type is correct
100  }
101  */
102 
103  //------------------------------------------------------------------------------------------------
104  protected override bool PrioritizeHeldGadget()
105  {
106  return true;
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override bool CanBePerformedScript(IEntity user)
111  {
112  bool canRefuel = true;
113 
114  if (!m_FuelManager)
115  {
116  canRefuel = false;
117  return false;
118  }
119 
120  if (m_aFuelTankIDs.IsEmpty())
121  {
122  if (!m_FuelManager.CanBeRefueledScripted(m_aFuelTankIDs))
123  canRefuel = false;
124  }
125  else
126  {
127  canRefuel = false;
128 
129  array<BaseFuelNode> nodes = {};
130  m_FuelManager.GetFuelNodesList(nodes);
131  SCR_FuelNode scrNode;
132 
133  foreach (BaseFuelNode node : nodes)
134  {
135  scrNode = SCR_FuelNode.Cast(node);
136 
137  if (!CheckIfFuelNodeIsValid(scrNode))
138  continue;
139 
140  if (node.GetFuel() < node.GetMaxFuel())
141  {
142  canRefuel = true;
143  break;
144  }
145  }
146  }
147 
148  if (!canRefuel)
149  {
150  SetCanPerform(false, ESupportStationReasonInvalid.FUEL_TANK_FULL);
151  return false;
152  }
153 
154  canRefuel = super.CanBePerformedScript(user);
155  return canRefuel;
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected override int GetActionDecimalCount()
160  {
161  return m_iActionDecimalCount;
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  protected override float GetActionPercentage()
166  {
167  if (!m_bCanPerform)
168  return int.MIN;
169 
170  float fuelPercentage;
171  int validFuelNodes;
172 
173  array<BaseFuelNode> nodes = {};
174  m_FuelManager.GetFuelNodesList(nodes);
175  SCR_FuelNode scrNode;
176 
177  foreach (BaseFuelNode node : nodes)
178  {
179  scrNode = SCR_FuelNode.Cast(node);
180 
181  if (!CheckIfFuelNodeIsValid(scrNode))
182  continue;
183 
184  fuelPercentage += node.GetFuel() / node.GetMaxFuel();
185  validFuelNodes++;
186  }
187 
188  if (validFuelNodes <= 0)
189  return 0;
190 
191  return (fuelPercentage / validFuelNodes) * 100;
192  }
193 };
BaseFuelNode
Definition: BaseFuelNode.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
ESupportStationReasonInvalid
ESupportStationReasonInvalid
Definition: ESupportStationReasonInvalid.c:3
m_FuelManager
protected FuelManagerComponent m_FuelManager
Definition: SCR_VehicleDamageManagerComponent.c:215
Attribute
typedef Attribute
Post-process effect of scripted camera.
ESupportStationType
ESupportStationType
Definition: ESupportStationType.c:2
SCR_FuelManagerComponent
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_FuelManagerComponent.c:475
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_BaseUseSupportStationAction
Definition: SCR_BaseUseSupportStationAction.c:1
LocalizedString
Definition: LocalizedString.c:21
SCR_RefuelAtSupportStationAction
Definition: SCR_RefuelAtSupportStationAction.c:1