1 #include "round_handler.qh"
4 #include "command/vote.qh"
5 #include "../common/util.qh"
7 void round_handler_Think()
11 if(time < game_starttime)
13 round_handler_Reset(game_starttime);
19 round_handler_Reset(0);
20 round_handler_Remove();
27 self.cnt = self.count + 1; // init countdown
28 round_starttime = time + self.count;
32 if(self.cnt > 0) // countdown running
34 if(self.canRoundStart())
36 if(self.cnt == self.count + 1)
37 round_starttime = time + self.count;
42 self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0;
43 self.nextthink = time;
48 self.cnt = self.cnt - 1;
52 round_handler_Reset(0);
54 self.nextthink = time + 1; // canRoundStart every second
58 if(self.canRoundEnd())
60 // schedule a new round
62 self.nextthink = time + self.delay;
66 self.nextthink = time; // canRoundEnd every frame
71 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
73 round_handler.delay = (the_delay > 0) ? the_delay : 0;
74 round_handler.count = fabs(floor(the_count));
75 round_handler.cnt = round_handler.count + 1;
76 round_handler.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()
83 round_starttime = max(time, game_starttime) + round_handler.count;
84 round_handler.think = round_handler_Think;
85 round_handler.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 round_handler = spawn();
96 round_handler.classname = "round_handler";
98 round_handler.think = round_handler_FirstThink;
99 round_handler.canRoundStart = canRoundStart_func;
100 round_handler.canRoundEnd = canRoundEnd_func;
101 round_handler.roundStart = roundStart_func;
102 round_handler.wait = false;
103 round_handler_Init(5, 5, 180);
104 round_handler.nextthink = time;
107 void round_handler_Reset(float next_think)
109 round_handler.wait = false;
110 if(round_handler.count)
111 if(round_handler.cnt < round_handler.count + 1)
112 round_handler.cnt = round_handler.count + 1;
113 round_handler.nextthink = next_think;
114 round_starttime = (next_think) ? (next_think + round_handler.count) : -1;
117 void round_handler_Remove()
119 remove(round_handler);
120 round_handler = world;