From ff3b4afb1cd0c71e6979f640741308eb21036f0c Mon Sep 17 00:00:00 2001 From: RGreenlees Date: Mon, 13 May 2024 10:34:45 +0100 Subject: [PATCH] Bot stuck checks * Bots will now suicide if falling for more than 15 seconds, handle stuck situations * Bots will hopefully not get stuck in walk nodes as much --- main/source/mod/AvHAIConstants.h | 1 + main/source/mod/AvHAINavigation.cpp | 2 ++ main/source/mod/AvHAIPlayer.cpp | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/main/source/mod/AvHAIConstants.h b/main/source/mod/AvHAIConstants.h index e1786e50..c1919dfd 100644 --- a/main/source/mod/AvHAIConstants.h +++ b/main/source/mod/AvHAIConstants.h @@ -607,6 +607,7 @@ typedef struct _NAV_STATUS Vector UnstuckMoveLocation = g_vecZero; // If the bot is unable to find a path, blindly move here to try and fix the problem float LandedTime = 0.0f; // When the bot last landed after a fall/jump. + float AirStartedTime = 0.0f; // When the bot left the ground if in the air float LeapAttemptedTime = 0.0f; // When the bot last attempted to leap/blink. Avoid spam that sends it flying around too fast bool bIsJumping = false; // Is the bot in the air from a jump? Will duck so it can duck-jump bool IsOnGround = true; // Is the bot currently on the ground, or on a ladder? diff --git a/main/source/mod/AvHAINavigation.cpp b/main/source/mod/AvHAINavigation.cpp index 3a10812e..2655f219 100644 --- a/main/source/mod/AvHAINavigation.cpp +++ b/main/source/mod/AvHAINavigation.cpp @@ -4686,6 +4686,8 @@ bool IsBotOffWalkNode(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, // This shouldn't happen... but does occasionally. Walk moves should always be directly reachable from start to end //if (!UTIL_PointIsDirectlyReachable(MoveStart, MoveEnd)) { return true; } + + if (UTIL_PointIsDirectlyReachable(MoveStart, MoveEnd) && !UTIL_PointIsDirectlyReachable(pBot->CurrentFloorPosition, MoveEnd)) { return true; } Vector NearestPointOnLine = vClosestPointOnLine2D(MoveStart, MoveEnd, pBot->Edict->v.origin); diff --git a/main/source/mod/AvHAIPlayer.cpp b/main/source/mod/AvHAIPlayer.cpp index aa961c1e..26d900e2 100644 --- a/main/source/mod/AvHAIPlayer.cpp +++ b/main/source/mod/AvHAIPlayer.cpp @@ -1782,11 +1782,24 @@ void StartNewBotFrame(AvHAIPlayer* pBot) pBot->BotNavInfo.IsOnGround = true; pBot->BotNavInfo.bIsJumping = false; + pBot->BotNavInfo.AirStartedTime = 0.0f; } else { + if (pBot->BotNavInfo.IsOnGround) + { + pBot->BotNavInfo.AirStartedTime = gpGlobals->time; + } + pBot->BotNavInfo.IsOnGround = false; + // It's possible that players can get stuck in angled geometry where they're permanently in the air + // This just checks for that possibility: if a bot is falling for more than 15 seconds they're probably stuck and should suicide + if (pBot->BotNavInfo.AirStartedTime > 0.0f && gpGlobals->time - pBot->BotNavInfo.AirStartedTime > 15.0f) + { + BotSuicide(pBot); + } + } pBot->BotNavInfo.bHasAttemptedJump = false;