From 375a64b861d4d8553196b3745bc43908fa42a771 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 15 Feb 2024 23:57:54 +0300 Subject: [PATCH] nav: reworked bot dropping on pathfinder failure --- inc/manager.h | 1 + src/botlib.cpp | 6 ------ src/engine.cpp | 3 +++ src/manager.cpp | 11 ++++++++++- src/navigate.cpp | 10 +++++----- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/inc/manager.h b/inc/manager.h index cbbcb4f..29fb035 100644 --- a/inc/manager.h +++ b/inc/manager.h @@ -121,6 +121,7 @@ public: void handleDeath (edict_t *killer, edict_t *victim); void setLastWinner (int winner); void checkBotModel (edict_t *ent, char *infobuffer); + void checkNeedsToBeKicked (); bool isTeamStacked (int team); bool kickRandom (bool decQuota = true, Team fromTeam = Team::Unassigned); diff --git a/src/botlib.cpp b/src/botlib.cpp index a968e00..b8972c4 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -2759,12 +2759,6 @@ void Bot::frame () { } void Bot::update () { - - // kick bot from server if requested - if (m_kickMeFromServer) { - kick (); - return; - } const auto tid = getCurrentTaskId (); m_canChooseAimDirection = true; diff --git a/src/engine.cpp b/src/engine.cpp index 795f0f5..42ea4be 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -1030,6 +1030,9 @@ void Game::slowFrame () { // display welcome message util.checkWelcome (); + // kick failed bots + bots.checkNeedsToBeKicked (); + // update next update time m_oneSecondFrame = nextUpdate + time (); } diff --git a/src/manager.cpp b/src/manager.cpp index 8b539c2..8cb90b7 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -816,6 +816,15 @@ void BotManager::checkBotModel (edict_t *ent, char *infobuffer) { } } +void BotManager::checkNeedsToBeKicked () { + for (const auto &bot : bots) { + if (bot->m_kickMeFromServer) { + bot->kick (); // kick bot from server if requested + break; + } + } +} + void BotManager::setWeaponMode (int selection) { // this function sets bots weapon mode @@ -1659,7 +1668,7 @@ void Bot::kick (bool silent) { // this function kick off one bot from the server. auto username = pev->netname.chars (); - if (!(pev->flags & FL_CLIENT) || strings.isEmpty (username)) { + if (!(pev->flags & FL_CLIENT) || (pev->flags & FL_DORMANT) || strings.isEmpty (username)) { return; } markStale (); diff --git a/src/navigate.cpp b/src/navigate.cpp index 5b9a6c1..03bc3be 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -3052,7 +3052,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) { srcIndex = changeNodeIndex (graph.getNearestNoBuckets (pev->origin, 256.0f)); if (!graph.exists (srcIndex)) { - printf ("%s source path index not valid (%d).\n", __func__, srcIndex); + fprintf (stderr, "%s source path index not valid (%d).\n", __func__, srcIndex); return; } } @@ -3063,7 +3063,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) { destIndex = graph.random (); if (!graph.exists (destIndex)) { - printf ("%s dest path index not valid (%d).\n", __func__, destIndex); + fprintf (stderr, "%s dest path index not valid (%d).\n", __func__, destIndex); return; } } @@ -3071,7 +3071,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) { // do not process if src points to dst if (srcIndex == destIndex) { - printf ("%s source path is same as dest (%d).\n", __func__, destIndex); + fprintf (stderr, "%s source path is same as dest (%d).\n", __func__, destIndex); return; } clearSearchNodes (); @@ -3126,7 +3126,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) { m_kickMeFromServer = true; // bot should be kicked within main thread, not here // bot should not roam when this occurs - printf ("A* Search for bot \"%s\" failed with internal pathfinder error. Seems to be graph is broken. Bot removed (re-added).\n", pev->netname.chars ()); + fprintf (stderr, "A* Search for bot \"%s\" failed with internal pathfinder error. Seems to be graph is broken. Bot removed (re-added).\n", pev->netname.chars ()); break; case AStarResult::Failed: @@ -3134,7 +3134,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) { findShortestPath (srcIndex, destIndex); // A* found no path, try floyd pathfinder instead if (cv_debug.bool_ ()) { - printf ("A* Search for bot \"%s\" has failed. Falling back to shortest-path algorithm. Seems to be graph is broken.\n", pev->netname.chars ()); + fprintf (stderr, "A* Search for bot \"%s\" has failed. Falling back to shortest-path algorithm. Seems to be graph is broken.\n", pev->netname.chars ()); } break; }