- use actor parameters for aiSetTarget and aiActivateDude in several places.

This commit is contained in:
Christoph Oelckers 2021-09-16 20:38:46 +02:00
parent 61d9cd1b17
commit 890cc4947b
9 changed files with 58 additions and 56 deletions

View file

@ -986,7 +986,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
else if (actor->GetTarget() == nullptr) // if no target, give the dude a target else if (actor->GetTarget() == nullptr) // if no target, give the dude a target
{ {
aiSetTarget(actor, source); aiSetTarget(actor, source);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (source != actor->GetTarget()) // if found a new target, retarget else if (source != actor->GetTarget()) // if found a new target, retarget
{ {
@ -1530,14 +1530,14 @@ void aiThinkTarget(DBloodActor* actor)
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
} }
@ -1546,6 +1546,7 @@ void aiThinkTarget(DBloodActor* actor)
void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite) void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite)
{ {
auto actor = &bloodActors[pSprite->index];
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax); assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
if (Chance(pDudeInfo->alertChance)) if (Chance(pDudeInfo->alertChance))
@ -1569,14 +1570,14 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite)
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
} }
@ -1586,11 +1587,10 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite)
const bool newSectCheckMethod = !cl_bloodvanillaenemies && !VanillaMode(); // use new sector checking logic const bool newSectCheckMethod = !cl_bloodvanillaenemies && !VanillaMode(); // use new sector checking logic
GetClosestSpriteSectors(pSprite->sectnum, pSprite->x, pSprite->y, 400, sectmap, nullptr, newSectCheckMethod); GetClosestSpriteSectors(pSprite->sectnum, pSprite->x, pSprite->y, 400, sectmap, nullptr, newSectCheckMethod);
int nSprite2; BloodStatIterator it(kStatDude);
StatIterator it(kStatDude); while (DBloodActor* actor2 = it.Next())
while ((nSprite2 = it.NextIndex()) >= 0)
{ {
spritetype *pSprite2 = &sprite[nSprite2]; spritetype* pSprite2 = &actor2->s();
int dx = pSprite2->x-pSprite->x; int dx = pSprite2->x-pSprite->x;
int dy = pSprite2->y-pSprite->y; int dy = pSprite2->y-pSprite->y;
int nDist = approxDist(dx, dy); int nDist = approxDist(dx, dy);
@ -1599,8 +1599,8 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite)
DUDEINFO *pDudeInfo = getDudeInfo(pSprite2->type); DUDEINFO *pDudeInfo = getDudeInfo(pSprite2->type);
if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist) if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist)
continue; continue;
aiSetTarget_(pXSprite, pSprite2->index); aiSetTarget(actor, actor2);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
} }

View file

@ -92,7 +92,7 @@ static void batThinkTarget(DBloodActor* actor)
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
aiNewState(actor, &batTurn); aiNewState(actor, &batTurn);
return; return;
} }
@ -117,13 +117,13 @@ static void batThinkTarget(DBloodActor* actor)
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;
@ -439,7 +439,7 @@ void batMoveToCeil(DBloodActor* actor)
aiNewState(actor, &batIdle); aiNewState(actor, &batIdle);
} }
else else
aiSetTarget_(pXSprite, x, y, sector[nSector].ceilingz); aiSetTarget(actor, x, y, sector[nSector].ceilingz);
} }
END_BLD_NS END_BLD_NS

View file

@ -104,7 +104,7 @@ static void eelThinkTarget(DBloodActor* actor)
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
aiNewState(actor, &eelTurn); aiNewState(actor, &eelTurn);
return; return;
} }
@ -130,14 +130,14 @@ static void eelThinkTarget(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;
@ -441,7 +441,7 @@ void eelMoveToCeil(DBloodActor* actor)
aiNewState(actor, &eelIdle); aiNewState(actor, &eelIdle);
} }
else else
aiSetTarget_(pXSprite, x, y, sector[nSector].ceilingz); aiSetTarget(actor, x, y, sector[nSector].ceilingz);
} }
END_BLD_NS END_BLD_NS

View file

@ -262,7 +262,7 @@ static void cerberusThinkTarget(DBloodActor* actor)
{ {
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
if (pSprite->type == kDudeCerberusTwoHead) if (pSprite->type == kDudeCerberusTwoHead)
aiNewState(actor, &cerberus139890); aiNewState(actor, &cerberus139890);
else else
@ -291,14 +291,14 @@ static void cerberusThinkTarget(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;

View file

@ -223,7 +223,7 @@ static void gargThinkTarget(DBloodActor* actor)
{ {
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
aiNewState(actor, &gargoyleTurn); aiNewState(actor, &gargoyleTurn);
return; return;
} }
@ -249,14 +249,14 @@ static void gargThinkTarget(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;

View file

@ -200,7 +200,7 @@ static void ghostThinkTarget(DBloodActor* actor)
{ {
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
aiNewState(actor, &ghostTurn); aiNewState(actor, &ghostTurn);
return; return;
} }
@ -226,15 +226,15 @@ static void ghostThinkTarget(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
return; return;
} }
} }

View file

@ -234,7 +234,7 @@ static void sub_725A4(DBloodActor* actor)
{ {
pXSprite->goalAng += 256; pXSprite->goalAng += 256;
POINT3D *pTarget = &baseSprite[pSprite->index]; POINT3D *pTarget = &baseSprite[pSprite->index];
aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z);
aiNewState(actor, &tcherno13AA28); aiNewState(actor, &tcherno13AA28);
return; return;
} }
@ -260,14 +260,14 @@ static void sub_725A4(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
pDudeExtraE->thinkTime = 0; pDudeExtraE->thinkTime = 0;
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;

View file

@ -466,7 +466,7 @@ static void unicultThinkChase(DBloodActor* actor)
GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index];
if (!pExtra->canAttack) { if (!pExtra->canAttack) {
if (pExtra->canWalk) aiSetTarget_(pXSprite, pSprite->index); if (pExtra->canWalk) aiSetTarget(actor, actor); // targeting self???
if (spriteIsUnderwater(pSprite, false)) aiGenDudeNewState(pSprite, &genDudeGotoW); if (spriteIsUnderwater(pSprite, false)) aiGenDudeNewState(pSprite, &genDudeGotoW);
else aiGenDudeNewState(pSprite, &genDudeGotoL); else aiGenDudeNewState(pSprite, &genDudeGotoL);
return; return;
@ -595,8 +595,9 @@ static void unicultThinkChase(DBloodActor* actor)
} else if (weaponType == kGenDudeWeaponSummon) { } else if (weaponType == kGenDudeWeaponSummon) {
// don't attack slaves // don't attack slaves
if (pXSprite->target_i >= 0 && sprite[pXSprite->target_i].owner == pSprite->index) { if (actor->GetTarget() != nullptr && actor->GetTarget()->GetOwner() == actor)
aiSetTarget_(pXSprite, pSprite->x, pSprite->y, pSprite->z); {
aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z);
return; return;
} else if (gGenDudeExtra[pSprite->index].slaveCount > gGameOptions.nDifficulty || dist < meleeVector->maxDist) { } else if (gGenDudeExtra[pSprite->index].slaveCount > gGameOptions.nDifficulty || dist < meleeVector->maxDist) {
if (dist <= meleeVector->maxDist) { if (dist <= meleeVector->maxDist) {
@ -1728,6 +1729,7 @@ void genDudeTransform(spritetype* pSprite) {
} }
XSPRITE* pXSprite = &xsprite[pSprite->extra]; XSPRITE* pXSprite = &xsprite[pSprite->extra];
auto actor = &bloodActors[pXSprite->reference];
XSPRITE* pXIncarnation = getNextIncarnation(pXSprite); XSPRITE* pXIncarnation = getNextIncarnation(pXSprite);
if (pXIncarnation == NULL) { if (pXIncarnation == NULL) {
if (pXSprite->sysData1 == kGenDudeTransformStatus) pXSprite->sysData1 = 0; if (pXSprite->sysData1 == kGenDudeTransformStatus) pXSprite->sysData1 = 0;
@ -1816,11 +1818,11 @@ void genDudeTransform(spritetype* pSprite) {
aiInitSprite(pSprite); aiInitSprite(pSprite);
// try to restore target // try to restore target
if (target == -1) aiSetTarget_(pXSprite, pSprite->x, pSprite->y, pSprite->z); if (target == -1) aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z);
else aiSetTarget_(pXSprite, target); else aiSetTarget_(pXSprite, target);
// finally activate it // finally activate it
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
break; break;
} }

View file

@ -239,13 +239,13 @@ static void myThinkTarget(DBloodActor* actor)
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{ {
aiSetTarget_(pXSprite, pPlayer->nSprite); aiSetTarget(actor, pPlayer->actor());
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else if (nDist < pDudeInfo->hearDist) else if (nDist < pDudeInfo->hearDist)
{ {
aiSetTarget_(pXSprite, x, y, z); aiSetTarget(actor, x, y, z);
aiActivateDude(&bloodActors[pXSprite->reference]); aiActivateDude(actor);
} }
else else
continue; continue;