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