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