|
Player12
An open source football management simulator
|
Singleton class that acts as an in-memory cache for the database state. More...
#include <gamedata.h>
Public Member Functions | |
| GameData () | |
| Constructs a new GameData instance. | |
| GameData (const GameData &)=delete | |
| GameData & | operator= (const GameData &)=delete |
| bool | loadFromDB (std::shared_ptr< DatabaseConnection > database_ptr) |
| Loads the initial game state from the database. | |
| bool | saveToDB () const |
| Saves the current in-memory state back to the database. | |
| const StatsConfig & | getStatsConfig () const |
| void | addLeague (LeagueID id, const League &league) |
| std::optional< std::reference_wrapper< const League > > | getLeague (LeagueID id) const |
| const std::unordered_map< LeagueID, League > & | getLeagues () const |
| std::unordered_map< LeagueID, League > & | getLeagues () |
| const std::vector< std::reference_wrapper< const League > > & | getLeaguesVector () const |
| void | addTeam (TeamID id, const Team &team) |
| std::optional< std::reference_wrapper< Team > > | getTeam (TeamID id) |
| std::optional< std::reference_wrapper< const Team > > | getTeam (TeamID id) const |
| const std::unordered_map< TeamID, Team > & | getTeams () const |
| std::unordered_map< TeamID, Team > & | getTeams () |
| const std::vector< std::reference_wrapper< const Team > > & | getTeamsVector () const |
| void | ageAllPlayers () |
| std::vector< PlayerID > | advanceContractsAndReleasePlayers (TeamID keep_selection=FREE_AGENTS_TEAM_ID) |
| void | addPlayer (PlayerID id, const Player &player) |
| std::optional< std::reference_wrapper< const Player > > | getPlayer (PlayerID id) const |
| const std::unordered_map< PlayerID, Player > & | getPlayers () const |
| std::unordered_map< PlayerID, Player > & | getPlayers () |
| const std::vector< std::reference_wrapper< const Player > > & | getPlayersVector () const |
| const std::vector< std::reference_wrapper< const Player > > & | getPlayersForTeam (TeamID team_id) const |
| const std::vector< std::reference_wrapper< const Player > > & | getAcademyForTeam (TeamID team_id) const |
| void | setAcademyMember (PlayerID id, bool academy) |
| bool | removePlayer (PlayerID id) |
| void | transferPlayer (PlayerID id, TeamID new_team_id) |
| SquadNumbers::Change | setSquadNumber (PlayerID id, int number) |
| void | assignSquadNumbers (TeamID team_id, PlayerID newcomer=0) |
| void | setWorldSeed (std::uint64_t seed) |
| Seeds the generation of a new world (call before loadFromDB). | |
| std::uint64_t | getWorldSeed () const |
| Seed of every random stream of the world simulation. | |
| PlayerID | allocatePlayerId () |
| Returns a new, never reused player id. | |
| PlayerID | peekNextPlayerId () const |
| The id the next allocatePlayerId() call will return. | |
| const std::vector< PlayerID > & | getRemovedPlayerIds () const |
| Players removed (retired) since the last save. | |
| void | clearRemovedPlayerIds () |
| Forgets removed players once their deletion is persisted. | |
| StaffRoster & | getStaff () |
| Coaches, medics and scouts of every club plus the staff market. | |
| const StaffRoster & | getStaff () const |
| TrainingRegistry & | getTraining () |
| Training plans, familiarity and player workloads. | |
| const TrainingRegistry & | getTraining () const |
| void | saveTransferListing (const TransferListing &listing) const |
| Saves a transfer listing to the database (UPSERT). | |
| void | deleteTransferListing (PlayerID player_id) const |
| Deletes a transfer listing from the database. | |
| std::unordered_map< PlayerID, TransferListing > | loadAllTransferListings () const |
| Loads all transfer listings from the database into a map. | |
Private Member Functions | |
| void | loadStatsConfig () |
| void | generateAndSaveInitialData () |
| void | loadExistingData () |
| void | migrateSchema () const |
| void | restoreWorldState () |
| void | restoreStaffAndTraining () |
Private Attributes | |
| std::unordered_map< LeagueID, League > | _leagues |
| std::vector< std::reference_wrapper< const League > > | _leaguesVec |
| std::unordered_map< TeamID, Team > | _teams |
| std::vector< std::reference_wrapper< const Team > > | _teamsVec |
| std::unordered_map< PlayerID, Player > | _players |
| std::vector< std::reference_wrapper< const Player > > | _playersVec |
| std::unordered_map< TeamID, std::vector< std::reference_wrapper< const Player > > > | _teamPlayers |
| std::unordered_map< TeamID, std::vector< std::reference_wrapper< const Player > > > | _teamAcademies |
| StatsConfig | stats_config |
| std::shared_ptr< DatabaseConnection > | db_conn |
| std::uint64_t | world_seed = 0 |
| bool | world_seed_set = false |
| PlayerID | next_player_id = 1 |
| std::vector< PlayerID > | removed_player_ids |
| StaffRoster | staff |
| TrainingRegistry | training |
Singleton class that acts as an in-memory cache for the database state.
GameData is responsible for loading the initial game state from SQLite, holding all core entities (Leagues, Teams, Players), and facilitating high-performance read/write access during gameplay without hitting the disk.
|
default |
Constructs a new GameData instance.
|
delete |
| std::vector< PlayerID > GameData::advanceContractsAndReleasePlayers | ( | TeamID | keep_selection = FREE_AGENTS_TEAM_ID | ) |
Advances contracts and releases newly out-of-contract players. Clubs that lose a player get a new line-up, except keep_selection (the manager's club), whose gaps the caller fills.
| void GameData::ageAllPlayers | ( | ) |
| PlayerID GameData::allocatePlayerId | ( | ) |
Returns a new, never reused player id.
Numbers the club's senior players who have none or share one. The number of newcomer (just arrived) only counts as his wish.
| void GameData::clearRemovedPlayerIds | ( | ) |
Forgets removed players once their deletion is persisted.
| void GameData::deleteTransferListing | ( | PlayerID | player_id | ) | const |
Deletes a transfer listing from the database.
|
private |
| const std::vector< std::reference_wrapper< const Player > > & GameData::getAcademyForTeam | ( | TeamID | team_id | ) | const |
Academy players of a club (still club players for contracts and wages, but not part of the senior squad).
| const std::vector< std::reference_wrapper< const League > > & GameData::getLeaguesVector | ( | ) | const |
| const std::vector< std::reference_wrapper< const Player > > & GameData::getPlayersForTeam | ( | TeamID | team_id | ) | const |
Senior squad of a club: academy players (U18 squad and intake trialists) are listed by getAcademyForTeam().
| const std::vector< std::reference_wrapper< const Player > > & GameData::getPlayersVector | ( | ) | const |
| const std::vector< PlayerID > & GameData::getRemovedPlayerIds | ( | ) | const |
Players removed (retired) since the last save.
|
inline |
Coaches, medics and scouts of every club plus the staff market.
|
inline |
| const StatsConfig & GameData::getStatsConfig | ( | ) | const |
| const std::vector< std::reference_wrapper< const Team > > & GameData::getTeamsVector | ( | ) | const |
|
inline |
Training plans, familiarity and player workloads.
|
inline |
| std::uint64_t GameData::getWorldSeed | ( | ) | const |
Seed of every random stream of the world simulation.
| std::unordered_map< PlayerID, TransferListing > GameData::loadAllTransferListings | ( | ) | const |
Loads all transfer listings from the database into a map.
|
private |
| bool GameData::loadFromDB | ( | std::shared_ptr< DatabaseConnection > | database_ptr | ) |
Loads the initial game state from the database.
| database_ptr | Shared pointer to the active DatabaseConnection. |
|
private |
|
private |
| PlayerID GameData::peekNextPlayerId | ( | ) | const |
The id the next allocatePlayerId() call will return.
| bool GameData::removePlayer | ( | PlayerID | id | ) |
|
private |
|
private |
| bool GameData::saveToDB | ( | ) | const |
Saves the current in-memory state back to the database.
| void GameData::saveTransferListing | ( | const TransferListing & | listing | ) | const |
Saves a transfer listing to the database (UPSERT).
| void GameData::setAcademyMember | ( | PlayerID | id, |
| bool | academy | ||
| ) |
Moves a player of his club between the senior squad and the academy: sets Player::isAcademyPlayer() and keeps the club's lists in sync.
| SquadNumbers::Change GameData::setSquadNumber | ( | PlayerID | id, |
| int | number | ||
| ) |
Gives id squad number number (1-99) at his club; a teammate wearing it takes his old number.
| void GameData::setWorldSeed | ( | std::uint64_t | seed | ) |
Seeds the generation of a new world (call before loadFromDB).
Without an explicit seed a new world uses FM_WORLD_SEED from the environment or, failing that, the system clock. Loaded saves use their stored seed.
Moves a player to another club's senior squad (academy membership does not travel with him). He keeps his squad number when it is free at the new club, otherwise he gets a free one (SquadNumbers).
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |