1 #include "announcer.qh"
3 #include "autocvars.qh"
5 #include "../common/notifications.qh"
6 #include "../common/stats.qh"
7 #include "../common/util.qh"
8 #include "../dpdefs/csprogsdefs.qh"
12 void Announcer_Countdown()
14 float starttime = getstatf(STAT_GAMESTARTTIME);
15 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
16 if(roundstarttime == -1)
18 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
22 if(roundstarttime >= starttime)
23 starttime = roundstarttime;
24 if(starttime <= time && roundstarttime != starttime) // game start time has passed
25 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
27 float countdown = (starttime - time);
28 float countdown_rounded = floor(0.5 + countdown);
30 if(countdown <= 0) // countdown has finished, starttime is now
32 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
33 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
37 else // countdown is still going
39 // if concomitant countdown to round start overrides countdown to game start
40 if(roundstarttime == starttime)
42 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
43 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
47 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
48 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
51 self.nextthink = (starttime - (countdown - 1));
56 * Checks whether the server initiated a map restart (stat_game_starttime changed)
58 * TODO: Use a better solution where a common shared entitiy is used that contains
59 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
60 * and STAT_FRAGLIMIT to be auto-sent)
62 float previous_game_starttime;
63 void Announcer_Gamestart()
65 float startTime = getstatf(STAT_GAMESTARTTIME);
66 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
67 if(roundstarttime > startTime)
68 startTime = roundstarttime;
70 if(previous_game_starttime != startTime)
74 entity e = find(world, classname, "announcer_countdown");
78 e.classname = "announcer_countdown";
79 e.think = Announcer_Countdown;
82 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
83 if(time > e.nextthink) // don't play it again if countdown was already going
84 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
86 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
90 previous_game_starttime = startTime;
94 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
97 float timelimit = getstatf(STAT_TIMELIMIT);
98 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
99 float warmup_timeleft = 0;
102 if(autocvar_g_warmup_limit > 0)
103 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
106 if(autocvar_cl_announcer_maptime >= 2)
108 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
111 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
112 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
113 announcer_5min = false;
117 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
118 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
120 //if we're in warmup mode, check whether there's a warmup timelimit
121 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
123 announcer_5min = true;
124 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
131 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
135 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
136 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
137 announcer_1min = false;
139 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
140 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
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_1min = true;
146 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
154 Announcer_Gamestart();