Player12
An open source football management simulator
Loading...
Searching...
No Matches
CompetitionManager Class Reference

Owns the result pipeline of all competitions. More...

#include <competition_manager.h>

Classes

struct  LineupSwap
 

Public Member Functions

 CompetitionManager (std::shared_ptr< GameData > gamedata, std::shared_ptr< DatabaseConnection > db_conn)
 
void load (Calendar &calendar, uint16_t season)
 
void save () const
 
void onSaved ()
 
void recordResult (const Match &match, MatchReport report)
 
void afterMatchday (Calendar &calendar, const GameDateValue &today)
 
void startContinentalSeason (const GameDateValue &today)
 
const ContinentalCompetitions & getContinental () const
 
ContinentalCompetitions & getContinental ()
 
void closeSeason (const Calendar &calendar, uint16_t season, uint16_t start_year)
 Records the season history and applies promotion/relegation.
 
std::vector< LineupSwap > benchSuspendedPlayers (const Match &match)
 
void restoreLineups (const std::vector< LineupSwap > &swaps)
 
void setCurrentSeason (uint16_t season)
 
std::optional< MatchRules::Knockout > knockoutRules (const Calendar &calendar, const Match &match) const
 
std::vector< StandingRow > getStandings (const Calendar &calendar, LeagueID league_id) const
 
std::vector< LeagueID > getCupIds () const
 
std::optional< Competitions::CupStatus > getCupStatus (const Calendar &calendar, LeagueID cup_id) const
 
std::optional< MatchReport > getMatchReport (const GameDateValue &date, TeamID home_id, TeamID away_id) const
 
const std::vector< SeasonHistoryEntry > & getSeasonHistory () const
 
std::vector< PlayerSeasonStats > getTopScorers (MatchType competition_type, LeagueID competition_id, size_t limit) const
 
std::vector< PlayerSeasonStats > getPlayerSeasonStats (PlayerID player_id) const
 
std::vector< PlayerSeasonStats > getPlayerCareer (PlayerID player_id) const
 
const Discipline & getDiscipline () const
 

Private Types

using FixtureKey = std::tuple< GameDateValue, TeamID, TeamID >
 

Private Member Functions

void refreshLeaguePoints (const Calendar &calendar, LeagueID league_id)
 
std::vector< TeamID > competitionTeams (MatchType competition_type, LeagueID competition_id) const
 

Private Attributes

std::shared_ptr< GameData > gamedata
 
std::shared_ptr< DatabaseConnection > db_conn
 
uint16_t current_season = 1
 
std::map< FixtureKey, MatchReport > pending_reports
 
PlayerSeasonTable player_stats
 
std::set< LeagueID > dirty_leagues
 
std::vector< SeasonHistoryEntry > season_history
 
Discipline discipline
 
ContinentalCompetitions continental
 
std::vector< FixtureKey > pending_deciders
 
bool history_dirty = false
 

Detailed Description

Owns the result pipeline of all competitions.

Stores the structured report of every played fixture, aggregates player season statistics, keeps league points in sync with the fixture-derived tables, draws cup rounds and closes seasons (history, promotion and relegation). Game forwards its lifecycle events here.

Member Typedef Documentation

◆ FixtureKey

Constructor & Destructor Documentation

◆ CompetitionManager()

CompetitionManager::CompetitionManager ( std::shared_ptr< GameData >  gamedata,
std::shared_ptr< DatabaseConnection >  db_conn 
)

Member Function Documentation

◆ afterMatchday()

void CompetitionManager::afterMatchday ( Calendar &  calendar,
const GameDateValue &  today 
)

Refreshes league points, draws cup rounds that became due and runs the continental competitions (draws, knockout rounds, and a decider recorded level from a score alone settled by extra time).

◆ benchSuspendedPlayers()

std::vector< CompetitionManager::LineupSwap > CompetitionManager::benchSuspendedPlayers ( const Match &  match)

Temporarily replaces suspended starters of both teams with eligible reserves for a simulated match; undo with restoreLineups().

◆ closeSeason()

void CompetitionManager::closeSeason ( const Calendar &  calendar,
uint16_t  season,
uint16_t  start_year 
)

Records the season history and applies promotion/relegation.

Parameters
seasonNumber of the season that ends.
start_yearCalendar year that season started in.

◆ competitionTeams()

std::vector< TeamID > CompetitionManager::competitionTeams ( MatchType  competition_type,
LeagueID  competition_id 
) const
private

◆ getContinental() [1/2]

ContinentalCompetitions & CompetitionManager::getContinental ( )
inline

◆ getContinental() [2/2]

const ContinentalCompetitions & CompetitionManager::getContinental ( ) const
inline

Continental club competitions (seasons, tables, coefficients).

◆ getCupIds()

std::vector< LeagueID > CompetitionManager::getCupIds ( ) const

One domestic cup per country, identified by its root league ID.

◆ getCupStatus()

std::optional< Competitions::CupStatus > CompetitionManager::getCupStatus ( const Calendar &  calendar,
LeagueID  cup_id 
) const

◆ getDiscipline()

const Discipline & CompetitionManager::getDiscipline ( ) const
inline

◆ getMatchReport()

std::optional< MatchReport > CompetitionManager::getMatchReport ( const GameDateValue &  date,
TeamID  home_id,
TeamID  away_id 
) const

◆ getPlayerCareer()

std::vector< PlayerSeasonStats > CompetitionManager::getPlayerCareer ( PlayerID  player_id) const

Every stored season row of a player, oldest first.

◆ getPlayerSeasonStats()

std::vector< PlayerSeasonStats > CompetitionManager::getPlayerSeasonStats ( PlayerID  player_id) const

Current-season rows of a player (one per team and competition).

◆ getSeasonHistory()

const std::vector< SeasonHistoryEntry > & CompetitionManager::getSeasonHistory ( ) const
inline

◆ getStandings()

std::vector< StandingRow > CompetitionManager::getStandings ( const Calendar &  calendar,
LeagueID  league_id 
) const

◆ getTopScorers()

std::vector< PlayerSeasonStats > CompetitionManager::getTopScorers ( MatchType  competition_type,
LeagueID  competition_id,
size_t  limit 
) const

League (or cup, with MatchType::CUP and a root league ID) scorers.

◆ knockoutRules()

std::optional< MatchRules::Knockout > CompetitionManager::knockoutRules ( const Calendar &  calendar,
const Match &  match 
) const

How a level score settles match, for the engine that plays it: a cup tie and a continental final go to extra time and penalties, a second leg too when level on aggregate (goals of the first leg included). nullopt for matches that may end drawn.

◆ load()

void CompetitionManager::load ( Calendar &  calendar,
uint16_t  season 
)

Migrates older saves and restores the state of the loaded season.

◆ onSaved()

void CompetitionManager::onSaved ( )

Drops buffers that are now persisted (call after a commit).

◆ recordResult()

void CompetitionManager::recordResult ( const Match &  match,
MatchReport  report 
)

Stores the report of a played match and aggregates its statistics.

◆ refreshLeaguePoints()

void CompetitionManager::refreshLeaguePoints ( const Calendar &  calendar,
LeagueID  league_id 
)
private

◆ restoreLineups()

void CompetitionManager::restoreLineups ( const std::vector< LineupSwap > &  swaps)

◆ save()

void CompetitionManager::save ( ) const

Persists pending reports, stats, history and memberships. Must run inside the caller's transaction.

◆ setCurrentSeason()

void CompetitionManager::setCurrentSeason ( uint16_t  season)
inline

Sets the season number used for new reports and statistics.

◆ startContinentalSeason()

void CompetitionManager::startContinentalSeason ( const GameDateValue &  today)

Enters the continental clubs of the season containing today (after the calendar has been generated); no-op when already done or too late.

Member Data Documentation

◆ continental

ContinentalCompetitions CompetitionManager::continental
private

◆ current_season

uint16_t CompetitionManager::current_season = 1
private

◆ db_conn

std::shared_ptr<DatabaseConnection> CompetitionManager::db_conn
private

◆ dirty_leagues

std::set<LeagueID> CompetitionManager::dirty_leagues
private

◆ discipline

Discipline CompetitionManager::discipline
private

◆ gamedata

std::shared_ptr<GameData> CompetitionManager::gamedata
private

◆ history_dirty

bool CompetitionManager::history_dirty = false
private

◆ pending_deciders

std::vector<FixtureKey> CompetitionManager::pending_deciders
private

Continental second legs and finals recorded since the last matchday processing (extra time when the aggregate is level).

◆ pending_reports

std::map<FixtureKey, MatchReport> CompetitionManager::pending_reports
private

◆ player_stats

PlayerSeasonTable CompetitionManager::player_stats
private

◆ season_history

std::vector<SeasonHistoryEntry> CompetitionManager::season_history
private

The documentation for this class was generated from the following files: