- SectorIsUnderwaterArea

This commit is contained in:
Christoph Oelckers 2021-11-24 22:55:31 +01:00
parent 4149a335a3
commit c43d594f34
4 changed files with 29 additions and 27 deletions

View file

@ -787,6 +787,7 @@ struct PLAYERstruct
int cursectnum,lastcursectnum;
sectortype* cursector() { return cursectnum < 0? nullptr : &sector[cursectnum]; }
void setcursector(sectortype* s) { cursectnum = sectnum(s); }
bool insector() const { return cursectnum >= 0; }
fixed_t turn180_target; // 180 degree turn
@ -2214,9 +2215,10 @@ inline bool SectorIsDiveArea(int sect)
return (TEST(sector[sect].extra, SECTFX_DIVE_AREA) ? true : false);
}
inline bool SectorIsUnderwaterArea(int sect)
inline bool SectorIsUnderwaterArea(sectortype* sect)
{
return (TEST(sector[sect].extra, SECTFX_UNDERWATER | SECTFX_UNDERWATER2) ? true : false);
if (!sect) return false;
return (TEST(sect->extra, SECTFX_UNDERWATER | SECTFX_UNDERWATER2) ? true : false);
}
END_SW_NS

View file

@ -2998,12 +2998,12 @@ void StackedWaterSplash(PLAYERp pp)
{
if (FAF_ConnectArea(pp->cursectnum))
{
int sectnum = pp->cursectnum;
auto sectnum = pp->cursector();
auto psp = &pp->Actor()->s();
updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(psp), &sectnum);
if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum))
if (SectorIsUnderwaterArea(sectnum))
{
PlaySound(DIGI_SPLASH1, pp, v3df_dontpan);
}
@ -3022,7 +3022,7 @@ void DoPlayerFall(PLAYERp pp)
pp->KeyPressBits |= SB_JUMP;
}
if (pp->cursectnum >= 0 && SectorIsUnderwaterArea(pp->cursectnum))
if (SectorIsUnderwaterArea(pp->cursector()))
{
StackedWaterSplash(pp);
DoPlayerBeginDiveNoWarp(pp);
@ -3509,7 +3509,7 @@ void DoPlayerCrawl(PLAYERp pp)
{
USERp u = pp->Actor()->u();
if (pp->cursectnum >= 0 && SectorIsUnderwaterArea(pp->cursectnum))
if (SectorIsUnderwaterArea(pp->cursector()))
{
// if stacked water - which it should be
if (FAF_ConnectArea(pp->cursectnum))
@ -3637,7 +3637,7 @@ bool PlayerFloorHit(PLAYERp pp, int zlimit)
void DoPlayerFly(PLAYERp pp)
{
if (pp->cursectnum >= 0 && SectorIsUnderwaterArea(pp->cursectnum))
if (SectorIsUnderwaterArea(pp->cursector()))
{
DoPlayerBeginDiveNoWarp(pp);
return;
@ -3882,14 +3882,14 @@ int PlayerCanDiveNoWarp(PLAYERp pp)
{
if (FAF_ConnectArea(pp->cursectnum))
{
int sectnum = pp->cursectnum;
auto sect = pp->cursector();
updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(&pp->Actor()->s()), &sectnum);
updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(&pp->Actor()->s()), &sect);
if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum))
if (SectorIsUnderwaterArea(sect))
{
pp->cursectnum = sectnum;
pp->posz = sector[sectnum].ceilingz;
pp->setcursector(sect);
pp->posz = sect->ceilingz;
pp->posz += Z(20);
pp->z_speed = Z(20);
@ -4297,7 +4297,7 @@ void DoPlayerBeginDiveNoWarp(PLAYERp pp)
if (Prediction)
return;
if (!pp->insector() || !SectorIsUnderwaterArea(pp->cursectnum))
if (!SectorIsUnderwaterArea(pp->cursector()))
return;
if (pp->Bloody) pp->Bloody = false; // Water washes away the blood
@ -4439,7 +4439,7 @@ void DoPlayerDive(PLAYERp pp)
auto sectu = pp->cursector();
// whenever your view is not in a water area
if (!pp->insector() || !SectorIsUnderwaterArea(pp->cursectnum))
if (!SectorIsUnderwaterArea(pp->cursector()))
{
DoPlayerStopDiveNoWarp(pp);
DoPlayerBeginRun(pp);
@ -4505,17 +4505,17 @@ void DoPlayerDive(PLAYERp pp)
{
if (pp->posz < pp->cursector()->ceilingz + Z(10))
{
int sectnum = pp->cursectnum;
auto sect = pp->cursector();
// check for sector above to see if it is an underwater sector also
updatesectorz(pp->posx, pp->posy, pp->cursector()->ceilingz - Z(8), &sectnum);
updatesectorz(pp->posx, pp->posy, pp->cursector()->ceilingz - Z(8), &sect);
if (sectnum >= 0 && !SectorIsUnderwaterArea(sectnum))
if (!SectorIsUnderwaterArea(sect))
{
// if not underwater sector we must surface
// force into above sector
pp->posz = pp->cursector()->ceilingz - Z(8);
pp->cursectnum = sectnum;
pp->setcursector(sect);
DoPlayerStopDiveNoWarp(pp);
DoPlayerBeginRun(pp);
return;
@ -6310,7 +6310,7 @@ void DoPlayerRun(PLAYERp pp)
{
USERp u = pp->Actor()->u();
if (pp->cursectnum >= 0 && SectorIsUnderwaterArea(pp->cursectnum))
if (SectorIsUnderwaterArea(pp->cursector()))
{
DoPlayerBeginDiveNoWarp(pp);
return;

View file

@ -13657,7 +13657,7 @@ int InitShotgun(PLAYERp pp)
if (TEST(sector[hitinfo.hitsect].ceilingstat, CEILING_STAT_PLAX))
continue;
if (SectorIsUnderwaterArea(hitinfo.hitsect))
if (SectorIsUnderwaterArea(hitinfo.sector()))
{
WarpToSurface(&hitinfo.hitsect, &hitinfo.pos.x, &hitinfo.pos.y, &hitinfo.pos.z);
ContinueHitscan(pp, hitinfo.hitsect, hitinfo.pos.x, hitinfo.pos.y, hitinfo.pos.z, ndaang, xvect, yvect, zvect);
@ -16219,7 +16219,7 @@ int InitUzi(PLAYERp pp)
if (TEST(sector[hitinfo.hitsect].ceilingstat, CEILING_STAT_PLAX))
return 0;
if (SectorIsUnderwaterArea(hitinfo.hitsect))
if (SectorIsUnderwaterArea(hitinfo.sector()))
{
WarpToSurface(&hitinfo.hitsect, &hitinfo.pos.x, &hitinfo.pos.y, &hitinfo.pos.z);
ContinueHitscan(pp, hitinfo.hitsect, hitinfo.pos.x, hitinfo.pos.y, hitinfo.pos.z, daang, xvect, yvect, zvect);
@ -18251,7 +18251,7 @@ bool MissileHitDiveArea(DSWActor* actor)
// in Stacked water areas.
if (FAF_ConnectArea(sp->sectnum))
{
if (SectorIsUnderwaterArea(sp->sectnum))
if (SectorIsUnderwaterArea(sp->sector()))
SET(u->Flags, SPR_UNDERWATER);
else
RESET(u->Flags, SPR_UNDERWATER);
@ -18443,7 +18443,7 @@ int DoBubble(DSWActor* actor)
if (sp->z < sp->sector()->ceilingz)
{
if (SectorIsUnderwaterArea(sectnum(u->hi_sectp)))
if (SectorIsUnderwaterArea(u->hi_sectp))
{
if (!SpriteWarpToSurface(actor))
{

View file

@ -821,14 +821,14 @@ void SpawnZombie2(DSWActor* actor)
if (sectu && (TEST(sectp->extra, SECTFX_LIQUID_MASK) != SECTFX_LIQUID_NONE))
return;
if (SectorIsUnderwaterArea(sp->sectnum))
if (SectorIsUnderwaterArea(sp->sector()))
return;
if (FAF_ConnectArea(sp->sectnum))
{
int sectnum = sp->sectnum;
updatesectorz(sp->x, sp->y, sp->z + Z(10), &sectnum);
if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum))
auto newsect = sp->sector();
updatesectorz(sp->x, sp->y, sp->z + Z(10), &newsect);
if (SectorIsUnderwaterArea(newsect))
return;
}