1 #include "announcer.qh"
3 #include <client/draw.qh>
4 #include <client/hud/panel/centerprint.qh>
5 #include <client/mutators/_mod.qh>
6 #include <common/notifications/all.qh>
7 #include <common/stats.qh>
8 #include <common/mapinfo.qh>
9 #include <common/ent_cs.qh>
13 string AnnouncerOption()
15 string ret = autocvar_cl_announcer;
16 MUTATOR_CALLHOOK(AnnouncerOption, ret);
17 ret = M_ARGV(0, string);
21 entity announcer_countdown;
24 * Displays duel title; updates it if the players in-game have changed.
30 entity pl1 = players.sort_next;
31 entity pl2 = pl1.sort_next;
32 string pl1_name = (pl1 && pl1.team != NUM_SPECTATOR ? entcs_GetName(pl1.sv_entnum) : "???");
33 string pl2_name = (pl2 && pl2.team != NUM_SPECTATOR ? entcs_GetName(pl2.sv_entnum) : "???");
35 if(pl1_name == prev_pl1_name && pl2_name == prev_pl2_name)
36 return; // Players haven't changed, stop here
38 strcpy(prev_pl1_name, pl1_name);
39 strcpy(prev_pl2_name, pl2_name);
41 // There are new duelers, update title
42 float offset = stringwidth(pl2_name, true, hud_fontsize) - stringwidth(pl1_name, true, hud_fontsize) - 1;
43 centerprint_SetTitle(sprintf("^BG%s^BG%s%s", pl1_name, _(" vs "), pl2_name), offset / 2);
46 void Announcer_ClearTitle()
48 strfree(prev_pl1_name);
49 strfree(prev_pl2_name);
50 centerprint_ClearTitle();
54 void Announcer_Countdown(entity this)
56 float starttime = STAT(GAMESTARTTIME);
57 float roundstarttime = STAT(ROUNDSTARTTIME);
58 if(roundstarttime == -1)
60 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
62 announcer_countdown = NULL;
63 Announcer_ClearTitle();
67 bool inround = (roundstarttime && time >= starttime);
68 float countdown = (inround ? roundstarttime - time : starttime - time);
69 float countdown_rounded = floor(0.5 + countdown);
71 if(countdown <= 0) // countdown has finished, starttime is now
73 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
74 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
76 announcer_countdown = NULL;
77 Announcer_ClearTitle();
80 else // countdown is still going
84 if(!prev_inround) Announcer_ClearTitle(); // clear title if we just started the match
85 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
86 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
88 Local_Notification(MSG_ANNCE, annce_num);
89 this.nextthink = (roundstarttime - (countdown - 1));
93 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
94 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
95 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
96 Local_Notification(MSG_ANNCE, annce_num);
97 this.nextthink = (starttime - (countdown - 1));
101 prev_inround = inround;
105 * Checks whether the server initiated a map restart (stat_game_starttime changed)
107 * TODO: Use a better solution where a common shared entitiy is used that contains
108 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
109 * and STAT_FRAGLIMIT to be auto-sent)
111 float previous_game_starttime;
112 void Announcer_Gamestart()
114 float startTime = STAT(GAMESTARTTIME);
115 float roundstarttime = STAT(ROUNDSTARTTIME);
116 if(roundstarttime > startTime)
117 startTime = roundstarttime;
120 if(announcer_countdown)
122 centerprint_Kill(ORDINAL(CPID_ROUND));
123 if(announcer_countdown)
125 delete(announcer_countdown);
126 announcer_countdown = NULL;
132 if(announcer_countdown && gametype.m_1v1)
135 if(previous_game_starttime != startTime)
139 if (!announcer_countdown)
141 announcer_countdown = new(announcer_countdown);
142 setthink(announcer_countdown, Announcer_Countdown);
145 if(!warmup_stage && time < STAT(GAMESTARTTIME))
150 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype)), 0); // Show game type as title
152 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
153 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
156 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
160 previous_game_starttime = startTime;
163 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
164 if(announcer_##minute##min) { \
165 if(timeleft > minute * 60) \
166 announcer_##minute##min = false; \
168 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
169 announcer_##minute##min = true; \
170 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
175 void Announcer_Time()
177 static bool warmup_stage_prev;
182 if (warmup_stage != warmup_stage_prev)
184 announcer_5min = announcer_1min = false;
185 warmup_stage_prev = warmup_stage;
189 float starttime = STAT(GAMESTARTTIME);
192 announcer_5min = announcer_1min = false;
199 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
200 if(warmup_timelimit > 0)
201 timeleft = max(0, warmup_timelimit - time);
206 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
208 if(autocvar_cl_announcer_maptime >= 2)
209 ANNOUNCER_CHECKMINUTE(5);
211 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
212 ANNOUNCER_CHECKMINUTE(1);
217 Announcer_Gamestart();