Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
contaminatedarea_dynamic.c
Go to the documentation of this file.
1// The parameters for the explosion light when creating dynamic area
3{
4 protected float m_DefaultBrightness = 10;
5 protected float m_DefaultRadius = 100;
6
7 void ShellLight()
8 {
9 SetVisibleDuringDaylight(false);
10 SetRadiusTo(m_DefaultRadius);
11 SetBrightnessTo(m_DefaultBrightness);
12 SetFlareVisible(false);
13 SetAmbientColor(1.0, 1.0, 0.3);
14 SetDiffuseColor(1.0, 1.0, 0.3);
15 SetLifetime(0.15);
16 SetDisableShadowsWithinRadius(-1);
17 SetCastShadow( false );
18 }
19}
20
21// The dynamic Contaminated area, using it's own default settings
22class ContaminatedArea_Dynamic : ContaminatedArea_DynamicBase
23{
24 protected vector m_OffsetPos; // This will be the position at which we spawn all future airborne FX
25 protected ref Timer m_StartupTimer;
26 protected ref Timer m_FXTimer;
28 protected ShellLight m_ShellLight; // Light used upon ariborne shell detonation
29
30 // Constants used for startup events
32 const int AREA_SETUP_DELAY = 10;
33 const float AIRBORNE_FX_OFFSET = 50;
34 const float ARTILLERY_SHELL_SPEED = 100; // Units per second
35
36 // Item Spawning upon area creation, the 4 arrays bellow have to have the same amount of elements
37 const ref array<string> SPAWN_ITEM_TYPE = {"Grenade_ChemGas"};//item classnames
38 const ref array<int> SPAWN_ITEM_COUNT = {Math.RandomIntInclusive(2,5)};//how many of each type
39 const ref array<float> SPAWN_ITEM_RAD_MIN = {5};//min distance the item will be spawned from the area position(epicenter)
40 const ref array<float> SPAWN_ITEM_RAD_MAX = {15};//max distance the item will be spawned from the area position(epicenter)
41
42 override void EEOnCECreate()
43 {
44 // We get the PPE index for future usage and synchronization ( we must do it here for dynamic as it is not read through file )
45 m_PPERequesterIdx = GetRequesterIndex(m_PPERequesterType);
46
47 // If this is the first initialization, we delay it in order to play cool effects
48 if (m_DecayState == eAreaDecayStage.INIT)
49 {
50 vector areaPos = GetPosition();
51 m_OffsetPos = areaPos;
53 vector closestPoint = areaPos;
54
55 // play artillery sound, sent to be played for everyone on server
56 array<vector> artilleryPoints = g_Game.GetMission().GetWorldData().GetArtyFiringPos();
57 int index = 0;
58 foreach (int i, vector artilleryPoint : artilleryPoints)
59 {
60 int dist = 0;
61 int temp = vector.DistanceSq(artilleryPoint, areaPos);
62 if (temp < dist || dist == 0)
63 {
64 dist = temp;
65 index = i;
66 }
67 }
68
69 closestPoint = artilleryPoints.Get(index);
70
71 // We calculate the delay depending on distance from firing position to simulate shell travel time
72 float delay = vector.Distance(closestPoint, areaPos);
73 delay = delay / ARTILLERY_SHELL_SPEED;
74 delay += AIRBORNE_EXPLOSION_DELAY; // We add the base, minimum time ( no area can start before this delay )
75
76 Param3<vector, vector, float> pos = new Param3<vector, vector, float>(closestPoint, areaPos, delay);
78 // We send the message with this set of coords
79 params.Insert(pos);
80 g_Game.RPC(null, ERPCs.RPC_SOUND_ARTILLERY_SINGLE, params, true);
81
83 m_FXTimer.Run(delay, this, "PlayFX");
84
85 delay += AREA_SETUP_DELAY; // We have an additional delay between shell detonation and finalization of area creation
86 // setup zone
88 m_StartupTimer.Run(delay, this, "InitZone");
89 }
90
91 SetSynchDirty();
92 }
93
95 {
96 super.OnVariablesSynchronized();
97
98 switch (m_DecayState)
99 {
100 case eAreaDecayStage.START:
102 break;
103 }
104 }
105
106 override void Tick()
107 {
109 {
110 // The second state of decay, further reduction of particle density and size
111 SetDecayState( eAreaDecayStage.DECAY_END );
112 }
114 {
115 // The first state of decay, slight reduction in particle density and size
116 SetDecayState( eAreaDecayStage.DECAY_START );
117 }
118
119 }
120
121 override void SetupZoneData(EffectAreaParams params)
122 {
123 params.m_ParamName = string.Format("Dynamic area (%1)", m_Position.ToString());
124 params.m_ParamPartId = ParticleList.CONTAMINATED_AREA_GAS_BIGASS;
125 params.m_ParamAroundPartId = ParticleList.CONTAMINATED_AREA_GAS_AROUND;
126 params.m_ParamTinyPartId = ParticleList.CONTAMINATED_AREA_GAS_TINY;
127 params.m_ParamPosHeight = 7;
128 params.m_ParamNegHeight = 10;
129 params.m_ParamRadius = 120;
130 params.m_ParamInnerRings = 1;
131 params.m_ParamInnerSpace = 40;
132 params.m_ParamOuterSpace = 30;
133 params.m_ParamOuterOffset = 0;
134 params.m_ParamTriggerType = "ContaminatedTrigger_Dynamic";
135
136 super.SetupZoneData(params);
137 }
138
139 override void DeferredInit()
140 {
141 // We make sure we have the particle array
142 if (!m_ToxicClouds)
143 m_ToxicClouds = new array<Particle>();
144
148
149 SetupZoneData(new EffectAreaParams);
150
151 // If a player arrives slightly later during the creation process we check if playing the flare FX is relevant
152 if (m_DecayState == eAreaDecayStage.INIT)
153 PlayFlareVFX();
154
155 if (m_DecayState >= eAreaDecayStage.LIVE)
156 InitZone(); // If it has already been created, we simply do the normal setup, no cool effects, force the LIVE state
157
158 super.DeferredInit();
159 }
160
161 override void InitZoneServer()
162 {
163 SpawnItems();
164
165 super.InitZoneServer();
166 }
167
169 {
170 //Print("---------============ Spawning items at pos:"+m_Position);
171 foreach (int j, string type : SPAWN_ITEM_TYPE)
172 {
173 //Print("----------------------------------");
174 for (int i = 0; i < SPAWN_ITEM_COUNT[j]; ++i)
175 {
176 vector randomDir2d = vector.RandomDir2D();
178 vector spawnPos = m_Position + (randomDir2d * randomDist);
180 vector mat[4];
182 mat[3] = spawnPos;
183 il.SetGround(null, mat);
184 //Print("Spawning item:"+ type + " at position:" + il.GetPos());
185 g_Game.CreateObjectEx(type, il.GetPos(), ECE_PLACE_ON_SURFACE);
186 }
187 }
188 }
189
190 override void CreateTrigger(vector pos, int radius)
191 {
192 super.CreateTrigger(pos, radius);
193
194 // This handles the specific case of dynamic triggers as some additionnal parameters are present
195 ContaminatedTrigger_Dynamic dynaTrigger = ContaminatedTrigger_Dynamic.Cast( m_Trigger );
196 if ( dynaTrigger )
197 {
198 dynaTrigger.SetLocalEffects( m_AroundParticleID, m_TinyParticleID, m_PPERequesterIdx );
199 dynaTrigger.SetAreaState( m_DecayState );
200 }
201 }
202
203 void PlayFX()
204 {
205 if (g_Game.IsServer())
206 {
207 Param1<vector> pos = new Param1<vector>(vector.Zero); // The value to be sent through RPC
208 array<ref Param> params = new array<ref Param>(); // The RPC params
209
210 // We send the message with this set of coords
211 pos.param1 = m_OffsetPos;
212 params.Insert(pos);
213 g_Game.RPC(null, ERPCs.RPC_SOUND_CONTAMINATION, params, true);
214
215 // We go to the next stage
217 SetSynchDirty();
218 }
219 }
220
222 {
224 }
225
227 {
228 if ( g_Game.IsClient() || ( g_Game.IsServer() && !g_Game.IsMultiplayer() ) )
229 {
230 // We spawn locally the dummy object which will be used to move and manage the particle
231 DynamicArea_Flare dummy = DynamicArea_Flare.Cast( g_Game.CreateObjectEx( "DynamicArea_Flare", m_OffsetPos, ECE_SETUP | ECE_LOCAL ) );
232
233 // We add some light to reinforce the effect
234 m_FlareLight = FlareLightContamination.Cast(ScriptedLightBase.CreateLight( FlareLightContamination, m_OffsetPos ));
235 }
236 }
237}
const int ECE_LOCAL
const int ECE_PLACE_ON_SURFACE
const int ECE_SETUP
InventoryLocation.
Definition enmath.c:7
static const int CONTAMINATED_AREA_GAS_TINY
static const int CONTAMINATED_AREA_GAS_AROUND
static const int CONTAMINATED_AREA_GAS_BIGASS
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
static vector RandomDir2D()
Returns randomly generated XZ unit vector with the Y(up) axis set to 0.
Definition enconvert.c:273
static const vector Zero
Definition enconvert.c:123
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
override void DeferredInit()
override void InitZoneServer()
void PlayFlareVFX()
ref Timer m_FXTimer
const int AIRBORNE_EXPLOSION_DELAY
const int AREA_SETUP_DELAY
override void EEOnCECreate()
override void Tick()
void PlayExplosionLight()
ShellLight m_OffsetPos
void SpawnItems()
const float AIRBORNE_FX_OFFSET
const ref array< string > SPAWN_ITEM_TYPE
const ref array< int > SPAWN_ITEM_COUNT
const ref array< float > SPAWN_ITEM_RAD_MIN
FlareLight m_FlareLight
override void OnVariablesSynchronized()
void PlayFX()
const ref array< float > SPAWN_ITEM_RAD_MAX
const float ARTILLERY_SHELL_SPEED
ShellLight m_ShellLight
override void SetupZoneData(EffectAreaParams params)
ref Timer m_StartupTimer
override void InitZone()
float GetFinishDecayLifetime()
void ContaminatedArea_DynamicBase()
enum eAreaDecayStage m_DecayState
float GetStartDecayLifetime()
void SetDecayState(int newState)
void ContaminatedTrigger_Dynamic()
DayZGame g_Game
Definition dayzgame.c:3942
vector m_Position
Cached world position.
Definition effect.c:43
ERPCs
Definition erpcs.c:2
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition enmath3d.c:256
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
vector GetPosition()
Get the world position of the Effect.
Definition effect.c:473
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
float GetRemainingTime()
void CreateTrigger()
Definition trapbase.c:465