From c43d594f346388e505842ffd7e0ee2ce585cf577 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 24 Nov 2021 22:55:31 +0100 Subject: [PATCH] - SectorIsUnderwaterArea --- source/games/sw/src/game.h | 6 ++++-- source/games/sw/src/player.cpp | 34 +++++++++++++++++----------------- source/games/sw/src/weapon.cpp | 8 ++++---- source/games/sw/src/zombie.cpp | 8 ++++---- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 694255f0b..d1359d016 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -787,6 +787,7 @@ struct PLAYERstruct int cursectnum,lastcursectnum; sectortype* cursector() { return cursectnum < 0? nullptr : §or[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 diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index ce4b48024..21822ef30 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -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), §num); - 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()), §num); + updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(&pp->Actor()->s()), §); - 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), §num); + updatesectorz(pp->posx, pp->posy, pp->cursector()->ceilingz - Z(8), §); - 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; diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 59902807b..531f04c0f 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -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)) { diff --git a/source/games/sw/src/zombie.cpp b/source/games/sw/src/zombie.cpp index 7aa367606..ae73d4c4f 100644 --- a/source/games/sw/src/zombie.cpp +++ b/source/games/sw/src/zombie.cpp @@ -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), §num); - if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum)) + auto newsect = sp->sector(); + updatesectorz(sp->x, sp->y, sp->z + Z(10), &newsect); + if (SectorIsUnderwaterArea(newsect)) return; }