From 890cc4947bf81187dea4aadbbe4bf788a6b739a0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Sep 2021 20:38:46 +0200 Subject: [PATCH] - use actor parameters for aiSetTarget and aiActivateDude in several places. --- source/games/blood/src/ai.cpp | 30 ++++++++++++++-------------- source/games/blood/src/aibat.cpp | 12 +++++------ source/games/blood/src/aiboneel.cpp | 12 +++++------ source/games/blood/src/aicerber.cpp | 10 +++++----- source/games/blood/src/aigarg.cpp | 10 +++++----- source/games/blood/src/aighost.cpp | 10 +++++----- source/games/blood/src/aitchern.cpp | 10 +++++----- source/games/blood/src/aiunicult.cpp | 12 ++++++----- source/games/blood/src/aizomba.cpp | 8 ++++---- 9 files changed, 58 insertions(+), 56 deletions(-) diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index f4f93c821..68782e60a 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -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 { aiSetTarget(actor, source); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiActivateDude(actor); } 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; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); return; } else if (nDist < pDudeInfo->hearDist) { - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); return; } } @@ -1546,6 +1546,7 @@ void aiThinkTarget(DBloodActor* actor) void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite) { + auto actor = &bloodActors[pSprite->index]; assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax); DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); if (Chance(pDudeInfo->alertChance)) @@ -1569,14 +1570,14 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite) int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); return; } else if (nDist < pDudeInfo->hearDist) { - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); return; } } @@ -1586,11 +1587,10 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite) const bool newSectCheckMethod = !cl_bloodvanillaenemies && !VanillaMode(); // use new sector checking logic GetClosestSpriteSectors(pSprite->sectnum, pSprite->x, pSprite->y, 400, sectmap, nullptr, newSectCheckMethod); - int nSprite2; - StatIterator it(kStatDude); - while ((nSprite2 = it.NextIndex()) >= 0) + BloodStatIterator it(kStatDude); + while (DBloodActor* actor2 = it.Next()) { - spritetype *pSprite2 = &sprite[nSprite2]; + spritetype* pSprite2 = &actor2->s(); int dx = pSprite2->x-pSprite->x; int dy = pSprite2->y-pSprite->y; int nDist = approxDist(dx, dy); @@ -1599,8 +1599,8 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite) DUDEINFO *pDudeInfo = getDudeInfo(pSprite2->type); if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist) continue; - aiSetTarget_(pXSprite, pSprite2->index); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, actor2); + aiActivateDude(actor); return; } } diff --git a/source/games/blood/src/aibat.cpp b/source/games/blood/src/aibat.cpp index 862a9799f..c94858020 100644 --- a/source/games/blood/src/aibat.cpp +++ b/source/games/blood/src/aibat.cpp @@ -92,7 +92,7 @@ static void batThinkTarget(DBloodActor* actor) pDudeExtraE->thinkTime = 0; pXSprite->goalAng += 256; POINT3D *pTarget = &baseSprite[pSprite->index]; - aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); + aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z); aiNewState(actor, &batTurn); return; } @@ -117,13 +117,13 @@ static void batThinkTarget(DBloodActor* actor) int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue; @@ -439,7 +439,7 @@ void batMoveToCeil(DBloodActor* actor) aiNewState(actor, &batIdle); } else - aiSetTarget_(pXSprite, x, y, sector[nSector].ceilingz); + aiSetTarget(actor, x, y, sector[nSector].ceilingz); } END_BLD_NS diff --git a/source/games/blood/src/aiboneel.cpp b/source/games/blood/src/aiboneel.cpp index 1f6c92315..ace561d8a 100644 --- a/source/games/blood/src/aiboneel.cpp +++ b/source/games/blood/src/aiboneel.cpp @@ -104,7 +104,7 @@ static void eelThinkTarget(DBloodActor* actor) pDudeExtraE->thinkTime = 0; pXSprite->goalAng += 256; POINT3D *pTarget = &baseSprite[pSprite->index]; - aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); + aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z); aiNewState(actor, &eelTurn); return; } @@ -130,14 +130,14 @@ static void eelThinkTarget(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue; @@ -441,7 +441,7 @@ void eelMoveToCeil(DBloodActor* actor) aiNewState(actor, &eelIdle); } else - aiSetTarget_(pXSprite, x, y, sector[nSector].ceilingz); + aiSetTarget(actor, x, y, sector[nSector].ceilingz); } END_BLD_NS diff --git a/source/games/blood/src/aicerber.cpp b/source/games/blood/src/aicerber.cpp index efda00e60..0132276fd 100644 --- a/source/games/blood/src/aicerber.cpp +++ b/source/games/blood/src/aicerber.cpp @@ -262,7 +262,7 @@ static void cerberusThinkTarget(DBloodActor* actor) { pXSprite->goalAng += 256; 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) aiNewState(actor, &cerberus139890); else @@ -291,14 +291,14 @@ static void cerberusThinkTarget(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue; diff --git a/source/games/blood/src/aigarg.cpp b/source/games/blood/src/aigarg.cpp index e82d36fea..859fccd6c 100644 --- a/source/games/blood/src/aigarg.cpp +++ b/source/games/blood/src/aigarg.cpp @@ -223,7 +223,7 @@ static void gargThinkTarget(DBloodActor* actor) { pXSprite->goalAng += 256; POINT3D *pTarget = &baseSprite[pSprite->index]; - aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); + aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z); aiNewState(actor, &gargoyleTurn); return; } @@ -249,14 +249,14 @@ static void gargThinkTarget(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue; diff --git a/source/games/blood/src/aighost.cpp b/source/games/blood/src/aighost.cpp index 3812a098a..53ce17fda 100644 --- a/source/games/blood/src/aighost.cpp +++ b/source/games/blood/src/aighost.cpp @@ -200,7 +200,7 @@ static void ghostThinkTarget(DBloodActor* actor) { pXSprite->goalAng += 256; POINT3D *pTarget = &baseSprite[pSprite->index]; - aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); + aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z); aiNewState(actor, &ghostTurn); return; } @@ -226,15 +226,15 @@ static void ghostThinkTarget(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); return; } else if (nDist < pDudeInfo->hearDist) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); return; } } diff --git a/source/games/blood/src/aitchern.cpp b/source/games/blood/src/aitchern.cpp index 8f7f28c0c..3407024cb 100644 --- a/source/games/blood/src/aitchern.cpp +++ b/source/games/blood/src/aitchern.cpp @@ -234,7 +234,7 @@ static void sub_725A4(DBloodActor* actor) { pXSprite->goalAng += 256; POINT3D *pTarget = &baseSprite[pSprite->index]; - aiSetTarget_(pXSprite, pTarget->x, pTarget->y, pTarget->z); + aiSetTarget(actor, pTarget->x, pTarget->y, pTarget->z); aiNewState(actor, &tcherno13AA28); return; } @@ -260,14 +260,14 @@ static void sub_725A4(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { pDudeExtraE->thinkTime = 0; - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue; diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index 6a712dbf2..422dd6eb2 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -466,7 +466,7 @@ static void unicultThinkChase(DBloodActor* actor) GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; 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); else aiGenDudeNewState(pSprite, &genDudeGotoL); return; @@ -595,8 +595,9 @@ static void unicultThinkChase(DBloodActor* actor) } else if (weaponType == kGenDudeWeaponSummon) { // don't attack slaves - if (pXSprite->target_i >= 0 && sprite[pXSprite->target_i].owner == pSprite->index) { - aiSetTarget_(pXSprite, pSprite->x, pSprite->y, pSprite->z); + if (actor->GetTarget() != nullptr && actor->GetTarget()->GetOwner() == actor) + { + aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z); return; } else if (gGenDudeExtra[pSprite->index].slaveCount > gGameOptions.nDifficulty || dist < meleeVector->maxDist) { if (dist <= meleeVector->maxDist) { @@ -1728,6 +1729,7 @@ void genDudeTransform(spritetype* pSprite) { } XSPRITE* pXSprite = &xsprite[pSprite->extra]; + auto actor = &bloodActors[pXSprite->reference]; XSPRITE* pXIncarnation = getNextIncarnation(pXSprite); if (pXIncarnation == NULL) { if (pXSprite->sysData1 == kGenDudeTransformStatus) pXSprite->sysData1 = 0; @@ -1816,11 +1818,11 @@ void genDudeTransform(spritetype* pSprite) { aiInitSprite(pSprite); // 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); // finally activate it - aiActivateDude(&bloodActors[pXSprite->reference]); + aiActivateDude(actor); break; } diff --git a/source/games/blood/src/aizomba.cpp b/source/games/blood/src/aizomba.cpp index a1e1620a0..f5124e0f8 100644 --- a/source/games/blood/src/aizomba.cpp +++ b/source/games/blood/src/aizomba.cpp @@ -239,13 +239,13 @@ static void myThinkTarget(DBloodActor* actor) int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024; if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) { - aiSetTarget_(pXSprite, pPlayer->nSprite); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, pPlayer->actor()); + aiActivateDude(actor); } else if (nDist < pDudeInfo->hearDist) { - aiSetTarget_(pXSprite, x, y, z); - aiActivateDude(&bloodActors[pXSprite->reference]); + aiSetTarget(actor, x, y, z); + aiActivateDude(actor); } else continue;