From 67eb6334f671682bdbd09af707fd14e90dd76065 Mon Sep 17 00:00:00 2001 From: jeefo Date: Mon, 19 Feb 2024 09:36:15 +0300 Subject: [PATCH] fix: problems with picking up grenades on the ground (ref #529) fix: picking up m249 ammo from the ground fix: make bots respect camping_time_min/max when guarding bomb/hostages nav: make normal and rusher bots less defensive on hostage maps (ref #528) --- inc/hooks.h | 2 ++ inc/support.h | 3 --- inc/yapb.h | 2 ++ src/botlib.cpp | 28 +++++++++++++++------------- src/hooks.cpp | 6 +++--- src/navigate.cpp | 17 ++++++++++++++--- src/vision.cpp | 2 +- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/inc/hooks.h b/inc/hooks.h index 88dd693..89d555f 100644 --- a/inc/hooks.h +++ b/inc/hooks.h @@ -104,6 +104,8 @@ public: return m_sendToDetour.restore (); } +public: + static int32_t CR_STDCALL sendTo (int socket, const void *message, size_t length, int flags, const struct sockaddr *dest, int destLength); }; // used for transit calls between game dll and engine without all needed functions on bot side diff --git a/inc/support.h b/inc/support.h index ec6641b..52b1ab9 100644 --- a/inc/support.h +++ b/inc/support.h @@ -126,9 +126,6 @@ public: bool isInViewCone (const Vector &pos, edict_t *ent) { return getShootingCone (ent, pos) >= cr::cosf (cr::deg2rad ((ent->v.fov > 0 ? ent->v.fov : 90.0f) * 0.5f)); } - -public: - static int32_t CR_STDCALL sendTo (int socket, const void *message, size_t length, int flags, const struct sockaddr *dest, int destLength); }; // expose global diff --git a/inc/yapb.h b/inc/yapb.h index 701b51b..725cd3f 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -871,6 +871,8 @@ extern ConVar cv_spraypaints; extern ConVar cv_whose_your_daddy; extern ConVar cv_grenadier_mode; extern ConVar cv_ignore_enemies_after_spawn_time; +extern ConVar cv_camping_time_min; +extern ConVar cv_camping_time_max; extern ConVar mp_freezetime; extern ConVar mp_roundtime; diff --git a/src/botlib.cpp b/src/botlib.cpp index a18e81c..087acba 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -449,6 +449,7 @@ void Bot::updatePickups () { const bool isSubmachine = weaponType == WeaponType::SMG; const bool isShotgun = weaponType == WeaponType::Shotgun; const bool isRifle = weaponType == WeaponType::Rifle || weaponType == WeaponType::ZoomRifle; + const bool isHeavy = weaponType == WeaponType::Heavy; if (!isRifle && model == "9mmarclip.mdl") { allowPickup = false; @@ -462,7 +463,7 @@ void Bot::updatePickups () { else if (!isSniperRifle && model == "crossbow_clip.mdl") { allowPickup = false; } - else if (primaryWeaponCarried != Weapon::M249 && model == "chainammo.mdl") { + else if (!isHeavy && model == "chainammo.mdl") { allowPickup = false; } } @@ -472,6 +473,15 @@ void Bot::updatePickups () { else if (pev->armorvalue >= 100.0f && (model == "kevlar.mdl"|| model == "battery.mdl" || model == "assault.mdl")) { allowPickup = false; } + else if ((pev->weapons & cr::bit (Weapon::Flashbang)) && model == kFlashbangModelName) { + allowPickup = false; + } + else if ((pev->weapons & cr::bit (Weapon::Explosive)) && model == kExplosiveModelName) { + allowPickup = false; + } + else if ((pev->weapons & cr::bit (Weapon::Smoke)) && model == kSmokeModelName) { + allowPickup = false; + } if (allowPickup) { pickupType = Pickup::AmmoAndKits; @@ -533,15 +543,6 @@ void Bot::updatePickups () { } } } - else if ((pev->weapons & cr::bit (Weapon::Flashbang)) && model == kFlashbangModelName) { - allowPickup = false; - } - else if ((pev->weapons & cr::bit (Weapon::Explosive)) && model == kExplosiveModelName) { - allowPickup = false; - } - else if ((pev->weapons & cr::bit (Weapon::Smoke)) && model == kSmokeModelName) { - allowPickup = false; - } } // found a shield on ground? @@ -566,11 +567,12 @@ void Bot::updatePickups () { if (!m_defendHostage && m_personality != Personality::Rusher && m_difficulty >= Difficulty::Normal && rg.chance (15) - && m_timeCamping + 15.0f < game.time ()) { + && m_timeCamping + 15.0f < game.time () + && numFriendsNear (pev->origin, 384.0f) < 3) { const int index = findDefendNode (origin); - startTask (Task::Camp, TaskPri::Camp, kInvalidNodeIndex, game.time () + rg.get (30.0f, 60.0f), true); // push camp task on to stack + startTask (Task::Camp, TaskPri::Camp, kInvalidNodeIndex, game.time () + rg.get (cv_camping_time_min.float_ (), cv_camping_time_max.float_ ()), true); // push camp task on to stack startTask (Task::MoveToPosition, TaskPri::MoveToPosition, index, game.time () + rg.get (3.0f, 6.0f), true); // push move command // decide to duck or not to duck @@ -693,7 +695,7 @@ void Bot::updatePickups () { if (!m_defendedBomb && m_difficulty >= Difficulty::Normal && rg.chance (75) && m_healthValue < 60) { const int index = findDefendNode (origin); - startTask (Task::Camp, TaskPri::Camp, kInvalidNodeIndex, game.time () + rg.get (30.0f, 70.0f), true); // push camp task on to stack + startTask (Task::Camp, TaskPri::Camp, kInvalidNodeIndex, game.time () + rg.get (cv_camping_time_min.float_ (), cv_camping_time_max.float_ ()), true); // push camp task on to stack startTask (Task::MoveToPosition, TaskPri::MoveToPosition, index, game.time () + rg.get (10.0f, 30.0f), true); // push move command // decide to duck or not to duck diff --git a/src/hooks.cpp b/src/hooks.cpp index 1b026a2..d6527f1 100644 --- a/src/hooks.cpp +++ b/src/hooks.cpp @@ -7,7 +7,7 @@ #include -int32_t BotSupport::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) { +int32_t ServerQueryHook::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) { const auto send = [&] (const Twin &msg) -> int32_t { return Socket::sendto (socket, msg.first, msg.second, flags, dest, destLength); }; @@ -94,10 +94,10 @@ void ServerQueryHook::init () { // enable only on modern games if (!game.is (GameFlags::Legacy) && (plat.nix || plat.win) && !plat.isNonX86 () && !m_sendToDetour.detoured ()) { - m_sendToDetour.install (reinterpret_cast (BotSupport::sendTo), true); + m_sendToDetour.install (reinterpret_cast (ServerQueryHook::sendTo), true); if (!m_sendToDetourSys.detoured ()) { - m_sendToDetourSys.install (reinterpret_cast (BotSupport::sendTo), true); + m_sendToDetourSys.install (reinterpret_cast (ServerQueryHook::sendTo), true); } } } diff --git a/src/navigate.cpp b/src/navigate.cpp index 0daa8b0..986eae4 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -105,8 +105,18 @@ int Bot::findBestGoal () { if (game.mapIs (MapFlags::Assassination | MapFlags::HostageRescue)) { if (m_team == Team::Terrorist) { - defensive += 25.0f; - offensive -= 25.0f; + if (m_personality == Personality::Rusher) { + defensive -= 25.0f - difficulty * 0.5f; + offensive += 25.0f + difficulty * 5.0f; + } + else if (m_personality == Personality::Normal && rg.chance (40)) { + defensive -= 25.0f; + offensive += 25.0f; + } + else { + defensive += 25.0f; + offensive -= 25.0f; + } } else if (m_team == Team::CT) { // on hostage maps force more bots to save hostages @@ -156,6 +166,7 @@ int Bot::findBestGoal () { const float goalDesire = rg.get (0.0f, 100.0f) + offensive; const float forwardDesire = rg.get (0.0f, 100.0f) + offensive; const float backoffDesire = rg.get (0.0f, 100.0f) + defensive; + float campDesire = rg.get (0.0f, 100.0f) + defensive; if (!usesCampGun ()) { @@ -1067,7 +1078,7 @@ bool Bot::updateNavigation () { } float desiredDistanceSq = cr::sqrf (8.0f); - const float nodeDistanceSq = pev->origin.distanceSq (m_pathOrigin); + const float nodeDistanceSq = pev->origin.distanceSq2d (m_pathOrigin); // initialize the radius for a special node type, where the node is considered to be reached if (m_pathFlags & NodeFlag::Lift) { diff --git a/src/vision.cpp b/src/vision.cpp index 77a8e26..4d007e7 100644 --- a/src/vision.cpp +++ b/src/vision.cpp @@ -226,7 +226,7 @@ void Bot::setAimDirection () { if (onLadder && m_pathWalk.hasNext ()) { const auto &nextPath = graph[m_pathWalk.next ()]; - if ((nextPath.flags & NodeFlag::Ladder) && m_destOrigin.distanceSq (pev->origin) < cr::sqrf (120.0f) && nextPath.origin.z > m_pathOrigin.z + 45.0f) { + if ((nextPath.flags & NodeFlag::Ladder) && m_destOrigin.distanceSq (pev->origin) < cr::sqrf (120.0f) && nextPath.origin.z > m_pathOrigin.z + 30.0f) { m_lookAt = nextPath.origin; } }