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();
34 bool inround = (roundstarttime && time >= starttime);
35 float countdown = (inround ? roundstarttime - time : starttime - time);
36 float countdown_rounded = floor(0.5 + countdown);
38 if(time >= starttime) centerprint_ClearTitle();
40 if(countdown <= 0) // countdown has finished, starttime is now
42 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
43 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
45 announcer_countdown = NULL;
46 centerprint_ClearTitle();
49 else // countdown is still going
53 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
54 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
56 Local_Notification(MSG_ANNCE, annce_num);
57 this.nextthink = (roundstarttime - (countdown - 1));
61 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
62 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
63 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
64 Local_Notification(MSG_ANNCE, annce_num);
65 this.nextthink = (starttime - (countdown - 1));
71 * Checks whether the server initiated a map restart (stat_game_starttime changed)
73 * TODO: Use a better solution where a common shared entitiy is used that contains
74 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
75 * and STAT_FRAGLIMIT to be auto-sent)
77 float previous_game_starttime;
78 void Announcer_Gamestart()
80 float startTime = STAT(GAMESTARTTIME);
81 float roundstarttime = STAT(ROUNDSTARTTIME);
82 if(roundstarttime > startTime)
83 startTime = roundstarttime;
86 if(announcer_countdown)
88 centerprint_Kill(ORDINAL(CPID_ROUND));
89 if(announcer_countdown)
91 delete(announcer_countdown);
92 announcer_countdown = NULL;
98 if(previous_game_starttime != startTime)
102 if (!announcer_countdown)
104 announcer_countdown = new(announcer_countdown);
105 setthink(announcer_countdown, Announcer_Countdown);
108 if(!warmup_stage && time < STAT(GAMESTARTTIME))
110 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype))); // Set centerprint title
111 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
112 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
115 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
119 previous_game_starttime = startTime;
122 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
123 if(announcer_##minute##min) { \
124 if(timeleft > minute * 60) \
125 announcer_##minute##min = false; \
127 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
128 announcer_##minute##min = true; \
129 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
134 void Announcer_Time()
136 static bool warmup_stage_prev;
141 if (warmup_stage != warmup_stage_prev)
143 announcer_5min = announcer_1min = false;
144 warmup_stage_prev = warmup_stage;
148 float starttime = STAT(GAMESTARTTIME);
151 announcer_5min = announcer_1min = false;
158 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
159 if(warmup_timelimit > 0)
160 timeleft = max(0, warmup_timelimit - time);
165 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
167 if(autocvar_cl_announcer_maptime >= 2)
168 ANNOUNCER_CHECKMINUTE(5);
170 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
171 ANNOUNCER_CHECKMINUTE(1);
176 Announcer_Gamestart();