Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
land_warheadstorage_main.c
Go to the documentation of this file.
2{
3 protected bool m_HasPowerPrev;
4 protected bool m_IsLowEnergy;
5 protected WarheadStorageLight m_StorageDoorLights[4];
9
10 protected const float DOOR_AUTOCLOSE_TIME = 12;//how long before the outer door auto-close after being opened
11 protected const int SOURCES_COUNT = 4; // storage lights, side vents, lamps
12
13 protected const string WARHEAD_BUNKER_TRIGGER = "UndergroundBunkerTrigger";
14
15 protected const string ALARM_POS_MEMPOINT = "underground";
16 protected const string VENT_MAIN_POS_MEMPOINT = "Ventilation_main";
17 protected const string VENT_POS_MEMPOINT = "Ventilation";
18
19 protected const string ALARM_DOOR_OPEN_SOUND = "UndergroundDoor_Alarm_Start_SoundSet";
20 protected const string ALARM_DOOR_OPEN_LOOP_SOUND = "UndergroundDoor_Alarm_Loop_SoundSet";
21 protected const string ALARM_DOOR_CLOSE_SOUND = "UndergroundDoor_Alarm_End_SoundSet";
22 protected const string VENTILATION_SOUND = "Bunker_Ventilation_SoundSet";
23 protected const string LAMPS_SOUND = "Bunker_Lamp_Hum_SoundSet";
24 protected const string ELECTRICITY_ON_SOUND = "Bunker_bunker_electricity_on_SoundSet";
25 protected const string ELECTRICITY_OFF_SOUND = "Bunker_bunker_electricity_off_SoundSet";
26
27 protected const string LAMP_SELECTION = "GlassLamp";
28 protected const string MAIN_DOOR_SELECTION1 = "maindoor1_outer";
29 protected const string MAIN_DOOR_SELECTION2 = "maindoor2_outer";
30
31 protected const string COLOR_LAMP_OFF = "DZ\\structures_sakhal\\military\\storage\\data\\Warhead_Storage_Lamp_Glass_int.rvmat";
32 protected const string COLOR_LAMP_ON = "DZ\\structures_sakhal\\military\\storage\\data\\Warhead_Storage_Lamp_Glass_e_int.rvmat";
33
34 // sync
35 protected bool m_HasPower;
36 protected bool m_LeverStatesBits;
37
39 {
40 RegisterNetSyncVariableBool("m_HasPower");
41 RegisterNetSyncVariableInt("m_LeverStatesBits");
42 RegisterNetSyncVariableInt("m_IsLowEnergy");
43
45 }
46
48 {
50
51 for (int i; i < 4; i++)
52 {
54 m_StorageDoorLights[i].Destroy();
55 }
56 }
57
58 override void DeferredInit()
59 {
60 g_Game.RegisterNetworkStaticObject(this);
61
62 if (g_Game.IsServer())
63 {
64 UpdateDoorStateServer(); // init closed state - code randomization? of opened state messes with doors in general
65 for (int i = 0; i < 12; i++)
66 {
67 if (IsBunkerDoor(i))
69
70 }
71
72 JsonUndergroundTriggers.SpawnParentedTriggers(this);
73 }
74 }
75
76 void SetPowerServer(bool hasPower)
77 {
78 m_HasPower = hasPower;
79 SetSynchDirty();
80 }
81
82 void SetLeverStatesServer(int leverBits)
83 {
84 m_LeverStatesBits = leverBits;
85 SetSynchDirty();
86
88 }
89
90 void SetLowEnergyStateServer(bool state)
91 {
92 m_IsLowEnergy = state;
93 SetSynchDirty();
94 }
95
97 {
98 return m_IsLowEnergy;
99 }
100
101 protected void OnPowerOnClient()
102 {
103 EffectSound soundEff;
104 PlaySoundSetAtMemoryPoint(soundEff, VENTILATION_SOUND, VENT_MAIN_POS_MEMPOINT, true, 0.5, 0.5);
105 m_PoweredSoundEffects.Insert(soundEff);
106 soundEff.SetAutodestroy(true);
107
108 PlaySoundSetAtMemoryPoint(soundEff, ELECTRICITY_ON_SOUND, VENT_MAIN_POS_MEMPOINT, false);
109 soundEff.SetAutodestroy(true);
110
111 for (int i; i < SOURCES_COUNT; i++)
112 {
113 PlaySoundSetAtMemoryPoint(soundEff, VENTILATION_SOUND, VENT_POS_MEMPOINT + (i+1).ToString(), true, 0.5, 0.5);
114 m_PoweredSoundEffects.Insert(soundEff);
115 soundEff.SetAutodestroy(true);
116 PlaySoundSetAtMemoryPoint(soundEff, LAMPS_SOUND, "lamp" + (i+1).ToString() + "_pos", true, 0.1, 0.1);
117 m_PoweredSoundEffects.Insert(soundEff);
118 soundEff.SetAutodestroy(true);
119 }
120 }
121
122 protected void OnPowerOffClient()
123 {
124 foreach (EffectSound soundEff : m_PoweredSoundEffects)
125 {
126 if (soundEff)
127 soundEff.Stop();
128 }
129
130 PlaySoundSetAtMemoryPoint(soundEff, ELECTRICITY_OFF_SOUND, VENT_MAIN_POS_MEMPOINT, false);
131 soundEff.SetAutodestroy(true);
132
133 m_PoweredSoundEffects.Clear();
134 }
135
136
137 override void OnDoorOpenStart(DoorStartParams params)
138 {
139 #ifndef SERVER
140 if (IsBunkerDoor(params.param1))
141 {
142 EffectSound sound;
143 PlaySoundSetAtMemoryPoint(sound, ALARM_DOOR_OPEN_SOUND, ALARM_POS_MEMPOINT, false, 0, 0);
144 sound.SetAutodestroy(true);
145
146 int effectID = GetBunkerEffectIndexByDoor(params.param1);
147 PlaySoundSetAtMemoryPoint(sound, ALARM_DOOR_OPEN_LOOP_SOUND, ALARM_POS_MEMPOINT, true, 0, 0);
148 m_SoundDoorLoop[effectID] = sound;
149 m_SoundDoorLoop[effectID].SetAutodestroy(true);
150 }
151 #endif
152
153 if (!IsBunkerDoor(params.param1))
154 return;
155
158
159 Timer doorTimer = new Timer();
160 doorTimer.Run(DOOR_AUTOCLOSE_TIME, this, "AutoCloseDoor", new Param1<int>(params.param1));
161 m_AutoCloseTimers.Set(params.param1, doorTimer);
162 }
163
164 override void OnDoorOpenFinish(DoorFinishParams params)
165 {
166 #ifndef SERVER
167 if (IsBunkerDoor(params.param1))
168 {
169 int effectID = GetBunkerEffectIndexByDoor(params.param1);
170 if (m_SoundDoorLoop[effectID] && m_SoundDoorLoop[effectID].IsPlaying())
171 {
172 EffectSound sound = m_SoundDoorLoop[effectID];
173 StopSoundSet(sound);
174 }
175 }
176 #endif
177 }
178
180 {
181 super.OnSpawnByObjectSpawner(item);
182
183 if (item.customString == string.Empty)
184 return;
185
187 if (jsonData && jsonData.Triggers)
188 {
189 foreach (int index, auto triggerData : jsonData.Triggers)
190 {
191 if (triggerData.CustomSpawn)
192 {
193 //JSON: "customString": "undergroundTriggerTag=TAG_NAME"
194 TStringArray customStringData = new TStringArray();
195 item.customString.Split(";", customStringData);
196
197 foreach (string entry : customStringData)
198 {
199 TStringArray optionValuePair = new TStringArray();
200 entry.Split("=", optionValuePair);
201 if (optionValuePair[0] == "undergroundTriggerTag")
202 {
203 if (optionValuePair[1] == triggerData.Tag)
204 {
205 JsonUndergroundTriggers.SpawnTriggerCarrier(this, index, triggerData);
206 }
207 }
208 }
209 }
210 }
211 }
212 }
213
214 protected void RemoveDoorTimer(int doorIndex)
215 {
216 if (!IsBunkerDoor(doorIndex))
217 return;
218
220 {
221 m_AutoCloseTimers.Remove(doorIndex);
222 }
223 }
224
225 override void OnDoorCloseStart(DoorStartParams params)
226 {
227 #ifndef SERVER
228 if (IsBunkerDoor(params.param1))
229 {
230 EffectSound sound;
231 int effectID = GetBunkerEffectIndexByDoor(params.param1);
232 if (m_SoundDoorLoop[effectID] && m_SoundDoorLoop[effectID].IsPlaying()) // in case events fire in wrong order
233 {
234 sound = m_SoundDoorLoop[effectID];
235 StopSoundSet(sound);
236 }
237
238 PlaySoundSetAtMemoryPoint(sound, ALARM_DOOR_OPEN_LOOP_SOUND, ALARM_POS_MEMPOINT, true, 0, 0);
239 m_SoundDoorLoop[effectID] = sound;
240 m_SoundDoorLoop[effectID].SetAutodestroy(true);
241 }
242 #endif
243
244 RemoveDoorTimer(params.param1);
245 }
246
248 {
249 #ifndef SERVER
250 if (IsBunkerDoor(params.param1))
251 {
252 EffectSound sound;
253 PlaySoundSetAtMemoryPoint(sound, ALARM_DOOR_CLOSE_SOUND, ALARM_POS_MEMPOINT, false, 0, 0);
254 sound.SetAutodestroy(true);
255
256 int effectID = GetBunkerEffectIndexByDoor(params.param1);
257 if (m_SoundDoorLoop[effectID] && m_SoundDoorLoop[effectID].IsPlaying())
258 {
259 sound = m_SoundDoorLoop[effectID];
260 StopSoundSet(sound);
261 }
262 }
263 #endif
264 }
265
266 void AutoCloseDoor(int doorIndex)
267 {
268 CloseDoor(doorIndex);
269 RemoveDoorTimer(doorIndex);
270 }
271
273 {
274 for (int index = 1; index <= 4; index++)
275 {
276 int bit = 1 << (index - 1);
277 int doorIndex = GetDoorIndexByLeverIndex(index);
278
279 if ( ((bit & m_LeverStatesBits) != 0) && m_HasPower )
280 {
281 if (!IsDoorOpen(doorIndex))
282 OpenDoor(doorIndex);
283 }
284 else
285 {
286 if (IsDoorOpen(doorIndex))
287 CloseDoor(doorIndex);
288 }
289 }
290 }
291
293 {
294 for (int index = 1; index <= 4; index++)
295 {
296 int bit = 1 << (index - 1);
297 int doorIndex = GetDoorIndexByLeverIndex(index);
298 int lightId = GetStorageLightIndexByDoor(doorIndex);
299
300 if ( ((bit & m_LeverStatesBits) != 0) && m_HasPower )
301 {
302 if (!m_StorageDoorLights[lightId])
303 {
304 m_StorageDoorLights[lightId] = WarheadStorageLight.Cast(ScriptedLightBase.CreateLightAtObjMemoryPoint(WarheadStorageLight, this, "lamp" + (lightId + 1).ToString() + "_pos"));
305 m_StorageDoorLights[lightId].SetSelectionID(GetHiddenSelectionIndex(LAMP_SELECTION + (lightId + 1).ToString()));
306 m_StorageDoorLights[lightId].UpdateLightSourceMaterial(WarheadStorageLight.LIGHT_MAT_ON);
307 }
308 }
309 else
310 {
311 if (m_StorageDoorLights[lightId])
312 {
313 m_StorageDoorLights[lightId].UpdateLightSourceMaterial(WarheadStorageLight.LIGHT_MAT_OFF);
314 m_StorageDoorLights[lightId].Destroy();
315 }
316 }
317 }
318 }
319
320 protected int GetStorageLightIndexByDoor(int doorIndex)
321 {
322 return doorIndex - 8;
323 }
324
325 protected int GetDoorIndexByLeverIndex(int LeverIndex)
326 {
327 switch (LeverIndex)
328 {
329 case 1:
330 return 8;
331
332 case 2:
333 return 9;
334
335 case 3:
336 return 10;
337
338 case 4:
339 return 11;
340 }
341 return -1;
342 }
343
344 override bool CanDoorBeOpened(int doorIndex, bool checkIfLocked = false)
345 {
346 if (!super.CanDoorBeOpened(doorIndex, checkIfLocked))
347 return false;
348
349 switch (doorIndex)
350 {
351 case 4:
352 return IsDoorClosed(4) && IsDoorClosed(5);
353 case 5:
354 return IsDoorClosed(4) && IsDoorClosed(5);
355 case 6:
356 return IsDoorClosed(6) && IsDoorClosed(7);
357 case 7:
358 return IsDoorClosed(6) && IsDoorClosed(7);
359 case 8:
360 case 9:
361 case 10:
362 case 11:
363 return false;
364 }
365 return true;
366 }
367
368 override bool CanDoorBeLocked(int doorIndex)
369 {
370 if (IsStorageDoor(doorIndex) || IsBunkerDoor(doorIndex))
371 return false;
372 return super.CanDoorBeLocked(doorIndex);
373 }
374
375 protected int GetBunkerEffectIndexByDoor(int doorIndex)
376 {
377 return doorIndex - 4;
378 }
379
380 protected bool IsBunkerDoor(int doorIndex)
381 {
382 return (doorIndex >= 4 && doorIndex <= 7);
383 }
384
385 protected bool IsStorageDoor(int doorIndex)
386 {
387 return (doorIndex >= 8 && doorIndex <= 11);
388 }
389
390 override bool CanDoorBeClosed(int doorIndex)
391 {
392 if (IsStorageDoor(doorIndex))
393 return false;
394
395 if (IsBunkerDoor(doorIndex))
396 return IsDoorOpen(doorIndex) && !IsDoorOpening(doorIndex);
397
398 return super.CanDoorBeClosed(doorIndex);
399 }
400
401 override string GetDebugText()
402 {
403 string debug_output;
404
405 if( g_Game.IsServer())
406 {
407 debug_output = "IsDoorOpen(4) " + IsDoorOpen(4)+ "\n";
408 debug_output += "IsDoorOpen(5) " + IsDoorOpen(5)+ "\n";
409 debug_output += "IsDoorOpen(6) " + IsDoorOpen(6)+ "\n";
410 debug_output += "IsDoorOpen(7) " + IsDoorOpen(7)+ "\n";
411 }
412 else
413 {
414 debug_output = "this is client";
415 }
416 return debug_output;
417 }
418
419
421 {
422 super.OnVariablesSynchronized();
425 else if(!m_HasPower && m_HasPowerPrev)
427
429
431 }
432}
Param1< int > DoorStartParams
Definition building.c:1
Param2< int, bool > DoorFinishParams
Definition building.c:2
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
override void OnSpawnByObjectSpawner(ITEM_SpawnerObject item)
override void OnDoorOpenStart(DoorStartParams params)
override bool CanDoorBeClosed(int doorIndex)
void SetLeverStatesServer(int leverBits)
override bool CanDoorBeOpened(int doorIndex, bool checkIfLocked=false)
ref map< int, ref Timer > m_AutoCloseTimers
int GetBunkerEffectIndexByDoor(int doorIndex)
override void OnDoorOpenFinish(DoorFinishParams params)
override bool CanDoorBeLocked(int doorIndex)
override void OnDoorCloseStart(DoorStartParams params)
int GetStorageLightIndexByDoor(int doorIndex)
override void OnDoorCloseFinish(DoorFinishParams params)
WarheadStorageLight m_StorageDoorLights[4]
int GetDoorIndexByLeverIndex(int LeverIndex)
ref array< EffectSound > m_PoweredSoundEffects
static void UnregisterBunker(Land_WarheadStorage_Main bunker)
static void RegisterBunker(Land_WarheadStorage_Main bunker)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
bool IsPlaying()
Returns true when the Effect is playing, false otherwise.
Definition effect.c:197
proto string ToString()
array< string > TStringArray
Definition enscript.c:712