nav: reworked bot dropping on pathfinder failure

This commit is contained in:
jeefo 2024-02-15 23:57:54 +03:00
commit 375a64b861
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
5 changed files with 19 additions and 12 deletions

View file

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

View file

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

View file

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

View file

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

View file

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