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, _("vs"));
48 void Announcer_ClearTitle()
50 strfree(prev_pl1_name);
51 strfree(prev_pl2_name);
52 centerprint_ClearTitle();
56 void Announcer_Countdown(entity this)
58 float starttime = STAT(GAMESTARTTIME);
59 float roundstarttime = STAT(ROUNDSTARTTIME);
60 if(roundstarttime == -1)
62 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
64 announcer_countdown = NULL;
65 Announcer_ClearTitle();
69 bool inround = (roundstarttime && time >= starttime);
70 float countdown = (inround ? roundstarttime - time : starttime - time);
71 float countdown_rounded = floor(0.5 + countdown);
73 if(countdown <= 0) // countdown has finished, starttime is now
75 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
76 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
78 announcer_countdown = NULL;
79 Announcer_ClearTitle();
82 else // countdown is still going
86 if(!prev_inround) Announcer_ClearTitle(); // clear title if we just started the match
87 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
88 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
90 Local_Notification(MSG_ANNCE, annce_num);
91 this.nextthink = (roundstarttime - (countdown - 1));
95 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
96 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
97 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
98 Local_Notification(MSG_ANNCE, annce_num);
99 this.nextthink = (starttime - (countdown - 1));
103 prev_inround = inround;
107 * Checks whether the server initiated a map restart (stat_game_starttime changed)
109 * TODO: Use a better solution where a common shared entitiy is used that contains
110 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
111 * and STAT_FRAGLIMIT to be auto-sent)
113 float previous_game_starttime;
114 void Announcer_Gamestart()
116 float startTime = STAT(GAMESTARTTIME);
117 float roundstarttime = STAT(ROUNDSTARTTIME);
118 if(roundstarttime > startTime)
119 startTime = roundstarttime;
122 if(announcer_countdown)
124 centerprint_Kill(ORDINAL(CPID_ROUND));
125 if(announcer_countdown)
127 delete(announcer_countdown);
128 announcer_countdown = NULL;
134 if(announcer_countdown && gametype.m_1v1)
137 if(previous_game_starttime != startTime)
141 if (!announcer_countdown)
143 announcer_countdown = new(announcer_countdown);
144 setthink(announcer_countdown, Announcer_Countdown);
147 if(!warmup_stage && time < STAT(GAMESTARTTIME))
152 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype))); // Show game type as title
154 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
155 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
158 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
162 previous_game_starttime = startTime;
165 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
166 if(announcer_##minute##min) { \
167 if(timeleft > minute * 60) \
168 announcer_##minute##min = false; \
170 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
171 announcer_##minute##min = true; \
172 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
177 void Announcer_Time()
179 static bool warmup_stage_prev;
184 if (warmup_stage != warmup_stage_prev)
186 announcer_5min = announcer_1min = false;
187 warmup_stage_prev = warmup_stage;
191 float starttime = STAT(GAMESTARTTIME);
194 announcer_5min = announcer_1min = false;
201 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
202 if(warmup_timelimit > 0)
203 timeleft = max(0, warmup_timelimit - time);
208 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
210 if(autocvar_cl_announcer_maptime >= 2)
211 ANNOUNCER_CHECKMINUTE(5);
213 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
214 ANNOUNCER_CHECKMINUTE(1);
219 Announcer_Gamestart();