4 private static float m_FuelTankCapacity;
5 private static float m_FuelToEnergyRatio;
6 private int m_FuelPercentage;
8 static const string START_SOUND =
"powerGeneratorTurnOn_SoundSet";
9 static const string LOOP_SOUND =
"powerGeneratorLoop_SoundSet";
10 static const string STOP_SOUND =
"powerGeneratorTurnOff_SoundSet";
11 static const string SPARKPLUG_ATTACH_SOUND =
"sparkplug_attach_SoundSet";
12 static const string SPARKPLUG_DETACH_SOUND =
"sparkplug_detach_SoundSet";
17 ref
Timer m_SoundLoopStartTimer;
18 ref
protected Effect m_Smoke;
31 m_FuelPercentage = 50;
32 RegisterNetSyncVariableInt(
"m_FuelPercentage");
33 RegisterNetSyncVariableBool(
"m_IsSoundSynchRemote");
34 RegisterNetSyncVariableBool(
"m_IsPlaceSound");
65 m_FuelPercentage = GetCompEM().GetEnergy0To100();
82 if (GetCompEM().IsWorking())
84 PlaySoundSetLoop(m_EngineLoop, LOOP_SOUND, 0, 0);
87 vector local_pos =
"0.3 0.21 0.4";
88 vector local_ori =
"270 0 0";
98 if (!super.CanPutInCargo(parent))
103 return CanManipulate();
109 if(!super.CanPutIntoHands(parent))
113 return CanManipulate();
119 return GetCompEM().GetPluggedDevicesCount() == 0 && !GetCompEM().IsWorking();
127 override void OnInitEnergy()
129 m_FuelTankCapacity =
GetGame().ConfigGetFloat (
"CfgVehicles " +
GetType() +
" fuelTankCapacity");
130 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
142 PlaySoundSet(m_EngineStart, START_SOUND, 0, 0);
145 if (!m_SoundLoopStartTimer)
150 if (!m_SoundLoopStartTimer.IsRunning())
152 m_SoundLoopStartTimer.Run(1.5,
this,
"StartLoopSound", NULL,
false);
163 override void OnWork(
float consumed_energy)
172 m_FuelPercentage = GetCompEM().GetEnergy0To100();
185 PlaySoundSet(m_EngineStop, STOP_SOUND, 0, 0);
186 StopSoundSet(m_EngineLoop);
204 super.OnItemLocationChanged(old_owner, new_owner);
210 super.EEItemAttached(item, slot_name);
211 GetCompEM().InteractBranch(
this);
217 ShowSelection(
"sparkplug_installed");
221 sound.SetAutodestroy(
true );
228 super.EEItemDetached(item, slot_name);
230 GetCompEM().InteractBranch(
this);
234 if (item_IB.IsKindOf(
"Sparkplug"))
236 HideSelection(
"sparkplug_installed");
237 GetCompEM().SwitchOff();
241 sound.SetAutodestroy(
true);
250 void UpdateFuelMeter()
254 SetAnimationPhase(
"dial_fuel", m_FuelPercentage * 0.01);
259 void SetFuel(
float fuel_amount)
261 if (m_FuelTankCapacity > 0)
263 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
264 GetCompEM().SetEnergy(fuel_amount * m_FuelToEnergyRatio);
265 m_FuelPercentage = GetCompEM().GetEnergy0To100();
271 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());
278 float AddFuel(
float available_fuel)
280 if (available_fuel == 0)
284 GetCompEM().InteractBranch(
this);
285 float needed_fuel = GetMaxFuel() - GetFuel();
287 if (needed_fuel > available_fuel)
289 SetFuel(GetFuel() + available_fuel);
290 return available_fuel;
294 SetFuel(GetMaxFuel());
305 int liquid_type = container.GetLiquidType();
308 if ( container.GetQuantity() > 0 && GetCompEM().
GetEnergy() < GetCompEM().GetEnergyMax() && (liquid_type &
LIQUID_GASOLINE))
320 return GetCompEM().GetEnergy() / m_FuelToEnergyRatio;
326 return m_FuelTankCapacity;
333 EntityAI ent = GetInventory().FindAttachment(slot);
335 return ent && !ent.IsRuined();
340 super.OnVariablesSynchronized();
356 super.OnPlacementComplete(player, position, orientation);
363 return "placePowerGenerator_SoundSet";
381 if (
Class.CastTo(entity,
this))
383 entity.GetInventory().CreateInInventory(
"SparkPlug");
386 SetFuel(GetMaxFuel());