diff --git a/source/src/bot/bot.h b/source/src/bot/bot.h index 25c25f3a..57d7b162 100644 --- a/source/src/bot/bot.h +++ b/source/src/bot/bot.h @@ -255,6 +255,7 @@ public: void MainAI(void); bool CheckStuck(void); bool CheckJump(void); + bool CheckCrouch(void); bool CheckStrafe(void); void CheckFOV(void); bool IsVisible(const vec &o, bool CheckPlayers = false) { return ::IsVisible(m_pMyEnt->o, o, diff --git a/source/src/bot/bot_ai.cpp b/source/src/bot/bot_ai.cpp index 22e8f9fe..32c18b3c 100644 --- a/source/src/bot/bot_ai.cpp +++ b/source/src/bot/bot_ai.cpp @@ -778,6 +778,10 @@ void CBot::MainAI() // Default bots won't strafe m_pMyEnt->strafe = 0; + // Whatever the bot is doing, check for needed crouch + if(CheckCrouch()) m_pMyEnt->trycrouch = true; + else m_pMyEnt->trycrouch = false; + if (!BotManager.BotsShoot() && m_pMyEnt->enemy) m_pMyEnt->enemy = NULL; // Clear enemy when bots may not shoot @@ -1244,7 +1248,7 @@ void CBot::DoCombatNav() bool CBot::CheckStuck() { - if (m_iStuckCheckDelay >= lastmillis) + if (m_iStuckCheckDelay + (CheckCrouch() ? 2000 : 0) >= lastmillis) return false; if ((m_vGoal!=g_vecZero) && (GetDistance(m_vGoal) < 2.0f)) @@ -1403,10 +1407,25 @@ bool CBot::CheckJump() return true; } } - return false; // Bot didn't had to jump(or couldn't) } +bool CBot::CheckCrouch() +{ + bool bHasGoal = m_vGoal!=g_vecZero; + float flGoalDist = (bHasGoal) ? GetDistance(m_vGoal) : 0.0f; + + vec start = m_pMyEnt->o; + vec crouch = vec(0, 0, 2.0f); + float flTraceDist = 3.0f; + + if (bHasGoal && (flGoalDist < flTraceDist)) + flTraceDist = flGoalDist; + + if (!IsVisible(vec(start).add(crouch), FORWARD, flTraceDist, false) && IsVisible(vec(start).sub(crouch), FORWARD, flTraceDist, false)) return true; + return false; +} + bool CBot::CheckStrafe() { if (m_iStrafeTime >= lastmillis) diff --git a/source/src/physics.cpp b/source/src/physics.cpp index c93590db..9a4996a0 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -648,10 +648,10 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) } // apply volume-resize when crouching - if(pl->type==ENT_PLAYER) + if(pl->type==ENT_PLAYER || pl->type==ENT_BOT) { // if(pl==player1 && !(intermission || player1->onladder || (pl->trycrouch && !player1->onfloor && player1->timeinair > 50))) updatecrouch(player1, player1->trycrouch); - if(pl==player1 && !intermission) updatecrouch(player1, player1->trycrouch); + if(!intermission) updatecrouch((playerent *)pl, pl->trycrouch); const float croucheyeheight = pl->maxeyeheight*3.0f/4.0f; resizephysent(pl, moveres, curtime, croucheyeheight, pl->maxeyeheight); }