Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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)]
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)]
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)]
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
19
20 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
48 {
49 return m_aFuelTankIDs.Count();
50 }
51
52 //------------------------------------------------------------------------------------------------
53 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
54 {
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 //------------------------------------------------------------------------------------------------
64 {
65 //~ Fuel station out of fuel
66 if (reasonInvalid == ESupportStationReasonInvalid.NO_FUEL_TO_GIVE)
68 else if (reasonInvalid == ESupportStationReasonInvalid.FUEL_TANK_FULL)
69 return m_sInvalidFullTank;
70 else if (reasonInvalid == ESupportStationReasonInvalid.FUEL_CANISTER_EMPTY)
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 Physics rootPhysics = GetOwner().GetRootParent().GetPhysics(); // Getting root parent to ensure slotted entities get the intended behaviour
115 if (rootPhysics && rootPhysics.GetVelocity().LengthSq() > MAXIMUM_VEHICLE_SPEED_FOR_INTERACTION_SQ)
116 {
118 return false;
119 }
120
121 if (!m_FuelManager)
122 {
123 canRefuel = false;
124 return false;
125 }
126
127 if (m_aFuelTankIDs.IsEmpty())
128 {
129 if (!m_FuelManager.CanBeRefueledScripted(m_aFuelTankIDs))
130 canRefuel = false;
131 }
132 else
133 {
134 canRefuel = false;
135
136 array<BaseFuelNode> nodes = {};
137 m_FuelManager.GetFuelNodesList(nodes);
138 SCR_FuelNode scrNode;
139
140 foreach (BaseFuelNode node : nodes)
141 {
142 scrNode = SCR_FuelNode.Cast(node);
143
144 if (!CheckIfFuelNodeIsValid(scrNode))
145 continue;
146
147 if (node.GetFuel() < node.GetMaxFuel())
148 {
149 canRefuel = true;
150 break;
151 }
152 }
153 }
154
155 if (!canRefuel)
156 {
157 SetCanPerform(false, ESupportStationReasonInvalid.FUEL_TANK_FULL);
158 return false;
159 }
160
161 canRefuel = super.CanBePerformedScript(user);
162 return canRefuel;
163 }
164
165 //------------------------------------------------------------------------------------------------
166 protected override int GetActionDecimalCount()
167 {
169 }
170
171 //------------------------------------------------------------------------------------------------
172 protected override float GetActionPercentage()
173 {
174 if (!m_bCanPerform)
175 return int.MIN;
176
177 float fuelPercentage;
178 int validFuelNodes;
179
180 array<BaseFuelNode> nodes = {};
181 m_FuelManager.GetFuelNodesList(nodes);
182 SCR_FuelNode scrNode;
183
184 foreach (BaseFuelNode node : nodes)
185 {
186 scrNode = SCR_FuelNode.Cast(node);
187
188 if (!CheckIfFuelNodeIsValid(scrNode))
189 continue;
190
191 fuelPercentage += node.GetFuel() / node.GetMaxFuel();
192 validFuelNodes++;
193 }
194
195 if (validFuelNodes <= 0)
196 return 0;
197
198 return (fuelPercentage / validFuelNodes) * 100;
199 }
200};
ESupportStationType
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external Managed FindComponent(typename typeName)
proto external Physics GetPhysics()
proto external string GetName()
proto external IEntity GetRootParent()
void SetCanPerform(bool canPerform, ESupportStationReasonInvalid reasonInvalid)
override LocalizedString GetInvalidPerformReasonString(ESupportStationReasonInvalid reasonInvalid)
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override ESupportStationType GetSupportStationType()
IEntity GetOwner()
Owner entity of the fuel tank.
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
SCR_FieldOfViewSettings Attribute