1 #include "announcer.qh"
4 #include "../common/notifications.qh"
5 #include "../common/stats.qh"
6 #include "../common/util.qh"
10 void Announcer_Countdown()
13 float starttime = getstatf(STAT_GAMESTARTTIME);
14 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
15 if(roundstarttime == -1)
17 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
21 if(roundstarttime >= starttime)
22 starttime = roundstarttime;
23 if(starttime <= time && roundstarttime != starttime) // game start time has passed
24 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
26 float countdown = (starttime - time);
27 float countdown_rounded = floor(0.5 + countdown);
29 if(countdown <= 0) // countdown has finished, starttime is now
31 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
32 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
36 else // countdown is still going
38 // if concomitant countdown to round start overrides countdown to game start
39 if(roundstarttime == starttime)
41 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
42 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
46 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
47 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
50 this.nextthink = (starttime - (countdown - 1));
55 * Checks whether the server initiated a map restart (stat_game_starttime changed)
57 * TODO: Use a better solution where a common shared entitiy is used that contains
58 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
59 * and STAT_FRAGLIMIT to be auto-sent)
61 float previous_game_starttime;
62 void Announcer_Gamestart()
64 float startTime = getstatf(STAT_GAMESTARTTIME);
65 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
66 if(roundstarttime > startTime)
67 startTime = roundstarttime;
69 if(previous_game_starttime != startTime)
73 entity e = find(world, classname, "announcer_countdown");
77 e.classname = "announcer_countdown";
78 e.think = Announcer_Countdown;
81 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
82 if(time > e.nextthink) // don't play it again if countdown was already going
83 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
85 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
89 previous_game_starttime = startTime;
93 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
96 float timelimit = getstatf(STAT_TIMELIMIT);
97 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
98 float warmup_timeleft = 0;
101 if(autocvar_g_warmup_limit > 0)
102 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
105 if(autocvar_cl_announcer_maptime >= 2)
107 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
110 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
111 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
112 announcer_5min = false;
116 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
117 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
119 //if we're in warmup mode, check whether there's a warmup timelimit
120 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
122 announcer_5min = true;
123 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
130 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
134 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
135 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
136 announcer_1min = false;
138 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
139 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
141 // if we're in warmup mode, check whether there's a warmup timelimit
142 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
144 announcer_1min = true;
145 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
153 Announcer_Gamestart();