Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
clockbase.c
Go to the documentation of this file.
2{
6 //-----------
9
10class ClockBase : Inventory_Base
11{
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
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
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 {
152 }
153
154 protected void OnRingingStartClient()
155 {
156 PlaySoundSetLoop( m_RingingSoundLoop, GetRingingSound(), 0, 0 );
157
158 if (m_WorkingSound)
159 {
161 }
162 }
163
164 protected void OnRingingStopServer();
165
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 {
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 {
202 }
203
204 protected void Arm()
205 {
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 {
235
237 }
238
240
242
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 {
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
292 {
293 return (m_State == EAlarmClockState.RINGING);
294 }
295
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 {
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}
ActionAttachExplosivesTriggerCB ActionContinuousBaseCB ActionAttachExplosivesTrigger()
void AddAction(typename actionName)
void SetActions()
override void OnDamageDestroyed(int oldLevel)
Definition animalbase.c:145
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
Definition enmath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
void SetupTimerServer()
Definition clockbase.c:187
enum EAlarmClockState m_AlarmTime01
void TurnOff()
Definition clockbase.c:306
bool IsRinging()
Definition clockbase.c:291
ref Timer m_TimerUpdate
Definition clockbase.c:15
void ActivateParent()
Definition clockbase.c:211
string GetHitSound()
Definition clockbase.c:109
void OnRingingStopClient()
Definition clockbase.c:166
void ClockBase()
Definition clockbase.c:27
EffectSound m_WorkingSound
Definition clockbase.c:23
bool IsAlarmOn()
Definition clockbase.c:296
void OnRingingStartServer()
Definition clockbase.c:149
const float RINGING_DURATION_MAX
Definition clockbase.c:25
int m_StatePrev
Definition clockbase.c:17
string GetRingingSound()
Definition clockbase.c:105
string GetToggleSound()
Definition clockbase.c:101
void TurnOnClient()
void SetAlarmInXMins(int in_mins)
Definition clockbase.c:171
float m_RingingDuration
Definition clockbase.c:16
void TurnOn()
Definition clockbase.c:301
int GetAlarmInMin()
Definition clockbase.c:53
EffectSound m_TurnOnSound
Definition clockbase.c:20
void OnRingingStartClient()
Definition clockbase.c:154
EffectSound m_DestoryedSound
Definition clockbase.c:21
EAlarmClockState
Definition clockbase.c:2
@ COUNT
Definition clockbase.c:7
@ SET
Definition clockbase.c:4
@ RINGING
Definition clockbase.c:5
@ UNSET
Definition clockbase.c:3
override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
Definition clockbase.c:128
float GetRingingDurationMax()
Definition clockbase.c:181
EffectSound m_HitSound
Definition clockbase.c:22
void Disarm()
Definition clockbase.c:199
void TurnOffClient()
void MakeRingingStart()
Definition clockbase.c:223
void MakeRingingStop()
Definition clockbase.c:232
void OnRingingStopServer()
EffectSound m_RingingSoundLoop
Definition clockbase.c:19
void SetAlarmTimeServer(float time01)
Definition clockbase.c:320
void ~ClockBase()
Definition clockbase.c:32
string GetWorkingSound()
Definition clockbase.c:117
string GetDestroyedSound()
Definition clockbase.c:113
override bool IsInitialized()
override void OnVariablesSynchronized()
override Widget Init()
Definition dayzgame.c:127
override void EEKilled(Object killer)
void Arm()
proto native CGame GetGame()
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
enum EObjectTemperatureState m_State
void SetState(bool state)