1 #include "announcer.qh"
3 #include <client/hud/panel/centerprint.qh>
4 #include <client/mutators/_mod.qh>
5 #include <common/notifications/all.qh>
6 #include <common/stats.qh>
10 string AnnouncerOption()
12 string ret = autocvar_cl_announcer;
13 MUTATOR_CALLHOOK(AnnouncerOption, ret);
14 ret = M_ARGV(0, string);
18 entity announcer_countdown;
20 void Announcer_Countdown(entity this)
22 float starttime = STAT(GAMESTARTTIME);
23 float roundstarttime = STAT(ROUNDSTARTTIME);
24 if(roundstarttime == -1)
26 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
28 announcer_countdown = NULL;
32 bool inround = (roundstarttime && time >= starttime);
33 float countdown = (inround ? roundstarttime - time : starttime - time);
34 float countdown_rounded = floor(0.5 + countdown);
36 if(countdown <= 0) // countdown has finished, starttime is now
38 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
39 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
41 announcer_countdown = NULL;
44 else // countdown is still going
48 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
49 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
51 Local_Notification(MSG_ANNCE, annce_num);
52 this.nextthink = (roundstarttime - (countdown - 1));
56 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
57 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
58 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
59 Local_Notification(MSG_ANNCE, annce_num);
60 this.nextthink = (starttime - (countdown - 1));
66 * Checks whether the server initiated a map restart (stat_game_starttime changed)
68 * TODO: Use a better solution where a common shared entitiy is used that contains
69 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
70 * and STAT_FRAGLIMIT to be auto-sent)
72 float previous_game_starttime;
73 void Announcer_Gamestart()
75 float startTime = STAT(GAMESTARTTIME);
76 float roundstarttime = STAT(ROUNDSTARTTIME);
77 if(roundstarttime > startTime)
78 startTime = roundstarttime;
81 if(announcer_countdown)
83 centerprint_Kill(ORDINAL(CPID_ROUND));
84 if(announcer_countdown)
86 delete(announcer_countdown);
87 announcer_countdown = NULL;
93 if(previous_game_starttime != startTime)
97 if (!announcer_countdown)
99 announcer_countdown = new(announcer_countdown);
100 setthink(announcer_countdown, Announcer_Countdown);
103 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
104 if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
105 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
107 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
111 previous_game_starttime = startTime;
114 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
115 if(announcer_##minute##min) { \
116 if(timeleft > minute * 60) \
117 announcer_##minute##min = false; \
119 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
120 announcer_##minute##min = true; \
121 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
126 void Announcer_Time()
128 static bool warmup_stage_prev;
133 if (warmup_stage != warmup_stage_prev)
135 announcer_5min = announcer_1min = false;
136 warmup_stage_prev = warmup_stage;
140 float starttime = STAT(GAMESTARTTIME);
143 announcer_5min = announcer_1min = false;
150 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
151 if(warmup_timelimit > 0)
152 timeleft = max(0, warmup_timelimit - time);
157 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
159 if(autocvar_cl_announcer_maptime >= 2)
160 ANNOUNCER_CHECKMINUTE(5);
162 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
163 ANNOUNCER_CHECKMINUTE(1);
168 Announcer_Gamestart();