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 self.cnt = self.count + 1; // init countdown
27 round_starttime = time + self.count;
31 if(self.cnt > 0) // countdown running
33 if(self.canRoundStart())
35 if(self.cnt == self.count + 1)
36 round_starttime = time + self.count;
41 self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0;
42 self.nextthink = time;
47 self.cnt = self.cnt - 1;
51 round_handler_Reset(0);
53 self.nextthink = time + 1; // canRoundStart every second
57 if(self.canRoundEnd())
59 // schedule a new round
61 self.nextthink = time + self.delay;
65 self.nextthink = time; // canRoundEnd every frame
70 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
72 round_handler.delay = (the_delay > 0) ? the_delay : 0;
73 round_handler.count = fabs(floor(the_count));
74 round_handler.cnt = round_handler.count + 1;
75 round_handler.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
78 // NOTE: this is only needed because if round_handler spawns at time 1
79 // gamestarttime isn't initialized yet
80 void round_handler_FirstThink()
82 round_starttime = max(time, game_starttime) + round_handler.count;
83 round_handler.think = round_handler_Think;
84 round_handler.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 round_handler = spawn();
95 round_handler.classname = "round_handler";
97 round_handler.think = round_handler_FirstThink;
98 round_handler.canRoundStart = canRoundStart_func;
99 round_handler.canRoundEnd = canRoundEnd_func;
100 round_handler.roundStart = roundStart_func;
101 round_handler.wait = false;
102 round_handler_Init(5, 5, 180);
103 round_handler.nextthink = time;
106 void round_handler_Reset(float next_think)
108 round_handler.wait = false;
109 if(round_handler.count)
110 if(round_handler.cnt < round_handler.count + 1)
111 round_handler.cnt = round_handler.count + 1;
112 round_handler.nextthink = next_think;
113 round_starttime = (next_think) ? (next_think + round_handler.count) : -1;
116 void round_handler_Remove()
118 remove(round_handler);
119 round_handler = world;