1 #include "round_handler.qh"
4 #include "command/vote.qh"
5 #include "../common/util.qh"
7 void round_handler_Think(entity this)
9 if (time < game_starttime)
11 round_handler_Reset(game_starttime);
17 round_handler_Reset(0);
18 round_handler_Remove();
25 this.cnt = this.count + 1; // init countdown
26 round_starttime = time + this.count;
30 if (this.cnt > 0) // countdown running
32 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
34 if (this.cnt == this.count + 1) round_starttime = time + this.count;
39 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
40 this.nextthink = time;
41 if (this.roundStart) this.roundStart();
44 this.cnt = this.cnt - 1;
48 round_handler_Reset(0);
50 this.nextthink = time + 1; // canRoundStart every second
54 if (this.canRoundEnd())
56 // schedule a new round
58 this.nextthink = time + this.delay;
62 this.nextthink = time; // canRoundEnd every frame
67 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
69 entity this = round_handler;
70 this.delay = (the_delay > 0) ? the_delay : 0;
71 this.count = fabs(floor(the_count));
72 this.cnt = this.count + 1;
73 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
76 // NOTE: this is only needed because if round_handler spawns at time 1
77 // gamestarttime isn't initialized yet
78 void round_handler_FirstThink(entity this)
80 round_starttime = max(time, game_starttime) + this.count;
81 setthink(this, round_handler_Think);
82 this.nextthink = max(time, game_starttime);
85 void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
89 backtrace("Can't spawn round_handler again!");
92 entity this = round_handler = new(round_handler);
94 setthink(this, round_handler_FirstThink);
95 this.canRoundStart = canRoundStart_func;
96 this.canRoundEnd = canRoundEnd_func;
97 this.roundStart = roundStart_func;
99 round_handler_Init(5, 5, 180);
100 this.nextthink = time;
103 void round_handler_Reset(float next_think)
105 entity this = round_handler;
108 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
109 this.nextthink = next_think;
110 round_starttime = (next_think) ? (next_think + this.count) : -1;
113 void round_handler_Remove()
115 delete(round_handler);
116 round_handler = NULL;