Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
alarmclock.c
Go to the documentation of this file.
1class AlarmClock_ColorBase: ClockBase
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
22 m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseAlarmClock");
23 }
24 }
25 }
26
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.RED));
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 {
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, NoiseAIEvaluate.GetNoiseReduction(GetGame().GetWeather()));
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
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
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition entityai.c:97
eBleedingSourceType GetType()
ref NoiseParams m_NoisePar
ActionTurnOffAlarmClockCB ActionSingleUseBaseCB ActionTurnOffAlarmClock()
ActionTurnOnAlarmClockCB ActionSingleUseBaseCB ActionTurnOnAlarmClock()
void AddAction(typename actionName)
void AnimateAlarmHand(float value)
Definition alarmclock.c:145
override void OnStoreSave(ParamsWriteContext ctx)
Definition alarmclock.c:189
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition alarmclock.c:151
override void OnDebugSpawn()
Definition alarmclock.c:197
Serialization general interface. Serializer API works with:
Definition serializer.c:56
enum EAlarmClockState m_AlarmTime01
void TurnOff()
Definition clockbase.c:306
bool IsRinging()
Definition clockbase.c:291
void OnRingingStopClient()
Definition clockbase.c:166
bool IsAlarmOn()
Definition clockbase.c:296
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
EAlarmClockState
Definition clockbase.c:2
float GetRingingDurationMax()
Definition clockbase.c:181
void MakeRingingStart()
Definition clockbase.c:223
void SetAlarmTimeServer(float time01)
Definition clockbase.c:320
EActions
Definition eactions.c:2
proto native CGame GetGame()
const int SAT_DEBUG_ACTION
Definition constants.c:454
class JsonUndergroundAreaTriggerData GetPosition
class NoiseSystem NoiseParams()
Definition noise.c:15
enum EObjectTemperatureState m_State
void SetState(bool state)