- Duke: Clean up player/actor accesses in hudweapon_*().

This commit is contained in:
Mitchell Richters 2023-10-03 22:12:24 +11:00
parent a508dfff31
commit 20ba784ab7
2 changed files with 27 additions and 25 deletions

View file

@ -220,8 +220,9 @@ void animateshrunken(DDukePlayer* p, double xoffset, double yoffset, int8_t shad
void displayweapon_d(DDukePlayer* const p, double interpfrac)
{
int pal, pal2;
const auto pact = p->GetActor();
if (p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->spr.pal != 1 && p->GetActor()->spr.extra <= 0))
if (p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (pact->spr.pal != 1 && pact->spr.extra <= 0))
return;
double weapon_sway, gun_pos, kickback_pic, random_club_frame, hard_landing;
@ -246,7 +247,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
}
hard_landing *= 8.;
gun_pos -= fabs(p->GetActor()->spr.scale.X < 0.5 ? BobVal(weapon_sway * 4.) * 32 : BobVal(weapon_sway * 0.5) * 16) + hard_landing;
gun_pos -= fabs(pact->spr.scale.X < 0.5 ? BobVal(weapon_sway * 4.) * 32 : BobVal(weapon_sway * 0.5) * 16) + hard_landing;
auto offpair = p->Angles.getWeaponOffsets(interpfrac);
auto offsets = offpair.first;
@ -254,9 +255,9 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
auto yawinput = getavel(p) * (1. / 16.);
auto angle = offpair.second;
auto weapon_xoffset = 160 - 90 - (BobVal(512 + weapon_sway * 0.5) * (16384. / 1536.)) - 58 - p->weapon_ang;
auto shade = min(p->GetActor()->spr.shade, (int8_t)24);
auto shade = min(pact->spr.shade, (int8_t)24);
pal2 = pal = !p->insector() ? 0 : p->GetActor()->spr.pal == 1 ? 1 : p->cursector->floorpal;
pal2 = pal = !p->insector() ? 0 : pact->spr.pal == 1 ? 1 : p->cursector->floorpal;
if (pal2 == 0) pal2 = p->palookup;
auto animoffs = offsets + DVector2(yawinput, -hard_landing + pitchoffset);
@ -294,7 +295,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
}
}
if (p->GetActor()->spr.scale.X < 0.625)
if (pact->spr.scale.X < 0.625)
{
//shrunken..
animateshrunken(p, offsets.X, offsets.Y + gun_pos, shade, o, interpfrac);
@ -410,7 +411,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
if (*kb > 0)
offsets.Y += BobVal(kickback_pic * 128.) * 4;
if (*kb > 0 && p->GetActor()->spr.pal != 1)
if (*kb > 0 && pact->spr.pal != 1)
offsets.X += 1 - (rand() & 3);
const char* pic = "SHOTGUN";
@ -518,7 +519,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
if (*kb > 0)
offsets.Y += BobVal(kickback_pic * 128.) * 4;
if (*kb > 0 && p->GetActor()->spr.pal != 1)
if (*kb > 0 && pact->spr.pal != 1)
offsets.X += 1 - (rand() & 3);
if (*kb == 0)
@ -591,7 +592,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
if (*kb > 0)
offsets.Y += BobVal(kickback_pic * 128.) * 4;
if (*kb > 0 && p->GetActor()->spr.pal != 1)
if (*kb > 0 && pact->spr.pal != 1)
offsets.X += 1 - (rand() & 3);
hud_drawpal(168 + offsets.X, 260 + offsets.Y, "CHAINGUN", shade, o, pal, angle);
@ -604,10 +605,10 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
default:
if (*kb > 4 && *kb < 12)
{
auto rnd = p->GetActor()->spr.pal != 1 ? rand() & 7 : 0;
auto rnd = pact->spr.pal != 1 ? rand() & 7 : 0;
hud_drawpal(136 + offsets.X + rnd, 208 + offsets.Y + rnd - (kickback_pic * 0.5), flashframes[((*kb - 4) / 5)], shade, o, pal, angle);
if (p->GetActor()->spr.pal != 1) rnd = rand() & 7;
if (pact->spr.pal != 1) rnd = rand() & 7;
hud_drawpal(180 + offsets.X + rnd, 208 + offsets.Y + rnd - (kickback_pic * 0.5), flashframes[((*kb - 4) / 5)], shade, o, pal, angle);
}
@ -840,7 +841,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
static const char* const cat[] = { "FREEZECAT0", "FREEZECAT1", "FREEZECAT2" };
static constexpr uint8_t cat_frames[] = { 0,0,1,1,2,2 };
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y += rand() & 3;
@ -886,7 +887,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
else
{
// the 'active' display.
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y -= rand() & 3;
@ -936,7 +937,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
}
else
{
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y -= rand() & 3;
@ -986,7 +987,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
}
else
{
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y -= rand() & 3;
@ -1015,7 +1016,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
}
else
{
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y -= rand() & 3;
@ -1044,7 +1045,7 @@ void displayweapon_d(DDukePlayer* const p, double interpfrac)
static const char* const cat[] = { "FLAMETHROWERCAT0", "FLAMETHROWERCAT1", "FLAMETHROWERCAT2" };
static constexpr uint8_t cat_frames[] = { 0, 0, 1, 1, 2, 2 };
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += krand() & 1;
offsets.Y += krand() & 1;

View file

@ -216,6 +216,7 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
DAngle TiltStatus;
auto kb = &p->kickback_pic;
const auto pact = p->GetActor();
int o = 0;
@ -235,22 +236,22 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
}
hard_landing *= 8.;
gun_pos -= fabs(p->GetActor()->spr.scale.X < 0.125 ? BobVal(weapon_sway * 4.) * 32 : BobVal(weapon_sway * 0.5) * 16) + hard_landing;
gun_pos -= fabs(pact->spr.scale.X < 0.125 ? BobVal(weapon_sway * 4.) * 32 : BobVal(weapon_sway * 0.5) * 16) + hard_landing;
auto offpair = p->Angles.getWeaponOffsets(interpfrac);
auto offsets = offpair.first;
auto angle = offpair.second;
auto weapon_xoffset = 160 - 90 - (BobVal(512 + weapon_sway * 0.5) * (16384. / 1536.)) - 58 - p->weapon_ang;
auto shade = min(p->insector() && p->cursector->shadedsector == 1 ? 16 : p->GetActor()->spr.shade, 24);
auto pal = !p->insector()? 0 : p->GetActor()->spr.pal == 1? 1 : p->cursector->floorpal;
auto shade = min(p->insector() && p->cursector->shadedsector == 1 ? 16 : pact->spr.shade, 24);
auto pal = !p->insector()? 0 : pact->spr.pal == 1? 1 : p->cursector->floorpal;
auto cw = p->last_weapon >= 0 ? p->last_weapon : p->curr_weapon;
if (p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->spr.pal != 1 && p->GetActor()->spr.extra <= 0))
if (p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (pact->spr.pal != 1 && pact->spr.extra <= 0))
return;
if ((14 - p->quick_kick) != 14)
{
pal = p->GetActor()->spr.pal == 1 ? 1 : p->palookup;
pal = pact->spr.pal == 1 ? 1 : p->palookup;
}
if (p->OnMotorcycle)
@ -267,7 +268,7 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
offsets.X += weapon_xoffset;
offsets.Y -= gun_pos;
if (p->GetActor()->spr.scale.X < 0.125)
if (pact->spr.scale.X < 0.125)
{
animateshrunken(p, offsets.X, offsets.Y + gun_pos, shade, o, interpfrac);
}
@ -419,7 +420,7 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
}
else if ((krand() & 15) == 5)
{
S_PlayActorSound(327, p->GetActor());
S_PlayActorSound(327, pact);
hud_drawpal(210 + offsets.X, 222 + offsets.Y, "CBOW2GUNATK7", shade, o | pin, pal, angle, 36700);
chickenphase = 6;
}
@ -555,7 +556,7 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
if (*kb > 0)
offsets.Y += BobVal((*kb) << 7) * 4;
if (*kb > 0 && p->GetActor()->spr.pal != 1) offsets.X += 1 - (rand() & 3);
if (*kb > 0 && pact->spr.pal != 1) offsets.X += 1 - (rand() & 3);
switch (*kb)
{
@ -761,7 +762,7 @@ void displayweapon_r(DDukePlayer* const p, double interpfrac)
}
else
{
if (p->GetActor()->spr.pal != 1)
if (pact->spr.pal != 1)
{
offsets.X += rand() & 3;
offsets.Y -= rand() & 3;