]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge remote-tracking branch 'origin/master' into samual/mutator_ctf
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / announcer.qc
1 float previous_announcement_time;
2 float previous_game_starttime;
3 string previous_announcement;
4
5 // remaining maptime announcer sounds, true when sound was already played
6 float announcer_1min;
7 float announcer_5min;
8
9 void Announcer_Play(string announcement)
10 {
11         if((announcement != previous_announcement) || (time >= (previous_announcement_time + autocvar_cl_announcer_antispam)))
12         {
13                 sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/", announcement, ".wav"), VOL_BASEVOICE, ATTN_NONE);
14
15                 if(previous_announcement) { strunzone(previous_announcement); }
16                 
17                 previous_announcement = strzone(announcement);
18                 previous_announcement_time = time;
19         }
20 }
21
22 void Announcer_Countdown() 
23 {
24         float starttime = getstatf(STAT_GAMESTARTTIME);
25         float countdown = (starttime - time);
26         float countdown_rounded = floor(0.5 + countdown);
27         
28         if(countdown <= 0) // countdown has finished, starttime is now
29         {
30                 if (!spectatee_status) 
31                         centerprint_generic(CPID_GAME_STARTING, _("^1Begin!"), 1, 0);
32
33                 Announcer_Play("begin");
34                 announcer_5min = announcer_1min = FALSE; // reset maptime announcers now as well
35                 remove(self);
36                 return;
37         }
38         else // countdown is still going
39         {
40                 if (!spectatee_status)
41                         centerprint_generic(CPID_GAME_STARTING, _("^1Game starts in %d seconds"), 1, countdown_rounded);
42
43                 if(countdown_rounded <= 3 && countdown_rounded >= 1) 
44                         Announcer_Play(ftos(countdown_rounded));
45
46                 self.nextthink = (starttime - (countdown - 1));
47         }
48 }
49
50 /**
51  * Checks whether the server initiated a map restart (stat_game_starttime changed)
52  *
53  * TODO: Use a better solution where a common shared entitiy is used that contains
54  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
55  * and STAT_FRAGLIMIT to be auto-sent)
56  */
57 void Announcer_Gamestart() 
58 {
59         float startTime = getstatf(STAT_GAMESTARTTIME);
60         
61         if(previous_game_starttime != startTime) 
62         {
63                 if((time + 5.0) < startTime) // if connecting to server while restart was active don't always play prepareforbattle
64                         Announcer_Play("prepareforbattle");
65                 
66                 if(time < startTime) 
67                 {
68                         entity e;
69                         e = spawn();
70                         e.think = Announcer_Countdown;
71                         e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
72                 }
73         }
74         
75         previous_game_starttime = startTime;
76 }
77
78
79 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
80 void Announcer_Time() 
81 {
82         float timelimit = getstatf(STAT_TIMELIMIT);
83         float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
84         float warmup_timeleft;
85         
86         if(warmup_stage) 
87                 if(autocvar_g_warmup_limit > 0)
88                         warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time); 
89
90         // 5 minute check
91         if(autocvar_cl_announcer_maptime >= 2) 
92         {
93                 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
94                 if(announcer_5min)
95                 {
96                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300) 
97                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
98                                         announcer_5min = FALSE;
99                 }
100                 else 
101                 {
102                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299) 
103                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
104                         {
105                                 //if we're in warmup mode, check whether there's a warmup timelimit
106                                 if not(autocvar_g_warmup_limit == -1 && warmup_stage) 
107                                 {
108                                         announcer_5min = TRUE;
109                                         Announcer_Play("5minutesremain");
110                                 }
111                         }
112                 }
113         }
114
115         // 1 minute check
116         if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
117         {
118                 if (announcer_1min)
119                 {
120                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60) 
121                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
122                                         announcer_1min = FALSE;
123                 }
124                 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60) 
125                         || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
126                 {
127                         // if we're in warmup mode, check whether there's a warmup timelimit
128                         if not(autocvar_g_warmup_limit == -1 && warmup_stage) 
129                         {
130                                 announcer_1min = TRUE;
131                                 Announcer_Play("1minuteremains");
132                         }
133                 }
134         }
135 }
136
137 void Announcer()
138 {
139         Announcer_Gamestart();
140         Announcer_Time();
141 }
142
143 void Announcer_Precache () 
144 {
145         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1minuteremains.wav"));
146         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/5minutesremain.wav"));
147
148         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/electrobitch.wav"));
149         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/airshot.wav"));
150         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/03kills.wav"));
151         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/05kills.wav"));
152         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/10kills.wav"));
153         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/15kills.wav"));
154         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/20kills.wav"));
155         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/25kills.wav"));
156         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/30kills.wav"));
157         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/botlike.wav"));
158         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/yoda.wav"));
159         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/amazing.wav"));
160         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/awesome.wav"));
161         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/headshot.wav"));
162         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/impressive.wav"));
163
164         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/prepareforbattle.wav"));
165         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/begin.wav"));
166         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/timeoutcalled.wav"));
167         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1fragleft.wav"));
168         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/2fragsleft.wav"));
169         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/3fragsleft.wav"));
170         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/terminated.wav"));
171
172         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/1.wav"));
173         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/2.wav"));
174         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/3.wav"));
175         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/4.wav"));
176         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/5.wav"));
177         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/6.wav"));
178         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/7.wav"));
179         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/8.wav"));
180         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/9.wav"));
181         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/10.wav"));
182
183         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/lastsecond.wav"));
184         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/narrowly.wav"));
185
186         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/voteaccept.wav"));
187         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/votecall.wav"));
188         precache_sound (strcat("announcer/", autocvar_cl_announcer, "/votefail.wav"));
189 }