diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index 0586a0772..0b6b4c759 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -47,10 +47,9 @@ bool FindSector(int nX, int nY, int nZ, int *nSector) return 1; } } - walltype *pWall = &wall[sector[*nSector].wallptr]; - for (int i = sector[*nSector].wallnum; i > 0; i--, pWall++) + for (auto& wal : wallsofsector(*nSector)) { - int nOSector = pWall->nextsector; + int nOSector = wal.nextsector; if (nOSector >= 0 && inside(nX, nY, nOSector)) { getzsofslope(nOSector, nX, nY, &nZCeil, &nZFloor); @@ -83,10 +82,9 @@ bool FindSector(int nX, int nY, int *nSector) { return 1; } - walltype *pWall = &wall[sector[*nSector].wallptr]; - for (int i = sector[*nSector].wallnum; i > 0; i--, pWall++) + for (auto& wal : wallsofsector(*nSector)) { - int nOSector = pWall->nextsector; + int nOSector = wal.nextsector; if (nOSector >= 0 && inside(nX, nY, nOSector)) { *nSector = nOSector; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index fab8d449d..ba95ec13f 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -6014,13 +6014,13 @@ bool modernTypeOperateWall(int nWall, walltype* pWall, XWALL* pXWall, EVENT even case kSwitchOneWay: switch (event.cmd) { case kCmdOff: - SetWallState(nWall, pXWall, 0); + SetWallState(pWall, 0); break; case kCmdOn: - SetWallState(nWall, pXWall, 1); + SetWallState(pWall, 1); break; default: - SetWallState(nWall, pXWall, pXWall->restState ^ 1); + SetWallState(pWall, pXWall->restState ^ 1); break; } return true; diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index 046bd486f..050e0a273 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -75,21 +75,22 @@ bool SetSpriteState(DBloodActor* actor, int nState) return 1; } -bool SetWallState(int nWall, XWALL *pXWall, int nState) +bool SetWallState(walltype* pWall, int nState) { + auto pXWall = &pWall->xw(); if ((pXWall->busy&0xffff) == 0 && pXWall->state == nState) return 0; pXWall->busy = IntToFixed(nState); pXWall->state = nState; - evKillWall(nWall); + evKillWall(wallnum(pWall)); if (pXWall->restState != nState && pXWall->waitTime > 0) - evPostWall(nWall, (pXWall->waitTime*120) / 10, pXWall->restState ? kCmdOn : kCmdOff); + evPostWall(wallnum(pWall), (pXWall->waitTime*120) / 10, pXWall->restState ? kCmdOn : kCmdOff); if (pXWall->txID) { if (pXWall->command != kCmdLink && pXWall->triggerOn && pXWall->state) - evSendWall(&wall[nWall], pXWall->txID, (COMMAND_ID)pXWall->command); + evSendWall(pWall, pXWall->txID, (COMMAND_ID)pXWall->command); if (pXWall->command != kCmdLink && pXWall->triggerOff && !pXWall->state) - evSendWall(&wall[nWall], pXWall->txID, (COMMAND_ID)pXWall->command); + evSendWall(pWall, pXWall->txID, (COMMAND_ID)pXWall->command); } return 1; } @@ -670,13 +671,13 @@ void OperateWall(walltype* pWall, EVENT event) { switch (event.cmd) { case kCmdOn: case kCmdWallImpact: - bStatus = SetWallState(wallnum(pWall), pXWall, 1); + bStatus = SetWallState(pWall, 1); break; case kCmdOff: - bStatus = SetWallState(wallnum(pWall), pXWall, 0); + bStatus = SetWallState(pWall, 0); break; default: - bStatus = SetWallState(wallnum(pWall), pXWall, pXWall->state ^ 1); + bStatus = SetWallState(pWall, pXWall->state ^ 1); break; } @@ -693,13 +694,13 @@ void OperateWall(walltype* pWall, EVENT event) { default: switch (event.cmd) { case kCmdOff: - SetWallState(wallnum(pWall), pXWall, 0); + SetWallState(pWall, 0); break; case kCmdOn: - SetWallState(wallnum(pWall), pXWall, 1); + SetWallState(pWall, 1); break; default: - SetWallState(wallnum(pWall), pXWall, pXWall->state ^ 1); + SetWallState(pWall, pXWall->state ^ 1); break; } return; @@ -1710,7 +1711,7 @@ void LinkWall(int nWall, XWALL *pXWall, EVENT event) int nBusy = GetSourceBusy(event); pXWall->busy = nBusy; if ((pXWall->busy & 0xffff) == 0) - SetWallState(nWall, pXWall, FixedToInt(nBusy)); + SetWallState(&wall[nWall], FixedToInt(nBusy)); } void trTriggerSector(sectortype* pSector, int command) diff --git a/source/games/blood/src/triggers.h b/source/games/blood/src/triggers.h index aefb16389..216079326 100644 --- a/source/games/blood/src/triggers.h +++ b/source/games/blood/src/triggers.h @@ -63,7 +63,7 @@ void trProcessBusy(void); void trInit(void); void trTextOver(int nId); bool SetSpriteState(DBloodActor* actor, int nState); -bool SetWallState(int nWall, XWALL* pXWall, int nState); +bool SetWallState(walltype* pWall, int nState); bool SetSectorState(int nSector, XSECTOR* pXSector, int nState); void TeleFrag(DBloodActor* killer, int nSector); void SectorStartSound(int nSector, int nState);