From c8501f8ea6f7de6faa41b32140f3892b56bc768d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Sep 2021 19:32:46 +0200 Subject: [PATCH] - refactored aiSetTarget --- source/games/blood/src/actor.cpp | 12 ++++++++++++ source/games/blood/src/ai.cpp | 32 +++++++++++++++---------------- source/games/blood/src/ai.h | 5 +++-- source/games/blood/src/nnexts.cpp | 21 +++++++++++--------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 862eb29a8..8d12fb4fd 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -7403,6 +7403,7 @@ void SerializeActor(FSerializer& arc) } } +// dumping ground for temporary wrappers. int actDamageSprite(int nSource, spritetype* pSprite, DAMAGE_TYPE damageType, int damage) { return actDamageSprite(nSource == -1 ? nullptr : &bloodActors[nSource], &bloodActors[pSprite->index], damageType, damage); @@ -7423,5 +7424,16 @@ void aiPlay3DSound(spritetype* pSprite, int a2, AI_SFX_PRIORITY a3, int a4) return aiPlay3DSound(&bloodActors[pSprite->index], a2, a3, a4); } +void aiSetTarget_(XSPRITE* pXSprite, int nTarget) +{ + aiSetTarget(&bloodActors[pXSprite->reference], &bloodActors[nTarget]); +} + +void aiSetTarget_(XSPRITE* pXSprite, int x, int y, int z) +{ + aiSetTarget(&bloodActors[pXSprite->reference], x, y, z); +} + + END_BLD_NS diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index 8ca8430c8..ebf8c9744 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -930,37 +930,37 @@ void aiActivateDude(DBloodActor* actor) // //--------------------------------------------------------------------------- -void aiSetTarget_(XSPRITE *pXSprite, int x, int y, int z) +void aiSetTarget(DBloodActor*actor, int x, int y, int z) { - pXSprite->target_i = -1; + auto pXSprite = &actor->x(); + actor->SetTarget(nullptr); pXSprite->targetX = x; pXSprite->targetY = y; pXSprite->targetZ = z; } -void aiSetTarget_(XSPRITE *pXSprite, int nTarget) +void aiSetTarget(DBloodActor* actor, DBloodActor* target) { - assert(nTarget >= 0 && nTarget < kMaxSprites); - spritetype *pTarget = &sprite[nTarget]; + if (target == nullptr) + { + actor->SetTarget(nullptr); + return; + } + auto pXSprite = &actor->x(); + spritetype* pTarget = &target->s(); if (pTarget->type >= kDudeBase && pTarget->type < kDudeMax) { - if (sprite[pXSprite->reference].owner != nTarget) + if (actor->GetOwner() != target) { - pXSprite->target_i = nTarget; - DUDEINFO *pDudeInfo = getDudeInfo(pTarget->type); + actor->SetTarget(target); + DUDEINFO* pDudeInfo = getDudeInfo(pTarget->type); pXSprite->targetX = pTarget->x; pXSprite->targetY = pTarget->y; - pXSprite->targetZ = pTarget->z-((pDudeInfo->eyeHeight*pTarget->yrepeat)<<2); + pXSprite->targetZ = pTarget->z - ((pDudeInfo->eyeHeight * pTarget->yrepeat) << 2); } } } -void aiSetTarget(DBloodActor* actor, DBloodActor* target) -{ - aiSetTarget_(&actor->x(), target ? target->x().reference : -1); -} - - int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType, int nDamage) { auto pSprite = &actor->s(); @@ -991,7 +991,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType nThresh *= pDudeInfo->changeTarget; if (Chance(nThresh)) { - aiSetTarget_(pXSprite, nSource); + aiSetTarget(actor, source); aiActivateDude(&bloodActors[pXSprite->reference]); } } diff --git a/source/games/blood/src/ai.h b/source/games/blood/src/ai.h index 9a6e1aa21..a6f4dd3b1 100644 --- a/source/games/blood/src/ai.h +++ b/source/games/blood/src/ai.h @@ -86,8 +86,7 @@ void aiMoveForward(DBloodActor*pXSprite); void aiMoveTurn(DBloodActor*pXSprite); void aiMoveDodge(DBloodActor *actor); void aiActivateDude(DBloodActor *actor); -void aiSetTarget_(XSPRITE *pXSprite, int x, int y, int z); -void aiSetTarget_(XSPRITE *pXSprite, int nTarget); +void aiSetTarget(DBloodActor* pXSprite, int x, int y, int z); void aiSetTarget(DBloodActor* actor, DBloodActor* target); int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType, int nDamage); void aiThinkTarget(DBloodActor* actor); @@ -99,5 +98,7 @@ bool CanMove(DBloodActor* pSprite, int a2, int nAngle, int nRange); bool dudeIsPlayingSeq(spritetype* pSprite, int nSeq); // deprecated void aiPlay3DSound(spritetype* pSprite, int a2, AI_SFX_PRIORITY a3, int a4); +void aiSetTarget_(XSPRITE* pXSprite, int x, int y, int z); +void aiSetTarget_(XSPRITE* pXSprite, int nTarget); END_BLD_NS diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index d81eaaa24..6d4f26133 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -6948,6 +6948,7 @@ void aiPatrolAlarmLite(spritetype* pSprite, XSPRITE* pXTarget) { if (!xsprIsFine(pSprite) || !IsDudeSprite(pSprite)) return; + auto targetactor = &bloodActors[pXTarget->reference]; XSPRITE* pXSprite = &xsprite[pSprite->extra]; if (pXSprite->health <= 0) return; @@ -6960,11 +6961,12 @@ void aiPatrolAlarmLite(spritetype* pSprite, XSPRITE* pXTarget) { for (int nSprite = headspritestat[kStatDude]; nSprite >= 0; nSprite = nextspritestat[nSprite]) { - pDude = &sprite[nSprite]; + auto dudeactor = &bloodActors[nSprite]; + pDude = &dudeactor->s(); if (pDude->index == pSprite->index || !IsDudeSprite(pDude) || IsPlayerSprite(pDude) || pDude->extra < 0) continue; - pXDude = &xsprite[pDude->extra]; + pXDude = &dudeactor->x(); if (pXDude->health <= 0) continue; @@ -6982,8 +6984,8 @@ void aiPatrolAlarmLite(spritetype* pSprite, XSPRITE* pXTarget) { if (pXDude->target_i >= 0 || pXDude->target_i == pXSprite->target_i) continue; - aiSetTarget_(pXDude, pXTarget->reference); - aiActivateDude(&bloodActors[pXDude->reference]); + aiSetTarget(dudeactor, targetactor); + aiActivateDude(dudeactor); } @@ -7010,11 +7012,12 @@ void aiPatrolAlarmFull(spritetype* pSprite, XSPRITE* pXTarget, bool chain) { for (int nSprite = headspritestat[kStatDude]; nSprite >= 0; nSprite = nextspritestat[nSprite]) { - pDude = &sprite[nSprite]; + auto dudeactor = &bloodActors[nSprite]; + pDude = &dudeactor->s(); if (pDude->index == pSprite->index || !IsDudeSprite(pDude) || IsPlayerSprite(pDude) || pDude->extra < 0) continue; - pXDude = &xsprite[pDude->extra]; + pXDude = &dudeactor->x(); if (pXDude->health <= 0) continue; @@ -7033,9 +7036,9 @@ void aiPatrolAlarmFull(spritetype* pSprite, XSPRITE* pXTarget, bool chain) { if (pXDude->target_i >= 0 || pXDude->target_i == pXSprite->target_i) continue; - if (spriRangeIsFine(pXSprite->target_i)) aiSetTarget_(pXDude, pXSprite->target_i); - else aiSetTarget_(pXDude, pSprite->x, pSprite->y, pSprite->z); - aiActivateDude(&bloodActors[pXDude->reference]); + if (spriRangeIsFine(pXSprite->target_i)) aiSetTarget(dudeactor, &bloodActors[pXSprite->target_i]); + else aiSetTarget(dudeactor, pSprite->x, pSprite->y, pSprite->z); + aiActivateDude(dudeactor); if (chain) aiPatrolAlarmFull(pDude, pXTarget, Chance(0x0010));