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.

Mann vs. Machine runs as TF_GAMETYPE_MVM within CTFGameRules. Its core systems live under game/server/tf/player_vs_environment/. A popfile (KeyValues text) is parsed at level load to define all waves, sub-waves, robot types, and currency budgets. The round state machine uses GR_STATE_BETWEEN_RNDS between waves and GR_STATE_RND_RUNNING during active robot pushes.

System components

CPopulationManager

Parses the .pop popfile, owns the wave list, and drives wave start/end transitions. Defined in tf_population_manager.h.

tf_populators / tf_populator_spawners

WaveSpawnPopulator and related classes read per-wave spawn definitions and schedule robot spawns at nav mesh spawn points.

CTFTankBoss

The tank enemy (tf_tank_boss.cpp/h). Follows a path to the bomb hole; damage tracking and death logic are separate from normal bot behavior.

CTFBaseBoss / boss_alpha

Base class for giant/boss robots (tf_base_boss.h). boss_alpha/ holds the Merasmus/Monoculus boss logic. monster_resource replicates boss health to clients.

CMannVsMachineLogic

Map entity (tf_mann_vs_machine_logic.cpp) that wires MvM-specific map I/O: bomb deployment zones, gate, and alarm triggers.

CUpgrades

Server-side upgrade shop handler (tf_upgrades.cpp/h). Validates purchases, applies attribute modifiers to player items, and persists upgrade state across waves.

Wave system

The popfile defines a tree of Wave → WaveSpawn → TFBot entries. CPopulationManager iterates this list each wave, handing spawn tasks to tf_populator_spawners.
// game/server/tf/player_vs_environment/tf_population_manager.h
class CPopulationManager
{
    // called by CTFGameRules on round start
    bool Initialize( void );
    void StartCurrentWave( void );
    void WaveEnd( bool bSuccess );

    // popfile name replicated through CTFObjectiveResource
    // m_iszMvMPopfileName / SetMvMPopfileName()
};

Robot types

Three enemy categories are tracked by eMvMEnemyTypes in tf_mann_vs_machine_stats.h:
enum eMvMEnemyTypes
{
    kMvMEnemy_Bot,    // standard robot
    kMvMEnemy_Giant,  // giant robot (oversized, high HP, slower)
    kMvMEnemy_Tank    // CTFTankBoss, path-following bomb carrier
};
Giant robots are normal CTFBot instances with scaled attributes. Boss-tier enemies (e.g. Merasmus) use CTFBaseBoss and replicate health through monster_resource.

Currency and upgrades

When robots are killed they drop currency packs. Collected currency is tracked in CTFObjectiveResource::m_nMvMWorldMoney (networked). Between waves, players spend currency at the upgrade shop.
// game/shared/tf/tf_upgrades_shared.h
class CMannVsMachineUpgrades
{
    char  szAttrib[ MAX_ATTRIBUTE_DESCRIPTION_LENGTH ];
    char  szIcon[ MAX_PATH ];
    float flIncrement;   // stat gain per purchase
    float flCap;         // maximum allowed value
    int   nCost;         // currency cost per step
    int   nUIGroup;      // shop UI grouping
    int   nTier;         // mutually exclusive within same tier
};
CMannVsMachineUpgradeManager::LoadUpgradesFile() reads items_game.txt upgrade blocks at level init. GetUpgradeStepData() computes the player’s current step and whether they are over the cap for a given weapon slot and upgrade index.

Stats tracking

CMannVsMachineStats (shared, tf_mann_vs_machine_stats.h) records per-wave and per-player events and syncs them to clients using eMannVsMachineEvent:
enum eMannVsMachineEvent
{
    kMVMEvent_Player_Points,
    kMVMEvent_Player_Death,
    kMVMEvent_Player_PickedUpCredits,
    kMVMEvent_Player_BoughtInstantRespawn,
    kMVMEvent_Player_BoughtUpgrade,
    kMVMEvent_Player_ActiveUpgrades,
};
CMannVsMachineWaveStats aggregates nCreditsDropped and nCreditsAcquired per wave, which drive the end-of-wave summary panel.
Upgrade state is not automatically reset between maps. CUpgrades must be explicitly reset via InputResetPlayerUpgrades when the map or mission changes.

Build docs developers (and LLMs) love