Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
8 {
14 };
15 
17 {
22 };
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
36  protected Particle m_ParInitialFire;
37  protected Particle m_ParMainFire;
38  protected Particle m_ParFinalFire;
39  protected Particle m_ParJustSmoke;
40 
41  static protected int PARTICLE_INIT_FIRE = ParticleList.ROADFLARE_BURNING_INIT;
42  static protected int PARTICLE_MAIN_FIRE = ParticleList.ROADFLARE_BURNING_MAIN;
43  static protected int PARTICLE_FINAL_FIRE = ParticleList.ROADFLARE_BURNING_ENDING;
44  static protected int PARTICLE_FINAL_SMOKE = ParticleList.ROADFLARE_BURNING_SMOKE;
45 
46  // Sounds
47  protected EffectSound m_BurningSound;
48  protected EffectSound m_IgniteSound;
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
54  ref Timer m_FinalSmokeTimer;
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
79  ref NoiseParams m_NoisePar;
80  private float m_NoiseTimer;
81 
82  void Roadflare()
83  {
84  RegisterNetSyncVariableInt("m_BurningState");
85  }
86 
87  // Use RoadflareModelStates enum
88  void SetModelState(int enum_state)
89  {
90  m_ModelState = enum_state;
91  UpdateModelSelections();
92  }
93 
94  override void EEDelete(EntityAI parent)
95  {
96  super.EEDelete(parent);
97 
98  if ( GetGame() )
99  {
100  SEffectManager.DestroyEffect( m_BurningSound );
101  SEffectManager.DestroyEffect( m_IgniteSound );
102  delete m_FinalSmokeTimer;
103  }
104 
105  DestroyAllParticles();
106 
107  if (m_Light)
108  m_Light.FadeOut(0);
109  }
110 
111  override void OnStoreSave(ParamsWriteContext ctx)
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 
127  SetModelState(state);
128 
129  return true;
130  }
131 
132  void UpdateModelSelections()
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 
215  SetBurningState(RoadflareBurningState.INITIAL_BURN);
216  SetModelState( RoadflareModelStates.UNCAPPED_IGNITED );
217  }
218 
219  // Insert RoadflareBurningState enum index as parameter
220  void SetBurningState(int state_number)
221  {
222  m_BurningState = state_number;
223  }
224 
225  // Insert RoadflareBurningState enum index as parameter. Activates server -> client synchronization
226  void SetBurningStateSynchronized(int state_number)
227  {
228  if ( GetGame().IsServer() )
229  {
230  m_BurningState = state_number;
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  {
245  if (burning_time >= INITIAL_BURNING_STATE_TIME)
246  {
247  SetBurningStateSynchronized(RoadflareBurningState.MAIN_BURN);
248  }
249  }
250  else if ( m_BurningState == RoadflareBurningState.MAIN_BURN )
251  {
252  /*if ( GetGame().GetWorld().IsNight() )
253  {
254  NoiseSystem noise = GetGame().GetNoiseSystem();
255  if ( noise )
256  {
257  noise.AddNoisePos( this, GetPosition(), m_NoisePar);
258  }
259  }*/
260 
261  if ( burning_time >= GetCompEM().GetEnergyMax() - FINAL_BURNING_STATE_TIME )
262  {
263  SetBurningStateSynchronized(RoadflareBurningState.FINAL_BURN);
264  }
265  }
266 
267  // Burn containers of this roadflare. This might be removed if lit roadflare can't be put into inventory.
268  /*EntityAI container_EAI = GetHierarchyParent();
269 
270  if ( container_EAI && container_EAI.IsInherited(ItemBase) && !container_EAI.IsInherited(TripwireTrap) )
271  {
272  ItemBase container_IB = ItemBase.Cast( container_EAI );
273 
274  int c_size = container_IB.GetItemSize();
275  if (c_size == 0)
276  c_size = 1;
277 
278  container_IB.AddHealth("","",-10/c_size);
279  }*/
280  }
281 
282  UpdateActiveParticles();
283  }
284 
285  // When the flare stops burning
286  override void OnWorkStop()
287  {
288  if ( GetGame().IsMissionMainMenu() ) // This is singleplayer main menu so no synchronization here!
289  {
290  SetBurningState(RoadflareBurningState.NOT_BURNING);
291  UpdateActiveParticles();
292  }
293  else
294  {
295  if ( GetGame().IsServer() )
296  {
297  //Safeguard if item is turned off by another event than running out of energy
298  if (GetCompEM().GetEnergy() > 0)
299  {
300  if (m_Light)
301  {
302  m_Light.FadeOut();
303  }
304  SetBurningState(RoadflareBurningState.NOT_BURNING);
305  return;
306  }
307  SetBurningStateSynchronized(RoadflareBurningState.SMOKE_ONLY);
308  SetHealth("","",0);
309  }
310 
311  UpdateActiveParticles();
312  m_FinalSmokeTimer = new Timer( CALL_CATEGORY_SYSTEM );
313  m_FinalSmokeTimer.Run(60, this, "StopSmoking", NULL, false);
314  }
315 
316 
317  if ( m_BurningSound )
318  StopSoundSet( m_BurningSound );
319 
320  if (m_Light)
321  m_Light.FadeOut();
322 
323  SetModelState( RoadflareModelStates.UNCAPPED_BURNED_OUT );
324  }
325 
326  // Updates all (in)active particles
327  void UpdateActiveParticles()
328  {
329  if ( GetGame().IsDedicatedServer() )
330  return;
331 
332  switch (m_BurningState)
333  {
334  case RoadflareBurningState.NOT_BURNING:
335 
336  DestroyAllParticles();
337  break;
338 
339  case RoadflareBurningState.INITIAL_BURN:
340 
341  if (!m_ParInitialFire)
342  {
343  DestroyAllParticles();
344  m_ParInitialFire = ParticleManager.GetInstance().PlayOnObject( PARTICLE_INIT_FIRE, this, m_FlameLocalPos);
345  m_ParInitialFire.SetWiggle( 10, 0.3 );
346  }
347  break;
348 
349  case RoadflareBurningState.MAIN_BURN:
350 
351  if (!m_ParMainFire)
352  {
353  m_ParMainFire = ParticleManager.GetInstance().PlayOnObject( PARTICLE_MAIN_FIRE, this, m_FlameLocalPos);
354  m_ParMainFire.SetWiggle( 7, 0.3 );
355  }
356 
357  DestroyParticleEx(m_ParInitialFire);
358 
359  break;
360 
361  case RoadflareBurningState.FINAL_BURN:
362 
363  if (!m_ParFinalFire)
364  {
365  DestroyAllParticles();
366  m_ParFinalFire = ParticleManager.GetInstance().PlayOnObject( PARTICLE_FINAL_FIRE, this, m_FlameLocalPos);
367  m_ParFinalFire.SetWiggle( 4, 0.3 );
368  }
369  break;
370 
371  case RoadflareBurningState.SMOKE_ONLY:
372 
373  if (!m_ParJustSmoke)
374  {
375  DestroyAllParticles();
376  m_ParJustSmoke = ParticleManager.GetInstance().PlayOnObject( PARTICLE_FINAL_SMOKE, this, m_FlameLocalPos);
377  m_ParJustSmoke.SetWiggle( 2, 0.3 );
378  }
379  break;
380  }
381  }
382 
383  // Destroys the given particle
384  void DestroyParticle( Particle p )
385  {
386  if (p)
387  {
388  p.SetWiggle(0,0);
389  p.Stop();
390  }
391  }
392 
393  void DestroyParticleEx( out Particle p )
394  {
395  DestroyParticle(p);
396  p = null;
397  }
398 
399  // Destroys all particles
400  void DestroyAllParticles()
401  {
402  DestroyParticleEx(m_ParInitialFire);
403  DestroyParticleEx(m_ParMainFire);
404  DestroyParticleEx(m_ParFinalFire);
405  DestroyParticleEx(m_ParJustSmoke);
406  }
407 
408  // Stop releasing final smoke
409  void StopSmoking()
410  {
411  SetBurningStateSynchronized(RoadflareBurningState.NOT_BURNING);
412  UpdateActiveParticles();
413  }
414 
415  // Inventory manipulation
416  override void OnInventoryExit(Man player)
417  {
418  super.OnInventoryExit(player);
419 
420  if (m_BurningState != RoadflareBurningState.NOT_BURNING)
421  {
422  HideSelection(STANDS_FOLDED);
423  ShowSelection(STANDS_UNFOLDED);
424 
425  if (player)
426  {
427  vector ori_rotate = player.GetOrientation();
428  ori_rotate = ori_rotate + Vector(180, 32, 0);
429  SetOrientation(ori_rotate);
430  }
431  }
432  }
433 
434  override bool CanPutInCargo( EntityAI parent )
435  {
436  if ( !super.CanPutInCargo(parent) )
437  return false;
438 
439  if ( parent && parent.IsInherited( FireplaceBase ) )
440  return true;
441 
442  if ( m_BurningState != RoadflareBurningState.NOT_BURNING )
443  return false;
444 
445  return true;
446  }
447 
448  override void OnInventoryEnter(Man player)
449  {
450  super.OnInventoryEnter(player);
451 
452  HideSelection(STANDS_UNFOLDED);
453  ShowSelection(STANDS_FOLDED);
454  }
455 
456  override void OnActivatedByItem(notnull ItemBase item)
457  {
458  if (item.IsInherited(TripwireTrap))
459  {
460  GetCompEM().SwitchOn();
461  }
462  }
463 
464  override bool CanIgniteItem(EntityAI ignite_target = NULL)
465  {
466  return GetCompEM().IsWorking();
467  }
468 
469  override void OnVariablesSynchronized()
470  {
471  super.OnVariablesSynchronized();
472 
473  UpdateActiveParticles();
474  }
475 
476  override void SetActions()
477  {
478  super.SetActions();
479 
484  }
485 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
UNCAPPED_IGNITED
@ UNCAPPED_IGNITED
Definition: roadflare.c:20
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
UNCAPPED_UNIGNITED
@ UNCAPPED_UNIGNITED
Definition: roadflare.c:19
RoadflareBurningState
RoadflareBurningState
Definition: roadflare.c:7
ActionDetach
void ActionDetach()
Definition: actiondetach.c:10
INITIAL_BURN
@ INITIAL_BURN
Definition: roadflare.c:10
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
RoadflareModelStates
RoadflareModelStates
Definition: roadflare.c:16
FireplaceBase
Definition: barrelholes_colorbase.c:1
SMOKE_ONLY
@ SMOKE_ONLY
Definition: roadflare.c:13
MAIN_BURN
@ MAIN_BURN
Definition: roadflare.c:11
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
FINAL_BURN
@ FINAL_BURN
Definition: roadflare.c:12
Roadflare
Definition: roadflare.c:24
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
NoiseParams
class ObjectSpawnerHandler NoiseParams
ActionLightItemOnFire
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
Definition: actionlightitemonfire.c:11
m_ParMainFire
protected Particle m_ParMainFire
Definition: flaresimulation.c:2
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ScriptedLightBase
Definition: pointlightbase.c:1
ActionAttach
ActionAttachWheels ActionAttach
UNCAPPED_BURNED_OUT
@ UNCAPPED_BURNED_OUT
Definition: roadflare.c:21
TripwireTrap
void TripwireTrap()
Definition: trap_tripwire.c:23
DEFAULT
@ DEFAULT
Definition: roadflare.c:18
Timer
Definition: dayzplayerimplement.c:62
GetEnergy
float GetEnergy()
Definition: itembase.c:3461
m_BurningSound
protected EffectSound m_BurningSound
Definition: flaresimulation.c:3
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
NOT_BURNING
@ NOT_BURNING
Definition: roadflare.c:9