DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Land_WarheadStorage_PowerStation.c
См. документацию.
2{
3 protected bool m_InitBunkerState; // if generator is running already, used for initial power setup of related bunker
4 protected static ref set<Land_WarheadStorage_Main> m_Bunkers;
5 protected ref Timer m_UpdateTimer;
8 protected int m_PlaySparks;
9 protected int m_LastActivatedLeverId;
10 protected int m_LeverStatesBits; // is persistent through power generator
11
13
14 protected const string LEVERS_POS_MEMPOINT = "leverup_axis";
15 protected const string GENERATOR_POS_MEMPOINT = "generator_pos";
16
17 protected const string SWITCH_UP_SOUND = "Power_Station_Switch_Up_SoundSet";
18 protected const string SWITCH_DOWN_SOUND = "Power_Station_Switch_Down_SoundSet";
19 protected const string SPARKLES_SOUND = "Power_Station_generator_overpowered_SoundSet";
20
22 {
23 m_PlaySparks = 0;
24
25 RegisterNetSyncVariableInt("m_PlaySparks", 0, 4);
26 }
27
28 override void DeferredInit()
29 {
30 if (GetGame().IsServer())
32
34 }
35
37 {
38 super.OnVariablesSynchronized();
39
40 if (m_PlaySparks != 0)
41 {
42 EffectSound sound;
43 string mempoint = "lever" + m_PlaySparks.ToString() + "_sparks_pos";
44 sound = SEffectManager.PlaySoundCachedParams(SPARKLES_SOUND, ModelToWorld(GetMemoryPointPos(mempoint)));
45 sound.SetAutodestroy(true);
46
47 ParticleManager.GetInstance().PlayInWorld(ParticleList.LEVER_SPARKS, ModelToWorld(GetMemoryPointPos(mempoint)));
48
49 m_PlaySparks = 0;
50 }
51 }
52
54 {
55 vector generatorPosLocal = GetMemoryPointPos(GENERATOR_POS_MEMPOINT);
56 return ModelToWorld(generatorPosLocal);
57 }
58
59 protected void LinkPowerGeneratorServer()
60 {
62
64 {
66
67 vector thisOrientation = GetOrientation();
68 m_PowerGenerator = PowerGeneratorStatic.Cast(GetGame().CreateObjectEx("PowerGeneratorStatic", GetPowerGeneratorSpawnPos(), flags, RF_IGNORE));
69 m_PowerGenerator.SetOrientation(thisOrientation + "180 0 0");
70 }
71
72 m_PowerGenerator.SetParent(this);
73
74 if (GetGame().IsServer())
76
77 //DebugPrepareGenerator();
78
79 if (m_PowerGenerator.GetCompEM().IsWorking())
80 OnGeneratorStart();//the generator can be already running when we link to it as it has a persistent running state
81 }
82
87
88
89 // 'state' -1 is for automatic behaviour ON -> OFF, OFF -> ON, 'state' > -1 forces specific state, 0 for OFF state 1 for ON
90 void AnimateLever(int index, int state = -1)
91 {
92 string leverName = GetLeverComponentNameByLeverIndex(index);
93
94 if (!GetGame().IsServer())
95 return;
96
97 StartTimer();
98
99 float animPhase = state;
100
101 if (state == -1)
102 {
103 if (GetAnimationPhase(leverName) > 0)
104 animPhase = 0;
105 else
106 animPhase = 1;
107 }
108
109 SetAnimationPhase(leverName, animPhase);
110 }
111
112 void PlayLeverSound(string leverName, int state)
113 {
114 EffectSound sound;
115
116 if (state == 0)
117 PlaySoundSetAtMemoryPoint(sound, SWITCH_DOWN_SOUND, LEVERS_POS_MEMPOINT, false, 0, 0);
118 else if (state == 1)
119 PlaySoundSetAtMemoryPoint(sound, SWITCH_UP_SOUND, LEVERS_POS_MEMPOINT, false, 0, 0);
120
121 sound.SetAutodestroy(true);
122 }
123
124 protected void StartTimer()
125 {
126 if (!m_UpdateTimer)
127 m_UpdateTimer = new Timer();
128 m_UpdateTimer.Run(0.1, this, "Tick", NULL, true);
129 }
130
131 protected void CheckStopTimer()
132 {
133 if (m_UpdateTimer.GetRunTime() > 10)
134 {
135 m_UpdateTimer = null;
136 }
137 }
138
139 void Tick()
140 {
141 bool updated = false;
142 for (int index = 1; index <= 4; index++)
143 {
144 float animPhase = GetAnimationPhase(GetLeverComponentNameByLeverIndex(index));
145 int bit = 1 << (index - 1);
146
147 if (animPhase == 0)
148 {
149 if ((bit & m_LeverStatesBits) != 0)
150 {
151 // in the bitmask, this lever is set as ON, but the anim phase is saying it should be OFF, turn the bit off
153 updated = true;
154 }
155 }
156 else if (animPhase == 1)
157 {
158 if ((bit & m_LeverStatesBits) == 0)
159 {
160 // in the bitmask, this lever is set as OFF, but the anim phase is saying it should be ON, turn the bit on
162 updated = true;
163
165 }
166 }
167 }
168 if (updated)
169 {
170 m_PowerGenerator.StoreLeverStates(m_LeverStatesBits);
173 }
174
176 }
177
178 protected void OnLeverToggled()
179 {
180 int leversActivatedCount = Math.GetNumberOfSetBits(m_LeverStatesBits);
181 if (leversActivatedCount > 1 || (leversActivatedCount > 0 && !m_IsPowerGeneratorRunning))
182 {
183 //doors are being opened/closed only when we are opening/closing a single door, or when none of the doors are supposed to be open
184 //so here, we only force all levers to OFF, and that in turn will make the doors to be closed later on
185
186 if (leversActivatedCount > 1 && m_PlaySparks == 0)
187 {
189 SetSynchDirty();
190 }
191
193 {
194 m_PowerGenerator.GetCompEM().SwitchOff();
195 m_PowerGenerator.GetCompEM().InteractBranch(m_PowerGenerator);
196 }
197
199 }
200 }
201
202 protected void TurnAllLeversOff()
203 {
204 string leverName;
205
206 for (int i = 1; i < 5; i++)
207 {
209 if (GetAnimationPhase(leverName) > 0)
210 AnimateLever(i, 0); // will update the lever states through tick
211 }
212 }
213
214
215 // 1 through 4
217 {
218 switch (leverIndex)
219 {
220 case 1:
221 return "lever1";
222 case 2:
223 return "lever2";
224 case 3:
225 return "lever3";
226 case 4:
227 return "lever4";
228 }
229 return "lever1";
230 }
231
233 {
234 name.ToLower();
235 switch (name)
236 {
237 case "storagedoor1":
238 return 1;
239 case "storagedoor2":
240 return 2;
241 case "storagedoor3":
242 return 3;
243 case "storagedoor4":
244 return 4;
245 }
246 return 0;
247 }
248
249 protected void UpdateLeverStatesServer()
250 {
252 if (!closestBunker)
253 return;
254
256 }
257
259 {
260 if (GetGame().IsServer())
261 {
263
265 if (closestBunker)
266 closestBunker.SetPowerServer(true);
267
268 m_PlaySparks = 0;
269 SetSynchDirty();
270 }
271 }
272
274 {
275 if (GetGame().IsServer())
276 {
278
280
282
283 if (closestBunker)
284 closestBunker.SetPowerServer(false);
285 }
286 }
287
288 override void OnAnimationPhaseStarted(string animSource, float phase)
289 {
290 #ifndef SERVER
291 if (animSource.Contains("lever"))
292 {
293 if (phase > 0)
294 PlayLeverSound(animSource, 0);
295 else
296 PlayLeverSound(animSource, 1);
297 }
298 #endif
299 }
300
301 //--------------------------------------------------------------------------------------------------
302 //-------------------------------------- Remote bunker get/set -------------------------------------
303 //--------------------------------------------------------------------------------------------------
304
306 {
307 Land_WarheadStorage_Main closestBunker;
308 closestBunker = m_BunkerStationMap.Get(this);
309 if (closestBunker)
310 return closestBunker;
311
312 float smallestDist = float.MAX;
313 vector thisPos = GetPosition();
314
315 if (!m_Bunkers)
316 return null;
317
318 foreach (Land_WarheadStorage_Main bunker:m_Bunkers)
319 {
320 float dist = vector.DistanceSq(bunker.GetPosition(),thisPos);
321 if (dist < smallestDist)
322 {
323 closestBunker = bunker;
324 smallestDist =dist;
325 }
326 }
327
329 {
330 m_InitBunkerState = true;
331
332 if (GetGame().IsServer() && m_PowerGenerator && m_PowerGenerator.GetCompEM().IsWorking())
333 closestBunker.SetPowerServer(true);
334 }
335
336 m_BunkerStationMap.Insert(this, closestBunker);
337
338 return closestBunker;
339 }
340
342 {
343 if (!m_Bunkers)
344 {
345 m_Bunkers = new set<Land_WarheadStorage_Main>();
346 }
347 m_Bunkers.Insert(bunker);
348 }
349
351 {
352 if (m_Bunkers)
353 {
354 int index = m_Bunkers.Find(bunker);
355 if (index != -1)
356 {
357 m_Bunkers.Remove(index);
358 }
359 else
360 {
361 ErrorEx("Attempted to unregister non-registered bunker");
362 }
363 }
364 }
365
366 protected void DebugPrepareGenerator()
367 {
368 if (GetGame().IsServer())
369 {
370 m_PowerGenerator.GetCompEM().SetEnergy(10000);
371 m_PowerGenerator.GetInventory().CreateInInventory("GlowPlug");
372 }
373 }
374
375 // animates levers based on synched lever state from linked generator entity
377 {
378 int leverBits = m_PowerGenerator.GetStoredLeverBits();
379
380 for (int index = 1; index <= 4; index++)
381 {
382 int bit = 1 << (index - 1);
383
384 if ( (bit & leverBits) != 0 )
385 {
386 float animPhase = GetAnimationPhase(GetLeverComponentNameByLeverIndex(index));
387 if (animPhase == 0)
388 AnimateLever(index, 1);
389 }
390 }
391 }
392}
vector GetOrientation()
Определения AreaDamageManager.c:306
const int ECE_SETUP
Определения CentralEconomy.c:9
const int ECE_UPDATEPATHGRAPH
Определения CentralEconomy.c:13
const int RF_IGNORE
Определения CentralEconomy.c:56
const int ECE_NOLIFETIME
Определения CentralEconomy.c:29
const int ECE_CREATEPHYSICS
Определения CentralEconomy.c:16
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
map
Определения ControlsXboxNew.c:4
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Определения ParticleManager.c:88
proto native bool RegisterNetworkStaticObject(Object object)
Static objects cannot be replicated by default (there are too many objects on the map)....
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:603
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
void House()
Определения Building.c:3
void SetLeverStatesServer(int leverBits)
Определения Land_WarheadStorage_Main.c:82
void SetPowerServer(bool hasPower)
Определения Land_WarheadStorage_Main.c:76
void AnimateLever(int index, int state=-1)
static void UnregisterBunker(Land_WarheadStorage_Main bunker)
override void OnAnimationPhaseStarted(string animSource, float phase)
string GetLeverComponentNameByLeverIndex(int leverIndex)
PowerGeneratorStatic GetPowerGenerator()
static ref map< Land_WarheadStorage_PowerStation, Land_WarheadStorage_Main > m_BunkerStationMap
Land_WarheadStorage_Main GetClosestBunker()
PowerGeneratorStatic m_PowerGenerator
int GetLeverIndexByComponentName(string name)
void PlayLeverSound(string leverName, int state)
static void RegisterBunker(Land_WarheadStorage_Main bunker)
static ref set< Land_WarheadStorage_Main > m_Bunkers
Определения EnMath.c:7
static const int LEVER_SPARKS
Определения ParticleList.c:141
Определения ParticleList.c:12
static PowerGeneratorStatic GetClosestGenerator(vector position, float tolerance)
Определения PowerGeneratorStatic.c:42
static EffectSound PlaySoundCachedParams(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound, using or creating cached SoundParams.
Определения EffectManager.c:207
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
Определения DayZPlayerImplement.c:63
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
Определения EnConvert.c:106
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto int GetNumberOfSetBits(int i)
returns the number of bits set in a bitmask i
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
bool Contains(string sample)
Returns true if sample is substring of string.
Определения EnString.c:286