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.

CTFGameRules is TF2’s top-level game rules class. It inherits from CTeamplayRoundBasedRules (teamplayroundbased_gamerules.h), which provides the shared round state machine, respawn wave timing, stalemate logic, and team win tracking. CTFGameRules extends this base with TF-specific game type dispatch, holiday logic, MvM population management, and competitive extensions.

Inheritance chain

CTFGameRules
  : public CTeamplayRoundBasedRules     // game/shared/teamplayroundbased_gamerules.h
      : public CTeamplayRules
          : public CMultiplayRules

Round state machine

CTeamplayRoundBasedRules drives all round transitions via the gamerules_roundstate_t enum. Each state maps to a distinct phase in the match lifecycle.
// game/shared/teamplayroundbased_gamerules.h
enum gamerules_roundstate_t
{
    GR_STATE_INIT = 0,       // create teams
    GR_STATE_PREGAME,        // waiting for enough players
    GR_STATE_STARTGAME,      // about to spawn everyone
    GR_STATE_PREROUND,       // players spawned, frozen (setup phase)
    GR_STATE_RND_RUNNING,    // round is live
    GR_STATE_TEAM_WIN,       // a team has won the round
    GR_STATE_RESTART,        // manual restart, scores reset
    GR_STATE_STALEMATE,      // nobody won, restarting
    GR_STATE_GAME_OVER,      // match over, scoreboard shown
    GR_STATE_BONUS,          // post-round bonus state
    GR_STATE_BETWEEN_RNDS,   // awaiting next wave/round (used in MvM)
    GR_NUM_ROUND_STATES
};

Game types

CTFGameRules stores an ETFGameType network variable (m_nGameType) that controls which objective logic is active. The enum is defined in tf_shareddefs.h.
ValueEnumMode
0TF_GAMETYPE_UNDEFINEDUnknown / unset
1TF_GAMETYPE_CTFCapture the Flag
2TF_GAMETYPE_CPControl Points (5CP, A/D, KOTH)
3TF_GAMETYPE_ESCORTPayload / Payload Race
4TF_GAMETYPE_ARENAArena
5TF_GAMETYPE_MVMMann vs. Machine
6TF_GAMETYPE_RDRobot Destruction
7TF_GAMETYPE_PASSTIMEPASS Time
8TF_GAMETYPE_PDPlayer Destruction

Win conditions

Win reasons are encoded in the WINREASON_* enum and broadcast to clients when a round ends.
// game/shared/teamplayroundbased_gamerules.h
enum {
    WINREASON_NONE = 0,
    WINREASON_ALL_POINTS_CAPTURED,
    WINREASON_OPPONENTS_DEAD,
    WINREASON_FLAG_CAPTURE_LIMIT,
    WINREASON_DEFEND_UNTIL_TIME_LIMIT,
    WINREASON_STALEMATE,
    WINREASON_TIMELIMIT,
    WINREASON_WINLIMIT,
    WINREASON_WINDIFFLIMIT,
    WINREASON_RD_REACTOR_CAPTURED,   // Robot Destruction
    WINREASON_PD_POINTS,             // Player Destruction
    WINREASON_SCORED,
    WINREASON_STOPWATCH_WATCHING_ROUNDS,
    WINREASON_STOPWATCH_WATCHING_FINAL_ROUND,
};
WINREASON_DEFEND_UNTIL_TIME_LIMIT is used by Attack/Defense CP maps where the defending team wins by running down the round timer.

Round timer and stalemate

CTeamplayRoundBasedRules tracks a networked round timer via teamplay_round_timer.h. Relevant convars exposed server-side:
extern ConVar mp_respawnwavetime;     // seconds between respawn waves
extern ConVar mp_bonusroundtime;      // time after a round win before map change
extern ConVar mp_stalemate_timelimit; // overtime cap before stalemate declared
extern ConVar mp_stalemate_enable;
extern ConVar mp_winlimit;            // rounds needed to win the match
extern ConVar mp_maxrounds;
The GR_STATE_STALEMATE state is entered when the round timer expires and no team has fulfilled its win condition. In CTF maps, m_bOvertimeAllowedForCTF (proxy field) gates whether sudden-death overtime applies before calling stalemate.

Build docs developers (and LLMs) love