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 void Announcer_Countdown(entity this)
26 float starttime = STAT(GAMESTARTTIME);
27 float roundstarttime = STAT(ROUNDSTARTTIME);
28 if(roundstarttime == -1)
30 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
32 announcer_countdown = NULL;
33 centerprint_ClearTitle();
37 bool inround = (roundstarttime && time >= starttime);
38 float countdown = (inround ? roundstarttime - time : starttime - time);
39 float countdown_rounded = floor(0.5 + countdown);
41 if(countdown <= 0) // countdown has finished, starttime is now
43 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
44 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
46 announcer_countdown = NULL;
47 centerprint_ClearTitle();
50 else // countdown is still going
54 if(!prev_inround) centerprint_ClearTitle(); // clear title if we just started the match
55 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, STAT(ROUNDS_PLAYED) + 1, countdown_rounded);
56 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
58 Local_Notification(MSG_ANNCE, annce_num);
59 this.nextthink = (roundstarttime - (countdown - 1));
63 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
64 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
65 if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
66 Local_Notification(MSG_ANNCE, annce_num);
67 this.nextthink = (starttime - (countdown - 1));
71 prev_inround = inround;
75 * Checks whether the server initiated a map restart (stat_game_starttime changed)
77 * TODO: Use a better solution where a common shared entitiy is used that contains
78 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
79 * and STAT_FRAGLIMIT to be auto-sent)
81 float previous_game_starttime;
82 void Announcer_Gamestart()
84 float startTime = STAT(GAMESTARTTIME);
85 float roundstarttime = STAT(ROUNDSTARTTIME);
86 if(roundstarttime > startTime)
87 startTime = roundstarttime;
90 if(announcer_countdown)
92 centerprint_Kill(ORDINAL(CPID_ROUND));
93 if(announcer_countdown)
95 delete(announcer_countdown);
96 announcer_countdown = NULL;
102 if(previous_game_starttime != startTime)
106 if (!announcer_countdown)
108 announcer_countdown = new(announcer_countdown);
109 setthink(announcer_countdown, Announcer_Countdown);
112 if(!warmup_stage && time < STAT(GAMESTARTTIME))
116 entity pl1 = players.sort_next;
117 entity pl2 = pl1.sort_next;
118 string pl1_name = (pl1 && pl1.team != NUM_SPECTATOR ? entcs_GetName(pl1.sv_entnum) : "???");
119 string pl2_name = (pl2 && pl2.team != NUM_SPECTATOR ? entcs_GetName(pl2.sv_entnum) : "???");
121 float offset = stringwidth(pl2_name, true, hud_fontsize) - stringwidth(pl1_name, true, hud_fontsize) - 1;
122 centerprint_SetTitle(sprintf("^BG%s^BG%s%s", pl1_name, _(" vs "), pl2_name), offset / 2); // Show duelers in 1v1 game mode
125 centerprint_SetTitle(strcat("^BG", MapInfo_Type_ToText(gametype)), 0); // Show game type as title
127 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
128 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
131 announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
135 previous_game_starttime = startTime;
138 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
139 if(announcer_##minute##min) { \
140 if(timeleft > minute * 60) \
141 announcer_##minute##min = false; \
143 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
144 announcer_##minute##min = true; \
145 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
150 void Announcer_Time()
152 static bool warmup_stage_prev;
157 if (warmup_stage != warmup_stage_prev)
159 announcer_5min = announcer_1min = false;
160 warmup_stage_prev = warmup_stage;
164 float starttime = STAT(GAMESTARTTIME);
167 announcer_5min = announcer_1min = false;
174 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
175 if(warmup_timelimit > 0)
176 timeleft = max(0, warmup_timelimit - time);
181 timeleft = max(0, STAT(TIMELIMIT) * 60 + starttime - time);
183 if(autocvar_cl_announcer_maptime >= 2)
184 ANNOUNCER_CHECKMINUTE(5);
186 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
187 ANNOUNCER_CHECKMINUTE(1);
192 Announcer_Gamestart();