15#include <unordered_map>
59 bool loadFromDB(std::shared_ptr<DatabaseConnection> database_ptr);
73 std::optional<std::reference_wrapper<const League>>
getLeague(
76 const std::unordered_map<LeagueID, League>&
getLeagues()
const;
78 std::unordered_map<LeagueID, League>&
getLeagues();
86 std::optional<std::reference_wrapper<Team>>
getTeam(
TeamID id);
88 std::optional<std::reference_wrapper<const Team>>
getTeam(
TeamID id)
const;
90 const std::unordered_map<TeamID, Team>&
getTeams()
const;
92 std::unordered_map<TeamID, Team>&
getTeams();
94 const std::vector<std::reference_wrapper<const Team>>&
getTeamsVector()
const;
107 std::optional<std::reference_wrapper<const Player>>
getPlayer(
109 const std::unordered_map<PlayerID, Player>&
getPlayers()
const;
110 std::unordered_map<PlayerID, Player>&
getPlayers();
195 std::vector<std::reference_wrapper<const Team>>
_teamsVec;
198 std::unordered_map<TeamID, std::vector<std::reference_wrapper<const Player>>>
200 std::unordered_map<TeamID, std::vector<std::reference_wrapper<const Player>>>
Manages the SQLite database connection and transaction lifecycle.
Definition database_connection.h:24
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
void loadStatsConfig()
Definition gamedata.cpp:880
void generateAndSaveInitialData()
Definition gamedata.cpp:184
StaffRoster & getStaff()
Coaches, medics and scouts of every club plus the staff market.
Definition gamedata.h:168
StatsConfig stats_config
Definition gamedata.h:202
const std::unordered_map< LeagueID, League > & getLeagues() const
Definition gamedata.cpp:484
bool world_seed_set
Definition gamedata.h:205
bool loadFromDB(std::shared_ptr< DatabaseConnection > database_ptr)
Loads the initial game state from the database.
Definition gamedata.cpp:116
std::uint64_t getWorldSeed() const
Seed of every random stream of the world simulation.
Definition gamedata.cpp:786
std::unordered_map< LeagueID, League > _leagues
Definition gamedata.h:192
std::vector< PlayerID > advanceContractsAndReleasePlayers(TeamID keep_selection=FREE_AGENTS_TEAM_ID)
Definition gamedata.cpp:577
std::vector< PlayerID > removed_player_ids
Definition gamedata.h:207
PlayerID next_player_id
Definition gamedata.h:206
void addLeague(LeagueID id, const League &league)
Definition gamedata.cpp:471
std::shared_ptr< DatabaseConnection > db_conn
Definition gamedata.h:203
void migrateSchema() const
Definition gamedata.cpp:299
const std::vector< std::reference_wrapper< const League > > & getLeaguesVector() const
Definition gamedata.cpp:495
const std::vector< std::reference_wrapper< const Player > > & getAcademyForTeam(TeamID team_id) const
Definition gamedata.cpp:628
GameData(const GameData &)=delete
std::unordered_map< TeamID, std::vector< std::reference_wrapper< const Player > > > _teamPlayers
Definition gamedata.h:199
void addPlayer(PlayerID id, const Player &player)
Definition gamedata.cpp:534
const std::vector< std::reference_wrapper< const Team > > & getTeamsVector() const
Definition gamedata.cpp:528
std::optional< std::reference_wrapper< const Player > > getPlayer(PlayerID id) const
Definition gamedata.cpp:547
GameData()
Constructs a new GameData instance.
void restoreStaffAndTraining()
Definition gamedata.cpp:167
std::unordered_map< PlayerID, TransferListing > loadAllTransferListings() const
Loads all transfer listings from the database into a map.
Definition gamedata.cpp:835
StaffRoster staff
Definition gamedata.h:208
void restoreWorldState()
Definition gamedata.cpp:306
const std::vector< PlayerID > & getRemovedPlayerIds() const
Players removed (retired) since the last save.
Definition gamedata.cpp:792
bool saveToDB() const
Saves the current in-memory state back to the database.
Definition gamedata.cpp:448
const TrainingRegistry & getTraining() const
Definition gamedata.h:173
bool removePlayer(PlayerID id)
Definition gamedata.cpp:656
TrainingRegistry & getTraining()
Training plans, familiarity and player workloads.
Definition gamedata.h:172
GameData & operator=(const GameData &)=delete
void clearRemovedPlayerIds()
Forgets removed players once their deletion is persisted.
Definition gamedata.cpp:797
void setAcademyMember(PlayerID id, bool academy)
Definition gamedata.cpp:636
PlayerID allocatePlayerId()
Returns a new, never reused player id.
Definition gamedata.cpp:788
void transferPlayer(PlayerID id, TeamID new_team_id)
Definition gamedata.cpp:680
void addTeam(TeamID id, const Team &team)
Definition gamedata.cpp:501
const std::unordered_map< TeamID, Team > & getTeams() const
Definition gamedata.cpp:520
void ageAllPlayers()
Definition gamedata.cpp:569
std::unordered_map< PlayerID, Player > _players
Definition gamedata.h:196
std::optional< std::reference_wrapper< Team > > getTeam(TeamID id)
Definition gamedata.cpp:507
std::vector< std::reference_wrapper< const Team > > _teamsVec
Definition gamedata.h:195
const std::unordered_map< PlayerID, Player > & getPlayers() const
Definition gamedata.cpp:554
const std::vector< std::reference_wrapper< const Player > > & getPlayersVector() const
Definition gamedata.cpp:564
const StatsConfig & getStatsConfig() const
Definition gamedata.cpp:891
std::unordered_map< TeamID, std::vector< std::reference_wrapper< const Player > > > _teamAcademies
Definition gamedata.h:201
void loadExistingData()
Definition gamedata.cpp:365
void deleteTransferListing(PlayerID player_id) const
Deletes a transfer listing from the database.
Definition gamedata.cpp:823
void setWorldSeed(std::uint64_t seed)
Seeds the generation of a new world (call before loadFromDB).
Definition gamedata.cpp:780
SquadNumbers::Change setSquadNumber(PlayerID id, int number)
Definition gamedata.cpp:752
void saveTransferListing(const TransferListing &listing) const
Saves a transfer listing to the database (UPSERT).
Definition gamedata.cpp:800
void assignSquadNumbers(TeamID team_id, PlayerID newcomer=0)
Definition gamedata.cpp:711
std::vector< std::reference_wrapper< const League > > _leaguesVec
Definition gamedata.h:193
std::optional< std::reference_wrapper< const League > > getLeague(LeagueID id) const
Definition gamedata.cpp:477
PlayerID peekNextPlayerId() const
The id the next allocatePlayerId() call will return.
Definition gamedata.cpp:790
std::unordered_map< TeamID, Team > _teams
Definition gamedata.h:194
std::vector< std::reference_wrapper< const Player > > _playersVec
Definition gamedata.h:197
std::uint64_t world_seed
Definition gamedata.h:204
TrainingRegistry training
Definition gamedata.h:209
const StaffRoster & getStaff() const
Definition gamedata.h:169
const std::vector< std::reference_wrapper< const Player > > & getPlayersForTeam(TeamID team_id) const
Definition gamedata.cpp:617
Represents a football league containing teams and a leaderboard.
Definition league.h:41
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
Every staff member of the world with per-club effect caches. Concurrent effects queries return indepe...
Definition staff.h:138
Represents a football team.
Definition team.h:47
Training plans of every club and training state of every player.
Definition training.h:242
constexpr uint8_t FREE_AGENTS_TEAM_ID
Team ID reserved for free agents.
Definition global.h:22
Change
Definition squad_numbers.h:42
Contains structures to simplify JSON parsing and loading of player statistics.
Configuration mapping roles to their focus areas and listing all possible stats.
Definition stats_config.h:42
Represents a player listed on the transfer market.
Definition transfer_listing.h:25
Weekly training microcycle, workload, individual focus and tactical familiarity.
uint8_t LeagueID
Type alias for League identifiers.
Definition types.h:15
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21