Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
flaresimulation.c
Go to the documentation of this file.
2 {
3  protected Particle m_ParMainFire;
4  protected EffectSound m_BurningSound;
5  protected FlareLight m_FlareLight;
6  const static float MAX_FARLIGHT_DIST = 40;
7  const static float MIN_FARLIGHT_DIST = 5;
8 
9  static ref NoiseParams m_NoisePar; // Contains the noise data ( template and strength )
10  float m_LastNoiseTime = -1;
11  float m_NoiseTimer = 0;
12  const float NOISE_DELAY = 5; // How much time between two consecutive noise pings
13 
14  static protected typename m_ScriptedLight;
15  static protected int m_ParticleId;
16 
17  void FlareSimulation()
18  {
19  m_ScriptedLight = FlareLight;
20  m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE;
21  }
22 
23  void OnActivation(Entity flare)
24  {
25  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() )
26  {
27  m_FlareLight = FlareLight.Cast( ScriptedLightBase.CreateLight( m_ScriptedLight, Vector(0,0,0) ) );
28  if ( m_FlareLight )
29  m_FlareLight.AttachOnObject( flare );
30 
31  if (m_ParMainFire)
32  m_ParMainFire.Stop();
33 
34  m_ParMainFire = ParticleManager.GetInstance().PlayOnObject( m_ParticleId, flare );
35  m_ParMainFire.SetWiggle( 7, 0.3 );
36 
37  flare.PlaySoundSetLoop( m_BurningSound, "roadflareLoop_SoundSet", 0, 0 );
38  }
39 
40  if ( GetGame().IsServer() )
41  {
42  // Create and load noise parameters
43  m_NoisePar = new NoiseParams();
44  m_NoisePar.LoadFromPath("cfgWeapons Flaregun_Base NoiseFlare");
45  }
46  }
47 
48  void OnTermination(Entity flare)
49  {
50  //MiscGameplayFunctions.GenerateAINoiseAtPosition(flare.GetPosition(), NOISE_DELAY, m_NoisePar);
51  }
52 
53  void OnFire( Entity flare)
54  {
55  //m_ParMainFire = ParticleManager.GetInstance().PlayOnObject( ParticleList.FLAREPROJ_FIRE, flare);
56  //m_ParMainFire.SetWiggle( 7, 0.3);
57  }
58 
59  void Simulate( Entity flare )
60  {
61  DayZPlayer player = GetGame().GetPlayer();
62  if ( player )
63  vector playerPos = player.GetPosition();
64 
65  float dist = vector.DistanceSq(flare.GetPosition(), playerPos);
66 
67  if ( ( dist <= MAX_FARLIGHT_DIST * MAX_FARLIGHT_DIST ) && ( dist > MIN_FARLIGHT_DIST * MIN_FARLIGHT_DIST ) )
68  m_ParMainFire.SetParameter( 0, EmitorParam.SIZE, MiscGameplayFunctions.Normalize(dist, MAX_FARLIGHT_DIST * MAX_FARLIGHT_DIST) );
69 
70  if ( dist <= MIN_FARLIGHT_DIST * MIN_FARLIGHT_DIST )
71  TurnOffDistantLight();
72 
73  //CastFlareAINoise( flare.GetPosition() );
74  }
75 
76  void CastFlareAINoise( vector position )
77  {
78  if ( m_LastNoiseTime < 0 )
79  m_LastNoiseTime = GetGame().GetTime() * 0.0033;
80 
81  float delta_time = GetGame().GetTime() * 0.0033 - m_LastNoiseTime;
82  m_LastNoiseTime = GetGame().GetTime() * 0.0033;
83 
84  m_NoiseTimer += delta_time;
85 
86  if ( m_NoiseTimer >= NOISE_DELAY )
87  {
88  MiscGameplayFunctions.GenerateAINoiseAtPosition(position, NOISE_DELAY, m_NoisePar);
89 
90  m_NoiseTimer = 0;
91  }
92  }
93 
94  void TurnOffDistantLight()
95  {
96  if (m_ParMainFire)
97  {
98  m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME, 0);
99  m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME_RND, 0);
100  m_ParMainFire.SetParameter(0, EmitorParam.REPEAT, 0);
101  m_ParMainFire.SetParameter(0, EmitorParam.SIZE, 0);
102  }
103  }
104 
105  void ~FlareSimulation()
106  {
107  if (m_ParMainFire)
108  m_ParMainFire.Stop();
109 
110  if (m_BurningSound)
111  m_BurningSound.SoundStop();
112 
113  if (m_FlareLight)
114  m_FlareLight.FadeOut();
115  }
116 }
117 
119 {
121  {
122  m_ScriptedLight = FlareLightRed;
123  m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE_RED;
124  }
125 }
126 
128 {
129  void FlareSimulation_Green()
130  {
131  m_ScriptedLight = FlareLightGreen;
132  m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE_GREEN;
133  }
134 }
135 
137 {
139  {
140  m_ScriptedLight = FlareLightBlue;
141  m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE_BLUE;
142  }
143 }
FlareSimulation_Red
FlareSimulation Managed FlareSimulation_Red()
Definition: flaresimulation.c:120
GetGame
proto native CGame GetGame()
FlareSimulation
Definition: flaresimulation.c:1
FlareLightGreen
void FlareLightGreen()
Definition: flarelight.c:2
FlareLight
Definition: flarelight.c:45
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
m_LastNoiseTime
float m_LastNoiseTime
Definition: flaresimulation.c:9
FlareLightBlue
class GoatLight extends PointLightBase FlareLightBlue
m_FlareLight
protected FlareLight m_FlareLight
Definition: flaresimulation.c:4
FlareSimulation_Blue
FlareSimulation_Green FlareSimulation FlareSimulation_Blue()
Definition: flaresimulation.c:138
Managed
TODO doc.
Definition: enscript.c:117
m_NoiseTimer
float m_NoiseTimer
Definition: flaresimulation.c:10
FlareLightRed
class FlareLight extends PointLightBase FlareLightRed()
Definition: flarelight.c:38
EmitorParam
EmitorParam
Definition: envisual.c:113
DayZPlayer
Definition: dayzplayerimplement.c:72
FlareSimulation_Green
Definition: flaresimulation.c:127
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
m_ParMainFire
protected Particle m_ParMainFire
Definition: flaresimulation.c:2
ScriptedLightBase
Definition: pointlightbase.c:1
m_NoisePar
ref NoiseParams m_NoisePar
Definition: actionopendoors.c:2
FlareLight
void FlareLight()
Definition: flarelight.c:6
Entity
Definition: camera.c:1
m_BurningSound
protected EffectSound m_BurningSound
Definition: flaresimulation.c:3
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
NOISE_DELAY
const float NOISE_DELAY
Definition: flaresimulation.c:11