diff --git a/source/blood/src/mirrors.cpp b/source/blood/src/mirrors.cpp index 243948c61..6e44e7146 100644 --- a/source/blood/src/mirrors.cpp +++ b/source/blood/src/mirrors.cpp @@ -204,7 +204,9 @@ void sub_557C4(int x, int y, int interpolation) { int nSector = mirror[i].Kills; int nSector2 = mirror[i].at14; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite == gView->pSprite) diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index b015339ba..eb04eff56 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -1967,8 +1967,10 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) { } // search for dudes in this sector and change their underwater status - for (int nSprite = headspritesect[objIndex]; nSprite >= 0; nSprite = nextspritesect[nSprite]) { - + int nSprite; + SectIterator it(objIndex); + while ((nSprite = it.NextIndex()) >= 0) + { spritetype* pSpr = &sprite[nSprite]; if (pSpr->statnum != kStatDude || !IsDudeSprite(pSpr) || !xspriRangeIsFine(pSpr->extra)) continue; @@ -2744,7 +2746,10 @@ bool condCheckSector(XSPRITE* pXCond, int cmpOp, bool PUSH) { case 5: return condCmp(pSect->floorheinum, arg1, arg2, cmpOp); case 6: return condCmp(pSect->ceilingheinum, arg1, arg2, cmpOp); case 10: // required sprite type is in current sector? - for (var = headspritesect[objIndex]; var >= 0; var = nextspritesect[var]) { + int nSprite; + SectIterator it(objIndex); + while ((nSprite = it.NextIndex()) >= 0) + { if (!condCmp(sprite[var].type, arg1, arg2, cmpOp)) continue; else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); return true; diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 0ea768cea..eeedcfb36 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -675,7 +675,10 @@ void playerStart(int nPlayer, int bNewLevel) if (maxRetries != 0) { // check if there is no spawned player in selected zone - for (int i = headspritesect[pStartZone->sectnum]; i >= 0; i = nextspritesect[i]) { + int i; + SectIterator it(pStartZone->sectnum); + while ((i = it.NextIndex()) >= 0) + { spritetype* pSprite = &sprite[i]; if (pStartZone->x == pSprite->x && pStartZone->y == pSprite->y && IsPlayerSprite(pSprite)) { pStartZone = NULL; diff --git a/source/blood/src/triggers.cpp b/source/blood/src/triggers.cpp index 159b084b0..4c5574c64 100644 --- a/source/blood/src/triggers.cpp +++ b/source/blood/src/triggers.cpp @@ -760,7 +760,9 @@ void OperateWall(int nWall, XWALL *pXWall, EVENT event) { void SectorStartSound(int nSector, int nState) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) @@ -784,7 +786,9 @@ void SectorStartSound(int nSector, int nState) void SectorEndSound(int nSector, int nState) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) @@ -808,7 +812,9 @@ void SectorEndSound(int nSector, int nState) void PathSound(int nSector, int nSound) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDecoration && pSprite->type == kSoundSector) @@ -920,7 +926,9 @@ void TranslateSector(int nSector, int a2, int a3, int a4, int a5, int a6, int a7 } } } - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; // allow to move markers by sector movements in game if flags 1 is added in editor. @@ -983,7 +991,9 @@ void ZTranslateSector(int nSector, XSECTOR *pXSector, int a3, int a4) int oldZ = pSector->floorz; baseFloor[nSector] = pSector->floorz = pXSector->offFloorZ + mulscale16(dz, GetWaveValue(a3, a4)); velFloor[nSector] += (pSector->floorz-oldZ)<<8; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker) @@ -1010,7 +1020,9 @@ void ZTranslateSector(int nSector, XSECTOR *pXSector, int a3, int a4) int oldZ = pSector->ceilingz; baseCeil[nSector] = pSector->ceilingz = pXSector->offCeilZ + mulscale16(dz, GetWaveValue(a3, a4)); velCeil[nSector] += (pSector->ceilingz-oldZ)<<8; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatMarker || pSprite->statnum == kStatPathMarker) @@ -1028,7 +1040,9 @@ int GetHighestSprite(int nSector, int nStatus, int *a3) { *a3 = sector[nSector].floorz; int v8 = -1; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { if (sprite[nSprite].statnum == nStatus || nStatus == kStatFree) { @@ -1052,7 +1066,9 @@ int GetCrushedSpriteExtents(unsigned int nSector, int *pzTop, int *pzBot) int vc = -1; sectortype *pSector = §or[nSector]; int vbp = pSector->ceilingz; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDude || pSprite->statnum == kStatThing) @@ -1124,7 +1140,9 @@ int VSpriteBusy(unsigned int nSector, unsigned int a2) int dz1 = pXSector->onFloorZ - pXSector->offFloorZ; if (dz1 != 0) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->cstat&8192) @@ -1137,7 +1155,9 @@ int VSpriteBusy(unsigned int nSector, unsigned int a2) int dz2 = pXSector->onCeilZ - pXSector->offCeilZ; if (dz2 != 0) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->cstat&16384) @@ -1430,7 +1450,9 @@ void OperateDoor(unsigned int nSector, XSECTOR *pXSector, EVENT event, BUSYID bu char SectorContainsDudes(int nSector) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { if (sprite[nSprite].statnum == kStatDude) return 1; @@ -1440,7 +1462,9 @@ char SectorContainsDudes(int nSector) void TeleFrag(int nKiller, int nSector) { - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDude) @@ -1459,7 +1483,9 @@ void OperateTeleport(unsigned int nSector, XSECTOR *pXSector) assert(pDest->statnum == kStatMarker); assert(pDest->type == kMarkerWarpDest); assert(pDest->sectnum >= 0 && pDest->sectnum < kMaxSectors); - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->statnum == kStatDude) @@ -1887,7 +1913,9 @@ void ProcessMotion(void) else pXSector->bobTheta += mulscale16(pXSector->bobSpeed, pXSector->busy); int vdi = mulscale30(Sin(pXSector->bobTheta), pXSector->bobZRange<<8); - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->cstat&24576) @@ -1901,7 +1929,9 @@ void ProcessMotion(void) int floorZ = pSector->floorz; viewInterpolateSector(nSector, pSector); pSector->floorz = baseFloor[nSector]+vdi; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; if (pSprite->flags&2) @@ -1923,7 +1953,9 @@ void ProcessMotion(void) int ceilZ = pSector->ceilingz; viewInterpolateSector(nSector, pSector); pSector->ceilingz = baseCeil[nSector]+vdi; - for (int nSprite = headspritesect[nSector]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(nSector); + while ((nSprite = it.NextIndex()) >= 0) { spritetype *pSprite = &sprite[nSprite]; int top, bottom; @@ -2072,7 +2104,9 @@ void trInit(void) baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x; baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y; } - for (int nSprite = headspritesect[i]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(i); + while ((nSprite = it.NextIndex()) >= 0) { baseSprite[nSprite].x = sprite[nSprite].x; baseSprite[nSprite].y = sprite[nSprite].y; @@ -2092,7 +2126,9 @@ void trInit(void) baseWall[pSector->wallptr+j].x = wall[pSector->wallptr+j].x; baseWall[pSector->wallptr+j].y = wall[pSector->wallptr+j].y; } - for (int nSprite = headspritesect[i]; nSprite >= 0; nSprite = nextspritesect[nSprite]) + int nSprite; + SectIterator it(i); + while ((nSprite = it.NextIndex()) >= 0) { baseSprite[nSprite].x = sprite[nSprite].x; baseSprite[nSprite].y = sprite[nSprite].y;