DayZ 1.24
Loading...
Searching...
No Matches
ContaminatedArea_Dynamic.c
Go to the documentation of this file.
2{
3 INIT = 1, // The dynamic area is initializing
4 START = 2, // The dynamic area is starting
5 LIVE = 3, // The dynamic area is live
6 DECAY_START = 4, // The dynamic area decay has started
7 DECAY_END = 5, // The dynamic area will soon be deleted
8}
9
10// The parameters for the explosion light when creating dynamic area
11class ShellLight extends PointLightBase
12{
13 protected float m_DefaultBrightness = 10;
14 protected float m_DefaultRadius = 100;
15
17 {
18 SetVisibleDuringDaylight(false);
19 SetRadiusTo(m_DefaultRadius);
20 SetBrightnessTo(m_DefaultBrightness);
21 SetFlareVisible(false);
22 SetAmbientColor(1.0, 1.0, 0.3);
23 SetDiffuseColor(1.0, 1.0, 0.3);
24 SetLifetime(0.15);
25 SetDisableShadowsWithinRadius(-1);
26 SetCastShadow(false);
27 }
28}
29
30// The dynamic Contaminated area, using it's own default settings
32{
34 protected ref Timer m_FXTimer;
36 protected ShellLight m_ShellLight; // Light used upon ariborne shell detonation
37 protected vector m_OffsetPos; // This will be the position at which we spawn all future airborne FX
38 protected int m_DecayState = eAreaDecayStage.INIT; // The current state in which the area is
39
40 // Constants used for startup events
42 const int AREA_SETUP_DELAY = 10;
43 const float AIRBORNE_FX_OFFSET = 50;
44 const float ARTILLERY_SHELL_SPEED = 100; // Units per second
45
46 // Constants used for dissapearing events
47 const float DECAY_START_PART_SIZE = 32;
49 const float DECAY_END_PART_SIZE = 17;
51 const float START_DECAY_LIFETIME = 900;
52 const float FINISH_DECAY_LIFETIME = 300;
53
54 // Item Spawning upon area creation, the 4 arrays bellow have to have the same amount of elements
55 const ref array<string> SPAWN_ITEM_TYPE = {"Grenade_ChemGas"};//item classnames
56 const ref array<int> SPAWN_ITEM_COUNT = {Math.RandomIntInclusive(2, 5)}; //how many of each type
57 const ref array<float> SPAWN_ITEM_RAD_MIN = {5};//min distance the item will be spawned from the area position(epicenter)
58 const ref array<float> SPAWN_ITEM_RAD_MAX = {15};//max distance the item will be spawned from the area position(epicenter)
59
60
62 {
63 RegisterNetSyncVariableInt("m_DecayState");
64 }
65
66 override void EEOnCECreate()
67 {
68 // We get the PPE index for future usage and synchronization ( we must do it here for dynamic as it is not read through file )
69 if (GetGame().IsServer())
71
72 SetSynchDirty();
73
74 // If this is the first initialization, we delay it in order to play cool effects
75 if (m_DecayState == eAreaDecayStage.INIT)
76 {
80
81 // play artillery sound, sent to be played for everyone on server
82 array<vector> artilleryPoints = GetGame().GetMission().GetWorldData().GetArtyFiringPos();
84 int dist = 0;
85 int temp;
86 int index = 0;
87 for (int i = 0; i < artilleryPoints.Count(); i++)
88 {
90 if (temp < dist || dist == 0)
91 {
92 dist = temp;
93 index = i;
94 }
95 }
96
98
99 // We calculate the delay depending on distance from firing position to simulate shell travel time
102 delay += AIRBORNE_EXPLOSION_DELAY; // We add the base, minimum time ( no area can start before this delay )
103
104 Param3<vector, vector, float> pos; // The value to be sent through RPC
105 array<ref Param> params; // The RPC params
106
107 // We prepare to send the message
110
111 // We send the message with this set of coords
112 params.Insert(pos);
113 GetGame().RPC(null, ERPCs.RPC_SOUND_ARTILLERY_SINGLE, params, true);
114
116 m_FXTimer.Run(delay, this, "PlayFX");
117
118 delay += AREA_SETUP_DELAY; // We have an additional delay between shell detonation and finalization of area creation
119 // setup zone
121 m_StartupTimer.Run(delay, this, "InitZone");
122 }
123 }
124
126 {
127 return GetLifetime();
128 }
129
131 {
133 }
134
136 {
138 }
139
140 override void Tick()
141 {
143 {
144 // The second state of decay, further reduction of particle density and size
146 }
148 {
149 // The first state of decay, slight reduction in particle density and size
150 SetDecayState(eAreaDecayStage.DECAY_START);
151 }
152
153 }
154
155 // Set the new state of the Area
157 {
158 if (m_DecayState != newState)
159 {
161
162 // We update the trigger state values as we also want to update player bound effects
163 if (m_Trigger)
165
166 SetSynchDirty();
167 }
168 }
169
170 override void EEInit()
171 {
172 // We make sure we have the particle array
173 if (!m_ToxicClouds)
175
176 // We set the values for dynamic area as these are not set through JSON and are standardized
177 m_Name = "Default Dynamic";
178 m_Radius = 120;
180 m_NegativeHeight = 10;
181 m_InnerRings = 1;
182 m_InnerSpacing = 40;
183 m_OuterSpacing = 30;
185 m_Type = eZoneType.DYNAMIC;
186 m_TriggerType = "ContaminatedTrigger_Dynamic";
187
188 SetSynchDirty();
189
190#ifdef DEVELOPER
191 // Debugs when placing entity by hand using internal tools
192 /*if ( GetGame().IsServer() && !GetGame().IsMultiplayer() )
193 {
194 Debug.Log("YOU CAN IGNORE THE FOLLOWING DUMP");
195 InitZone();
196 Debug.Log("YOU CAN USE FOLLOWING DATA PROPERLY");
197 }*/
198#endif
199
202
203 // If a player arrives slightly later during the creation process we check if playing the flare FX is relevant
204 if (m_DecayState == eAreaDecayStage.INIT)
205 PlayFlareVFX();
206
207 if (m_DecayState == eAreaDecayStage.LIVE)
208 InitZone(); // If it has already been created, we simply do the normal setup, no cool effects, force the LIVE state
209 else if (GetGame().IsClient() && m_DecayState > eAreaDecayStage.LIVE)
210 InitZoneClient(); // Same as before but without state forcing
211
212 super.EEInit();
213 }
214
215 // We spawn particles and setup trigger
216 override void InitZone()
217 {
219 SetSynchDirty();
220
221 super.InitZone();
222 }
223
224 override void InitZoneServer()
225 {
226 super.InitZoneServer();
227
228 SpawnItems();
229 // We create the trigger on server
230 if (m_TriggerType != "")
232 }
233
235 {
236 //Print("---------============ Spawning items at pos:"+m_Position);
237 foreach (int j, string type: SPAWN_ITEM_TYPE)
238 {
239 //Print("----------------------------------");
240 for (int i = 0; i < SPAWN_ITEM_COUNT[j]; i++)
241 {
246 vector mat[4];
248 mat[3] = spawnPos;
249 il.SetGround(NULL, mat);
250 //Print("Spawning item:"+ type + " at position:" + il.GetPos());
251 GetGame().CreateObjectEx(type, il.GetPos(), ECE_PLACE_ON_SURFACE);
252 }
253 }
254 }
255
256 override void InitZoneClient()
257 {
258 super.InitZoneClient();
259
260 if (!m_ToxicClouds)
262
263 // We spawn VFX on client
265 }
266
268 {
269 super.OnParticleAllocation(pm, particles);
270
271 if (m_DecayState > eAreaDecayStage.LIVE)
272 {
273 foreach (ParticleSource p : particles)
274 {
275 if (m_DecayState == eAreaDecayStage.DECAY_END)
276 {
277 p.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_END_PART_BIRTH_RATE);
278 p.SetParameter(0, EmitorParam.SIZE, DECAY_END_PART_SIZE);
279 }
280 else
281 {
282 p.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_START_PART_BIRTH_RATE);
283 p.SetParameter(0, EmitorParam.SIZE, DECAY_START_PART_SIZE);
284 }
285 }
286 }
287 }
288
289 override void CreateTrigger(vector pos, int radius)
290 {
291 super.CreateTrigger(pos, radius);
292
293 // This handles the specific case of dynamic triggers as some additionnal parameters are present
295 if (dynaTrigger)
296 {
298 dynaTrigger.SetAreaState(m_DecayState);
299 }
300 }
301
302 void PlayFX()
303 {
304 if (GetGame().IsServer())
305 {
306 Param1<vector> pos; // The value to be sent through RPC
307 array<ref Param> params; // The RPC params
308
309 // We prepare to send the message
310 pos = new Param1<vector>(vector.Zero);
312
313 // We send the message with this set of coords
314 pos.param1 = m_OffsetPos;
315 params.Insert(pos);
316 GetGame().RPC(null, ERPCs.RPC_SOUND_CONTAMINATION, params, true);
317
318 // We go to the next stage
320 SetSynchDirty();
321 }
322 }
323
328
330 {
331 if (GetGame().IsClient() || (GetGame().IsServer() && !GetGame().IsMultiplayer()))
332 {
333 // We spawn locally the dummy object which will be used to move and manage the particle
334 DynamicArea_Flare dummy = DynamicArea_Flare.Cast(GetGame().CreateObjectEx("DynamicArea_Flare", m_OffsetPos, ECE_SETUP | ECE_LOCAL));
335
336 // We add some light to reinforce the effect
337 m_FlareLight = FlareLightContamination.Cast(ScriptedLightBase.CreateLight(FlareLightContamination, m_OffsetPos));
338 }
339 }
340
341 override void EEDelete(EntityAI parent)
342 {
343 super.EEDelete(parent);
344 }
345
347 {
348 super.OnVariablesSynchronized();
349
350 if (!m_ToxicClouds)
352
353 switch (m_DecayState)
354 {
355 case eAreaDecayStage.START:
357 break;
358 case eAreaDecayStage.LIVE:
360
361 break;
362 case eAreaDecayStage.DECAY_START:
363 {
364 // We go through all the particles bound to this area and update relevant parameters
365 //Debug.Log("We start decay");
366 foreach (Particle p : m_ToxicClouds)
367 {
368 p.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_START_PART_BIRTH_RATE);
369 p.SetParameter(0, EmitorParam.SIZE, DECAY_START_PART_SIZE);
370 }
371
372 break;
373 }
374 case eAreaDecayStage.DECAY_END:
375 {
376 // We go through all the particles bound to this area and update relevant parameters
377 //Debug.Log("We finish decay");
378 foreach (Particle prt : m_ToxicClouds)
379 {
380 prt.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_END_PART_BIRTH_RATE);
381 prt.SetParameter(0, EmitorParam.SIZE, DECAY_END_PART_SIZE);
382 }
383
384 break;
385 }
386 default:
387 break;
388 }
389 }
390}
const int ECE_LOCAL
const int ECE_PLACE_ON_SURFACE
const int ECE_SETUP
float m_DefaultRadius
enum eAreaDecayStage m_DefaultBrightness
void ShellLight()
void ContaminatedTrigger_Dynamic()
ERPCs
Definition ERPCs.c:2
eZoneType
Definition EffectArea.c:3
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
void CreateTrigger()
Definition TrapBase.c:468
class JsonUndergroundAreaTriggerData GetPosition
const ref array< float > SPAWN_ITEM_RAD_MAX
override void EEDelete(EntityAI parent)
override void CreateTrigger(vector pos, int radius)
const ref array< string > SPAWN_ITEM_TYPE
const ref array< int > SPAWN_ITEM_COUNT
override void OnParticleAllocation(ParticleManager pm, array< ParticleSource > particles)
const ref array< float > SPAWN_ITEM_RAD_MIN
string m_Name
Definition EffectArea.c:39
ref array< Particle > m_ToxicClouds
Definition EffectArea.c:72
vector m_Position
Definition EffectArea.c:41
int GetRequesterIndex(string type)
Definition EffectArea.c:375
bool m_OuterRingToggle
Definition EffectArea.c:53
float m_NegativeHeight
Definition EffectArea.c:46
float m_PositiveHeight
Definition EffectArea.c:45
EffectTrigger m_Trigger
Definition EffectArea.c:70
string m_TriggerType
Definition EffectArea.c:69
int m_PPERequesterIdx
Definition EffectArea.c:65
int m_InnerRings
Definition EffectArea.c:50
string m_PPERequesterType
Definition EffectArea.c:64
float m_Radius
Definition EffectArea.c:44
int m_OuterRingOffset
Definition EffectArea.c:54
int m_InnerSpacing
Definition EffectArea.c:51
int m_ParticleID
Definition EffectArea.c:61
int m_TinyParticleID
Definition EffectArea.c:63
int m_AroundParticleID
Definition EffectArea.c:62
void PlaceParticles(vector pos, float radius, int nbRings, int innerSpacing, bool outerToggle, int outerSpacing, int outerOffset, int partId)
Definition EffectArea.c:218
int m_OuterSpacing
Definition EffectArea.c:55
InventoryLocation.
Definition EnMath.c:7
Legacy way of using particles in the game.
Definition Particle.c:7
Entity which has the particle instance as an ObjectComponent.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static const vector Zero
Definition EnConvert.c:110
static vector RandomDir2D()
Returns randomly generated XZ unit vector with the Y(up) axis set to 0.
Definition EnConvert.c:260
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition EnMath3D.c:233
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
EmitorParam
Definition EnVisual.c:114
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10