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