- sanitized the abuse of using XSPRITE's target field to pass along some info with explosions.

This is neither safe nor future proof, so now it uses a separate variable.
This commit is contained in:
Christoph Oelckers 2021-08-29 14:42:05 +02:00
parent 146de69169
commit 48073a2cd6
5 changed files with 10 additions and 8 deletions

View file

@ -5633,6 +5633,7 @@ void actExplodeSprite(DBloodActor* actor)
pSprite->type = nType;
const EXPLOSION* pExplodeInfo = &explodeInfo[nType];
actor->SetTarget(nullptr);
actor->explosionhackflag = true;
pXSprite->data1 = pExplodeInfo->ticks;
pXSprite->data2 = pExplodeInfo->quakeEffect;
pXSprite->data3 = pExplodeInfo->flashEffect;
@ -5976,9 +5977,9 @@ static void actCheckExplosion()
{
if (pXSprite->data1 && CheckProximity(pDude, x, y, z, nSector, radius))
{
if (pExplodeInfo->dmg && pXSprite->target_i == 0)
if (pExplodeInfo->dmg && actor->explosionhackflag)
{
pXSprite->target_i = 1;
actor->explosionhackflag = false;
actDamageSprite(Owner, dudeactor, kDamageFall, (pExplodeInfo->dmg + Random(pExplodeInfo->dmgRng)) << 4);
}
if (pExplodeInfo->dmgType) ConcussSprite(actor, dudeactor, x, y, z, pExplodeInfo->dmgType);

View file

@ -97,13 +97,15 @@ public:
SPRITEMASS spriteMass;
GENDUDEEXTRA genDudeExtra;
int cumulDamage;
int cumulDamage; // this one's transient and does not need to be saved.
bool explosionhackflag; // this originally hijacked the target field which is not safe when working with pointers.
DBloodActor() :index(int(this - base())) { /*assert(index >= 0 && index < kMaxSprites);*/ }
DBloodActor& operator=(const DBloodActor& other) = default;
void Clear()
{
explosionhackflag = false;
dudeSlope = 0;
dudeExtra = {};
spriteMass = {};

View file

@ -385,9 +385,7 @@ void FinishHim(DBloodActor* actor, int) // 13
{
if (!actor) return;
spritetype* pSprite = &actor->s();
int nXSprite = pSprite->extra;
XSPRITE* pXSprite = &actor->x();
if (IsPlayerSprite(pSprite) && playerSeqPlaying(&gPlayer[pSprite->type - kDudePlayer1], 16) && pXSprite->target_i == gMe->nSprite)
if (actor->IsPlayerActor() && playerSeqPlaying(&gPlayer[pSprite->type - kDudePlayer1], 16) && actor == gMe->actor())
sndStartSample(3313, -1, 1, 0);
}

View file

@ -482,7 +482,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, DBloodActor& w, DB
if (w.hasX())
{
arc("dudeslope", w.dudeSlope, def->dudeSlope)
("dudeextra", w.dudeExtra, def->dudeExtra);
("dudeextra", w.dudeExtra, def->dudeExtra)
("explosionflag", w.explosionhackflag, def->explosionhackflag);
if (gModernMap)
{

View file

@ -6995,7 +6995,7 @@ void useTargetChanger(DBloodActor* sourceactor, DBloodActor* actor)
if (aiFightDudeCanSeeTarget(actor, pDudeInfo, pMateTargetActor))
{
if (pXMateTarget->target_i < 0)
if (pMateTargetActor->GetTarget() == nullptr)
{
aiSetTarget(pMateTargetActor, actor);
if (pMateTargetActor->IsDudeActor() && !isActive(pMateTargetActor))