1 #include "round_handler.qh"
4 #include "command/vote.qh"
5 #include "../common/util.qh"
7 void round_handler_Think(entity this)
9 if (intermission_running)
11 round_handler_Reset(0);
12 round_handler_Remove();
16 if (time < game_starttime)
18 round_handler_Reset(game_starttime);
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() && !(autocvar_g_campaign && !campaign_bots_may_start))
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;
64 this.nextthink = time; // canRoundEnd every frame
69 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
71 entity this = round_handler;
72 this.delay = (the_delay > 0) ? the_delay : 0;
73 this.count = fabs(floor(the_count));
74 this.cnt = this.count + 1;
75 this.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 // game_starttime isn't initialized yet
80 void round_handler_FirstThink(entity this)
82 round_starttime = max(time, game_starttime) + this.count;
83 setthink(this, round_handler_Think);
84 this.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 entity this = round_handler = new(round_handler);
96 setthink(this, round_handler_FirstThink);
97 this.canRoundStart = canRoundStart_func;
98 this.canRoundEnd = canRoundEnd_func;
99 this.roundStart = roundStart_func;
101 round_handler_Init(5, 5, 180);
102 this.nextthink = time;
105 void round_handler_Reset(float next_think)
107 entity this = round_handler;
110 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
111 this.nextthink = next_think;
112 round_starttime = (next_think) ? (next_think + this.count) : -1;
115 void round_handler_Remove()
117 delete(round_handler);
118 round_handler = NULL;