GameModeController - alexneargarder/Broforce-Docs GitHub Wiki

GameModeController

Table of Contents

Unity Lifecycle

Methods

private void Awake()

Unity Awake lifecycle method that initializes the GameModeController singleton, sets up player arrays, and configures initial game mode settings.


private void Start()

Unity Start lifecycle method that resets level state, adds mode-specific components (like RaceModeController), and clears deathmatch statistics.


private void Update()

Unity Update lifecycle method that handles exhibition mode timeout, monitors level completion conditions, manages victory timers, and processes input for debug commands.


Fields

public bool forcePlayLevel

Forces the level to play normally even if level editor is active. Used for testing levels in editor mode.


private static GameModeController instance

Singleton instance of the GameModeController. Provides global access to game mode management.


private float lastInputTimer

Timer tracking seconds since last player input in exhibition mode. Increments each frame and resets on any key press. When exceeding 150 seconds, automatically returns to join screen for exhibition builds.


public LevelEditorGUI levelEditor

Reference to the LevelEditorGUI component for managing level editing functionality.


private int maxPlayersJoined

Tracks the maximum number of players that have joined the current level. Used to determine if match should end when all players are eliminated in death match modes. Prevents immediate match end if only one player ever joined.


Game Mode Management

Methods

public static LevelResult GetLevelResult()

Gets the final result of the current level.

Returns:

  • LevelResult: The level result (Success, Fail, ForcedFail, or Unknown if level is not finished or instance is null).

public static bool IsHelicopterVictory()

Determines if the level ended with a helicopter victory (players successfully evacuated).

Returns:

  • bool: True if the level is finished and at least one player made it to the helicopter, false otherwise.

public static bool IsInHardMode()

Determines if the game is currently in Hard Mode based on campaign type and game state.

Returns:

  • bool: True if the game is in hard mode, false otherwise. Hard mode can be enabled through world map campaign settings, custom campaign options, or forced by map data.

public static bool IsLevelFinished()

Checks if the current level has been completed.

Returns:

  • bool: True if the level is finished (victory or defeat has been determined), false if the level is still in progress.

public static bool ShowStandardHUDS()

Determines whether standard HUD elements should be displayed based on the current game mode.

Returns:

  • bool: True if standard HUD should be shown (Campaign mode without brutality scoring), false for competitive modes or when showing brutality score.

Properties

public static bool AllowPlayerDropIn { get; set; }

Indicates whether players can join mid-game in the current game mode and conditions.


public static int deathMatchLives { get; set; }

Gets the number of lives each player has in Deathmatch mode.


public static GameMode GameMode { get; set; }

Gets or sets the current game mode.


public static GameModeController Instance { get; set; }

Gets the singleton instance of GameModeController.


public static bool IsDeathMatchMode { get; set; }

Gets whether the current game mode is Deathmatch.


public static bool IsHardcoreMode { get; set; }

Gets whether the game is in Hardcore mode (permadeath campaign mode).


public static bool SpawnBeforeCountdown { get; set; }

Determines whether players should spawn before the countdown starts based on the current game mode.


Fields

public static int broPlayer = -1

In Suicide Horde mode, indicates which player is currently playing as the Bro (cycles through players).


private static Campaign campaignBeforeBrodown = null

Stores the campaign reference that was active before entering a Bro-down, used to restore campaign context after tiebreaker.


protected static bool cheatsEnabled = false

Static flag indicating whether cheat functionality is enabled. When true, allows debug commands and special key combinations. Always returns true when running in Unity editor regardless of this field's value.


public static HeroType[] deathmatchHero = new HeroType[]

Stores the hero type selection for each player in Deathmatch mode. Initialized with HeroType.None for all 4 players.


private bool forceDraw

Forces a draw/tie outcome during match end determination. When true, forces the match to end in a tie regardless of actual player performance. Used for debugging or special scenarios where a draw result is required.


public static bool forceRestartOnDeathInHardcoreThisLevel = false

Forces a level restart on death in Hardcore mode for this specific level. Used by boss fights like Satan that require full restart.


private static GameMode gameModeBeforeBrodown = GameMode.NotSet

Stores the game mode that was active before entering a Bro-down tiebreaker, used to restore proper mode after tiebreaker.


public static bool[] isPlayerDoingBrodown = new bool[4]

Tracks which players are participating in a Bro-down tiebreaker round. Used when matches end in a draw.


private static int levelNumBeforeBrodown

Stores the level number that was active before entering a Bro-down, used to restore level progression after tiebreaker.


public static bool publishRun

Indicates whether the current campaign run is for publishing. When true, the game treats successful completion differently, redirecting back to level editor instead of normal victory screens. Used when testing custom campaigns before publishing.


public bool switchSilently

Controls whether level transitions display the level over screen. When true, suppresses the normal level completion UI and switches levels immediately. Used for seamless transitions during cutscenes or special sequences.


Level Flow & Transitions

Methods

public static string FinishCampaignFromCutscene(bool forceWorldMap)

Completes the current campaign from a cutscene, determining the appropriate next scene based on campaign type.

Parameters:

  • bool forceWorldMap: If true, forces return to world map regardless of campaign type

Returns:

  • string: The name of the scene to load next

public static bool HasEveryBodyVotedToSkip()

Checks if all active players have voted to skip the current level.

Returns:

  • bool: True if all playing players have voted to skip, false if any active player hasn't voted or no players are active.

public static bool InSwitchingScenesPhase()

Checks if the game is currently in the process of switching between levels or scenes.

Returns:

  • bool: True if currently switching levels, false otherwise

public static void LevelFinish(LevelResult result)

Initiates the level finish sequence with the specified result.

Parameters:

  • LevelResult result: The result of the level (Success, Fail, ForcedFail, or Unknown).

public void LevelFinishRPC(int finishedLevelNum, LevelResult result)

RPC method that finalizes the level completion across all clients.

Parameters:

  • int finishedLevelNum: The level number that finished (used to verify synchronization).
  • LevelResult result: The result of the level.

public static void LoadNextScene(GameState sceneAndGameState)

Loads the next scene immediately without transition effects. Used for quick scene changes.

Parameters:

  • GameState sceneAndGameState: The GameState object containing scene and game configuration to apply

public static void LoadNextSceneFade(GameState sceneAndGameState)

Loads the next scene with a fade transition effect. Used for smooth scene transitions.

Parameters:

  • GameState sceneAndGameState: The GameState object containing scene and game configuration to apply

public static void MakeFinishInstant()

Forces the level to finish immediately by setting the win timer to near zero.


private void OnDisable()

Unity callback when the component is disabled. Currently empty but provides hook for cleanup operations.


public void RequestHostRestartLevel()

Handles client requests to restart the level. Called via RPC when non-host players request a restart.


public static void RestartLevel()

Restarts the current level by reloading the active scene. Handles host/client logic for multiplayer compatibility.


public void ReturnToWorldMap()

Initiates a return to the world map scene, saving the scene transition in game state.


public static void SendReady()

Sends a ready signal from the local player to all other players, used for vote-to-skip functionality.


public static void SetSwitchDelay(float d)

Sets the delay before switching to the next level, allowing UI elements time to display.

Parameters:

  • float d: The delay in seconds before the level switch occurs

public void SwitchLevel()

Switches to the next level or scene, handling all necessary game state updates and synchronization.


private void VoteToSkipRPC(PID sender)

RPC method that registers a player's vote to skip the level.

Parameters:

  • PID sender: The PID of the player voting to skip.

Properties

public static bool CheatsEnabled { get; set; }

Gets or sets whether cheat codes are enabled. Always returns true in the Unity editor.


public static bool LevelFinished { get; set; }

Gets or sets whether the current level has been completed. Used to track level completion state.


Fields

protected float deathMatchRewardCounter

Timer controlling ammo box spawn frequency during death match reward phase. Increments each frame and spawns an ammo box every 2 seconds, then decrements by 3.5 to create periodic spawning. Only active when deathMatchRewarded is true.


protected bool deathMatchRewarded

Indicates whether the death match winner is currently receiving reward ammo boxes. When true, periodically spawns ammo boxes from the top of the screen. Becomes false when the winning player dies.


protected int deathMatchWinnerPlayerNum = -1

Player number (0-3) of the death match winner during reward phase. Set to -1 when no winner is determined. Used to check if winner is still alive to continue receiving rewards.


private string nextScene = string.Empty

The name of the next scene to load when transitioning levels. Empty string by default.


public static bool[] playersVotedToSkip = new bool[4]

Tracks which players have voted to skip the current level results screen. Reset on each level.


private bool resetWinsOnLevelSwitch

Controls whether player round wins are reset when switching levels. When true, calls ResetPlayerRoundWins() before switching to the next level. Used to start fresh scoring in new matches.


public static bool[] stillNeedToReady = new bool[4]

Array tracking which players (0-3) still need to ready up before level transition. Set for all playing players when waiting for ready state. Players signal ready through vote-to-skip mechanism, clearing their flag.


private bool switchingLevel

Indicates whether the game is currently in the process of switching levels/scenes.


private float switchLevelDelay = 1.5f

Time delay in seconds before switching to the next level. Defaults to 1.5 seconds.


private bool waitingForAllPlayersToReady

Indicates whether the game is waiting for all players to ready before switching levels. When true, level transition is delayed until all players in stillNeedToReady array have signaled ready.


Player Score Management

Methods

public static void AddPoint(int playernum)

Adds a round win point to the specified player's score.

Parameters:

  • int playernum: The player number (0-3) to award a point to

public static bool DoesPlayerNumDamage(int fromNum, int toNum)

Determines if damage should be applied between two player numbers based on the current game mode.

Parameters:

  • int fromNum: The player number dealing damage (negative values for enemies/environment)
  • int toNum: The player number receiving damage (negative values for enemies/environment)

Returns:

  • bool: True if damage should be applied, false if it should be prevented

public static int GetBrodownBroCount()

Gets the number of players currently participating in a Brodown tiebreaker round.

Returns:

  • int: The count of players marked for Brodown participation

public static float GetExplosionRunFailM()

Calculates the failure rate in Explosion Run mode as a ratio of fails to total attempts.

Returns:

  • float: The failure rate as a decimal (0.0 to 1.0), or 0 if no attempts

public static float GetExplosionRunLevelFails()

Gets the number of consecutive failures in the current Explosion Run session.

Returns:

  • float: The count of recent consecutive failures

public static int GetExplosionRunTotalAttempts()

Gets the total number of Explosion Run attempts in the current session.

Returns:

  • int: The total attempt count as an integer

public static float GetExplosionRunWinsInARow()

Gets the current win streak in Explosion Run mode.

Returns:

  • float: The number of consecutive Explosion Run victories

public static int GetPlayerRoundWins(int playerNum)

Gets the number of round wins for a specific player.

Parameters:

  • int playerNum: The player number (0-3).

Returns:

  • int: The number of rounds won by the player, or 0 if invalid player number.

public static int GetWinnerNum()

Gets the player number of the current deathmatch round winner.

Returns:

  • int: The winning player number (0-3), or -1 if no winner

public static bool IsMatchLeader(int playerNum)

Determines if a player is currently leading the match in round wins.

Parameters:

  • int playerNum: The player number (0-3) to check.

Returns:

  • bool: True if the player has the most round wins (or is tied for most), false otherwise.

public static void ResetPlayerRoundWins(int playerNum)

Resets all players' round win counts to zero.


public static void ResetPlayerRoundWins(int playerNum)

Resets a specific player's round win count to zero.

Parameters:

  • int playerNum: The player number (0-3) to reset.

public static void SetupIntroActions()

Sets up countdown timers and intro sequences based on the current game mode.


Fields

public static int campaignLevelFailCount = 0

Tracks consecutive failures on the current campaign level. Used to trigger celebration on eventual success after multiple failures.


private static int explosionRunFailCount = 0

Static counter tracking consecutive failures in Explosion Run mode for the current level. Increments on failure, resets to 0 on success. Used to calculate fail rate statistics.


private static float explosionRunFailTotalFails = 0f

Static counter tracking total Explosion Run failures across all sessions. Increments by 1 for each failure. Multiplied by 0.8 when attempts over 4 to decay old data. Used with explosionRunTotalAttempts to calculate fail rate.


private static float explosionRunTotalAttempts = 0f

Static counter tracking total Explosion Run attempts across all sessions. Increments by 1 for each attempt. Multiplied by 0.8 when over 4 attempts to decay old data. Used to calculate overall success/fail ratio.


private static int explosionRunWinsInARow = 0

Static counter tracking consecutive Explosion Run victories. Increments on win, resets to 0 on failure. Displayed to players when reaching streaks of 3 or more wins.


public static int lastPlayerToWin = -1

The player number (0-3) of the last player to win a round. -1 if no winner yet.


protected static int[] playerRoundWins

Array tracking the number of round wins for each player in multi-round game modes.


Internal Game Flow

Methods

private void DetermineLevelOutcome()

Determines what happens after level completion based on game mode, player performance, and level results.


public static bool InRewardPhase()

Checks if the game is currently in the deathmatch reward phase where ammo boxes drop from the sky.

Returns:

  • bool: True if in the reward phase, false otherwise

private static void LoadSceneCore(GameState sceneAndGameState)

Core scene loading logic shared by LoadNextScene and LoadNextSceneFade. Handles game state setup.

Parameters:

  • GameState sceneAndGameState: The GameState to apply before loading

public void ReceiveStatsFromMaster(byte[] stats)

Receives and applies synchronized statistics data from the host player.

Parameters:

  • byte[] stats: Serialized statistics data from the host

private void ResetForNextLevel()

Resets internal timers and flags in preparation for the next level.


public void SyncStats()

Synchronizes statistics from the host to all other players in multiplayer sessions.


private void WaitForAllPlayersToReadyBeforeSwitch()

Initiates waiting for all players to ready up before switching levels in multiplayer modes.


Fields

protected float lastDebugLivesTime

Unused timer field likely intended for debug display of player lives. Currently not referenced anywhere in the codebase.


protected bool levelFinished

Indicates whether the current level has been completed (win/loss determined).


private bool levelHasStarted

Tracks whether the current level has officially started gameplay (after countdown and initial setup).


protected LevelResult levelResult

The outcome of the current level (Success, Fail, ForcedFail, or Unknown).


protected float levelStartCounter = 2f

Countdown timer at level start before gameplay begins. Defaults to 2 seconds.


protected float winTimer = 2f

Countdown timer after level completion before transitioning to next scene. Defaults to 2 seconds.