- usePropertiesChanger

This commit is contained in:
Christoph Oelckers 2021-09-02 23:26:18 +02:00
parent cd98e940aa
commit f21dc51207

View file

@ -2626,9 +2626,10 @@ void useObjResizer(DBloodActor* sourceactor, int targType, int targIndex, DBlood
//
//---------------------------------------------------------------------------
void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
spritetype* pSource = &sprite[pXSource->reference];
void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, DBloodActor* targetactor)
{
auto pXSource = &sourceactor->x();
spritetype* pSource = &sourceactor->s();
switch (objType)
{
@ -2670,10 +2671,12 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
}
}
break;
case OBJ_SPRITE: {
auto actor = &bloodActors[objIndex];
spritetype* pSprite = &sprite[objIndex]; bool thing2debris = false;
XSPRITE* pXSprite = &xsprite[pSprite->extra]; int old = -1;
case OBJ_SPRITE:
{
spritetype* pSprite = &targetactor->s();
XSPRITE* pXSprite = &targetactor->x();
bool thing2debris = false;
int old = -1;
// data3 = set sprite hitag
if (valueIsBetween(pXSource->data3, -1, 32767))
@ -2824,14 +2827,14 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
}
}
int nIndex = debrisGetIndex(&bloodActors[objIndex]); // check if there is no sprite in list
int nIndex = debrisGetIndex(targetactor); // check if there is no sprite in list
// adding physics sprite in list
if ((flags & kPhysGravity) != 0 || (flags & kPhysMove) != 0)
{
if (oldFlags == 0)
xvel[objIndex] = yvel[objIndex] = zvel[objIndex] = 0;
targetactor->xvel() = targetactor->yvel() = targetactor->zvel() = 0;
if (nIndex != -1)
{
@ -2846,31 +2849,31 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) {
pXSprite->physAttr = flags; // update physics attributes
// allow things to became debris, so they use different physics...
if (pSprite->statnum == kStatThing) changespritestat(objIndex, 0);
if (pSprite->statnum == kStatThing) ChangeActorStat(targetactor, 0);
// set random goal ang for swimming so they start turning
if ((flags & kPhysDebrisSwim) && !xvel[objIndex] && !yvel[objIndex] && !zvel[objIndex])
if ((flags & kPhysDebrisSwim) && !targetactor->xvel() && !targetactor->yvel() && !targetactor->zvel())
pXSprite->goalAng = (pSprite->ang + Random3(kAng45)) & 2047;
if (pXSprite->physAttr & kPhysDebrisVector)
pSprite->cstat |= CSTAT_SPRITE_BLOCK_HITSCAN;
gPhysSpritesList[nIndex] = &bloodActors[objIndex];
gPhysSpritesList[nIndex] = targetactor;
if (nIndex >= gPhysSpritesCount) gPhysSpritesCount++;
getSpriteMassBySize(actor); // create physics cache
getSpriteMassBySize(targetactor); // create physics cache
}
// removing physics from sprite in list (don't remove sprite from list)
} else if (nIndex != -1) {
}
else if (nIndex != -1)
{
pXSprite->physAttr = flags;
xvel[objIndex] = yvel[objIndex] = zvel[objIndex] = 0;
targetactor->xvel() = targetactor->yvel() = targetactor->zvel() = 0;
if (pSprite->lotag >= kThingBase && pSprite->lotag < kThingMax)
changespritestat(objIndex, kStatThing); // if it was a thing - restore statnum
ChangeActorStat(targetactor, kStatThing); // if it was a thing - restore statnum
}
break;
}
}
@ -4740,7 +4743,7 @@ void modernTypeTrigger(int destObjType, int destObjIndex, EVENT event) {
break;
// change various properties
case kModernObjPropertiesChanger:
usePropertiesChanger(pXSource, destObjType, destObjIndex);
usePropertiesChanger(event.actor, destObjType, destObjIndex, destactor);
break;
// updated vanilla sound gen that now allows to play sounds on TX ID sprites
case kGenModernSound:
@ -5369,7 +5372,7 @@ bool modernTypeOperateSprite(int nSprite, spritetype* pSprite, XSPRITE* pXSprite
case kModernObjPropertiesChanger:
if (pXSprite->txID <= 0) {
if (SetSpriteState(nSprite, pXSprite, pXSprite->state ^ 1) == 1)
usePropertiesChanger(pXSprite, -1, -1);
usePropertiesChanger(&bloodActors[nSprite], -1, -1, nullptr);
return true;
}
[[fallthrough]];