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