1 #include "round_handler.qh"
3 #include "command/vote.qh"
4 #include "../common/util.qh"
6 void round_handler_Think()
10 if (time < game_starttime)
12 round_handler_Reset(game_starttime);
18 round_handler_Reset(0);
19 round_handler_Remove();
26 this.cnt = this.count + 1; // init countdown
27 round_starttime = time + this.count;
31 if (this.cnt > 0) // countdown running
33 if (this.canRoundStart())
35 if (this.cnt == this.count + 1) round_starttime = time + this.count;
40 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
41 this.nextthink = time;
42 if (this.roundStart) this.roundStart();
45 this.cnt = this.cnt - 1;
49 round_handler_Reset(0);
51 this.nextthink = time + 1; // canRoundStart every second
55 if (this.canRoundEnd())
57 // schedule a new round
59 this.nextthink = time + this.delay;
63 this.nextthink = time; // canRoundEnd every frame
68 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
70 entity this = round_handler;
71 this.delay = (the_delay > 0) ? the_delay : 0;
72 this.count = fabs(floor(the_count));
73 this.cnt = this.count + 1;
74 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
77 // NOTE: this is only needed because if round_handler spawns at time 1
78 // gamestarttime isn't initialized yet
79 void round_handler_FirstThink()
82 round_starttime = max(time, game_starttime) + this.count;
83 this.think = round_handler_Think;
84 this.nextthink = max(time, game_starttime);
87 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
91 backtrace("Can't spawn round_handler again!");
94 entity this = round_handler = new(round_handler);
96 this.think = round_handler_FirstThink;
97 this.canRoundStart = canRoundStart_func;
98 this.canRoundEnd = canRoundEnd_func;
99 this.roundStart = roundStart_func;
101 round_handler_Init(5, 5, 180);
102 this.nextthink = time;
105 void round_handler_Reset(float next_think)
107 entity this = round_handler;
110 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
111 this.nextthink = next_think;
112 round_starttime = (next_think) ? (next_think + this.count) : -1;
115 void round_handler_Remove()
117 remove(round_handler);
118 round_handler = world;