4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../common/util.qh"
8 #include "round_handler.qh"
11 void round_handler_Think()
15 if(time < game_starttime)
17 round_handler_Reset(game_starttime);
23 round_handler_Reset(0);
24 round_handler_Remove();
31 self.cnt = self.count + 1; // init countdown
32 round_starttime = time + self.count;
36 if(self.cnt > 0) // countdown running
38 if(self.canRoundStart())
40 if(self.cnt == self.count + 1)
41 round_starttime = time + self.count;
46 self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0;
47 self.nextthink = time;
52 self.cnt = self.cnt - 1;
56 round_handler_Reset(0);
58 self.nextthink = time + 1; // canRoundStart every second
62 if(self.canRoundEnd())
64 // schedule a new round
66 self.nextthink = time + self.delay;
70 self.nextthink = time; // canRoundEnd every frame
75 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
77 round_handler.delay = (the_delay > 0) ? the_delay : 0;
78 round_handler.count = fabs(floor(the_count));
79 round_handler.cnt = round_handler.count + 1;
80 round_handler.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
83 // NOTE: this is only needed because if round_handler spawns at time 1
84 // gamestarttime isn't initialized yet
85 void round_handler_FirstThink()
87 round_starttime = max(time, game_starttime) + round_handler.count;
88 round_handler.think = round_handler_Think;
89 round_handler.nextthink = max(time, game_starttime);
92 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
96 backtrace("Can't spawn round_handler again!");
99 round_handler = spawn();
100 round_handler.classname = "round_handler";
102 round_handler.think = round_handler_FirstThink;
103 round_handler.canRoundStart = canRoundStart_func;
104 round_handler.canRoundEnd = canRoundEnd_func;
105 round_handler.roundStart = roundStart_func;
106 round_handler.wait = false;
107 round_handler_Init(5, 5, 180);
108 round_handler.nextthink = time;
111 void round_handler_Reset(float next_think)
113 round_handler.wait = false;
114 if(round_handler.count)
115 if(round_handler.cnt < round_handler.count + 1)
116 round_handler.cnt = round_handler.count + 1;
117 round_handler.nextthink = next_think;
118 round_starttime = (next_think) ? (next_think + round_handler.count) : -1;
121 void round_handler_Remove()
123 remove(round_handler);
124 round_handler = world;