Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
alarmclock.c
Go to the documentation of this file.
2 {
3  const string RINGING_SOUND = "AlarmClock_Ring_Loop_SoundSet";
4  const string TURN_TOGGLE_SOUND = "AlarmClock_Turn_Off_SoundSet";
5  const string DESTROYED_SOUND = "AlarmClock_Destroyed_SoundSet";
6  const string HIT_SOUND = "AlarmClock_Hit_SoundSet";
7 
8 
9  static ref NoiseParams m_NoisePar;
10  static NoiseSystem m_NoiseSystem;
11 
12  override void Init()
13  {
14  super.Init();
15  if ( GetGame().IsServer() )
16  {
17  m_NoiseSystem = GetGame().GetNoiseSystem();
18  if ( m_NoiseSystem && !m_NoisePar )
19  {
20  // Create and load noise parameters
21  m_NoisePar = new NoiseParams;
22  m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseAlarmClock");
23  }
24  }
25  }
26 
27  void ~AlarmClock_ColorBase()
28  {
29  #ifndef SERVER
31  #endif
32  }
33 
34 
35  override void SetActions()
36  {
37  super.SetActions();
38 
42  }
43 
44  override string GetToggleSound()
45  {
46  return TURN_TOGGLE_SOUND;
47  }
48 
49  override string GetRingingSound()
50  {
51  return RINGING_SOUND;
52  }
53 
54  override string GetDestroyedSound()
55  {
56  return DESTROYED_SOUND;
57  }
58 
59  override string GetHitSound()
60  {
61  return HIT_SOUND;
62  }
63 
64  override string GetExplosiveTriggerSlotName()
65  {
66  return "TriggerAlarmClock";
67  }
68 
69  override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
70  {
71  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "SetAlarmAhead1Min", FadeColors.LIGHT_GREY));
72  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
73 
74  super.GetDebugActions(outputList);
75  }
76 
77  override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
78  {
79  if (super.OnAction(action_id, player, ctx))
80  return true;
81  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
82  {
83  if (action_id == EActions.ACTIVATE_ENTITY)
84  {
85  SetAlarmInXMins(1);
86  }
87 
88  }
89  return false;
90  }
91 
92  override string GetDebugText()
93  {
94  string debug_output;
95 
96  if( GetGame().IsDedicatedServer())
97  {
98  debug_output = "alarm in: " + GetAlarmInMin().ToString() + " mins" + "\n";
99  debug_output += "current state: " + typename.EnumToString(EAlarmClockState, m_State) + "\n";;
100  debug_output += "ringing for " + m_RingingDuration.ToString()+ " secs" + "\n";
101  debug_output += "ringing max " + GetRingingDurationMax().ToString()+ " secs" + "\n";
102  }
103  else
104  {
105  debug_output = "this is client";
106  }
107  return debug_output;
108  }
109 
110  void OnUpdate()
111  {
112  if ( IsAlarmOn() )
113  {
114  //due to variable server time flow(day-night time accel), it's not possible to simply set a timer for X secs without some convoluted math/code, so we need to check at regular intervals
115  int alarm_hand_in_minutes = ConvertAlarmHand01ToMins12h(m_AlarmTime01);
116 
117  int pass, hour, minute;
118  GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
119 
120  int curr_time_in_minutes = ConvertTimeToMins12h(hour, minute);
121 
122  //Print(GetAlarmInMin());
123 
124  if ( alarm_hand_in_minutes == curr_time_in_minutes )
125  {
127  }
128  }
129 
130  if ( IsRinging())
131  {
132  m_RingingDuration += UPDATE_TICK_RATE;
133 
135  {
136  TurnOff();
137  }
138  else if ( m_NoiseSystem )
139  {
140  m_NoiseSystem.AddNoiseTarget( GetPosition(), UPDATE_TICK_RATE, m_NoisePar);
141  }
142  }
143  }
144 
145  protected void AnimateAlarmHand(float value)
146  {
147  SetAnimationPhaseNow("ClockAlarm", value);
148  }
149 
150 
151  override bool OnStoreLoad( ParamsReadContext ctx, int version )
152  {
153  if (!super.OnStoreLoad(ctx, version))
154  return false;
155 
156  if (version < 126)
157  {
158  return true;
159  }
160 
161  EAlarmClockState state;
162 
163  if ( !ctx.Read( state ) )
164  {
165  return false;
166  }
167 
168  float time;
169 
170  if ( !ctx.Read( time ) )
171  {
172  return false;
173  }
174 
175  SetAlarmTimeServer(time);
176  SetState(state);
177  if ( state == EAlarmClockState.SET )
178  {
179  TurnOn();
180  }
181  else if (state == EAlarmClockState.RINGING )
182  {
184  }
185 
186  return true;
187  }
188 
189  override void OnStoreSave(ParamsWriteContext ctx)
190  {
191  super.OnStoreSave(ctx);
192 
193  ctx.Write(m_State);
194  ctx.Write(m_AlarmTime01);
195  }
196 
197  override void OnDebugSpawn()
198  {
199  TurnOn();
201  }
202 
203 };
204 
GetGame
proto native CGame GetGame()
IsAlarmOn
bool IsAlarmOn()
Definition: clockbase.c:296
SetAlarmInXMins
void SetAlarmInXMins(int in_mins)
Definition: clockbase.c:171
AlarmClock_Blue
Definition: alarmclock.c:206
SetAlarmTimeServer
void SetAlarmTimeServer(float time01)
Definition: clockbase.c:320
OnRingingStopClient
protected void OnRingingStopClient()
Definition: clockbase.c:166
AlarmClock_Red
Definition: alarmclock.c:205
ClockBase
void ClockBase()
Definition: clockbase.c:27
AlarmClock_Green
Definition: alarmclock.c:207
GetRingingDurationMax
float GetRingingDurationMax()
Definition: clockbase.c:181
MakeRingingStart
protected void MakeRingingStart()
Definition: clockbase.c:223
ActionTurnOffAlarmClock
ActionTurnOffHeadtorch ActionTurnOffAlarmClock
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
SetState
void SetState(bool state)
Definition: staminahandler.c:30
NoiseParams
class ObjectSpawnerHandler NoiseParams
ActionSetAlarmClock
Definition: actionsetalarmclock.c:13
IsRinging
bool IsRinging()
Definition: clockbase.c:291
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ActionTurnOnAlarmClock
ActionTurnOnChemlight ActionTurnOnAlarmClock
m_NoisePar
ref NoiseParams m_NoisePar
Definition: actionopendoors.c:2
m_AlarmTime01
enum EAlarmClockState m_AlarmTime01
EActions
EActions
Definition: eactions.c:1
m_NoiseSystem
protected NoiseSystem m_NoiseSystem
Definition: carscript.c:231
NoiseSystem
Definition: noise.c:1
TurnOff
void TurnOff()
Definition: clockbase.c:306
EAlarmClockState
EAlarmClockState
Definition: clockbase.c:1
SAT_DEBUG_ACTION
const int SAT_DEBUG_ACTION
Definition: constants.c:424
m_RingingDuration
float m_RingingDuration
Definition: clockbase.c:16
AlarmClock_ColorBase
Definition: alarmclock.c:1
TurnOn
void TurnOn()
Definition: clockbase.c:301
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
m_State
protected float m_DrainThreshold protected bool m_State
Definition: staminahandler.c:20
GetAlarmInMin
protected int GetAlarmInMin()
Definition: clockbase.c:53