]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/announcer.qc
Merge branch 'bones_was_here/walking_groundentity_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / announcer.qc
1 #include "announcer.qh"
2
3 #include <client/hud/panel/centerprint.qh>
4 #include <client/mutators/_mod.qh>
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 = M_ARGV(0, string);
15         return ret;
16 }
17
18 entity announcer_countdown;
19
20 void Announcer_Countdown(entity this)
21 {
22         float starttime = STAT(GAMESTARTTIME);
23         float roundstarttime = STAT(ROUNDSTARTTIME);
24         if(roundstarttime == -1)
25         {
26                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP);
27                 delete(this);
28                 announcer_countdown = NULL;
29                 return;
30         }
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         bool inround = (roundstarttime && time >= starttime);
35         float countdown = (inround ? roundstarttime - time : starttime - time);
36         float countdown_rounded = floor(0.5 + countdown);
37
38         if(countdown <= 0) // countdown has finished, starttime is now
39         {
40                 Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN);
41                 Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN);
42                 delete(this);
43                 announcer_countdown = NULL;
44                 return;
45         }
46         else // countdown is still going
47         {
48                 if(inround)
49                 {
50                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded);
51                         Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded);
52                         if(annce_num != NULL)
53                                 Local_Notification(MSG_ANNCE, annce_num);
54                         this.nextthink = (roundstarttime - (countdown - 1));
55                 }
56                 else
57                 {
58                         Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded);
59                         Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded);
60                         if(!roundstarttime && annce_num != NULL) // Don't announce game start in round based modes
61                                 Local_Notification(MSG_ANNCE, annce_num);
62                         this.nextthink = (starttime - (countdown - 1));
63                 }
64         }
65 }
66
67 /**
68  * Checks whether the server initiated a map restart (stat_game_starttime changed)
69  *
70  * TODO: Use a better solution where a common shared entitiy is used that contains
71  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
72  * and STAT_FRAGLIMIT to be auto-sent)
73  */
74  float previous_game_starttime;
75 void Announcer_Gamestart()
76 {
77         float startTime = STAT(GAMESTARTTIME);
78         float roundstarttime = STAT(ROUNDSTARTTIME);
79         if(roundstarttime > startTime)
80                 startTime = roundstarttime;
81         if(intermission)
82         {
83                 if(announcer_countdown)
84                 {
85                         centerprint_Kill(ORDINAL(CPID_ROUND));
86                         if(announcer_countdown)
87                         {
88                                 delete(announcer_countdown);
89                                 announcer_countdown = NULL;
90                         }
91                 }
92                 return;
93         }
94
95         if(previous_game_starttime != startTime)
96         {
97                 if(time < startTime)
98                 {
99                         if (!announcer_countdown)
100                         {
101                                 announcer_countdown = new(announcer_countdown);
102                                 setthink(announcer_countdown, Announcer_Countdown);
103                         }
104
105                         if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle
106                         if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going
107                                 Local_Notification(MSG_ANNCE, ANNCE_PREPARE);
108
109                         announcer_countdown.nextthink = startTime - floor(startTime - time + 0.5); //synchronize nextthink to startTime
110                 }
111         }
112
113         previous_game_starttime = startTime;
114 }
115
116 #define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \
117         if(announcer_##minute##min) { \
118                 if(timeleft > minute * 60) \
119                         announcer_##minute##min = false; \
120         } else { \
121                 if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \
122                         announcer_##minute##min = true; \
123                         Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \
124                 } \
125         } \
126 MACRO_END
127
128 void Announcer_Time()
129 {
130         if(intermission)
131                 return;
132
133         float timeleft;
134         if(warmup_stage)
135         {
136                 float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
137                 if(warmup_timelimit > 0)
138                         timeleft = max(0, warmup_timelimit - time);
139                 else
140                         timeleft = 0;
141         }
142         else
143                 timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time);
144
145         if(autocvar_cl_announcer_maptime >= 2)
146                 ANNOUNCER_CHECKMINUTE(5);
147
148         if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3))
149                 ANNOUNCER_CHECKMINUTE(1);
150 }
151
152 void Announcer()
153 {
154         Announcer_Gamestart();
155         Announcer_Time();
156 }