]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
6074bf89a4f85955818cbeb3825e04168c68d2f1
[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                 Local_Notification(MSG_MULTI, MULTI_BEGIN); 
31                 announcer_5min = announcer_1min = FALSE; // reset maptime announcers now as well
32                 remove(self);
33                 return;
34         }
35         else // countdown is still going
36         {
37                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
38
39                 switch(countdown_rounded)
40                 {
41                         case 1: Local_Notification(MSG_ANNCE, ANNCE_NUM_1); break;
42                         case 2: Local_Notification(MSG_ANNCE, ANNCE_NUM_2); break;
43                         case 3: Local_Notification(MSG_ANNCE, ANNCE_NUM_3); break;
44                 }
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                         Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
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 = 0;
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                                         Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
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                                 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
132                         }
133                 }
134         }
135 }
136
137 void Announcer()
138 {
139         Announcer_Gamestart();
140         Announcer_Time();
141 }
142
143 void Announcer_Precache () 
144 {
145         // NOTHING
146 }