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