Dayz Explorer 1.28.160049
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 = GetGame().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 GetGame().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 super.DeferredInit();
142
143 // We make sure we have the particle array
144 if (!m_ToxicClouds)
145 m_ToxicClouds = new array<Particle>();
146
150
151 SetupZoneData(new EffectAreaParams);
152
153 // If a player arrives slightly later during the creation process we check if playing the flare FX is relevant
154 if (m_DecayState == eAreaDecayStage.INIT)
155 PlayFlareVFX();
156
157 if ( m_DecayState == eAreaDecayStage.LIVE )
158 InitZone(); // If it has already been created, we simply do the normal setup, no cool effects, force the LIVE state
159
160 super.DeferredInit();
161 }
162
163 override void InitZoneServer()
164 {
165 SpawnItems();
166
167 super.InitZoneServer();
168 }
169
171 {
172 //Print("---------============ Spawning items at pos:"+m_Position);
173 foreach (int j, string type : SPAWN_ITEM_TYPE)
174 {
175 //Print("----------------------------------");
176 for (int i = 0; i < SPAWN_ITEM_COUNT[j]; ++i)
177 {
178 vector randomDir2d = vector.RandomDir2D();
179 float randomDist = Math.RandomFloatInclusive(SPAWN_ITEM_RAD_MIN[j],SPAWN_ITEM_RAD_MAX[j]);
180 vector spawnPos = m_Position + (randomDir2d * randomDist);
182 vector mat[4];
183 Math3D.MatrixIdentity4(mat);
184 mat[3] = spawnPos;
185 il.SetGround(NULL, mat);
186 //Print("Spawning item:"+ type + " at position:" + il.GetPos());
187 GetGame().CreateObjectEx(type, il.GetPos(), ECE_PLACE_ON_SURFACE);
188 }
189 }
190 }
191
192 override void CreateTrigger(vector pos, int radius)
193 {
194 super.CreateTrigger(pos, radius);
195
196 // This handles the specific case of dynamic triggers as some additionnal parameters are present
197 ContaminatedTrigger_Dynamic dynaTrigger = ContaminatedTrigger_Dynamic.Cast( m_Trigger );
198 if ( dynaTrigger )
199 {
200 dynaTrigger.SetLocalEffects( m_AroundParticleID, m_TinyParticleID, m_PPERequesterIdx );
201 dynaTrigger.SetAreaState( m_DecayState );
202 }
203 }
204
205 void PlayFX()
206 {
207 if (GetGame().IsServer())
208 {
209 Param1<vector> pos = new Param1<vector>(vector.Zero); // The value to be sent through RPC
210 array<ref Param> params = new array<ref Param>(); // The RPC params
211
212 // We send the message with this set of coords
213 pos.param1 = m_OffsetPos;
214 params.Insert(pos);
215 GetGame().RPC(null, ERPCs.RPC_SOUND_CONTAMINATION, params, true);
216
217 // We go to the next stage
219 SetSynchDirty();
220 }
221 }
222
224 {
226 }
227
229 {
230 if ( GetGame().IsClient() || ( GetGame().IsServer() && !GetGame().IsMultiplayer() ) )
231 {
232 // We spawn locally the dummy object which will be used to move and manage the particle
233 DynamicArea_Flare dummy = DynamicArea_Flare.Cast( GetGame().CreateObjectEx( "DynamicArea_Flare", m_OffsetPos, ECE_SETUP | ECE_LOCAL ) );
234
235 // We add some light to reinforce the effect
236 m_FlareLight = FlareLightContamination.Cast(ScriptedLightBase.CreateLight( FlareLightContamination, m_OffsetPos ));
237 }
238 }
239}
const int ECE_LOCAL
const int ECE_PLACE_ON_SURFACE
const int ECE_SETUP
InventoryLocation.
Definition enmath.c:7
array< vector > GetArtyFiringPos()
Definition worlddata.c:247
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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()
enum eAreaDecayStage m_DecayState
float GetStartDecayLifetime()
void SetDecayState(int newState)
void ContaminatedTrigger_Dynamic()
vector m_Position
Cached world position.
Definition effect.c:43
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
class JsonUndergroundAreaTriggerData GetPosition
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
float GetRemainingTime()
void CreateTrigger()
Definition trapbase.c:475