1class PowerGeneratorBase
extends ItemBase
4 private static float m_FuelTankCapacity;
5 private static float m_FuelToEnergyRatio;
6 private int m_FuelPercentage;
8 protected const float LOW_ENERGY_FUEL_PERCENTAGE = 20;
9 static const string START_SOUND =
"powerGeneratorTurnOn_SoundSet";
10 static const string LOOP_SOUND =
"powerGeneratorLoop_SoundSet";
11 protected const string LOOP_LOW_FUEL_SOUND =
"powerGenerator_low_Fuel_Loop_SoundSet";
12 static const string STOP_SOUND =
"powerGeneratorTurnOff_SoundSet";
13 static const string SPARKPLUG_ATTACH_SOUND =
"sparkplug_attach_SoundSet";
14 static const string SPARKPLUG_DETACH_SOUND =
"sparkplug_detach_SoundSet";
27 protected ref UniversalTemperatureSourceLambdaConstant
m_UTSLEngine;
34 m_FuelPercentage = 50;
35 RegisterNetSyncVariableInt(
"m_FuelPercentage");
56 m_UTSLEngine =
new UniversalTemperatureSourceLambdaConstant();
65 m_FuelPercentage = GetCompEM().GetEnergy0To100();
79 return "0.3 0.21 0.4";
92 if (GetCompEM().IsWorking())
95 PlaySoundSetLoop(m_EngineLoop, LOOP_LOW_FUEL_SOUND, 0.3, 0.3);
97 PlaySoundSetLoop(m_EngineLoop, LOOP_SOUND, 0.3, 0.3);
109 if (!super.CanPutInCargo(parent))
114 return CanManipulate();
120 if(!super.CanPutIntoHands(parent))
124 return CanManipulate();
130 return GetCompEM().GetPluggedDevicesCount() == 0 && !GetCompEM().IsWorking();
140 m_FuelTankCapacity =
GetGame().ConfigGetFloat (
"CfgVehicles " +
GetType() +
" fuelTankCapacity");
141 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
153 PlaySoundSet(m_EngineStart, START_SOUND, 0, 0);
156 if (!m_SoundLoopStartTimer)
161 if (!m_SoundLoopStartTimer.IsRunning())
163 m_SoundLoopStartTimer.Run(1.5,
this,
"StartLoopSound", NULL,
false);
174 override void OnWork(
float consumed_energy)
183 m_FuelPercentage = GetCompEM().GetEnergy0To100();
187 if (m_FuelPercentage < LOW_ENERGY_FUEL_PERCENTAGE && !m_IsLowEnergy)
188 SetLowEnergyState(
true);
189 else if (m_FuelPercentage >= LOW_ENERGY_FUEL_PERCENTAGE && m_IsLowEnergy)
190 SetLowEnergyState(
false);
201 PlaySoundSet(m_EngineStop, STOP_SOUND, 0, 0);
202 StopSoundSet(m_EngineLoop);
220 super.OnItemLocationChanged(old_owner, new_owner);
226 super.EEItemAttached(item, slot_name);
227 GetCompEM().InteractBranch(
this);
233 ShowSelection(
"sparkplug_installed");
244 super.EEItemDetached(item, slot_name);
246 GetCompEM().InteractBranch(
this);
250 if (item_IB.IsKindOf(
"Sparkplug"))
252 HideSelection(
"sparkplug_installed");
253 GetCompEM().SwitchOff();
268 m_IsLowEnergy = state;
272 StopSoundSet(m_EngineLoop);
281 SetAnimationPhase(
"dial_fuel", m_FuelPercentage * 0.01);
289 if (GetFuel() == 0.0 && fuel_amount <= 0.0)
292 if (m_FuelTankCapacity > 0)
294 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
295 GetCompEM().SetEnergy(fuel_amount * m_FuelToEnergyRatio);
296 m_FuelPercentage = GetCompEM().GetEnergy0To100();
302 string error =
string.Format(
"ERROR! Item %1 has fuel tank with 0 capacity! Add parameter 'fuelTankCapacity' to its config and set it to more than 0!", this.
GetType());
311 if (available_fuel == 0.0)
314 GetCompEM().InteractBranch(
this);
315 float needed_fuel = GetMaxFuel() - GetFuel();
317 if (needed_fuel > available_fuel)
319 SetFuel(GetFuel() + available_fuel);
320 return available_fuel;
324 SetFuel(GetMaxFuel());
335 int liquid_type = container.GetLiquidType();
338 if ( container.GetQuantity() > 0 && GetCompEM().
GetEnergy() < GetCompEM().GetEnergyMax() && (liquid_type &
LIQUID_GASOLINE))
350 return Math.Clamp(GetCompEM().
GetEnergy() / m_FuelToEnergyRatio, 0.0, GetMaxFuel());
356 return m_FuelTankCapacity;
361 return m_FuelPercentage;
368 EntityAI ent = GetInventory().FindAttachment(slot);
370 return ent && !ent.IsRuined();
375 super.OnVariablesSynchronized();
386 return "placePowerGenerator_SoundSet";
404 if (
Class.CastTo(entity,
this))
406 entity.GetInventory().CreateInInventory(
"SparkPlug");
409 SetFuel(GetMaxFuel());
421 super.GetDebugActions(outputList);
426 if (super.OnAction(action_id, player, ctx))
435 SetFuel(GetMaxFuel());
440 case EActions.GENERIC_FUEL_INCREASE:
441 AddFuel(
Math.Clamp(GetMaxFuel() * 0.1, 0.0, GetMaxFuel()));
443 case EActions.GENERIC_FUEL_DECREASE:
444 float value = GetMaxFuel() * 0.1;
451 SetFuel(GetFuel() - value);
460class PowerGenerator
extends PowerGeneratorBase {}
Param4< int, int, string, int > TSelectableActionInfoWithColor
eBleedingSourceType GetType()
ActionPlaceObjectCB ActiondeployObjectCB ActionPlaceObject()
void AddAction(typename actionName)
ref UniversalTemperatureSourceLambdaEngine m_UTSLEngine
Super root of all classes in Enforce script.
Wrapper class for managing sound through SEffectManager.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
provides access to slot configuration
override void EEItemAttached(EntityAI item, string slot_name)
override void OnWork(float consumed_energy)
override void OnWorkStart()
void SetFuel(float fuel_amount)
void PowerGeneratorBase()
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
override bool CanPutIntoHands(EntityAI parent)
override void SetActions()
override void OnInitEnergy()
EffectSound m_EngineStart
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
ref UniversalTemperatureSourceLambdaConstant m_UTSLEngine
override string GetDeploySoundset()
override void OnWorkStop()
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
float GetFuelPercentage()
override float GetLiquidThroughputCoef()
override void EEItemDetached(EntityAI item, string slot_name)
override void OnVariablesSynchronized()
override bool CanPutInCargo(EntityAI parent)
override void OnDebugSpawn()
vector GetSmokeParticleOrientation()
ref Timer m_SoundLoopStartTimer
float AddFuel(float available_fuel)
vector GetSmokeParticlePosition()
void ~PowerGeneratorBase()
void SetLowEnergyState(bool state)
override void EOnInit(IEntity other, int extra)
bool CanAddFuel(ItemBase container)
Manager class for managing Effect (EffectParticle, EffectSound)
static int PlayOnObject(notnull Effect eff, Object obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_relative_to_world=false)
Play an Effect.
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
original Timer deletes m_params which is unwanted
override bool IsInitialized()
ref UniversalTemperatureSourceSettings m_UTSSettings
ref UniversalTemperatureSource m_UTSource
proto native CGame GetGame()
proto void DPrint(string var)
Prints content of variable to console/log. Should be used for critical messages so it will appear in ...
EntityEvent
Entity events for event-mask, or throwing event from code.
const float LIQUID_THROUGHPUT_GENERATOR
const int SAT_DEBUG_ACTION
class JsonUndergroundAreaTriggerData GetPosition