From 7ac1e0db2f1d086b3bd9b998cc619bcfc43f8257 Mon Sep 17 00:00:00 2001 From: s1lent Date: Wed, 11 Sep 2019 00:04:18 +0700 Subject: [PATCH] Enhanced behavior armoury_entity with czbot, don't pick up if forbidden by cvars --- regamedll/dlls/bot/cs_bot_manager.cpp | 33 +++++++++++++---- regamedll/dlls/bot/cs_bot_manager.h | 1 + regamedll/dlls/weapons.cpp | 5 +++ regamedll/dlls/weapontype.cpp | 52 +++++++++++++++++++++++++++ regamedll/dlls/weapontype.h | 1 + 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index 2086a839..3ce41d40 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -168,16 +168,35 @@ bool CCSBotManager::IsWeaponUseable(CBasePlayerItem *item) const if (item->m_iId == WEAPON_C4) return true; - int weaponClass = WeaponIDToWeaponClass(item->m_iId); + WeaponClassType weaponClass = WeaponIDToWeaponClass(item->m_iId); - if ((!AllowShotguns() && weaponClass == WEAPONCLASS_SHOTGUN) - || (!AllowMachineGuns() && weaponClass == WEAPONCLASS_MACHINEGUN) - || (!AllowRifles() && weaponClass == WEAPONCLASS_RIFLE) - || (!AllowSnipers() && weaponClass == WEAPONCLASS_SNIPERRIFLE) + if ((!AllowShotguns() && weaponClass == WEAPONCLASS_SHOTGUN) + || (!AllowMachineGuns() && weaponClass == WEAPONCLASS_MACHINEGUN) + || (!AllowRifles() && weaponClass == WEAPONCLASS_RIFLE) + || (!AllowSnipers() && weaponClass == WEAPONCLASS_SNIPERRIFLE) || (!AllowSubMachineGuns() && weaponClass == WEAPONCLASS_SUBMACHINEGUN) || (!AllowTacticalShield() && item->m_iId == WEAPON_SHIELDGUN) - || (!AllowPistols() && weaponClass == WEAPONCLASS_PISTOL) - || (!AllowGrenades() && weaponClass == WEAPONCLASS_GRENADE)) + || (!AllowPistols() && weaponClass == WEAPONCLASS_PISTOL) + || (!AllowGrenades() && weaponClass == WEAPONCLASS_GRENADE)) + { + return false; + } + + return true; +} + +bool CCSBotManager::IsWeaponUseable(ArmouryItemPack item) const +{ + WeaponClassType weaponClass = WeaponIDToWeaponClass(item); + + if ((!AllowShotguns() && weaponClass == WEAPONCLASS_SHOTGUN) + || (!AllowMachineGuns() && weaponClass == WEAPONCLASS_MACHINEGUN) + || (!AllowRifles() && weaponClass == WEAPONCLASS_RIFLE) + || (!AllowSnipers() && weaponClass == WEAPONCLASS_SNIPERRIFLE) + || (!AllowSubMachineGuns() && weaponClass == WEAPONCLASS_SUBMACHINEGUN) + || (!AllowTacticalShield() && item == ARMOURY_SHIELD) + || (!AllowPistols() && weaponClass == WEAPONCLASS_PISTOL) + || (!AllowGrenades() && weaponClass == WEAPONCLASS_GRENADE)) { return false; } diff --git a/regamedll/dlls/bot/cs_bot_manager.h b/regamedll/dlls/bot/cs_bot_manager.h index 53246818..132d1596 100644 --- a/regamedll/dlls/bot/cs_bot_manager.h +++ b/regamedll/dlls/bot/cs_bot_manager.h @@ -195,6 +195,7 @@ public: bool AllowFriendlyFireDamage() const { return friendlyfire.value != 0.0f; } bool IsWeaponUseable(CBasePlayerItem *item) const; // return true if the bot can use this weapon + bool IsWeaponUseable(ArmouryItemPack item) const; bool IsDefenseRushing() const { return m_isDefenseRushing; } // returns true if defense team has "decided" to rush this round bool IsOnDefense(CBasePlayer *pPlayer) const; // return true if this player is on "defense" diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 6af023e7..2101adad 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -2255,6 +2255,11 @@ void CArmoury::ArmouryTouch(CBaseEntity *pOther) return; #endif +#ifdef REGAMEDLL_FIXES + if (pToucher->IsBot() && TheCSBots() && !TheCSBots()->IsWeaponUseable(m_iItem)) + return; +#endif + // primary weapons if (m_iCount > 0 && (m_iItem <= ARMOURY_M249 #ifdef REGAMEDLL_ADD diff --git a/regamedll/dlls/weapontype.cpp b/regamedll/dlls/weapontype.cpp index f677ee29..07d67c60 100644 --- a/regamedll/dlls/weapontype.cpp +++ b/regamedll/dlls/weapontype.cpp @@ -388,6 +388,58 @@ WeaponClassType WeaponIDToWeaponClass(int id) return AliasToWeaponClass(WeaponIDToAlias(id)); } +WeaponClassType WeaponIDToWeaponClass(ArmouryItemPack id) +{ + switch (id) + { + case ARMOURY_AUG: + case ARMOURY_GALIL: + case ARMOURY_M4A1: + case ARMOURY_SG552: + case ARMOURY_AK47: + case ARMOURY_FAMAS: + return WEAPONCLASS_RIFLE; + + case ARMOURY_GLOCK18: + case ARMOURY_USP: + case ARMOURY_ELITE: + case ARMOURY_FIVESEVEN: + case ARMOURY_P228: + case ARMOURY_DEAGLE: + return WEAPONCLASS_PISTOL; + + case ARMOURY_MP5NAVY: + case ARMOURY_MAC10: + case ARMOURY_TMP: + case ARMOURY_UMP45: + case ARMOURY_P90: + return WEAPONCLASS_SUBMACHINEGUN; + + case ARMOURY_SCOUT: + case ARMOURY_SG550: + case ARMOURY_AWP: + case ARMOURY_G3SG1: + return WEAPONCLASS_SNIPERRIFLE; + + case ARMOURY_FLASHBANG: + case ARMOURY_HEGRENADE: + case ARMOURY_SMOKEGRENADE: + return WEAPONCLASS_GRENADE; + + case ARMOURY_M3: + case ARMOURY_XM1014: + return WEAPONCLASS_SHOTGUN; + + case ARMOURY_M249: + return WEAPONCLASS_MACHINEGUN; + + default: + break; + } + + return WEAPONCLASS_NONE; +} + // Return true if given weapon ID is a primary weapon bool IsPrimaryWeapon(int id) { diff --git a/regamedll/dlls/weapontype.h b/regamedll/dlls/weapontype.h index 390ca22a..a6f91817 100644 --- a/regamedll/dlls/weapontype.h +++ b/regamedll/dlls/weapontype.h @@ -447,6 +447,7 @@ const char *BuyAliasToWeaponID(const char *alias, WeaponIdType &id); const char *WeaponIDToAlias(int id); WeaponClassType AliasToWeaponClass(const char *alias); WeaponClassType WeaponIDToWeaponClass(int id); +WeaponClassType WeaponIDToWeaponClass(ArmouryItemPack id); bool IsPrimaryWeapon(int id); bool IsSecondaryWeapon(int id); bool IsGrenadeWeapon(int id);