Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
land_underground_panel.c
Go to the documentation of this file.
2 {
3  OFF,
5  ON,
6 }
7 
8 enum ELEDColors
9 {
10  RED,
11  GREEN,
12 }
13 
15 {
16  static ref set<Land_Underground_EntranceBase> m_Entrances;
17  static ref set<Land_Underground_Panel> m_Panels;
18 
20 
21  const string COLOR_LED_OFF = "#(argb,8,8,3)color(0,0,0,1.0,co)";
22  const string COLOR_LED_GREEN = "#(argb,8,8,3)color(0,1,0,1.0,co)";
23  const string COLOR_LED_RED = "#(argb,8,8,3)color(1,0,0,1.0,co)";
24 
25  const string SELECTION_NAME_LED_RED = "LED_Red";
26  const string SELECTION_NAME_LED_GREEN = "LED_Green";
27 
28  bool m_PanelWasUsed
32 
34 
37 
39  {
40  RegisterNetSyncVariableBool("m_PanelWasUsed");
41  RegisterPanel(this);
42  SetLEDState(ELEDColors.RED, ELEDState.ON);
43  SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
44  }
45 
47  {
48  UnregisterPanel(this);
49  }
50 
51  bool CanInteract()
52  {
54  if (door)
55  {
56  return Land_Underground_EntranceBase.Cast(door).CanManipulate();
57  }
58  return false;
59  }
60 
61  void Interact()
62  {
64  if (door)
65  {
66  GetGame().RegisterNetworkStaticObject(this);
67  Land_Underground_EntranceBase.Cast(door).Manipulate();
68  GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( ResetPanelUsed, 500);
69  m_PanelWasUsed = true;
70  SetSynchDirty();
71  }
72  else
73  {
74  ErrorEx("Can't find the instance of entrance the panel is linkined to");
75  }
76  }
77 
78  static void RegisterEntrance(Land_Underground_EntranceBase entrance)
79  {
80  if (!m_Entrances)
81  {
82  m_Entrances = new set<Land_Underground_EntranceBase>();
83  }
84  m_Entrances.Insert(entrance);
85  }
86 
87  static void UnregisterEntrance(Land_Underground_EntranceBase entrance)
88  {
89  if (m_Entrances)
90  {
91  int index = m_Entrances.Find(entrance);
92  if (index != -1)
93  {
94  m_Entrances.Remove(index);
95  }
96  else
97  {
98  ErrorEx("Attempted to unregistered non-registered entrance");
99  }
100  }
101  }
102 
103  static void RegisterPanel(Land_Underground_Panel panel)
104  {
105  if (!m_Panels)
106  {
107  m_Panels = new set<Land_Underground_Panel>;
108  }
109  m_Panels.Insert(panel);
110  }
111 
112  static void UnregisterPanel(Land_Underground_Panel panel)
113  {
114  if (m_Panels)
115  {
116  int index = m_Panels.Find(panel);
117  if (index != -1)
118  {
119  m_Panels.Remove(index);
120  }
121  else
122  {
123  ErrorEx("Attempted to unregistered non-registered panel");
124  }
125  }
126  }
127 
128  EUndegroundDoorType GetLinkedDoorType()
129  {
130  return GetLinkedDoor().m_DoorType;
131  }
132 
134  {
135  if (!m_LinkedDoor)
137  return m_LinkedDoor;
138  }
139 
141  {
142  if (!m_Entrances)
143  {
144  return null;
145  }
146 
147  float closestDst = float.MAX;
149  vector thisPos = GetPosition();
150 
152  {
153  float dist = vector.DistanceSq(thisPos, obj.GetPosition());
154  if (dist < closestDst)
155  {
156  closestDst = dist;
157  closestObj = obj;
158  }
159  }
160 
161  return closestObj;
162  }
163 
164  void SetLEDState(ELEDColors color, ELEDState state)
165  {
166  #ifndef SERVER
167  if (color == ELEDColors.RED)
168  {
169  if (m_LedStateRed != state)
170  {
171  m_LedStateRed = state;
173  }
174  }
175  else
176  {
177  if (m_LedStateGreen != state)
178  {
179  m_LedStateGreen = state;
181  }
182  }
183  #endif
184  }
185 
186  void SetBlinkingTimer(bool enable)
187  {
188  if (enable)
189  {
190  if (!m_FlipFlopTimer)
191  {
192  m_FlipFlopTimer = new Timer();
193  m_FlipFlopTimer.Run(0.1, this, "ToggleFlipFlop", NULL, true);
194  }
195  }
196  else
197  {
198  if (m_FlipFlopTimer)
199  {
200  m_FlipFlopTimer = null;
201  }
202  }
203  }
204 
206  {
207  /*
208  Print("OnLEDStateChanged()");
209  Print("m_LedStateRed: " + m_LedStateRed);
210  Print("m_LedStateGreen: " + m_LedStateGreen);
211  */
212  if (m_LedStateRed == ELEDState.BLINKING || m_LedStateGreen == ELEDState.BLINKING)
213  {
214  SetBlinkingTimer(true);
215  }
216  else
217  {
218  SetBlinkingTimer(false);
219  }
220  //red
221  if (m_LedStateRed == ELEDState.ON)
222  {
224  }
225  else if (m_LedStateRed == ELEDState.OFF)
226  {
228  }
229  else if (m_LedStateRed == ELEDState.BLINKING)
230  {
231  if (m_BlinkingFlipFlop)
232  {
234  }
235  else
236  {
238  }
239 
240  //green
241  }
242  if (m_LedStateGreen == ELEDState.ON)
243  {
245  }
246  else if (m_LedStateGreen == ELEDState.OFF)
247  {
249  }
250  else if (m_LedStateGreen == ELEDState.BLINKING)
251  {
253  {
255  }
256  else
257  {
259  }
260 
261  }
262  }
263 
265  {
266  m_PanelWasUsed = false;
267  SetSynchDirty();
268  }
269 
271  {
272  switch (GetLinkedDoorType())
273  {
274  case EUndegroundDoorType.MAIN:
275  {
276  if (newState >= EUndegroundEntranceState.CLOSED && newState < EUndegroundEntranceState.OPENING_G)
277  {
278  SetLEDState(ELEDColors.RED, ELEDState.ON);
279  }
280  else if (newState == EUndegroundEntranceState.OPENING_G)
281  {
282  SetLEDState(ELEDColors.RED, ELEDState.OFF);
283  }
284  else if (newState >= EUndegroundEntranceState.CLOSING_A)
285  {
286  SetLEDState(ELEDColors.RED, ELEDState.BLINKING);
287  }
288 
289  if (newState == EUndegroundEntranceState.CLOSED)
290  {
291  SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
292  }
293  else if (newState >= EUndegroundEntranceState.OPENING_A && newState < EUndegroundEntranceState.OPENING_G)
294  {
295  SetLEDState(ELEDColors.GREEN, ELEDState.BLINKING);
296  }
297  else if (newState >= EUndegroundEntranceState.OPENING_G)
298  {
299  SetLEDState(ELEDColors.GREEN, ELEDState.ON);
300  }
301  }
302  break;
303  case EUndegroundDoorType.SMALL:
304  {
305  if (newState == EUndegroundEntranceState.OPENING_A)
306  {
307  SetLEDState(ELEDColors.RED, ELEDState.ON);
308  SetLEDState(ELEDColors.GREEN, ELEDState.BLINKING);
309  }
310  else if (newState == EUndegroundEntranceState.OPENING_B)
311  {
312  SetLEDState(ELEDColors.RED, ELEDState.OFF);
313  SetLEDState(ELEDColors.GREEN, ELEDState.ON);
314  }
315  else if (newState == EUndegroundEntranceState.CLOSING_A)
316  {
317  SetLEDState(ELEDColors.RED, ELEDState.BLINKING);
318  SetLEDState(ELEDColors.GREEN, ELEDState.ON);
319  }
320  if (newState == EUndegroundEntranceState.CLOSING_B || newState == EUndegroundEntranceState.CLOSED)
321  {
322  SetLEDState(ELEDColors.RED, ELEDState.ON);
323  SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
324  }
325  }
326  break;
327  }
328  }
329 
330 
331  protected void UpdateLED(string selection, string color)
332  {
333  int selectionIdx = GetHiddenSelectionIndex(selection);
334  SetObjectTexture(selectionIdx, color);
335  //Print("selection: " +selection + ", color: " + color +", selectionIdx: "+ selectionIdx);
336  }
337 
339  {
342  }
343 
345  {
346  PlaySoundSet( m_ActivationSound, "UndergroundDoor_PanelActivation_SoundSet", 0, 0 );
347  }
348 
349  override void OnVariablesSynchronized()
350  {
351  if (m_PanelWasUsed != m_PanelWasUsedPrev)
352  {
353  if (m_PanelWasUsed)
354  {
356  }
357  m_PanelWasUsedPrev = m_PanelWasUsed;
358  }
359  }
360 
361 }
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
ELEDState
ELEDState
Definition: land_underground_panel.c:1
UpdateLED
protected void UpdateLED(string selection, string color)
Definition: land_underground_panel.c:331
m_PanelWasUsedPrev
bool m_PanelWasUsed bool m_PanelWasUsedPrev
Definition: land_underground_panel.c:29
m_FlipFlopTimer
ref Timer m_FlipFlopTimer
Definition: land_underground_panel.c:31
m_LedStateGreen
ELEDState m_LedStateGreen
Definition: land_underground_panel.c:36
Land_Underground_EntranceBase
Definition: land_underground_entrance.c:51
OnLEDStateChanged
void OnLEDStateChanged()
Definition: land_underground_panel.c:205
BLINKING
@ BLINKING
Definition: land_underground_panel.c:4
SetLEDState
void SetLEDState(ELEDColors color, ELEDState state)
Definition: land_underground_panel.c:164
m_LinkedDoor
Land_Underground_EntranceBase m_LinkedDoor
Definition: land_underground_panel.c:19
CanInteract
bool CanInteract()
Definition: land_underground_panel.c:51
COLOR_LED_OFF
const string COLOR_LED_OFF
Definition: land_underground_panel.c:21
ResetPanelUsed
void ResetPanelUsed()
Definition: land_underground_panel.c:264
GetLinkedDoor
Land_Underground_EntranceBase GetLinkedDoor()
Definition: land_underground_panel.c:133
ToggleFlipFlop
void ToggleFlipFlop()
Definition: land_underground_panel.c:338
SELECTION_NAME_LED_RED
const string SELECTION_NAME_LED_RED
Definition: land_underground_panel.c:25
EUndegroundEntranceState
EUndegroundEntranceState
Definition: land_underground_entrance.c:1
SELECTION_NAME_LED_GREEN
const string SELECTION_NAME_LED_GREEN
Definition: land_underground_panel.c:26
COLOR_LED_RED
const string COLOR_LED_RED
Definition: land_underground_panel.c:23
RED
enum ELEDState RED
ErrorEx
enum ShapeType ErrorEx
COLOR_LED_GREEN
const string COLOR_LED_GREEN
Definition: land_underground_panel.c:22
OnPanelUsedSynchronized
void OnPanelUsedSynchronized()
Definition: land_underground_panel.c:344
m_LedStateRed
ELEDState m_LedStateRed
Definition: land_underground_panel.c:35
m_Entrances
enum ELEDState m_Entrances
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
vector
Definition: enconvert.c:105
~Land_Underground_Panel
void ~Land_Underground_Panel()
Definition: land_underground_panel.c:46
ON
@ ON
Definition: land_underground_panel.c:5
OnDoorStateChangedClient
void OnDoorStateChangedClient(EUndegroundEntranceState newState, EUndegroundEntranceState prevState)
Definition: land_underground_panel.c:270
OFF
@ OFF
Definition: land_underground_panel.c:3
House
Definition: crashbase.c:1
m_ActivationSound
EffectSound m_ActivationSound
Definition: land_underground_panel.c:33
GetClosestDoor
Land_Underground_EntranceBase GetClosestDoor()
Definition: land_underground_panel.c:140
GetLinkedDoorType
EUndegroundDoorType GetLinkedDoorType()
Definition: land_underground_panel.c:128
SetBlinkingTimer
void SetBlinkingTimer(bool enable)
Definition: land_underground_panel.c:186
m_Panels
ref array< ref HudDebugWinBase > m_Panels
Definition: huddebug.c:94
m_BlinkingFlipFlop
bool m_BlinkingFlipFlop
Definition: land_underground_panel.c:30
Timer
Definition: dayzplayerimplement.c:62
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: land_underground_panel.c:349
GREEN
enum ELEDState GREEN
Land_Underground_Panel
void Land_Underground_Panel()
Definition: land_underground_panel.c:38
Interact
void Interact()
Definition: land_underground_panel.c:61