diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index 59ead45e3..d493ee6c2 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -33,7 +33,7 @@ DExhumedActor* BuildAnim(DExhumedActor* actor, int val, int val2, int x, int y, void FuncAnim(int, int, int, int); void BuildExplosion(DExhumedActor* actor); -void BuildSplash(DExhumedActor* actor, int nSector); +void BuildSplash(DExhumedActor* actor, sectortype* nSector); // anubis diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index f3dd61aff..5d85d4531 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -255,7 +255,7 @@ void BuildExplosion(DExhumedActor* pActor) BuildAnim(nullptr, edx, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->xrepeat, 4); } -void BuildSplash(DExhumedActor* actor, int nSector) +void BuildSplash(DExhumedActor* actor, sectortype* pSector) { auto pSprite = &actor->s(); int nRepeat, nSound; @@ -271,7 +271,7 @@ void BuildSplash(DExhumedActor* actor, int nSector) nSound = kSound1; } - int bIsLava = sector[nSector].Flag & kSectLava; + int bIsLava = pSector->Flag & kSectLava; int edx, nFlag; @@ -286,7 +286,7 @@ void BuildSplash(DExhumedActor* actor, int nSector) nFlag = 0; } - auto pActor = BuildAnim(nullptr, edx, 0, pSprite->x, pSprite->y, sector[nSector].floorz, nSector, nRepeat, nFlag); + auto pActor = BuildAnim(nullptr, edx, 0, pSprite->x, pSprite->y, pSector->floorz, sectnum(pSector), nRepeat, nFlag); if (!bIsLava) { diff --git a/source/games/exhumed/src/anubis.cpp b/source/games/exhumed/src/anubis.cpp index a3179a8ab..ff0f94fb9 100644 --- a/source/games/exhumed/src/anubis.cpp +++ b/source/games/exhumed/src/anubis.cpp @@ -220,8 +220,8 @@ void AIAnubis::Tick(RunListEvent* ev) if (pTarget != nullptr) // NOTE: nTarget can be -1. this check wasn't in original code. TODO: demo compatiblity? { - if (cansee(sp->x, sp->y, sp->z - GetActorHeight(ap), sp->sectnum, - pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sectnum)) + if (cansee(sp->x, sp->y, sp->z - GetActorHeight(ap), sp->sector(), + pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sector())) { sp->xvel = 0; sp->yvel = 0; diff --git a/source/games/exhumed/src/bullet.cpp b/source/games/exhumed/src/bullet.cpp index 63bfbe933..1cc3e699e 100644 --- a/source/games/exhumed/src/bullet.cpp +++ b/source/games/exhumed/src/bullet.cpp @@ -488,15 +488,14 @@ HITSPRITE: auto pWall = &wall[hitwall]; if (pWall->picnum == kEnergy1) { - int nSector = pWall->nextsector; - if (nSector > -1) + if (pWall->twoSided()) { int nDamage = BulletInfo[pBullet->nType].nDamage; if (pBullet->nDoubleDamage > 1) { nDamage *= 2; } - runlist_DamageEnemy(EnergyBlocks[sector[nSector].extra], pActor, nDamage); + runlist_DamageEnemy(EnergyBlocks[pWall->nextSector()->extra], pActor, nDamage); } } } @@ -511,7 +510,7 @@ HITSPRITE: pSprite->x = x2; pSprite->y = y2; pSprite->z = z2; - BuildSplash(pActor, hitsect); + BuildSplash(pActor, pHitSect); } else { diff --git a/source/games/exhumed/src/lavadude.cpp b/source/games/exhumed/src/lavadude.cpp index 708070e04..8702eb22c 100644 --- a/source/games/exhumed/src/lavadude.cpp +++ b/source/games/exhumed/src/lavadude.cpp @@ -260,7 +260,7 @@ void AILavaDude::Tick(RunListEvent* ev) if (pTarget && nAction < 4) { - if (!(pTarget->s().cstat & 0x101) || pTarget->s().sectnum >= 1024) + if (!(pTarget->s().cstat & 0x101) || pTarget->s().statnum == MAXSTATUS) { pTarget = nullptr; pActor->pTarget = nullptr; diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index c6aae9028..93a5daf0c 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -223,10 +223,10 @@ void clipwall() } -int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int nSector) +int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int _nSector) { auto pSprite = &pActor->s(); - nSector = pSprite->sectnum; + auto pSector = pSprite->sector(); int z = pSprite->z; int z2; @@ -237,44 +237,43 @@ int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int nSector) } else { - z2 = sector[nSector].floorz + sector[nSector].Depth; + z2 = pSector->floorz + pSector->Depth; - BFSSearch search(numsectors, nSector); + BFSSectorSearch search(pSector); - int edx = 0; - for (unsigned nCurSector; (nCurSector = search.GetNext()) != BFSSearch::EOL;) + sectortype* pTempSect = nullptr; + while (auto pCurSector = search.GetNext()) { - for (auto& wal : wallsofsector(nCurSector)) + for (auto& wal : wallsofsector(pCurSector)) { - int nNextSector = wal.nextsector; - if (nNextSector >= 0) + if (wal.twoSided()) { - if (!search.Check(nNextSector)) + if (!search.Check(wal.nextSector())) { vec2_t pos = { x, y }; if (clipinsidebox(&pos, wallnum(&wal), walldist)) { - search.Add(nNextSector); + search.Add(wal.nextSector()); } } } } - int nSect2 = nCurSector; + auto pSect2 = pCurSector; - while (nSect2 >= 0) + while (pSect2) { - edx = nSect2; - nSect2 = sector[nSect2].Below; + pTempSect = pSect2; + pSect2 = pSect2->Below>=0? §or[pSect2->Below] : nullptr; } - int ecx = sector[edx].floorz + sector[edx].Depth; + int ecx = pTempSect->floorz + pTempSect->Depth; int eax = ecx - z; if (eax < 0 && eax >= -5120) { z2 = ecx; - nSector = edx; + pSector = pTempSect; } } } @@ -283,7 +282,7 @@ int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int nSector) if (z2 < pSprite->z) { pSprite->z = z2; - overridesect = nSector; + overridesect = sectnum(pSector); pSprite->zvel = 0; bTouchFloor = true; @@ -300,6 +299,7 @@ Collision movespritez(DExhumedActor* pActor, int z, int height, int, int clipdis { spritetype* pSprite = &pActor->s(); int nSector =pSprite->sectnum; + auto pSector = pSprite->sector(); assert(validSectorIndex(nSector)); overridesect = nSector; @@ -456,7 +456,7 @@ Collision movespritez(DExhumedActor* pActor, int z, int height, int, int clipdis if ((sector[nSector].Depth != 0) || (edi != nSector && (sector[edi].Flag & kSectUnderwater))) { assert(validSectorIndex(nSector)); - BuildSplash(pActor, nSector); + BuildSplash(pActor, pSector); } } diff --git a/source/games/exhumed/src/mummy.cpp b/source/games/exhumed/src/mummy.cpp index 338a59f66..6d3e4dd1c 100644 --- a/source/games/exhumed/src/mummy.cpp +++ b/source/games/exhumed/src/mummy.cpp @@ -214,8 +214,8 @@ void AIMummy::Tick(RunListEvent* ev) { if (RandomBit() && pTarget) { - if (cansee(pSprite->x, pSprite->y, pSprite->z - GetActorHeight(pActor), pSprite->sectnum, - pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sectnum)) + if (cansee(pSprite->x, pSprite->y, pSprite->z - GetActorHeight(pActor), pSprite->sector(), + pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sector())) { pActor->nAction = 3; pActor->nFrame = 0; diff --git a/source/games/exhumed/src/rat.cpp b/source/games/exhumed/src/rat.cpp index 85ea1a602..74fb3831c 100644 --- a/source/games/exhumed/src/rat.cpp +++ b/source/games/exhumed/src/rat.cpp @@ -129,12 +129,12 @@ void BuildRat(DExhumedActor* pActor, int x, int y, int z, int nSector, int nAngl DExhumedActor* FindFood(DExhumedActor* pActor) { auto pSprite = &pActor->s(); - int nSector = pSprite->sectnum; + auto pSector = pSprite->sector(); int x = pSprite->x; int y = pSprite->y; int z = pSprite->z; - int z2 = (z + sector[nSector].ceilingz) / 2; + int z2 = (z + pSector->ceilingz) / 2; if (nChunkTotal) { @@ -142,7 +142,7 @@ DExhumedActor* FindFood(DExhumedActor* pActor) if (pActor2 != nullptr) { auto pSprite2 = &pActor2->s(); - if (cansee(x, y, z2, nSector, pSprite2->x, pSprite2->y, pSprite2->z, pSprite2->sectnum)) { + if (cansee(x, y, z2, pSector, pSprite2->x, pSprite2->y, pSprite2->z, pSprite2->sector())) { return pActor2; } } @@ -158,7 +158,7 @@ DExhumedActor* FindFood(DExhumedActor* pActor) auto pSprite2 = &pActor2->s(); if (nPlayerPic == pSprite2->picnum) { - if (cansee(x, y, z, nSector, pSprite2->x, pSprite2->y, pSprite2->z, pSprite2->sectnum)) { + if (cansee(x, y, z, pSector, pSprite2->x, pSprite2->y, pSprite2->z, pSprite2->sector())) { return pActor2; } } diff --git a/source/games/exhumed/src/runlist.cpp b/source/games/exhumed/src/runlist.cpp index 2aa19459d..994dfd128 100644 --- a/source/games/exhumed/src/runlist.cpp +++ b/source/games/exhumed/src/runlist.cpp @@ -1783,9 +1783,9 @@ void runlist_DamageEnemy(DExhumedActor* pActor, DExhumedActor* pActor2, int nDam { // Do a taunt auto pPlayerActor = PlayerList[nPlayer].Actor(); - int nSector = pPlayerActor->s().sectnum; + auto pSector = pPlayerActor->s().sector(); - if (!(sector[nSector].Flag & kSectUnderwater)) + if (!(pSector->Flag & kSectUnderwater)) { int ebx = 0x4000; diff --git a/source/games/exhumed/src/scorp.cpp b/source/games/exhumed/src/scorp.cpp index 0f825002c..afba751f8 100644 --- a/source/games/exhumed/src/scorp.cpp +++ b/source/games/exhumed/src/scorp.cpp @@ -440,8 +440,8 @@ void AIScorp::Effect(RunListEvent* ev, DExhumedActor* pTarget, int mode) { pActor->nCount = 45; - if (cansee(pSprite->x, pSprite->y, pSprite->z - GetActorHeight(pActor), pSprite->sectnum, - pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sectnum)) + if (cansee(pSprite->x, pSprite->y, pSprite->z - GetActorHeight(pActor), pSprite->sector(), + pTarget->s().x, pTarget->s().y, pTarget->s().z - GetActorHeight(pTarget), pTarget->s().sector())) { pSprite->xvel = 0; pSprite->yvel = 0; diff --git a/source/games/exhumed/src/spider.cpp b/source/games/exhumed/src/spider.cpp index 97faacf2b..53adcbdba 100644 --- a/source/games/exhumed/src/spider.cpp +++ b/source/games/exhumed/src/spider.cpp @@ -178,14 +178,14 @@ void AISpider::Tick(RunListEvent* ev) case 3: { case_3: - int nSector =sp->sectnum; + auto pSector =sp->sector(); if (sp->cstat & 8) { sp->zvel = 0; - sp->z = sector[nSector].ceilingz + (tileHeight(sp->picnum) << 5); + sp->z = pSector->ceilingz + (tileHeight(sp->picnum) << 5); - if (sector[nSector].ceilingstat & 1) + if (pSector->ceilingstat & 1) { sp->cstat ^= 8; sp->zvel = 1; @@ -216,7 +216,7 @@ void AISpider::Tick(RunListEvent* ev) { sp->cstat ^= 8; sp->zvel = 1; - sp->z = sector[nSector].ceilingz + GetActorHeight(spp); + sp->z = pSector->ceilingz + GetActorHeight(spp); } else { diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index a0639dd67..b38ac6fee 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -111,7 +111,7 @@ static void analyzesprites(spritetype* tsprite, int& spritesortcnt, int x, int y if (pTSprite->sectnum >= 0) { - sectortype *pSector = §or[pTSprite->sectnum]; + sectortype *pSector = pTSprite->sector(); int nSectShade = (pSector->ceilingstat & 1) ? pSector->ceilingshade : pSector->floorshade; int nShade = pTSprite->shade + nSectShade + 6; pTSprite->shade = clamp(nShade, -128, 127); @@ -305,15 +305,15 @@ void DrawView(double smoothRatio, bool sceneonly) } } } - + auto pSector = §or[nSector]; nCamerax = playerX; nCameray = playerY; nCameraz = playerZ; - int Z = sector[nSector].ceilingz + 256; + int Z = pSector->ceilingz + 256; if (Z <= viewz) { - Z = sector[nSector].floorz - 256; + Z = pSector->floorz - 256; if (Z < viewz) viewz = Z; diff --git a/source/games/exhumed/src/wasp.cpp b/source/games/exhumed/src/wasp.cpp index 71edbdc80..b244d1398 100644 --- a/source/games/exhumed/src/wasp.cpp +++ b/source/games/exhumed/src/wasp.cpp @@ -338,15 +338,15 @@ void AIWasp::Tick(RunListEvent* ev) } case 5: { - int nSector =pSprite->sectnum; + auto pSector =pSprite->sector(); pSprite->z += pSprite->zvel; - if (pSprite->z >= sector[nSector].floorz) + if (pSprite->z >= pSector->floorz) { - if (sector[nSector].Below > -1) + if (pSector->Below > -1) { - BuildSplash(pActor, nSector); + BuildSplash(pActor, pSector); pSprite->cstat |= 0x8000; }