Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt
Use this file to discover all available pages before exploring further.
CTFBot (game/server/tf/bot/tf_bot.h) is TF2’s bot player class. It inherits from NextBotPlayer<CTFPlayer>, combining the full player entity with the NextBot component system. CTFBot drives all AI-controlled players: Mann vs. Machine robots, training mode bots, and tournament practice bots.
CTFBot class structure
NextBot components
CTFBot uses four specialized components declared ingame/server/tf/bot/:
| Component | File | Responsibility |
|---|---|---|
CTFBotLocomotion | tf_bot_locomotion.h | Movement, jumping, ladder climbing, stuck detection |
CTFBotVision | tf_bot_vision.h | Enemy detection, FOV filtering, threat prioritization |
CTFBotBody | tf_bot_body.h | Aim direction, look-at targets, crouch control |
| Intention / Behavior | behavior/tf_bot_behavior.h | Behavior tree root, dispatches to action classes |
Behavior action tree
The bot’s decision-making is a stack ofAction<CTFBot> objects. The top action runs each tick; it can return Continue(), SuspendFor(newAction), Done(), or ChangeTo(newAction). Actions are organized by scenario role:
Top-level actions
Top-level actions
CTFBotMainAction is the root. It delegates to scenario-specific actions:CTFBotSeekAndDestroy— general offensive behaviorCTFBotAttack— engage a specific threatCTFBotRetreatToCover— disengage and find coverCTFBotGetHealth— navigate to a health pickupCTFBotGetAmmo— navigate to an ammo pickup
Class-specific behavior folders
Class-specific behavior folders
Each TF2 class has a subfolder under
behavior/ with override actions:behavior/engineer/— sentry placement, dispenser building, teleporter setupbehavior/medic/— healing target selection, ÜberCharge managementbehavior/spy/— disguise selection, backstab approach, sapper placementbehavior/sniper/— vantage point selection, scope timingbehavior/demoman/— sticky trap placement, grenade arc targeting
MvM-specific actions
MvM-specific actions
CTFBotMvMDeployBomb— carrying and deploying the bomb at the hatchCTFBotEscortFlag— following the bomb carrier in a squadbehavior/missions/— tank escort, sentry buster, spy mission behaviors
Vision system
CTFBotVision (tf_bot_vision.h/cpp) extends IVision and filters detected entities by team, distance, and line-of-sight. It maintains a sorted threat list and exposes GetPrimaryKnownThreat() to behavior actions.
Difficulty attributes
CTFBot difficulty is controlled by a set of integer attributes (m_iSkill) that scale reaction time, aim spread, and target-switching speed. MvM popfiles can also override individual bot attributes such as MaxVisionRange and AimTrackingInterval per bot generator.