1 #include "round_handler.qh"
3 #include <common/mapobjects/triggers.qh>
4 #include <common/scores.qh>
5 #include <common/util.qh>
6 #include <server/campaign.qh>
7 #include <server/command/vote.qh>
8 #include <server/scores.qh>
9 #include <server/world.qh>
11 void round_handler_Think(entity this)
13 if (intermission_running)
15 round_handler_Reset(0);
16 round_handler_Remove();
20 if (time < game_starttime)
22 round_handler_Reset(game_starttime);
31 this.cnt = this.count + 1; // init countdown
32 round_starttime = time + this.count;
36 if (this.cnt > 0) // countdown running
38 if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start))
40 if (this.cnt == this.count + 1) round_starttime = time + this.count;
44 FOREACH_CLIENT((IS_PLAYER(it) || INGAME(it)), {
45 GameRules_scoring_add(it, ROUNDS_PL, 1);
48 this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
49 this.nextthink = time;
51 if (this.roundStart) this.roundStart();
54 this.cnt = this.cnt - 1;
58 round_handler_Reset(0);
59 round_starttime = -1; // can't start
61 this.nextthink = time + 1; // canRoundStart every second
65 if (this.canRoundEnd())
67 // schedule a new round
69 this.nextthink = time + this.delay;
70 round_handler_ResetEndDelayTime();
74 this.nextthink = time; // canRoundEnd every frame
79 void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
81 entity this = round_handler;
82 this.delay = (the_delay > 0) ? the_delay : 0;
83 this.count = fabs(floor(the_count));
84 this.cnt = this.count + 1;
85 this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
86 round_limit = the_round_timelimit;
89 // NOTE: this is only needed because if round_handler spawns at time 1
90 // game_starttime isn't initialized yet
91 void round_handler_FirstThink(entity this)
93 round_starttime = max(time, game_starttime) + this.count;
94 setthink(this, round_handler_Think);
95 this.nextthink = max(time, game_starttime);
98 void round_handler_Spawn(bool() canRoundStart_func, bool() canRoundEnd_func, void() roundStart_func)
102 backtrace("Can't spawn round_handler again!");
105 entity this = round_handler = new_pure(round_handler);
107 setthink(this, round_handler_FirstThink);
108 this.canRoundStart = canRoundStart_func;
109 this.canRoundEnd = canRoundEnd_func;
110 this.roundStart = roundStart_func;
112 round_handler_ResetEndDelayTime();
113 round_handler_Init(5, 5, 180);
114 this.nextthink = time;
116 ScoreInfo_SetLabel_PlayerScore(SP_ROUNDS_PL, "rounds_pl", 0);
119 void round_handler_Reset(float next_think)
121 entity this = round_handler;
123 round_handler_ResetEndDelayTime();
125 if (this.cnt < this.count + 1) this.cnt = this.count + 1;
126 this.nextthink = next_think;
129 if (next_think <= game_starttime) rounds_played = 0;
130 round_starttime = next_think + this.count;
134 void round_handler_Remove()
136 delete(round_handler);
137 round_handler = NULL;