1 #include "announcer.qh"
4 #include "../common/notifications.qh"
5 #include "../common/stats.qh"
6 #include "../common/util.qh"
10 void Announcer_Countdown()
12 float starttime = getstatf(STAT_GAMESTARTTIME);
13 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
14 if(roundstarttime == -1)
16 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
20 if(roundstarttime >= starttime)
21 starttime = roundstarttime;
22 if(starttime <= time && roundstarttime != starttime) // game start time has passed
23 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
25 float countdown = (starttime - time);
26 float countdown_rounded = floor(0.5 + countdown);
28 if(countdown <= 0) // countdown has finished, starttime is now
30 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
31 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
35 else // countdown is still going
37 // if concomitant countdown to round start overrides countdown to game start
38 if(roundstarttime == starttime)
40 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
41 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
45 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
46 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
49 self.nextthink = (starttime - (countdown - 1));
54 * Checks whether the server initiated a map restart (stat_game_starttime changed)
56 * TODO: Use a better solution where a common shared entitiy is used that contains
57 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
58 * and STAT_FRAGLIMIT to be auto-sent)
60 float previous_game_starttime;
61 void Announcer_Gamestart()
63 float startTime = getstatf(STAT_GAMESTARTTIME);
64 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
65 if(roundstarttime > startTime)
66 startTime = roundstarttime;
68 if(previous_game_starttime != startTime)
72 entity e = find(world, classname, "announcer_countdown");
76 e.classname = "announcer_countdown";
77 e.think = Announcer_Countdown;
80 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
81 if(time > e.nextthink) // don't play it again if countdown was already going
82 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
84 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
88 previous_game_starttime = startTime;
92 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
95 float timelimit = getstatf(STAT_TIMELIMIT);
96 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
97 float warmup_timeleft = 0;
100 if(autocvar_g_warmup_limit > 0)
101 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
104 if(autocvar_cl_announcer_maptime >= 2)
106 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
109 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
110 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
111 announcer_5min = false;
115 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
116 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
118 //if we're in warmup mode, check whether there's a warmup timelimit
119 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
121 announcer_5min = true;
122 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
129 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
133 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
134 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
135 announcer_1min = false;
137 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
138 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
140 // if we're in warmup mode, check whether there's a warmup timelimit
141 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
143 announcer_1min = true;
144 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
152 Announcer_Gamestart();