From 0425cc82fa8f0691ba513b3841e0fc8568ab2118 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 3 Oct 2023 22:19:20 +1100 Subject: [PATCH] - Duke: Clean up player/actor accesses in `noise.cpp`. --- source/games/duke/src/actors.cpp | 5 ++--- source/games/duke/src/funct.h | 4 ++-- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/noise.cpp | 7 ++----- source/games/duke/src/player_r.cpp | 28 ++++++++++++++-------------- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index dcdf0cf7a..9e3b47e43 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -4285,8 +4285,7 @@ void movefta(void) DukeStatIterator it(STAT_ZOMBIEACTOR); while (auto act = it.Next()) { - const auto pnum = findplayer(act, &xx); - const auto p = getPlayer(pnum); + const auto p = getPlayer(findplayer(act, &xx)); const auto pact = p->GetActor(); canseeme = 0; ssect = psect = act->sector(); @@ -4360,7 +4359,7 @@ void movefta(void) // wakeup is an RR feature, this flag will allow it to use in Duke, too. if ((act->flags1 & SFLAG_MOVEFTA_WAKEUPCHECK)) { - if (wakeup(act, pnum)) + if (wakeup(act, p)) { act->timetosleep = 0; check_fta_sounds(act); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 07396a4ec..31f35a9c4 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -93,7 +93,8 @@ void addammo(int weapon, DDukePlayer* p, int amount); int ssp(DDukeActor* i, unsigned int cliptype); //The set sprite function void insertspriteq(DDukeActor *i); -int wakeup(DDukeActor* sn, int pn); +int madenoise(DDukePlayer* const p); +int wakeup(DDukeActor* sn, DDukePlayer* const p); int timedexit(int snum); @@ -118,7 +119,6 @@ void checkweapons(DDukePlayer* const p); int findotherplayer(int p, double* d); void quickkill(DDukePlayer* p); int setpal(DDukePlayer* p); -int madenoise(int playerNum); int haslock(sectortype* sect, int snum); void purplelavacheck(DDukePlayer* p); void addphealth(DDukePlayer* p, int amount, bool bigitem); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 179127222..216604927 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -332,7 +332,7 @@ void hud_input(DDukePlayer* const p) p->yehaa_timer = 126; S_PlayActorSound(390, pact); p->noise_radius = 1024; - madenoise(p->pnum); + madenoise(p); if (p->cursector->lotag == 857) { if (pact->spr.extra <= gs.max_player_health) diff --git a/source/games/duke/src/noise.cpp b/source/games/duke/src/noise.cpp index c571dd711..e6aa3cb81 100644 --- a/source/games/duke/src/noise.cpp +++ b/source/games/duke/src/noise.cpp @@ -30,18 +30,15 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms BEGIN_DUKE_NS -int madenoise(int snum) +int madenoise(DDukePlayer* const p) { - DDukePlayer *p; - p = getPlayer(snum); p->donoise = 1; p->noise = p->GetActor()->spr.pos.XY(); return 1; } -int wakeup(DDukeActor* actor, int snum) +int wakeup(DDukeActor* actor, DDukePlayer* const p) { - auto p = getPlayer(snum); if (!p->donoise) return 0; if (actor->spr.pal == 30 || actor->spr.pal == 32 || actor->spr.pal == 33 || (isRRRA() && actor->spr.pal == 8)) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 1d7d5e400..b0d03ae23 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -427,7 +427,7 @@ int doincrements_r(DDukePlayer* p) if (numplayers < 2) { p->noise_radius = 1024; - madenoise(screenpeek); + madenoise(getPlayer(screenpeek)); p->vel.XY() += p->GetActor()->spr.Angles.Yaw.ToVector(); } p->eat -= 4; @@ -1675,7 +1675,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { p->hbomb_on = 0; p->noise_radius = 512; - madenoise(snum); + madenoise(p); } if (p->kickback_pic == 12) { @@ -1743,7 +1743,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) shoot(pact, DukeShotSparkClass); S_PlayActorSound(PISTOL_FIRE, pact); p->noise_radius = 512; - madenoise(snum); + madenoise(p); lastvisinc = PlayClock + 32; p->visibility = 0; @@ -1813,7 +1813,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(SHOTGUN_FIRE, pact); p->noise_radius = 512; - madenoise(snum); + madenoise(p); lastvisinc = PlayClock + 32; p->visibility = 0; @@ -1917,7 +1917,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(CHAINGUN_FIRE, pact); shoot(pact, DukeChaingunShotClass); p->noise_radius = 512; - madenoise(snum); + madenoise(p); lastvisinc = PlayClock + 32; p->visibility = 0; @@ -1949,7 +1949,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->okickback_pic = p->kickback_pic = 0; shoot(pact, RedneckBuzzSawClass); p->noise_radius = 64; - madenoise(snum); + madenoise(p); checkavailweapon(p); } else p->kickback_pic++; @@ -1977,7 +1977,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(CHAINGUN_FIRE, pact); shoot(pact, DukeShotSparkClass); p->noise_radius = 1024; - madenoise(snum); + madenoise(p); p->ammo_amount[TIT_WEAPON]--; checkavailweapon(p); } @@ -2004,7 +2004,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(CHAINGUN_FIRE, pact); shoot(pact, DukeChaingunShotClass); p->noise_radius = 1024; - madenoise(snum); + madenoise(p); p->ammo_amount[MOTORCYCLE_WEAPON]--; if (p->ammo_amount[MOTORCYCLE_WEAPON] <= 0) p->okickback_pic = p->kickback_pic = 0; @@ -2052,7 +2052,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { S_PlayActorSound(CAT_FIRE, pact); p->noise_radius = 128; - madenoise(snum); + madenoise(p); } else if (p->kickback_pic == 9) { @@ -2106,7 +2106,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(354, pact); shoot(pact, RedneckBowlingBallClass); p->noise_radius = 64; - madenoise(snum); + madenoise(p); } if (p->kickback_pic < 30) { @@ -2129,7 +2129,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { shoot(pact, DukeMeleeAttackClass); p->noise_radius = 64; - madenoise(snum); + madenoise(p); } else if (p->kickback_pic == 16) p->okickback_pic = p->kickback_pic = 0; @@ -2147,7 +2147,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { shoot(pact, RedneckSlingbladeAttackClass); p->noise_radius = 64; - madenoise(snum); + madenoise(p); } else if (p->kickback_pic == 16) p->okickback_pic = p->kickback_pic = 0; @@ -2167,7 +2167,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->visibility = 0; shoot(pact, RedneckDynamiteArrowClass); p->noise_radius = 2048; - madenoise(snum); + madenoise(p); checkavailweapon(p); } else if (p->kickback_pic == 16) @@ -2185,7 +2185,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->visibility = 0; shoot(pact, RedneckChickenArrowClass); p->noise_radius = 2048; - madenoise(snum); + madenoise(p); checkavailweapon(p); } else if (p->kickback_pic == 16)