1 #include "round_handler.qh"
3 #include <common/mapobjects/triggers.qh>
4 #include <common/util.qh>
5 #include <server/campaign.qh>
6 #include <server/command/vote.qh>
7 #include <server/world.qh>
9 void round_handler_Think(entity this)
11 if (!this.isactive) return;
12 if (game_timeout) { this.nextthink = time + 1; return; }
14 if (intermission_running)
16 round_handler_Reset(0);
17 round_handler_Remove();
21 if (time < game_starttime)
23 round_handler_Reset(game_starttime);
32 this.cnt = this.count + 1; // init countdown
33 round_starttime = time + this.count;
34 reset_map(true, false);
37 if (this.cnt > 0) // countdown running
39 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
41 if (this.cnt == this.count + 1) round_starttime = time + this.count;
46 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
47 this.nextthink = time;
48 FOREACH_CLIENT(IS_PLAYER(it), { roundaccuracy_clear(it); });
49 if (this.roundStart) this.roundStart();
52 this.cnt = this.cnt - 1;
56 round_handler_Reset(0);
58 this.nextthink = time + 1; // canRoundStart every second
62 if (this.canRoundEnd())
64 // schedule a new round
66 this.nextthink = time + this.delay;
70 this.nextthink = time; // canRoundEnd every frame
75 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
77 entity this = round_handler;
78 this.delay = (the_delay > 0) ? the_delay : 0;
79 this.count = fabs(floor(the_count));
80 this.cnt = this.count + 1;
81 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
84 // NOTE: this is only needed because if round_handler spawns at time 1
85 // game_starttime isn't initialized yet
86 void round_handler_FirstThink(entity this)
88 round_starttime = max(time, game_starttime) + this.count;
89 setthink(this, round_handler_Think);
90 this.nextthink = max(time, game_starttime);
93 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
97 backtrace("Can't spawn round_handler again!");
100 entity this = round_handler = new_pure(round_handler);
102 this.canRoundStart = canRoundStart_func;
103 this.canRoundEnd = canRoundEnd_func;
104 this.roundStart = roundStart_func;
106 round_handler_Init(5, 5, 180);
109 void round_handler_Activate(bool active) {
111 entity this = round_handler;
113 this.isactive = active;
115 setthink(this, round_handler_FirstThink);
116 this.nextthink = time;
118 round_starttime = -1;
123 void round_handler_Reset(float next_think)
125 entity this = round_handler;
128 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
129 this.nextthink = next_think;
130 round_starttime = (next_think) ? (next_think + this.count) : -1;
133 void round_handler_Remove()
135 delete(round_handler);
136 round_handler = NULL;