From a789fe97afc6fd4e859001ba19c9649d02be8965 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 13 Nov 2021 20:48:43 +0100 Subject: [PATCH] - handled all sector iterators. Again mostly cppy/paste. --- source/games/whaven/src/aifred.cpp | 23 ++++++++++++----------- source/games/whaven/src/aigonzo.cpp | 22 ++++++++++++---------- source/games/whaven/src/aiimp.cpp | 24 +++++++++++++----------- source/games/whaven/src/aikobold.cpp | 24 +++++++++++++----------- source/games/whaven/src/aikurt.cpp | 24 +++++++++++++----------- source/games/whaven/src/aiminotaur.cpp | 24 +++++++++++++----------- source/games/whaven/src/aiskeleton.cpp | 24 +++++++++++++----------- source/games/whaven/src/aispider.cpp | 24 +++++++++++++----------- source/games/whaven/src/whobj.cpp | 24 +++++++++++++----------- 9 files changed, 115 insertions(+), 98 deletions(-) diff --git a/source/games/whaven/src/aifred.cpp b/source/games/whaven/src/aifred.cpp index e5744c87e..067ca292c 100644 --- a/source/games/whaven/src/aifred.cpp +++ b/source/games/whaven/src/aifred.cpp @@ -278,24 +278,25 @@ static void resurectfred(PLAYER& plr, short i) { static void checkexplfred(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aigonzo.cpp b/source/games/whaven/src/aigonzo.cpp index 7214b0284..eec20ec08 100644 --- a/source/games/whaven/src/aigonzo.cpp +++ b/source/games/whaven/src/aigonzo.cpp @@ -673,23 +673,25 @@ static void gonzopike(short s, PLAYER& plr) { static void checkexplgonzo(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - long dx = abs(spr.x - sprite[j].x); // x distance to sprite - long dy = abs(spr.y - sprite[j].y); // y distance to sprite - long dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - long dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aiimp.cpp b/source/games/whaven/src/aiimp.cpp index 42d269c46..5e16ad4cb 100644 --- a/source/games/whaven/src/aiimp.cpp +++ b/source/games/whaven/src/aiimp.cpp @@ -290,24 +290,26 @@ static void skirmishimp(PLAYER& plr, short i) { static void checkexplimp(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aikobold.cpp b/source/games/whaven/src/aikobold.cpp index 667c82f24..6ccb2f45f 100644 --- a/source/games/whaven/src/aikobold.cpp +++ b/source/games/whaven/src/aikobold.cpp @@ -310,24 +310,26 @@ static void skirmishkobold(PLAYER& plr, short i) { static void checkexplkobold(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aikurt.cpp b/source/games/whaven/src/aikurt.cpp index d79a9a4b4..4e7fa1bb3 100644 --- a/source/games/whaven/src/aikurt.cpp +++ b/source/games/whaven/src/aikurt.cpp @@ -34,22 +34,24 @@ static void kurtExplo(PLAYER& plr, short i) { if (spr.lotag < 0) spr.lotag = 12; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].detail == KURTTYPE) { - sprite[j].hitag -= TICSPERFRAME << 4; - if (sprite[j].hitag < 0) { + if (tspr.detail == KURTTYPE) { + tspr.hitag -= TICSPERFRAME << 4; + if (tspr.hitag < 0) { newstatus(j, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aiminotaur.cpp b/source/games/whaven/src/aiminotaur.cpp index 2366a82ad..8d372fe47 100644 --- a/source/games/whaven/src/aiminotaur.cpp +++ b/source/games/whaven/src/aiminotaur.cpp @@ -307,24 +307,26 @@ static void searchminotaur(PLAYER& plr, short i) { static void checkexplminotaur(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aiskeleton.cpp b/source/games/whaven/src/aiskeleton.cpp index 69129afd5..64bfc1917 100644 --- a/source/games/whaven/src/aiskeleton.cpp +++ b/source/games/whaven/src/aiskeleton.cpp @@ -331,24 +331,26 @@ void skeletonChill(PLAYER& plr, short i) { static void checkexplskeleton(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/aispider.cpp b/source/games/whaven/src/aispider.cpp index 6f3b59872..a5b635990 100644 --- a/source/games/whaven/src/aispider.cpp +++ b/source/games/whaven/src/aispider.cpp @@ -276,24 +276,26 @@ static void diespider(PLAYER& plr, short i) { static void checkexplspider(PLAYER& plr, short i) { SPRITE& spr = sprite[i]; - short j = headspritesect[spr.sectnum]; - while (j != -1) { - short nextj = nextspritesect[j]; - int dx = abs(spr.x - sprite[j].x); // x distance to sprite - int dy = abs(spr.y - sprite[j].y); // y distance to sprite - int dz = abs((spr.z >> 8) - (sprite[j].z >> 8)); // z distance to sprite - int dh = tileHeight(sprite[j].picnum) >> 1; // height of sprite + WHSectIterator it(spr.sectnum); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int j = actor->GetSpriteIndex(); + + int dx = abs(spr.x - tspr.x); // x distance to sprite + int dy = abs(spr.y - tspr.y); // y distance to sprite + int dz = abs((spr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + int dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if (sprite[j].picnum == EXPLO2 - || sprite[j].picnum == SMOKEFX - || sprite[j].picnum == MONSTERBALL) { + if (tspr.picnum == EXPLO2 + || tspr.picnum == SMOKEFX + || tspr.picnum == MONSTERBALL) { spr.hitag -= TICSPERFRAME << 2; if (spr.hitag < 0) { newstatus(i, DIE); } } } - j = nextj; } } diff --git a/source/games/whaven/src/whobj.cpp b/source/games/whaven/src/whobj.cpp index 0312c0265..d190dac23 100644 --- a/source/games/whaven/src/whobj.cpp +++ b/source/games/whaven/src/whobj.cpp @@ -109,27 +109,29 @@ int getPickHeight() { void processobjs(PLAYER& plr) { - int dh, dx, dy, dz, i, nexti; + int dh, dx, dy, dz; if (plr.sector < 0 || plr.sector >= numsectors) return; - i = headspritesect[plr.sector]; - while (i != -1) { - nexti = nextspritesect[i]; - dx = abs(plr.x - sprite[i].x); // x distance to sprite - dy = abs(plr.y - sprite[i].y); // y distance to sprite - dz = abs((plr.z >> 8) - (sprite[i].z >> 8)); // z distance to sprite - dh = tileHeight(sprite[i].picnum) >> 1; // height of sprite + WHSectIterator it(plr.sector); + while (auto actor = it.Next()) + { + SPRITE& tspr = actor->s(); + int i = actor->GetSpriteIndex(); + + dx = abs(plr.x - tspr.x); // x distance to sprite + dy = abs(plr.y - tspr.y); // y distance to sprite + dz = abs((plr.z >> 8) - (tspr.z >> 8)); // z distance to sprite + dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { if(isItemSprite(i)) - items[(sprite[i].detail & 0xFF) - ITEMSBASE].pickup(plr, (short)i); + items[(tspr.detail & 0xFF) - ITEMSBASE].pickup(plr, (short)i); - if (sprite[i].picnum >= EXPLOSTART && sprite[i].picnum <= EXPLOEND && sprite[i].owner != sprite[plr.spritenum].owner) + if (tspr.picnum >= EXPLOSTART && tspr.picnum <= EXPLOEND && tspr.owner != sprite[plr.spritenum].owner) if (plr.manatime < 1) addhealth(plr, -1); } - i = nexti; } }