From e3ad05d4d706bae44b3d308e22613eddc963d602 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 24 Nov 2021 21:45:03 +0100 Subject: [PATCH] - quick cursectnum replacements. --- source/games/sw/src/game.h | 1 + source/games/sw/src/jweapon.cpp | 4 +-- source/games/sw/src/player.cpp | 44 ++++++++++++++------------------- source/games/sw/src/sector.cpp | 4 +-- source/games/sw/src/swactor.h | 5 ++++ source/games/sw/src/weapon.cpp | 34 ++++++++++++------------- 6 files changed, 45 insertions(+), 47 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 8936538a4..34df50954 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]; } + bool insector() const { return cursectnum >= 0; } fixed_t turn180_target; // 180 degree turn // variables that do not fit into sprite structure diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index 4cf98346e..529aabc5b 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -1306,7 +1306,7 @@ int PlayerInitChemBomb(PLAYERp pp) PlaySound(DIGI_THROW, pp, v3df_dontpan | v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -1731,7 +1731,7 @@ int PlayerInitCaltrops(PLAYERp pp) PlaySound(DIGI_THROW, pp, v3df_dontpan | v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 27e7ec853..925171095 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -72,10 +72,6 @@ void pWeaponForceRest(PLAYERp pp); extern bool NoMeters; -#define TEST_UNDERWATER(pp) (TEST(sector[(pp)->cursectnum].extra, SECTFX_UNDERWATER)) - -//#define PLAYER_MIN_HEIGHT (Z(30)) -//#define PLAYER_MIN_HEIGHT_JUMP (Z(20)) #define PLAYER_MIN_HEIGHT (Z(20)) #define PLAYER_CRAWL_WADE_DEPTH (30) @@ -1597,7 +1593,7 @@ void SlipSlope(PLAYERp pp) { short ang; - if (pp->cursectnum < 0 || !pp->cursector()->hasU()) + if (!pp->insector() || !pp->cursector()->hasU()) return; auto sectu = pp->cursector(); @@ -1784,7 +1780,7 @@ void UpdatePlayerSprite(PLAYERp pp) // there are multiple death functions if (TEST(pp->Flags, PF_DEAD)) { - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); sp->ang = pp->angle.ang.asbuild(); UpdatePlayerUnderSprite(pp); return; @@ -1793,24 +1789,24 @@ void UpdatePlayerSprite(PLAYERp pp) if (pp->sop_control) { sp->z = pp->cursector()->floorz; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else if (pp->DoPlayerAction == DoPlayerCrawl) { sp->z = pp->posz + PLAYER_CRAWL_HEIGHT; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } #if 0 else if (pp->DoPlayerAction == DoPlayerSwim) { sp->z = pp->loz - Z(pp->WadeDepth) + Z(1); - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } #endif else if (pp->DoPlayerAction == DoPlayerWade) { sp->z = pp->posz + PLAYER_HEIGHT; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); if (pp->WadeDepth > Z(29)) { @@ -1821,7 +1817,7 @@ void UpdatePlayerSprite(PLAYERp pp) { // bobbing and sprite position taken care of in DoPlayerDive sp->z = pp->posz + Z(10); - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else if (pp->DoPlayerAction == DoPlayerClimb) { @@ -1831,7 +1827,7 @@ void UpdatePlayerSprite(PLAYERp pp) //sp->x += MOVEx(256+64, sp->ang); //sp->y += MOVEy(256+64, sp->ang); - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else if (pp->DoPlayerAction == DoPlayerFly) { @@ -1840,22 +1836,22 @@ void UpdatePlayerSprite(PLAYERp pp) //sp->z = pp->posz + PLAYER_HEIGHT; //DoPlayerSpriteBob(pp, PLAYER_HEIGHT, PLAYER_FLY_BOB_AMT, 3); DoPlayerSpriteBob(pp, PLAYER_HEIGHT, Z(6), 3); - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else if (pp->DoPlayerAction == DoPlayerJump || pp->DoPlayerAction == DoPlayerFall || pp->DoPlayerAction == DoPlayerForceJump) { sp->z = pp->posz + PLAYER_HEIGHT; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else if (pp->DoPlayerAction == DoPlayerTeleportPause) { sp->z = pp->posz + PLAYER_HEIGHT; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } else { sp->z = pp->loz; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); } UpdatePlayerUnderSprite(pp); @@ -1968,7 +1964,7 @@ void DoPlayerSlide(PLAYERp pp) void PlayerCheckValidMove(PLAYERp pp) { - if (pp->cursectnum == -1) + if (!pp->insector()) { static int count = 0; @@ -1987,7 +1983,7 @@ void PlayerCheckValidMove(PLAYERp pp) void PlayerSectorBound(PLAYERp pp, int amt) { - if (pp->cursectnum < 9) + if (!pp->insector()) return; int cz,fz; @@ -2229,7 +2225,7 @@ void DoPlayerSectorUpdatePostMove(PLAYERp pp) updatesectorz(pp->posx, pp->posy, pp->posz, &pp->cursectnum); // can mess up if below - if (pp->cursectnum < 0) + if (!pp->insector()) { pp->cursectnum = sectnum; @@ -3362,7 +3358,7 @@ void DoPlayerClimb(PLAYERp pp) // setsprite to players location sp->z = pp->posz + PLAYER_HEIGHT; - ChangeActorSect(pp->Actor(), pp->cursectnum); + ChangeActorSect(pp->Actor(), pp->cursector()); if (!SyncInput()) { @@ -4301,7 +4297,7 @@ void DoPlayerBeginDiveNoWarp(PLAYERp pp) if (Prediction) return; - if (pp->cursectnum < 0 || !SectorIsUnderwaterArea(pp->cursectnum)) + if (!pp->insector() || !SectorIsUnderwaterArea(pp->cursectnum)) return; if (pp->Bloody) pp->Bloody = false; // Water washes away the blood @@ -4443,7 +4439,7 @@ void DoPlayerDive(PLAYERp pp) auto sectu = pp->cursector(); // whenever your view is not in a water area - if (pp->cursectnum < 0 || !SectorIsUnderwaterArea(pp->cursectnum)) + if (!pp->insector() || !SectorIsUnderwaterArea(pp->cursectnum)) { DoPlayerStopDiveNoWarp(pp); DoPlayerBeginRun(pp); @@ -6265,12 +6261,10 @@ void DoPlayerDeathExplode(PLAYERp pp) else { // special line for amoeba - //updatesector(pp->posx, pp->posy, &pp->cursectnum); DoPlayerDeathCheckKick(pp); DoPlayerDeathHurl(pp); DoPlayerDeathFollowKiller(pp); - //pp->posz = pp->loz - PLAYER_DEATH_HEIGHT; } DoPlayerDeathCheckKeys(pp); @@ -6855,8 +6849,6 @@ void InitAllPlayers(void) extern bool NewGame; //int fz,cz; - //getzsofslope(pfirst->cursectnum, pfirst->posx, pfirst->posy, &cz, &fz); - //pfirst->posz = fz - PLAYER_HEIGHT; pfirst->horizon.horiz = q16horiz(0); // Initialize all [MAX_SW_PLAYERS] arrays here! diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 1d1596fba..273a4698d 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -1878,7 +1878,7 @@ void OperateTripTrigger(PLAYERp pp) if (Prediction) return; - if (pp->cursectnum < 0) + if (!pp->insector()) return; SECTORp sectp = pp->cursector(); @@ -2014,7 +2014,7 @@ void OperateContinuousTrigger(PLAYERp pp) if (Prediction) return; - if (pp->cursectnum < 0) + if (!pp->insector()) return; switch (pp->cursector()->lotag) diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 86a54a094..39e733e15 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -239,6 +239,11 @@ inline void ChangeActorSect(DSWActor* actor, int sect) changespritesect(actor->GetSpriteIndex(), sect); } +inline void ChangeActorSect(DSWActor* actor, sectortype* sect) +{ + changespritesect(actor->GetSpriteIndex(), sectnum(sect)); +} + inline int SetActorZ(DSWActor* actor, const vec3_t* newpos) { return setspritez(actor->GetSpriteIndex(), newpos); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 67e42dc69..8ce992f11 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -11838,7 +11838,7 @@ void InitSpellRing(PLAYERp pp) if (!SW_SHAREWARE) PlaySound(DIGI_RFWIZ, pp, v3df_none); - if (pp->cursectnum < 0) + if (!pp->insector()) return; for (missiles = 0, ang = ang_start; missiles < max_missiles; ang += ang_diff, missiles++) @@ -12219,7 +12219,7 @@ void InitSpellNapalm(PLAYERp pp) PlaySound(DIGI_NAPFIRE, pp, v3df_none); - if (pp->cursectnum < 0) + if (!pp->insector()) return; for (i = 0; i < SIZ(mp); i++) @@ -12373,7 +12373,7 @@ int InitSpellMirv(PLAYERp pp) PlaySound(DIGI_MIRVFIRE, pp, v3df_none); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; auto actorNew = SpawnActor(STAT_MISSILE, FIREBALL1, s_Mirv, pp->cursector(), @@ -13341,7 +13341,7 @@ int InitStar(PLAYERp pp) PlaySound(DIGI_STAR, pp, v3df_dontpan|v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -13458,7 +13458,7 @@ void InitHeartAttack(PLAYERp pp) PlayerUpdateAmmo(pp, WPN_HEART, -1); - if (pp->cursectnum < 0) + if (!pp->insector()) return; auto actorNew = SpawnActor(STAT_MISSILE_SKIP4, BLOOD_WORM, s_BloodWorm, pp->cursector(), @@ -13764,7 +13764,7 @@ int InitLaser(PLAYERp pp) PlayerUpdateAmmo(pp, u->WeaponNum, -1); PlaySound(DIGI_RIOTFIRE, pp, v3df_dontpan|v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -13873,7 +13873,7 @@ int InitRail(PLAYERp pp) // Make sprite shade brighter u->Vis = 128; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -14054,7 +14054,7 @@ int InitRocket(PLAYERp pp) // Make sprite shade brighter u->Vis = 128; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -14167,7 +14167,7 @@ int InitBunnyRocket(PLAYERp pp) PlaySound(DIGI_BUNNYATTACK, pp, v3df_dontpan|v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -14276,7 +14276,7 @@ int InitNuke(PLAYERp pp) // Make sprite shade brighter u->Vis = 128; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -14457,7 +14457,7 @@ int InitMicro(PLAYERp pp) if (TargetSortCount > MAX_MICRO) TargetSortCount = MAX_MICRO; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; for (i = 0; i < MAX_MICRO; i++) @@ -15810,7 +15810,7 @@ int DoDefaultStat(DSWActor* actor) int InitTracerUzi(PLAYERp pp) { - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; USERp u = pp->Actor()->u(); @@ -16604,7 +16604,7 @@ int InitTurretRail(DSWActor* actor, PLAYERp pp) if (SW_SHAREWARE) return false; // JBF: verify - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = sp->x; @@ -16660,7 +16660,7 @@ int InitTurretLaser(DSWActor* actor, PLAYERp pp) if (SW_SHAREWARE) return false; // JBF: verify - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = sp->x; @@ -17418,7 +17418,7 @@ int InitGrenade(PLAYERp pp) // Make sprite shade brighter u->Vis = 128; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -17576,7 +17576,7 @@ int InitMine(PLAYERp pp) PlaySound(DIGI_MINETHROW, pp, v3df_dontpan|v3df_doppler); - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx = pp->posx; @@ -17723,7 +17723,7 @@ int InitFireball(PLAYERp pp) // Make sprite shade brighter u->Vis = 128; - if (pp->cursectnum < 0) + if (!pp->insector()) return 0; nx += pp->posx;