From 3ff0f0cbf9b8158c5c7e6450ebbe7aa115af7ab7 Mon Sep 17 00:00:00 2001 From: Vaqtincha <51029683+Vaqtincha@users.noreply.github.com> Date: Sun, 6 Jun 2021 17:13:55 +0500 Subject: [PATCH] Bots can switch weapons underwater (#631) * Bots can switch weapons underwater --- regamedll/dlls/bot/cs_bot_update.cpp | 8 ++++++++ regamedll/dlls/bot/cs_bot_weapon.cpp | 5 +++++ regamedll/game_shared/bot/bot.h | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/regamedll/dlls/bot/cs_bot_update.cpp b/regamedll/dlls/bot/cs_bot_update.cpp index 0ef8e4ee..635360d0 100644 --- a/regamedll/dlls/bot/cs_bot_update.cpp +++ b/regamedll/dlls/bot/cs_bot_update.cpp @@ -516,6 +516,14 @@ void CCSBot::Update() m_isWaitingToTossGrenade = false; } +#ifdef REGAMEDLL_FIXES + // bots with low skill cannot switch weapons underwater + if (GetProfile()->GetSkill() > 0.4f && pev->waterlevel == 3 && !IsActiveWeaponCanShootUnderwater()) + { + EquipBestWeapon(MUST_EQUIP); + } +#endif + if (IsHunting() && IsWellPastSafe() && IsUsingGrenade()) { EquipBestWeapon(MUST_EQUIP); diff --git a/regamedll/dlls/bot/cs_bot_weapon.cpp b/regamedll/dlls/bot/cs_bot_weapon.cpp index f8c86e41..ac9b723b 100644 --- a/regamedll/dlls/bot/cs_bot_weapon.cpp +++ b/regamedll/dlls/bot/cs_bot_weapon.cpp @@ -414,6 +414,11 @@ bool CCSBot::DoEquip(CBasePlayerWeapon *pWeapon) if (!pWeapon) return false; +#ifdef REGAMEDLL_FIXES + if (GetProfile()->GetSkill() > 0.4f && pev->waterlevel == 3 && (pWeapon->iFlags() & ITEM_FLAG_NOFIREUNDERWATER)) + return false; +#endif + // check if weapon has any ammo left if (!HasAnyAmmo(pWeapon)) return false; diff --git a/regamedll/game_shared/bot/bot.h b/regamedll/game_shared/bot/bot.h index e366a210..6ad3cda1 100644 --- a/regamedll/game_shared/bot/bot.h +++ b/regamedll/game_shared/bot/bot.h @@ -196,6 +196,8 @@ public: // is the weapon in the middle of a reload bool IsActiveWeaponReloading() const; + bool IsActiveWeaponCanShootUnderwater() const; + // return true if active weapon's bullet spray has become large and inaccurate bool IsActiveWeaponRecoilHigh() const; @@ -327,6 +329,15 @@ inline CBasePlayerWeapon *CBot::GetActiveWeapon() const return static_cast(m_pActiveItem); } +inline bool CBot::IsActiveWeaponCanShootUnderwater() const +{ + CBasePlayerWeapon *pCurrentWeapon = GetActiveWeapon(); + if (pCurrentWeapon && !(pCurrentWeapon->iFlags() & ITEM_FLAG_NOFIREUNDERWATER)) + return true; + + return false; +} + inline bool CBot::IsActiveWeaponReloading() const { CBasePlayerWeapon *pCurrentWeapon = GetActiveWeapon();