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);
18 entity announcer_countdown;
20 void Announcer_Countdown()
23 float starttime = STAT(GAMESTARTTIME);
24 float roundstarttime = STAT(ROUNDSTARTTIME);
25 if(roundstarttime == -1)
27 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
29 announcer_countdown = NULL;
32 if(roundstarttime >= starttime)
33 starttime = roundstarttime;
34 if(starttime <= time && roundstarttime != starttime) // game start time has passed
35 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
37 float countdown = (starttime - time);
38 float countdown_rounded = floor(0.5 + countdown);
40 if(countdown <= 0) // countdown has finished, starttime is now
42 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
43 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
45 announcer_countdown = NULL;
48 else // countdown is still going
50 // if concomitant countdown to round start overrides countdown to game start
51 if(roundstarttime == starttime)
53 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
54 Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
56 Local_Notification(MSG_ANNCE, annce_num);
60 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
61 Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
63 Local_Notification(MSG_ANNCE, annce_num);
66 this.nextthink = (starttime - (countdown - 1));
71 * Checks whether the server initiated a map restart (stat_game_starttime changed)
73 * TODO: Use a better solution where a common shared entitiy is used that contains
74 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
75 * and STAT_FRAGLIMIT to be auto-sent)
77 float previous_game_starttime;
78 void Announcer_Gamestart()
80 float startTime = STAT(GAMESTARTTIME);
81 float roundstarttime = STAT(ROUNDSTARTTIME);
82 if(roundstarttime > startTime)
83 startTime = roundstarttime;
86 if(announcer_countdown)
88 centerprint_kill(ORDINAL(CPID_ROUND));
89 if(announcer_countdown)
91 remove(announcer_countdown);
92 announcer_countdown = NULL;
98 if(previous_game_starttime != startTime)
102 if (!announcer_countdown)
104 announcer_countdown = new(announcer_countdown);
105 announcer_countdown.think = Announcer_Countdown;
108 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
109 if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
110 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
112 announcer_countdown.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
116 previous_game_starttime = startTime;
119 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN { \
120 if(announcer_##minute##min) { \
121 if(timeleft > minute * 60) \
122 announcer_##minute##min = false; \
124 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
125 announcer_##minute##min = true; \
126 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
131 void Announcer_Time()
136 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
137 if(warmup_timelimit > 0)
138 timeleft = max(0, warmup_timelimit - time);
143 timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time);
145 if(autocvar_cl_announcer_maptime >= 2)
146 ANNOUNCER_CHECKMINUTE(5);
148 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
149 ANNOUNCER_CHECKMINUTE(1);
154 Announcer_Gamestart();