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/weapons/accuracy.qh>
8 #include <server/world.qh>
10 void round_handler_Think(entity this)
12 if (!this.isactive) return;
13 if (game_timeout) { this.nextthink = time + 1; return; }
15 if (intermission_running)
17 round_handler_Reset(0);
18 round_handler_Remove();
22 if (time < game_starttime)
24 round_handler_Reset(game_starttime);
33 this.cnt = this.count + 1; // init countdown
34 round_starttime = time + this.count;
36 reset_map(true, false);
39 if (this.cnt > 0) // countdown running
41 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
43 if (this.cnt == this.count + 1) round_starttime = time + this.count;
48 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
49 this.nextthink = time;
50 FOREACH_CLIENT(IS_PLAYER(it), { roundaccuracy_clear(it); });
52 if (this.roundStart) this.roundStart();
55 this.cnt = this.cnt - 1;
59 round_handler_Reset(0);
60 round_starttime = -1; // can't start
62 this.nextthink = time + 1; // canRoundStart every second
66 if (this.canRoundEnd())
68 // schedule a new round
69 round_delaytime = time;
71 this.nextthink = time + this.delay;
75 this.nextthink = time; // canRoundEnd every frame
80 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
82 entity this = round_handler;
83 this.delay = (the_delay > 0) ? the_delay : 0;
84 this.count = fabs(floor(the_count));
85 this.cnt = this.count + 1;
86 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
87 round_limit = the_round_timelimit;
90 // NOTE: this is only needed because if round_handler spawns at time 1
91 // game_starttime isn't initialized yet
92 void round_handler_FirstThink(entity this)
94 round_starttime = max(time, game_starttime) + this.count;
95 setthink(this, round_handler_Think);
96 this.nextthink = max(time, game_starttime);
99 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
103 backtrace("Can't spawn round_handler again!");
106 entity this = round_handler = new_pure(round_handler);
108 this.canRoundStart = canRoundStart_func;
109 this.canRoundEnd = canRoundEnd_func;
110 this.roundStart = roundStart_func;
112 round_handler_Init(5, 5, 180);
115 void round_handler_Activate(bool active) {
117 entity this = round_handler;
119 this.isactive = active;
121 setthink(this, round_handler_FirstThink);
122 this.nextthink = time;
124 round_starttime = -1;
129 void round_handler_Reset(float next_think)
131 entity this = round_handler;
134 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
135 this.nextthink = next_think;
138 if (next_think <= game_starttime) rounds_played = 0;
139 round_starttime = next_think + this.count;
143 void round_handler_Remove()
145 delete(round_handler);
146 round_handler = NULL;