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

National-team calendar, call-ups, matches and records. More...

#include <national_teams.h>

Classes

struct  Finals
 
struct  Honour
 
struct  Squad
 
struct  Team
 
struct  Travel
 

Public Types

using ResultSink = std::function< void(const International::Fixture &, double home_expected)>
 
using FinalsSink = std::function< void(const Finals &, bool decided)>
 

Public Member Functions

 NationalTeams (std::shared_ptr< GameData > gamedata)
 
void setResultSink (ResultSink sink)
 
void setFinalsSink (FinalsSink sink)
 
void onDay (const GameDateValue &today, MatchScheduler &scheduler, WorldSimulation &world, TeamID managed_team_id)
 Daily processing: plans the season's international calendar, announces squads a week before each window, plays the day's matches through scheduler, runs the finals and releases players.
 
void planSeason (uint16_t season_year, const GameDateValue &today, WorldSimulation *world)
 
bool isOnDuty (PlayerID player_id, const GameDateValue &date) const
 
std::optional< Language > dutyNation (PlayerID player_id, const GameDateValue &date) const
 
double injuryRiskMultiplier (PlayerID player_id, const GameDateValue &date) const
 
bool isEligibleFor (const Player &player, Language nation, const GameDateValue &date) const
 
const Squad * squadOf (Language nation, const GameDateValue &date) const
 
std::vector< PlayerID > eligiblePool (Language nation, const GameDateValue &date) const
 
International::CallUpResult validateSquad (Language nation, const std::vector< PlayerID > &players, const GameDateValue &today) const
 
International::CallUpResult setSquad (Language nation, std::vector< PlayerID > players, const GameDateValue &today)
 
void setCoach (Language nation, std::string name)
 
double expectedScore (Language home, Language away, bool neutral) const
 
const std::vector< Team > & getTeams () const
 
const Team * getTeam (Language nation) const
 
std::vector< Language > ranking () const
 
const std::vector< International::Fixture > & getFixtures () const
 
const std::vector< International::Group > & getGroups () const
 
const std::vector< Finals > & getFinals () const
 
const std::vector< Squad > & getSquads () const
 
const std::vector< Honour > & getHonours () const
 
const International::Record * getRecord (PlayerID player_id) const
 
std::vector< std::pair< PlayerID, International::Record > > capsLeaders (size_t limit) const
 
std::vector< International::GroupRow > table (const International::Group &group) const
 
void load (const DatabaseConnection &db)
 
void save (const DatabaseConnection &db) const
 
std::string serialize () const
 
void deserialize (const std::string &data)
 

Static Public Member Functions

static size_t squadLimit (const Squad &squad)
 

Static Public Attributes

static constexpr TeamID TEAM_ID_BASE = 0xF000
 
static constexpr size_t MIN_POOL = 20
 
static constexpr int64_t COMPENSATION_PER_DAY = 5'000
 

Private Member Functions

void refreshNations ()
 
std::vector< Language > pool (std::optional< International::Confederation > confederation) const
 
void planQualifiers (uint16_t season_year, uint16_t finals_year, const std::vector< GameDateValue > &slots, const GameDateValue &summer_start)
 
void planNationsLeague (uint16_t season_year, const std::vector< GameDateValue > &slots, const GameDateValue &summer_start)
 
void scheduleGroup (const International::Group &group, const std::vector< GameDateValue > &slots, bool neutral)
 
void drawFinals (Finals &entry, const GameDateValue &today, WorldSimulation &world)
 
void progressFinals (Finals &entry, const GameDateValue &today, WorldSimulation &world)
 
void announceWindow (const GameDateValue &today, const std::vector< GameDateValue > &match_days, const GameDateValue &start, const GameDateValue &end, WorldSimulation &world, TeamID managed_team_id)
 
void playMatches (const GameDateValue &today, MatchScheduler &scheduler, WorldSimulation &world, TeamID managed_team_id)
 
void releasePlayers (const GameDateValue &today, WorldSimulation &world, TeamID managed_team_id)
 
void replaceInjured (const GameDateValue &today)
 
std::vector< PlayerID > pickSquad (Language nation, size_t size, const GameDateValue &date, const std::vector< PlayerID > &keep) const
 
void updateRatings (const International::Fixture &fixture)
 
uint32_t addFixture (International::Fixture fixture)
 
bool hasFixture (Language nation, const GameDateValue &date) const
 
const Finals * finalsFor (Language nation, const GameDateValue &date) const
 
void rebuildDutyIndex ()
 
void post (WorldSimulation &world, const GameDateValue &date, std::string title_key, std::string body_key, std::vector< std::string > args, bool read) const
 

Private Attributes

std::shared_ptr< GameData > gamedata
 
std::vector< Team > teams
 
std::vector< International::Fixture > fixtures
 
std::vector< International::Group > groups
 
std::vector< Finals > finals
 
std::vector< Squad > squads
 
std::vector< Honour > honours
 
std::unordered_map< PlayerID, International::Record > records
 
std::unordered_map< PlayerID, Travel > travel
 
std::unordered_map< PlayerID, std::pair< GameDateValue, GameDateValue > > duty
 
uint16_t planned_season = 0
 
uint32_t next_fixture_id = 1
 
ResultSink result_sink
 
FinalsSink finals_sink
 

Detailed Description

National-team calendar, call-ups, matches and records.

Matches are simulated with the match engine through the same MatchScheduler batch as club matches. Called-up players are unavailable to their clubs from the Monday of a window to its last day (finals: until their nation is out), come back with the match fatigue and injuries of the engine plus travel fatigue, and raise the injury risk for a few days after long trips. Clubs are compensated per player and day for finals.

Member Typedef Documentation

◆ FinalsSink

using NationalTeams::FinalsSink = std::function<void(const Finals&, bool decided)>

A finals tournament was drawn (qualifiers known) or decided.

◆ ResultSink

using NationalTeams::ResultSink = std::function<void(const International::Fixture&, double home_expected)>

A played match and the home side's expected score before it.

Constructor & Destructor Documentation

◆ NationalTeams()

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

Member Function Documentation

◆ addFixture()

uint32_t NationalTeams::addFixture ( International::Fixture  fixture)
private

◆ announceWindow()

void NationalTeams::announceWindow ( const GameDateValue &  today,
const std::vector< GameDateValue > &  match_days,
const GameDateValue &  start,
const GameDateValue &  end,
WorldSimulation &  world,
TeamID  managed_team_id 
)
private

◆ capsLeaders()

std::vector< std::pair< PlayerID, International::Record > > NationalTeams::capsLeaders ( size_t  limit) const

Most capped players (ties: goals, then ID).

◆ deserialize()

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

◆ drawFinals()

void NationalTeams::drawFinals ( Finals &  entry,
const GameDateValue &  today,
WorldSimulation &  world 
)
private

◆ dutyNation()

std::optional< Language > NationalTeams::dutyNation ( PlayerID  player_id,
const GameDateValue &  date 
) const

Nation a player is (or will be) with on date.

◆ eligiblePool()

std::vector< PlayerID > NationalTeams::eligiblePool ( Language  nation,
const GameDateValue &  date 
) const

Players the nation may call up on date (injured ones included), sorted by ID.

◆ expectedScore()

double NationalTeams::expectedScore ( Language  home,
Language  away,
bool  neutral 
) const

Expected score of home against away (Elo, home advantage unless neutral).

◆ finalsFor()

const NationalTeams::Finals * NationalTeams::finalsFor ( Language  nation,
const GameDateValue &  date 
) const
private

◆ getFinals()

const std::vector< Finals > & NationalTeams::getFinals ( ) const
inline

◆ getFixtures()

const std::vector< International::Fixture > & NationalTeams::getFixtures ( ) const
inline

◆ getGroups()

const std::vector< International::Group > & NationalTeams::getGroups ( ) const
inline

Qualifying and nations-league groups of the current cycle.

◆ getHonours()

const std::vector< Honour > & NationalTeams::getHonours ( ) const
inline

◆ getRecord()

const International::Record * NationalTeams::getRecord ( PlayerID  player_id) const

◆ getSquads()

const std::vector< Squad > & NationalTeams::getSquads ( ) const
inline

◆ getTeam()

const NationalTeams::Team * NationalTeams::getTeam ( Language  nation) const

◆ getTeams()

const std::vector< Team > & NationalTeams::getTeams ( ) const
inline

◆ hasFixture()

bool NationalTeams::hasFixture ( Language  nation,
const GameDateValue &  date 
) const
private

◆ injuryRiskMultiplier()

double NationalTeams::injuryRiskMultiplier ( PlayerID  player_id,
const GameDateValue &  date 
) const

Injury-risk multiplier (>= 1) after long trips, for a few days.

◆ isEligibleFor()

bool NationalTeams::isEligibleFor ( const Player &  player,
Language  nation,
const GameDateValue &  date 
) const

Whether player may be picked by nation on date.

◆ isOnDuty()

bool NationalTeams::isOnDuty ( PlayerID  player_id,
const GameDateValue &  date 
) const

Called up and not yet released on date.

◆ load()

void NationalTeams::load ( const DatabaseConnection &  db)

◆ onDay()

void NationalTeams::onDay ( const GameDateValue &  today,
MatchScheduler &  scheduler,
WorldSimulation &  world,
TeamID  managed_team_id 
)

Daily processing: plans the season's international calendar, announces squads a week before each window, plays the day's matches through scheduler, runs the finals and releases players.

◆ pickSquad()

std::vector< PlayerID > NationalTeams::pickSquad ( Language  nation,
size_t  size,
const GameDateValue &  date,
const std::vector< PlayerID > &  keep 
) const
private

◆ planNationsLeague()

void NationalTeams::planNationsLeague ( uint16_t  season_year,
const std::vector< GameDateValue > &  slots,
const GameDateValue &  summer_start 
)
private

◆ planQualifiers()

void NationalTeams::planQualifiers ( uint16_t  season_year,
uint16_t  finals_year,
const std::vector< GameDateValue > &  slots,
const GameDateValue &  summer_start 
)
private

◆ planSeason()

void NationalTeams::planSeason ( uint16_t  season_year,
const GameDateValue &  today,
WorldSimulation *  world 
)

Plans the international matches of the season (idempotent).

◆ playMatches()

void NationalTeams::playMatches ( const GameDateValue &  today,
MatchScheduler &  scheduler,
WorldSimulation &  world,
TeamID  managed_team_id 
)
private

◆ pool()

std::vector< Language > NationalTeams::pool ( std::optional< International::Confederation >  confederation) const
private

◆ post()

void NationalTeams::post ( WorldSimulation &  world,
const GameDateValue &  date,
std::string  title_key,
std::string  body_key,
std::vector< std::string >  args,
bool  read 
) const
private

◆ progressFinals()

void NationalTeams::progressFinals ( Finals &  entry,
const GameDateValue &  today,
WorldSimulation &  world 
)
private

◆ ranking()

std::vector< Language > NationalTeams::ranking ( ) const

Nations by rating, best first.

◆ rebuildDutyIndex()

void NationalTeams::rebuildDutyIndex ( )
private

◆ refreshNations()

void NationalTeams::refreshNations ( )
private

◆ releasePlayers()

void NationalTeams::releasePlayers ( const GameDateValue &  today,
WorldSimulation &  world,
TeamID  managed_team_id 
)
private

◆ replaceInjured()

void NationalTeams::replaceInjured ( const GameDateValue &  today)
private

◆ save()

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

◆ scheduleGroup()

void NationalTeams::scheduleGroup ( const International::Group &  group,
const std::vector< GameDateValue > &  slots,
bool  neutral 
)
private

◆ serialize()

std::string NationalTeams::serialize ( ) const

◆ setCoach()

void NationalTeams::setCoach ( Language  nation,
std::string  name 
)

Names the nation's head coach.

◆ setFinalsSink()

void NationalTeams::setFinalsSink ( FinalsSink  sink)
inline

◆ setResultSink()

void NationalTeams::setResultSink ( ResultSink  sink)
inline

◆ setSquad()

International::CallUpResult NationalTeams::setSquad ( Language  nation,
std::vector< PlayerID >  players,
const GameDateValue &  today 
)

Replaces the announced squad once validateSquad() accepts it.

◆ squadLimit()

static size_t NationalTeams::squadLimit ( const Squad &  squad)
inlinestatic

Squad limit of a call-up (window or finals).

◆ squadOf()

const NationalTeams::Squad * NationalTeams::squadOf ( Language  nation,
const GameDateValue &  date 
) const

The nation's announced or current squad on date (nullptr if none).

◆ table()

std::vector< International::GroupRow > NationalTeams::table ( const International::Group &  group) const

Group table with the current ratings as the last tie-breaker.

◆ updateRatings()

void NationalTeams::updateRatings ( const International::Fixture &  fixture)
private

◆ validateSquad()

International::CallUpResult NationalTeams::validateSquad ( Language  nation,
const std::vector< PlayerID > &  players,
const GameDateValue &  today 
) const

Checks a squad a head coach wants to call up for the announced window.

Member Data Documentation

◆ COMPENSATION_PER_DAY

constexpr int64_t NationalTeams::COMPENSATION_PER_DAY = 5'000
staticconstexpr

Club compensation per finals player and day (whole euros).

◆ duty

std::unordered_map<PlayerID, std::pair<GameDateValue, GameDateValue> > NationalTeams::duty
private

Player -> (start, until) of his current or announced duty.

◆ finals

std::vector<Finals> NationalTeams::finals
private

◆ finals_sink

FinalsSink NationalTeams::finals_sink
private

◆ fixtures

std::vector<International::Fixture> NationalTeams::fixtures
private

◆ gamedata

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

◆ groups

std::vector<International::Group> NationalTeams::groups
private

◆ honours

std::vector<Honour> NationalTeams::honours
private

◆ MIN_POOL

constexpr size_t NationalTeams::MIN_POOL = 20
staticconstexpr

Nations need this many players (and two goalkeepers).

◆ next_fixture_id

uint32_t NationalTeams::next_fixture_id = 1
private

◆ planned_season

uint16_t NationalTeams::planned_season = 0
private

◆ records

std::unordered_map<PlayerID, International::Record> NationalTeams::records
private

◆ result_sink

ResultSink NationalTeams::result_sink
private

◆ squads

std::vector<Squad> NationalTeams::squads
private

◆ TEAM_ID_BASE

constexpr TeamID NationalTeams::TEAM_ID_BASE = 0xF000
staticconstexpr

Team IDs used for national teams inside match reports.

◆ teams

std::vector<Team> NationalTeams::teams
private

◆ travel

std::unordered_map<PlayerID, Travel> NationalTeams::travel
private

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