DayZ 1.27
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 static const string SPARKPLUG_ATTACH_SOUND = "sparkplug_attach_SoundSet";
14 static const string SPARKPLUG_DETACH_SOUND = "sparkplug_detach_SoundSet";
15
16 protected bool m_IsLowEnergy;
21 ref protected Effect m_Smoke;
22
24
27 protected ref UniversalTemperatureSourceLambdaConstant m_UTSLEngine;
28
29 // Constructor
31 {
32 SetEventMask(EntityEvent.INIT); // Enable EOnInit event
33
35 RegisterNetSyncVariableInt("m_FuelPercentage");
36 }
37
42
43 override void EEInit()
44 {
45 super.EEInit();
46
47 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
48 {
50 m_UTSSettings.m_ManualUpdate = true;
52 m_UTSSettings.m_TemperatureCap = 8;
53 m_UTSSettings.m_RangeFull = 1;
54 m_UTSSettings.m_RangeMax = 2.5;
55
56 m_UTSLEngine = new UniversalTemperatureSourceLambdaConstant();
58 }
59 }
60
61 override void EOnInit(IEntity other, int extra)
62 {
63 if (GetGame().IsServer())
64 {
65 m_FuelPercentage = GetCompEM().GetEnergy0To100();
66 SetSynchDirty();
67 }
68
70 }
71
72 override float GetLiquidThroughputCoef()
73 {
75 }
76
78 {
79 return "0.3 0.21 0.4";
80 }
81
83 {
84 return "270 0 0";
85 }
86
87 // Play the loop sound
89 {
90 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
91 {
92 if (GetCompEM().IsWorking())
93 {
94 if (m_IsLowEnergy)
95 PlaySoundSetLoop(m_EngineLoop, LOOP_LOW_FUEL_SOUND, 0.3, 0.3);
96 else
97 PlaySoundSetLoop(m_EngineLoop, LOOP_SOUND, 0.3, 0.3);
98
99 // Particle
102 }
103 }
104 }
105
106 // Taking item into inventory
107 override bool CanPutInCargo( EntityAI parent )
108 {
109 if (!super.CanPutInCargo(parent))
110 {
111 return false;
112 }
113
114 return CanManipulate();
115 }
116
117 // Taking item into inventory
118 override bool CanPutIntoHands(EntityAI parent)
119 {
120 if(!super.CanPutIntoHands(parent))
121 {
122 return false;
123 }
124 return CanManipulate();
125 }
126
127 // Returns true/false if this item can be moved into inventory/hands
129 {
130 return GetCompEM().GetPluggedDevicesCount() == 0 && !GetCompEM().IsWorking();
131 }
132
133 /*===================================
134 EVENTS
135 ===================================*/
136
137 // Init
138 override void OnInitEnergy()
139 {
140 m_FuelTankCapacity = GetGame().ConfigGetFloat ("CfgVehicles " + GetType() + " fuelTankCapacity");
141 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity; // Conversion ratio of 1 ml of fuel to X Energy
142
144 }
145
146 // Generator is working
147 override void OnWorkStart()
148 {
149 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
150 {
151 if (IsInitialized())
152 {
153 PlaySoundSet(m_EngineStart, START_SOUND, 0, 0);
154 }
155
157 {
159 }
160
161 if (!m_SoundLoopStartTimer.IsRunning()) // Makes sure the timer is NOT running already
162 {
163 m_SoundLoopStartTimer.Run(1.5, this, "StartLoopSound", NULL, false);
164 }
165 }
166
167 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
168 {
169 m_UTSource.SetDefferedActive(true, 20.0);
170 }
171 }
172
173 // Do work
174 override void OnWork(float consumed_energy)
175 {
176 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
177 {
179 }
180
181 if (GetGame().IsServer())
182 {
183 m_FuelPercentage = GetCompEM().GetEnergy0To100();
184 SetSynchDirty();
185 }
186
188 SetLowEnergyState(true);
190 SetLowEnergyState(false);
191
193 }
194
195 // Turn off when this runs out of fuel
196 override void OnWorkStop()
197 {
198 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
199 {
200 // Sound
201 PlaySoundSet(m_EngineStop, STOP_SOUND, 0, 0);
202 StopSoundSet(m_EngineLoop);
203
204 // particle
206
207 // Fuel meter
209 }
210
211 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
212 {
213 m_UTSource.SetDefferedActive(false, 20.0);
214 }
215 }
216
217 // Called when this generator is picked up
218 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
219 {
220 super.OnItemLocationChanged(old_owner, new_owner);
222 }
223
224 override void EEItemAttached(EntityAI item, string slot_name)
225 {
226 super.EEItemAttached(item, slot_name);
227 GetCompEM().InteractBranch(this);
228
229 ItemBase item_IB = ItemBase.Cast(item);
230
231 if (item_IB.IsKindOf("Sparkplug") && IsInitialized())
232 {
233 ShowSelection("sparkplug_installed");
234
235 #ifndef SERVER
237 sound.SetAutodestroy( true );
238 #endif
239 }
240 }
241
242 override void EEItemDetached(EntityAI item, string slot_name)
243 {
244 super.EEItemDetached(item, slot_name);
245
246 GetCompEM().InteractBranch(this);
247
248 ItemBase item_IB = ItemBase.Cast(item);
249
250 if (item_IB.IsKindOf("Sparkplug"))
251 {
252 HideSelection("sparkplug_installed");
253 GetCompEM().SwitchOff();
254
255 #ifndef SERVER
257 sound.SetAutodestroy(true);
258 #endif
259 }
260 }
261
262 /*================================
263 FUNCTIONS
264 ================================*/
265
266 protected void SetLowEnergyState(bool state)
267 {
268 m_IsLowEnergy = state;
269
270 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
271 {
272 StopSoundSet(m_EngineLoop);
274 }
275 }
276
278 {
279 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
280 {
281 SetAnimationPhase("dial_fuel", m_FuelPercentage * 0.01);
282 }
283 }
284
285 // Adds energy to the generator
286 void SetFuel(float fuel_amount)
287 {
288 // clamp
289 if (GetFuel() == 0.0 && fuel_amount <= 0.0)
290 return;
291
292 if (m_FuelTankCapacity > 0)
293 {
294 m_FuelToEnergyRatio = GetCompEM().GetEnergyMax() / m_FuelTankCapacity;
295 GetCompEM().SetEnergy(fuel_amount * m_FuelToEnergyRatio);
296 m_FuelPercentage = GetCompEM().GetEnergy0To100();
297 SetSynchDirty();
299 }
300 else
301 {
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());
303 DPrint(error);
304 }
305 }
306
307 // Adds fuel (energy) to the generator
308 // Returns how much fuel was accepted
309 float AddFuel(float available_fuel)
310 {
311 if (available_fuel == 0.0)
312 return 0.0;
313
314 GetCompEM().InteractBranch(this);
315 float needed_fuel = GetMaxFuel() - GetFuel();
316
317 if (needed_fuel > available_fuel)
318 {
319 SetFuel(GetFuel() + available_fuel);
320 return available_fuel; // Return used fuel amount
321 }
322 else
323 {
325 return needed_fuel;
326 }
327 }
328
329 // Check the bottle if it can be used to fill the tank
330 bool CanAddFuel(ItemBase container)
331 {
332 if (container)
333 {
334 // Get the liquid
335 int liquid_type = container.GetLiquidType();
336
337 // Do all checks
338 if ( container.GetQuantity() > 0 && GetCompEM().GetEnergy() < GetCompEM().GetEnergyMax() && (liquid_type & LIQUID_GASOLINE))
339 {
340 return true;
341 }
342 }
343
344 return false;
345 }
346
347 // Returns fuel amount
348 float GetFuel()
349 {
350 return Math.Clamp(GetCompEM().GetEnergy() / m_FuelToEnergyRatio, 0.0, GetMaxFuel());
351 }
352
353 // Returns max fuel amount
355 {
356 return m_FuelTankCapacity;
357 }
358
360 {
361 return m_FuelPercentage;
362 }
363
364 // Checks sparkplug
366 {
367 int slot = InventorySlots.GetSlotIdFromString("SparkPlug");
368 EntityAI ent = GetInventory().FindAttachment(slot);
369
370 return ent && !ent.IsRuined();
371 }
372
374 {
375 super.OnVariablesSynchronized();
376
378 }
379
380 //================================================================
381 // ADVANCED PLACEMENT
382 //================================================================
383
384 override string GetDeploySoundset()
385 {
386 return "placePowerGenerator_SoundSet";
387 }
388
399
400 //Debug menu Spawn Ground Special
401 override void OnDebugSpawn()
402 {
403 EntityAI entity;
404 if (Class.CastTo(entity, this))
405 {
406 entity.GetInventory().CreateInInventory("SparkPlug");
407 }
408
410 }
411
412 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
413 {
414 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "PowerGenerator Fuel", FadeColors.RED));
415 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_FULL, "Full", FadeColors.LIGHT_GREY));
416 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_EMPTY, "Empty", FadeColors.LIGHT_GREY));
417 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_INCREASE, "10% increase", FadeColors.LIGHT_GREY));
418 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GENERIC_FUEL_DECREASE, "10% decrease", FadeColors.LIGHT_GREY));
419 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
420
421 super.GetDebugActions(outputList);
422 }
423
424 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
425 {
426 if (super.OnAction(action_id, player, ctx))
427 return true;
428
429 if (!GetGame().IsServer())
430 return false;
431
432 switch (action_id)
433 {
434 case EActions.GENERIC_FUEL_FULL:
436 return true;
437 case EActions.GENERIC_FUEL_EMPTY:
438 SetFuel(0);
439 return true;
440 case EActions.GENERIC_FUEL_INCREASE:
441 AddFuel(Math.Clamp(GetMaxFuel() * 0.1, 0.0, GetMaxFuel()));
442 return true;
443 case EActions.GENERIC_FUEL_DECREASE:
444 float value = GetMaxFuel() * -0.1;
445 if (value <= 0)
446 SetFuel(0.0);
447 return true;
448
449 AddFuel(value);
450 return true;
451 }
452
453 return false;
454 }
455}
456
457
458class PowerGenerator extends PowerGeneratorBase {}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Определения EntityAI.c:97
eBleedingSourceType GetType()
Определения BleedingSource.c:63
ActionPlaceObjectCB ActiondeployObjectCB ActionPlaceObject()
Определения ActionPlaceObject.c:11
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
override bool IsInitialized()
Определения CombinationLock.c:70
EActions
Определения EActions.c:2
void Effect()
ctor
Определения Effect.c:70
float GetEnergy()
Определения ItemBase.c:8278
proto native float ConfigGetFloat(string path)
Get float value from config on path.
Super root of all classes in Enforce script.
Определения EnScript.c:11
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:603
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения Building.c:6
Определения constants.c:659
Определения 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:224
static const string SPARKPLUG_ATTACH_SOUND
Определения PowerGenerator.c:13
override void OnWork(float consumed_energy)
Определения PowerGenerator.c:174
override void OnWorkStart()
Определения PowerGenerator.c:147
ref UniversalTemperatureSource m_UTSource
DEPRECATED Attached spark plug item.
Определения PortableGasStove.c:29
bool HasSparkplug()
Определения PowerGenerator.c:365
static const string STOP_SOUND
Определения PowerGenerator.c:12
void SetFuel(float fuel_amount)
Определения PowerGenerator.c:286
void PowerGeneratorBase()
Определения PowerGenerator.c:30
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Определения PowerGenerator.c:218
override bool CanPutIntoHands(EntityAI parent)
Определения PowerGenerator.c:118
static float m_FuelTankCapacity
Определения PowerGenerator.c:4
float GetMaxFuel()
Определения PowerGenerator.c:354
override void SetActions()
Определения PowerGenerator.c:389
override void OnInitEnergy()
Определения PowerGenerator.c:138
EffectSound m_EngineStart
Определения PowerGenerator.c:18
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Определения PowerGenerator.c:412
Effect m_Smoke
Определения PowerGenerator.c:21
ref UniversalTemperatureSourceSettings m_UTSSettings
Определения PortableGasStove.c:30
static const string START_SOUND
Определения PowerGenerator.c:9
static const string SPARKPLUG_DETACH_SOUND
Определения PowerGenerator.c:14
ref UniversalTemperatureSourceLambdaConstant m_UTSLEngine
Определения PowerGenerator.c:27
EffectSound m_EngineLoop
Определения PowerGenerator.c:17
override string GetDeploySoundset()
Определения PowerGenerator.c:384
override void OnWorkStop()
Определения PowerGenerator.c:196
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Определения PowerGenerator.c:424
float GetFuelPercentage()
Определения PowerGenerator.c:359
override float GetLiquidThroughputCoef()
Определения PowerGenerator.c:72
static float m_FuelToEnergyRatio
Определения PowerGenerator.c:5
void StartLoopSound()
Определения PowerGenerator.c:88
void UpdateFuelMeter()
Определения PowerGenerator.c:277
override void EEItemDetached(EntityAI item, string slot_name)
Определения PowerGenerator.c:242
override void OnVariablesSynchronized()
Определения PowerGenerator.c:373
EffectSound m_EngineStop
Определения PowerGenerator.c:19
float GetFuel()
Определения PowerGenerator.c:348
override bool CanPutInCargo(EntityAI parent)
Определения PowerGenerator.c:107
override void EEInit()
Определения PowerGenerator.c:43
override void OnDebugSpawn()
Определения PowerGenerator.c:401
vector GetSmokeParticleOrientation()
Определения PowerGenerator.c:82
ItemBase m_SparkPlug
Определения PowerGenerator.c:23
static const string LOOP_SOUND
Определения PowerGenerator.c:10
ref Timer m_SoundLoopStartTimer
Определения PowerGenerator.c:20
bool m_IsLowEnergy
Определения PowerGenerator.c:16
float AddFuel(float available_fuel)
Определения PowerGenerator.c:309
vector GetSmokeParticlePosition()
Определения PowerGenerator.c:77
const string LOOP_LOW_FUEL_SOUND
Определения PowerGenerator.c:11
void ~PowerGeneratorBase()
Определения PowerGenerator.c:38
void SetLowEnergyState(bool state)
Определения PowerGenerator.c:266
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:61
bool CanManipulate()
Определения PowerGenerator.c:128
bool CanAddFuel(ItemBase container)
Определения PowerGenerator.c:330
Определения InventoryItem.c:731
Определения 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 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.
Определения EffectManager.c:169
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:63
original Timer deletes m_params which is unwanted
Определения UniversalTemperatureSource.c:38
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
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 ...
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
Определения constants.c:806
const float LIQUID_THROUGHPUT_GENERATOR
Определения constants.c:571
const int LIQUID_GASOLINE
Определения constants.c:543
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
Определения constants.c:452
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
const int CALL_CATEGORY_SYSTEM
Определения tools.c:8