DayZ 1.24
Loading...
Searching...
No Matches
Roadflare.c
Go to the documentation of this file.
1/*
2 Author: Boris Vacula
3 Description: The flare has 3 burning states during which it uses different particle effects while illumnatingthe environment. After it burns up, it still releases smoke for a while.
4 When the flare is dropped while its burning, it is stood up on its stands. This makes the shadows, illumination and particles stand out better.
5*/
6
15
23
25{
26 // Burning
27 static protected const int INITIAL_BURNING_STATE_TIME = 5;
28 static protected const int FINAL_BURNING_STATE_TIME = 60;
29 static protected vector m_FlameLocalPos = "0 0.285 0";
30 private int m_BurningState = RoadflareBurningState.NOT_BURNING;
31
32 // Light
33 RoadflareLight m_Light;
34
35 // Particles
40
45
46 // Sounds
49 static protected const string BURNING_SOUND = "roadflareLoop_SoundSet";
50 static protected const string IGNITE_SOUND = "roadflareTurnOn_SoundSet";
51 static protected const int BURNING_NOISE_RANGE = 30;
52
53 // Timers
55
56 // Ignition states
57 private int m_ModelState = RoadflareModelStates.DEFAULT;
58
59 // Selections
60 static const string STANDS_FOLDED = "Sticks_Flare_Folded";
61 static const string STANDS_UNFOLDED = "Sticks_Flare_Unfolded";
62 static const string FLARE_CAP = "Flare_cap";
63 static const string UNIGNITED_TIP = "Pristine";
64 static const string IGNITED_TIP = "Burning";
65 static const string EXTINGUISHED_TIP = "Burned_out";
66
67 static const int SELECTION_Burning = 0;
68 static const int SELECTION_Burned_out = 1;
69 static const int SELECTION_Pristine = 2;
70 static const int SELECTION_All = 3;
71
72 static const string DEFAULT_TEXTURE = "dz\\gear\\consumables\\data\\road_flare_co.paa";
73 static const string BURNING_TEXTURE = "dz\\gear\\consumables\\data\\road_flare_e_co.paa";
74
75 static const string DEFAULT_MATERIAL = "dz\\gear\\consumables\\data\\road_flare.rvmat";
76 static const string BURNING_MATERIAL = "dz\\gear\\consumables\\data\\road_flare_on.rvmat";
77
78 // Noise
80 private float m_NoiseTimer;
81
82 void Roadflare()
83 {
84 RegisterNetSyncVariableInt("m_BurningState");
85 }
86
87 // Use RoadflareModelStates enum
93
94 override void EEDelete(EntityAI parent)
95 {
96 super.EEDelete(parent);
97
98 if (GetGame())
99 {
102 delete m_FinalSmokeTimer;
103 }
104
106
107 if (m_Light)
108 m_Light.FadeOut(0);
109 }
110
112 {
113 super.OnStoreSave(ctx);
114
115 ctx.Write(m_ModelState);
116 }
117
118 override bool OnStoreLoad(ParamsReadContext ctx, int version)
119 {
120 if (!super.OnStoreLoad(ctx, version))
121 return false;
122
123 int state;
124 if (!ctx.Read(state))
125 state = RoadflareModelStates.DEFAULT;
126
128
129 return true;
130 }
131
133 {
134 switch (m_ModelState)
135 {
136 case RoadflareModelStates.DEFAULT:
137
138 ShowSelection(FLARE_CAP);
139 ShowSelection(UNIGNITED_TIP);
140
141 HideSelection(IGNITED_TIP);
142 HideSelection(EXTINGUISHED_TIP);
143
144 SetObjectTexture(SELECTION_Pristine, DEFAULT_TEXTURE);
145 SetObjectMaterial(SELECTION_Pristine, DEFAULT_MATERIAL);
146
147 break;
148
149 case RoadflareModelStates.UNCAPPED_UNIGNITED:
150
151 ShowSelection(UNIGNITED_TIP);
152
153 HideSelection(FLARE_CAP);
154 HideSelection(IGNITED_TIP);
155 HideSelection(EXTINGUISHED_TIP);
156
157 SetObjectTexture(SELECTION_Pristine, DEFAULT_TEXTURE);
158 SetObjectMaterial(SELECTION_Pristine, DEFAULT_MATERIAL);
159
160 break;
161
162 case RoadflareModelStates.UNCAPPED_IGNITED:
163
164 ShowSelection(IGNITED_TIP);
165
166 HideSelection(UNIGNITED_TIP);
167 HideSelection(FLARE_CAP);
168 HideSelection(EXTINGUISHED_TIP);
169
170 // No texture/material change here because the model already contains them
171
172 break;
173
174 case RoadflareModelStates.UNCAPPED_BURNED_OUT:
175
176 ShowSelection(EXTINGUISHED_TIP);
177
178 HideSelection(UNIGNITED_TIP);
179 HideSelection(FLARE_CAP);
180 HideSelection(IGNITED_TIP);
181
182 SetObjectTexture(SELECTION_Burned_out, DEFAULT_TEXTURE);
183 SetObjectMaterial(SELECTION_Burned_out, DEFAULT_MATERIAL);
184
185 break;
186 }
187 }
188
189 // When the flare starts burning
190 override void OnWorkStart()
191 {
192 if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
193 {
194 PlaySoundSetLoop(m_BurningSound, BURNING_SOUND, 0.5, 0);
195 PlaySoundSet(m_IgniteSound, IGNITE_SOUND, 0, 0);
196
197 m_Light = RoadflareLight.Cast(ScriptedLightBase.CreateLight(RoadflareLight, Vector(0, 0, 0)));
198 m_Light.AttachOnMemoryPoint(this, m_Light.m_MemoryPoint);
199 }
200
201 if (GetGame().IsServer())
202 {
203 /*m_NoisePar = new NoiseParams();
204 m_NoisePar.LoadFromPath("cfgVehicles Roadflare NoiseRoadFlare");
205 if ( GetGame().GetWorld().IsNight() )
206 {
207 NoiseSystem noise = GetGame().GetNoiseSystem();
208 if ( noise )
209 {
210 noise.AddNoisePos( this, GetPosition(), m_NoisePar );
211 }
212 }*/
213 }
214
216 SetModelState(RoadflareModelStates.UNCAPPED_IGNITED);
217 }
218
219 // Insert RoadflareBurningState enum index as parameter
224
225 // Insert RoadflareBurningState enum index as parameter. Activates server -> client synchronization
227 {
228 if (GetGame().IsServer())
229 {
231 SetSynchDirty();
232 }
233 }
234
235 // Every second of the flare burning
236 override void OnWork(float consumed_energy)
237 {
238 if (GetGame().IsServer())
239 {
240 float burning_time = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
241
242 // Update burning states
243 if (m_BurningState == RoadflareBurningState.INITIAL_BURN)
244 {
247 }
248 else if (m_BurningState == RoadflareBurningState.MAIN_BURN)
249 {
250 /*if ( GetGame().GetWorld().IsNight() )
251 {
252 NoiseSystem noise = GetGame().GetNoiseSystem();
253 if ( noise )
254 {
255 noise.AddNoisePos( this, GetPosition(), m_NoisePar);
256 }
257 }*/
258
259 if (burning_time >= GetCompEM().GetEnergyMax() - FINAL_BURNING_STATE_TIME)
261 }
262
263 // Burn containers of this roadflare. This might be removed if lit roadflare can't be put into inventory.
264 /*EntityAI container_EAI = GetHierarchyParent();
265
266 if ( container_EAI && container_EAI.IsInherited(ItemBase) && !container_EAI.IsInherited(TripwireTrap) )
267 {
268 ItemBase container_IB = ItemBase.Cast( container_EAI );
269
270 int c_size = container_IB.GetItemSize();
271 if (c_size == 0)
272 c_size = 1;
273
274 container_IB.AddHealth("","",-10/c_size);
275 }*/
276 }
277
279 }
280
281 // When the flare stops burning
282 override void OnWorkStop()
283 {
284 if (GetGame().IsMissionMainMenu()) // This is singleplayer main menu so no synchronization here!
285 {
288 }
289 else
290 {
291 if (GetGame().IsServer())
292 {
293 //Safeguard if item is turned off by another event than running out of energy
294 if (GetCompEM().GetEnergy() > 0)
295 {
296 if (m_Light)
297 m_Light.FadeOut();
299 return;
300 }
302 SetHealth("", "", 0);
303 }
304
307 m_FinalSmokeTimer.Run(60, this, "StopSmoking", NULL, false);
308 }
309
310
311 if (m_BurningSound)
312 StopSoundSet(m_BurningSound);
313
314 if (m_Light)
315 m_Light.FadeOut();
316
317 SetModelState(RoadflareModelStates.UNCAPPED_BURNED_OUT);
318 }
319
320 // Updates all (in)active particles
322 {
323 if (GetGame().IsDedicatedServer())
324 return;
325
326 switch (m_BurningState)
327 {
328 case RoadflareBurningState.NOT_BURNING:
329
331 break;
332
333 case RoadflareBurningState.INITIAL_BURN:
334
335 if (!m_ParInitialFire)
336 {
338 m_ParInitialFire = ParticleManager.GetInstance().PlayOnObject(PARTICLE_INIT_FIRE, this, m_FlameLocalPos);
340 }
341 break;
342
343 case RoadflareBurningState.MAIN_BURN:
344
345 if (!m_ParMainFire)
346 {
347 m_ParMainFire = ParticleManager.GetInstance().PlayOnObject(PARTICLE_MAIN_FIRE, this, m_FlameLocalPos);
348 m_ParMainFire.SetWiggle(7, 0.3);
349 }
350
352
353 break;
354
355 case RoadflareBurningState.FINAL_BURN:
356
357 if (!m_ParFinalFire)
358 {
360 m_ParFinalFire = ParticleManager.GetInstance().PlayOnObject(PARTICLE_FINAL_FIRE, this, m_FlameLocalPos);
362 }
363 break;
364
365 case RoadflareBurningState.SMOKE_ONLY:
366
367 if (!m_ParJustSmoke)
368 {
370 m_ParJustSmoke = ParticleManager.GetInstance().PlayOnObject(PARTICLE_FINAL_SMOKE, this, m_FlameLocalPos);
372 }
373 break;
374 }
375 }
376
377 // Destroys the given particle
379 {
380 if (p)
381 {
382 p.SetWiggle(0, 0);
383 p.Stop();
384 }
385 }
386
388 {
390 p = null;
391 }
392
393 // Destroys all particles
401
402 // Stop releasing final smoke
408
409 // Inventory manipulation
410 override void OnInventoryExit(Man player)
411 {
412 super.OnInventoryExit(player);
413
414 if (m_BurningState != RoadflareBurningState.NOT_BURNING)
415 {
416 HideSelection(STANDS_FOLDED);
417 ShowSelection(STANDS_UNFOLDED);
418
419 if (player)
420 {
421 vector ori_rotate = player.GetOrientation();
422 ori_rotate = ori_rotate + Vector(180, 32, 0);
423 SetOrientation(ori_rotate);
424 }
425 }
426 }
427
428 override bool CanPutInCargo(EntityAI parent)
429 {
430 if (!super.CanPutInCargo(parent))
431 return false;
432
433 if (parent && parent.IsInherited(FireplaceBase))
434 return true;
435
436 if (m_BurningState != RoadflareBurningState.NOT_BURNING)
437 return false;
438
439 return true;
440 }
441
442 override void OnInventoryEnter(Man player)
443 {
444 super.OnInventoryEnter(player);
445
446 HideSelection(STANDS_UNFOLDED);
447 ShowSelection(STANDS_FOLDED);
448 }
449
451 {
452 if (item.IsInherited(TripwireTrap))
453 GetCompEM().SwitchOn();
454 }
455
457 {
458 return GetCompEM().IsWorking();
459 }
460
462 {
463 super.OnVariablesSynchronized();
464
466 }
467
468 override void SetActions()
469 {
470 super.SetActions();
471
472 AddAction(ActionAttach);
476 }
477};
void ActionDetach()
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
void AddAction(typename actionName)
float GetEnergy()
Definition ItemBase.c:8140
class NoiseSystem NoiseParams()
Definition Noise.c:15
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
RoadflareModelStates
Definition Roadflare.c:17
@ DEFAULT
Definition Roadflare.c:18
@ UNCAPPED_UNIGNITED
Definition Roadflare.c:19
@ UNCAPPED_BURNED_OUT
Definition Roadflare.c:21
@ UNCAPPED_IGNITED
Definition Roadflare.c:20
RoadflareBurningState
Definition Roadflare.c:8
@ SMOKE_ONLY
Definition Roadflare.c:13
@ MAIN_BURN
Definition Roadflare.c:11
@ FINAL_BURN
Definition Roadflare.c:12
@ INITIAL_BURN
Definition Roadflare.c:10
@ NOT_BURNING
Definition Roadflare.c:9
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
Legacy way of using particles in the game.
Definition Particle.c:7
void SetWiggle(float random_angle, float random_interval)
Makes the particle change direction by random_angle every random_interval seconds.
Definition Particle.c:742
static const int ROADFLARE_BURNING_INIT
static const int ROADFLARE_BURNING_SMOKE
static const int ROADFLARE_BURNING_ENDING
static const int ROADFLARE_BURNING_MAIN
void DestroyParticle(Particle p)
Definition Roadflare.c:378
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition Roadflare.c:118
const int FINAL_BURNING_STATE_TIME
Definition Roadflare.c:28
int PARTICLE_INIT_FIRE
Definition Roadflare.c:41
override bool CanPutInCargo(EntityAI parent)
Definition Roadflare.c:428
void DestroyAllParticles()
Definition Roadflare.c:394
override void SetActions()
Definition Roadflare.c:468
static const string EXTINGUISHED_TIP
Definition Roadflare.c:65
static const int SELECTION_Pristine
Definition Roadflare.c:69
void UpdateActiveParticles()
Definition Roadflare.c:321
override void OnStoreSave(ParamsWriteContext ctx)
Definition Roadflare.c:111
static const string DEFAULT_TEXTURE
Definition Roadflare.c:72
void StopSmoking()
Definition Roadflare.c:403
void SetModelState(int enum_state)
Definition Roadflare.c:88
EffectSound m_BurningSound
Definition Roadflare.c:47
static const int SELECTION_Burned_out
Definition Roadflare.c:68
static const string UNIGNITED_TIP
Definition Roadflare.c:63
const int BURNING_NOISE_RANGE
Definition Roadflare.c:51
static const int SELECTION_All
Definition Roadflare.c:70
void Roadflare()
Definition Roadflare.c:82
vector m_FlameLocalPos
Definition Roadflare.c:29
void SetBurningStateSynchronized(int state_number)
Definition Roadflare.c:226
ref NoiseParams m_NoisePar
Definition Roadflare.c:79
void UpdateModelSelections()
Definition Roadflare.c:132
static const string IGNITED_TIP
Definition Roadflare.c:64
override void OnWorkStart()
Definition Roadflare.c:190
static const int SELECTION_Burning
Definition Roadflare.c:67
override void OnVariablesSynchronized()
Definition Roadflare.c:461
const string IGNITE_SOUND
Definition Roadflare.c:50
static const string BURNING_TEXTURE
Definition Roadflare.c:73
void DestroyParticleEx(out Particle p)
Definition Roadflare.c:387
int m_ModelState
Definition Roadflare.c:57
Particle m_ParMainFire
Definition Roadflare.c:37
override bool CanIgniteItem(EntityAI ignite_target=NULL)
Definition Roadflare.c:456
void SetBurningState(int state_number)
Definition Roadflare.c:220
const int INITIAL_BURNING_STATE_TIME
Definition Roadflare.c:27
RoadflareLight m_Light
Definition Roadflare.c:33
override void EEDelete(EntityAI parent)
Definition Roadflare.c:94
int PARTICLE_FINAL_FIRE
Definition Roadflare.c:43
static const string BURNING_MATERIAL
Definition Roadflare.c:76
float m_NoiseTimer
Definition Roadflare.c:80
const string BURNING_SOUND
Definition Roadflare.c:49
override void OnInventoryEnter(Man player)
Definition Roadflare.c:442
static const string DEFAULT_MATERIAL
Definition Roadflare.c:75
override void OnInventoryExit(Man player)
Definition Roadflare.c:410
static const string STANDS_FOLDED
Definition Roadflare.c:60
static const string FLARE_CAP
Definition Roadflare.c:62
int PARTICLE_FINAL_SMOKE
Definition Roadflare.c:44
override void OnActivatedByItem(notnull ItemBase item)
Definition Roadflare.c:450
int m_BurningState
Definition Roadflare.c:30
override void OnWorkStop()
Definition Roadflare.c:282
EffectSound m_IgniteSound
Definition Roadflare.c:48
override void OnWork(float consumed_energy)
Definition Roadflare.c:236
Particle m_ParFinalFire
Definition Roadflare.c:38
Particle m_ParJustSmoke
Definition Roadflare.c:39
ref Timer m_FinalSmokeTimer
Definition Roadflare.c:54
Particle m_ParInitialFire
Definition Roadflare.c:36
int PARTICLE_MAIN_FIRE
Definition Roadflare.c:42
static const string STANDS_UNFOLDED
Definition Roadflare.c:61
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8