Player12
An open source football management simulator
Loading...
Searching...
No Matches
Competitions Namespace Reference

Domestic competitions: league pyramids, cups, knockout resolution and promotion/relegation. More...

Classes

struct  CupDraw
 A cup round that has been drawn, as the calendar holds it. More...
 
struct  CupRound
 
struct  CupStatus
 
struct  KnockoutResolution
 
struct  LeagueMovement
 
struct  ShootoutResult
 

Functions

uint32_t mixSeed (uint32_t a, uint32_t b, uint32_t c)
 
LeagueID rootLeague (const GameData &gamedata, LeagueID league_id)
 
uint8_t leagueTier (const GameData &gamedata, LeagueID league_id)
 
std::vector< LeagueID > countryRoots (const GameData &gamedata)
 
std::vector< LeagueID > countryLeagues (const GameData &gamedata, LeagueID root)
 
std::vector< TeamID > cupEntrants (const GameData &gamedata, LeagueID root)
 
std::string cupName (const GameData &gamedata, LeagueID root)
 
std::string leagueName (const League &league)
 
std::string leagueNameArg (const League &league)
 
uint8_t cupRoundCount (size_t entrants)
 
const char * cupRoundLabelKey (uint8_t stage, uint8_t total_rounds)
 
CupStatus cupStatus (const Calendar &calendar, const GameData &gamedata, LeagueID root)
 
void scheduleCupFirstRounds (Calendar &calendar, const GameData &gamedata, uint16_t season_year)
 Schedules round 1 of every domestic cup.
 
size_t drawPendingCupRounds (Calendar &calendar, const GameData &gamedata, uint16_t season_year, const GameDateValue &today)
 Draws the next round of every cup whose latest round is complete.
 
std::optional< CupDraw > cupDraw (const Calendar &calendar, const GameData &gamedata, LeagueID root, uint8_t stage)
 Read-only view of a drawn round of the cup of root (nullopt when that round has not been drawn). Never changes the calendar.
 
float penaltyConversionProbability (float shooting, float goalkeeping)
 
ShootoutResult simulateShootout (const std::vector< float > &home_takers, const std::vector< float > &away_takers, std::mt19937 &rng)
 Best-of-five shootout with early finish, then sudden death.
 
KnockoutResolution resolveDrawnKnockout (const Team &home, const Team &away, const StatsConfig &stats_config, uint32_t seed)
 
std::vector< LeagueMovement > computeLeagueMovements (const GameData &gamedata, const std::unordered_map< LeagueID, std::vector< StandingRow > > &standings)
 Swaps the bottom clubs of each parent league with the top clubs of its child division(s), using final standings.
 
void applyLeagueMovements (GameData &gamedata, const std::vector< LeagueMovement > &movements)
 

Variables

constexpr size_t PROMOTION_SLOTS = 3
 

Detailed Description

Domestic competitions: league pyramids, cups, knockout resolution and promotion/relegation.

A "country" is a pyramid rooted at a league without a parent league; every league whose parent chain reaches the root belongs to it. Each country has one domestic cup whose ID is the root league ID (with MatchType::CUP).

Function Documentation

◆ applyLeagueMovements()

void Competitions::applyLeagueMovements ( GameData &  gamedata,
const std::vector< LeagueMovement > &  movements 
)

Moves the teams between leagues (team league IDs and league rosters).

◆ computeLeagueMovements()

std::vector< Competitions::LeagueMovement > Competitions::computeLeagueMovements ( const GameData &  gamedata,
const std::unordered_map< LeagueID, std::vector< StandingRow > > &  standings 
)

Swaps the bottom clubs of each parent league with the top clubs of its child division(s), using final standings.

◆ countryLeagues()

std::vector< LeagueID > Competitions::countryLeagues ( const GameData &  gamedata,
LeagueID  root 
)

All leagues of a country ordered by tier then ID.

◆ countryRoots()

std::vector< LeagueID > Competitions::countryRoots ( const GameData &  gamedata)

Root league IDs (one per country), ascending.

◆ cupDraw()

std::optional< Competitions::CupDraw > Competitions::cupDraw ( const Calendar &  calendar,
const GameData &  gamedata,
LeagueID  root,
uint8_t  stage 
)

Read-only view of a drawn round of the cup of root (nullopt when that round has not been drawn). Never changes the calendar.

◆ cupEntrants()

std::vector< TeamID > Competitions::cupEntrants ( const GameData &  gamedata,
LeagueID  root 
)

Every club of the country's pyramid.

◆ cupName()

std::string Competitions::cupName ( const GameData &  gamedata,
LeagueID  root 
)

Cup name in the current language: the CUP_NAME_<LEAGUE NAME> key of the root league (e.g. CUP_NAME_ITALIAN_LEAGUE) when the language has one, otherwise built from the data pack's league name ("X League" -> "X Cup").

◆ cupRoundCount()

uint8_t Competitions::cupRoundCount ( size_t  entrants)

Knockout rounds needed so that exactly one team remains.

◆ cupRoundLabelKey()

const char * Competitions::cupRoundLabelKey ( uint8_t  stage,
uint8_t  total_rounds 
)

Language key naming a cup round (final, semi-final, ...).

◆ cupStatus()

Competitions::CupStatus Competitions::cupStatus ( const Calendar &  calendar,
const GameData &  gamedata,
LeagueID  root 
)

◆ drawPendingCupRounds()

size_t Competitions::drawPendingCupRounds ( Calendar &  calendar,
const GameData &  gamedata,
uint16_t  season_year,
const GameDateValue &  today 
)

Draws the next round of every cup whose latest round is complete.

Returns
Number of fixtures added to the calendar.

◆ leagueName()

std::string Competitions::leagueName ( const League &  league)

League name in the current language: the LEAGUE_NAME_<LEAGUE NAME> key (e.g. LEAGUE_NAME_ITALIAN_LEAGUE) when the language has one, otherwise the data pack's name, so custom packs keep their own names.

◆ leagueNameArg()

std::string Competitions::leagueNameArg ( const League &  league)

Inbox argument naming league ("@LEAGUE_NAME_..." when translated).

◆ leagueTier()

uint8_t Competitions::leagueTier ( const GameData &  gamedata,
LeagueID  league_id 
)

1 for a top division, 2 for the division below, ...

◆ mixSeed()

uint32_t Competitions::mixSeed ( uint32_t  a,
uint32_t  b,
uint32_t  c 
)

Deterministic seed mixing (e.g. season year, competition, round).

◆ penaltyConversionProbability()

float Competitions::penaltyConversionProbability ( float  shooting,
float  goalkeeping 
)

Conversion chance of one kick (~75% for average taker and keeper).

◆ resolveDrawnKnockout()

Competitions::KnockoutResolution Competitions::resolveDrawnKnockout ( const Team &  home,
const Team &  away,
const StatsConfig &  stats_config,
uint32_t  seed 
)

Extra time (30 minutes) and, if still level, penalties.

◆ rootLeague()

LeagueID Competitions::rootLeague ( const GameData &  gamedata,
LeagueID  league_id 
)

Top league of the pyramid containing league_id.

◆ scheduleCupFirstRounds()

void Competitions::scheduleCupFirstRounds ( Calendar &  calendar,
const GameData &  gamedata,
uint16_t  season_year 
)

Schedules round 1 of every domestic cup.

When the entrant count is not a power of two only the lowest-tier clubs play a preliminary round; everybody else receives a bye to round 2. Midweek rounds are spread from Tuesday to Thursday: each tie takes the day that best rests both clubs, then the quietest.

◆ simulateShootout()

Competitions::ShootoutResult Competitions::simulateShootout ( const std::vector< float > &  home_takers,
const std::vector< float > &  away_takers,
std::mt19937 &  rng 
)

Best-of-five shootout with early finish, then sudden death.

Parameters
home_takersConversion probabilities of the home kickers in order.
away_takersConversion probabilities of the away kickers in order.

Variable Documentation

◆ PROMOTION_SLOTS

constexpr size_t Competitions::PROMOTION_SLOTS = 3
constexpr

Teams promoted/relegated between two linked divisions of 20 teams.