Xonotic
round_handler.qc
Go to the documentation of this file.
1 #include "round_handler.qh"
2 
4 #include <common/util.qh>
5 #include <server/campaign.qh>
6 #include <server/command/vote.qh>
7 #include <server/world.qh>
8 
10 {
12  {
15  return;
16  }
17 
18  if (time < game_starttime)
19  {
20  round_handler_Reset(game_starttime);
21  return;
22  }
23 
24  game_stopped = false;
25 
26  if (this.wait)
27  {
28  this.wait = false;
29  this.cnt = this.count + 1; // init countdown
30  round_starttime = time + this.count;
31  reset_map(true, false);
32  }
33 
34  if (this.cnt > 0) // countdown running
35  {
36  if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
37  {
38  if (this.cnt == this.count + 1) round_starttime = time + this.count;
39  int f = this.cnt - 1;
40  if (f == 0)
41  {
42  this.cnt = 0;
43  this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
44  this.nextthink = time;
45  if (this.roundStart) this.roundStart();
46  return;
47  }
48  this.cnt = this.cnt - 1;
49  }
50  else
51  {
53  round_starttime = -1; // can't start
54  }
55  this.nextthink = time + 1; // canRoundStart every second
56  }
57  else
58  {
59  if (this.canRoundEnd())
60  {
61  // schedule a new round
62  this.wait = true;
63  this.nextthink = time + this.delay;
64  }
65  else
66  {
67  this.nextthink = time; // canRoundEnd every frame
68  }
69  }
70 }
71 
72 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
73 {
74  entity this = round_handler;
75  this.delay = (the_delay > 0) ? the_delay : 0;
76  this.count = fabs(floor(the_count));
77  this.cnt = this.count + 1;
78  this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
79  round_limit = the_round_timelimit;
80 }
81 
82 // NOTE: this is only needed because if round_handler spawns at time 1
83 // game_starttime isn't initialized yet
85 {
86  round_starttime = max(time, game_starttime) + this.count;
88  this.nextthink = max(time, game_starttime);
89 }
90 
91 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
92 {
93  if (round_handler)
94  {
95  backtrace("Can't spawn round_handler again!");
96  return;
97  }
99 
101  this.canRoundStart = canRoundStart_func;
102  this.canRoundEnd = canRoundEnd_func;
103  this.roundStart = roundStart_func;
104  this.wait = false;
105  round_handler_Init(5, 5, 180);
106  this.nextthink = time;
107 }
108 
109 void round_handler_Reset(float next_think)
110 {
111  entity this = round_handler;
112  this.wait = false;
113  if (this.count)
114  if (this.cnt < this.count + 1) this.cnt = this.count + 1;
115  this.nextthink = next_think;
116  if (next_think)
117  round_starttime = next_think + this.count;
118 }
119 
121 {
122  delete(round_handler);
124 }
float round_endtime
void round_handler_Remove()
void round_handler_FirstThink(entity this)
void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
void round_handler_Think(entity this)
Definition: round_handler.qc:9
entity round_handler
Definition: round_handler.qh:3
entity() spawn
void reset_map(bool dorespawn, bool is_fake_round_start)
Definition: vote.qc:339
float cnt
Definition: powerups.qc:24
float round_timelimit
Definition: round_handler.qh:9
float wait
Definition: subs.qh:39
float delay
Definition: subs.qh:38
#define NULL
Definition: post.qh:17
#define backtrace(msg)
Definition: log.qh:105
void round_handler_Reset(float next_think)
float nextthink
Definition: csprogsdefs.qc:121
bool campaign_bots_may_start
campaign mode: bots shall spawn but wait for the player to spawn before they do anything in other gam...
Definition: campaign.qh:27
float count
Definition: powerups.qc:22
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define setthink(e, f)
bool intermission_running
Definition: intermission.qh:9
bool autocvar_g_campaign
Definition: campaign.qh:6
float time
Definition: csprogsdefs.qc:16
void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)