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 (intermission_running)
13 round_handler_Reset(0);
14 round_handler_Remove();
18 if (time < game_starttime)
20 round_handler_Reset(game_starttime);
29 this.cnt = this.count + 1; // init countdown
30 round_starttime = time + this.count;
31 reset_map(true, false);
34 if (this.cnt > 0) // countdown running
36 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
38 if (this.cnt == this.count + 1) {
39 round_starttime = time + this.count;
46 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
47 this.nextthink = time;
48 if (this.roundStart) this.roundStart();
51 this.cnt = this.cnt - 1;
55 round_handler_Reset(0);
56 round_starttime = -1; // can't start
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;
82 round_limit = the_round_timelimit;
85 // NOTE: this is only needed because if round_handler spawns at time 1
86 // game_starttime isn't initialized yet
87 void round_handler_FirstThink(entity this)
89 round_starttime = max(time, game_starttime) + this.count;
90 setthink(this, round_handler_Think);
91 this.nextthink = max(time, game_starttime);
94 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
98 backtrace("Can't spawn round_handler again!");
101 entity this = round_handler = new_pure(round_handler);
103 setthink(this, round_handler_FirstThink);
104 this.canRoundStart = canRoundStart_func;
105 this.canRoundEnd = canRoundEnd_func;
106 this.roundStart = roundStart_func;
108 round_handler_Init(5, 5, 180);
109 this.nextthink = time;
112 void round_handler_Reset(float next_think)
114 entity this = round_handler;
117 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
118 this.nextthink = next_think;
120 round_starttime = next_think + this.count;
123 void round_handler_Remove()
125 delete(round_handler);
126 round_handler = NULL;