1 #include "announcer.qh"
3 #include "../common/notifications.qh"
4 #include "../common/stats.qh"
8 void Announcer_Countdown()
11 float starttime = getstatf(STAT_GAMESTARTTIME);
12 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
13 if(roundstarttime == -1)
15 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
19 if(roundstarttime >= starttime)
20 starttime = roundstarttime;
21 if(starttime <= time && roundstarttime != starttime) // game start time has passed
22 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
24 float countdown = (starttime - time);
25 float countdown_rounded = floor(0.5 + countdown);
27 if(countdown <= 0) // countdown has finished, starttime is now
29 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
30 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
34 else // countdown is still going
36 // if concomitant countdown to round start overrides countdown to game start
37 if(roundstarttime == starttime)
39 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
40 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
44 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
45 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
48 this.nextthink = (starttime - (countdown - 1));
53 * Checks whether the server initiated a map restart (stat_game_starttime changed)
55 * TODO: Use a better solution where a common shared entitiy is used that contains
56 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
57 * and STAT_FRAGLIMIT to be auto-sent)
59 float previous_game_starttime;
60 void Announcer_Gamestart()
62 float startTime = getstatf(STAT_GAMESTARTTIME);
63 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
64 if(roundstarttime > startTime)
65 startTime = roundstarttime;
67 if(previous_game_starttime != startTime)
71 entity e = find(world, classname, "announcer_countdown");
75 e.classname = "announcer_countdown";
76 e.think = Announcer_Countdown;
79 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
80 if(time > e.nextthink) // don't play it again if countdown was already going
81 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
83 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
87 previous_game_starttime = startTime;
91 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
94 float timelimit = getstatf(STAT_TIMELIMIT);
95 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
96 float warmup_timeleft = 0;
99 if(autocvar_g_warmup_limit > 0)
100 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
103 if(autocvar_cl_announcer_maptime >= 2)
105 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
108 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
109 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
110 announcer_5min = false;
114 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
115 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
117 //if we're in warmup mode, check whether there's a warmup timelimit
118 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
120 announcer_5min = true;
121 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
128 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
132 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
133 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
134 announcer_1min = false;
136 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
137 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
139 // if we're in warmup mode, check whether there's a warmup timelimit
140 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
142 announcer_1min = true;
143 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
151 Announcer_Gamestart();