Skip to content

Bots avoid hazard areas#2020

Draft
sunzenshen wants to merge 2 commits into
NeotokyoRebuild:masterfrom
sunzenshen:bot-avoid-smoke
Draft

Bots avoid hazard areas#2020
sunzenshen wants to merge 2 commits into
NeotokyoRebuild:masterfrom
sunzenshen:bot-avoid-smoke

Conversation

@sunzenshen

Copy link
Copy Markdown
Contributor

Description

Bots avoid hazard areas:

  • areas that are in line of sight of a smoke cloud
  • areas that are in line of sight of a grenade trajectory
  • areas where a teammate recently died

Toolchain

  • Windows MSVC VS2022

Bots avoid hazard areas:
- areas that are in line of sight of a smoke cloud
- areas that are in line of sight of a grenade trajectory
- areas where a teammate recently died
else
{
// Fallback if GetLastKnownArea is null, try finding nearest nav area
CNavArea *nearestArea = TheNavMesh->GetNearestNavArea( me->GetAbsOrigin() );

@sunzenshen sunzenshen Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided that if for some reason the situation was bugged enough that we don't know the GetLastKnownArea of a bot, we shouldn't bother trying to search for GetNearestNavArea. GetNearestNavArea is a bit more expensive and, if the situation is glitched, might not even return an appropriate navarea.

@sunzenshen sunzenshen left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this PR was to have bots avoid areas that were visible from smoked areas, if they do not have thermal vision. Before this PR, bots tended to disregard smoke and would fall victim to either Support bots or humans that know to spray into the smoke. This PR introduces a time-expiring hazard area marking lookup for smoke and general hazardous areas.

Along with support for smoke, I added hazard area marking for grenades and death locations. The thinking for bot grenade trajectories is that they are so erratic that it's safer to assume that any place along the trajectory towards the target and beyond is a dangerous area. For marking death areas of friendly bots, it's mostly to have bots pause towards running into a fatal funnel if the room is narrow enough to be blocked by the bot death locations.

return -1.0f;
return -1.0f; // attempt to route around hazards
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff on this file is kind of ugly, but this hazard avoidance marking is the new change. A return value of -1.0 is considered an impassable navarea. The assumption is that this impassability applies only when a bot is not in a hazard area, and if a bot was in a hazard area, then they will check that in tactical monitor and try to exit the hazard area.

// first area in path, no cost
return 0.0f;
}
else

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of this file was getting rid of one level of indentation inherited from copying CSimpleBotPathCost, by getting rid of this else.

@sunzenshen sunzenshen requested a review from a team July 14, 2026 05:03
@sunzenshen sunzenshen added the Bots Related to bot players label Jul 14, 2026
@sunzenshen

Copy link
Copy Markdown
Contributor Author

Demo example of bots moving out of a room with smoke coverage, into one where there is no exposed smoke:

bot-avoid-smoke-demo.mp4

@sunzenshen sunzenshen left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that I also incremented OnStuck area avoidance penalties for bot death areas, not just for bots getting stuck so here's another set of adjustments when testing the allowance of bot death areas as candidates for where to escape a hazard.

{
return true;
}
if (CNEOBotPathReservations()->GetAreaAvoidPenalty(navAreaId) >= m_onStuckPenalty)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot I added avoidance penalties for areas where a bot died, so I made the threshold under which a bot got stuck in a location, allowing to minor penalty for death areas to be used as candidates if under the OnStuck threshold.


if ( m_goalArea && m_attackCoverArea )
{
return ANSWER_NO;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While preventing the bots from retreating when they are rushing for a cover area was okay for proving out #2000, it made the bots a bit suicidal when their chosen advancing cover was too exposed, so I think it's better to retreat when there's any incoming fire.

This also encourages more grenade throw attempts which is helpful for viewing the smoke and grenade avoidance behavior.

{
m_coverArea = FindCoverArea( me );
CNEOBotPathCompute(me, m_path, m_coverArea->GetCenter(), FASTEST_ROUTE);
CNEOBotPathReservations()->IncrementAreaAvoidPenalty(me->GetLastKnownArea()->GetID(), neo_bot_path_reservation_onstuck_penalty.GetFloat());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a bot gets stuck, sometimes the chosen cover area is the culprit, so look for another random cover area to reset.

@sunzenshen sunzenshen removed the request for review from a team July 15, 2026 03:30
@sunzenshen sunzenshen marked this pull request as draft July 15, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bots Related to bot players

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant