From 723e22743e1b07689d6b9dbc4f3912ddc08dbb47 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Dec 2021 20:48:11 +0100 Subject: [PATCH] - handle all x() calls in AI code. --- source/games/blood/src/aibeast.cpp | 10 +++++----- source/games/blood/src/aiboneel.cpp | 8 ++++---- source/games/blood/src/aiburn.cpp | 4 ++-- source/games/blood/src/aicaleb.cpp | 8 ++++---- source/games/blood/src/aicerber.cpp | 4 ++-- source/games/blood/src/aicult.cpp | 4 ++-- source/games/blood/src/aigarg.cpp | 4 ++-- source/games/blood/src/aighost.cpp | 4 ++-- source/games/blood/src/aihand.cpp | 4 ++-- source/games/blood/src/aihound.cpp | 4 ++-- source/games/blood/src/aiinnoc.cpp | 4 ++-- source/games/blood/src/aipod.cpp | 4 ++-- source/games/blood/src/airat.cpp | 4 ++-- source/games/blood/src/aispid.cpp | 4 ++-- source/games/blood/src/aitchern.cpp | 4 ++-- source/games/blood/src/aiunicult.cpp | 1 + source/games/blood/src/aizomba.cpp | 8 ++++---- source/games/blood/src/aizombf.cpp | 4 ++-- 18 files changed, 44 insertions(+), 43 deletions(-) diff --git a/source/games/blood/src/aibeast.cpp b/source/games/blood/src/aibeast.cpp index 333cf395b..1afcf774f 100644 --- a/source/games/blood/src/aibeast.cpp +++ b/source/games/blood/src/aibeast.cpp @@ -214,7 +214,7 @@ static void beastThinkChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); @@ -222,7 +222,7 @@ static void beastThinkChase(DBloodActor* actor) auto pSector = actor->spr.sector(); auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr; - if (pXTarget->health == 0) + if (target->xspr.health == 0) { if (pXSector && pXSector->Underwater) aiNewState(actor, &beastSwimSearch); @@ -253,7 +253,7 @@ static void beastThinkChase(DBloodActor* actor) && target->IsPlayerActor() && Chance(0x8000)) { int hit = HitScan(actor, actor->spr.pos.Z, dx, dy, 0, CLIPMASK1, 0); - if (pXTarget->health > (unsigned)gPlayerTemplate[0].startHealth / 2) + if (target->xspr.health > (unsigned)gPlayerTemplate[0].startHealth / 2) { switch (hit) { @@ -355,11 +355,11 @@ static void beastThinkSwimChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &beastSwimSearch); return; diff --git a/source/games/blood/src/aiboneel.cpp b/source/games/blood/src/aiboneel.cpp index f9f8b3bd6..c28d1761f 100644 --- a/source/games/blood/src/aiboneel.cpp +++ b/source/games/blood/src/aiboneel.cpp @@ -174,11 +174,11 @@ static void eelThinkPonder(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &eelSearch); return; @@ -277,11 +277,11 @@ static void eelThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &eelSearch); return; diff --git a/source/games/blood/src/aiburn.cpp b/source/games/blood/src/aiburn.cpp index b01a5b815..ec12c34d9 100644 --- a/source/games/blood/src/aiburn.cpp +++ b/source/games/blood/src/aiburn.cpp @@ -158,11 +158,11 @@ static void burnThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { switch (actor->spr.type) { diff --git a/source/games/blood/src/aicaleb.cpp b/source/games/blood/src/aicaleb.cpp index 4044ee7f6..b9a39115c 100644 --- a/source/games/blood/src/aicaleb.cpp +++ b/source/games/blood/src/aicaleb.cpp @@ -127,11 +127,11 @@ static void calebThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { if (pXSector && pXSector->Underwater) aiNewState(actor, &tinycalebSwimSearch); @@ -235,11 +235,11 @@ static void calebThinkSwimChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &tinycalebSwimSearch); return; diff --git a/source/games/blood/src/aicerber.cpp b/source/games/blood/src/aicerber.cpp index 8f0a4a05b..044f089a0 100644 --- a/source/games/blood/src/aicerber.cpp +++ b/source/games/blood/src/aicerber.cpp @@ -343,12 +343,12 @@ static void cerberusThinkChase(DBloodActor* actor) if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) { + if (target->xspr.health == 0) { switch (actor->spr.type) { case kDudeCerberusTwoHead: aiNewState(actor, &cerberusSearch); diff --git a/source/games/blood/src/aicult.cpp b/source/games/blood/src/aicult.cpp index 01bc1f211..8eab0984a 100644 --- a/source/games/blood/src/aicult.cpp +++ b/source/games/blood/src/aicult.cpp @@ -236,11 +236,11 @@ static void cultThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { switch (pXSprite->medium) { diff --git a/source/games/blood/src/aigarg.cpp b/source/games/blood/src/aigarg.cpp index a4767d40d..d1b228f59 100644 --- a/source/games/blood/src/aigarg.cpp +++ b/source/games/blood/src/aigarg.cpp @@ -347,11 +347,11 @@ static void gargThinkChase(DBloodActor* actor) } DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &gargoyleFSearch); return; diff --git a/source/games/blood/src/aighost.cpp b/source/games/blood/src/aighost.cpp index e27684f98..d764f2538 100644 --- a/source/games/blood/src/aighost.cpp +++ b/source/games/blood/src/aighost.cpp @@ -327,11 +327,11 @@ static void ghostThinkChase(DBloodActor* actor) } DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &ghostSearch); return; diff --git a/source/games/blood/src/aihand.cpp b/source/games/blood/src/aihand.cpp index 532933710..4406b6474 100644 --- a/source/games/blood/src/aihand.cpp +++ b/source/games/blood/src/aihand.cpp @@ -89,11 +89,11 @@ static void handThinkChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &handSearch); return; diff --git a/source/games/blood/src/aihound.cpp b/source/games/blood/src/aihound.cpp index 34911e0ad..9a67e3766 100644 --- a/source/games/blood/src/aihound.cpp +++ b/source/games/blood/src/aihound.cpp @@ -106,11 +106,11 @@ static void houndThinkChase(DBloodActor* actor) } DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &houndSearch); return; diff --git a/source/games/blood/src/aiinnoc.cpp b/source/games/blood/src/aiinnoc.cpp index 0cc9a276e..9ce84897c 100644 --- a/source/games/blood/src/aiinnoc.cpp +++ b/source/games/blood/src/aiinnoc.cpp @@ -74,11 +74,11 @@ static void innocThinkChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &innocentSearch); return; diff --git a/source/games/blood/src/aipod.cpp b/source/games/blood/src/aipod.cpp index 1451f5958..eb52e1aab 100644 --- a/source/games/blood/src/aipod.cpp +++ b/source/games/blood/src/aipod.cpp @@ -182,11 +182,11 @@ static void aiPodChase(DBloodActor* actor) } DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) { + if (target->xspr.health == 0) { switch (actor->spr.type) { case kDudePodGreen: diff --git a/source/games/blood/src/airat.cpp b/source/games/blood/src/airat.cpp index a7b9a1e4e..147fbec59 100644 --- a/source/games/blood/src/airat.cpp +++ b/source/games/blood/src/airat.cpp @@ -84,11 +84,11 @@ static void ratThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &ratSearch); return; diff --git a/source/games/blood/src/aispid.cpp b/source/games/blood/src/aispid.cpp index ad3a4cf17..1e922a4fa 100644 --- a/source/games/blood/src/aispid.cpp +++ b/source/games/blood/src/aispid.cpp @@ -194,11 +194,11 @@ static void spidThinkChase(DBloodActor* actor) assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax); DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &spidSearch); return; diff --git a/source/games/blood/src/aitchern.cpp b/source/games/blood/src/aitchern.cpp index 9a09f6486..85b33a520 100644 --- a/source/games/blood/src/aitchern.cpp +++ b/source/games/blood/src/aitchern.cpp @@ -291,11 +291,11 @@ static void sub_72934(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &tchernobogSearch); return; diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index 1141baf12..a867541ec 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -478,6 +478,7 @@ static void unicultThinkChase(DBloodActor* actor) genDudeUpdate(actor); } + // we need to be very careful here not to screw up the condition for this check! XSPRITE* pXTarget = !targetactor || !targetactor->IsDudeActor() || !targetactor->hasX() ? nullptr : &targetactor->x(); if (pXTarget == nullptr) // target lost diff --git a/source/games/blood/src/aizomba.cpp b/source/games/blood/src/aizomba.cpp index 98a10762b..545f6f8c5 100644 --- a/source/games/blood/src/aizomba.cpp +++ b/source/games/blood/src/aizomba.cpp @@ -115,11 +115,11 @@ static void zombaThinkChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &zombieASearch); return; @@ -165,11 +165,11 @@ static void zombaThinkPonder(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &zombieASearch); return; diff --git a/source/games/blood/src/aizombf.cpp b/source/games/blood/src/aizombf.cpp index 5e1dcb0c5..b4f6ba578 100644 --- a/source/games/blood/src/aizombf.cpp +++ b/source/games/blood/src/aizombf.cpp @@ -114,11 +114,11 @@ static void zombfThinkChase(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); - XSPRITE* pXTarget = &actor->GetTarget()->x(); + int dx = target->spr.pos.X - actor->spr.pos.X; int dy = target->spr.pos.Y - actor->spr.pos.Y; aiChooseDirection(actor, getangle(dx, dy)); - if (pXTarget->health == 0) + if (target->xspr.health == 0) { aiNewState(actor, &zombieFSearch); return;