From 8d1938b363f075b2b6927ce10bf8cb300236d303 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Sep 2022 21:12:18 +0200 Subject: [PATCH] - Blood: cleaned up various angle and distance checks in AI code --- source/games/blood/src/aibat.cpp | 12 ++++++------ source/games/blood/src/aibeast.cpp | 18 +++++++++--------- source/games/blood/src/aiboneel.cpp | 4 ++-- source/games/blood/src/aigarg.cpp | 8 ++++---- source/games/blood/src/aighost.cpp | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/source/games/blood/src/aibat.cpp b/source/games/blood/src/aibat.cpp index 81e28d68a..18a1b0904 100644 --- a/source/games/blood/src/aibat.cpp +++ b/source/games/blood/src/aibat.cpp @@ -137,9 +137,9 @@ static void batThinkGoto(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto dvec = actor->xspr.TargetPos.XY() - actor->spr.pos.X; auto nAngle = VecToAngle(dvec); - int nDist = approxDist(dvec); + double nDist = dvec.Length(); aiChooseDirection(actor, nAngle); - if (nDist < 512 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) + if (nDist < 32 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) aiNewState(actor, &batSearch); batThinkTarget(actor); } @@ -257,9 +257,9 @@ static void batThinkChase(DBloodActor* actor) return; } double nDist = dvec.Length(); - if (nDist <= (pDudeInfo->seeDist * inttoworld)) + if (nDist <= pDudeInfo->SeeDist()) { - DAngle nDeltaAngle = deltaangle(actor->spr.angle, dvec.Angle()); + DAngle nDeltaAngle = absangle(actor->spr.angle, dvec.Angle()); double height = pDudeInfo->eyeHeight * actor->spr.yrepeat * REPEAT_SCALE; // Should be dudeInfo[pTarget->spr.type-kDudeBase] double height2 = pDudeInfo->eyeHeight * pTarget->spr.yrepeat * REPEAT_SCALE; @@ -267,13 +267,13 @@ static void batThinkChase(DBloodActor* actor) GetActorExtents(actor, &top, &bottom); if (cansee(pTarget->spr.pos, pTarget->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { - if (nDist < (pDudeInfo->seeDist * inttoworld) && abs(nDeltaAngle).Buildang() <= pDudeInfo->periphery) + if (nDist < pDudeInfo->SeeDist() && nDeltaAngle <= pDudeInfo->Periphery()) { aiSetTarget(actor, actor->GetTarget()); double floorZ = getflorzofslopeptr(actor->sector(), actor->spr.pos); double floorDelta = floorZ - bottom; double heightDelta = height2 - height; - bool angWithinRange = abs(nDeltaAngle) < mapangle(85); + bool angWithinRange = nDeltaAngle < mapangle(85); if (heightDelta < 32 && nDist < 0x20 && angWithinRange) aiNewState(actor, &batBite); else if ((heightDelta > 80 || floorDelta > 80) && nDist < 0x140 && nDist > 0x80 && angWithinRange) diff --git a/source/games/blood/src/aibeast.cpp b/source/games/blood/src/aibeast.cpp index 650068901..96b15cae5 100644 --- a/source/games/blood/src/aibeast.cpp +++ b/source/games/blood/src/aibeast.cpp @@ -176,9 +176,9 @@ static void beastThinkGoto(DBloodActor* actor) auto dvec = actor->xspr.TargetPos.XY() - actor->spr.pos.XY(); auto nAngle = VecToAngle(dvec); - int nDist = approxDist(dvec); + double nDist = dvec.Length(); aiChooseDirection(actor, nAngle); - if (nDist < 512 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) + if (nDist < 32 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) { if (pXSector && pXSector->Underwater) aiNewState(actor, &beastSwimSearch); @@ -326,9 +326,9 @@ static void beastThinkSwimGoto(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto dvec = actor->xspr.TargetPos.XY() - actor->spr.pos.XY(); auto nAngle = VecToAngle(dvec); - int nDist = approxDist(dvec); + double nDist = dvec.Length(); aiChooseDirection(actor, nAngle); - if (nDist < 512 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) + if (nDist < 32 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) aiNewState(actor, &beastSwimSearch); aiThinkTarget(actor); } @@ -347,7 +347,7 @@ static void beastThinkSwimChase(DBloodActor* actor) auto dvec = target->spr.pos.XY() - actor->spr.pos.XY(); DAngle nAngle = VecToAngle(dvec); - int nDist = approxDist(dvec); + double nDist = dvec.Length(); aiChooseDirection(actor, nAngle); if (target->xspr.health == 0) @@ -361,18 +361,18 @@ static void beastThinkSwimChase(DBloodActor* actor) return; } - if (nDist <= pDudeInfo->seeDist) + if (nDist <= pDudeInfo->SeeDist()) { - int nDeltaAngle = getincangle(actor->int_ang(), nAngle.Buildang()); + DAngle nDeltaAngle = absangle(actor->spr.angle, nAngle); double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE; int top, bottom; GetActorExtents(actor, &top, &bottom); if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { - if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery) + if (nDist < pDudeInfo->SeeDist() && nDeltaAngle <= pDudeInfo->Periphery()) { aiSetTarget(actor, actor->GetTarget()); - if (nDist < 0x400 && abs(nDeltaAngle) < 85) + if (nDist < 64 && nDeltaAngle < mapangle(85)) aiNewState(actor, &beastSwimSlash); else { diff --git a/source/games/blood/src/aiboneel.cpp b/source/games/blood/src/aiboneel.cpp index 3472c7081..32b76ee1f 100644 --- a/source/games/blood/src/aiboneel.cpp +++ b/source/games/blood/src/aiboneel.cpp @@ -150,9 +150,9 @@ static void eelThinkGoto(DBloodActor* actor) DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); auto dvec = actor->xspr.TargetPos.XY() - actor->spr.pos.XY(); auto nAngle = VecToAngle(dvec); - int nDist = approxDist(dvec); + double nDist = dvec.Length(); aiChooseDirection(actor, nAngle); - if (nDist < 512 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) + if (nDist < 32 && absangle(actor->spr.angle, nAngle) < pDudeInfo->Periphery()) aiNewState(actor, &eelSearch); eelThinkTarget(actor); } diff --git a/source/games/blood/src/aigarg.cpp b/source/games/blood/src/aigarg.cpp index 0752f9d2b..9d9121452 100644 --- a/source/games/blood/src/aigarg.cpp +++ b/source/games/blood/src/aigarg.cpp @@ -340,9 +340,9 @@ static void gargThinkChase(DBloodActor* actor) return; } double nDist = dxy.Length(); - if (nDist <= (pDudeInfo->seeDist * inttoworld)) + if (nDist <= pDudeInfo->SeeDist()) { - DAngle nDeltaAngle = deltaangle(actor->spr.angle, dxyAngle); + DAngle nDeltaAngle = absangle(actor->spr.angle, dxyAngle); double height = pDudeInfo->eyeHeight * actor->spr.yrepeat * REPEAT_SCALE; // Should be dudeInfo[target->spr.type-kDudeBase] double height2 = pDudeInfo->eyeHeight * target->spr.yrepeat * REPEAT_SCALE; @@ -350,13 +350,13 @@ static void gargThinkChase(DBloodActor* actor) GetActorExtents(actor, &top, &bottom); if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { - if (nDist < (pDudeInfo->seeDist * inttoworld) && abs(nDeltaAngle).Buildang() <= pDudeInfo->periphery) + if (nDist < pDudeInfo->SeeDist() && nDeltaAngle <= pDudeInfo->Periphery()) { aiSetTarget(actor, actor->GetTarget()); double floorZ = getflorzofslopeptr(actor->sector(), actor->spr.pos); double floorDelta = floorZ - bottom; double heightDelta = height2 - height; - bool angWithinRange = abs(nDeltaAngle) < mapangle(85); + bool angWithinRange = nDeltaAngle < mapangle(85); switch (actor->spr.type) { case kDudeGargoyleFlesh: diff --git a/source/games/blood/src/aighost.cpp b/source/games/blood/src/aighost.cpp index d09ab06bd..441ce5c3a 100644 --- a/source/games/blood/src/aighost.cpp +++ b/source/games/blood/src/aighost.cpp @@ -318,9 +318,9 @@ static void ghostThinkChase(DBloodActor* actor) return; } double nDist = dxy.Length(); - if (nDist <= (pDudeInfo->seeDist * inttoworld)) + if (nDist <= pDudeInfo->SeeDist()) { - DAngle nDeltaAngle = deltaangle(actor->spr.angle, dxyAngle); + DAngle nDeltaAngle = absangle(actor->spr.angle, dxyAngle); double height = pDudeInfo->eyeHeight * actor->spr.yrepeat * REPEAT_SCALE; // Should be dudeInfo[target->spr.type-kDudeBase] double height2 = pDudeInfo->eyeHeight * target->spr.yrepeat * REPEAT_SCALE; @@ -328,13 +328,13 @@ static void ghostThinkChase(DBloodActor* actor) GetActorExtents(actor, &top, &bottom); if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector())) { - if (nDist < (pDudeInfo->seeDist * inttoworld) && abs(nDeltaAngle).Buildang() <= pDudeInfo->periphery) + if (nDist < pDudeInfo->SeeDist() && nDeltaAngle <= pDudeInfo->Periphery()) { aiSetTarget(actor, actor->GetTarget()); double floorZ = getflorzofslopeptr(actor->sector(), actor->spr.pos); double floorDelta = floorZ - bottom; double heightDelta = height2 - height; - bool angWithinRange = abs(nDeltaAngle) < mapangle(85); + bool angWithinRange = nDeltaAngle < mapangle(85); switch (actor->spr.type) { case kDudePhantasm: if (nDist < 0x200 && nDist > 0x100 && angWithinRange) {