TFBot Technicalities

TFBots are NextBots used in officially for Mann vs. Machine, training modes, and also competitive in the event that a player leaves before the match completes.
In Mann vs. Machine, 22 slots are reserved for TFBots to use, leading to the recommendation of 32 maxplayers for servers hosting Mann vs. Machine games.
==Skill / Difficulty==
Bots behave based on the skill value (or difficulty) they have, which can be set through or with . Skills are defined in game as follows:
* Easy (0)
* Normal (1)
* Hard (2)
* Expert (3)
==Combat==
TFBot has a chance to perform a taunt upon killing an enemy.
Bots will stay in combat until:
* They have less than 20% max ammo left.
* They need to do a full reload and they are Hard or Expert bots.
* Their friend score is lower than the foe score.
* Their health percentage is lower than .
Bots will search for health kits and dispensers when their health is lower than or they are on fire, they are not in combat, and a healer is not healing them already. The range that bots will hunt for health in is
 searchRange = tf_bot_health_search_far_range + (current health / max health) * (tf_bot_health_search_near_range - tf_bot_health_search_far_range );
Bots won't try to get health in the Mann Vs. Machine gamemode.
===Threat Level===
Threat levels are scores used to determine how dangerous something is. This value is between 0 (no danger) and 1 (immediate danger). The following actions give a certain threat level:
Threat 	Value
Enemy (Class) 	Varied
Übered enemies 	1
Level 3 Sentry 	1
Level 2 Sentry 	0.8
Level 1 Sentry 	0.6
Enemies further than units from a Sniper	0
Typically the threat level is stored in two variables: the friend score and the foe score. These scores are determined through accumulating the threat level of every visible known ally and enemy respectively. Bots will try to retreat if the friend score is lower than the foe score.
==Class Info==
TFBots will change classes in spawn with , and upon death through . 
===Rosters===
ClassSelectionInfo is a structure that determines the conditions for selecting a class.[4] The conditions for selecting a class can be the minimum team size, the player rate, minimum and maximum amount of the class.[4]
Rosters are ClassSelectionInfo arrays that determine how TFBots choose each class.[4]
There are 3 predefined rosters that are used if is set; the offensive roster, the defensive roster, and competitive roster for competitive game modes.[4]
 Offense Roster
 	 	 	 	Limits	Limits	Limits	Limits
Class 	Team Size Threshold	Player Rate	Minimum Amount	Easy 	Normal	Hard 	Expert
Scout 	0 	0 	1 	3 	3 	3 	3
Soldier 	0 	0 	0 	None 	None 	None 	None
Pyro 	0 	0 	0 	2 	3 	3 	3
Demoman 	3 	0 	0 	None 	None 	None 	None
Heavy(weapons)	3 	0 	0 	1 	1 	2 	2
Engineer 	5 	0 	0 	1 	1 	1 	1
Medic 	4 	4 	1 	1 	1 	2 	2
Sniper 	5 	0 	0 	0 	1 	1 	1
Spy 	5 	0 	0 	1 	1 	1 	1
 Defense Roster
 	 	 	 	Limits	Limits	Limits	Limits
Class 	Team Size Threshold	Player Rate	Minimum Amount	Easy 	Normal	Hard 	Expert
Soldier 	0 	0 	0 	None 	None 	None 	None
Pyro 	3 	0 	0 	None 	None 	None 	None
Demoman 	3 	0 	0 	2 	3 	3 	3
Heavy(weapons)	3 	0 	0 	1 	1 	2 	2
Engineer 	0 	4 	1 	1 	2 	3 	3
Medic 	4 	4 	1 	1 	1 	2 	2
Sniper 	5 	0 	0 	0 	1 	1 	1
Spy 	5 	0 	0 	0 	1 	2 	2
 Competitive Roster
 	 	 	 	Limits	Limits	Limits	Limits
Class 	Team Size Threshold	Player Rate	Minimum Amount	Easy 	Normal	Hard 	Expert
Scout 	0 	0 	0 	0 	0 	2 	2
Soldier 	0 	0 	0 	0 	0 	None 	None
Pyro 	0 	-1 	 	 	 	 	
Demoman 	0 	0 	0 	0 	0 	2 	2
Heavyweapons	3 	0 	0 	0 	0 	2 	2
Engineer 	0 	-1 	 	 	 	 	
Medic 	1 	0 	1 	0 	0 	1 	1
Sniper 	0 	-1 	 	 	 	 	
Spy 	0 	-1 	 	 	 	 	
===Scout===
 Info
Preferred Weapon 	Primary
Threat Value 	0.6
Medic Bot Priority	None
===Soldier===
 Info
Preferred Weapon 	Primary
Threat Value 	0.8
Medic Bot Priority	2nd
Soldier bots prefer their primary weapon in combat, but will switch to their secondary if they are out of primary weapon ammo and the threat is closer than 500hu.
===Pyro===
 Info
Preferred Weapon 	Primary
Threat Value 	1
Medic Bot Priority	3rd
Pyro bots are normally offensive and will attack enemies with their primary weapon. However if the enemy is further than 750hu, the bot Pyro will equip its secondary weapon.
They airblast enemies that are closer than hammer units to the bot pyro, and projectiles if they are visible to the pyro bot and are within angles (in radians) relative to the Pyro bot's FOV. The chance that they will airblast a projectile depends on their skill level.
Skill Level	Chance to Airblast
Easy 	0% chance
Normal 	50% chance
Hard 	90% chance
Expert 	100% chance
===Demoman===
 Info
Preferred Weapon 	Primary and Secondary
Threat Value 	0.6
Medic Bot Priority	4th
Demoman bots fire their primary weapon in an arc. The angle they fire grenades is × v, v being the distance to the target as a normalized vector. They will not fire with their primary above 45° or 0.79π.
When they encounter Sentries, Demoman bots prefer their secondary over their primary and stack stickybombs on the Sentry to then detonate them.
They will sometimes set up sticky-bomb traps on nav areas where they predict the enemy will pass through. The amount of stickybombs they place is × the area of the target nav area which will always be ≥1. Demoman bots will stop setting up their trap if they see an enemy that is less than 500hu away.
===Heavy===
 Info
Preferred Weapon 	Primary
Threat Value 	0.8
Medic Bot Priority	1st
Heavy bots prefer to use their primary weapon when in combat. They will "rev" (hold right click) for at least three seconds if they see an enemy.
They are the most preferred patient to be healed by Medic bots, out of the other classes.
===Engineer===
 Info
Preferred Weapon 	Melee and Primary (for combat)
Threat Value 	0.4
Medic Bot Priority	None
Engineer bots focus on building near sentry spots (s with hint KV set to 1). Engineer bots normally just stay around their sentry and constantly hit it with their wrench. If the engineer bot get attacked however, they will attack with their weapon and flee.
In Mann Vs. Machine Engineer bots will not attack, unless if they're marked as a squad. They can only build Sentry Guns and Teleporters, and they build around groups of s, s, and s, rather than 's.
====Teleporters====
Non-Medic bots will normally prefer to take active teleporters over walking to the destination, but they will only take them when their incursion distance is less than 350hu + the teleporter area's incursion distance. However Medic bots will only take the teleporter if it's patient also goes through the teleporter; otherwise they ignore teleporters.
===Medic===
 Info
Preferred Weapon 	Secondary
Threat Value 	0.2
Medic Bot Priority	None
Medic bots passively heal patients that are in their current viscinity, and will follow their patient when they are between and from them. They will respond to call for medic from human players that are within units from the medic bots.
They prefer to heal ally heavies, soldiers, pyros, and demomen over the other classes. If the medic bot is in a squad, they will only heal the squad leader. In the training gamemode, medic bots will always stay on the human player.
If Medic bots have the vaccinator equipped, they will use their über when they or their patient have taken damage. Otherwise medic bots will use their über when:
* The patient's health ratio is less than 0.5.
* The patient is not already übered.
* The medic bot's health is less than 25, 50, or bot_medic_uber_health_threshold attribute.
In MvM medic bots will not attack, unless if marked to be part of a squad in the popfile.
===Sniper===
 Info
Preferred Weapon 	Primary
Threat Value 	0.4
Medic Bot Priority	None
Sniper bots typically look around for up to Sniper Spots, which are hint-0-s in MvM or nav areas outside MvM, that are at least units away from adjacent sniper spots and attack from those areas; they search for sniper spots per update frame. However if an enemy gets close to them, the Sniper bot will fight them and then try to retreat to their goal. If the threat is closer than 750hu, then Sniper bots will use their secondary weapon.
When aiming through their primary, Sniper bots choose a target part to hit based on their skill level and take 0.5 to 1.5 seconds to adjust their aim. An error angle between ±π and error radius between 0 and is then applied to their aim.[3] Expert and Hard bots always aim for the head, normal bots aim between the head and body (specifically ⅓ of the head's z position), and easy bots just aim for the body. If Sniper bots have the Huntsman equipped, then they will fire in an arc affected by , and aim for the same body parts.
Sniper bots will stay units away from an enemy capture point, while they'll stay within this range in an ally capture point.
===Spy===
 Info
Preferred Weapon 	Primary and Melee
Threat Value 	0.6
Medic Bot Priority	None
Spy bots typically lurk around hiding spots.[game/server/tf/bot/behavior/spy/CTFBotSpyInfiltrate::Update] They prefer to use their melee weapon if the target is closer than units to the spy. If their target is further than units away, Spy bots will choose another target that is closer than that distance. They will attempt to attack the back of an enemy (or backstab) at an angle based on the difficulty of the bot.
They are suspected by enemies if they collide with an enemy for more than consecutive seconds.
When sapping a building. If a spy bot is less than 300HUs from the sap target; they will not dodge enemies.[5: game/server/tf/bot/behavior/spy/tf_bot_spy_sap.cpp]
==Console Variables and Commands==
To skip to the next section (Bot Names), click here.
=== Server Management ===
=== Global Behavior ===
==== Debugging ====
=== Class Specific ===
==== Pyro ====
==== Demoman ====
==== Engineer ====
==== Medic ====
==== Sniper ====
==== Spy ====
=== Mode Specific ===
==== Flag-based modes ====
Includes Capture the Flag, Special Delivery, Mann vs. Machine, etc.
==== Mann vs. Machine ====
===== Engineer =====
===== Sentry Buster =====
==== Payload ====
=== Miscellaneous ===
==== ====
==== Unused ====
==Bot Names==
To go back up to the previous section (ConVars/ConCommands), click here.
The following 4 columns of bot names are what the game uses to randomly set a bot name when creating a bot.
			
===Unused Bot Names===
The following bot names were found in a leaked source code version of TF2, containing bot names that were never put into production for unknown reasons.
==Code References==
* [1] - game/server/tf/bot/behavior/medic/tf_bot_medic_heal.cpp:CTFBotMedicHeal::IsGoodUberTarget(CTFPlayer *who)
* [2] - game/server/tf/bot/behavior/medic/tf_bot_medic_heal.cpp:CTFBotMedicHeal::SelectPatient(CTFBot *me, CTFPlayer *current)
* [3] - game/server/tf/bot/behavior/tf_bot_behavior.cpp:CTFBotMainAction::SelectTargetPoint(const INextBot *meBot, const CBaseCombatCharacter *subject)
* [4] - game/server/tf/bot/tf_bot.cpp:CTFBot::GetNextSpawnClassname()
==See also==
* 
* 'TFBot skill levels explained in excruciating detail' - By Sigsegv
* 'MvM - Advanced Popfile Techniques' - By Mince and 8 other collaborators
Category:NextBot Entities
Category:Team Fortress 2