nav: fix some door opening glitches

This commit is contained in:
jeefo 2024-07-10 23:48:20 +03:00
commit c63cccb1a2
No known key found for this signature in database
GPG key ID: D696786B81B667C8

View file

@ -1171,17 +1171,19 @@ bool Bot::updateNavigation () {
} }
// if bot hits the door, then it opens, so wait a bit to let it open safely // if bot hits the door, then it opens, so wait a bit to let it open safely
if (pev->velocity.lengthSq2d () < cr::sqrf (2.0f) && m_timeDoorOpen < game.time ()) { if (pev->velocity.lengthSq2d () < cr::sqrf (4.0f) && m_timeDoorOpen < game.time ()) {
if (getCurrentTaskId () != Task::MoveToPosition) {
startTask (Task::Pause, TaskPri::Pause, kInvalidNodeIndex, game.time () + 0.5f, false); startTask (Task::Pause, TaskPri::Pause, kInvalidNodeIndex, game.time () + 0.5f, false);
}
m_timeDoorOpen = game.time () + 1.0f; // retry in 1 sec until door is open m_timeDoorOpen = game.time () + 1.0f; // retry in 1 sec until door is open
++m_tryOpenDoor; ++m_tryOpenDoor;
if (m_tryOpenDoor > 2) { if (m_tryOpenDoor > 1 && m_tryOpenDoor < 4) {
edict_t *nearest = nullptr; edict_t *nearest = nullptr;
// try to find nearest enemy (maybe behind a door) // try to find nearest enemy (maybe behind a door)
util.findNearestPlayer (reinterpret_cast <void **> (&nearest), ent (), 192.0f, false, false, true, true, false); util.findNearestPlayer (reinterpret_cast <void **> (&nearest), ent (), 256.0f, false, false, true, true, false);
// check if enemy is penetrable // check if enemy is penetrable
if (util.isAlive (nearest) && isPenetrableObstacle (nearest->v.origin) && !cv_ignore_enemies) { if (util.isAlive (nearest) && isPenetrableObstacle (nearest->v.origin) && !cv_ignore_enemies) {
@ -1197,10 +1199,12 @@ bool Bot::updateNavigation () {
} }
} }
else if (m_tryOpenDoor > 4) { else if (m_tryOpenDoor > 4) {
clearSearchNodes ();
clearTasks ();
m_tryOpenDoor = 0; m_tryOpenDoor = 0;
// go back to prev node, if blocked for long time
if (graph.exists (m_previousNodes[0])) {
startTask (Task::MoveToPosition, TaskPri::MoveToPosition, m_previousNodes[0], game.time () + 3.0f, true);
}
} }
} }
} }