Every playable character in TF2 is an instance ofDocumentation 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.
CTFPlayer, a server-side class that inherits from CBaseMultiplayerPlayer. The current class a player has selected is tracked by an embedded CTFPlayerClassShared object, which holds the class index and delegates all stat lookups to a TFPlayerClassData_t struct loaded from script files at startup.
The TF_CLASS enum
All 9 classes (plus sentinel values) are defined as an anonymous enum in tf_shareddefs.h:
TF_CLASS_CIVILIAN is the TF_LAST_NORMAL_CLASS sentinel. Iterating over all playable classes uses the macro FOR_EACH_NORMAL_PLAYER_CLASS(_i), which loops from TF_FIRST_NORMAL_CLASS (1) up to but not including TF_LAST_NORMAL_CLASS.Class reference
| Class | TF_CLASS_* value | Role |
|---|---|---|
| Scout | 1 | Fast flanker, double jump |
| Sniper | 2 | Long-range, scoped shots |
| Soldier | 3 | Rocket launcher, rocket jump |
| Demoman | 4 | Sticky bombs, grenades |
| Medic | 5 | Healing, Ubercharge |
| Heavy | 6 | High health, minigun |
| Pyro | 7 | Flamethrower, airblast |
| Spy | 8 | Disguise, backstab, cloak |
| Engineer | 9 | Buildings: sentry, dispenser, teleporter |
CTFPlayer class hierarchy
CTFPlayer is declared in game/server/tf/tf_player.h and inherits from three bases:
CBaseMultiplayerPlayer sits above CBasePlayer in the Source engine hierarchy and adds team-play utilities. IHasAttributes plugs the player into the item attribute system. IInventoryUpdateListener receives callbacks when the loadout changes.
CTFPlayerClassShared: current class state
The CTFPlayerClassShared object (declared in game/shared/tf/tf_playerclass_shared.h) is embedded inside CTFPlayerShared and networked to the client via DT_TFPlayerClassShared. It stores:
m_iClass— the currentTF_CLASS_*index (networked)m_iszClassIcon/m_iszCustomModel— optional custom visuals (MvM robots, Halloween)- Custom model transform and animation flags
GetPlayerClassData(m_iClass):
GetPlayerClassData() returns a pointer into a global array of TFPlayerClassData_t structs. Each struct is populated at startup from a per-class script file by parsing the speed_max, health_max, and model keys via KeyValues.
Class switching flow
Player selects a class
The client sends a
joinclass command. The server validates the request and calls CTFPlayer::HandleCommand_JoinClass().Desired class is stored
m_Shared.SetDesiredPlayerClassIndex() records the new class. The switch is deferred until the next respawn.Respawn applies the class
On respawn,
CTFPlayerClassShared::Init( iClass ) sets m_iClass and resets all per-class state. TeamFortress_SetSpeed() is called to update m_flMaxspeed from the new class data.