]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge remote-tracking branch 'origin/master' into terencehill/hud_code_restructure
[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 countdown = (starttime - time);
20         float countdown_rounded = floor(0.5 + countdown);
21         
22         if(countdown <= 0) // countdown has finished, starttime is now
23         {
24                 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN); 
25                 announcer_5min = announcer_1min = FALSE; // reset maptime announcers now as well
26                 remove(self);
27                 return;
28         }
29         else // countdown is still going
30         {
31                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
32
33                 switch(countdown_rounded)
34                 {
35                         case 1: Local_Notification(MSG_ANNCE, ANNCE_NUM_1); break;
36                         case 2: Local_Notification(MSG_ANNCE, ANNCE_NUM_2); break;
37                         case 3: Local_Notification(MSG_ANNCE, ANNCE_NUM_3); break;
38                 }
39
40                 self.nextthink = (starttime - (countdown - 1));
41         }
42 }
43
44 /**
45  * Checks whether the server initiated a map restart (stat_game_starttime changed)
46  *
47  * TODO: Use a better solution where a common shared entitiy is used that contains
48  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
49  * and STAT_FRAGLIMIT to be auto-sent)
50  */
51  float previous_game_starttime;
52 void Announcer_Gamestart() 
53 {
54         float startTime = getstatf(STAT_GAMESTARTTIME);
55         
56         if(previous_game_starttime != startTime) 
57         {
58                 if((time + 5.0) < startTime) // if connecting to server while restart was active don't always play prepareforbattle
59                         Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
60                 
61                 if(time < startTime) 
62                 {
63                         entity e;
64                         e = spawn();
65                         e.think = Announcer_Countdown;
66                         e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
67                 }
68         }
69         
70         previous_game_starttime = startTime;
71 }
72
73
74 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
75 void Announcer_Time() 
76 {
77         float timelimit = getstatf(STAT_TIMELIMIT);
78         float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
79         float warmup_timeleft = 0;
80         
81         if(warmup_stage) 
82                 if(autocvar_g_warmup_limit > 0)
83                         warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time); 
84
85         // 5 minute check
86         if(autocvar_cl_announcer_maptime >= 2) 
87         {
88                 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
89                 if(announcer_5min)
90                 {
91                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300) 
92                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
93                                         announcer_5min = FALSE;
94                 }
95                 else 
96                 {
97                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299) 
98                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
99                         {
100                                 //if we're in warmup mode, check whether there's a warmup timelimit
101                                 if not(autocvar_g_warmup_limit == -1 && warmup_stage) 
102                                 {
103                                         announcer_5min = TRUE;
104                                         Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
105                                 }
106                         }
107                 }
108         }
109
110         // 1 minute check
111         if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
112         {
113                 if (announcer_1min)
114                 {
115                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60) 
116                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
117                                         announcer_1min = FALSE;
118                 }
119                 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60) 
120                         || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
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_1min = TRUE;
126                                 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
127                         }
128                 }
129         }
130 }
131
132 void Announcer()
133 {
134         Announcer_Gamestart();
135         Announcer_Time();
136 }