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>
7 #include <common/mapinfo.qh>
11 string AnnouncerOption()
13 string ret = autocvar_cl_announcer;
14 MUTATOR_CALLHOOK(AnnouncerOption, ret);
15 ret = M_ARGV(0, string);
19 entity announcer_countdown;
21 void Announcer_Countdown(entity this)
23 float starttime = STAT(GAMESTARTTIME);
24 float roundstarttime = STAT(ROUNDSTARTTIME);
25 if(roundstarttime == -1)
27 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
29 announcer_countdown = NULL;
30 centerprint_ClearTitle();
33 if(starttime <= time && roundstarttime != starttime) // game start time has passed
34 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
36 bool inround = (roundstarttime && time >= starttime);
37 float countdown = (inround ? roundstarttime - time : starttime - time);
38 float countdown_rounded = floor(0.5 + countdown);
40 if(time >= starttime) centerprint_ClearTitle();
42 if(countdown <= 0) // countdown has finished, starttime is now
44 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
45 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
47 announcer_countdown = NULL;
48 centerprint_ClearTitle();
51 else // countdown is still going
55 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
56 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
58 Local_Notification(MSG_ANNCE, annce_num);
59 this.nextthink = (roundstarttime - (countdown - 1));
63 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
64 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
65 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
66 Local_Notification(MSG_ANNCE, annce_num);
67 this.nextthink = (starttime - (countdown - 1));
73 * Checks whether the server initiated a map restart (stat_game_starttime changed)
75 * TODO: Use a better solution where a common shared entitiy is used that contains
76 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
77 * and STAT_FRAGLIMIT to be auto-sent)
79 float previous_game_starttime;
80 void Announcer_Gamestart()
82 float startTime = STAT(GAMESTARTTIME);
83 float roundstarttime = STAT(ROUNDSTARTTIME);
84 if(roundstarttime > startTime)
85 startTime = roundstarttime;
88 if(announcer_countdown)
90 centerprint_Kill(ORDINAL(CPID_ROUND));
91 if(announcer_countdown)
93 delete(announcer_countdown);
94 announcer_countdown = NULL;
100 if(previous_game_starttime != startTime)
104 if (!announcer_countdown)
106 announcer_countdown = new(announcer_countdown);
107 setthink(announcer_countdown, Announcer_Countdown);
110 if(!warmup_stage && time < STAT(GAMESTARTTIME))
112 centerprint_SetTitle(MapInfo_Type_ToText(gametype)); // Set centerprint title
113 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
114 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
117 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
121 previous_game_starttime = startTime;
124 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
125 if(announcer_##minute##min) { \
126 if(timeleft > minute * 60) \
127 announcer_##minute##min = false; \
129 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
130 announcer_##minute##min = true; \
131 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
136 void Announcer_Time()
144 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
145 if(warmup_timelimit > 0)
146 timeleft = max(0, warmup_timelimit - time);
151 timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time);
153 if(autocvar_cl_announcer_maptime >= 2)
154 ANNOUNCER_CHECKMINUTE(5);
156 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
157 ANNOUNCER_CHECKMINUTE(1);
162 Announcer_Gamestart();