]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge branch 'master' into Mario/turrets
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / announcer.qc
1 #if defined(CSQC)
2         #include "../dpdefs/csprogsdefs.qh"
3     #include "../common/stats.qh"
4     #include "../common/util.qh"
5     #include "autocvars.qh"
6     #include "../common/notifications.qh"
7     #include "main.qh"
8 #elif defined(MENUQC)
9 #elif defined(SVQC)
10 #endif
11
12 bool announcer_1min;
13 bool announcer_5min;
14 void Announcer_Countdown()
15 {
16         float starttime = getstatf(STAT_GAMESTARTTIME);
17         float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
18         if(roundstarttime == -1)
19         {
20                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
21                 remove(self);
22                 return;
23         }
24         if(roundstarttime >= starttime)
25                 starttime = roundstarttime;
26         if(starttime <= time && roundstarttime != starttime) // game start time has passed
27                 announcer_5min = announcer_1min = false; // reset maptime announcers now as well
28
29         float countdown = (starttime - time);
30         float countdown_rounded = floor(0.5 + countdown);
31
32         if(countdown <= 0) // countdown has finished, starttime is now
33         {
34                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
35                 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
36                 remove(self);
37                 return;
38         }
39         else // countdown is still going
40         {
41                 // if concomitant countdown to round start overrides countdown to game start
42                 if(roundstarttime == starttime)
43                 {
44                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
45                         Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded));
46                 }
47                 else
48                 {
49                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
50                         Local_Notification(MSG_ANNCE, Announcer_PickNumber(CNT_GAMESTART, countdown_rounded));
51                 }
52
53                 self.nextthink = (starttime - (countdown - 1));
54         }
55 }
56
57 /**
58  * Checks whether the server initiated a map restart (stat_game_starttime changed)
59  *
60  * TODO: Use a better solution where a common shared entitiy is used that contains
61  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
62  * and STAT_FRAGLIMIT to be auto-sent)
63  */
64  float previous_game_starttime;
65 void Announcer_Gamestart()
66 {
67         float startTime = getstatf(STAT_GAMESTARTTIME);
68         float roundstarttime = getstatf(STAT_ROUNDSTARTTIME);
69         if(roundstarttime > startTime)
70                 startTime = roundstarttime;
71
72         if(previous_game_starttime != startTime)
73         {
74                 if(time < startTime)
75                 {
76                         entity e = find(world, classname, "announcer_countdown");
77                         if (!e)
78                         {
79                                 e = spawn();
80                                 e.classname = "announcer_countdown";
81                                 e.think = Announcer_Countdown;
82                         }
83
84                         if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
85                         if(time > e.nextthink) // don't play it again if countdown was already going
86                                 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
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(!(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(!(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 }