From 774a015e6b7505dc6e8c9d80a4868be380a03cfc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Sep 2021 00:17:37 +0200 Subject: [PATCH] - aiChooseDirection and its subfunctions. --- source/games/blood/src/ai.cpp | 47 +++++++++++++++------------- source/games/blood/src/ai.h | 4 +-- source/games/blood/src/aibat.cpp | 8 ++--- source/games/blood/src/aibeast.cpp | 10 +++--- source/games/blood/src/aiboneel.cpp | 8 ++--- source/games/blood/src/aiburn.cpp | 6 ++-- source/games/blood/src/aicaleb.cpp | 10 +++--- source/games/blood/src/aicerber.cpp | 6 ++-- source/games/blood/src/aicult.cpp | 6 ++-- source/games/blood/src/aigarg.cpp | 6 ++-- source/games/blood/src/aighost.cpp | 6 ++-- source/games/blood/src/aigilbst.cpp | 10 +++--- source/games/blood/src/aihand.cpp | 6 ++-- source/games/blood/src/aihound.cpp | 6 ++-- source/games/blood/src/aiinnoc.cpp | 6 ++-- source/games/blood/src/aipod.cpp | 6 ++-- source/games/blood/src/airat.cpp | 6 ++-- source/games/blood/src/aispid.cpp | 6 ++-- source/games/blood/src/aitchern.cpp | 6 ++-- source/games/blood/src/aiunicult.cpp | 25 ++++++++------- source/games/blood/src/aizomba.cpp | 10 +++--- source/games/blood/src/aizombf.cpp | 6 ++-- source/games/blood/src/nnexts.cpp | 1 + 23 files changed, 109 insertions(+), 102 deletions(-) diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index de0485788..89e122a24 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -96,11 +96,11 @@ void aiNewState(DBloodActor* actor, AISTATE *pAIState) { seqStartId += pAIState->seqId; if (getSequence(seqStartId)) - seqSpawn(seqStartId, 3, pSprite->extra, pAIState->funcId); + seqSpawn(seqStartId, actor, pAIState->funcId); } if (pAIState->enterFunc) - pAIState->enterFunc(&bloodActors[pXSprite->reference]); + pAIState->enterFunc(actor); } //--------------------------------------------------------------------------- @@ -109,17 +109,18 @@ void aiNewState(DBloodActor* actor, AISTATE *pAIState) // //--------------------------------------------------------------------------- -bool isImmune(spritetype* pSprite, int dmgType, int minScale) +static bool isImmune(DBloodActor* actor, int dmgType, int minScale) { - if (dmgType >= kDmgFall && dmgType < kDmgMax && pSprite->extra >= 0 && xsprite[pSprite->extra].locked != 1) + if (dmgType >= kDmgFall && dmgType < kDmgMax && actor->hasX() && actor->x().locked != 1) { - if (pSprite->type >= kThingBase && pSprite->type < kThingMax) - return (thingInfo[pSprite->type - kThingBase].dmgControl[dmgType] <= minScale); - else if (IsDudeSprite(pSprite)) + int type = actor->s().type; + if (type >= kThingBase && type < kThingMax) + return (thingInfo[type - kThingBase].dmgControl[dmgType] <= minScale); + else if (actor->IsDudeActor()) { - if (IsPlayerSprite(pSprite)) return (gPlayer[pSprite->type - kDudePlayer1].godMode || gPlayer[pSprite->type - kDudePlayer1].damageControl[dmgType] <= minScale); - else return (dudeInfo[pSprite->type - kDudeBase].damageVal[dmgType] <= minScale); + if (actor->IsPlayerActor()) return (gPlayer[type - kDudePlayer1].godMode || gPlayer[type - kDudePlayer1].damageControl[dmgType] <= minScale); + else return (dudeInfo[type - kDudeBase].damageVal[dmgType] <= minScale); } } return true; @@ -131,8 +132,9 @@ bool isImmune(spritetype* pSprite, int dmgType, int minScale) // //--------------------------------------------------------------------------- -bool CanMove(spritetype *pSprite, int a2, int nAngle, int nRange) +bool CanMove(DBloodActor *actor, int a2, int nAngle, int nRange) { + auto pSprite = &actor->s(); int top, bottom; GetSpriteExtents(pSprite, &top, &bottom); int x = pSprite->x; @@ -207,7 +209,7 @@ bool CanMove(spritetype *pSprite, int a2, int nAngle, int nRange) // It makes ignore danger if enemy immune to N damageType. As result Cerberus start acting like // in Blood 1.0 so it can move normally to player. It's up to you for adding rest of enemies here as // i don't think it will broke something in game. - if (!cl_bloodvanillaenemies && !VanillaMode() && Crusher && isImmune(pSprite, pXSector->damageType, 16)) return true; + if (!cl_bloodvanillaenemies && !VanillaMode() && Crusher && isImmune(actor, pXSector->damageType, 16)) return true; [[fallthrough]]; case kDudeZombieButcher: case kDudeSpiderBrown: @@ -250,8 +252,11 @@ bool CanMove(spritetype *pSprite, int a2, int nAngle, int nRange) // //--------------------------------------------------------------------------- -void aiChooseDirection(spritetype *pSprite, XSPRITE *pXSprite, int a3) +void aiChooseDirection(DBloodActor* actor, int a3) { + auto pXSprite = &actor->x(); + auto pSprite = &actor->s(); + int nSprite = pSprite->index; assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax); int vc = ((a3+1024-pSprite->ang)&2047)-1024; @@ -264,17 +269,17 @@ void aiChooseDirection(spritetype *pSprite, XSPRITE *pXSprite, int a3) int v8 = 341; if (vc < 0) v8 = -341; - if (CanMove(pSprite, pXSprite->target, pSprite->ang+vc, vsi)) + if (CanMove(actor, pXSprite->target, pSprite->ang+vc, vsi)) pXSprite->goalAng = pSprite->ang+vc; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang+vc/2, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang+vc/2, vsi)) pXSprite->goalAng = pSprite->ang+vc/2; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang-vc/2, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang-vc/2, vsi)) pXSprite->goalAng = pSprite->ang-vc/2; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang+v8, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang+v8, vsi)) pXSprite->goalAng = pSprite->ang+v8; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang, vsi)) pXSprite->goalAng = pSprite->ang; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang-v8, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang-v8, vsi)) pXSprite->goalAng = pSprite->ang-v8; //else if (pSprite->flags&2) //pXSprite->goalAng = pSprite->ang+341; @@ -284,10 +289,10 @@ void aiChooseDirection(spritetype *pSprite, XSPRITE *pXSprite, int a3) pXSprite->dodgeDir = 1; else pXSprite->dodgeDir = -1; - if (!CanMove(pSprite, pXSprite->target, pSprite->ang+pXSprite->dodgeDir*512, 512)) + if (!CanMove(actor, pXSprite->target, pSprite->ang+pXSprite->dodgeDir*512, 512)) { pXSprite->dodgeDir = -pXSprite->dodgeDir; - if (!CanMove(pSprite, pXSprite->target, pSprite->ang+pXSprite->dodgeDir*512, 512)) + if (!CanMove(actor, pXSprite->target, pSprite->ang+pXSprite->dodgeDir*512, 512)) pXSprite->dodgeDir = 0; } } @@ -376,7 +381,7 @@ void aiActivateDude(DBloodActor* actor) assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax); if (!pXSprite->state) { - aiChooseDirection(pSprite, pXSprite, getangle(pXSprite->targetX-pSprite->x, pXSprite->targetY-pSprite->y)); + aiChooseDirection(actor, getangle(pXSprite->targetX-pSprite->x, pXSprite->targetY-pSprite->y)); pXSprite->state = 1; } switch (pSprite->type) diff --git a/source/games/blood/src/ai.h b/source/games/blood/src/ai.h index b097fed0c..2443ddd3c 100644 --- a/source/games/blood/src/ai.h +++ b/source/games/blood/src/ai.h @@ -91,7 +91,7 @@ extern const int dword_138BB0[5]; bool dudeIsPlayingSeq(DBloodActor* pSprite, int nSeq); void aiPlay3DSound(DBloodActor* pSprite, int a2, AI_SFX_PRIORITY a3, int a4); void aiNewState(DBloodActor* actor, AISTATE *pAIState); -void aiChooseDirection(spritetype *pSprite, XSPRITE *pXSprite, int a3); +void aiChooseDirection(DBloodActor* actor, int a3); void aiMoveForward(DBloodActor*pXSprite); void aiMoveTurn(DBloodActor*pXSprite); void aiMoveDodge(DBloodActor *actor); @@ -104,7 +104,7 @@ void aiLookForTarget(spritetype *pSprite, XSPRITE *pXSprite); void aiProcessDudes(void); void aiInit(void); void aiInitSprite(spritetype *pSprite); -bool CanMove(spritetype* pSprite, int a2, int nAngle, int nRange); +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); diff --git a/source/games/blood/src/aibat.cpp b/source/games/blood/src/aibat.cpp index 8726664b9..e2579c641 100644 --- a/source/games/blood/src/aibat.cpp +++ b/source/games/blood/src/aibat.cpp @@ -136,7 +136,7 @@ static void batThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor, pXSprite->goalAng); batThinkTarget(actor); } @@ -150,7 +150,7 @@ static void batThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor, nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &batSearch); batThinkTarget(actor); @@ -172,7 +172,7 @@ static void batThinkPonder(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor, getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &batSearch); @@ -280,7 +280,7 @@ static void batThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor, getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &batSearch); diff --git a/source/games/blood/src/aibeast.cpp b/source/games/blood/src/aibeast.cpp index 9cb99eaea..d4f7dc07f 100644 --- a/source/games/blood/src/aibeast.cpp +++ b/source/games/blood/src/aibeast.cpp @@ -187,7 +187,7 @@ static void beastThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -207,7 +207,7 @@ static void beastThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { if (pXSector && pXSector->Underwater) @@ -243,7 +243,7 @@ static void beastThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { XSECTOR *pXSector; @@ -391,7 +391,7 @@ static void beastThinkSwimGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &beastSwimSearch); aiThinkTarget(actor); @@ -413,7 +413,7 @@ static void beastThinkSwimChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &beastSwimSearch); diff --git a/source/games/blood/src/aiboneel.cpp b/source/games/blood/src/aiboneel.cpp index 117a16bfd..97c640acd 100644 --- a/source/games/blood/src/aiboneel.cpp +++ b/source/games/blood/src/aiboneel.cpp @@ -149,7 +149,7 @@ static void eelThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); eelThinkTarget(actor); } @@ -163,7 +163,7 @@ static void eelThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &eelSearch); eelThinkTarget(actor); @@ -185,7 +185,7 @@ static void eelThinkPonder(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &eelSearch); @@ -293,7 +293,7 @@ static void eelThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &eelSearch); diff --git a/source/games/blood/src/aiburn.cpp b/source/games/blood/src/aiburn.cpp index 7470a20e0..5c015c090 100644 --- a/source/games/blood/src/aiburn.cpp +++ b/source/games/blood/src/aiburn.cpp @@ -79,7 +79,7 @@ static void burnThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -93,7 +93,7 @@ static void burnThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { switch (pSprite->type) @@ -167,7 +167,7 @@ static void burnThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { switch (pSprite->type) diff --git a/source/games/blood/src/aicaleb.cpp b/source/games/blood/src/aicaleb.cpp index 93cb06236..0663b1cee 100644 --- a/source/games/blood/src/aicaleb.cpp +++ b/source/games/blood/src/aicaleb.cpp @@ -86,7 +86,7 @@ static void calebThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -106,7 +106,7 @@ static void calebThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { if (pXSector && pXSector->Underwater) @@ -142,7 +142,7 @@ static void calebThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { XSECTOR *pXSector; @@ -256,7 +256,7 @@ static void calebThinkSwimGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &tinycalebSwimSearch); aiThinkTarget(actor); @@ -278,7 +278,7 @@ static void calebThinkSwimChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &tinycalebSwimSearch); diff --git a/source/games/blood/src/aicerber.cpp b/source/games/blood/src/aicerber.cpp index 8c732f24a..b65ca31f8 100644 --- a/source/games/blood/src/aicerber.cpp +++ b/source/games/blood/src/aicerber.cpp @@ -252,7 +252,7 @@ static void cerberusThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -332,7 +332,7 @@ static void cerberusThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { switch (pSprite->type) { @@ -380,7 +380,7 @@ static void cerberusThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { switch (pSprite->type) { diff --git a/source/games/blood/src/aicult.cpp b/source/games/blood/src/aicult.cpp index ec0ba18fc..69400fd39 100644 --- a/source/games/blood/src/aicult.cpp +++ b/source/games/blood/src/aicult.cpp @@ -201,7 +201,7 @@ static void cultThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiLookForTarget(pSprite, pXSprite); } @@ -215,7 +215,7 @@ static void cultThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 5120 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { switch (pXSprite->medium) @@ -257,7 +257,7 @@ static void cultThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { switch (pXSprite->medium) diff --git a/source/games/blood/src/aigarg.cpp b/source/games/blood/src/aigarg.cpp index 617bdc133..fc80cd0b8 100644 --- a/source/games/blood/src/aigarg.cpp +++ b/source/games/blood/src/aigarg.cpp @@ -267,7 +267,7 @@ static void gargThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiLookForTarget(pSprite, pXSprite); } @@ -285,7 +285,7 @@ static void gargThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &gargoyleFSearch); aiThinkTarget(actor); @@ -375,7 +375,7 @@ static void gargThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &gargoyleFSearch); diff --git a/source/games/blood/src/aighost.cpp b/source/games/blood/src/aighost.cpp index fdfc54498..c0acd0795 100644 --- a/source/games/blood/src/aighost.cpp +++ b/source/games/blood/src/aighost.cpp @@ -243,7 +243,7 @@ static void ghostThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -261,7 +261,7 @@ static void ghostThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &ghostSearch); aiThinkTarget(actor); @@ -353,7 +353,7 @@ static void ghostThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &ghostSearch); diff --git a/source/games/blood/src/aigilbst.cpp b/source/games/blood/src/aigilbst.cpp index 8c0b15bca..aefda23da 100644 --- a/source/games/blood/src/aigilbst.cpp +++ b/source/games/blood/src/aigilbst.cpp @@ -77,7 +77,7 @@ static void gillThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -97,7 +97,7 @@ static void gillThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { if (pXSector && pXSector->Underwater) @@ -133,7 +133,7 @@ static void gillThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { XSECTOR *pXSector; @@ -243,7 +243,7 @@ static void gillThinkSwimGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &gillBeastSwimSearch); aiThinkTarget(actor); @@ -265,7 +265,7 @@ static void gillThinkSwimChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &gillBeastSwimSearch); diff --git a/source/games/blood/src/aihand.cpp b/source/games/blood/src/aihand.cpp index a427518be..1f580e84a 100644 --- a/source/games/blood/src/aihand.cpp +++ b/source/games/blood/src/aihand.cpp @@ -62,7 +62,7 @@ static void handThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -76,7 +76,7 @@ static void handThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &handSearch); aiThinkTarget(actor); @@ -98,7 +98,7 @@ static void handThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &handSearch); diff --git a/source/games/blood/src/aihound.cpp b/source/games/blood/src/aihound.cpp index 9ac73c2b4..a490d721c 100644 --- a/source/games/blood/src/aihound.cpp +++ b/source/games/blood/src/aihound.cpp @@ -80,7 +80,7 @@ static void houndThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -99,7 +99,7 @@ static void houndThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &houndSearch); aiThinkTarget(actor); @@ -129,7 +129,7 @@ static void houndThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &houndSearch); diff --git a/source/games/blood/src/aiinnoc.cpp b/source/games/blood/src/aiinnoc.cpp index 09b83bdd8..b5f1430d5 100644 --- a/source/games/blood/src/aiinnoc.cpp +++ b/source/games/blood/src/aiinnoc.cpp @@ -45,7 +45,7 @@ static void innocThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -59,7 +59,7 @@ static void innocThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &innocentSearch); aiThinkTarget(actor); @@ -81,7 +81,7 @@ static void innocThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &innocentSearch); diff --git a/source/games/blood/src/aipod.cpp b/source/games/blood/src/aipod.cpp index ab5a567d8..b654a3ef5 100644 --- a/source/games/blood/src/aipod.cpp +++ b/source/games/blood/src/aipod.cpp @@ -143,7 +143,7 @@ static void aiPodSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -162,7 +162,7 @@ static void aiPodMove(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) { switch (pSprite->type) { case kDudePodGreen: @@ -210,7 +210,7 @@ static void aiPodChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { switch (pSprite->type) { diff --git a/source/games/blood/src/airat.cpp b/source/games/blood/src/airat.cpp index b94dd23f0..133c2be3e 100644 --- a/source/games/blood/src/airat.cpp +++ b/source/games/blood/src/airat.cpp @@ -59,7 +59,7 @@ static void ratThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -73,7 +73,7 @@ static void ratThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &ratSearch); aiThinkTarget(actor); @@ -95,7 +95,7 @@ static void ratThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &ratSearch); diff --git a/source/games/blood/src/aispid.cpp b/source/games/blood/src/aispid.cpp index cfb07e774..81326e4bc 100644 --- a/source/games/blood/src/aispid.cpp +++ b/source/games/blood/src/aispid.cpp @@ -176,7 +176,7 @@ static void spidThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -190,7 +190,7 @@ static void spidThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &spidSearch); aiThinkTarget(actor); @@ -212,7 +212,7 @@ static void spidThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &spidSearch); diff --git a/source/games/blood/src/aitchern.cpp b/source/games/blood/src/aitchern.cpp index 1be20c9d2..75001713d 100644 --- a/source/games/blood/src/aitchern.cpp +++ b/source/games/blood/src/aitchern.cpp @@ -219,7 +219,7 @@ static void sub_72580(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -296,7 +296,7 @@ static void sub_72850(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &tchernobogSearch); aiThinkTarget(actor); @@ -326,7 +326,7 @@ static void sub_72934(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &tchernobogSearch); diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index d4030052e..cfb248e78 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -386,7 +386,7 @@ static void unicultThinkSearch(DBloodActor* actor) // TO DO: if can't see the target, but in fireDist range - stop moving and look around //viewSetSystemMessage("IN SEARCH"); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiLookForTarget(pSprite, pXSprite); } @@ -403,7 +403,7 @@ static void unicultThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY - pSprite->y; int nAngle = getangle(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); // if reached target, change to search mode if (approxDist(dx, dy) < 5120 && abs(pSprite->ang - nAngle) < getDudeInfo(pSprite->type)->periphery) { @@ -461,7 +461,7 @@ static void unicultThinkChase(DBloodActor* actor) if (inAttack(pXSprite->aiState)) xvelocity = yvelocity = ClipLow(pSprite->clipdist >> 1, 1); - //aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + //aiChooseDirection(actor,getangle(dx, dy)); aiGenDudeChooseDirection(pSprite, pXSprite, getangle(dx, dy), xvelocity, yvelocity); GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; @@ -1040,33 +1040,34 @@ void aiGenDudeChooseDirection(spritetype* pSprite, XSPRITE* pXSprite, int a3, in Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax"); return; } - + auto actor = &bloodActors[pSprite->index]; + // TO-DO: Take in account if sprite is flip-x, so enemy select correct angle int vc = ((a3 + 1024 - pSprite->ang) & 2047) - 1024; int t1 = DMulScale(xvel, Cos(pSprite->ang), yvel, Sin(pSprite->ang), 30); int vsi = ((t1 * 15) >> 12) / 2; int v8 = (vc >= 0) ? 341 : -341; - if (CanMove(pSprite, pXSprite->target, pSprite->ang + vc, vsi)) + if (CanMove(actor, pXSprite->target, pSprite->ang + vc, vsi)) pXSprite->goalAng = pSprite->ang + vc; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang + vc / 2, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang + vc / 2, vsi)) pXSprite->goalAng = pSprite->ang + vc / 2; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang - vc / 2, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang - vc / 2, vsi)) pXSprite->goalAng = pSprite->ang - vc / 2; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang + v8, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang + v8, vsi)) pXSprite->goalAng = pSprite->ang + v8; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang, vsi)) pXSprite->goalAng = pSprite->ang; - else if (CanMove(pSprite, pXSprite->target, pSprite->ang - v8, vsi)) + else if (CanMove(actor, pXSprite->target, pSprite->ang - v8, vsi)) pXSprite->goalAng = pSprite->ang - v8; else pXSprite->goalAng = pSprite->ang + 341; pXSprite->dodgeDir = (Chance(0x8000)) ? 1 : -1; - if (!CanMove(pSprite, pXSprite->target, pSprite->ang + pXSprite->dodgeDir * 512, 512)) { + if (!CanMove(actor, pXSprite->target, pSprite->ang + pXSprite->dodgeDir * 512, 512)) { pXSprite->dodgeDir = -pXSprite->dodgeDir; - if (!CanMove(pSprite, pXSprite->target, pSprite->ang + pXSprite->dodgeDir * 512, 512)) + if (!CanMove(actor, pXSprite->target, pSprite->ang + pXSprite->dodgeDir * 512, 512)) pXSprite->dodgeDir = 0; } } diff --git a/source/games/blood/src/aizomba.cpp b/source/games/blood/src/aizomba.cpp index 59d7ab83e..238f3fa8b 100644 --- a/source/games/blood/src/aizomba.cpp +++ b/source/games/blood/src/aizomba.cpp @@ -87,7 +87,7 @@ static void zombaThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiLookForTarget(pSprite, pXSprite); } @@ -101,7 +101,7 @@ static void zombaThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 921 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &zombieASearch); aiThinkTarget(actor); @@ -123,7 +123,7 @@ static void zombaThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &zombieASearch); @@ -175,7 +175,7 @@ static void zombaThinkPonder(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &zombieASearch); @@ -256,7 +256,7 @@ static void myThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); myThinkTarget(actor); } diff --git a/source/games/blood/src/aizombf.cpp b/source/games/blood/src/aizombf.cpp index 0f5c71c2c..2fd873f47 100644 --- a/source/games/blood/src/aizombf.cpp +++ b/source/games/blood/src/aizombf.cpp @@ -88,7 +88,7 @@ static void zombfThinkSearch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng); + aiChooseDirection(actor,pXSprite->goalAng); aiThinkTarget(actor); } @@ -102,7 +102,7 @@ static void zombfThinkGoto(DBloodActor* actor) int dy = pXSprite->targetY-pSprite->y; int nAngle = getangle(dx, dy); int nDist = approxDist(dx, dy); - aiChooseDirection(pSprite, pXSprite, nAngle); + aiChooseDirection(actor,nAngle); if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery) aiNewState(actor, &zombieFSearch); aiThinkTarget(actor); @@ -124,7 +124,7 @@ static void zombfThinkChase(DBloodActor* actor) XSPRITE *pXTarget = &xsprite[pTarget->extra]; int dx = pTarget->x-pSprite->x; int dy = pTarget->y-pSprite->y; - aiChooseDirection(pSprite, pXSprite, getangle(dx, dy)); + aiChooseDirection(actor,getangle(dx, dy)); if (pXTarget->health == 0) { aiNewState(actor, &zombieFSearch); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 1fced1c09..7d1794bf3 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -6514,6 +6514,7 @@ void nnExtAiSetDirection(spritetype* pSprite, XSPRITE* pXSprite, int a3) { /// patrol functions // ------------------------------------------------ void aiPatrolState(spritetype* pSprite, int state) { + auto actor = &bloodActors[pSprite->index]; assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);