X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fround_handler.qc;h=70d2d144d984c5c3220c0d8da9cc7a9c25f159dc;hb=931a2648cb8ff8083a0af9ea06841d548e4d461b;hp=9f7f939dcca9982f51211cc9cf56026dfe5936b1;hpb=a6a1f0e6a1d9c6952cfe395c35bcd9983d10bfa4;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/round_handler.qc b/qcsrc/server/round_handler.qc index 9f7f939dc..70d2d144d 100644 --- a/qcsrc/server/round_handler.qc +++ b/qcsrc/server/round_handler.qc @@ -1,54 +1,59 @@ +#if defined(CSQC) +#elif defined(MENUQC) +#elif defined(SVQC) + #include "../dpdefs/progsdefs.qh" + #include "../dpdefs/dpextensions.qh" + #include "../common/util.qh" + #include "defs.qh" + #include "round_handler.qh" +#endif + void round_handler_Think() { - entity e; float f; - if(inWarmupStage || time < game_starttime) + if(time < game_starttime) { - self.nextthink = time + 1; + round_handler_Reset(game_starttime); return; } if(gameover) { - round_handler_ResetCountdown(); + round_handler_Reset(0); round_handler_Remove(); return; } if(self.wait) { - reset_map(TRUE); - self.wait = FALSE; + self.wait = false; self.cnt = self.count + 1; // init countdown + round_starttime = time + self.count; + reset_map(true); } if(self.cnt > 0) // countdown running { if(self.canRoundStart()) { + if(self.cnt == self.count + 1) + round_starttime = time + self.count; f = self.cnt - 1; - if(f == 5) Announce("prepareforbattle"); - else if(f == 3) Announce("3"); - else if(f == 2) Announce("2"); - else if(f == 1) Announce("1"); - else if(f == 0) + if(f == 0) { - Announce("begin"); - FOR_EACH_REALCLIENT(e) - Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0); self.cnt = 0; + self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0; self.nextthink = time; + if(self.roundStart) + self.roundStart(); return; } - - FOR_EACH_REALCLIENT(e) - Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d", 1, f); self.cnt = self.cnt - 1; } else { - round_handler_ResetCountdown(); + round_handler_Reset(0); } self.nextthink = time + 1; // canRoundStart every second } @@ -57,7 +62,7 @@ void round_handler_Think() if(self.canRoundEnd()) { // schedule a new round - self.wait = TRUE; + self.wait = true; self.nextthink = time + self.delay; } else @@ -67,7 +72,24 @@ void round_handler_Think() } } -void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count) +void round_handler_Init(float the_delay, float the_count, float the_round_timelimit) +{ + round_handler.delay = (the_delay > 0) ? the_delay : 0; + round_handler.count = fabs(floor(the_count)); + round_handler.cnt = round_handler.count + 1; + round_handler.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0; +} + +// NOTE: this is only needed because if round_handler spawns at time 1 +// gamestarttime isn't initialized yet +void round_handler_FirstThink() +{ + round_starttime = max(time, game_starttime) + round_handler.count; + round_handler.think = round_handler_Think; + round_handler.nextthink = max(time, game_starttime); +} + +void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func) { if(round_handler) { @@ -77,46 +99,23 @@ void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, f round_handler = spawn(); round_handler.classname = "round_handler"; - round_handler.think = round_handler_Think; + round_handler.think = round_handler_FirstThink; round_handler.canRoundStart = canRoundStart_func; round_handler.canRoundEnd = canRoundEnd_func; - round_handler.delay = (the_delay > 0) ? the_delay : 0; - round_handler.count = fabs(floor(the_count)); - round_handler.wait = FALSE; - round_handler.cnt = round_handler.count + 1; + round_handler.roundStart = roundStart_func; + round_handler.wait = false; + round_handler_Init(5, 5, 180); round_handler.nextthink = time; } -float round_handler_IsActive() -{ - return (round_handler && !inWarmupStage && time > game_starttime); -} - -float round_handler_AwaitingNextRound() +void round_handler_Reset(float next_think) { - return (round_handler.wait); -} - -float round_handler_CountdownRunning() -{ - return (!round_handler.wait && round_handler.cnt); -} - -float round_handler_IsRoundStarted() -{ - return (!round_handler.wait && !round_handler.cnt); -} - -void round_handler_ResetCountdown() -{ - entity e; + round_handler.wait = false; if(round_handler.count) if(round_handler.cnt < round_handler.count + 1) - { - FOR_EACH_REALCLIENT(e) - Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING); round_handler.cnt = round_handler.count + 1; - } + round_handler.nextthink = next_think; + round_starttime = (next_think) ? (next_think + round_handler.count) : -1; } void round_handler_Remove()