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);
17 if (intermission_running)
19 round_handler_Reset(0);
20 round_handler_Remove();
27 this.cnt = this.count + 1; // init countdown
28 round_starttime = time + this.count;
32 if (this.cnt > 0) // countdown running
34 if (this.canRoundStart())
36 if (this.cnt == this.count + 1) round_starttime = time + this.count;
41 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
42 this.nextthink = time;
43 if (this.roundStart) this.roundStart();
46 this.cnt = this.cnt - 1;
50 round_handler_Reset(0);
52 this.nextthink = time + 1; // canRoundStart every second
56 if (this.canRoundEnd())
58 // schedule a new round
60 this.nextthink = time + this.delay;
65 this.nextthink = time; // canRoundEnd every frame
70 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
72 entity this = round_handler;
73 this.delay = (the_delay > 0) ? the_delay : 0;
74 this.count = fabs(floor(the_count));
75 this.cnt = this.count + 1;
76 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
79 // NOTE: this is only needed because if round_handler spawns at time 1
80 // gamestarttime isn't initialized yet
81 void round_handler_FirstThink(entity this)
83 round_starttime = max(time, game_starttime) + this.count;
84 setthink(this, round_handler_Think);
85 this.nextthink = max(time, game_starttime);
88 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
92 backtrace("Can't spawn round_handler again!");
95 entity this = round_handler = new(round_handler);
97 setthink(this, round_handler_FirstThink);
98 this.canRoundStart = canRoundStart_func;
99 this.canRoundEnd = canRoundEnd_func;
100 this.roundStart = roundStart_func;
102 round_handler_Init(5, 5, 180);
103 this.nextthink = time;
106 void round_handler_Reset(float next_think)
108 entity this = round_handler;
111 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
112 this.nextthink = next_think;
113 round_starttime = (next_think) ? (next_think + this.count) : -1;
116 void round_handler_Remove()
118 delete(round_handler);
119 round_handler = NULL;