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 float offset = stringwidth(pl2_name, true, hud_fontsize) - stringwidth(pl1_name, true, hud_fontsize) - 1;
46 centerprint_SetTitle(sprintf("^BG%s^BG %s %s", pl1_name, _("vs"), pl2_name), offset / 2);
49 void Announcer_ClearTitle()
51 strfree(prev_pl1_name);
52 strfree(prev_pl2_name);
53 centerprint_ClearTitle();
57 void Announcer_Countdown(entity this)
59 float starttime = STAT(GAMESTARTTIME);
60 float roundstarttime = STAT(ROUNDSTARTTIME);
61 if(roundstarttime == -1)
63 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
65 announcer_countdown = NULL;
66 Announcer_ClearTitle();
70 bool inround = (roundstarttime && time >= starttime);
71 float countdown = (inround ? roundstarttime - time : starttime - time);
72 float countdown_rounded = floor(0.5 + countdown);
74 if(countdown <= 0) // countdown has finished, starttime is now
76 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
77 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
79 announcer_countdown = NULL;
80 Announcer_ClearTitle();
83 else // countdown is still going
87 if(!prev_inround) Announcer_ClearTitle(); // clear title if we just started the match
88 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
89 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
91 Local_Notification(MSG_ANNCE, annce_num);
92 this.nextthink = (roundstarttime - (countdown - 1));
96 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
97 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
98 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
99 Local_Notification(MSG_ANNCE, annce_num);
100 this.nextthink = (starttime - (countdown - 1));
104 prev_inround = inround;
108 * Checks whether the server initiated a map restart (stat_game_starttime changed)
110 * TODO: Use a better solution where a common shared entitiy is used that contains
111 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
112 * and STAT_FRAGLIMIT to be auto-sent)
114 float previous_game_starttime;
115 void Announcer_Gamestart()
117 float startTime = STAT(GAMESTARTTIME);
118 float roundstarttime = STAT(ROUNDSTARTTIME);
119 if(roundstarttime > startTime)
120 startTime = roundstarttime;
123 if(announcer_countdown)
125 centerprint_Kill(ORDINAL(CPID_ROUND));
126 if(announcer_countdown)
128 delete(announcer_countdown);
129 announcer_countdown = NULL;
135 if(announcer_countdown && gametype.m_1v1)
138 if(previous_game_starttime != startTime)
142 if (!announcer_countdown)
144 announcer_countdown = new(announcer_countdown);
145 setthink(announcer_countdown, Announcer_Countdown);
148 if(!warmup_stage && time < STAT(GAMESTARTTIME))
153 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype)), 0); // Show game type as title
155 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
156 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
159 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
163 previous_game_starttime = startTime;
166 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
167 if(announcer_##minute##min) { \
168 if(timeleft > minute * 60) \
169 announcer_##minute##min = false; \
171 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
172 announcer_##minute##min = true; \
173 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
178 void Announcer_Time()
180 static bool warmup_stage_prev;
185 if (warmup_stage != warmup_stage_prev)
187 announcer_5min = announcer_1min = false;
188 warmup_stage_prev = warmup_stage;
192 float starttime = STAT(GAMESTARTTIME);
195 announcer_5min = announcer_1min = false;
202 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
203 if(warmup_timelimit > 0)
204 timeleft = max(0, warmup_timelimit - time);
209 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
211 if(autocvar_cl_announcer_maptime >= 2)
212 ANNOUNCER_CHECKMINUTE(5);
214 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
215 ANNOUNCER_CHECKMINUTE(1);
220 Announcer_Gamestart();