- eliminated HITINFO.hitsprite.

This was one of the more annoying sprite index variables because it is part of static global data.
This commit is contained in:
Christoph Oelckers 2021-05-05 16:43:42 +02:00
parent 9b4ee3dc2c
commit 62502439d7
19 changed files with 121 additions and 132 deletions

View file

@ -3852,17 +3852,17 @@ int actDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE damageT
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void actHitcodeToData(int a1, HITINFO* pHitInfo, DBloodActor** pActor, walltype** a7) void actHitcodeToData(int a1, HITINFO* pHitInfo, DBloodActor** pActor, walltype** ppWall)
{ {
assert(pHitInfo != nullptr); assert(pHitInfo != nullptr);
int nSprite = -1; DBloodActor* actor = nullptr;
int nWall = -1; int nWall = -1;
walltype* pWall = nullptr; walltype* pWall = nullptr;
switch (a1) switch (a1)
{ {
case 3: case 3:
case 5: case 5:
nSprite = pHitInfo->hitsprite; actor = pHitInfo->hitactor;
break; break;
case 0: case 0:
case 4: case 4:
@ -3872,8 +3872,8 @@ void actHitcodeToData(int a1, HITINFO* pHitInfo, DBloodActor** pActor, walltype*
default: default:
break; break;
} }
if (pActor) *pActor = nSprite == -1 ? nullptr : &bloodActors[nSprite]; if (pActor) *pActor = actor;
if (a7) *a7 = pWall; if (ppWall) *ppWall = pWall;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -4901,7 +4901,7 @@ void MoveDude(DBloodActor* actor)
if (pHitSprite->statnum == kStatProjectile && !(pHitSprite->flags & 32) && actor != Owner) if (pHitSprite->statnum == kStatProjectile && !(pHitSprite->flags & 32) && actor != Owner)
{ {
HITINFO hitInfo = gHitInfo; HITINFO hitInfo = gHitInfo;
gHitInfo.hitsprite = pSprite->index; gHitInfo.hitactor = actor;
actImpactMissile(coll.actor, 3); actImpactMissile(coll.actor, 3);
gHitInfo = hitInfo; gHitInfo = hitInfo;
} }
@ -5344,9 +5344,7 @@ int MoveMissile(DBloodActor* actor)
bakCstat = pOwner->cstat; bakCstat = pOwner->cstat;
pOwner->cstat &= ~257; pOwner->cstat &= ~257;
} }
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
if (pSprite->type == kMissileFlameSpray) actAirDrag(actor, 0x1000); if (pSprite->type == kMissileFlameSpray) actAirDrag(actor, 0x1000);
if (actor->GetTarget() != nullptr && (actor->xvel() || actor->yvel() || actor->zvel())) if (actor->GetTarget() != nullptr && (actor->xvel() || actor->yvel() || actor->zvel()))
@ -5405,7 +5403,7 @@ int MoveMissile(DBloodActor* actor)
} }
if (clipmoveresult.type == kHitSprite) if (clipmoveresult.type == kHitSprite)
{ {
gHitInfo.hitsprite = clipmoveresult.legacyVal & kHitIndexMask; gHitInfo.hitactor = clipmoveresult.actor;
cliptype = 3; cliptype = 3;
} }
else if (clipmoveresult.type == kHitWall) else if (clipmoveresult.type == kHitWall)
@ -6924,17 +6922,16 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6,
int hit = VectorScan(pShooter, a2, a3, a4, a5, a6, nRange, 1); int hit = VectorScan(pShooter, a2, a3, a4, a5, a6, nRange, 1);
if (hit == 3) if (hit == 3)
{ {
int nSprite_ = gHitInfo.hitsprite; auto hitactor = gHitInfo.hitactor;
assert(nSprite_ >= 0 && nSprite_ < kMaxSprites); assert(hitactor != nullptr);
auto actor = &bloodActors[nSprite_]; spritetype* pSprite = &hitactor->s();
spritetype* pSprite = &actor->s();
if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pShooter, pSprite)) return; if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pShooter, pSprite)) return;
if (IsPlayerSprite(pSprite)) if (IsPlayerSprite(pSprite))
{ {
PLAYER* pPlayer = &gPlayer[pSprite->type - kDudePlayer1]; PLAYER* pPlayer = &gPlayer[pSprite->type - kDudePlayer1];
if (powerupCheck(pPlayer, kPwUpReflectShots)) if (powerupCheck(pPlayer, kPwUpReflectShots))
{ {
gHitInfo.hitsprite = pShooter->index; gHitInfo.hitactor = shooter;
gHitInfo.hitx = pShooter->x; gHitInfo.hitx = pShooter->x;
gHitInfo.hity = pShooter->y; gHitInfo.hity = pShooter->y;
gHitInfo.hitz = pShooter->z; gHitInfo.hitz = pShooter->z;
@ -7008,9 +7005,7 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6,
} }
case 3: case 3:
{ {
int nSprite = gHitInfo.hitsprite; auto actor = gHitInfo.hitactor;
assert(nSprite >= 0 && nSprite < kMaxSprites);
auto actor = &bloodActors[nSprite];
spritetype* pSprite = &actor->s(); spritetype* pSprite = &actor->s();
nSurf = surfType[pSprite->picnum]; nSurf = surfType[pSprite->picnum];
x -= MulScale(a4, 112, 14); x -= MulScale(a4, 112, 14);
@ -7117,12 +7112,12 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6,
if (pXSprite->physAttr & kPhysDebrisVector) { if (pXSprite->physAttr & kPhysDebrisVector) {
int impulse = DivScale(pVectorData->impulse, ClipLow(gSpriteMass[pSprite->extra].mass, 10), 6); int impulse = DivScale(pVectorData->impulse, ClipLow(gSpriteMass[pSprite->extra].mass, 10), 6);
xvel[nSprite] += MulScale(a4, impulse, 16); actor->xvel() += MulScale(a4, impulse, 16);
yvel[nSprite] += MulScale(a5, impulse, 16); actor->yvel() += MulScale(a5, impulse, 16);
zvel[nSprite] += MulScale(a6, impulse, 16); actor->zvel() += MulScale(a6, impulse, 16);
if (pVectorData->burnTime != 0) { if (pVectorData->burnTime != 0) {
if (!pXSprite->burnTime) evPost(nSprite, 3, 0, kCallbackFXFlameLick); if (!pXSprite->burnTime) evPost(actor, 0, kCallbackFXFlameLick);
actBurnSprite(shooter->GetOwner(), actor, pVectorData->burnTime); actBurnSprite(shooter->GetOwner(), actor, pVectorData->burnTime);
} }
@ -7404,6 +7399,19 @@ void SerializeActor(FSerializer& arc)
} }
// dumping ground for temporary wrappers. // dumping ground for temporary wrappers.
void HITINFO::set(hitdata_t* hit)
{
hitsect = hit->sect;
hitwall = hit->wall;
hitsprite = hit->sprite;
hitactor = hit->sprite >= 0 ? &bloodActors[hit->sprite] : nullptr;
hitx = hit->pos.x;
hity = hit->pos.y;
hitz = hit->pos.z;
}
void actPostSprite(int nSprite, int nStatus) void actPostSprite(int nSprite, int nStatus)
{ {
actPostSprite(&bloodActors[nSprite], nStatus); actPostSprite(&bloodActors[nSprite], nStatus);

View file

@ -142,7 +142,7 @@ bool CanMove(DBloodActor *actor, DBloodActor* target, int nAngle, int nRange)
int nDist = approxDist(x-gHitInfo.hitx, y-gHitInfo.hity); int nDist = approxDist(x-gHitInfo.hitx, y-gHitInfo.hity);
if (nDist - (pSprite->clipdist << 2) < nRange) if (nDist - (pSprite->clipdist << 2) < nRange)
{ {
if (gHitInfo.hitsprite < 0 || target == nullptr || target->s().index != gHitInfo.hitsprite) if (gHitInfo.hitactor == nullptr || target == nullptr || target != gHitInfo.hitactor)
return false; return false;
return true; return true;
} }

View file

@ -301,7 +301,7 @@ static void beastThinkChase(DBloodActor* actor)
aiNewState(actor, &beastStomp); aiNewState(actor, &beastStomp);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
{ {
if (!pXSector || !pXSector->Underwater) if (!pXSector || !pXSector->Underwater)
aiNewState(actor, &beastStomp); aiNewState(actor, &beastStomp);
@ -339,7 +339,7 @@ static void beastThinkChase(DBloodActor* actor)
aiNewState(actor, &beastSlash); aiNewState(actor, &beastSlash);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
{ {
if (pXSector && pXSector->Underwater) if (pXSector && pXSector->Underwater)
aiNewState(actor, &beastSwimSlash); aiNewState(actor, &beastSwimSlash);

View file

@ -202,7 +202,7 @@ static void calebThinkChase(DBloodActor* actor)
aiNewState(actor, &tinycalebAttack); aiNewState(actor, &tinycalebAttack);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
{ {
if (pXSector && pXSector->Underwater) if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimAttack); aiNewState(actor, &tinycalebSwimAttack);

View file

@ -432,7 +432,7 @@ static void cerberusThinkChase(DBloodActor* actor)
aiNewState(actor, &cerberusBite); aiNewState(actor, &cerberusBite);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeHellHound) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeHellHound)
aiNewState(actor, &cerberusBite); aiNewState(actor, &cerberusBite);
break; break;
case 0: case 0:
@ -449,7 +449,7 @@ static void cerberusThinkChase(DBloodActor* actor)
aiNewState(actor, &cerberus2Bite); aiNewState(actor, &cerberus2Bite);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeHellHound) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeHellHound)
aiNewState(actor, &cerberus2Bite); aiNewState(actor, &cerberus2Bite);
break; break;
case 0: case 0:

View file

@ -316,7 +316,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultistTThrow); aiNewState(actor, &cultistTThrow);
break; break;
default: default:
@ -338,7 +338,7 @@ static void cultThinkChase(DBloodActor* actor)
aiNewState(actor, &cultistTSwimFire); aiNewState(actor, &cultistTSwimFire);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun)
{ {
if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal) if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal)
aiNewState(actor, &cultistTFire); aiNewState(actor, &cultistTFire);
@ -384,7 +384,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultistSThrow); aiNewState(actor, &cultistSThrow);
break; break;
default: default:
@ -406,7 +406,7 @@ static void cultThinkChase(DBloodActor* actor)
aiNewState(actor, &cultistSSwimFire); aiNewState(actor, &cultistSSwimFire);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistTommy) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistTommy)
{ {
if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal) if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal)
aiNewState(actor, &cultistSFire); aiNewState(actor, &cultistSFire);
@ -452,7 +452,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultistTsThrow); aiNewState(actor, &cultistTsThrow);
break; break;
default: default:
@ -474,7 +474,7 @@ static void cultThinkChase(DBloodActor* actor)
aiNewState(actor, &cultistTsSwimFire); aiNewState(actor, &cultistTsSwimFire);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistTommy) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistTommy)
{ {
if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal) if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal)
aiNewState(actor, &cultistTsFire); aiNewState(actor, &cultistTsFire);
@ -518,7 +518,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultistDThrow); aiNewState(actor, &cultistDThrow);
break; break;
default: default:
@ -539,7 +539,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultist139A78); aiNewState(actor, &cultist139A78);
break; break;
default: default:
@ -564,7 +564,7 @@ static void cultThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistShotgun && pXSprite->medium != kMediumWater && pXSprite->medium != kMediumGoo)
aiNewState(actor, &cultistSThrow); aiNewState(actor, &cultistSThrow);
break; break;
default: default:
@ -586,7 +586,7 @@ static void cultThinkChase(DBloodActor* actor)
aiNewState(actor, &cultistSSwimFire); aiNewState(actor, &cultistSSwimFire);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeCultistTommy) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeCultistTommy)
{ {
if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal) if (!dudeIsPlayingSeq(actor, 14) && pXSprite->medium == kMediumNormal)
aiNewState(actor, &cultistSFire); aiNewState(actor, &cultistSFire);

View file

@ -414,7 +414,7 @@ static void gargThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeGargoyleStone) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeGargoyleStone)
{ {
sfxPlay3DSound(actor, 1408, 0, 0); sfxPlay3DSound(actor, 1408, 0, 0);
aiNewState(actor, &gargoyleFThrow); aiNewState(actor, &gargoyleFThrow);
@ -439,7 +439,7 @@ static void gargThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeGargoyleStone) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeGargoyleStone)
{ {
sfxPlay3DSound(actor, 1406, 0, 0); sfxPlay3DSound(actor, 1406, 0, 0);
aiNewState(actor, &gargoyleFSlash); aiNewState(actor, &gargoyleFSlash);
@ -473,7 +473,7 @@ static void gargThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeGargoyleFlesh) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeGargoyleFlesh)
{ {
sfxPlay3DSound(actor, 1457, 0, 0); sfxPlay3DSound(actor, 1457, 0, 0);
aiNewState(actor, &gargoyleSBlast); aiNewState(actor, &gargoyleSBlast);
@ -497,7 +497,7 @@ static void gargThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudeGargoyleFlesh) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudeGargoyleFlesh)
aiNewState(actor, &gargoyleFSlash); aiNewState(actor, &gargoyleFSlash);
break; break;
default: default:

View file

@ -389,7 +389,7 @@ static void ghostThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudePhantasm) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudePhantasm)
aiNewState(actor, &ghostBlast); aiNewState(actor, &ghostBlast);
break; break;
default: default:
@ -409,7 +409,7 @@ static void ghostThinkChase(DBloodActor* actor)
case 4: case 4:
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type && sprite[gHitInfo.hitsprite].type != kDudePhantasm) if (pSprite->type != gHitInfo.hitactor->s().type && gHitInfo.hitactor->s().type != kDudePhantasm)
aiNewState(actor, &ghostSlash); aiNewState(actor, &ghostSlash);
break; break;
default: default:

View file

@ -192,7 +192,7 @@ static void gillThinkChase(DBloodActor* actor)
aiNewState(actor, &gillBeastBite); aiNewState(actor, &gillBeastBite);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
{ {
if (pXSector && pXSector->Underwater) if (pXSector && pXSector->Underwater)
aiNewState(actor, &gillBeastSwimBite); aiNewState(actor, &gillBeastSwimBite);

View file

@ -79,7 +79,7 @@ void SpidBiteSeqCallback(int, DBloodActor* actor)
if (IsPlayerSprite(pTarget)) { if (IsPlayerSprite(pTarget)) {
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0); int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
if (hit == 3 && IsPlayerSprite(&sprite[gHitInfo.hitsprite])) { if (hit == 3 && gHitInfo.hitactor->IsPlayerActor()) {
dz += pTarget->z - pSprite->z; dz += pTarget->z - pSprite->z;
PLAYER *pPlayer = &gPlayer[pTarget->type - kDudePlayer1]; PLAYER *pPlayer = &gPlayer[pTarget->type - kDudePlayer1];
switch (pSprite->type) { switch (pSprite->type) {

View file

@ -140,8 +140,8 @@ static bool genDudeAdjustSlope(DBloodActor* actor, int dist, int weaponType, int
for (int i = -8191; i < 8192; i += by) for (int i = -8191; i < 8192; i += by)
{ {
HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), i, clipMask, dist); HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), i, clipMask, dist);
if (!fStart && pXSprite->target_i == gHitInfo.hitsprite) fStart = i; if (!fStart && actor->GetTarget() == gHitInfo.hitactor) fStart = i;
else if (fStart && pXSprite->target_i != gHitInfo.hitsprite) else if (fStart && actor->GetTarget() != gHitInfo.hitactor)
{ {
fEnd = i; fEnd = i;
break; break;
@ -427,16 +427,20 @@ static void unicultThinkChase(DBloodActor* actor)
} }
spritetype* pTarget = &sprite[pXSprite->target_i]; auto const targetactor = actor->GetTarget();
XSPRITE* pXTarget = (!IsDudeSprite(pTarget) || !xspriRangeIsFine(pTarget->extra)) ? NULL : &xsprite[pTarget->extra]; XSPRITE* pXTarget = !targetactor || !targetactor->IsDudeActor() || !targetactor->GetTarget() ? nullptr : &targetactor->x();
if (pXTarget == NULL) { // target lost if (pXTarget == nullptr) // target lost
{
if(spriteIsUnderwater(pSprite,false)) aiGenDudeNewState(pSprite, &genDudeSearchShortW); if(spriteIsUnderwater(pSprite,false)) aiGenDudeNewState(pSprite, &genDudeSearchShortW);
else aiGenDudeNewState(pSprite, &genDudeSearchShortL); else aiGenDudeNewState(pSprite, &genDudeSearchShortL);
actor->SetTarget(nullptr); actor->SetTarget(nullptr);
return; return;
}
} else if (pXTarget->health <= 0) { // target is dead auto const pTarget = &targetactor->s();
if (pXTarget->health <= 0) // target is dead
{
PLAYER* pPlayer = NULL; PLAYER* pPlayer = NULL;
if ((!IsPlayerSprite(pTarget)) || ((pPlayer = getPlayerById(pTarget->type)) != NULL && pPlayer->fraggerId == pSprite->index)) { if ((!IsPlayerSprite(pTarget)) || ((pPlayer = getPlayerById(pTarget->type)) != NULL && pPlayer->fraggerId == pSprite->index)) {
playGenDudeSound(pSprite, kGenDudeSndTargetDead); playGenDudeSound(pSprite, kGenDudeSndTargetDead);
@ -677,16 +681,27 @@ static void unicultThinkChase(DBloodActor* actor)
objDist = approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y); objDist = approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y);
} }
if (pXSprite->target_i != gHitInfo.hitsprite && targetDist > objDist) { if (actor != gHitInfo.hitactor && targetDist > objDist)
walltype* pHWall = NULL; XWALL* pXHWall = NULL; {
spritetype* pHSprite = NULL; XSPRITE* pXHSprite = NULL; DBloodActor* hitactor = nullptr;
bool hscn = false; bool blck = false; bool failed = false; walltype* pHWall = NULL;
XWALL* pXHWall = NULL;
spritetype* pHSprite = NULL;
XSPRITE* pXHSprite = NULL;
bool hscn = false;
bool blck = false;
bool failed = false;
switch (hit) { switch (hit)
{
case 3: case 3:
pHSprite = &sprite[gHitInfo.hitsprite]; hitactor = gHitInfo.hitactor;
if (xspriRangeIsFine(pHSprite->extra)) pXHSprite = &xsprite[pHSprite->extra]; if (hitactor)
{
pHSprite = &hitactor->s();
pXHSprite = &hitactor->x();
hscn = (pHSprite->cstat & CSTAT_SPRITE_BLOCK_HITSCAN); blck = (pHSprite->cstat & CSTAT_SPRITE_BLOCK); hscn = (pHSprite->cstat & CSTAT_SPRITE_BLOCK_HITSCAN); blck = (pHSprite->cstat & CSTAT_SPRITE_BLOCK);
}
break; break;
case 0: case 0:
case 4: case 4:
@ -774,7 +789,7 @@ static void unicultThinkChase(DBloodActor* actor)
{ {
if (genDudeAdjustSlope(actor, dist, weaponType)) break; if (genDudeAdjustSlope(actor, dist, weaponType)) break;
VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope, dist, 1); VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope, dist, 1);
if (pXSprite->target_i == gHitInfo.hitsprite) break; if (actor == gHitInfo.hitactor) break;
bool immune = nnExtIsImmune(pHSprite, gVectorData[curWeapon].dmgType); bool immune = nnExtIsImmune(pHSprite, gVectorData[curWeapon].dmgType);
if (!(pXHSprite != NULL && (!immune || (immune && pHSprite->statnum == kStatThing && pXHSprite->Vector)) && !pXHSprite->locked)) if (!(pXHSprite != NULL && (!immune || (immune && pHSprite->statnum == kStatThing && pXHSprite->Vector)) && !pXHSprite->locked))
@ -828,7 +843,8 @@ static void unicultThinkChase(DBloodActor* actor)
if (masked) VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope, dist, 1); if (masked) VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope, dist, 1);
//viewSetSystemMessage("WALL VHIT: %d", gHitInfo.hitwall); //viewSetSystemMessage("WALL VHIT: %d", gHitInfo.hitwall);
if ((pXSprite->target_i != gHitInfo.hitsprite) && (pHWall->type != kWallGib || !masked || pXHWall == NULL || !pXHWall->triggerVector || pXHWall->locked)) { if ((actor != gHitInfo.hitactor) && (pHWall->type != kWallGib || !masked || pXHWall == NULL || !pXHWall->triggerVector || pXHWall->locked))
{
if (spriteIsUnderwater(pSprite)) aiGenDudeNewState(pSprite, &genDudeChaseW); if (spriteIsUnderwater(pSprite)) aiGenDudeNewState(pSprite, &genDudeChaseW);
else aiGenDudeNewState(pSprite, &genDudeChaseL); else aiGenDudeNewState(pSprite, &genDudeChaseL);
return; return;

View file

@ -156,7 +156,7 @@ static void zombfThinkChase(DBloodActor* actor)
aiNewState(actor, &zombieFThrow); aiNewState(actor, &zombieFThrow);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
aiNewState(actor, &zombieFThrow); aiNewState(actor, &zombieFThrow);
else else
aiNewState(actor, &zombieFDodge); aiNewState(actor, &zombieFDodge);
@ -175,7 +175,7 @@ static void zombfThinkChase(DBloodActor* actor)
aiNewState(actor, &zombieFPuke); aiNewState(actor, &zombieFPuke);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
aiNewState(actor, &zombieFPuke); aiNewState(actor, &zombieFPuke);
else else
aiNewState(actor, &zombieFDodge); aiNewState(actor, &zombieFDodge);
@ -194,7 +194,7 @@ static void zombfThinkChase(DBloodActor* actor)
aiNewState(actor, &zombieFHack); aiNewState(actor, &zombieFHack);
break; break;
case 3: case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type) if (pSprite->type != gHitInfo.hitactor->s().type)
aiNewState(actor, &zombieFHack); aiNewState(actor, &zombieFHack);
else else
aiNewState(actor, &zombieFDodge); aiNewState(actor, &zombieFDodge);

View file

@ -277,7 +277,6 @@ struct Collision
} }
}; };
inline DBloodActor* getUpperLink(int sect) inline DBloodActor* getUpperLink(int sect)
{ {
auto l = gUpperLink[sect]; auto l = gUpperLink[sect];

View file

@ -382,9 +382,7 @@ int HitScan(spritetype *pSprite, int z, int dx, int dy, int dz, unsigned int nMa
{ {
assert(pSprite != NULL); assert(pSprite != NULL);
assert(dx != 0 || dy != 0); assert(dx != 0 || dy != 0);
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
int x = pSprite->x; int x = pSprite->x;
int y = pSprite->y; int y = pSprite->y;
int nSector = pSprite->sectnum; int nSector = pSprite->sectnum;
@ -403,17 +401,12 @@ int HitScan(spritetype *pSprite, int z, int dx, int dy, int dz, unsigned int nMa
hitdata_t hitData; hitdata_t hitData;
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, nSector, dx, dy, dz << 4, &hitData, nMask); hitscan(&pos, nSector, dx, dy, dz << 4, &hitData, nMask);
gHitInfo.hitsect = hitData.sect; gHitInfo.set(&hitData);
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
hitscangoal.x = hitscangoal.y = 0x1ffffff; hitscangoal.x = hitscangoal.y = 0x1ffffff;
pSprite->cstat = bakCstat; pSprite->cstat = bakCstat;
if (gHitInfo.hitsprite >= kMaxSprites || gHitInfo.hitwall >= kMaxWalls || gHitInfo.hitsect >= kMaxSectors) if (gHitInfo.hitwall >= kMaxWalls || gHitInfo.hitsect >= kMaxSectors)
return -1; return -1;
if (gHitInfo.hitsprite >= 0) if (gHitInfo.hitactor != nullptr)
return 3; return 3;
if (gHitInfo.hitwall >= 0) if (gHitInfo.hitwall >= 0)
{ {
@ -434,9 +427,7 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
{ {
int nNum = 256; int nNum = 256;
assert(pSprite != NULL); assert(pSprite != NULL);
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
int x1 = pSprite->x+MulScale(nOffset, Cos(pSprite->ang+512), 30); int x1 = pSprite->x+MulScale(nOffset, Cos(pSprite->ang+512), 30);
int y1 = pSprite->y+MulScale(nOffset, Sin(pSprite->ang+512), 30); int y1 = pSprite->y+MulScale(nOffset, Sin(pSprite->ang+512), 30);
int z1 = pSprite->z+nZOffset; int z1 = pSprite->z+nZOffset;
@ -456,23 +447,18 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
hitdata_t hitData; hitdata_t hitData;
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, nSector, dx, dy, dz << 4, &hitData, CLIPMASK1); hitscan(&pos, nSector, dx, dy, dz << 4, &hitData, CLIPMASK1);
gHitInfo.hitsect = hitData.sect; gHitInfo.set(&hitData);
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
hitscangoal.x = hitscangoal.y = 0x1ffffff; hitscangoal.x = hitscangoal.y = 0x1ffffff;
pSprite->cstat = bakCstat; pSprite->cstat = bakCstat;
while (nNum--) while (nNum--)
{ {
if (gHitInfo.hitsprite >= kMaxSprites || gHitInfo.hitwall >= kMaxWalls || gHitInfo.hitsect >= kMaxSectors) if (gHitInfo.hitwall >= kMaxWalls || gHitInfo.hitsect >= kMaxSectors)
return -1; return -1;
if (nRange && approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y) > nRange) if (nRange && approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y) > nRange)
return -1; return -1;
if (gHitInfo.hitsprite >= 0) if (gHitInfo.hitactor != nullptr)
{ {
spritetype *pOther = &sprite[gHitInfo.hitsprite]; spritetype *pOther = &gHitInfo.hitactor->s();
if ((pOther->flags & 8) && !(ac & 1)) if ((pOther->flags & 8) && !(ac & 1))
return 3; return 3;
if ((pOther->cstat & 0x30) != 0) if ((pOther->cstat & 0x30) != 0)
@ -509,22 +495,14 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
} }
int bakCstat = pOther->cstat; int bakCstat = pOther->cstat;
pOther->cstat &= ~256; pOther->cstat &= ~256;
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
x1 = gHitInfo.hitx; x1 = gHitInfo.hitx;
y1 = gHitInfo.hity; y1 = gHitInfo.hity;
z1 = gHitInfo.hitz; z1 = gHitInfo.hitz;
pos = { x1, y1, z1 }; pos = { x1, y1, z1 };
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, pOther->sectnum, hitscan(&pos, pOther->sectnum, dx, dy, dz << 4, &hitData, CLIPMASK1);
dx, dy, dz << 4, &hitData, CLIPMASK1); gHitInfo.set(&hitData);
gHitInfo.hitsect = hitData.sect;
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
pOther->cstat = bakCstat; pOther->cstat = bakCstat;
continue; continue;
} }
@ -584,9 +562,7 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
pWall->cstat &= ~64; pWall->cstat &= ~64;
int bakCstat2 = wall[pWall->nextwall].cstat; int bakCstat2 = wall[pWall->nextwall].cstat;
wall[pWall->nextwall].cstat &= ~64; wall[pWall->nextwall].cstat &= ~64;
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
x1 = gHitInfo.hitx; x1 = gHitInfo.hitx;
y1 = gHitInfo.hity; y1 = gHitInfo.hity;
z1 = gHitInfo.hitz; z1 = gHitInfo.hitz;
@ -594,12 +570,7 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, pWall->nextsector, hitscan(&pos, pWall->nextsector,
dx, dy, dz << 4, &hitData, CLIPMASK1); dx, dy, dz << 4, &hitData, CLIPMASK1);
gHitInfo.hitsect = hitData.sect; gHitInfo.set(&hitData);
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
pWall->cstat = bakCstat; pWall->cstat = bakCstat;
wall[pWall->nextwall].cstat = bakCstat2; wall[pWall->nextwall].cstat = bakCstat2;
continue; continue;
@ -614,21 +585,14 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
return 2; return 2;
int nSprite = gUpperLink[gHitInfo.hitsect]; int nSprite = gUpperLink[gHitInfo.hitsect];
int nLink = sprite[nSprite].owner & 0xfff; int nLink = sprite[nSprite].owner & 0xfff;
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
x1 = gHitInfo.hitx + sprite[nLink].x - sprite[nSprite].x; x1 = gHitInfo.hitx + sprite[nLink].x - sprite[nSprite].x;
y1 = gHitInfo.hity + sprite[nLink].y - sprite[nSprite].y; y1 = gHitInfo.hity + sprite[nLink].y - sprite[nSprite].y;
z1 = gHitInfo.hitz + sprite[nLink].z - sprite[nSprite].z; z1 = gHitInfo.hitz + sprite[nLink].z - sprite[nSprite].z;
pos = { x1, y1, z1 }; pos = { x1, y1, z1 };
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, sprite[nLink].sectnum, dx, dy, dz<<4, &hitData, CLIPMASK1); hitscan(&pos, sprite[nLink].sectnum, dx, dy, dz<<4, &hitData, CLIPMASK1);
gHitInfo.hitsect = hitData.sect; gHitInfo.set(&hitData);
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
continue; continue;
} }
else else
@ -637,21 +601,14 @@ int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, i
return 1; return 1;
int nSprite = gLowerLink[gHitInfo.hitsect]; int nSprite = gLowerLink[gHitInfo.hitsect];
int nLink = sprite[nSprite].owner & 0xfff; int nLink = sprite[nSprite].owner & 0xfff;
gHitInfo.hitsect = -1; gHitInfo.clearObj();
gHitInfo.hitwall = -1;
gHitInfo.hitsprite = -1;
x1 = gHitInfo.hitx + sprite[nLink].x - sprite[nSprite].x; x1 = gHitInfo.hitx + sprite[nLink].x - sprite[nSprite].x;
y1 = gHitInfo.hity + sprite[nLink].y - sprite[nSprite].y; y1 = gHitInfo.hity + sprite[nLink].y - sprite[nSprite].y;
z1 = gHitInfo.hitz + sprite[nLink].z - sprite[nSprite].z; z1 = gHitInfo.hitz + sprite[nLink].z - sprite[nSprite].z;
pos = { x1, y1, z1 }; pos = { x1, y1, z1 };
hitData.pos.z = gHitInfo.hitz; hitData.pos.z = gHitInfo.hitz;
hitscan(&pos, sprite[nLink].sectnum, dx, dy, dz<<4, &hitData, CLIPMASK1); hitscan(&pos, sprite[nLink].sectnum, dx, dy, dz<<4, &hitData, CLIPMASK1);
gHitInfo.hitsect = hitData.sect; gHitInfo.set(&hitData);
gHitInfo.hitwall = hitData.wall;
gHitInfo.hitsprite = hitData.sprite;
gHitInfo.hitx = hitData.pos.x;
gHitInfo.hity = hitData.pos.y;
gHitInfo.hitz = hitData.pos.z;
continue; continue;
} }
} }

View file

@ -27,12 +27,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
struct HITINFO { struct HITINFO {
DBloodActor* hitactor;
short hitsect; short hitsect;
short hitwall; short hitwall;
short hitsprite; short hitsprite;
int hitx; int hitx;
int hity; int hity;
int hitz; int hitz;
void clearObj()
{
hitsect = hitwall = -1;
hitsprite = -1;
hitactor = nullptr;
}
void set(hitdata_t* hit);
}; };
extern POINT2D baseWall[kMaxWalls]; extern POINT2D baseWall[kMaxWalls];

View file

@ -615,7 +615,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, HITINFO& w, HITINF
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))
{ {
arc("sect", w.hitsect) arc("sect", w.hitsect)
("sprite", w.hitsprite) ("sprite", w.hitactor)
("wall", w.hitwall) ("wall", w.hitwall)
("x", w.hitx) ("x", w.hitx)
("y", w.hity) ("y", w.hity)

View file

@ -3977,7 +3977,7 @@ bool condCheckSprite(XSPRITE* pXCond, int cmpOp, bool PUSH) {
switch (var) { switch (var) {
case 0: case 4: condPush(pXCond, OBJ_WALL, gHitInfo.hitwall); break; case 0: case 4: condPush(pXCond, OBJ_WALL, gHitInfo.hitwall); break;
case 1: case 2: condPush(pXCond, OBJ_SECTOR, gHitInfo.hitsect); break; case 1: case 2: condPush(pXCond, OBJ_SECTOR, gHitInfo.hitsect); break;
case 3: condPush(pXCond, OBJ_SPRITE, gHitInfo.hitsprite); break; case 3: condPush(pXCond, OBJ_SPRITE, gHitInfo.hitactor? gHitInfo.hitactor->s().index : -1); break;
} }
} }

View file

@ -1254,7 +1254,7 @@ int ActionScan(PLAYER *pPlayer, int *a2, int *a3)
switch (hit) switch (hit)
{ {
case 3: case 3:
*a2 = gHitInfo.hitsprite; *a2 = gHitInfo.hitactor ? gHitInfo.hitactor->s().index : -1;
*a3 = sprite[*a2].extra; *a3 = sprite[*a2].extra;
if (*a3 > 0 && sprite[*a2].statnum == kStatThing) if (*a3 > 0 && sprite[*a2].statnum == kStatThing)
{ {

View file

@ -121,9 +121,9 @@ void viewDrawAimedPlayerName(void)
int hit = HitScan(gView->pSprite, gView->zView, gView->aim.dx, gView->aim.dy, gView->aim.dz, CLIPMASK0, 512); int hit = HitScan(gView->pSprite, gView->zView, gView->aim.dx, gView->aim.dy, gView->aim.dz, CLIPMASK0, 512);
if (hit == 3) if (hit == 3)
{ {
spritetype* pSprite = &sprite[gHitInfo.hitsprite]; if (gHitInfo.hitactor && gHitInfo.hitactor->IsPlayerActor())
if (IsPlayerSprite(pSprite))
{ {
spritetype* pSprite = &gHitInfo.hitactor->s();
int nPlayer = pSprite->type-kDudePlayer1; int nPlayer = pSprite->type-kDudePlayer1;
const char* szName = PlayerName(nPlayer); const char* szName = PlayerName(nPlayer);
int nPalette = (gPlayer[nPlayer].teamId&3)+11; int nPalette = (gPlayer[nPlayer].teamId&3)+11;