Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
clockbase.c
Go to the documentation of this file.
2 {
4  SET,
6  //-----------
8 }
9 
11 {
12  float m_AlarmTime01;
14  static const float UPDATE_TICK_RATE = 1; // Clock update tick frequency
17  int m_StatePrev = -1;
18 
24 
25  const float RINGING_DURATION_MAX = 60;//in secs, at or past this value, the clock stops ringing
26 
27  void ClockBase()
28  {
29  Init();
30  }
31 
32  void ~ClockBase()
33  {
34  SEffectManager.DestroyEffect(m_WorkingSound);
35  SEffectManager.DestroyEffect(m_HitSound);
36  SEffectManager.DestroyEffect(m_DestoryedSound);
37  SEffectManager.DestroyEffect(m_TurnOnSound);
38  SEffectManager.DestroyEffect(m_RingingSoundLoop);
39  }
40 
41  void Init()
42  {
43  RegisterNetSyncVariableInt("m_State", 0, EAlarmClockState.COUNT - 1);
44  }
45 
46  override void SetActions()
47  {
48  super.SetActions();
49 
51  }
52 
53  protected int GetAlarmInMin()
54  {
55  int alarm_hand_in_mins = ConvertAlarmHand01ToMins12h(m_AlarmTime01);
56 
57  int pass, hour, minute;
58  GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
59 
60  int curr_time_in_minutes = ConvertTimeToMins12h(hour, minute);
61  int ring_in_mins = GetTimeDiffInMins12h(curr_time_in_minutes, alarm_hand_in_mins);
62  return ring_in_mins;
63  }
64 
65  static int ConvertAlarmHand01ToMins12h(float time01)
66  {
67  return Math.Lerp(0,12*60,time01);
68  }
69 
70  static int ConvertAlarmHand01ToMins(float time01, int mins_max/*what's the upper range in minutes we are trying to map the time01 to*/)
71  {
72  return Math.Lerp(0,mins_max,time01);
73  }
74 
75  static float ConvertMins12hToAlarmHand01(int mins)
76  {
77  return Math.InverseLerp(0,12*60,mins);
78  }
79 
80 
81  static int ConvertTimeToMins12h(int hour, int minute)
82  {
83  if (hour >= 12)
84  hour -= 12;
85  return hour * 60 + minute;
86  }
87 
88  static int GetTimeDiffInMins12h(int from_mins, int to_mins)
89  {
90  if (to_mins > from_mins)
91  {
92  return to_mins - from_mins;
93  }
94  else if (to_mins < from_mins)
95  {
96  return ((12 * 60) - from_mins) + to_mins;
97  }
98  else return 0;
99  }
100 
101  string GetToggleSound()
102  {
103  return "";
104  }
106  {
107  return "";
108  }
109  string GetHitSound()
110  {
111  return "";
112  }
114  {
115  return "";
116  }
118  {
119  return "";
120  }
121 
122  override void EEKilled(Object killer)
123  {
124  super.EEKilled(killer);
125  TurnOff();
126  }
127 
128  override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
129  {
130  super.EEHitByRemote(damageType, source, component, dmgZone, ammo, modelPos);
131  PlaySoundSet( m_HitSound, GetHitSound(), 0, 0 );
132  }
133 
134  override void OnDamageDestroyed(int oldLevel)
135  {
136  super.OnDamageDestroyed(oldLevel);
137 
138  if (GetGame().IsClient())
139  {
141 
142  if (oldLevel != -1)
143  {
144  PlaySoundSet(m_DestoryedSound, GetDestroyedSound(), 0, 0);
145  }
146  }
147  }
148 
149  protected void OnRingingStartServer()
150  {
151  ActivateParent();
152  }
153 
154  protected void OnRingingStartClient()
155  {
156  PlaySoundSetLoop( m_RingingSoundLoop, GetRingingSound(), 0, 0 );
157 
158  if (m_WorkingSound)
159  {
160  SEffectManager.DestroyEffect(m_WorkingSound);
161  }
162  }
163 
164  protected void OnRingingStopServer();
165 
166  protected void OnRingingStopClient()
167  {
168  SEffectManager.DestroyEffect(m_RingingSoundLoop);
169  }
170 
171  void SetAlarmInXMins(int in_mins)
172  {
173  int pass, hour, minute;
174  GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
175  int mins12h = ConvertTimeToMins12h(hour, minute) + in_mins;
176  float time01 = ConvertMins12hToAlarmHand01(mins12h);
177  SetAlarmTimeServer(time01);
178  Arm();
179  }
180 
182  {
183  return RINGING_DURATION_MAX;
184  }
185 
186 
187  protected void SetupTimerServer()
188  {
189  m_TimerUpdate = new Timer();
190  m_TimerUpdate.Run(UPDATE_TICK_RATE , this, "OnUpdate", null, true);
191  }
192 
193  protected void SetState(EAlarmClockState state)
194  {
195  m_State = state;
196  SetSynchDirty();
197  }
198 
199  protected void Disarm()
200  {
201  SetState(EAlarmClockState.UNSET);
202  }
203 
204  protected void Arm()
205  {
208  m_RingingDuration = 0;
209  }
210 
211  protected void ActivateParent()
212  {
213  if (GetHierarchyParent())
214  {
215  ItemBase parent = ItemBase.Cast(GetHierarchyParent());
216  if (parent)
217  {
218  parent.OnActivatedByItem(this);
219  }
220  }
221  }
222 
223  protected void MakeRingingStart()
224  {
225  if (!m_TimerUpdate)
227  SetState(EAlarmClockState.RINGING);
228 
230  }
231 
232  protected void MakeRingingStop()
233  {
234  SetState(EAlarmClockState.UNSET);
235 
237  }
238 
239  void TurnOnClient();
240 
241  void TurnOffClient();
242 
243  override void OnVariablesSynchronized()
244  {
245  super.OnVariablesSynchronized();
246 
247  if (m_State != m_StatePrev)//state changed
248  {
249  if (m_StatePrev == EAlarmClockState.RINGING)
250  {
252  }
253  else if (m_State == EAlarmClockState.RINGING)
254  {
256  }
257  if (m_State == EAlarmClockState.SET)
258  {
259  if (m_StatePrev != -1 || IsInitialized())
260  {
261  PlaySoundSet( m_TurnOnSound, GetToggleSound(), 0, 0 );
262  }
263  if (GetWorkingSound())
264  {
265  PlaySoundSet( m_WorkingSound, GetWorkingSound(), 0, 0, true );
266  }
267  }
268  else if (m_State == EAlarmClockState.UNSET)
269  {
270  if (m_StatePrev == EAlarmClockState.SET)
271  {
272  if (m_WorkingSound)
273  {
274  SEffectManager.DestroyEffect(m_WorkingSound);
275  }
276  if (m_StatePrev != -1 || IsInitialized())
277  {
278  PlaySoundSet( m_TurnOnSound, GetToggleSound(), 0, 0 );
279  }
280  }
281  }
283  }
284  }
285 
286 
287  //---------------------------------------------------------------------------------------------------------
288  //---------------------------------------------- Public methods -------------------------------------------
289  //---------------------------------------------------------------------------------------------------------
290 
291  bool IsRinging()
292  {
293  return (m_State == EAlarmClockState.RINGING);
294  }
295 
296  bool IsAlarmOn()
297  {
298  return (m_State == EAlarmClockState.SET);
299  }
300 
301  void TurnOn()
302  {
303  Arm();
304  }
305 
306  void TurnOff()
307  {
308  if ( IsRinging() )
309  {
310  MakeRingingStop();
311  }
312  else
313  {
314  Disarm();
315  }
316 
317  m_TimerUpdate = null;
318  }
319 
320  void SetAlarmTimeServer(float time01)
321  {
322  SetAnimationPhaseNow("ClockAlarm", time01);
323  m_AlarmTime01 = time01;
324  }
325 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
IsAlarmOn
bool IsAlarmOn()
Definition: clockbase.c:296
UNSET
@ UNSET
Definition: clockbase.c:3
RINGING_DURATION_MAX
const float RINGING_DURATION_MAX
Definition: clockbase.c:25
SetAlarmInXMins
void SetAlarmInXMins(int in_mins)
Definition: clockbase.c:171
GetHitSound
string GetHitSound()
Definition: clockbase.c:109
TurnOnClient
void TurnOnClient()
GetDestroyedSound
string GetDestroyedSound()
Definition: clockbase.c:113
SetAlarmTimeServer
void SetAlarmTimeServer(float time01)
Definition: clockbase.c:320
OnRingingStartServer
protected void OnRingingStartServer()
Definition: clockbase.c:149
SetupTimerServer
protected void SetupTimerServer()
Definition: clockbase.c:187
SetActions
override void SetActions()
Definition: clockbase.c:46
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: clockbase.c:243
Arm
protected void Arm()
Definition: clockbase.c:204
ActionAttachExplosivesTrigger
ActionBreakLongWoodenStickCB ActionAttachExplosivesTrigger
m_StatePrev
int m_StatePrev
Definition: clockbase.c:17
IsInitialized
bool IsInitialized()
Definition: huddebug.c:299
OnRingingStopClient
protected void OnRingingStopClient()
Definition: clockbase.c:166
EEHitByRemote
override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
Definition: clockbase.c:128
GetWorkingSound
string GetWorkingSound()
Definition: clockbase.c:117
EEKilled
override void EEKilled(Object killer)
Definition: clockbase.c:122
SET
@ SET
Definition: clockbase.c:4
m_TurnOnSound
EffectSound m_TurnOnSound
Definition: clockbase.c:20
ClockBase
void ClockBase()
Definition: clockbase.c:27
GetRingingDurationMax
float GetRingingDurationMax()
Definition: clockbase.c:181
Disarm
protected void Disarm()
Definition: clockbase.c:199
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
MakeRingingStop
protected void MakeRingingStop()
Definition: clockbase.c:232
MakeRingingStart
protected void MakeRingingStart()
Definition: clockbase.c:223
m_WorkingSound
EffectSound m_WorkingSound
Definition: clockbase.c:23
OnDamageDestroyed
override void OnDamageDestroyed(int oldLevel)
Definition: clockbase.c:134
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
vector
Definition: enconvert.c:105
m_State
int m_State
Definition: clockbase.c:13
IsRinging
bool IsRinging()
Definition: clockbase.c:291
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
m_AlarmTime01
enum EAlarmClockState m_AlarmTime01
m_TimerUpdate
ref Timer m_TimerUpdate
Definition: clockbase.c:15
TurnOffClient
void TurnOffClient()
GetRingingSound
string GetRingingSound()
Definition: clockbase.c:105
TurnOff
void TurnOff()
Definition: clockbase.c:306
Init
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: clockbase.c:41
m_RingingSoundLoop
EffectSound m_RingingSoundLoop
Definition: clockbase.c:19
COUNT
@ COUNT
Definition: clockbase.c:7
~ClockBase
void ~ClockBase()
Definition: clockbase.c:32
Timer
Definition: dayzplayerimplement.c:62
m_DestoryedSound
EffectSound m_DestoryedSound
Definition: clockbase.c:21
EAlarmClockState
EAlarmClockState
Definition: clockbase.c:1
GetToggleSound
string GetToggleSound()
Definition: clockbase.c:101
Inventory_Base
Definition: barbedbaseballbat.c:1
m_RingingDuration
float m_RingingDuration
Definition: clockbase.c:16
Math
Definition: enmath.c:6
ActivateParent
protected void ActivateParent()
Definition: clockbase.c:211
TurnOn
void TurnOn()
Definition: clockbase.c:301
RINGING
@ RINGING
Definition: clockbase.c:5
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
OnRingingStartClient
protected void OnRingingStartClient()
Definition: clockbase.c:154
EntityAI
Definition: building.c:5
m_HitSound
EffectSound m_HitSound
Definition: clockbase.c:22
OnRingingStopServer
protected void OnRingingStopServer()
SetState
protected void SetState(EAlarmClockState state)
Definition: clockbase.c:193
GetAlarmInMin
protected int GetAlarmInMin()
Definition: clockbase.c:53