nav: break camp task if avoiding

This commit is contained in:
jeefo 2025-01-31 23:45:35 +03:00
commit f0b74452d3
No known key found for this signature in database
GPG key ID: D696786B81B667C8
2 changed files with 16 additions and 4 deletions

View file

@ -478,6 +478,18 @@ void Bot::doPlayerAvoidance (const Vector &normal) {
const auto ownPrio = bots.getPlayerPriority (ent ()); const auto ownPrio = bots.getPlayerPriority (ent ());
auto clearCamp = [] (edict_t *ent) {
auto bot = bots[ent];
if (bot) {
auto tid = bot->getCurrentTaskId ();
if (tid == Task::Camp || tid == Task::Hide || tid == Task::Pause) {
bot->completeTask ();
}
}
};
// find nearest player to bot // find nearest player to bot
for (const auto &client : util.getClients ()) { for (const auto &client : util.getClients ()) {
if (!(client.flags & ClientFlags::Used) || !(client.flags & ClientFlags::Alive) || client.team != m_team || client.ent == ent ()) { if (!(client.flags & ClientFlags::Used) || !(client.flags & ClientFlags::Alive) || client.team != m_team || client.ent == ent ()) {
@ -554,6 +566,7 @@ void Bot::doPlayerAvoidance (const Vector &normal) {
} }
} }
m_isStuck = false; m_isStuck = false;
m_navTimeset = game.time ();
if (distanceSq < cr::sqrf (96.0f)) { if (distanceSq < cr::sqrf (96.0f)) {
if ((dir | forward.normalize2d_apx ()) < 0.0f) { if ((dir | forward.normalize2d_apx ()) < 0.0f) {
@ -1304,7 +1317,7 @@ bool Bot::updateNavigation () {
} }
// always increase reachability distance for occupied nodes // always increase reachability distance for occupied nodes
if (isOccupiedNode (m_path->number, pathHasFlags)) { if (!(graph[m_path->number].flags & NodeFlag::Crouch) && isOccupiedNode (m_path->number, pathHasFlags)) {
desiredDistanceSq = cr::sqrf (96.0f); desiredDistanceSq = cr::sqrf (96.0f);
nodeDistanceSq *= 0.5f; nodeDistanceSq *= 0.5f;
} }
@ -2622,7 +2635,7 @@ void Bot::setPathOrigin () {
}; };
// if node radius non zero vary origin a bit depending on the body angles // if node radius non zero vary origin a bit depending on the body angles
if (radius > 16.0f) { if (radius > 16.0f && !isInNarrowPlace ()) {
int nearestIndex = kInvalidNodeIndex; int nearestIndex = kInvalidNodeIndex;
if (!m_pathWalk.empty () && m_pathWalk.hasNext ()) { if (!m_pathWalk.empty () && m_pathWalk.hasNext ()) {

View file

@ -266,13 +266,12 @@ bool BotSupport::isBreakableEntity (edict_t *ent, bool initialSeed) {
constexpr auto kFuncWall = StringRef::fnv1a32 ("func_wall"); constexpr auto kFuncWall = StringRef::fnv1a32 ("func_wall");
if (ent->v.takedamage > 0.0f && ent->v.impulse <= 0 && !(ent->v.flags & FL_WORLDBRUSH) && !(ent->v.spawnflags & SF_BREAK_TRIGGER_ONLY)) { if (ent->v.takedamage > 0.0f && ent->v.impulse <= 0 && !(ent->v.flags & FL_WORLDBRUSH) && !(ent->v.spawnflags & SF_BREAK_TRIGGER_ONLY)) {
auto classHash = ent->v.classname.str ().hash (); const auto classHash = ent->v.classname.str ().hash ();
if (classHash == kFuncBreakable || (classHash == kFuncPushable && (ent->v.spawnflags & SF_PUSH_BREAKABLE)) || classHash == kFuncWall) { if (classHash == kFuncBreakable || (classHash == kFuncPushable && (ent->v.spawnflags & SF_PUSH_BREAKABLE)) || classHash == kFuncWall) {
return ent->v.movetype == MOVETYPE_PUSH || ent->v.movetype == MOVETYPE_PUSHSTEP; return ent->v.movetype == MOVETYPE_PUSH || ent->v.movetype == MOVETYPE_PUSHSTEP;
} }
} }
return false; return false;
} }