From 53bf2689427e11616d100949df37f463426ef78f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 15 Oct 2015 02:27:25 +1000 Subject: [PATCH] Move some race related stuff out of the main physics function --- qcsrc/common/physics.qc | 60 -------------------------- qcsrc/server/mutators/gamemode_cts.qc | 47 ++++++++++++++++++++ qcsrc/server/mutators/gamemode_race.qc | 46 ++++++++++++++++++++ qcsrc/server/race.qh | 3 ++ 4 files changed, 96 insertions(+), 60 deletions(-) diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 54a700205..b3954d2ee 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -975,17 +975,6 @@ void SpecialCommand() #endif } -void PM_check_race_movetime(void) -{SELFPARAM(); -#ifdef SVQC - self.race_movetime_frac += PHYS_INPUT_TIMELENGTH; - float f = floor(self.race_movetime_frac); - self.race_movetime_frac -= f; - self.race_movetime_count += f; - self.race_movetime = self.race_movetime_frac + self.race_movetime_count; -#endif -} - float PM_check_specialcommand(float buttons) {SELFPARAM(); #ifdef SVQC @@ -1145,40 +1134,6 @@ void PM_check_blocked(void) #endif } -#ifdef SVQC -float speedaward_lastsent; -float speedaward_lastupdate; -#endif -void PM_check_race(void) -{SELFPARAM(); -#ifdef SVQC - if(!(g_cts || g_race)) - return; - if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) - { - speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1'); - speedaward_holder = self.netname; - speedaward_uid = self.crypto_idfp; - speedaward_lastupdate = time; - } - if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) - { - string rr = (g_cts) ? CTS_RECORD : RACE_RECORD; - race_send_speedaward(MSG_ALL); - speedaward_lastsent = speedaward_speed; - if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") - { - speedaward_alltimebest = speedaward_speed; - speedaward_alltimebest_holder = speedaward_holder; - speedaward_alltimebest_uid = speedaward_uid; - db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest)); - db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid); - race_send_speedaward_alltimebest(MSG_ALL); - } - } -#endif -} - void PM_check_vortex(void) {SELFPARAM(); #ifdef SVQC @@ -1675,7 +1630,6 @@ void PM_Main() return; #endif - PM_check_race_movetime(); #ifdef SVQC anticheat_physics(); #endif @@ -1708,17 +1662,7 @@ void PM_Main() if (IS_PLAYER(self)) #endif { -#ifdef SVQC - if (self.race_penalty) - if (time > self.race_penalty) - self.race_penalty = 0; -#endif - bool not_allowed_to_move = false; -#ifdef SVQC - if (self.race_penalty) - not_allowed_to_move = true; -#endif #ifdef SVQC if (time < game_starttime) not_allowed_to_move = true; @@ -1893,10 +1837,6 @@ void PM_Main() else PM_air(buttons_prev, maxspeed_mod); -#ifdef SVQC - if (!IS_OBSERVER(self)) - PM_check_race(); -#endif PM_check_vortex(); :end diff --git a/qcsrc/server/mutators/gamemode_cts.qc b/qcsrc/server/mutators/gamemode_cts.qc index a45367afa..679bbb094 100644 --- a/qcsrc/server/mutators/gamemode_cts.qc +++ b/qcsrc/server/mutators/gamemode_cts.qc @@ -71,6 +71,27 @@ void CTS_ClientKill(entity e) // silent version of ClientKill, used when player MUTATOR_HOOKFUNCTION(cts, PlayerPhysics) {SELFPARAM(); + self.race_movetime_frac += PHYS_INPUT_TIMELENGTH; + float f = floor(self.race_movetime_frac); + self.race_movetime_frac -= f; + self.race_movetime_count += f; + self.race_movetime = self.race_movetime_frac + self.race_movetime_count; + +#ifdef SVQC + if(IS_PLAYER(self)) + { + if (self.race_penalty) + if (time > self.race_penalty) + self.race_penalty = 0; + if(self.race_penalty) + { + self.velocity = '0 0 0'; + self.movetype = MOVETYPE_NONE; + self.disableclientprediction = 2; + } + } +#endif + // force kbd movement for fairness float wishspeed; vector wishvel; @@ -261,6 +282,32 @@ MUTATOR_HOOKFUNCTION(cts, GetPressedKeys) } } + if (!IS_OBSERVER(self)) + { + if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) + { + speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1'); + speedaward_holder = self.netname; + speedaward_uid = self.crypto_idfp; + speedaward_lastupdate = time; + } + if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) + { + string rr = CTS_RECORD; + race_send_speedaward(MSG_ALL); + speedaward_lastsent = speedaward_speed; + if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") + { + speedaward_alltimebest = speedaward_speed; + speedaward_alltimebest_holder = speedaward_holder; + speedaward_alltimebest_uid = speedaward_uid; + db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest)); + db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid); + race_send_speedaward_alltimebest(MSG_ALL); + } + } + } + return false; } diff --git a/qcsrc/server/mutators/gamemode_race.qc b/qcsrc/server/mutators/gamemode_race.qc index b7c660a46..7a56d7f9d 100644 --- a/qcsrc/server/mutators/gamemode_race.qc +++ b/qcsrc/server/mutators/gamemode_race.qc @@ -69,6 +69,27 @@ void race_EventLog(string mode, entity actor) // use an alias for easy changing MUTATOR_HOOKFUNCTION(rc, PlayerPhysics) {SELFPARAM(); + self.race_movetime_frac += PHYS_INPUT_TIMELENGTH; + float f = floor(self.race_movetime_frac); + self.race_movetime_frac -= f; + self.race_movetime_count += f; + self.race_movetime = self.race_movetime_frac + self.race_movetime_count; + +#ifdef SVQC + if(IS_PLAYER(self)) + { + if (self.race_penalty) + if (time > self.race_penalty) + self.race_penalty = 0; + if(self.race_penalty) + { + self.velocity = '0 0 0'; + self.movetype = MOVETYPE_NONE; + self.disableclientprediction = 2; + } + } +#endif + // force kbd movement for fairness float wishspeed; vector wishvel; @@ -260,6 +281,31 @@ MUTATOR_HOOKFUNCTION(rc, GetPressedKeys) } } + if (!IS_OBSERVER(self)) + { + if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) + { + speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1'); + speedaward_holder = self.netname; + speedaward_uid = self.crypto_idfp; + speedaward_lastupdate = time; + } + if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) + { + string rr = RACE_RECORD; + race_send_speedaward(MSG_ALL); + speedaward_lastsent = speedaward_speed; + if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") + { + speedaward_alltimebest = speedaward_speed; + speedaward_alltimebest_holder = speedaward_holder; + speedaward_alltimebest_uid = speedaward_uid; + db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest)); + db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid); + race_send_speedaward_alltimebest(MSG_ALL); + } + } + } return false; } diff --git a/qcsrc/server/race.qh b/qcsrc/server/race.qh index 47c1db4a3..5e9f0cf85 100644 --- a/qcsrc/server/race.qh +++ b/qcsrc/server/race.qh @@ -1,6 +1,9 @@ #ifndef RACE_H #define RACE_H +float speedaward_lastsent; +float speedaward_lastupdate; + float race_spawns; float race_highest_place_spawn; // number of places; a place higher gets spawned at 0 float race_lowest_place_spawn; // where to spawn in qualifying -- 2.39.2