Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
round_handler.qc
Go to the documentation of this file.
1#include "round_handler.qh"
2
4#include <common/scores.qh>
5#include <common/util.qh>
6#include <server/campaign.qh>
8#include <server/scores.qh>
9#include <server/world.qh>
10
12{
14 {
17 return;
18 }
19
20 if (time < game_starttime)
21 {
23 return;
24 }
25
26 game_stopped = false;
27
28 if (this.wait)
29 {
30 this.wait = false;
31 this.cnt = this.count + 1; // init countdown
32 round_starttime = time + this.count;
33 reset_map(false);
34 }
35
36 if (this.cnt > 0) // countdown running
37 {
38 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
39 {
40 if (this.cnt == this.count + 1) round_starttime = time + this.count;
41 int f = this.cnt - 1;
42 if (f == 0)
43 {
44 FOREACH_CLIENT((IS_PLAYER(it) || INGAME(it)), {
45 GameRules_scoring_add(it, ROUNDS_PL, 1);
46 });
47 this.cnt = 0;
48 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
49 this.nextthink = time;
51 if (this.roundStart) this.roundStart();
52 return;
53 }
54 this.cnt = this.cnt - 1;
55 }
56 else
57 {
59 round_starttime = -1; // can't start
60 }
61 this.nextthink = time + 1; // canRoundStart every second
62 }
63 else
64 {
65 if (this.canRoundEnd())
66 {
67 // schedule a new round
68 this.wait = true;
69 this.nextthink = time + this.delay;
71 }
72 else
73 {
74 this.nextthink = time; // canRoundEnd every frame
75 }
76 }
77}
78
79void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
80{
81 entity this = round_handler;
82 this.delay = (the_delay > 0) ? the_delay : 0;
83 this.count = fabs(floor(the_count));
84 this.cnt = this.count + 1;
85 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
86 round_limit = the_round_timelimit;
87}
88
89// NOTE: this is only needed because if round_handler spawns at time 1
90// game_starttime isn't initialized yet
97
98void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
99{
100 if (round_handler)
101 {
102 backtrace("Can't spawn round_handler again!");
103 return;
104 }
106
108 this.canRoundStart = canRoundStart_func;
109 this.canRoundEnd = canRoundEnd_func;
110 this.roundStart = roundStart_func;
111 this.wait = false;
113 round_handler_Init(5, 5, 180);
114 this.nextthink = time;
115
116 ScoreInfo_SetLabel_PlayerScore(SP_ROUNDS_PL, "rounds_pl", 0);
117}
118
119void round_handler_Reset(float next_think)
120{
121 entity this = round_handler;
122 this.wait = false;
124 if (this.count)
125 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
126 this.nextthink = next_think;
127 if (next_think)
128 {
129 if (next_think <= game_starttime) rounds_played = 0;
130 round_starttime = next_think + this.count;
131 }
132}
133
135{
136 delete(round_handler);
138}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
float count
Definition powerups.qc:22
float delay
Definition items.qc:17
float wait
Definition items.qc:17
#define IS_PLAYER(s)
Definition player.qh:243
float round_limit
Definition stats.qh:376
float round_starttime
Definition stats.qh:83
float game_starttime
Definition stats.qh:82
int rounds_played
Definition stats.qh:377
float game_stopped
Definition stats.qh:81
float time
float nextthink
bool intermission_running
#define backtrace(msg)
Definition log.qh:99
bool autocvar_g_campaign
Definition menu.qc:747
float fabs(float f)
float floor(float f)
float max(float f,...)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define NULL
Definition post.qh:14
void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
void round_handler_Remove()
void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
void round_handler_Reset(float next_think)
void round_handler_Think(entity this)
void round_handler_FirstThink(entity this)
float round_timelimit
entity round_handler
#define round_handler_ResetEndDelayTime()
float round_endtime
void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, int scoreflags)
Definition scores.qc:167
#define setthink(e, f)
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:26
void reset_map(bool is_fake_round_start)
Definition vote.qc:351
#define INGAME(it)
Definition sv_rules.qh:24
#define GameRules_scoring_add(client, fld, value)
Definition sv_rules.qh:85
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50