]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge remote-tracking branch 'origin/master' into samual/lightning_gun
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / announcer.qc
1 void Announcer_Play(string announcement)
2 {
3         /*if((announcement != previous_announcement) || (time >= (previous_announcement_time + autocvar_cl_announcer_antispam)))
4         {
5                 sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/", announcement, ".wav"), VOL_BASEVOICE, ATTN_NONE);
6
7                 if(previous_announcement) { strunzone(previous_announcement); }
8                 
9                 previous_announcement = strzone(announcement);
10                 previous_announcement_time = time;
11         }*/
12 }
13
14 float announcer_1min;
15 float announcer_5min;
16 void Announcer_Countdown() 
17 {
18         float starttime = getstatf(STAT_GAMESTARTTIME);
19         float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
20         if(roundstarttime == -1)
21         {
22                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
23                 remove(self);
24                 return;
25         }
26         if(roundstarttime >= starttime)
27                 starttime = roundstarttime;
28         if(starttime <= time && roundstarttime != starttime) // game start time has passed
29                 announcer_5min = announcer_1min = FALSE; // reset maptime announcers now as well
30
31         float countdown = (starttime - time);
32         float countdown_rounded = floor(0.5 + countdown);
33
34         if(countdown <= 0) // countdown has finished, starttime is now
35         {
36                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN); 
37                 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN); 
38                 remove(self);
39                 return;
40         }
41         else // countdown is still going
42         {
43                 if(roundstarttime == starttime)
44                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
45                 else
46                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
47
48                 switch(countdown_rounded)
49                 {
50                         case 1: Local_Notification(MSG_ANNCE, ANNCE_NUM_1); break;
51                         case 2: Local_Notification(MSG_ANNCE, ANNCE_NUM_2); break;
52                         case 3: Local_Notification(MSG_ANNCE, ANNCE_NUM_3); break;
53                 }
54
55                 self.nextthink = (starttime - (countdown - 1));
56         }
57 }
58
59 /**
60  * Checks whether the server initiated a map restart (stat_game_starttime changed)
61  *
62  * TODO: Use a better solution where a common shared entitiy is used that contains
63  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
64  * and STAT_FRAGLIMIT to be auto-sent)
65  */
66  float previous_game_starttime;
67 void Announcer_Gamestart() 
68 {
69         float startTime = getstatf(STAT_GAMESTARTTIME);
70         float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
71         if(roundstarttime > startTime)
72                 startTime = roundstarttime;
73
74         if(previous_game_starttime != startTime) 
75         {
76                 if((time + 5.0) < startTime) // if connecting to server while restart was active don't always play prepareforbattle
77                         Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
78
79                 if(time < startTime) 
80                 {
81                         entity e = find(world, classname, "announcer_countdown");
82                         if not(e)
83                         {
84                                 e = spawn();
85                                 e.classname = "announcer_countdown";
86                                 e.think = Announcer_Countdown;
87                         }
88                         e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
89                 }
90         }
91         
92         previous_game_starttime = startTime;
93 }
94
95
96 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
97 void Announcer_Time() 
98 {
99         float timelimit = getstatf(STAT_TIMELIMIT);
100         float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
101         float warmup_timeleft = 0;
102         
103         if(warmup_stage) 
104                 if(autocvar_g_warmup_limit > 0)
105                         warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time); 
106
107         // 5 minute check
108         if(autocvar_cl_announcer_maptime >= 2) 
109         {
110                 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
111                 if(announcer_5min)
112                 {
113                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300) 
114                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
115                                         announcer_5min = FALSE;
116                 }
117                 else 
118                 {
119                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299) 
120                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
121                         {
122                                 //if we're in warmup mode, check whether there's a warmup timelimit
123                                 if not(autocvar_g_warmup_limit == -1 && warmup_stage) 
124                                 {
125                                         announcer_5min = TRUE;
126                                         Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
127                                 }
128                         }
129                 }
130         }
131
132         // 1 minute check
133         if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
134         {
135                 if (announcer_1min)
136                 {
137                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60) 
138                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
139                                         announcer_1min = FALSE;
140                 }
141                 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60) 
142                         || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
143                 {
144                         // if we're in warmup mode, check whether there's a warmup timelimit
145                         if not(autocvar_g_warmup_limit == -1 && warmup_stage) 
146                         {
147                                 announcer_1min = TRUE;
148                                 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
149                         }
150                 }
151         }
152 }
153
154 void Announcer()
155 {
156         Announcer_Gamestart();
157         Announcer_Time();
158 }