Xonotic
announcer.qc
Go to the documentation of this file.
1 #include "announcer.qh"
2 
6 #include <common/stats.qh>
7 
11 {
12  string ret = autocvar_cl_announcer;
14  ret = M_ARGV(0, string);
15  return ret;
16 }
17 
19 
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);
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);
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 
74 {
75  float startTime = STAT(GAMESTARTTIME);
76  float roundstarttime = STAT(ROUNDSTARTTIME);
77  if(roundstarttime > startTime)
78  startTime = roundstarttime;
79  if(intermission)
80  {
82  {
83  centerprint_Kill(ORDINAL(CPID_ROUND));
85  {
86  delete(announcer_countdown);
88  }
89  }
90  return;
91  }
92 
93  if(previous_game_starttime != startTime)
94  {
95  if(time < startTime)
96  {
98  {
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 
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 
161 
164 }
165 
166 void Announcer()
167 {
169  Announcer_Time();
170 }
void centerprint_Kill(int id)
Definition: centerprint.qc:126
#define ORDINAL(it)
Definition: enumclass.qh:25
entity announcer_countdown
Definition: announcer.qc:18
entity() spawn
float intermission
Definition: csprogsdefs.qc:148
bool warmup_stage
Definition: main.qh:103
void Announcer()
Definition: announcer.qc:166
bool announcer_1min
Definition: announcer.qc:8
void Announcer_Time()
Definition: announcer.qc:126
bool announcer_5min
Definition: announcer.qc:9
float previous_game_starttime
Checks whether the server initiated a map restart (stat_game_starttime changed)
Definition: announcer.qc:72
void Announcer_Gamestart()
Definition: announcer.qc:73
#define NULL
Definition: post.qh:17
#define M_ARGV(x, type)
Definition: events.qh:17
string autocvar_cl_announcer
Definition: announcer.qh:3
float nextthink
Definition: csprogsdefs.qc:121
void Announcer_Countdown(entity this)
Definition: announcer.qc:20
entity Notification
always last
Definition: all.qh:82
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
string AnnouncerOption()
Definition: announcer.qc:10
#define setthink(e, f)
float autocvar_cl_announcer_maptime
Definition: announcer.qh:5
void Local_Notification(MSG net_type, Notification net_name,...count)
Definition: all.qc:1185
float time
Definition: csprogsdefs.qc:16
float starttime
Definition: strafehud.qc:38
#define ANNOUNCER_CHECKMINUTE(minute)
Definition: announcer.qc:114