- sprite2sectorSlope + useSlopeChanger

This commit is contained in:
Christoph Oelckers 2021-10-13 19:13:15 +02:00
parent b7465ab67b
commit e3b8980ecd
2 changed files with 55 additions and 37 deletions

View file

@ -4755,7 +4755,7 @@ void modernTypeTrigger(int destObjType, int destObjIndex, DBloodActor* destactor
{ {
case OBJ_SPRITE: case OBJ_SPRITE:
case OBJ_SECTOR: case OBJ_SECTOR:
useSlopeChanger(pXSource, destObjType, destObjIndex); useSlopeChanger(event.actor, destObjType, destObjIndex, destactor);
break; break;
} }
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; int slope = 0, z = 0;
switch (rel) { switch (rel) {
default: default:
z = getflorzofslope(pSprite->sectnum, pSprite->x, pSprite->y); 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; slope = pSector->floorheinum;
break; break;
case 1: case 1:
z = getceilzofslope(pSprite->sectnum, pSprite->x, pSprite->y); 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; slope = pSector->ceilingheinum;
break; 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; int slope, oslope, i;
spritetype* pSource = &sprite[pXSource->reference];
bool flag2 = (pSource->flags & kModernTypeFlag2); bool flag2 = (pSource->flags & kModernTypeFlag2);
if (pSource->flags & kModernTypeFlag1) slope = ClipRange(pXSource->data2, -32767, 32767); if (pSource->flags & kModernTypeFlag1) slope = ClipRange(pXSource->data2, -32767, 32767);
@ -6513,21 +6521,24 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) {
else else
{ {
// force closest floor aligned sprites to inherit slope of the sector's floor // 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]) { oslope = pSect->floorheinum;
if (!(sprite[i].cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; BloodSectIterator it(objIndex);
else if (getflorzofslope(objIndex, sprite[i].x, sprite[i].y) - kSlopeDist <= sprite[i].z) { while (auto iactor = it.Next())
{
sprite2sectorSlope(&sprite[i], &sector[objIndex], 0, true); 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, &sector[objIndex], 0, true);
// set new slope of floor // set new slope of floor
pSect->floorheinum = slope; pSect->floorheinum = slope;
// force sloped sprites to be on floor slope z // force sloped sprites to be on floor slope z
sprite2sectorSlope(&sprite[i], &sector[objIndex], 0, true); sprite2sectorSlope(iactor, &sector[objIndex], 0, true);
// restore old slope for next sprite // restore old slope for next sprite
pSect->floorheinum = oslope; pSect->floorheinum = oslope;
} }
} }
@ -6550,22 +6561,24 @@ void useSlopeChanger(XSPRITE* pXSource, int objType, int objIndex) {
} }
else else
{ {
// force closest floor aligned sprites to inherit slope of the sector's ceiling oslope = pSect->ceilingheinum;
for (i = headspritesect[objIndex], oslope = pSect->ceilingheinum; i != -1; i = nextspritesect[i]) { BloodSectIterator it(objIndex);
if (!(sprite[i].cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue; while (auto iactor = it.Next())
else if (getceilzofslope(objIndex, sprite[i].x, sprite[i].y) + kSlopeDist >= sprite[i].z) { {
auto spr = &iactor->s();
sprite2sectorSlope(&sprite[i], &sector[objIndex], 1, true); if (!(spr->cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) continue;
else if (getceilzofslope(objIndex, spr->x, spr->y) + kSlopeDist >= spr->z)
{
sprite2sectorSlope(iactor, &sector[objIndex], 1, true);
// set new slope of ceiling // set new slope of ceiling
pSect->ceilingheinum = slope; pSect->ceilingheinum = slope;
// force sloped sprites to be on ceiling slope z // force sloped sprites to be on ceiling slope z
sprite2sectorSlope(&sprite[i], &sector[objIndex], 1, true); sprite2sectorSlope(iactor, &sector[objIndex], 1, true);
// restore old slope for next sprite // restore old slope for next sprite
pSect->ceilingheinum = oslope; 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... // let's give a little impulse to the physics sprites...
for (i = headspritesect[objIndex]; i != -1; i = nextspritesect[i]) { BloodSectIterator it(objIndex);
while (auto iactor = it.Next())
if (sprite[i].extra > 0 && xsprite[sprite[i].extra].physAttr > 0) { {
xsprite[sprite[i].extra].physAttr |= kPhysFalling; auto spr = &iactor->s();
zvel[i]++; auto xspr = &iactor->x();
if (spr->extra > 0 && xspr->physAttr > 0)
} else if ((sprite[i].statnum == kStatThing || sprite[i].statnum == kStatDude) && (sprite[i].flags & kPhysGravity)) { {
sprite[i].flags |= kPhysFalling; xspr->physAttr |= kPhysFalling;
zvel[i]++; iactor->zvel()++;
}
else if ((spr->statnum == kStatThing || spr->statnum == kStatDude) && (spr->flags & kPhysGravity))
{
spr->flags |= kPhysFalling;
iactor->zvel()++;
} }
} }
} }
else if (objType == OBJ_SPRITE) 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_FLOOR)) pSpr->cstat |= CSTAT_SPRITE_ALIGNMENT_FLOOR;
if ((pSpr->cstat & CSTAT_SPRITE_ALIGNMENT_SLOPE) != CSTAT_SPRITE_ALIGNMENT_SLOPE) if ((pSpr->cstat & CSTAT_SPRITE_ALIGNMENT_SLOPE) != CSTAT_SPRITE_ALIGNMENT_SLOPE)
pSpr->cstat |= 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; if (!sectRangeIsFine(pSpr->sectnum)) break;
switch (pXSource->data4) switch (pXSource->data4)
{ {
case 1: sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 0, flag2); break; case 1: sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 0, flag2); break;
case 2: sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 1, flag2); break; case 2: sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 1, flag2); break;
case 3: case 3:
if (getflorzofslope(pSpr->sectnum, pSpr->x, pSpr->y) - kSlopeDist <= pSpr->z) sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 0, flag2); if (getflorzofslope(pSpr->sectnum, pSpr->x, pSpr->y) - kSlopeDist <= pSpr->z) sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 0, flag2);
if (getceilzofslope(pSpr->sectnum, pSpr->x, pSpr->y) + kSlopeDist >= pSpr->z) sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 1, flag2); if (getceilzofslope(pSpr->sectnum, pSpr->x, pSpr->y) + kSlopeDist >= pSpr->z) sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 1, flag2);
break; break;
} }
break; break;

View file

@ -319,7 +319,7 @@ bool aiFightDudeIsAffected(DBloodActor* pXDude);
bool aiFightMatesHaveSameTarget(DBloodActor* leaderactor, DBloodActor* targetactor, int allow); bool aiFightMatesHaveSameTarget(DBloodActor* leaderactor, DBloodActor* targetactor, int allow);
void aiFightActivateDudes(int rx); 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 damageSprites(DBloodActor* pXSource, DBloodActor* pSprite);
void useRandomItemGen(DBloodActor* pSource); void useRandomItemGen(DBloodActor* pSource);
void useUniMissileGen(DBloodActor* sourceactor, DBloodActor* actor); void useUniMissileGen(DBloodActor* sourceactor, DBloodActor* actor);