1 [
EntityEditorProps(
category:
"GameScripted/ScriptWizard", description:
"SCR_FuelConsumptionComponent", color:
"0 0 255 255")]
4 [
Attribute( defvalue:
"1", uiwidget: UIWidgets.CheckBox,
desc:
"Automatic fuel tank switching. Automatically select next fuel tank upon depletion of current fuel tank." )]
5 bool m_bAutomaticFuelTankSwitching;
7 [
Attribute( defvalue:
"20", uiwidget: UIWidgets.Auto,
desc:
"Fuel consumption at max power RPM\n[liters/hour]" )]
8 float m_fFuelConsumption;
10 [
Attribute( defvalue:
"0.5", uiwidget: UIWidgets.Auto,
desc:
"Fuel consumption idle\n[liters/hour]" )]
11 float m_fFuelConsumptionIdle;
14 class SCR_FuelConsumptionComponent : ScriptGameComponent
31 protected static float s_fGlobalFuelConsumptionScale = 8;
37 static void SetGlobalFuelConsumptionScale(
float globalFuelConsumptionScale,
int playerThatChangedValue = -1)
39 if (s_fGlobalFuelConsumptionScale == globalFuelConsumptionScale || globalFuelConsumptionScale < 0)
43 if (!gameMode || gameMode.IsMaster())
46 if (playerThatChangedValue > 0)
47 SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(
ENotification.EDITOR_CHANGED_FUEL_CONSUMPTION_SCALE, playerThatChangedValue, globalFuelConsumptionScale * 100);
49 s_fGlobalFuelConsumptionScale = globalFuelConsumptionScale;
55 static float GetGlobalFuelConsumptionScale()
57 return s_fGlobalFuelConsumptionScale;
81 FuelManagerComponent fuelManager = FuelManagerComponent.Cast(
GetOwner().FindComponent(FuelManagerComponent));
85 array<BaseFuelNode> nodes = {};
86 fuelManager.GetFuelNodesList(nodes);
91 scrNode = SCR_FuelNode.Cast(node);
92 if (scrNode && scrNode.GetFuelTankID() == iFuelTankID)
103 FuelManagerComponent fuelManager = FuelManagerComponent.Cast(
GetOwner().FindComponent(FuelManagerComponent));
107 array<BaseFuelNode> nodes = {};
108 fuelManager.GetFuelNodesList(nodes);
111 if (node && node.GetFuel() >
MIN_FUEL)
126 RplComponent rpl = RplComponent.Cast(
GetOwner().FindComponent(RplComponent));
127 if (rpl && rpl.IsProxy())
161 float currentConsumption;
165 VehicleWheeledSimulation wheeledSimulation = VehicleWheeledSimulation.Cast(
m_Simulation);
166 if (wheeledSimulation)
168 float throttle = wheeledSimulation.GetThrottle();
170 currentConsumption =
m_ComponentData.m_fFuelConsumption * throttle * wheeledSimulation.EngineGetRPM() / wheeledSimulation.EngineGetRPMPeakTorque();
172 currentConsumption =
m_ComponentData.m_fFuelConsumptionIdle * wheeledSimulation.EngineGetRPM() / wheeledSimulation.EngineGetRPMIdle();
177 VehicleHelicopterSimulation helicopterSimulation = VehicleHelicopterSimulation.Cast(
m_Simulation);
178 if (helicopterSimulation)
186 float newFuel =
m_CurrentFuelTank.GetFuel() - currentConsumption * consumptionScale;
189 if (wheeledSimulation && currentConsumption > 0 && DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_VEHICLES_FUEL_CONSUMPTION))
191 float throttle = wheeledSimulation.GetThrottle();
192 float speed = wheeledSimulation.GetSpeedKmh();
195 if (s_fGlobalFuelConsumptionScale != 0 && currentConsumption != 0)
196 range = speed * newFuel / (currentConsumption * s_fGlobalFuelConsumptionScale);
200 float litersPer100KM;
202 litersPer100KM = currentConsumption * 100 / speed;
206 Print(currentConsumption);
209 Print(litersPer100KM);
211 #endif // ENABLE_DIAG
216 VehicleWheeledSimulation_SA wheeledSimulation = VehicleWheeledSimulation_SA.Cast(
m_Simulation);
217 if (wheeledSimulation)
219 float throttle = wheeledSimulation.GetThrottle();
221 currentConsumption =
m_ComponentData.m_fFuelConsumption * throttle * wheeledSimulation.EngineGetRPM() / wheeledSimulation.EngineGetRPMPeakTorque();
223 currentConsumption =
m_ComponentData.m_fFuelConsumptionIdle * wheeledSimulation.EngineGetRPM() / wheeledSimulation.EngineGetRPMIdle();
228 VehicleHelicopterSimulation helicopterSimulation = VehicleHelicopterSimulation.Cast(
m_Simulation);
229 if (helicopterSimulation)
237 float newFuel =
m_CurrentFuelTank.GetFuel() - currentConsumption * consumptionScale;
240 if (wheeledSimulation && currentConsumption > 0 && DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_VEHICLES_FUEL_CONSUMPTION))
242 float throttle = wheeledSimulation.GetThrottle();
243 float speed = wheeledSimulation.GetSpeedKmh();
246 if (s_fGlobalFuelConsumptionScale != 0 && currentConsumption != 0)
247 range = speed * newFuel / (currentConsumption * s_fGlobalFuelConsumptionScale);
251 float litersPer100KM;
253 litersPer100KM = currentConsumption * 100 / speed;
257 Print(currentConsumption);
260 Print(litersPer100KM);
262 #endif // ENABLE_DIAG
270 VehicleControllerComponent controller = VehicleControllerComponent.Cast(
GetOwner().FindComponent(VehicleControllerComponent));
273 controller.StopEngine(
false);
278 VehicleControllerComponent_SA controller = VehicleControllerComponent_SA.Cast(
GetOwner().FindComponent(VehicleControllerComponent_SA));
281 controller.StopEngine(
false);
292 World world =
GetOwner().GetWorld();
297 updateSystem.Register(
this);
304 World world =
GetOwner().GetWorld();
309 updateSystem.Unregister(
this);
333 RplComponent rpl = RplComponent.Cast(owner.FindComponent(RplComponent));
334 if (rpl && !rpl.IsProxy())
335 SetEventMask(owner, EntityEvent.INIT);
341 FuelManagerComponent fuelManager = FuelManagerComponent.Cast(owner.FindComponent(FuelManagerComponent));
347 m_Simulation = VehicleBaseSimulation.Cast(owner.FindComponent(VehicleBaseSimulation));
357 VehicleWheeledSimulation wheeledSimulation = VehicleWheeledSimulation.Cast(
m_Simulation);
358 if (wheeledSimulation && wheeledSimulation.EngineIsOn())
363 VehicleWheeledSimulation_SA wheeledSimulation = VehicleWheeledSimulation_SA.Cast(
m_Simulation);
364 if (wheeledSimulation && wheeledSimulation.EngineIsOn())
369 VehicleHelicopterSimulation helicopterSimulation = VehicleHelicopterSimulation.Cast(
m_Simulation);
370 if (helicopterSimulation && helicopterSimulation.EngineIsOn())
374 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_VEHICLES_FUEL_CONSUMPTION,
"",
"Fuel consumption",
"Vehicles");
375 #endif // ENABLE_DIAG
383 super.OnDelete(owner);