1 #include "announcer.qh"
3 #include <client/draw.qh>
4 #include <client/hud/panel/centerprint.qh>
5 #include <client/hud/panel/scoreboard.qh>
6 #include <client/mutators/_mod.qh>
7 #include <common/notifications/all.qh>
8 #include <common/stats.qh>
9 #include <common/mapinfo.qh>
10 #include <common/ent_cs.qh>
14 string AnnouncerOption()
16 string ret = autocvar_cl_announcer;
17 MUTATOR_CALLHOOK(AnnouncerOption, ret);
18 ret = M_ARGV(0, string);
22 entity announcer_countdown;
25 * Displays duel title; updates it if the players in-game have changed.
31 Scoreboard_UpdatePlayerTeams();
33 entity pl1 = players.sort_next;
34 entity pl2 = pl1.sort_next;
35 string pl1_name = (pl1 && pl1.team != NUM_SPECTATOR ? entcs_GetName(pl1.sv_entnum) : "???");
36 string pl2_name = (pl2 && pl2.team != NUM_SPECTATOR ? entcs_GetName(pl2.sv_entnum) : "???");
38 if(pl1_name == prev_pl1_name && pl2_name == prev_pl2_name)
39 return; // Players haven't changed, stop here
41 strcpy(prev_pl1_name, pl1_name);
42 strcpy(prev_pl2_name, pl2_name);
44 // There are new duelers, update title
45 centerprint_SetDuelTitle(pl1_name, pl2_name);
48 void Announcer_ClearTitle()
50 strfree(prev_pl1_name);
51 strfree(prev_pl2_name);
52 centerprint_ClearTitle();
57 float prev_roundstarttime;
58 void Announcer_Countdown(entity this)
60 float starttime = STAT(GAMESTARTTIME);
61 float roundstarttime = STAT(ROUNDSTARTTIME);
62 if(roundstarttime == -1)
64 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
66 announcer_countdown = NULL;
67 Announcer_ClearTitle();
71 bool inround = (roundstarttime && time >= starttime);
72 float countdown = (inround ? roundstarttime - time : starttime - time);
73 float countdown_rounded = floor(0.5 + countdown);
75 if (starttime != prev_starttime || roundstarttime != prev_roundstarttime || prev_inround != inround)
76 this.skin = 0; // restart centerprint countdown
78 if(countdown <= 0) // countdown has finished, starttime is now
80 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
81 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
83 announcer_countdown = NULL;
84 Announcer_ClearTitle();
87 else // countdown is still going
91 if(!prev_inround) Announcer_ClearTitle(); // clear title if we just started the match
92 if (!this.skin) // first tic
93 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
94 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
96 Local_Notification(MSG_ANNCE, annce_num);
97 this.nextthink = (roundstarttime - (countdown - 1));
101 if (!this.skin) // first tic
102 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
103 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
104 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
105 Local_Notification(MSG_ANNCE, annce_num);
106 this.nextthink = (starttime - (countdown - 1));
108 // Don't call centerprint countdown in the remaining tics, it will continue automatically.
109 // It's an optimization but also fixes ^COUNT shown in the last tic because of high slowmo values (15+).
110 // Hopefully it fixes ^COUNT occasionally shown in online servers, probably due to lags.
111 this.skin = 1; // recycled field
114 prev_inround = inround;
115 prev_starttime = starttime;
116 prev_roundstarttime = roundstarttime;
120 * Checks whether the server initiated a map restart (stat_game_starttime changed)
122 * TODO: Use a better solution where a common shared entitiy is used that contains
123 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
124 * and STAT_FRAGLIMIT to be auto-sent)
126 float previous_game_starttime;
127 void Announcer_Gamestart()
129 float startTime = STAT(GAMESTARTTIME);
130 float roundstarttime = STAT(ROUNDSTARTTIME);
131 if(roundstarttime > startTime)
132 startTime = roundstarttime;
135 Announcer_ClearTitle();
136 if(announcer_countdown)
138 centerprint_Kill(ORDINAL(CPID_ROUND));
139 if(announcer_countdown)
141 delete(announcer_countdown);
142 announcer_countdown = NULL;
148 if(announcer_countdown && gametype.m_1v1)
151 if(previous_game_starttime != startTime)
155 if (!announcer_countdown)
157 announcer_countdown = new(announcer_countdown);
158 setthink(announcer_countdown, Announcer_Countdown);
161 if(!warmup_stage && time < STAT(GAMESTARTTIME))
166 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype))); // Show game type as title
168 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
169 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
172 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
176 previous_game_starttime = startTime;
179 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
180 if(announcer_##minute##min) { \
181 if(timeleft > minute * 60) \
182 announcer_##minute##min = false; \
184 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
185 announcer_##minute##min = true; \
186 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
191 void Announcer_Time()
193 static bool warmup_stage_prev;
198 if (warmup_stage != warmup_stage_prev)
200 announcer_5min = announcer_1min = false;
201 warmup_stage_prev = warmup_stage;
205 float starttime = STAT(GAMESTARTTIME);
208 announcer_5min = announcer_1min = false;
215 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
216 if(warmup_timelimit > 0)
217 timeleft = max(0, warmup_timelimit - time);
222 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
224 if(autocvar_cl_announcer_maptime >= 2)
225 ANNOUNCER_CHECKMINUTE(5);
227 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
228 ANNOUNCER_CHECKMINUTE(1);
233 // announcer code sets gametype name as centerprint title
236 Announcer_Gamestart();