- Duke: Clean up player/actor accesses in checkhitswitch() and associated utilities.

This commit is contained in:
Mitchell Richters 2023-10-04 11:32:15 +11:00 committed by Christoph Oelckers
parent b5f2357949
commit 48f1be7e0c
9 changed files with 67 additions and 65 deletions

View file

@ -32,8 +32,8 @@ BEGIN_DUKE_NS
//
//---------------------------------------------------------------------------
bool checkaccessswitch_d(int snum, int pal, DDukeActor *act, walltype* w);
bool checkaccessswitch_r(int snum, int pal, DDukeActor* act, walltype* w);
bool checkaccessswitch_d(DDukePlayer* const p, int pal, DDukeActor *act, walltype* w);
bool checkaccessswitch_r(DDukePlayer* const p, int pal, DDukeActor* act, walltype* w);
void activatebysector_d(sectortype* sect, DDukeActor* j);
void activatebysector_r(sectortype* sect, DDukeActor* j);
void checksectors_d(int snum);

View file

@ -70,7 +70,7 @@ struct Dispatcher
// sectors_?.cpp
void (*think)();
void (*movetransports)();
bool (*checkaccessswitch)(int snum, int switchpal, DDukeActor* act, walltype* w);
bool (*checkaccessswitch)(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* w);
void (*activatebysector)(sectortype* sect, DDukeActor* j);
void (*checksectors)(int low);

View file

@ -240,7 +240,7 @@ void underwater(DDukePlayer* p, ESyncBits actions, double floorz, double ceiling
void loadcons();
void DrawStatusBar();
void thunder(void);
bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act);
bool checkhitswitch(DDukePlayer* const p, walltype* wwal, DDukeActor* act);
void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h);
void applyanimations(tspritetype* t, DDukeActor* h, const DVector2& viewVec, DAngle viewang);

View file

@ -449,7 +449,7 @@ int doincrements_d(DDukePlayer* p)
{
if (p->access_spritenum != nullptr)
{
checkhitswitch(snum, nullptr, p->access_spritenum);
checkhitswitch(p, nullptr, p->access_spritenum);
switch (p->access_spritenum->spr.pal)
{
case 0:p->got_access &= (0xffff - 0x1); break;
@ -460,7 +460,7 @@ int doincrements_d(DDukePlayer* p)
}
else
{
checkhitswitch(snum, p->access_wall, nullptr);
checkhitswitch(p, p->access_wall, nullptr);
switch (p->access_wall->pal)
{
case 0:p->got_access &= (0xffff - 0x1); break;

View file

@ -507,7 +507,7 @@ int doincrements_r(DDukePlayer* p)
{
if (p->access_spritenum != nullptr)
{
checkhitswitch(snum, nullptr, p->access_spritenum);
checkhitswitch(p, nullptr, p->access_spritenum);
switch (p->access_spritenum->spr.pal)
{
case 0:p->keys[1] = 1; break;
@ -518,7 +518,7 @@ int doincrements_r(DDukePlayer* p)
}
else
{
checkhitswitch(snum, p->access_wall, nullptr);
checkhitswitch(p, p->access_wall, nullptr);
switch (p->access_wall->pal)
{
case 0:p->keys[1] = 1; break;

View file

@ -1589,7 +1589,7 @@ void resetswitch(int tag)
//
//---------------------------------------------------------------------------
void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v)
static void tag10000specialswitch(DDukePlayer* const p, DDukeActor* act, const DVector3& v)
{
DDukeActor* switches[3];
int switchcount = 0, j;
@ -1620,7 +1620,7 @@ void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v)
{
switches[j]->spr.hitag = 0;
switches[j]->spr.setspritetexture(::switches[GetExtInfo(switches[j]->spr.spritetexture()).switchindex].states[3]);
checkhitswitch(snum, nullptr, switches[j]);
checkhitswitch(p, nullptr, switches[j]);
}
}
}
@ -1735,7 +1735,7 @@ void togglewallswitches(walltype* wwal, const TexExtInfo& ext, int lotag, int& c
//
//---------------------------------------------------------------------------
bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
bool checkhitswitch(DDukePlayer* const p, walltype* wwal, DDukeActor* act)
{
uint8_t switchpal;
int lotag, hitag, correctdips, numdips;
@ -1757,7 +1757,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
switchpal = act->spr.pal;
// custom switches that maintain themselves can immediately abort.
swresult = CallTriggerSwitch(act, getPlayer(snum));
swresult = CallTriggerSwitch(act, p);
if (swresult == 1) return true;
}
else
@ -1781,7 +1781,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
break;
case SwitchDef::Access:
if (fi.checkaccessswitch(snum, switchpal, act, wwal))
if (fi.checkaccessswitch(p, switchpal, act, wwal))
return 0;
[[fallthrough]];
@ -1808,15 +1808,15 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
if (hitag == 10001 && swdef.flags & SwitchDef::oneway && isRRRA())
{
act->spr.setspritetexture(swdef.states[1]);
if (getPlayer(snum)->SeaSick == 0)
getPlayer(snum)->SeaSick = 350;
operateactivators(668, getPlayer(snum));
if (p->SeaSick == 0)
p->SeaSick = 350;
operateactivators(668, p);
operatemasterswitches(668);
S_PlayActorSound(328, getPlayer(snum)->GetActor());
S_PlayActorSound(328, p->GetActor());
return 1;
}
}
DVector3 v(spos, getPlayer(snum)->GetActor()->getOffsetZ());
DVector3 v(spos, p->GetActor()->getOffsetZ());
if (swdef.type != SwitchDef::None || isadoorwall(texid))
{
@ -1826,16 +1826,16 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
{
FSoundID sound = swdef.soundid != NO_SOUND ? swdef.soundid : S_FindSoundByResID(SWITCH_ON);
if (act) S_PlaySound3D(sound, act, v);
else S_PlaySound3D(sound, getPlayer(snum)->GetActor(), v);
else S_PlaySound3D(sound, p->GetActor(), v);
if (numdips != correctdips) return 0;
S_PlaySound3D(END_OF_LEVEL_WARN, getPlayer(snum)->GetActor(), v);
S_PlaySound3D(END_OF_LEVEL_WARN, p->GetActor(), v);
}
if (swdef.type == SwitchDef::Multi)
{
lotag += ext.switchphase;
if (hitag == 10000 && act && isRRRA()) // no idea if the game check is really needed for something this far off the beaten path...
{
tag10000specialswitch(snum, act, v);
tag10000specialswitch(p, act, v);
return 1;
}
}
@ -1866,8 +1866,8 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
case SE_25_PISTON:
other->temp_data[4] = !other->temp_data[4];
if (other->temp_data[4])
FTA(15, getPlayer(snum));
else FTA(2, getPlayer(snum));
FTA(15, p);
else FTA(2, p);
break;
case SE_21_DROP_FLOOR:
FTA(2, getPlayer(screenpeek));
@ -1876,8 +1876,8 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
}
}
operateactivators(lotag, getPlayer(snum));
operateforcefields(getPlayer(snum)->GetActor(), lotag);
operateactivators(lotag, p);
operateforcefields(p->GetActor(), lotag);
operatemasterswitches(lotag);
if (swdef.type == SwitchDef::Combo) return 1;
@ -1886,7 +1886,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
{
FSoundID sound = swdef.soundid != NO_SOUND ? swdef.soundid : S_FindSoundByResID(SWITCH_ON);
if (act) S_PlaySound3D(sound, act, v);
else S_PlaySound3D(sound, getPlayer(snum)->GetActor(), v);
else S_PlaySound3D(sound, p->GetActor(), v);
}
else if (hitag != 0)
{
@ -1895,7 +1895,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act)
if (act && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, act, v);
else
S_PlayActorSound(hitag, getPlayer(snum)->GetActor());
S_PlayActorSound(hitag, p->GetActor());
}
return 1;

View file

@ -48,37 +48,37 @@ BEGIN_DUKE_NS
//
//---------------------------------------------------------------------------
bool checkaccessswitch_d(int snum, int switchpal, DDukeActor* act, walltype* wwal)
bool checkaccessswitch_d(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* wwal)
{
if (getPlayer(snum)->access_incs == 0)
if (p->access_incs == 0)
{
if (switchpal == 0)
{
if ((getPlayer(snum)->got_access & 1))
getPlayer(snum)->access_incs = 1;
else FTA(70, getPlayer(snum));
if ((p->got_access & 1))
p->access_incs = 1;
else FTA(70, p);
}
else if (switchpal == 21)
{
if (getPlayer(snum)->got_access & 2)
getPlayer(snum)->access_incs = 1;
else FTA(71, getPlayer(snum));
if (p->got_access & 2)
p->access_incs = 1;
else FTA(71, p);
}
else if (switchpal == 23)
{
if (getPlayer(snum)->got_access & 4)
getPlayer(snum)->access_incs = 1;
else FTA(72, getPlayer(snum));
if (p->got_access & 4)
p->access_incs = 1;
else FTA(72, p);
}
if (getPlayer(snum)->access_incs == 1)
if (p->access_incs == 1)
{
if (!act)
getPlayer(snum)->access_wall = wwal;
p->access_wall = wwal;
else
getPlayer(snum)->access_spritenum = act;
p->access_spritenum = act;
}
return 1;
@ -306,7 +306,7 @@ void checksectors_d(int snum)
auto const neartagsprite = near.actor();
if (neartagsprite != nullptr)
{
if (checkhitswitch(snum, nullptr, neartagsprite)) return;
if (checkhitswitch(p, nullptr, neartagsprite)) return;
if (CallOnUse(neartagsprite, p))
return;
@ -333,7 +333,7 @@ void checksectors_d(int snum)
if (near.hitWall->lotag > 0 && isadoorwall(near.hitWall->walltexture))
{
if (hitscanwall == near.hitWall || hitscanwall == nullptr)
checkhitswitch(snum, near.hitWall, nullptr);
checkhitswitch(p, near.hitWall, nullptr);
return;
}
else if (p->newOwner != nullptr)
@ -364,7 +364,7 @@ void checksectors_d(int snum)
}
operatesectors(p->GetActor()->sector(), p->GetActor());
}
else checkhitswitch(snum, near.hitWall, nullptr);
else checkhitswitch(p, near.hitWall, nullptr);
}
}
}

View file

@ -49,49 +49,51 @@ BEGIN_DUKE_NS
//
//---------------------------------------------------------------------------
bool checkaccessswitch_r(int snum, int switchpal, DDukeActor* act, walltype* wwal)
bool checkaccessswitch_r(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* wwal)
{
if (getPlayer(snum)->access_incs == 0)
const auto pact = p->GetActor();
if (p->access_incs == 0)
{
if (switchpal == 0)
{
if (getPlayer(snum)->keys[1])
getPlayer(snum)->access_incs = 1;
if (p->keys[1])
p->access_incs = 1;
else
{
FTA(70, getPlayer(snum));
if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor());
FTA(70, p);
if (isRRRA()) S_PlayActorSound(99, act ? act : pact);
}
}
else if (switchpal == 21)
{
if (getPlayer(snum)->keys[2])
getPlayer(snum)->access_incs = 1;
if (p->keys[2])
p->access_incs = 1;
else
{
FTA(71, getPlayer(snum));
if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor());
FTA(71, p);
if (isRRRA()) S_PlayActorSound(99, act ? act : pact);
}
}
else if (switchpal == 23)
{
if (getPlayer(snum)->keys[3])
getPlayer(snum)->access_incs = 1;
if (p->keys[3])
p->access_incs = 1;
else
{
FTA(72, getPlayer(snum));
if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor());
FTA(72, p);
if (isRRRA()) S_PlayActorSound(99, act ? act : pact);
}
}
if (getPlayer(snum)->access_incs == 1)
if (p->access_incs == 1)
{
if (!act)
getPlayer(snum)->access_wall = wwal;
p->access_wall = wwal;
else
getPlayer(snum)->access_spritenum = act;
p->access_spritenum = act;
}
return 1;
}
@ -330,7 +332,7 @@ void checksectors_r(int snum)
auto const neartagsprite = near.actor();
if (neartagsprite != nullptr)
{
if (checkhitswitch(snum, nullptr, neartagsprite)) return;
if (checkhitswitch(p, nullptr, neartagsprite)) return;
if (neartagsprite->GetClass() != RUNTIME_CLASS(DDukeActor))
{
@ -355,7 +357,7 @@ void checksectors_r(int snum)
if (near.hitWall->lotag > 0 && isadoorwall(near.hitWall->walltexture))
{
if (hitscanwall == near.hitWall || hitscanwall == nullptr)
checkhitswitch(snum, near.hitWall, nullptr);
checkhitswitch(p, near.hitWall, nullptr);
return;
}
}
@ -400,7 +402,7 @@ void checksectors_r(int snum)
FTA(41, p);
}
}
else checkhitswitch(snum, near.hitWall, nullptr);
else checkhitswitch(p, near.hitWall, nullptr);
}
}
}

View file

@ -1359,7 +1359,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, StartBoat, OnBoat)
void pl_checkhitswitch(DDukePlayer* p, walltype* wal, DDukeActor* act)
{
checkhitswitch(p->GetPlayerNum(), wal, act);
checkhitswitch(p, wal, act);
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, checkhitswitch, pl_checkhitswitch)