1 #include "round_handler.qh"
3 #include <server/world.qh>
4 #include <server/miscfunctions.qh>
6 #include "command/vote.qh"
7 #include <common/mapobjects/triggers.qh>
8 #include "../common/util.qh"
10 void round_handler_Think(entity this)
12 if (intermission_running)
14 round_handler_Reset(0);
15 round_handler_Remove();
19 if (time < game_starttime)
21 round_handler_Reset(game_starttime);
30 this.cnt = this.count + 1; // init countdown
31 round_starttime = time + this.count;
35 if (this.cnt > 0) // countdown running
37 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
39 if (this.cnt == this.count + 1) round_starttime = time + this.count;
44 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
45 this.nextthink = time;
46 if (this.roundStart) this.roundStart();
49 this.cnt = this.cnt - 1;
53 round_handler_Reset(0);
55 this.nextthink = time + 1; // canRoundStart every second
59 if (this.canRoundEnd())
61 // schedule a new round
63 this.nextthink = time + this.delay;
67 this.nextthink = time; // canRoundEnd every frame
72 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
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;
81 // NOTE: this is only needed because if round_handler spawns at time 1
82 // game_starttime isn't initialized yet
83 void round_handler_FirstThink(entity this)
85 round_starttime = max(time, game_starttime) + this.count;
86 setthink(this, round_handler_Think);
87 this.nextthink = max(time, game_starttime);
90 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
94 backtrace("Can't spawn round_handler again!");
97 entity this = round_handler = new(round_handler);
99 setthink(this, round_handler_FirstThink);
100 this.canRoundStart = canRoundStart_func;
101 this.canRoundEnd = canRoundEnd_func;
102 this.roundStart = roundStart_func;
104 round_handler_Init(5, 5, 180);
105 this.nextthink = time;
108 void round_handler_Reset(float next_think)
110 entity this = round_handler;
113 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
114 this.nextthink = next_think;
115 round_starttime = (next_think) ? (next_think + this.count) : -1;
118 void round_handler_Remove()
120 delete(round_handler);
121 round_handler = NULL;