From e3b8980ecd93e7823d55af36158ea4b90dc940ac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 13 Oct 2021 19:13:15 +0200 Subject: [PATCH] - sprite2sectorSlope + useSlopeChanger --- source/games/blood/src/nnexts.cpp | 90 ++++++++++++++++++------------- source/games/blood/src/nnexts.h | 2 +- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 3f90a5a41..df1a17382 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -4755,7 +4755,7 @@ void modernTypeTrigger(int destObjType, int destObjIndex, DBloodActor* destactor { case OBJ_SPRITE: case OBJ_SECTOR: - useSlopeChanger(pXSource, destObjType, destObjIndex); + useSlopeChanger(event.actor, destObjType, destObjIndex, destactor); break; } break; @@ -6457,19 +6457,25 @@ void useIncDecGen(DBloodActor* sourceactor, short objType, int objIndex, DBloodA } } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- -void sprite2sectorSlope(spritetype* pSprite, sectortype* pSector, char rel, bool forcez) { - +void sprite2sectorSlope(DBloodActor* actor, sectortype* pSector, char rel, bool forcez) +{ + auto pSprite = &actor->s(); int slope = 0, z = 0; switch (rel) { default: z = getflorzofslope(pSprite->sectnum, pSprite->x, pSprite->y); - if ((pSprite->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR) && pSprite->extra > 0 && xsprite[pSprite->extra].Touch) z--; + if ((pSprite->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR) && actor->hasX() && actor->x().Touch) z--; slope = pSector->floorheinum; break; case 1: z = getceilzofslope(pSprite->sectnum, pSprite->x, pSprite->y); - if ((pSprite->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR) && pSprite->extra > 0 && xsprite[pSprite->extra].Touch) z++; + if ((pSprite->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR) && actor->hasX() && actor->x().Touch) z++; slope = pSector->ceilingheinum; break; } @@ -6484,10 +6490,12 @@ void sprite2sectorSlope(spritetype* pSprite, sectortype* pSector, char rel, bool // //--------------------------------------------------------------------------- -void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) { +void useSlopeChanger(DBloodActor* sourceactor, int objType, int objIndex, DBloodActor* objActor) +{ + auto pXSource = &sourceactor->x(); + spritetype* pSource = &sourceactor->s(); int slope, oslope, i; - spritetype* pSource = &sprite[pXSource->reference]; bool flag2 = (pSource->flags & kModernTypeFlag2); if (pSource->flags & kModernTypeFlag1) slope = ClipRange(pXSource->data2, -32767, 32767); @@ -6513,21 +6521,24 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) { else { // force closest floor aligned sprites to inherit slope of the sector's floor - for (i = headspritesect[objIndex], oslope = pSect->floorheinum; i != -1; i = nextspritesect[i]) { - if (!(sprite[i].cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; - else if (getflorzofslope(objIndex, sprite[i].x, sprite[i].y) - kSlopeDist <= sprite[i].z) { - - sprite2sectorSlope(&sprite[i], §or[objIndex], 0, true); + oslope = pSect->floorheinum; + BloodSectIterator it(objIndex); + while (auto iactor = it.Next()) + { + auto spr = &iactor->s(); + if (!(spr->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; + else if (getflorzofslope(objIndex, spr->x, spr->y) - kSlopeDist <= spr->z) + { + sprite2sectorSlope(iactor, §or[objIndex], 0, true); // set new slope of floor pSect->floorheinum = slope; // force sloped sprites to be on floor slope z - sprite2sectorSlope(&sprite[i], §or[objIndex], 0, true); + sprite2sectorSlope(iactor, §or[objIndex], 0, true); // restore old slope for next sprite pSect->floorheinum = oslope; - } } @@ -6550,22 +6561,24 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) { } else { - // force closest floor aligned sprites to inherit slope of the sector's ceiling - for (i = headspritesect[objIndex], oslope = pSect->ceilingheinum; i != -1; i = nextspritesect[i]) { - if (!(sprite[i].cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; - else if (getceilzofslope(objIndex, sprite[i].x, sprite[i].y) + kSlopeDist >= sprite[i].z) { - - sprite2sectorSlope(&sprite[i], §or[objIndex], 1, true); + oslope = pSect->ceilingheinum; + BloodSectIterator it(objIndex); + while (auto iactor = it.Next()) + { + auto spr = &iactor->s(); + if (!(spr->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; + else if (getceilzofslope(objIndex, spr->x, spr->y) + kSlopeDist >= spr->z) + { + sprite2sectorSlope(iactor, §or[objIndex], 1, true); // set new slope of ceiling pSect->ceilingheinum = slope; // force sloped sprites to be on ceiling slope z - sprite2sectorSlope(&sprite[i], §or[objIndex], 1, true); + sprite2sectorSlope(iactor, §or[objIndex], 1, true); // restore old slope for next sprite pSect->ceilingheinum = oslope; - } } @@ -6577,21 +6590,26 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) { } // let's give a little impulse to the physics sprites... - for (i = headspritesect[objIndex]; i != -1; i = nextspritesect[i]) { - - if (sprite[i].extra > 0 && xsprite[sprite[i].extra].physAttr > 0) { - xsprite[sprite[i].extra].physAttr |= kPhysFalling; - zvel[i]++; - - } else if ((sprite[i].statnum == kStatThing || sprite[i].statnum == kStatDude) && (sprite[i].flags & kPhysGravity)) { - sprite[i].flags |= kPhysFalling; - zvel[i]++; + BloodSectIterator it(objIndex); + while (auto iactor = it.Next()) + { + auto spr = &iactor->s(); + auto xspr = &iactor->x(); + if (spr->extra > 0 && xspr->physAttr > 0) + { + xspr->physAttr |= kPhysFalling; + iactor->zvel()++; + } + else if ((spr->statnum == kStatThing || spr->statnum == kStatDude) && (spr->flags & kPhysGravity)) + { + spr->flags |= kPhysFalling; + iactor->zvel()++; } } } else if (objType == OBJ_SPRITE) { - spritetype* pSpr = &sprite[objIndex]; + spritetype* pSpr = &objActor->s(); if (!(pSpr->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) pSpr->cstat |= CSTAT_SPRITE_ALIGNMENT_FLOOR; if ((pSpr->cstat & CSTAT_SPRITE_ALIGNMENT_SLOPE) != CSTAT_SPRITE_ALIGNMENT_SLOPE) pSpr->cstat |= CSTAT_SPRITE_ALIGNMENT_SLOPE; @@ -6604,11 +6622,11 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) { if (!sectRangeIsFine(pSpr->sectnum)) break; switch (pXSource->data4) { - case 1: sprite2sectorSlope(pSpr, §or[pSpr->sectnum], 0, flag2); break; - case 2: sprite2sectorSlope(pSpr, §or[pSpr->sectnum], 1, flag2); break; + case 1: sprite2sectorSlope(objActor, §or[pSpr->sectnum], 0, flag2); break; + case 2: sprite2sectorSlope(objActor, §or[pSpr->sectnum], 1, flag2); break; case 3: - if (getflorzofslope(pSpr->sectnum, pSpr->x, pSpr->y) - kSlopeDist <= pSpr->z) sprite2sectorSlope(pSpr, §or[pSpr->sectnum], 0, flag2); - if (getceilzofslope(pSpr->sectnum, pSpr->x, pSpr->y) + kSlopeDist >= pSpr->z) sprite2sectorSlope(pSpr, §or[pSpr->sectnum], 1, flag2); + if (getflorzofslope(pSpr->sectnum, pSpr->x, pSpr->y) - kSlopeDist <= pSpr->z) sprite2sectorSlope(objActor, §or[pSpr->sectnum], 0, flag2); + if (getceilzofslope(pSpr->sectnum, pSpr->x, pSpr->y) + kSlopeDist >= pSpr->z) sprite2sectorSlope(objActor, §or[pSpr->sectnum], 1, flag2); break; } break; diff --git a/source/games/blood/src/nnexts.h b/source/games/blood/src/nnexts.h index cd4bf8e7e..ba1641387 100644 --- a/source/games/blood/src/nnexts.h +++ b/source/games/blood/src/nnexts.h @@ -319,7 +319,7 @@ bool aiFightDudeIsAffected(DBloodActor* pXDude); bool aiFightMatesHaveSameTarget(DBloodActor* leaderactor, DBloodActor* targetactor, int allow); void aiFightActivateDudes(int rx); // ------------------------------------------------------------------------- // -void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex); +void useSlopeChanger(DBloodActor* sourceactor, int objType, int objIndex, DBloodActor* objActor); void damageSprites(DBloodActor* pXSource, DBloodActor* pSprite); void useRandomItemGen(DBloodActor* pSource); void useUniMissileGen(DBloodActor* sourceactor, DBloodActor* actor);