]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge branch 'terencehill/hide_motd' 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 = getstatf(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 = getstatf(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                         entity e = find(world, classname, "announcer_countdown");
82                         if (!e)
83                         {
84                                 e = spawn();
85                                 e.classname = "announcer_countdown";
86                                 e.think = Announcer_Countdown;
87                         }
88
89                         if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
90                         if(time > e.nextthink) // don't play it again if countdown was already going
91                                 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
92
93                         e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
94                 }
95         }
96
97         previous_game_starttime = startTime;
98 }
99
100
101 // Plays the 1 minute or 5 minutes (of maptime) remaining sound, if client wants it
102 void Announcer_Time()
103 {
104         float timelimit = getstatf(STAT_TIMELIMIT);
105         float timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
106         float warmup_timeleft = 0;
107
108         if(warmup_stage)
109                 if(autocvar_g_warmup_limit > 0)
110                         warmup_timeleft = max(0, autocvar_g_warmup_limit + getstatf(STAT_GAMESTARTTIME) - time);
111
112         // 5 minute check
113         if(autocvar_cl_announcer_maptime >= 2)
114         {
115                 // make sure that after connect (and e.g. 4 minutes left) we will not get a wrong sound
116                 if(announcer_5min)
117                 {
118                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 300)
119                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 300))
120                                         announcer_5min = false;
121                 }
122                 else
123                 {
124                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 300 && timeleft > 299)
125                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 300 && warmup_timeleft > 299))
126                         {
127                                 //if we're in warmup mode, check whether there's a warmup timelimit
128                                 if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
129                                 {
130                                         announcer_5min = true;
131                                         Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_5);
132                                 }
133                         }
134                 }
135         }
136
137         // 1 minute check
138         if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
139         {
140                 if (announcer_1min)
141                 {
142                         if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timeleft > 60)
143                                 || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft > 60))
144                                         announcer_1min = false;
145                 }
146                 else if(((!warmup_stage || autocvar_g_warmup_limit == 0) && timelimit > 0 && timeleft < 60)
147                         || (warmup_stage && autocvar_g_warmup_limit > 0 && warmup_timeleft < 60))
148                 {
149                         // if we're in warmup mode, check whether there's a warmup timelimit
150                         if(!(autocvar_g_warmup_limit == -1 && warmup_stage))
151                         {
152                                 announcer_1min = true;
153                                 Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_1);
154                         }
155                 }
156         }
157 }
158
159 void Announcer()
160 {
161         Announcer_Gamestart();
162         Announcer_Time();
163 }