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