Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
flaresimulation.c
Go to the documentation of this file.
2{
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 // flare effect rotation
15 protected const float FLARE_SPIN_RATE = 1.15; // in degrees per simul tick
16 protected const float FLARE_SPIN_RADIUS = 0.18; // radius of circling motion
17 protected Entity m_Flare;
20 protected float m_RotationDegrees;
21
22 static protected typename m_ScriptedLight;
23 static protected int m_ParticleId;
24
26 {
28 m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE;
29 }
30
31 void OnActivation(Entity flare)
32 {
33 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() )
34 {
35 m_FlareLight = FlareLight.Cast( ScriptedLightBase.CreateLight( m_ScriptedLight, Vector(0,0,0) ) );
36 if ( m_FlareLight )
37 m_FlareLight.AttachOnObject( flare );
38
39 if (m_ParMainFire)
41
42 m_Flare = flare;
43 m_RotationPoint = m_Flare.GetOrigin();
45
47
48 flare.PlaySoundSetLoop( m_BurningSound, "roadflareLoop_SoundSet", 0, 0 );
49 }
50
51 if ( GetGame().IsServer() )
52 {
53 // Create and load noise parameters
54 m_NoisePar = new NoiseParams();
55 m_NoisePar.LoadFromPath("cfgWeapons Flaregun_Base NoiseFlare");
56 }
57 }
58
60 {
61 //MiscGameplayFunctions.GenerateAINoiseAtPosition(flare.GetPosition(), NOISE_DELAY, m_NoisePar);
62 }
63
64 void OnFire( Entity flare)
65 {
66 //m_ParMainFire = ParticleManager.GetInstance().PlayOnObject( ParticleList.FLAREPROJ_FIRE, flare);
67 //m_ParMainFire.SetWiggle( 7, 0.3);
68 }
69
70 void Simulate( Entity flare )
71 {
72 DayZPlayer player = GetGame().GetPlayer();
73 if ( player )
74 vector playerPos = player.GetPosition();
75
76 float dist = vector.DistanceSq(flare.GetPosition(), playerPos);
77
79 m_ParMainFire.SetParameter( 0, EmitorParam.SIZE, MiscGameplayFunctions.Normalize(dist, MAX_FARLIGHT_DIST * MAX_FARLIGHT_DIST) );
80
83
84 //CastFlareAINoise( flare.GetPosition() );
86 }
87
88 // Rotate flare particle and set its new position
89 protected void FlareParticleUpdate()
90 {
92 if (m_RotationDegrees > 360)
94
95 float angleRad = m_RotationDegrees * Math.DEG2RAD;
96 float sin = Math.Sin(angleRad);
97 float cos = Math.Cos(angleRad);
98
99 vector newFlarePos = m_ParMainFire.GetOrigin();
100 float surfacePos = GetGame().SurfaceY(newFlarePos[0], newFlarePos[2]);
101
102 if (newFlarePos[1] - surfacePos < 1) // reached ground
103 {
104 if (m_Flare.GetOrigin()[1] <= surfacePos) // actual flare pos might not match and height could be underground
105 m_ParMainFire.SetPosition(Vector(newFlarePos[0], surfacePos, newFlarePos[2]));
106 else
107 m_ParMainFire.SetPosition(Vector(newFlarePos[0], m_Flare.GetOrigin()[1] ,newFlarePos[2]));
108
109 return;
110 }
111
112 // rotate vector around point
113 float xRotated = ((m_FlarePosition[0] - m_RotationPoint[0]) * cos) - ((m_FlarePosition[2] - m_RotationPoint[2]) * sin) + m_RotationPoint[0];
114 float yRotated = ((m_FlarePosition[0] - m_RotationPoint[0]) * sin) + ((m_FlarePosition[2] - m_RotationPoint[2]) * cos) + m_RotationPoint[2];
115
116 newFlarePos[0] = xRotated;
117 newFlarePos[1] = m_Flare.GetOrigin()[1];
118 newFlarePos[2] = yRotated;
119
120 m_ParMainFire.SetPosition(newFlarePos);
121
122 }
123
124 void CastFlareAINoise( vector position )
125 {
126 if ( m_LastNoiseTime < 0 )
127 m_LastNoiseTime = GetGame().GetTime() * 0.0033;
128
129 float delta_time = GetGame().GetTime() * 0.0033 - m_LastNoiseTime;
130 m_LastNoiseTime = GetGame().GetTime() * 0.0033;
131
132 m_NoiseTimer += delta_time;
133
134 if ( m_NoiseTimer >= NOISE_DELAY )
135 {
136 MiscGameplayFunctions.GenerateAINoiseAtPosition(position, NOISE_DELAY, m_NoisePar);
137
138 m_NoiseTimer = 0;
139 }
140 }
141
143 {
144 if (m_ParMainFire)
145 {
146 m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME, 0);
147 m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME_RND, 0);
148 m_ParMainFire.SetParameter(0, EmitorParam.REPEAT, 0);
149 m_ParMainFire.SetParameter(0, EmitorParam.SIZE, 0);
150 }
151 }
152
154 {
155 if (m_ParMainFire)
157
158 if (m_BurningSound)
160
161 if (m_FlareLight)
162 m_FlareLight.FadeOut();
163 }
164}
165
167{
170 m_ScriptedLight = FlareLightRed;
171 m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE_RED;
172 }
173}
174
188 m_ScriptedLight = FlareLightBlue;
189 m_ParticleId = ParticleList.FLAREPROJ_ACTIVATE_BLUE;
190 }
proto native float SurfaceY(float x, float z)
proto int GetTime()
returns mission time in milliseconds
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
void SoundStop()
Stops sound.
Definition camera.c:2
EffectSound m_BurningSound
Particle m_ParMainFire
FlareLight m_FlareLight
static const float MAX_FARLIGHT_DIST
void CastFlareAINoise(vector position)
const float FLARE_SPIN_RATE
const float FLARE_SPIN_RADIUS
static ref NoiseParams m_NoisePar
void OnTermination(Entity flare)
void OnActivation(Entity flare)
static const float MIN_FARLIGHT_DIST
void OnFire(Entity flare)
const float NOISE_DELAY
void Simulate(Entity flare)
TODO doc.
Definition enscript.c:118
Definition enmath.c:7
Legacy way of using particles in the game.
Definition particle.c:7
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition particle.c:174
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition particle.c:266
void FlareLightGreen()
Definition flarelight.c:57
class FlareLightGreen extends FlareLight FlareLightBlue()
Definition flarelight.c:56
class FlareLight extends PointLightBase FlareLightRed()
Definition flarelight.c:38
void FlareLight()
Definition flarelight.c:43
FlareSimulation_Green FlareSimulation FlareSimulation_Blue()
FlareSimulation Managed FlareSimulation_Red()
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EmitorParam
Definition envisual.c:114
class NoiseSystem NoiseParams()
Definition noise.c:15
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)