DayZ 1.24
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
64
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
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
89 {
90 if (to_mins > from_mins)
91 return to_mins - from_mins;
92 else if (to_mins < from_mins)
93 return ((12 * 60) - from_mins) + to_mins;
94 else return 0;
95 }
96
98 {
99 return "";
100 }
102 {
103 return "";
104 }
105 string GetHitSound()
106 {
107 return "";
108 }
110 {
111 return "";
112 }
114 {
115 return "";
116 }
117
118 override void EEKilled(Object killer)
119 {
120 super.EEKilled(killer);
121 TurnOff();
122 }
123
124 override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
125 {
127 PlaySoundSet(m_HitSound, GetHitSound(), 0, 0);
128 }
129
130 override void OnDamageDestroyed(int oldLevel)
131 {
132 super.OnDamageDestroyed(oldLevel);
133
134 if (GetGame().IsClient())
135 {
137
138 if (oldLevel != -1)
139 PlaySoundSet(m_DestoryedSound, GetDestroyedSound(), 0, 0);
140 }
141 }
142
143 protected void OnRingingStartServer()
144 {
146 }
147
148 protected void OnRingingStartClient()
149 {
150 PlaySoundSetLoop(m_RingingSoundLoop, GetRingingSound(), 0, 0);
151
152 if (m_WorkingSound)
154 }
155
156 protected void OnRingingStopServer();
157
162
164 {
165 int pass, hour, minute;
166 GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
170 Arm();
171 }
172
174 {
176 }
177
178
179 protected void SetupTimerServer()
180 {
181 m_TimerUpdate = new Timer();
182 m_TimerUpdate.Run(UPDATE_TICK_RATE, this, "OnUpdate", null, true);
183 }
184
186 {
187 m_State = state;
188 SetSynchDirty();
189 }
190
191 protected void Disarm()
192 {
194 }
195
196 protected void Arm()
197 {
201 }
202
203 protected void ActivateParent()
204 {
205 if (GetHierarchyParent())
206 {
207 ItemBase parent = ItemBase.Cast(GetHierarchyParent());
208 if (parent)
209 parent.OnActivatedByItem(this);
210 }
211 }
212
213 protected void MakeRingingStart()
214 {
215 if (!m_TimerUpdate)
217 SetState(EAlarmClockState.RINGING);
218
220 }
221
222 protected void MakeRingingStop()
223 {
225
227 }
228
230
232
234 {
235 super.OnVariablesSynchronized();
236
237 if (m_State != m_StatePrev)//state changed
238 {
239 if (m_StatePrev == EAlarmClockState.RINGING)
241 else if (m_State == EAlarmClockState.RINGING)
243 if (m_State == EAlarmClockState.SET)
244 {
245 if (m_StatePrev != -1 || IsInitialized())
246 PlaySoundSet(m_TurnOnSound, GetToggleSound(), 0, 0);
247 if (GetWorkingSound())
248 PlaySoundSet(m_WorkingSound, GetWorkingSound(), 0, 0, true);
249 }
250 else if (m_State == EAlarmClockState.UNSET)
251 {
252 if (m_StatePrev == EAlarmClockState.SET)
253 {
254 if (m_WorkingSound)
256 if (m_StatePrev != -1 || IsInitialized())
257 PlaySoundSet(m_TurnOnSound, GetToggleSound(), 0, 0);
258 }
259 }
261 }
262 }
263
264
265 //---------------------------------------------------------------------------------------------------------
266 //---------------------------------------------- Public methods -------------------------------------------
267 //---------------------------------------------------------------------------------------------------------
268
270 {
271 return (m_State == EAlarmClockState.RINGING);
272 }
273
275 {
276 return (m_State == EAlarmClockState.SET);
277 }
278
279 void TurnOn()
280 {
281 Arm();
282 }
283
284 void TurnOff()
285 {
286 if (IsRinging())
288 else
289 Disarm();
290
292 }
293
295 {
296 SetAnimationPhaseNow("ClockAlarm", time01);
298 }
299}
ActionAttachExplosivesTriggerCB ActionContinuousBaseCB ActionAttachExplosivesTrigger()
void AddAction(typename actionName)
void SetActions()
override void OnDamageDestroyed(int oldLevel)
Definition AnimalBase.c:128
override void OnVariablesSynchronized()
void SetupTimerServer()
Definition ClockBase.c:179
enum EAlarmClockState m_AlarmTime01
void TurnOff()
Definition ClockBase.c:284
bool IsRinging()
Definition ClockBase.c:269
ref Timer m_TimerUpdate
Definition ClockBase.c:15
void ActivateParent()
Definition ClockBase.c:203
string GetHitSound()
Definition ClockBase.c:105
void OnRingingStopClient()
Definition ClockBase.c:158
void ClockBase()
Definition ClockBase.c:27
static int ConvertAlarmHand01ToMins(float time01, int mins_max)
Definition ClockBase.c:70
EffectSound m_WorkingSound
Definition ClockBase.c:23
bool IsAlarmOn()
Definition ClockBase.c:274
void OnRingingStartServer()
Definition ClockBase.c:143
const float RINGING_DURATION_MAX
Definition ClockBase.c:25
int m_StatePrev
Definition ClockBase.c:17
string GetRingingSound()
Definition ClockBase.c:101
static int GetTimeDiffInMins12h(int from_mins, int to_mins)
Definition ClockBase.c:88
string GetToggleSound()
Definition ClockBase.c:97
void TurnOnClient()
void SetAlarmInXMins(int in_mins)
Definition ClockBase.c:163
float m_RingingDuration
Definition ClockBase.c:16
void TurnOn()
Definition ClockBase.c:279
int GetAlarmInMin()
Definition ClockBase.c:53
EffectSound m_TurnOnSound
Definition ClockBase.c:20
void OnRingingStartClient()
Definition ClockBase.c:148
EffectSound m_DestoryedSound
Definition ClockBase.c:21
static float ConvertMins12hToAlarmHand01(int mins)
Definition ClockBase.c:75
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:124
static int ConvertAlarmHand01ToMins12h(float time01)
Definition ClockBase.c:65
float GetRingingDurationMax()
Definition ClockBase.c:173
EffectSound m_HitSound
Definition ClockBase.c:22
static const float UPDATE_TICK_RATE
Definition ClockBase.c:14
void Disarm()
Definition ClockBase.c:191
void TurnOffClient()
void MakeRingingStart()
Definition ClockBase.c:213
void MakeRingingStop()
Definition ClockBase.c:222
void OnRingingStopServer()
EffectSound m_RingingSoundLoop
Definition ClockBase.c:19
void SetAlarmTimeServer(float time01)
Definition ClockBase.c:294
void ~ClockBase()
Definition ClockBase.c:32
string GetWorkingSound()
Definition ClockBase.c:113
string GetDestroyedSound()
Definition ClockBase.c:109
static int ConvertTimeToMins12h(int hour, int minute)
Definition ClockBase.c:81
override bool IsInitialized()
override Widget Init()
Definition DayZGame.c:120
override void EEKilled(Object killer)
void Arm()
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
void SetState(bool state)
bool m_State
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.
proto native CGame GetGame()
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...