Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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
11 class ShellLight extends PointLightBase
12 {
13  protected float m_DefaultBrightness = 10;
14  protected float m_DefaultRadius = 100;
15 
16  void ShellLight()
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 {
33  protected ref Timer m_StartupTimer;
34  protected ref Timer m_FXTimer;
35  protected FlareLight m_FlareLight;
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
41  const int AIRBORNE_EXPLOSION_DELAY = 20;
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;
48  const int DECAY_START_PART_BIRTH_RATE = 1;
49  const float DECAY_END_PART_SIZE = 17;
50  const int DECAY_END_PART_BIRTH_RATE = 1;
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() )
70  m_PPERequesterIdx = GetRequesterIndex(m_PPERequesterType);
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  {
77  vector areaPos = GetPosition();
78  m_OffsetPos = areaPos;
79  m_OffsetPos[1] = m_OffsetPos[1] + AIRBORNE_FX_OFFSET;
80 
81  // play artillery sound, sent to be played for everyone on server
82  array<vector> artilleryPoints = GetGame().GetMission().GetWorldData().GetArtyFiringPos();
83  vector closestPoint = areaPos;
84  int dist = 0;
85  int temp;
86  int index = 0;
87  for ( int i = 0; i < artilleryPoints.Count(); i++ )
88  {
89  temp = vector.DistanceSq( artilleryPoints.Get( i ), areaPos );
90  if ( temp < dist || dist == 0 )
91  {
92  dist = temp;
93  index = i;
94  }
95  }
96 
97  closestPoint = artilleryPoints.Get( index );
98 
99  // We calculate the delay depending on distance from firing position to simulate shell travel time
100  float delay = vector.Distance( closestPoint, areaPos );
101  delay = delay / ARTILLERY_SHELL_SPEED;
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
108  pos = new Param3<vector, vector, float>( closestPoint, areaPos, delay );
109  params = new array<ref Param>;
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 
115  m_FXTimer = new Timer( CALL_CATEGORY_GAMEPLAY );
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
120  m_StartupTimer = new Timer( CALL_CATEGORY_GAMEPLAY );
121  m_StartupTimer.Run( delay, this, "InitZone" );
122  }
123  }
124 
125  float GetRemainingTime()
126  {
127  return GetLifetime();
128  }
129 
130  float GetStartDecayLifetime()
131  {
132  return START_DECAY_LIFETIME;
133  }
134 
135  float GetFinishDecayLifetime()
136  {
137  return FINISH_DECAY_LIFETIME;
138  }
139 
140  override void Tick()
141  {
142  if ( GetRemainingTime() < GetFinishDecayLifetime() )
143  {
144  // The second state of decay, further reduction of particle density and size
145  SetDecayState( eAreaDecayStage.DECAY_END );
146  }
147  else if ( GetRemainingTime() < GetStartDecayLifetime() )
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
156  void SetDecayState( int newState )
157  {
158  if (m_DecayState != newState)
159  {
160  m_DecayState = newState;
161 
162  // We update the trigger state values as we also want to update player bound effects
163  if ( m_Trigger )
164  ContaminatedTrigger_Dynamic.Cast( m_Trigger ).SetAreaState( m_DecayState );
165 
166  SetSynchDirty();
167  }
168  }
169 
170  override void EEInit()
171  {
172  // We make sure we have the particle array
173  if ( !m_ToxicClouds )
174  m_ToxicClouds = new array<Particle>;
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;
179  m_PositiveHeight = 7;
180  m_NegativeHeight = 10;
181  m_InnerRings = 1;
182  m_InnerSpacing = 40;
183  m_OuterSpacing = 30;
184  m_OuterRingOffset = 0;
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 
200  m_OffsetPos = GetPosition();
201  m_OffsetPos[1] = m_OffsetPos[1] + AIRBORNE_FX_OFFSET;
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  {
218  m_DecayState = eAreaDecayStage.LIVE;
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 != "" )
231  CreateTrigger( m_Position, m_Radius );
232  }
233 
234  void SpawnItems()
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  {
242  vector randomDir2d = vector.RandomDir2D();
243  float randomDist = Math.RandomFloatInclusive(SPAWN_ITEM_RAD_MIN[j],SPAWN_ITEM_RAD_MAX[j]);
244  vector spawnPos = m_Position + (randomDir2d * randomDist);
246  vector mat[4];
247  Math3D.MatrixIdentity4(mat);
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 )
261  m_ToxicClouds = new array<Particle>;
262 
263  // We spawn VFX on client
264  PlaceParticles( GetWorldPosition(), m_Radius, m_InnerRings, m_InnerSpacing, m_OuterRingToggle, m_OuterSpacing, m_OuterRingOffset, m_ParticleID );
265  }
266 
267  override void OnParticleAllocation(ParticleManager pm, array<ParticleSource> particles)
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
294  ContaminatedTrigger_Dynamic dynaTrigger = ContaminatedTrigger_Dynamic.Cast( m_Trigger );
295  if ( dynaTrigger )
296  {
297  dynaTrigger.SetLocalEffects( m_AroundParticleID, m_TinyParticleID, m_PPERequesterIdx );
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 );
311  params = new array<ref Param>;
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
319  m_DecayState = eAreaDecayStage.START;
320  SetSynchDirty();
321  }
322  }
323 
324  void PlayExplosionLight()
325  {
326  m_ShellLight = ShellLight.Cast( ScriptedLightBase.CreateLight( ShellLight, m_OffsetPos ) );
327  }
328 
329  void PlayFlareVFX()
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 
346  override void OnVariablesSynchronized()
347  {
348  super.OnVariablesSynchronized();
349 
350  if ( !m_ToxicClouds )
351  m_ToxicClouds = new array<Particle>;
352 
353  switch ( m_DecayState )
354  {
355  case eAreaDecayStage.START:
356  PlayExplosionLight();
357  break;
358  case eAreaDecayStage.LIVE:
359  InitZoneClient();
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 }
eZoneType
eZoneType
Definition: effectarea.c:2
GetGame
proto native CGame GetGame()
FlareLight
Definition: flarelight.c:45
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
DECAY_START
@ DECAY_START
Definition: contaminatedarea_dynamic.c:6
m_Type
eBleedingSourceType m_Type
Definition: bleedingsource.c:25
m_Position
protected vector m_Position
Cached world position.
Definition: effect.c:41
PointLightBase
Definition: staticobj_roadblock_wood_small.c:27
m_FlareLight
protected FlareLight m_FlareLight
Definition: flaresimulation.c:4
m_Name
string m_Name
Definition: bioslobbyservice.c:35
DynamicArea_Flare
Definition: dynamicarea_flare.c:2
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ContaminatedTrigger_Dynamic
void ContaminatedTrigger_Dynamic()
Definition: contaminatedtrigger.c:91
m_Radius
float m_Radius
Definition: aigroupbehaviour.c:10
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
Param3
Definition: entityai.c:95
eAreaDecayStage
eAreaDecayStage
Definition: contaminatedarea_dynamic.c:1
EmitorParam
EmitorParam
Definition: envisual.c:113
INIT
@ INIT
Definition: contaminatedarea_dynamic.c:3
m_DefaultRadius
protected float m_DefaultRadius
Definition: contaminatedarea_dynamic.c:14
DECAY_END
@ DECAY_END
Definition: contaminatedarea_dynamic.c:7
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
vector
Definition: enconvert.c:105
START
@ START
Definition: contaminatedarea_dynamic.c:4
m_DefaultBrightness
enum eAreaDecayStage m_DefaultBrightness
ScriptedLightBase
Definition: pointlightbase.c:1
array< string >
ContaminatedArea_Base
Definition: contaminatedarea.c:1
ShellLight
void ShellLight()
Definition: contaminatedarea_dynamic.c:16
ParticleSource
Entity which has the particle instance as an ObjectComponent.
Definition: particlesource.c:123
ContaminatedArea_Dynamic
Definition: contaminatedarea_dynamic.c:31
LIVE
@ LIVE
Definition: contaminatedarea_dynamic.c:5
ECE_SETUP
const int ECE_SETUP
Definition: centraleconomy.c:9
ERPCs
ERPCs
Definition: erpcs.c:1
Timer
Definition: dayzplayerimplement.c:62
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
EntityAI
Definition: building.c:5
Math3D
Definition: enmath3d.c:27