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

Seasons, draws, knockouts, prize money and coefficients of the continental club competitions. More...

#include <continental.h>

Classes

struct  AssociationCoefficient
 
struct  DrawEvent
 
struct  Entrant
 
struct  Season
 
struct  Tie
 
struct  TieScore
 

Public Types

using NewsSink = std::function< void(InboxMessage, const std::vector< TeamID > &, bool)>
 

Public Member Functions

 ContinentalCompetitions (std::shared_ptr< GameData > gamedata)
 
void setNewsSink (NewsSink sink)
 
void startSeason (uint16_t season_year, const GameDateValue &today)
 Enters the qualified clubs of season_year and plans the league-phase draw. Uses the qualification computed by closeSeason() or, without one (first season, older saves), the clubs' reputation. Nothing happens if the season already exists or if today is too late to play the league phase.
 
void afterMatchday (Calendar &calendar, const GameDateValue &today)
 
void onResult (const Match &match)
 
bool needsExtraTime (const Calendar &calendar, const Match &match) const
 
std::optional< int > deciderLead (const Calendar &calendar, const Match &match) const
 
std::optional< std::pair< int, int > > deciderAggregate (const Calendar &calendar, const Match &match) const
 
bool resolveDecider (const Calendar &calendar, Match &match)
 
void closeSeason (const Calendar &calendar, uint16_t season_year, const std::unordered_map< LeagueID, std::vector< StandingRow > > &tables, const std::map< LeagueID, TeamID > &cup_winners)
 Season end: updates coefficients from the season's matches and computes the clubs qualified for the next season.
 
void refresh (const Calendar &calendar)
 
const std::vector< Season > & getSeasons () const
 
const Season * getSeason (LeagueID competition_id) const
 
const std::vector< StandingRow > & getTable (LeagueID competition_id) const
 
TieScore tieScore (const Calendar &calendar, const Season &season, const Tie &tie) const
 
std::vector< AssociationCoefficient > associationRanking (Continental::Continent continent) const
 
double clubCoefficient (TeamID team_id) const
 
std::optional< LeagueID > competitionOf (TeamID team_id) const
 
const std::map< LeagueID, std::vector< Entrant > > & getQualified () const
 
void load (const DatabaseConnection &db)
 
void save (const DatabaseConnection &db) const
 
std::string serialize () const
 
void deserialize (const std::string &data)
 

Static Public Attributes

static constexpr size_t COEFFICIENT_SEASONS = 5
 

Private Member Functions

Season * findSeason (LeagueID competition_id)
 
std::vector< Entrant > qualifyByReputation (const Continental::CompetitionRules &rules, std::vector< TeamID > &taken) const
 
std::vector< Entrant > qualify (const Continental::CompetitionRules &rules, const std::unordered_map< LeagueID, std::vector< StandingRow > > &tables, const std::map< LeagueID, TeamID > &cup_winners, std::vector< TeamID > &taken) const
 
std::vector< LeagueID > rankedAssociations (Continental::Continent continent) const
 
AssociationCoefficient associationCoefficient (LeagueID association) const
 
std::vector< TeamID > topDivisionClubs (LeagueID association) const
 
bool isLowestTier (const Continental::CompetitionRules &rules) const
 
void assignPots (Season &season) const
 
void drawLeaguePhase (Calendar &calendar, Season &season, const GameDateValue &today)
 
void advanceKnockouts (Calendar &calendar, Season &season, const GameDateValue &today)
 
void drawKnockoutRound (Calendar &calendar, Season &season, Continental::Round round, std::vector< TeamID > seeded, std::vector< TeamID > unseeded, const GameDateValue &today)
 
void payPrize (TeamID team_id, const GameDateValue &date, int64_t amount)
 
void postNews (const GameDateValue &date, std::string title_key, std::string body_key, std::vector< std::string > args, const std::vector< TeamID > &involved, bool headline) const
 
std::vector< const Match * > competitionMatches (const Calendar &calendar, LeagueID competition_id) const
 
const Match * findLeg (const Calendar &calendar, LeagueID competition_id, uint8_t stage, TeamID home_id, TeamID away_id) const
 
std::string teamName (TeamID team_id) const
 

Private Attributes

std::shared_ptr< GameData > gamedata
 
NewsSink news
 
std::vector< Season > seasons
 
std::map< LeagueID, AssociationCoefficient > associations
 
std::map< TeamID, std::array< double, COEFFICIENT_SEASONS > > clubs
 
uint16_t last_closed_season = 0
 
bool results_dirty = true
 
std::map< LeagueID, std::vector< Entrant > > qualified
 
uint16_t qualified_season = 0
 
std::map< LeagueID, std::vector< StandingRow > > tables
 

Detailed Description

Seasons, draws, knockouts, prize money and coefficients of the continental club competitions.

Qualification comes from the final domestic tables (and cup winners) of the previous season, association places from the association coefficient ranking (club results of the last five seasons divided by the clubs entered). The league-phase draw is an event in late August; each knockout draw happens the day the previous round is complete.

Member Typedef Documentation

◆ NewsSink

using ContinentalCompetitions::NewsSink = std::function<void(InboxMessage, const std::vector<TeamID>&, bool)>

Message, clubs it concerns, and whether it is general news.

Constructor & Destructor Documentation

◆ ContinentalCompetitions()

ContinentalCompetitions::ContinentalCompetitions ( std::shared_ptr< GameData >  gamedata)
explicit

Member Function Documentation

◆ advanceKnockouts()

void ContinentalCompetitions::advanceKnockouts ( Calendar &  calendar,
Season &  season,
const GameDateValue &  today 
)
private

◆ afterMatchday()

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

Draws that are due and knockout progress; call once per day.

◆ assignPots()

void ContinentalCompetitions::assignPots ( Season &  season) const
private

◆ associationCoefficient()

ContinentalCompetitions::AssociationCoefficient ContinentalCompetitions::associationCoefficient ( LeagueID  association) const
private

◆ associationRanking()

std::vector< ContinentalCompetitions::AssociationCoefficient > ContinentalCompetitions::associationRanking ( Continental::Continent  continent) const

Associations of a continent, best coefficient first.

◆ closeSeason()

void ContinentalCompetitions::closeSeason ( const Calendar &  calendar,
uint16_t  season_year,
const std::unordered_map< LeagueID, std::vector< StandingRow > > &  tables,
const std::map< LeagueID, TeamID > &  cup_winners 
)

Season end: updates coefficients from the season's matches and computes the clubs qualified for the next season.

Parameters
tablesFinal tables of the top divisions (1st first).
cup_winnersDomestic cup winner per association (top league).

◆ clubCoefficient()

double ContinentalCompetitions::clubCoefficient ( TeamID  team_id) const

Club coefficient: own points of five seasons or 20% of its association's coefficient, whichever is higher.

◆ competitionMatches()

std::vector< const Match * > ContinentalCompetitions::competitionMatches ( const Calendar &  calendar,
LeagueID  competition_id 
) const
private

◆ competitionOf()

std::optional< LeagueID > ContinentalCompetitions::competitionOf ( TeamID  team_id) const

Competition a club plays this season, if any.

◆ deciderAggregate()

std::optional< std::pair< int, int > > ContinentalCompetitions::deciderAggregate ( const Calendar &  calendar,
const Match &  match 
) const

For a deciding match: the goals this match's home and away sides scored in the earlier leg ({0, 0} for a final); nullopt for any other match.

◆ deciderLead()

std::optional< int > ContinentalCompetitions::deciderLead ( const Calendar &  calendar,
const Match &  match 
) const

For a deciding match (a final, or a second leg whose first leg is played): the home side's aggregate lead from the earlier leg (0 for a final). The tie goes to extra time when the home side's goals plus this lead equal the away side's goals. nullopt for any other match.

◆ deserialize()

void ContinentalCompetitions::deserialize ( const std::string &  data)

◆ drawKnockoutRound()

void ContinentalCompetitions::drawKnockoutRound ( Calendar &  calendar,
Season &  season,
Continental::Round  round,
std::vector< TeamID >  seeded,
std::vector< TeamID >  unseeded,
const GameDateValue &  today 
)
private

◆ drawLeaguePhase()

void ContinentalCompetitions::drawLeaguePhase ( Calendar &  calendar,
Season &  season,
const GameDateValue &  today 
)
private

◆ findLeg()

const Match * ContinentalCompetitions::findLeg ( const Calendar &  calendar,
LeagueID  competition_id,
uint8_t  stage,
TeamID  home_id,
TeamID  away_id 
) const
private

◆ findSeason()

ContinentalCompetitions::Season * ContinentalCompetitions::findSeason ( LeagueID  competition_id)
private

◆ getQualified()

const std::map< LeagueID, std::vector< Entrant > > & ContinentalCompetitions::getQualified ( ) const
inline

Clubs qualified for next season (after closeSeason()).

◆ getSeason()

const ContinentalCompetitions::Season * ContinentalCompetitions::getSeason ( LeagueID  competition_id) const

◆ getSeasons()

const std::vector< Season > & ContinentalCompetitions::getSeasons ( ) const
inline

◆ getTable()

const std::vector< StandingRow > & ContinentalCompetitions::getTable ( LeagueID  competition_id) const

Cached league-phase table (empty before the draw).

◆ isLowestTier()

bool ContinentalCompetitions::isLowestTier ( const Continental::CompetitionRules &  rules) const
private

◆ load()

void ContinentalCompetitions::load ( const DatabaseConnection &  db)

◆ needsExtraTime()

bool ContinentalCompetitions::needsExtraTime ( const Calendar &  calendar,
const Match &  match 
) const

A second leg (or final) whose aggregate is level after 90 minutes.

◆ onResult()

void ContinentalCompetitions::onResult ( const Match &  match)

Prize money of a league-phase result; call once per played match.

◆ payPrize()

void ContinentalCompetitions::payPrize ( TeamID  team_id,
const GameDateValue &  date,
int64_t  amount 
)
private

◆ postNews()

void ContinentalCompetitions::postNews ( const GameDateValue &  date,
std::string  title_key,
std::string  body_key,
std::vector< std::string >  args,
const std::vector< TeamID > &  involved,
bool  headline 
) const
private

◆ qualify()

std::vector< ContinentalCompetitions::Entrant > ContinentalCompetitions::qualify ( const Continental::CompetitionRules &  rules,
const std::unordered_map< LeagueID, std::vector< StandingRow > > &  tables,
const std::map< LeagueID, TeamID > &  cup_winners,
std::vector< TeamID > &  taken 
) const
private

◆ qualifyByReputation()

std::vector< ContinentalCompetitions::Entrant > ContinentalCompetitions::qualifyByReputation ( const Continental::CompetitionRules &  rules,
std::vector< TeamID > &  taken 
) const
private

◆ rankedAssociations()

std::vector< LeagueID > ContinentalCompetitions::rankedAssociations ( Continental::Continent  continent) const
private

◆ refresh()

void ContinentalCompetitions::refresh ( const Calendar &  calendar)

Rebuilds cached tables from the calendar (after loading).

◆ resolveDecider()

bool ContinentalCompetitions::resolveDecider ( const Calendar &  calendar,
Match &  match 
)

Settles a deciding match whose aggregate is level with extra time and penalties; true if match changed.

◆ save()

void ContinentalCompetitions::save ( const DatabaseConnection &  db) const

◆ serialize()

std::string ContinentalCompetitions::serialize ( ) const

◆ setNewsSink()

void ContinentalCompetitions::setNewsSink ( NewsSink  sink)
inline

◆ startSeason()

void ContinentalCompetitions::startSeason ( uint16_t  season_year,
const GameDateValue &  today 
)

Enters the qualified clubs of season_year and plans the league-phase draw. Uses the qualification computed by closeSeason() or, without one (first season, older saves), the clubs' reputation. Nothing happens if the season already exists or if today is too late to play the league phase.

◆ teamName()

std::string ContinentalCompetitions::teamName ( TeamID  team_id) const
private

◆ tieScore()

ContinentalCompetitions::TieScore ContinentalCompetitions::tieScore ( const Calendar &  calendar,
const Season &  season,
const Tie &  tie 
) const

Aggregate score of a tie.

◆ topDivisionClubs()

std::vector< TeamID > ContinentalCompetitions::topDivisionClubs ( LeagueID  association) const
private

Member Data Documentation

◆ associations

std::map<LeagueID, AssociationCoefficient> ContinentalCompetitions::associations
private

◆ clubs

std::map<TeamID, std::array<double, COEFFICIENT_SEASONS> > ContinentalCompetitions::clubs
private

◆ COEFFICIENT_SEASONS

constexpr size_t ContinentalCompetitions::COEFFICIENT_SEASONS = 5
staticconstexpr

◆ gamedata

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

◆ last_closed_season

uint16_t ContinentalCompetitions::last_closed_season = 0
private

Latest season whose results are in the coefficients.

◆ news

NewsSink ContinentalCompetitions::news
private

◆ qualified

std::map<LeagueID, std::vector<Entrant> > ContinentalCompetitions::qualified
private

◆ qualified_season

uint16_t ContinentalCompetitions::qualified_season = 0
private

◆ results_dirty

bool ContinentalCompetitions::results_dirty = true
private

A result changed since the last knockout check.

◆ seasons

std::vector<Season> ContinentalCompetitions::seasons
private

◆ tables

std::map<LeagueID, std::vector<StandingRow> > ContinentalCompetitions::tables
private

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