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 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
58 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
59 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
62 this.nextthink = (starttime - (countdown - 1));
67 * Checks whether the server initiated a map restart (stat_game_starttime changed)
69 * TODO: Use a better solution where a common shared entitiy is used that contains
70 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
71 * and STAT_FRAGLIMIT to be auto-sent)
73 float previous_game_starttime;
74 void Announcer_Gamestart()
76 float startTime = STAT(GAMESTARTTIME);
77 float roundstarttime = STAT(ROUNDSTARTTIME);
78 if(roundstarttime > startTime)
79 startTime = roundstarttime;
82 if(announcer_countdown)
84 centerprint_kill(ORDINAL(CPID_ROUND));
85 if(announcer_countdown)
87 remove(announcer_countdown);
88 announcer_countdown = NULL;
94 if(previous_game_starttime != startTime)
98 if (!announcer_countdown)
100 announcer_countdown = new(announcer_countdown);
101 announcer_countdown.think = Announcer_Countdown;
104 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
105 if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
106 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
108 announcer_countdown.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
112 previous_game_starttime = startTime;
116 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
117 void Announcer_Time()
119 float timelimit = STAT(TIMELIMIT);
120 float timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
121 float warmup_timeleft = 0;
124 if(autocvar_g_warmup_limit > 0)
125 warmup_timeleft = max(0, autocvar_g_warmup_limit + STAT(GAMESTARTTIME) - time);
128 if(autocvar_cl_announcer_maptime >= 2)
130 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
133 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
134 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
135 announcer_5min = false;
139 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
140 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
142 //if we're in warmup mode, check whether there's a warmup timelimit
143 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
145 announcer_5min = true;
146 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
153 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
157 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
158 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
159 announcer_1min = false;
161 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
162 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
164 // if we're in warmup mode, check whether there's a warmup timelimit
165 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
167 announcer_1min = true;
168 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
176 Announcer_Gamestart();