- 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_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], &sector[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, &sector[objIndex], 0, true);
// set new slope of floor
pSect->floorheinum = slope;
// 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
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], &sector[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, &sector[objIndex], 1, true);
// set new slope of ceiling
pSect->ceilingheinum = slope;
// 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
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, &sector[pSpr->sectnum], 0, flag2); break;
case 2: sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 1, flag2); break;
case 1: sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 0, flag2); break;
case 2: sprite2sectorSlope(objActor, &sector[pSpr->sectnum], 1, flag2); break;
case 3:
if (getflorzofslope(pSpr->sectnum, pSpr->x, pSpr->y) - kSlopeDist <= pSpr->z) sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 0, flag2);
if (getceilzofslope(pSpr->sectnum, pSpr->x, pSpr->y) + kSlopeDist >= pSpr->z) sprite2sectorSlope(pSpr, &sector[pSpr->sectnum], 1, 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(objActor, &sector[pSpr->sectnum], 1, flag2);
break;
}
break;

View file

@ -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);