1 #include "round_handler.qh"
3 #include <common/mapobjects/triggers.qh>
4 #include <common/util.qh>
5 #include <server/campaign.qh>
6 #include <server/command/vote.qh>
7 #include <server/world.qh>
9 void round_handler_Think(entity this)
11 if (intermission_running)
13 round_handler_Reset(0);
14 round_handler_Remove();
18 if (time < game_starttime)
20 round_handler_Reset(game_starttime);
29 this.cnt = this.count + 1; // init countdown
30 round_starttime = time + this.count;
31 reset_map(true, false);
34 if (this.cnt > 0) // countdown running
36 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
38 if (this.cnt == this.count + 1) round_starttime = time + this.count;
43 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
44 this.nextthink = time;
45 if (this.roundStart) this.roundStart();
48 this.cnt = this.cnt - 1;
52 round_handler_Reset(0);
53 round_starttime = -1; // can't start
55 this.nextthink = time + 1; // canRoundStart every second
59 if (this.canRoundEnd())
61 // schedule a new round
63 this.nextthink = time + this.delay;
67 this.nextthink = time; // canRoundEnd every frame
72 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
74 entity this = round_handler;
75 this.delay = (the_delay > 0) ? the_delay : 0;
76 this.count = fabs(floor(the_count));
77 this.cnt = this.count + 1;
78 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
79 round_limit = the_round_timelimit;
82 // NOTE: this is only needed because if round_handler spawns at time 1
83 // game_starttime isn't initialized yet
84 void round_handler_FirstThink(entity this)
86 round_starttime = max(time, game_starttime) + this.count;
87 setthink(this, round_handler_Think);
88 this.nextthink = max(time, game_starttime);
91 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
95 backtrace("Can't spawn round_handler again!");
98 entity this = round_handler = new_pure(round_handler);
100 setthink(this, round_handler_FirstThink);
101 this.canRoundStart = canRoundStart_func;
102 this.canRoundEnd = canRoundEnd_func;
103 this.roundStart = roundStart_func;
105 round_handler_Init(5, 5, 180);
106 this.nextthink = time;
109 void round_handler_Reset(float next_think)
111 entity this = round_handler;
114 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
115 this.nextthink = next_think;
117 round_starttime = next_think + this.count;
120 void round_handler_Remove()
122 delete(round_handler);
123 round_handler = NULL;