From 475d290767ba4ede7f3d1fc876b5dc3573d70ac6 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 17 Feb 2024 00:09:32 +0300 Subject: [PATCH] fix: allow to pickup ammo and kits regardless of weapon --- src/botlib.cpp | 14 ++++++++++++++ src/combat.cpp | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/botlib.cpp b/src/botlib.cpp index 8e6d606..a18e81c 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -518,6 +518,20 @@ void Bot::updatePickups () { } else if (!rateGroundWeapon (ent)) { allowPickup = false; + + // double check if it's ammo/kits + if (pickupType == Pickup::AmmoAndKits) { + const auto &rawWeapons = conf.getWeapons (); + + // verify that the model is not weapon + for (const auto &rw : rawWeapons) { + if (rw.model == model) { + allowPickup = false; + break; + } + allowPickup = true; + } + } } else if ((pev->weapons & cr::bit (Weapon::Flashbang)) && model == kFlashbangModelName) { allowPickup = false; diff --git a/src/combat.cpp b/src/combat.cpp index 8f0c6da..bb07ed9 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1458,12 +1458,12 @@ bool Bot::isEnemyBehindShield (edict_t *enemy) { int Bot::bestPrimaryCarried () { // this function returns the best weapon of this bot (based on personality prefs) - const int *pref = conf.getWeaponPrefs (m_personality); + auto pref = conf.getWeaponPrefs (m_personality); int weaponIndex = 0; int weapons = pev->weapons; - const auto &tab = conf.getWeapons (); + const auto &tab = conf.getRawWeapons (); // take the shield in account if (hasShield ()) { @@ -1482,7 +1482,7 @@ int Bot::bestPrimaryCarried () { int Bot::bestSecondaryCarried () { // this function returns the best secondary weapon of this bot (based on personality prefs) - const int *pref = conf.getWeaponPrefs (m_personality); + auto pref = conf.getWeaponPrefs (m_personality); int weaponIndex = 0; int weapons = pev->weapons; @@ -1494,9 +1494,9 @@ int Bot::bestSecondaryCarried () { const auto tab = conf.getRawWeapons (); for (int i = 0; i < kNumWeapons; ++i) { - int id = tab[*pref].id; + const int id = tab[*pref].id; - if ((weapons & cr::bit (tab[*pref].id)) && conf.getWeaponType (id) == WeaponType::Pistol) { + if ((weapons & cr::bit (id)) && conf.getWeaponType (id) == WeaponType::Pistol) { weaponIndex = i; break; }