2 #include "../dpdefs/csprogsdefs.qh"
3 #include "../common/stats.qh"
4 #include "../common/util.qh"
5 #include "autocvars.qh"
6 #include "../common/notifications.qh"
14 void Announcer_Countdown()
16 float starttime = getstatf(STAT_GAMESTARTTIME);
17 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
18 if(roundstarttime == -1)
20 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
24 if(roundstarttime >= starttime)
25 starttime = roundstarttime;
26 if(starttime <= time && roundstarttime != starttime) // game start time has passed
27 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
29 float countdown = (starttime - time);
30 float countdown_rounded = floor(0.5 + countdown);
32 if(countdown <= 0) // countdown has finished, starttime is now
34 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
35 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
39 else // countdown is still going
41 // if concomitant countdown to round start overrides countdown to game start
42 if(roundstarttime == starttime)
44 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
45 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
49 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
50 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
53 self.nextthink = (starttime - (countdown - 1));
58 * Checks whether the server initiated a map restart (stat_game_starttime changed)
60 * TODO: Use a better solution where a common shared entitiy is used that contains
61 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
62 * and STAT_FRAGLIMIT to be auto-sent)
64 float previous_game_starttime;
65 void Announcer_Gamestart()
67 float startTime = getstatf(STAT_GAMESTARTTIME);
68 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
69 if(roundstarttime > startTime)
70 startTime = roundstarttime;
72 if(previous_game_starttime != startTime)
76 entity e = find(world, classname, "announcer_countdown");
80 e.classname = "announcer_countdown";
81 e.think = Announcer_Countdown;
84 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
85 if(time > e.nextthink) // don't play it again if countdown was already going
86 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
88 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
92 previous_game_starttime = startTime;
96 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
99 float timelimit = getstatf(STAT_TIMELIMIT);
100 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
101 float warmup_timeleft = 0;
104 if(autocvar_g_warmup_limit > 0)
105 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
108 if(autocvar_cl_announcer_maptime >= 2)
110 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
113 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
114 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
115 announcer_5min = false;
119 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
120 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
122 //if we're in warmup mode, check whether there's a warmup timelimit
123 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
125 announcer_5min = true;
126 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
133 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
137 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
138 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
139 announcer_1min = false;
141 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
142 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
144 // if we're in warmup mode, check whether there's a warmup timelimit
145 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
147 announcer_1min = true;
148 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
156 Announcer_Gamestart();