1 #include "announcer.qh"
3 #include "mutators/events.qh"
5 #include <common/notifications/all.qh>
6 #include <common/stats.qh>
10 string AnnouncerOption()
12 string ret = autocvar_cl_announcer;
13 MUTATOR_CALLHOOK(AnnouncerOption, ret);
14 ret = M_ARGV(0, string);
18 entity announcer_countdown;
20 void Announcer_Countdown(entity this)
22 float starttime = STAT(GAMESTARTTIME);
23 float roundstarttime = STAT(ROUNDSTARTTIME);
24 if (roundstarttime == -1) {
25 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
27 announcer_countdown = NULL;
30 if (roundstarttime >= starttime) {
31 starttime = roundstarttime;
33 if (starttime <= time && roundstarttime != starttime) { // game start time has passed
34 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
36 float countdown = (starttime - time);
37 float countdown_rounded = floor(0.5 + countdown);
39 if (countdown <= 0) { // countdown has finished, starttime is now
40 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
41 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
43 announcer_countdown = NULL;
45 } else { // countdown is still going
46 // if concomitant countdown to round start overrides countdown to game start
47 if (roundstarttime == starttime) {
48 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
49 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
50 if (annce_num != NULL) {
51 Local_Notification(MSG_ANNCE, annce_num);
54 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
55 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
56 if (annce_num != NULL) {
57 Local_Notification(MSG_ANNCE, annce_num);
61 this.nextthink = (starttime - (countdown - 1));
66 * Checks whether the server initiated a map restart (stat_game_starttime changed)
68 * TODO: Use a better solution where a common shared entitiy is used that contains
69 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
70 * and STAT_FRAGLIMIT to be auto-sent)
72 float previous_game_starttime;
73 void Announcer_Gamestart()
75 float startTime = STAT(GAMESTARTTIME);
76 float roundstarttime = STAT(ROUNDSTARTTIME);
77 if (roundstarttime > startTime) {
78 startTime = roundstarttime;
81 if (announcer_countdown) {
82 centerprint_kill(ORDINAL(CPID_ROUND));
83 if (announcer_countdown) {
84 delete(announcer_countdown);
85 announcer_countdown = NULL;
91 if (previous_game_starttime != startTime) {
92 if (time < startTime) {
93 if (!announcer_countdown) {
94 announcer_countdown = new(announcer_countdown);
95 setthink(announcer_countdown, Announcer_Countdown);
98 if (time + 5.0 < startTime) { // if connecting to server while restart was active don't always play prepareforbattle
99 if (time > announcer_countdown.nextthink) { // don't play it again if countdown was already going
100 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
104 announcer_countdown.nextthink = startTime - floor(startTime - time); // synchronize nextthink to startTime
108 previous_game_starttime = startTime;
111 #define ANNOUNCER_CHECKMINUTE(minute) \
113 if (announcer_##minute##min) { \
114 if (timeleft > minute * 60) { \
115 announcer_##minute##min = false; \
118 if (timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
119 announcer_##minute##min = true; \
120 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
125 void Announcer_Time()
129 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
130 if (warmup_timelimit > 0) {
131 timeleft = max(0, warmup_timelimit - time);
136 timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time);
139 if (autocvar_cl_announcer_maptime >= 2) {
140 ANNOUNCER_CHECKMINUTE(5);
143 if ((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3)) {
144 ANNOUNCER_CHECKMINUTE(1);
150 Announcer_Gamestart();