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 = 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 = STAT(GAMESTARTTIME);
73 float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
74 if(roundstarttime > startTime)
75 startTime = roundstarttime;
77 if(previous_game_starttime != startTime)
81 static entity announcer_countdown;
82 if (!announcer_countdown)
84 announcer_countdown = new(announcer_countdown);
85 announcer_countdown.think = Announcer_Countdown;
88 if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
89 if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
90 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
92 announcer_countdown.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
96 previous_game_starttime = startTime;
100 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
101 void Announcer_Time()
103 float timelimit = getstatf(STAT_TIMELIMIT);
104 float timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
105 float warmup_timeleft = 0;
108 if(autocvar_g_warmup_limit > 0)
109 warmup_timeleft = max(0, autocvar_g_warmup_limit + STAT(GAMESTARTTIME) - time);
112 if(autocvar_cl_announcer_maptime >= 2)
114 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
117 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
118 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
119 announcer_5min = false;
123 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
124 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
126 //if we're in warmup mode, check whether there's a warmup timelimit
127 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
129 announcer_5min = true;
130 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
137 if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
141 if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
142 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
143 announcer_1min = false;
145 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
146 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
148 // if we're in warmup mode, check whether there's a warmup timelimit
149 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
151 announcer_1min = true;
152 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
160 Announcer_Gamestart();