1 #include "announcer.qh"
3 #include "mutators/events.qh"
5 #include "../common/notifications.qh"
6 #include "../common/stats.qh"
10 string AnnouncerOption()
12 string ret = autocvar_cl_announcer;
13 MUTATOR_CALLHOOK(AnnouncerOption, ret);
18 void Announcer_Countdown()
21 float starttime = getstatf(STAT_GAMESTARTTIME);
22 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
23 if(roundstarttime == -1)
25 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
29 if(roundstarttime >= starttime)
30 starttime = roundstarttime;
31 if(starttime <= time && roundstarttime != starttime) // game start time has passed
32 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
34 float countdown = (starttime - time);
35 float countdown_rounded = floor(0.5 + countdown);
37 if(countdown <= 0) // countdown has finished, starttime is now
39 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
40 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
44 else // countdown is still going
46 // if concomitant countdown to round start overrides countdown to game start
47 if(roundstarttime == starttime)
49 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
50 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
54 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
55 Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
58 this.nextthink = (starttime - (countdown - 1));
63 * Checks whether the server initiated a map restart (stat_game_starttime changed)
65 * TODO: Use a better solution where a common shared entitiy is used that contains
66 * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
67 * and STAT_FRAGLIMIT to be auto-sent)
69 float previous_game_starttime;
70 void Announcer_Gamestart()
72 float startTime = getstatf(STAT_GAMESTARTTIME);
73 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
74 if(roundstarttime > startTime)
75 startTime = roundstarttime;
77 if(previous_game_starttime != startTime)
81 entity e = find(world, classname, "announcer_countdown");
85 e.classname = "announcer_countdown";
86 e.think = Announcer_Countdown;
89 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
90 if(time > e.nextthink) // don't play it again if countdown was already going
91 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
93 e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
97 previous_game_starttime = startTime;
101 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
102 void Announcer_Time()
104 float timelimit = getstatf(STAT_TIMELIMIT);
105 float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
106 float warmup_timeleft = 0;
109 if(autocvar_g_warmup_limit > 0)
110 warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
113 if(autocvar_cl_announcer_maptime >= 2)
115 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
118 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
119 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
120 announcer_5min = false;
124 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
125 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
127 //if we're in warmup mode, check whether there's a warmup timelimit
128 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
130 announcer_5min = true;
131 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
138 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
142 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
143 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
144 announcer_1min = false;
146 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
147 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
149 // if we're in warmup mode, check whether there's a warmup timelimit
150 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
152 announcer_1min = true;
153 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
161 Announcer_Gamestart();