From cd9380e44806612f8eb2d04f27ca283ae8f0a461 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 7 Dec 2020 22:42:26 +1000 Subject: [PATCH] Record player race move time in PlayerPreThink so it can be recorded while inside a vehicle, fixes #2263 --- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 14 ++++++++++++-- qcsrc/common/gamemodes/gamemode/race/sv_race.qc | 14 ++++++++++++-- qcsrc/server/race.qc | 6 ++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 144788917..7c83260d0 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -71,16 +71,26 @@ void cts_EventLog(string mode, entity actor) // use an alias for easy changing a GameLogEcho(strcat(":cts:", mode, ":", ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : ""))); } -MUTATOR_HOOKFUNCTION(cts, PlayerPhysics) +MUTATOR_HOOKFUNCTION(cts, PlayerPreThink) { entity player = M_ARGV(0, entity); - float dt = M_ARGV(1, float); + if(!IS_PLAYER(player)) + return; + + // we need to perform this in PlayerPreThink as PlayerPhysics may not be called (vehicle support) + float dt = frametime; player.race_movetime_frac += dt; float f = floor(player.race_movetime_frac); player.race_movetime_frac -= f; player.race_movetime_count += f; player.race_movetime = player.race_movetime_frac + player.race_movetime_count; +} + +MUTATOR_HOOKFUNCTION(cts, PlayerPhysics) +{ + entity player = M_ARGV(0, entity); + //float dt = M_ARGV(1, float); if(IS_PLAYER(player)) { diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index a69a43522..c87384c94 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -128,16 +128,26 @@ MUTATOR_HOOKFUNCTION(rc, AbortSpeedrun) race_PreparePlayer(player); // nice try } -MUTATOR_HOOKFUNCTION(rc, PlayerPhysics) +MUTATOR_HOOKFUNCTION(rc, PlayerPreThink) { entity player = M_ARGV(0, entity); - float dt = M_ARGV(1, float); + if(!IS_PLAYER(player)) + return; + + // we need to perform this in PlayerPreThink as PlayerPhysics may not be called (vehicle support) + float dt = frametime; player.race_movetime_frac += dt; float f = floor(player.race_movetime_frac); player.race_movetime_frac -= f; player.race_movetime_count += f; player.race_movetime = player.race_movetime_frac + player.race_movetime_count; +} + +MUTATOR_HOOKFUNCTION(rc, PlayerPhysics) +{ + entity player = M_ARGV(0, entity); + //float dt = M_ARGV(1, float); #ifdef SVQC if(IS_PLAYER(player)) diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 70a98083e..4e166214c 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -424,8 +424,6 @@ void race_deleteTime(string map, float pos) void race_SendTime(entity e, float cp, float t, float tvalid) { - float snew, l; - if(g_race_qualifying) t += e.race_penalty_accumulator; @@ -449,9 +447,9 @@ void race_SendTime(entity e, float cp, float t, float tvalid) GameRules_scoring_add(e, RACE_FASTEST, t - s); s = GameRules_scoring_add(e, RACE_TIME, 0); - snew = TIME_ENCODE(time - game_starttime); + float snew = TIME_ENCODE(time - game_starttime); GameRules_scoring_add(e, RACE_TIME, snew - s); - l = GameRules_scoring_add_team(e, RACE_LAPS, 1); + float l = GameRules_scoring_add_team(e, RACE_LAPS, 1); if(autocvar_fraglimit) if(l >= autocvar_fraglimit) -- 2.39.2