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;
31 if(starttime <= time && roundstarttime != starttime) // game start time has passed
32 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
34 bool inround = (roundstarttime && time >= starttime);
35 float countdown = (inround ? roundstarttime - time : starttime - time);
36 float countdown_rounded = floor(0.5 + countdown);
38 if(countdown <= 0) // countdown has finished, starttime is now
40 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
41 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
43 announcer_countdown = NULL;
46 else // countdown is still going
50 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
51 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
53 Local_Notification(MSG_ANNCE, annce_num);
54 this.nextthink = (roundstarttime - (countdown - 1));
58 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
59 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
60 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
61 Local_Notification(MSG_ANNCE, annce_num);
62 this.nextthink = (starttime - (countdown - 1));
68 * Checks whether the server initiated a map restart (stat_game_starttime changed)
70 * TODO: Use a better solution where a common shared entitiy is used that contains
71 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
72 * and STAT_FRAGLIMIT to be auto-sent)
74 float previous_game_starttime;
75 void Announcer_Gamestart()
77 float startTime = STAT(GAMESTARTTIME);
78 float roundstarttime = STAT(ROUNDSTARTTIME);
79 if(roundstarttime > startTime)
80 startTime = roundstarttime;
83 if(announcer_countdown)
85 centerprint_Kill(ORDINAL(CPID_ROUND));
86 if(announcer_countdown)
88 delete(announcer_countdown);
89 announcer_countdown = NULL;
95 if(previous_game_starttime != startTime)
99 if (!announcer_countdown)
101 announcer_countdown = new(announcer_countdown);
102 setthink(announcer_countdown, Announcer_Countdown);
105 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
106 if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
107 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
109 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
113 previous_game_starttime = startTime;
116 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
117 if(announcer_##minute##min) { \
118 if(timeleft > minute * 60) \
119 announcer_##minute##min = false; \
121 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
122 announcer_##minute##min = true; \
123 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
128 void Announcer_Time()
136 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
137 if(warmup_timelimit > 0)
138 timeleft = max(0, warmup_timelimit - time);
143 timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time);
145 if(autocvar_cl_announcer_maptime >= 2)
146 ANNOUNCER_CHECKMINUTE(5);
148 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
149 ANNOUNCER_CHECKMINUTE(1);
154 Announcer_Gamestart();