From 44b0e59127d27a5a8eea29ce85833333b51ee7e0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 5 May 2021 12:55:52 +0200 Subject: [PATCH] - aiProcessDudes and aiInitSprite done, completing the main pass over ai.cpp. --- source/games/blood/src/actor.cpp | 2 +- source/games/blood/src/ai.cpp | 70 +++++++++++++--------------- source/games/blood/src/ai.h | 2 +- source/games/blood/src/aiunicult.cpp | 4 +- source/games/blood/src/callback.cpp | 2 +- source/games/blood/src/nnexts.cpp | 11 +++-- 6 files changed, 44 insertions(+), 47 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index c5b6cf8c9..64d5b5458 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -6519,7 +6519,7 @@ DBloodActor* actSpawnDude(DBloodActor* source, short nType, int a3, int a4) } #endif - aiInitSprite(pSprite2); + aiInitSprite(spawned); return spawned; } diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index 021f3d17f..4d01e21c5 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -1642,7 +1642,7 @@ void aiLookForTarget(DBloodActor* actor) // //--------------------------------------------------------------------------- -void aiProcessDudes(void) +void aiProcessDudes(void) { BloodStatIterator it(kStatDude); while (auto actor = it.Next()) @@ -1650,10 +1650,10 @@ void aiProcessDudes(void) auto pSprite = &actor->s(); if (pSprite->flags & 32) continue; auto pXSprite = &actor->x(); - DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); + DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type); if (IsPlayerSprite(pSprite) || pXSprite->health == 0) continue; - pXSprite->stateTimer = ClipLow(pXSprite->stateTimer-4, 0); + pXSprite->stateTimer = ClipLow(pXSprite->stateTimer - 4, 0); if (pXSprite->aiState && pXSprite->aiState->moveFunc) pXSprite->aiState->moveFunc(actor); @@ -1662,14 +1662,14 @@ void aiProcessDudes(void) pXSprite->aiState->thinkFunc(actor); switch (pSprite->type) { - #ifdef NOONE_EXTENSIONS +#ifdef NOONE_EXTENSIONS case kDudeModernCustom: case kDudeModernCustomBurning: { GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite); if (pExtra->nLifeLeech >= 0) updateTargetOfLeech(pSprite); if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState - && (pXSprite->aiState->stateTicks > 0 || seqGetStatus(3, pSprite->extra) < 0)) + && (pXSprite->aiState->stateTicks > 0 || seqGetStatus(3, pSprite->extra) < 0)) { aiGenDudeNewState(pSprite, pXSprite->aiState->nextState); } @@ -1679,7 +1679,7 @@ void aiProcessDudes(void) RecoilDude(actor); break; } - #endif +#endif default: if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState) { if (pXSprite->aiState->stateTicks > 0) @@ -1688,7 +1688,7 @@ void aiProcessDudes(void) aiNewState(actor, pXSprite->aiState->nextState); } - if (pXSprite->health > 0 && ((pDudeInfo->hinderDamage << 4) <= actor->cumulDamage)) + if (pXSprite->health > 0 && ((pDudeInfo->hinderDamage << 4) <= actor->cumulDamage)) { pXSprite->data3 = actor->cumulDamage; RecoilDude(actor); @@ -1706,25 +1706,23 @@ void aiProcessDudes(void) void aiInit(void) { - int nSprite; - StatIterator it(kStatDude); - while ((nSprite = it.NextIndex()) >= 0) + BloodStatIterator it(kStatDude); + while (auto actor = it.Next()) { - aiInitSprite(&sprite[nSprite]); + aiInitSprite(actor); } } -void aiInitSprite(spritetype *pSprite) +void aiInitSprite(DBloodActor* actor) { - auto actor = &bloodActors[pSprite->index]; - int nXSprite = pSprite->extra; - XSPRITE *pXSprite = &xsprite[nXSprite]; + auto pSprite = &actor->s(); + auto pXSprite = &actor->x(); int nSector = pSprite->sectnum; int nXSector = sector[nSector].extra; - XSECTOR *pXSector = NULL; + XSECTOR* pXSector = NULL; if (nXSector > 0) pXSector = &xsector[nXSector]; - DUDEEXTRA *pDudeExtra = &actor->dudeExtra; + DUDEEXTRA* pDudeExtra = &actor->dudeExtra; DUDEEXTRA_STATS *pDudeExtraE = &actor->dudeExtra.stats; pDudeExtra->teslaHit = 0; pDudeExtra->time = 0; @@ -1734,21 +1732,21 @@ void aiInitSprite(spritetype *pSprite) #ifdef NOONE_EXTENSIONS int stateTimer = -1, targetMarker = -1; int targetX = 0, targetY = 0, targetZ = 0; - + // dude patrol init - if (gModernMap) { - + if (gModernMap) + { // must keep it in case of loading save if (pXSprite->dudeFlag4 && spriRangeIsFine(pXSprite->target_i) && sprite[pXSprite->target_i].type == kMarkerPath) { stateTimer = pXSprite->stateTimer; targetMarker = pXSprite->target_i; targetX = pXSprite->targetX; targetY = pXSprite->targetY; targetZ = pXSprite->targetZ; } - } - #endif +#endif - switch (pSprite->type) { + switch (pSprite->type) + { case kDudeCultistTommy: case kDudeCultistShotgun: case kDudeCultistTesla: @@ -1903,14 +1901,14 @@ void aiInitSprite(spritetype *pSprite) aiNewState(actor, &genIdle); break; } - aiSetTarget_(pXSprite, 0, 0, 0); + aiSetTarget(actor, 0, 0, 0); pXSprite->stateTimer = 0; switch (pSprite->type) { case kDudeSpiderBrown: case kDudeSpiderRed: case kDudeSpiderBlack: - if (pSprite->cstat&8) pSprite->flags |= 9; + if (pSprite->cstat & 8) pSprite->flags |= 9; else pSprite->flags = 15; break; case kDudeGargoyleFlesh: @@ -1928,7 +1926,7 @@ void aiInitSprite(spritetype *pSprite) case kDudeZombieAxeLaying: pSprite->flags = 7; break; - #ifdef NOONE_EXTENSIONS +#ifdef NOONE_EXTENSIONS case kDudePodMother: // FakeDude type if (gModernMap) break; [[fallthrough]]; @@ -1945,19 +1943,20 @@ void aiInitSprite(spritetype *pSprite) } [[fallthrough]]; // go default - #endif +#endif default: pSprite->flags = 15; break; } - #ifdef NOONE_EXTENSIONS - if (gModernMap) { - - if (pXSprite->dudeFlag4) { - +#ifdef NOONE_EXTENSIONS + if (gModernMap) + { + if (pXSprite->dudeFlag4) + { // restore dude's path - if (spriRangeIsFine(targetMarker)) { + if (spriRangeIsFine(targetMarker)) + { pXSprite->target_i = targetMarker; pXSprite->targetX = targetX; pXSprite->targetY = targetY; @@ -1982,12 +1981,9 @@ void aiInitSprite(spritetype *pSprite) else if (uwater) aiPatrolState(pSprite, kAiStatePatrolMoveW); else if (pXSprite->unused1 & kDudeFlagCrouch) aiPatrolState(pSprite, kAiStatePatrolMoveC); else aiPatrolState(pSprite, kAiStatePatrolMoveL); - } - } - #endif - +#endif } END_BLD_NS diff --git a/source/games/blood/src/ai.h b/source/games/blood/src/ai.h index d85c0bde1..5f2488c71 100644 --- a/source/games/blood/src/ai.h +++ b/source/games/blood/src/ai.h @@ -93,7 +93,7 @@ void aiThinkTarget(DBloodActor* actor); void aiLookForTarget(DBloodActor* actor); void aiProcessDudes(void); void aiInit(void); -void aiInitSprite(spritetype *pSprite); +void aiInitSprite(DBloodActor* pSprite); bool CanMove(DBloodActor* pSprite, int a2, int nAngle, int nRange); void aiSetTarget_(XSPRITE* pXSprite, int x, int y, int z); diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index 3586ee67c..12bbb851a 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -1716,7 +1716,7 @@ spritetype* genDudeSpawn(XSPRITE* pXSource, spritetype* pSprite, int nDist) { } gKillMgr.AddNewKill(1); - aiInitSprite(pDude); + aiInitSprite(spawned); return pDude; } @@ -1814,7 +1814,7 @@ void genDudeTransform(spritetype* pSprite) { int target = pXSprite->target_i; // re-init sprite - aiInitSprite(pSprite); + aiInitSprite(actor); // try to restore target if (target == -1) aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z); diff --git a/source/games/blood/src/callback.cpp b/source/games/blood/src/callback.cpp index 8efa861e4..f86f8185d 100644 --- a/source/games/blood/src/callback.cpp +++ b/source/games/blood/src/callback.cpp @@ -277,7 +277,7 @@ void Respawn(int nSprite) // 9 if (getSequence(getDudeInfo(nType + kDudeBase)->seqStartID)) seqSpawn(getDudeInfo(nType + kDudeBase)->seqStartID, 3, pSprite->extra, -1); #endif - aiInitSprite(pSprite); + aiInitSprite(actor); pXSprite->key = 0; } else if (pSprite->type == kThingTNTBarrel) { pSprite->cstat |= CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 336c69189..34327d409 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -331,7 +331,7 @@ spritetype* nnExtSpawnDude(XSPRITE* pXSource, spritetype* pSprite, short nType, } - aiInitSprite(pDude); + aiInitSprite(pDudeActor); gKillMgr.AddNewKill(1); @@ -342,7 +342,7 @@ spritetype* nnExtSpawnDude(XSPRITE* pXSource, spritetype* pSprite, short nType, } if ((burning || (pSource->flags & kModernTypeFlag3)) && !pXDude->dudeFlag4) - aiActivateDude(&bloodActors[pXDude->reference]); + aiActivateDude(pDudeActor); return pDude; } @@ -2664,6 +2664,7 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) { } void useTeleportTarget(XSPRITE* pXSource, spritetype* pSprite) { + auto actor = &bloodActors[pSprite->index]; spritetype* pSource = &sprite[pXSource->reference]; PLAYER* pPlayer = getPlayerById(pSprite->type); XSECTOR* pXSector = (sector[pSource->sectnum].extra >= 0) ? &xsector[sector[pSource->sectnum].extra] : NULL; bool isDude = (!pPlayer && IsDudeSprite(pSprite)); @@ -2733,7 +2734,7 @@ void useTeleportTarget(XSPRITE* pXSource, spritetype* pSprite) { int x = pXDude->targetX; int y = pXDude->targetY; int z = pXDude->targetZ; int target = pXDude->target_i; - aiInitSprite(pSprite); + aiInitSprite(actor); if (target >= 0) { pXDude->targetX = x; pXDude->targetY = y; pXDude->targetZ = z; @@ -4414,7 +4415,7 @@ void aiFightActivateDudes(int rx) { if (rxBucket[i].type != OBJ_SPRITE) continue; spritetype* pDude = &sprite[rxBucket[i].index]; XSPRITE* pXDude = &xsprite[pDude->extra]; if (!IsDudeSprite(pDude) || pXDude->aiState->stateType != kAiStateGenIdle) continue; - aiInitSprite(pDude); + aiInitSprite(&bloodActors[pDude->index]); } } @@ -6826,7 +6827,7 @@ void aiPatrolStop(spritetype* pSprite, int target, bool alarm) } else { - aiInitSprite(pSprite); + aiInitSprite(actor); aiSetTarget_(pXSprite, pXSprite->targetX, pXSprite->targetY, pXSprite->targetZ);