diff --git a/source/games/whaven/src/aigoblin.cpp b/source/games/whaven/src/aigoblin.cpp index a710760cf..c27797079 100644 --- a/source/games/whaven/src/aigoblin.cpp +++ b/source/games/whaven/src/aigoblin.cpp @@ -383,14 +383,17 @@ static void goblinWar(PLAYER& plr, DWHActor* actor) { int olddist = 1024 << 4; boolean found = false; - for (k = 0; k < MAXSPRITES; k++) { - if (sprite[k].picnum == GOBLIN && spr.pal != sprite[k].pal && spr.hitag == sprite[k].hitag) { - int dist = abs(spr.x - sprite[k].x) + abs(spr.y - sprite[k].y); + WHSpriteIterator it; + while (auto itActor = it.Next()) + { + auto& spk = itActor->s(); + if (spk.picnum == GOBLIN && spr.pal != spk.pal && spr.hitag == spk.hitag) { + int dist = abs(spr.x - spk.x) + abs(spr.y - spk.y); if (dist < olddist) { found = true; olddist = dist; - spr.owner = k; - spr.ang = getangle(sprite[k].x - spr.x, sprite[k].y - spr.y); + spr.owner = itActor->GetSpriteIndex(); + spr.ang = getangle(spk.x - spr.x, spk.y - spr.y); spr.extra = 1; } } diff --git a/source/games/whaven/src/aikatie.cpp b/source/games/whaven/src/aikatie.cpp index 0103a470b..019a405db 100644 --- a/source/games/whaven/src/aikatie.cpp +++ b/source/games/whaven/src/aikatie.cpp @@ -235,12 +235,15 @@ static void castkatie(PLAYER& plr, DWHActor* actor) if (spr.picnum == KATIEAT + 6) { if (spr.extra == 1) { - for (short j = 0; j < MAXSPRITES; j++) { - if (sprite[j].pal == 8) { - sprite[j].picnum--; - sprite[j].pal = 0; - sprite[j].shade = 0; - changespritestat(j, FACE); + WHSpriteIterator it; + while (auto itActor = it.Next()) + { + auto& spk = itActor->s(); + if (spk.pal == 8) { + spk.picnum--; + spk.pal = 0; + spk.shade = 0; + ChangeActorStat(itActor, FACE); } } spr.picnum = KATIE; diff --git a/source/games/whaven/src/main.cpp b/source/games/whaven/src/main.cpp index 0de41162b..1f6338342 100644 --- a/source/games/whaven/src/main.cpp +++ b/source/games/whaven/src/main.cpp @@ -648,9 +648,10 @@ bool playrunning() static void recordoldspritepos() { - for (int i = 0; i < MAXSPRITES; i++) + WHSpriteIterator it; + while (auto itActor = it.Next()) { - sprite[i].backuploc(); + itActor->s().backuploc(); } } diff --git a/source/games/whaven/src/precache.cpp b/source/games/whaven/src/precache.cpp index 689fc915a..17794fe83 100644 --- a/source/games/whaven/src/precache.cpp +++ b/source/games/whaven/src/precache.cpp @@ -70,9 +70,10 @@ void precacheTiles() addTile(wall[i].overpicnum); } } - for (int i = 0; i < MAXSPRITES; i++) { - if (sprite[i].statnum < MAXSTATUS) - cachespritenum(i); + WHSpriteIterator it; + while (auto itActor = it.Next()) + { + cachespritenum(itActor->GetSpriteIndex()); } addTile(BAT); diff --git a/source/games/whaven/src/whfx.cpp b/source/games/whaven/src/whfx.cpp index bca14bc06..929c80c7c 100644 --- a/source/games/whaven/src/whfx.cpp +++ b/source/games/whaven/src/whfx.cpp @@ -941,11 +941,14 @@ void cracks() { if (datag == 3001) { sector[plr.sector].lotag = 0; - for (short k = 0; k < MAXSPRITES; k++) { - if (sector[plr.sector].hitag == sprite[k].hitag) { - sprite[k].lotag = 36; - sprite[k].zvel = (short) (krand() & 1024 + 512); - newstatus(k, SHOVE); + WHSpriteIterator it; + while (auto itActor = it.Next()) + { + auto& spk = itActor->s(); + if (sector[plr.sector].hitag == spk.hitag) { + spk.lotag = 36; + spk.zvel = (short) (krand() & 1024 + 512); + SetNewStatus(itActor, SHOVE); } } }