Skip to content

Instantly share code, notes, and snippets.

@sigsegv-mvm
Last active March 30, 2024 04:28
Show Gist options
  • Save sigsegv-mvm/a1f103ae79bbb0a5c5ff7dcd4a378958 to your computer and use it in GitHub Desktop.
Save sigsegv-mvm/a1f103ae79bbb0a5c5ff7dcd4a378958 to your computer and use it in GitHub Desktop.
How MvM engineer bots decide where to teleport in

How MvM engineer bots decide where to teleport in

Console variables

There are 3 console variables that control which hints engie bots will prefer to teleport into based on the bomb position:

tf_bot_engineer_mvm_sentry_hint_bomb_forward_range  (default:    0)
tf_bot_engineer_mvm_sentry_hint_bomb_backward_range (default: 3000)
tf_bot_engineer_mvm_hint_min_distance_from_bomb     (default: 1300)

These all require sv_cheats 1 to modify (but I can potentially invent a popfile parameter to allow changing them per-map/per-mission, if that turns out to be useful). In any case, they're easy to mess around with in a listen server with sv_cheats 1.

They'll be explained a little later.

Nav Mesh: Bomb target distance

For every nav area in the map's nav mesh, the game pre-computes the shortest path distance from that area to the bomb hatch and stores that distance for later use. You can view what the distance is for each area with nav_edit 1 + tf_nav_show_bomb_target_distance 1; here's a video demonstration.

(There's also a not-completely-related, but somewhat similar and certainly very cool-looking overlay you can turn on that shows the nav incursion flow gradient, demonstrated by this video and explained in its video description.)

How the game decides which bomb to consider if there are multiple

If the map has multiple active bombs, then the game goes through each bomb and checks what its bomb target distance is (based on the nav area it's on or close to); and then it uses whichever bomb that has the smallest bomb target distance for all of the calculations I'll be talking about next.

In other words, it always uses the bomb closest to the hatch (in terms of precomputed path distance) for these calculations.

The actual logic used to decide where tele-in engie bots should go

Sorting nest hints into lists

So when it's time for an engie bot to teleport in, the game collects all of the bot_hint_engineer_nest entities on the map that aren't currently occupied by an engie bot, and organizes them into 4 lists:

  1. Hints whose bomb target distance is within [backward_range, forward_range] of the bomb, which are stale nests.*
  2. Hints whose bomb target distance is within [backward_range, forward_range] of the bomb, which are not stale, which are not less than min_distance_from_bomb HU from the bomb (in terms of straight-line distance, not path distance).**
  3. Any hints whose bomb target distance is more than backward_range behind the bomb.
  4. Any hints whose bomb target distance is more than forward_range ahead of the bomb.

* A stale engie nest is one which has at least one building standing, that isn't owned by any active engie bot. Generally this means a "Engineer bot destroyed! Now take down his teleporter!" (or sentry) type of situation. So a non-stale nest, for our purposes here, is defined as a nest that's completely empty.

** Notice that any hints that are within [backward_range, forward_range] of the bomb, which are not stale nests, and which are less than min_distance_from_bomb Hammer Units from the bomb, will not be added to any list, and are therefore effectively completely ignored.

Picking from the lists

The game now goes through the 4 lists to decide which hint the engie bot should teleport in to. It does this in a sort of priority order:

  • If there are any hints in list 1, then the hint is picked randomly from list 1.
  • If list 1 is empty, but there are hints in list 2, then the hint is picked randomly from list 2.
  • If list 2 is empty, but there are hints in list 3, then the hint is picked randomly from list 3.*
  • If list 3 is empty, but there are hints in list 4, then the hint is picked randomly from list 4.*

* When the game is picking from list 3 or list 4, it will always prefer to pick a stale nest hint from the list if there happens to be at least one.

What happens if all 4 lists are empty?

If there are no hints in any of the 4 lists, then the game will simply refuse to spawn a teleport-in engie bot.

If by some happenstance a teleport-in engie bot were to spawn at such a time, then the engie would just awkwardly stand around in the bot spawn until conditions change such that there is a hint in one of the lists, and then he would finally teleport in.

Troubleshooting teleport-in engie bots

Based on reading the previous section, it should be pretty clear that by tweaking the 3 console variables mentioned at the top of this writeup, you can have a substantial impact on which hints will end up in each oof those 4 lists.

In cases where engie bots are teleporting into seemingly random hints that are nowhere near the bomb, it's very likely that list 1 and list 2 are ending up empty (perhaps due to the map being too "compact" or "serpentine", therefore meaning that the hints that are within [3000 HU back, 0 HU fwd] path distance of the bomb also tend to be within 1300 HU straight-line distance from the bomb). When there are no hints in list 1 and list 2, then the game is forced to fall back to list 3 and list 4, which essentially means that the game will be picking random hints that are far behind the bomb or far in front of the bomb (they can basically be almost anywhere on the map).

Improving this situation could potentially entail adding more engie nests (simply boosting the likelihood that there will be at least one hint that's in a valid spot for list 2); and/or tweaking the console variables to be less restrictive (making the min_distance_from_bomb smaller and/or making the forward_range/backward_range larger, which again will boost the chance that at least one hint will be considered valid for list 2).

Visualizing the engie bot hint choosing logic in-game

There's a helpful console command, tf_bot_mvm_show_engineer_hint_region, which illustrates the teleport-in logic somewhat. You simply point at a spot on the map, and then execute the command, and then it'll draw some stuff. (It's probably a good idea to bind this command to a key, so that you can just point at various locations and hit that key with minimal effort.)

What the command does, is to essentially draw a "what if" scenario for what would happen if the bomb were to be at the location you pointed to. It gets the bomb target distance for the nav area where you pointed, and then draws various things on the screen for a few seconds:

  1. It draws a big ugly yellow "sphere" (basically three polygons that sort of roughly, very vaguely resemble a sphere) around the hypothetical bomb position you chose, which shows the volume of the map encompassed by the min_distance_from_bomb radius.
  2. It draws orange rectangles for all of the nav areas that have a bomb target distance within [backward_range, forward_range] of the hypothetical bomb position.
  3. It draws small colored spheres for the engie hints in those orange nav areas, as follows:
  • bot_hint_sentrygun hints will always be green.
  • bot_hint_teleporter_exit hints will always be blue.
  • bot_hint_engineer_nest hints within min_distance_from_bomb of the hypothetical bomb position (i.e. inside the yellow "sphere") will be red. These hints would be excluded from list 2.*
  • bot_hint_engineer_nest hints beyond min_distance_from_bomb of the hypothetical bomb position (i.e. outside the yellow "sphere") will be yellow. These hints would be included in list 2.*

* And note that in both cases, if the bot_hint_engineer_nest were to be stale, it would be included in list 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment