1 #include "round_handler.qh"
3 #include "command/vote.qh"
4 #include "../common/util.qh"
6 void round_handler_Think(entity this)
8 if (time < game_starttime)
10 round_handler_Reset(game_starttime);
16 round_handler_Reset(0);
17 round_handler_Remove();
24 this.cnt = this.count + 1; // init countdown
25 round_starttime = time + this.count;
29 if (this.cnt > 0) // countdown running
31 if (this.canRoundStart())
33 if (this.cnt == this.count + 1) round_starttime = time + this.count;
38 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
39 this.nextthink = time;
40 if (this.roundStart) this.roundStart();
43 this.cnt = this.cnt - 1;
47 round_handler_Reset(0);
49 this.nextthink = time + 1; // canRoundStart every second
53 if (this.canRoundEnd())
55 // schedule a new round
57 this.nextthink = time + this.delay;
61 this.nextthink = time; // canRoundEnd every frame
66 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
68 entity this = round_handler;
69 this.delay = (the_delay > 0) ? the_delay : 0;
70 this.count = fabs(floor(the_count));
71 this.cnt = this.count + 1;
72 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
75 // NOTE: this is only needed because if round_handler spawns at time 1
76 // gamestarttime isn't initialized yet
77 void round_handler_FirstThink(entity this)
79 round_starttime = max(time, game_starttime) + this.count;
80 setthink(this, round_handler_Think);
81 this.nextthink = max(time, game_starttime);
84 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
88 backtrace("Can't spawn round_handler again!");
91 entity this = round_handler = new(round_handler);
93 setthink(this, round_handler_FirstThink);
94 this.canRoundStart = canRoundStart_func;
95 this.canRoundEnd = canRoundEnd_func;
96 this.roundStart = roundStart_func;
98 round_handler_Init(5, 5, 180);
99 this.nextthink = time;
102 void round_handler_Reset(float next_think)
104 entity this = round_handler;
107 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
108 this.nextthink = next_think;
109 round_starttime = (next_think) ? (next_think + this.count) : -1;
112 void round_handler_Remove()
114 remove(round_handler);
115 round_handler = NULL;