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