Skip to main content

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.

All three Engineer buildings share a common base class, CBaseObject, defined in game/server/tf/tf_obj.h. It extends CBaseCombatCharacter and implements IHasBuildPoints and IScorer. Each building goes through a well-defined lifecycle — placement, construction, active operation, upgrade, and destruction — controlled by virtual methods that each subclass overrides.

CBaseObject base class

Key constants and virtual methods from tf_obj.h:
#define OBJ_MAX_UPGRADE_LEVEL           3
#define OBJECT_REPAIR_RATE              10      // HP healed per second while repairing
#define OBJECT_CONSTRUCTION_INTERVAL    0.1
#define OBJECT_CONSTRUCTION_STARTINGHEALTH  0.1
MethodPurpose
StartBuilding(CBaseEntity*)Transitions the object from placement to active construction
FinishedBuilding()Called when construction health reaches 100%
DetonateObject()Engineer-triggered self-destruct
DestroyObject()Silent cleanup (no explosion)
Killed(CTakeDamageInfo&)Handles death from enemy damage
OnWrenchHit(CTFPlayer*, CTFWrench*, Vector)Processes wrench repair and upgrade hits
CheckUpgradeOnHit(CTFPlayer*)Returns true if enough metal was contributed to level up
IsCarried()True when the Engineer is hauling the building
Objects accept entity I/O inputs for SetHealth, AddHealth, RemoveHealth, Enable, and Disable, all wired through DECLARE_DATADESC().

The three buildings

Sentry Gun

CObjectSentryguntf_obj_sentrygun.hMax health: 150 (mini: 100). Range: 1100 units (SENTRY_MAX_RANGE).Levels 1–3 defined as SENTRY_LEVEL_1/2/3. Level 3 adds rockets (FireRocket()). Networked ammo: m_iAmmoShells, m_iAmmoRockets.

Dispenser

CObjectDispensertf_obj_dispenser.hMax health: 150 (mini: 100). Proximity healing via CDispenserTouchTrigger — a CBaseTrigger that forwards StartTouch/EndTouch to the dispenser.Healing: GetHealRate(), DispenseAmmo(), DispenseMetal(). Separate RefillThink and DispenseThink callbacks.

Teleporter

CObjectTeleportertf_obj_teleporter.hMax health: 150. Two instances linked by type: TTYPE_ENTRANCE / TTYPE_EXIT. Partners found via FindMatch() and stored in m_hMatchingTeleporter.Networked state: m_iState, m_flRechargeTime, m_flCurrentRechargeDuration, m_iTimesUsed.

Construction and upgrade flow

1

Placement

StartPlacement(CTFPlayer*) validates position using IsPlacementPosValid() and VerifyCorner(). The object spawns with OBJECT_CONSTRUCTION_STARTINGHEALTH (0.1).
2

Building

Each wrench hit calls Construct(float flHealth) which advances construction health. BuildingThink() runs on a 0.1 s interval until FinishedBuilding() fires.
3

Upgrading

CheckUpgradeOnHit accumulates metal. When enough metal is deposited (via GetUpgradeMetalRequired()), StartUpgrading()FinishUpgrading() transitions the building to the next level and swaps the model.
4

Destruction

Damage flows through OnTakeDamage. When health reaches 0, Killed() is called. DetonateObject() produces an explosion; DestroyObject() performs a silent removal.

Hauling

When an Engineer picks up a building, IsCarried() returns true and IsDisabled() is forced true for the duration. The sentry overrides MakeCarriedObject(CTFPlayer*) to clear its current target and ammo via RemoveAllAmmo(). On placement, OnEndBeingCarried(CBaseEntity*) is called to restore state.
The SF_SENTRY_INFINITE_AMMO spawn flag is available for map-placed sentries and bypasses normal ammo depletion entirely.

Build docs developers (and LLMs) love