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)
This commit is contained in:
jeefo 2024-02-19 09:36:15 +03:00
commit 67eb6334f6
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
7 changed files with 37 additions and 23 deletions

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -7,7 +7,7 @@
#include <yapb.h>
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 <const uint8_t *, size_t> &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 <void *> (BotSupport::sendTo), true);
m_sendToDetour.install (reinterpret_cast <void *> (ServerQueryHook::sendTo), true);
if (!m_sendToDetourSys.detoured ()) {
m_sendToDetourSys.install (reinterpret_cast <void *> (BotSupport::sendTo), true);
m_sendToDetourSys.install (reinterpret_cast <void *> (ServerQueryHook::sendTo), true);
}
}
}

View file

@ -105,9 +105,19 @@ int Bot::findBestGoal () {
if (game.mapIs (MapFlags::Assassination | MapFlags::HostageRescue)) {
if (m_team == Team::Terrorist) {
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
if (game.mapIs (MapFlags::HostageRescue)) {
@ -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) {

View file

@ -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;
}
}