From f135097193b7ce26edcfbd88265b516902ada199 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 3 Oct 2023 22:41:22 +1100 Subject: [PATCH] - Duke: Clean up player/actor accesses in `playerCrouch()`. --- source/games/duke/src/funct.h | 2 +- source/games/duke/src/player.cpp | 10 +++++----- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index fdc7d31b9..a0ed8659b 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -103,7 +103,7 @@ int endoflevel(DDukePlayer* const p); void playerisdead(DDukePlayer* const p, int psectlotag, double fz, double cz); void footprints(DDukePlayer* const p); int makepainsounds(DDukePlayer* const p, int type); -void playerCrouch(int snum); +void playerCrouch(DDukePlayer* const p); void playerJump(int snum, double fz, double cz); void checklook(int snum, ESyncBits actions); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index bfe44f139..e8891778d 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -673,15 +673,15 @@ int timedexit(DDukePlayer* const p) // //--------------------------------------------------------------------------- -void playerCrouch(int snum) +void playerCrouch(DDukePlayer* const p) { - const auto p = getPlayer(snum); const auto pact = p->GetActor(); const auto nVelMoveDown = abs(p->cmd.ucmd.vel.Z * (p->cmd.ucmd.vel.Z < 0)); constexpr double vel = 8 + 3; - SetGameVarID(g_iReturnVarID, 0, pact, snum); - OnEvent(EVENT_CROUCH, snum, pact, -1); - if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0) + + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_CROUCH, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() == 0) { pact->spr.pos.Z += clamp(vel * !!(p->cmd.ucmd.actions & SB_CROUCH) + vel * nVelMoveDown, -vel, vel); p->crack_time = CRACK_TIME; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index ed98e8595..e6c8223ce 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -767,7 +767,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo if ((actions & SB_CROUCH) || p->cmd.ucmd.vel.Z < 0) { - playerCrouch(snum); + playerCrouch(p); } // jumping diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index dfdd9dfce..1bd362320 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1283,7 +1283,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo if (((actions & SB_CROUCH) || p->cmd.ucmd.vel.Z < 0) && !p->OnMotorcycle) { - playerCrouch(snum); + playerCrouch(p); } if ((actions & SB_JUMP) == 0 && !p->OnMotorcycle && p->jumping_toggle == 1)