DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PowerGenerator.c
См. документацию.
1class PowerGeneratorBase extends ItemBase
2{
3 float m_Fuel;
4 private static float m_FuelTankCapacity; // Capacity in ml.
5 private static float m_FuelToEnergyRatio; // Conversion ratio of 1 ml of fuel to X Energy
6 private int m_FuelPercentage;
7
8 protected const float LOW_ENERGY_FUEL_PERCENTAGE = 20; // how much % of fuel has to remain to trigger low fuel state
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
14 protected bool m_IsLowEnergy;
19 ref protected Effect m_Smoke;
20
22
25 protected ref UniversalTemperatureSourceLambdaConstant m_UTSLEngine;
26
27 // Constructor
29 {
30 SetEventMask(EntityEvent.INIT); // Enable EOnInit event
31
33 RegisterNetSyncVariableInt("m_FuelPercentage");
34 }
35
40
41 override void EEInit()
42 {
43 super.EEInit();
44
45 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
46 {
48 m_UTSSettings.m_ManualUpdate = true;
50 m_UTSSettings.m_TemperatureCap = 8;
51 m_UTSSettings.m_RangeFull = 1;
52 m_UTSSettings.m_RangeMax = 2.5;
53
54 m_UTSLEngine = new UniversalTemperatureSourceLambdaConstant();
56 }
57 }
58
59 override void EOnInit(IEntity other, int extra)
60 {
61 if (g_Game.IsServer())
62 {
63 m_FuelPercentage = GetCompEM().GetEnergy0To100();
64 SetSynchDirty();
65 }
66
68 }
69
70 override float GetLiquidThroughputCoef()
71 {
73 }
74
76 {
77 return "0.3 0.21 0.4";
78 }
79
81 {
82 return "270 0 0";
83 }
84
85 // Play the loop sound
87 {
88 if (g_Game.IsClient() || !g_Game.IsMultiplayer())
89 {
90 if (GetCompEM().IsWorking())
91 {
92 if (m_IsLowEnergy)
93 PlaySoundSetLoop(m_EngineLoop, LOOP_LOW_FUEL_SOUND, 0.3, 0.3);
94 else
95 PlaySoundSetLoop(m_EngineLoop, LOOP_SOUND, 0.3, 0.3);
96
97 // Particle
100 }
101 }
102 }
103
104 // Taking item into inventory
105 override bool CanPutInCargo( EntityAI parent )
106 {
107 if (!super.CanPutInCargo(parent))
108 {
109 return false;
110 }
111
112 return CanManipulate();
113 }
114
115 // Taking item into inventory
116 override bool CanPutIntoHands(EntityAI parent)
117 {
118 if(!super.CanPutIntoHands(parent))
119 {
120 return false;
121 }
122 return CanManipulate();
123 }
124
125 // Returns true/false if this item can be moved into inventory/hands
127 {
128 return GetCompEM().GetPluggedDevicesCount() == 0 && !GetCompEM().IsWorking();
129 }
130
131 /*===================================
132 EVENTS
133 ===================================*/
134
135 // Init
136 override void OnInitEnergy()
137 {
138 m_FuelTankCapacity = g_Game.ConfigGetFloat ("CfgVehicles " + GetType() + " fuelTankCapacity");
139 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity; // Conversion ratio of 1 ml of fuel to X Energy
140
142 }
143
144 // Generator is working
145 override void OnWorkStart()
146 {
147 if (g_Game.IsClient() || !g_Game.IsMultiplayer())
148 {
149 if (IsInitialized())
150 {
151 PlaySoundSet(m_EngineStart, START_SOUND, 0, 0);
152 }
153
155 {
157 }
158
159 if (!m_SoundLoopStartTimer.IsRunning()) // Makes sure the timer is NOT running already
160 {
161 m_SoundLoopStartTimer.Run(1.5, this, "StartLoopSound", NULL, false);
162 }
163 }
164
165 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
166 {
167 m_UTSource.SetDefferedActive(true, 20.0);
168 }
169 }
170
171 // Do work
172 override void OnWork(float consumed_energy)
173 {
174 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
175 {
177 }
178
179 if (g_Game.IsServer())
180 {
181 m_FuelPercentage = GetCompEM().GetEnergy0To100();
182 SetSynchDirty();
183 }
184
186 SetLowEnergyState(true);
188 SetLowEnergyState(false);
189
191 }
192
193 // Turn off when this runs out of fuel
194 override void OnWorkStop()
195 {
196 if (g_Game.IsClient() || !g_Game.IsMultiplayer())
197 {
198 // Sound
199 PlaySoundSet(m_EngineStop, STOP_SOUND, 0, 0);
200 StopSoundSet(m_EngineLoop);
201
202 // particle
204
205 // Fuel meter
207 }
208
209 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
210 {
211 m_UTSource.SetDefferedActive(false, 20.0);
212 }
213 }
214
215 // Called when this generator is picked up
216 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
217 {
218 super.OnItemLocationChanged(old_owner, new_owner);
220 }
221
222 override void EEItemAttached(EntityAI item, string slot_name)
223 {
224 super.EEItemAttached(item, slot_name);
225 GetCompEM().InteractBranch(this);
226
227 ItemBase item_IB = ItemBase.Cast(item);
228 if (item_IB.IsKindOf("Sparkplug") && IsInitialized())
229 {
230 ShowSelection("sparkplug_installed");
231 }
232 }
233
234 override void EEItemDetached(EntityAI item, string slot_name)
235 {
236 super.EEItemDetached(item, slot_name);
237 GetCompEM().InteractBranch(this);
238
239 ItemBase item_IB = ItemBase.Cast(item);
240 if (item_IB.IsKindOf("Sparkplug"))
241 {
242 HideSelection("sparkplug_installed");
243 GetCompEM().SwitchOff();
244 }
245 }
246
247 /*================================
248 FUNCTIONS
249 ================================*/
250
251 protected void SetLowEnergyState(bool state)
252 {
253 m_IsLowEnergy = state;
254
255 if (g_Game.IsClient() || !g_Game.IsMultiplayer())
256 {
257 StopSoundSet(m_EngineLoop);
259 }
260 }
261
263 {
264 if (g_Game.IsClient() || !g_Game.IsMultiplayer())
265 {
266 SetAnimationPhase("dial_fuel", m_FuelPercentage * 0.01);
267 }
268 }
269
270 // Adds energy to the generator
271 void SetFuel(float fuel_amount)
272 {
273 // clamp
274 if (GetFuel() == 0.0 && fuel_amount <= 0.0)
275 return;
276
277 if (m_FuelTankCapacity > 0)
278 {
279 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
280 GetCompEM().SetEnergy(fuel_amount * m_FuelToEnergyRatio);
281 m_FuelPercentage = GetCompEM().GetEnergy0To100();
282 SetSynchDirty();
284 }
285 else
286 {
287 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());
288 DPrint(error);
289 }
290 }
291
292 // Adds fuel (energy) to the generator
293 // Returns how much fuel was accepted
294 float AddFuel(float available_fuel)
295 {
296 if (available_fuel == 0.0)
297 return 0.0;
298
299 GetCompEM().InteractBranch(this);
300 float needed_fuel = GetMaxFuel() - GetFuel();
301
302 if (needed_fuel > available_fuel)
303 {
304 SetFuel(GetFuel() + available_fuel);
305 return available_fuel; // Return used fuel amount
306 }
307 else
308 {
310 return needed_fuel;
311 }
312 }
313
314 // Check the bottle if it can be used to fill the tank
315 bool CanAddFuel(ItemBase container)
316 {
317 if (container)
318 {
319 // Get the liquid
320 int liquid_type = container.GetLiquidType();
321
322 // Do all checks
323 if ( container.GetQuantity() > 0 && GetCompEM().GetEnergy() < GetCompEM().GetEnergyMax() && (liquid_type & LIQUID_GASOLINE))
324 {
325 return true;
326 }
327 }
328
329 return false;
330 }
331
332 // Returns fuel amount
333 float GetFuel()
334 {
335 return Math.Clamp(GetCompEM().GetEnergy() / m_FuelToEnergyRatio, 0.0, GetMaxFuel());
336 }
337
338 // Returns max fuel amount
340 {
341 return m_FuelTankCapacity;
342 }
343
345 {
346 return m_FuelPercentage;
347 }
348
349 // Checks sparkplug
351 {
352 int slot = InventorySlots.GetSlotIdFromString("SparkPlug");
353 EntityAI ent = GetInventory().FindAttachment(slot);
354
355 return ent && !ent.IsRuined();
356 }
357
359 {
360 super.OnVariablesSynchronized();
361
363 }
364
365 //================================================================
366 // ADVANCED PLACEMENT
367 //================================================================
368
369 override string GetDeploySoundset()
370 {
371 return "placePowerGenerator_SoundSet";
372 }
373
384
385 //Debug menu Spawn Ground Special
386 override void OnDebugSpawn()
387 {
388 EntityAI entity;
389 if (Class.CastTo(entity, this))
390 {
391 entity.GetInventory().CreateInInventory("SparkPlug");
392 }
393
395 }
396
397 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
398 {
399 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "PowerGenerator Fuel", FadeColors.RED));
400 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_FULL, "Full", FadeColors.LIGHT_GREY));
401 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_EMPTY, "Empty", FadeColors.LIGHT_GREY));
402 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_INCREASE, "10% increase", FadeColors.LIGHT_GREY));
403 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_DECREASE, "10% decrease", FadeColors.LIGHT_GREY));
404 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
405
406 super.GetDebugActions(outputList);
407 }
408
409 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
410 {
411 if (super.OnAction(action_id, player, ctx))
412 return true;
413
414 if (!g_Game.IsServer())
415 return false;
416
417 switch (action_id)
418 {
419 case EActions.GENERIC_FUEL_FULL:
421 return true;
422 case EActions.GENERIC_FUEL_EMPTY:
423 SetFuel(0);
424 return true;
425 case EActions.GENERIC_FUEL_INCREASE:
426 AddFuel(Math.Clamp(GetMaxFuel() * 0.1, 0.0, GetMaxFuel()));
427 return true;
428 case EActions.GENERIC_FUEL_DECREASE:
429 float value = GetMaxFuel() * 0.1;
430 if (value <= 0.0)
431 {
432 SetFuel(0.0);
433 return true;
434 }
435
436 SetFuel(GetFuel() - value);
437 return true;
438 }
439
440 return false;
441 }
442}
443
444
445class PowerGenerator extends PowerGeneratorBase {}
Param4< int, int, string, int > TSelectableActionInfoWithColor
eBleedingSourceType GetType()
ActionPlaceObjectCB ActiondeployObjectCB ActionPlaceObject()
Определения ActionPlaceObject.c:11
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
override bool IsInitialized()
Определения CombinationLock.c:70
DayZGame g_Game
Определения DayZGame.c:3942
EActions
Определения EActions.c:2
void Effect()
ctor
Определения Effect.c:72
float GetEnergy()
Определения ItemBase.c:8525
Super root of all classes in Enforce script.
Определения EnScript.c:11
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения EnEntity.c:165
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
provides access to slot configuration
Определения InventorySlots.c:6
override void EEItemAttached(EntityAI item, string slot_name)
Определения PowerGenerator.c:222
override void OnWork(float consumed_energy)
Определения PowerGenerator.c:172
override void OnWorkStart()
Определения PowerGenerator.c:145
ref UniversalTemperatureSource m_UTSource
DEPRECATED Attached spark plug item.
Определения PortableGasStove.c:29
bool HasSparkplug()
Определения PowerGenerator.c:350
static const string STOP_SOUND
Определения PowerGenerator.c:12
void SetFuel(float fuel_amount)
Определения PowerGenerator.c:271
void PowerGeneratorBase()
Определения PowerGenerator.c:28
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Определения PowerGenerator.c:216
override bool CanPutIntoHands(EntityAI parent)
Определения PowerGenerator.c:116
static float m_FuelTankCapacity
Определения PowerGenerator.c:4
float GetMaxFuel()
Определения PowerGenerator.c:339
override void SetActions()
Определения PowerGenerator.c:374
override void OnInitEnergy()
Определения PowerGenerator.c:136
EffectSound m_EngineStart
Определения PowerGenerator.c:16
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Определения PowerGenerator.c:397
Effect m_Smoke
Определения PowerGenerator.c:19
ref UniversalTemperatureSourceSettings m_UTSSettings
Определения PortableGasStove.c:30
static const string START_SOUND
Определения PowerGenerator.c:9
ref UniversalTemperatureSourceLambdaConstant m_UTSLEngine
Определения PowerGenerator.c:25
EffectSound m_EngineLoop
Определения PowerGenerator.c:15
override string GetDeploySoundset()
Определения PowerGenerator.c:369
override void OnWorkStop()
Определения PowerGenerator.c:194
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Определения PowerGenerator.c:409
float GetFuelPercentage()
Определения PowerGenerator.c:344
override float GetLiquidThroughputCoef()
Определения PowerGenerator.c:70
static float m_FuelToEnergyRatio
Определения PowerGenerator.c:5
void StartLoopSound()
Определения PowerGenerator.c:86
void UpdateFuelMeter()
Определения PowerGenerator.c:262
override void EEItemDetached(EntityAI item, string slot_name)
Определения PowerGenerator.c:234
override void OnVariablesSynchronized()
Определения PowerGenerator.c:358
EffectSound m_EngineStop
Определения PowerGenerator.c:17
float GetFuel()
Определения PowerGenerator.c:333
override bool CanPutInCargo(EntityAI parent)
Определения PowerGenerator.c:105
override void EEInit()
Определения PowerGenerator.c:41
override void OnDebugSpawn()
Определения PowerGenerator.c:386
vector GetSmokeParticleOrientation()
Определения PowerGenerator.c:80
ItemBase m_SparkPlug
Определения PowerGenerator.c:21
static const string LOOP_SOUND
Определения PowerGenerator.c:10
ref Timer m_SoundLoopStartTimer
Определения PowerGenerator.c:18
bool m_IsLowEnergy
Определения PowerGenerator.c:14
float AddFuel(float available_fuel)
Определения PowerGenerator.c:294
vector GetSmokeParticlePosition()
Определения PowerGenerator.c:75
const string LOOP_LOW_FUEL_SOUND
Определения PowerGenerator.c:11
void ~PowerGeneratorBase()
Определения PowerGenerator.c:36
void SetLowEnergyState(bool state)
Определения PowerGenerator.c:251
float m_Fuel
Определения PowerGenerator.c:3
const float LOW_ENERGY_FUEL_PERCENTAGE
Определения PowerGenerator.c:8
int m_FuelPercentage
Определения PowerGenerator.c:6
override void EOnInit(IEntity other, int extra)
Определения PowerGenerator.c:59
bool CanManipulate()
Определения PowerGenerator.c:126
bool CanAddFuel(ItemBase container)
Определения PowerGenerator.c:315
Определения EnMath.c:7
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.
Определения EffectManager.c:70
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Определения EffectManager.c:271
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
Определения DayZPlayerImplement.c:39
original Timer deletes m_params which is unwanted
Определения UniversalTemperatureSource.c:39
Определения EnConvert.c:119
Serializer ParamsReadContext
Определения gameplay.c:15
proto void DPrint(string var)
Prints content of variable to console/log. Should be used for critical messages so it will appear in ...
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
EntityEvent
Entity events for event-mask, or throwing event from code.
Определения EnEntity.c:45
static const float ITEM_TEMPERATURE_NEUTRAL_ZONE_MIDDLE
Определения 3_Game/DayZ/constants.c:811
const float LIQUID_THROUGHPUT_GENERATOR
Определения 3_Game/DayZ/constants.c:576
const int LIQUID_GASOLINE
Определения 3_Game/DayZ/constants.c:548
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
const int SAT_DEBUG_ACTION
Определения 3_Game/DayZ/constants.c:457
const int CALL_CATEGORY_SYSTEM
Определения 3_Game/DayZ/tools/tools.c:8