Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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
30
31 void OnActivation(Entity flare)
32 {
33 if ( !g_Game.IsServer() || !g_Game.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)
40 m_ParMainFire.Stop();
41
42 m_Flare = flare;
43 m_RotationPoint = m_Flare.GetOrigin();
45
46 m_ParMainFire = ParticleManager.GetInstance().PlayInWorld( m_ParticleId, m_FlarePosition );
47
48 flare.PlaySoundSetLoop( m_BurningSound, "roadflareLoop_SoundSet", 0, 0 );
49 }
50
51 if ( g_Game.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 = g_Game.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 = g_Game.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 int currentTime = g_Game.GetTime();
127 float timeAdjusted = currentTime * 0.0033;
128 if ( m_LastNoiseTime < 0 )
129 m_LastNoiseTime = timeAdjusted;
130
131 float delta_time = timeAdjusted - m_LastNoiseTime;
132 m_LastNoiseTime = timeAdjusted;
133
134 m_NoiseTimer += delta_time;
135
136 if ( m_NoiseTimer >= NOISE_DELAY )
137 {
138 MiscGameplayFunctions.GenerateAINoiseAtPosition(position, NOISE_DELAY, m_NoisePar);
139
140 m_NoiseTimer = 0;
141 }
142 }
143
145 {
146 if (m_ParMainFire)
147 {
148 m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME, 0);
149 m_ParMainFire.SetParameter(0, EmitorParam.LIFETIME_RND, 0);
150 m_ParMainFire.SetParameter(0, EmitorParam.REPEAT, 0);
151 m_ParMainFire.SetParameter(0, EmitorParam.SIZE, 0);
152 }
153 }
154
156 {
157 if (m_ParMainFire)
158 m_ParMainFire.Stop();
159
160 if (m_BurningSound)
161 m_BurningSound.SoundStop();
162
163 if (m_FlareLight)
164 m_FlareLight.FadeOut();
165 }
166}
167
169{
176
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
Definition camera.c:2
static const float MIN_FARLIGHT_DIST
EffectSound m_BurningSound
static ref NoiseParams m_NoisePar
const float NOISE_DELAY
const float FLARE_SPIN_RADIUS
void Simulate(Entity flare)
void OnFire(Entity flare)
void CastFlareAINoise(vector position)
FlareLight m_FlareLight
void OnTermination(Entity flare)
const float FLARE_SPIN_RATE
static const float MAX_FARLIGHT_DIST
void OnActivation(Entity flare)
Particle m_ParMainFire
TODO doc.
Definition enscript.c:118
Definition enmath.c:7
Legacy way of using particles in the game.
Definition particle.c:7
static const int FLAREPROJ_ACTIVATE_GREEN
static const int FLAREPROJ_ACTIVATE_RED
static const int FLAREPROJ_ACTIVATE_BLUE
static const int FLAREPROJ_ACTIVATE
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
DayZGame g_Game
Definition dayzgame.c:3942
class FlareLightGreen extends FlareLight FlareLightBlue()
Definition flarelight.c:56
void FlareLightGreen()
Definition flarelight.c:57
FlareSimulation_Green FlareSimulation FlareSimulation_Blue()
FlareSimulation Managed FlareSimulation_Red()
m_ScriptedLight
int m_ParticleId
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static const float DEG2RAD
Definition enmath.c:17
static proto float Sin(float angle)
Returns sinus of angle in radians.
EmitorParam
Definition envisual.c:114
class NoiseSystem NoiseParams()
Definition noise.c:15
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor).