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

Represents the core game state and logic. More...

#include <game.h>

Classes

struct  CupRun
 

Public Member Functions

 Game (std::shared_ptr< class GameData > gd, std::shared_ptr< DatabaseConnection > conn)
 Constructs a new Game object.
 
void advanceDay ()
 Advances the game time by one day, simulating any matches or events scheduled for the current date.
 
bool setMatchResult (const GameDateValue &date, TeamID home_id, TeamID away_id, uint8_t home_score, uint8_t away_score)
 
bool setMatchResult (const GameDateValue &date, TeamID home_id, TeamID away_id, MatchReport report, std::span< const PlayerMatchConsequence > consequences={})
 
bool isEligible (const Player &player, MatchType type, std::optional< GameDateValue > date=std::nullopt) const
 
std::vector< PlayerID > ineligibleSelections (TeamID team_id, MatchType type) const
 
std::size_t fixMatchdaySquad (TeamID team_id, MatchType type, std::optional< GameDateValue > date=std::nullopt)
 
std::vector< std::pair< PlayerID, PlayerID > > previewMatchdaySquadFix (TeamID team_id, MatchType type) const
 
bool canKickOff (TeamID team_id, MatchType type) const
 
void setAssistantFixesLineup (bool enabled)
 
bool getAssistantFixesLineup () const
 
CareerGuidance & getGuidance ()
 
const CareerGuidance & getGuidance () const
 
MedicalDesk & getMedical ()
 
const MedicalDesk & getMedical () const
 
const Supporters & getSupporters () const
 
const CompetitionManager & getCompetitions () const
 
const SeasonArchive & getSeasonArchive () const
 
SeasonArchive & getSeasonArchive ()
 
int youngRegulars (TeamID team_id) const
 
CupRun cupRun (TeamID team_id) const
 
const NationalTeams & getNationalTeams () const
 
NationalTeams & getNationalTeams ()
 
NationalManagement & getNationalJob ()
 
const NationalManagement & getNationalJob () const
 
const NationalDayEvents & getLastNationalEvents () const
 
WorldSimulation & getWorld ()
 
const WorldSimulation & getWorld () const
 
TransferMarket & getTransfers ()
 
const TransferMarket & getTransfers () const
 
ManagerCareer & getCareer ()
 
const ManagerCareer & getCareer () const
 
const CareerDayEvents & getLastCareerEvents () const
 
void leaveManagedTeam (DepartureReason reason)
 
void takeJob (TeamID team_id, const ManagerContract &contract)
 
SimulationProgress getSimulationProgress () const
 
void resetSimulationProgress ()
 
void setSimulationThreads (unsigned threads)
 
unsigned getSimulationThreads () const
 
const GameDateValue & getCurrentDate () const
 Retrieves the current in-game date.
 
const Calendar & getCalendar () const
 Retrieves the calendar containing all fixtures.
 
Calendar & getCalendar ()
 
int getCurrentSeason () const
 Retrieves the current season number.
 
uint16_t getManagedTeamId () const
 Retrieves the ID of the team currently managed by the user.
 
void setManagedTeamId (uint16_t id)
 Sets the team managed by the user.
 
void saveGame ()
 Saves the current game state, including calendar and game variables, to the database.
 

Private Member Functions

void loadGame ()
 
void endSeason ()
 
void handleSeasonTransition ()
 
void startNewSeason ()
 
void beginSeasonReview (const std::map< LeagueID, std::vector< StandingRow > > &final_tables, std::uint16_t start_year)
 
void judgeSeason (std::span< const SeasonHistoryEntry > finished)
 
void finishSeasonReview ()
 
void fillLineupGap (Team &team, const Player &departed)
 
void postLineupRepairs ()
 
std::vector< UpcomingFixture > upcomingFixtures (TeamID team_id) const
 
void keepManagedSelectionEligible ()
 
std::size_t fillMatchdaySquad (Lineup &lineup, TeamID team_id, MatchType type, const GameDateValue &date, bool recall_regulars) const
 
void runCareerDay ()
 
void recordCareerMatch (const Match &match)
 
void simulateMatches (std::vector< Match > &matches, bool include_managed=false)
 
void settleLevelTie (Match &match, MatchReport &report)
 
void discoverExtensions ()
 
void serialize (bool probe)
 

Private Attributes

std::shared_ptr< DatabaseConnection > db_conn
 
std::unique_ptr< RuntimeEditor::Extensions > extensions
 
int extensions_version = -1
 
RuntimeEditor::Payloads payload_extensions
 
std::shared_ptr< class GameData > gamedata
 
Calendar calendar
 
CompetitionManager competitions
 
WorldSimulation world
 
TransferMarket transfers
 
ManagerCareer career
 
CareerDayEvents last_career_events
 
NationalTeams international
 
NationalManagement national_job
 
NationalDayEvents last_national_events
 
MatchScheduler scheduler
 
GameDateValue currentDate = START_DATE
 
uint8_t current_season = 1
 
uint16_t managed_team_id
 
CareerGuidance guidance
 
MedicalDesk medical
 
Supporters supporters
 
SeasonArchive season_archive
 
std::optional< SeasonReview > closing_review
 
std::vector< std::pair< std::string, std::string > > lineup_repairs
 

Detailed Description

Represents the core game state and logic.

The Game class orchestrates the simulation mechanics, handling the progression of time, saving and loading the game state, and triggering match simulations.

Constructor & Destructor Documentation

◆ Game()

Game::Game ( std::shared_ptr< class GameData >  gd,
std::shared_ptr< DatabaseConnection >  conn 
)
explicit

Constructs a new Game object.

Parameters
gdShared pointer to the GameData instance.
connShared pointer to the DatabaseConnection.

Member Function Documentation

◆ advanceDay()

void Game::advanceDay ( )

Advances the game time by one day, simulating any matches or events scheduled for the current date.

◆ beginSeasonReview()

void Game::beginSeasonReview ( const std::map< LeagueID, std::vector< StandingRow > > &  final_tables,
std::uint16_t  start_year 
)
private

The managed club's season numbers, read from the final tables before promotion and relegation move the clubs.

◆ canKickOff()

bool Game::canKickOff ( TeamID  team_id,
MatchType  type 
) const

Whether the club's selection may kick off as it is: it is exactly what fixMatchdaySquad() would pick, so players still listed by ineligibleSelections() are injured players nobody fit can replace.

◆ cupRun()

Game::CupRun Game::cupRun ( TeamID  team_id) const

◆ discoverExtensions()

void Game::discoverExtensions ( )
private

◆ endSeason()

void Game::endSeason ( )
private

◆ fillLineupGap()

void Game::fillLineupGap ( Team &  team,
const Player &  departed 
)
private

Takes a departing managed player out of the line-up, filling only his place, and notes the change for postLineupRepairs().

◆ fillMatchdaySquad()

std::size_t Game::fillMatchdaySquad ( Lineup &  lineup,
TeamID  team_id,
MatchType  type,
const GameDateValue &  date,
bool  recall_regulars 
) const
private

fixMatchdaySquad() applied to lineup, a selection of team_id; without recall_regulars recovered regulars stay where they are (the selection is only made eligible).

◆ finishSeasonReview()

void Game::finishSeasonReview ( )
private

Archives the review with next season's objectives.

◆ fixMatchdaySquad()

std::size_t Game::fixMatchdaySquad ( TeamID  team_id,
MatchType  type,
std::optional< GameDateValue >  date = std::nullopt 
)

The assistant's matchday selection: regulars fit again take back their places from the players who stood in for them, then ineligible players are replaced by the best-fitting eligible squad and academy players, then by trialists, and the replacements are noted as stand-ins (Lineup::getStandIns()). When nobody fit is left for a starting place, injured players play through it (the least injured first), so a side always takes the field; players who may not play at all (suspended, on national duty) and cannot be replaced leave the XI and the side plays with the players it has. Availability is judged on date (default: today). Returns how many selections changed.

◆ getAssistantFixesLineup()

bool Game::getAssistantFixesLineup ( ) const
inline

◆ getCalendar() [1/2]

Calendar & Game::getCalendar ( )

◆ getCalendar() [2/2]

const Calendar & Game::getCalendar ( ) const

Retrieves the calendar containing all fixtures.

Returns
A constant reference to the game Calendar.

◆ getCareer() [1/2]

ManagerCareer & Game::getCareer ( )
inline

The human manager's career and the market for managers.

◆ getCareer() [2/2]

const ManagerCareer & Game::getCareer ( ) const
inline

◆ getCompetitions()

const CompetitionManager & Game::getCompetitions ( ) const
inline

Standings, cups, reports, player season stats and season history.

◆ getCurrentDate()

const GameDateValue & Game::getCurrentDate ( ) const

Retrieves the current in-game date.

Returns
A constant reference to the current GameDateValue.

◆ getCurrentSeason()

int Game::getCurrentSeason ( ) const

Retrieves the current season number.

Returns
The current season as an integer.

◆ getGuidance() [1/2]

CareerGuidance & Game::getGuidance ( )
inline

Checklist, delegation, opposition instructions, match analytics.

◆ getGuidance() [2/2]

const CareerGuidance & Game::getGuidance ( ) const
inline

◆ getLastCareerEvents()

const CareerDayEvents & Game::getLastCareerEvents ( ) const
inline

What the manager market did on the latest simulated day.

◆ getLastNationalEvents()

const NationalDayEvents & Game::getLastNationalEvents ( ) const
inline

What the national-job market did on the latest simulated day.

◆ getManagedTeamId()

uint16_t Game::getManagedTeamId ( ) const

Retrieves the ID of the team currently managed by the user.

Returns
The managed team's ID.

◆ getMedical() [1/2]

MedicalDesk & Game::getMedical ( )
inline

Rest and minute-limit flags, load log and warnings of the physios.

◆ getMedical() [2/2]

const MedicalDesk & Game::getMedical ( ) const
inline

◆ getNationalJob() [1/2]

NationalManagement & Game::getNationalJob ( )
inline

The manager's national-team job and the market for national jobs.

◆ getNationalJob() [2/2]

const NationalManagement & Game::getNationalJob ( ) const
inline

◆ getNationalTeams() [1/2]

NationalTeams & Game::getNationalTeams ( )
inline

◆ getNationalTeams() [2/2]

const NationalTeams & Game::getNationalTeams ( ) const
inline

National teams: calendar, call-ups, finals, caps.

◆ getSeasonArchive() [1/2]

SeasonArchive & Game::getSeasonArchive ( )
inline

◆ getSeasonArchive() [2/2]

const SeasonArchive & Game::getSeasonArchive ( ) const
inline

Final tables of past seasons and the managed club's season reviews.

◆ getSimulationProgress()

SimulationProgress Game::getSimulationProgress ( ) const
inline

Matches simulated / scheduled so far in the current advanceDay(). Safe to poll from another thread while advanceDay() runs.

◆ getSimulationThreads()

unsigned Game::getSimulationThreads ( ) const
inline

◆ getSupporters()

const Supporters & Game::getSupporters ( ) const
inline

The managed club's supporters and their weekly mood.

◆ getTransfers() [1/2]

TransferMarket & Game::getTransfers ( )
inline

Deals, loans, pre-contracts, scheduled payments and transfer history.

◆ getTransfers() [2/2]

const TransferMarket & Game::getTransfers ( ) const
inline

◆ getWorld() [1/2]

WorldSimulation & Game::getWorld ( )
inline

Inbox, board, injuries, finances and development between matches.

◆ getWorld() [2/2]

const WorldSimulation & Game::getWorld ( ) const
inline

◆ handleSeasonTransition()

void Game::handleSeasonTransition ( )
private

◆ ineligibleSelections()

std::vector< PlayerID > Game::ineligibleSelections ( TeamID  team_id,
MatchType  type 
) const

Selected players of a club who may not play a match of type.

◆ isEligible()

bool Game::isEligible ( const Player &  player,
MatchType  type,
std::optional< GameDateValue >  date = std::nullopt 
) const

Fit (not injured), outside friendlies not suspended for type, and not away with his national team on date (default: today).

◆ judgeSeason()

void Game::judgeSeason ( std::span< const SeasonHistoryEntry >  finished)
private

Outcome, board verdict and season news once the clubs have moved.

◆ keepManagedSelectionEligible()

void Game::keepManagedSelectionEligible ( )
private

Replaces unavailable managed players for the next managed fixture.

◆ leaveManagedTeam()

void Game::leaveManagedTeam ( DepartureReason  reason)

The manager leaves the managed club (sacked, resigned, contract expired, or moving on): the club gets a vacancy and an AI manager in due course, its board, shortlist, transfer talks and offers are dropped and no command reaches it any more. The inbox stays.

◆ loadGame()

void Game::loadGame ( )
private

◆ postLineupRepairs()

void Game::postLineupRepairs ( )
private

Tells the manager which starting places were filled.

◆ previewMatchdaySquadFix()

std::vector< std::pair< PlayerID, PlayerID > > Game::previewMatchdaySquadFix ( TeamID  team_id,
MatchType  type 
) const

What fixMatchdaySquad() would change: (replaced, replacement or 0).

◆ recordCareerMatch()

void Game::recordCareerMatch ( const Match &  match)
private

Job security of AI managers and the human's record.

◆ resetSimulationProgress()

void Game::resetSimulationProgress ( )
inline

◆ runCareerDay()

void Game::runCareerDay ( )
private

Manager market day and the board's verdict on the manager.

◆ saveGame()

void Game::saveGame ( )

Saves the current game state, including calendar and game variables, to the database.

◆ serialize()

void Game::serialize ( bool  probe)
private

◆ setAssistantFixesLineup()

void Game::setAssistantFixesLineup ( bool  enabled)
inline

Whether the assistant keeps the managed selection eligible: after each day, and at kick-off, injured or suspended players are replaced.

◆ setManagedTeamId()

void Game::setManagedTeamId ( uint16_t  id)

Sets the team managed by the user.

Taking charge of a new club sets the board's objective and budgets immediately and posts the day-one inbox (welcome, squad report, pre-season schedule, scouting suggestion).

Parameters
idThe ID of the team to manage.

◆ setMatchResult() [1/2]

bool Game::setMatchResult ( const GameDateValue &  date,
TeamID  home_id,
TeamID  away_id,
MatchReport  report,
std::span< const PlayerMatchConsequence >  consequences = {} 
)

Records a managed match with its structured report (e.g. built from the live MatchEngine). A drawn cup tie is settled by extra time and penalties unless the report already carries them. consequences (MatchdaySquad::consequences of the engine) apply the measured condition and injuries exactly as for simulated matches.

◆ setMatchResult() [2/2]

bool Game::setMatchResult ( const GameDateValue &  date,
TeamID  home_id,
TeamID  away_id,
uint8_t  home_score,
uint8_t  away_score 
)

Records a managed match exactly once and applies its consequences.

◆ setSimulationThreads()

void Game::setSimulationThreads ( unsigned  threads)
inline

Threads used to simulate a matchday (1 = one match after another).

◆ settleLevelTie()

void Game::settleLevelTie ( Match &  match,
MatchReport &  report 
)
private

Fallback for a knockout tie recorded level without extra time (a score-only result, or a match abandoned before the engine could settle it): extra time and penalties are resolved from the squads and the extra-time goals credited to players who finished the match.

◆ simulateMatches()

void Game::simulateMatches ( std::vector< Match > &  matches,
bool  include_managed = false 
)
private

◆ startNewSeason()

void Game::startNewSeason ( )
private

◆ takeJob()

void Game::takeJob ( TeamID  team_id,
const ManagerContract &  contract 
)

The manager takes charge of team_id under contract (leaving the current club first): the board sets objectives and budgets for the new club, scouting starts afresh and the club's squad, line-up, tactics and training plan become the manager's.

◆ upcomingFixtures()

std::vector< UpcomingFixture > Game::upcomingFixtures ( TeamID  team_id) const
private

The club's fixtures from today up to its first competitive match.

◆ youngRegulars()

int Game::youngRegulars ( TeamID  team_id) const

Squad players aged 21 or under with ten or more appearances.

Member Data Documentation

◆ calendar

Calendar Game::calendar
private

◆ career

ManagerCareer Game::career
private

◆ closing_review

std::optional<SeasonReview> Game::closing_review
private

◆ competitions

CompetitionManager Game::competitions
private

◆ current_season

uint8_t Game::current_season = 1
private

◆ currentDate

GameDateValue Game::currentDate = START_DATE
private

◆ db_conn

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

◆ extensions

std::unique_ptr<RuntimeEditor::Extensions> Game::extensions
private

◆ extensions_version

int Game::extensions_version = -1
private

◆ gamedata

std::shared_ptr<class GameData> Game::gamedata
private

◆ guidance

CareerGuidance Game::guidance
private

◆ international

NationalTeams Game::international
private

◆ last_career_events

CareerDayEvents Game::last_career_events
private

◆ last_national_events

NationalDayEvents Game::last_national_events
private

◆ lineup_repairs

std::vector<std::pair<std::string, std::string> > Game::lineup_repairs
private

Starting places filled at the season end: (departed, replacement).

◆ managed_team_id

uint16_t Game::managed_team_id
private

◆ medical

MedicalDesk Game::medical
private

◆ national_job

NationalManagement Game::national_job
private

◆ payload_extensions

RuntimeEditor::Payloads Game::payload_extensions
private

◆ scheduler

MatchScheduler Game::scheduler
private

◆ season_archive

SeasonArchive Game::season_archive
private

◆ supporters

Supporters Game::supporters
private

◆ transfers

TransferMarket Game::transfers
private

◆ world

WorldSimulation Game::world
private

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