Every weapon in TF2 descends fromDocumentation 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.
CBaseCombatWeapon (the Source engine base) through a three-level hierarchy defined in game/shared/tf/tf_weaponbase.h. The tree splits at CTFWeaponBase into ranged (CTFWeaponBaseGun) and melee (CTFWeaponBaseMelee) branches, with a grenade sub-branch for throwable weapons.
Inheritance tree
On the client,
CTFWeaponBase is aliased to C_TFWeaponBase via a preprocessor define so the same header compiles for both DLLs.CTFWeaponBase — the root class
CTFWeaponBase inherits from both CBaseCombatWeapon and IHasOwner. On the client it also extends CGameEventListener. Its declaration from tf_weaponbase.h:
Weapon data parsing
Each weapon’s stats are stored in aCTFWeaponInfo struct (from tf_weapon_parse.h) loaded from script files. GetTFWpnData() returns a const reference to this parsed data, which includes projectile type, damage, fire rate, and per-mode data via GetWeaponData(m_iWeaponMode).
Reload state machine
Single-shell reload weapons (e.g. shotguns) use a four-state enum defined intf_weaponbase.h:
Charge-up interface
Weapons that charge before firing implementITFChargeUpWeapon:
CTFWeaponBaseGun — ranged weapons
Defined intf_weaponbase_gun.h, this class handles all projectile and hitscan fire:
FireProjectile dispatches to the correct helper (FireRocket, FireBullet, FireArrow, etc.) based on GetWeaponProjectileType(), which reads from the parsed weapon data.
CTFWeaponBaseMelee — melee weapons
Defined intf_weaponbase_melee.h, melee weapons always report HasPrimaryAmmo() = true and resolve hits via a swing trace:
Smack() is the deferred hit callback: it fires after the swing animation starts and calls DoSwingTrace to find targets in range.
Ammo types
IsAmmoType(int iAmmoType, const char *pAmmoName) (declared in tf_weaponbase.h) compares an integer ammo index against a string name. Ammo types are registered in the game rules and referenced by weapon scripts; common types include TF_AMMO_PRIMARY, TF_AMMO_SECONDARY, and TF_AMMO_METAL (for the Engineer).