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