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