Player12
An open source football management simulator
Loading...
Searching...
No Matches
game.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <cstddef>
12#include <cstdint>
13#include <map>
14#include <memory>
15#include <optional>
16#include <span>
17#include <string>
18#include <utility>
19#include <vector>
20
23#include "model/calendar.h"
25#include "model/gamedate.h"
26#include "model/guidance.h"
28#include "model/match.h"
29#include "model/match_report.h"
32#include "model/national_job.h"
34#include "model/season_review.h"
35#include "model/supporters.h"
38
47class Game
48{
49 public:
55 explicit Game(std::shared_ptr<class GameData> gd,
56 std::shared_ptr<DatabaseConnection> conn);
57
62 void advanceDay();
63
65 bool setMatchResult(const GameDateValue& date, TeamID home_id, TeamID away_id,
66 uint8_t home_score, uint8_t away_score);
67
75 bool setMatchResult(
76 const GameDateValue& date, TeamID home_id, TeamID away_id,
77 MatchReport report,
78 std::span<const PlayerMatchConsequence> consequences = {});
79
82 bool isEligible(const Player& player, MatchType type,
83 std::optional<GameDateValue> date = std::nullopt) const;
85 std::vector<PlayerID> ineligibleSelections(TeamID team_id,
86 MatchType type) const;
100 std::size_t fixMatchdaySquad(
101 TeamID team_id, MatchType type,
102 std::optional<GameDateValue> date = std::nullopt);
104 std::vector<std::pair<PlayerID, PlayerID>> previewMatchdaySquadFix(
105 TeamID team_id, MatchType type) const;
111 bool canKickOff(TeamID team_id, MatchType type) const;
125
128 const CareerGuidance& getGuidance() const { return guidance; }
129
132 const MedicalDesk& getMedical() const { return medical; }
134 const Supporters& getSupporters() const { return supporters; }
135
138
142
144 int youngRegulars(TeamID team_id) const;
146 struct CupRun
147 {
150 std::optional<int> rounds_left;
151 bool won = false;
152 bool still_in = false;
153 };
154 CupRun cupRun(TeamID team_id) const;
155
159
165 {
167 }
168
171 const WorldSimulation& getWorld() const { return world; }
172
175 const TransferMarket& getTransfers() const { return transfers; }
176
179 const ManagerCareer& getCareer() const { return career; }
182 {
183 return last_career_events;
184 }
185
193
200 void takeJob(TeamID team_id, const ManagerContract& contract);
201
212 void setSimulationThreads(unsigned threads)
213 {
214 scheduler.setThreadCount(threads);
215 }
216 unsigned getSimulationThreads() const { return scheduler.getThreadCount(); }
217
222 const GameDateValue& getCurrentDate() const;
223
228 const Calendar& getCalendar() const;
230
235 int getCurrentSeason() const;
236
241 uint16_t getManagedTeamId() const;
242
251 void setManagedTeamId(uint16_t id);
252
257 void saveGame();
258
259 private:
260 void loadGame();
261 void endSeason();
263 void startNewSeason();
267 const std::map<LeagueID, std::vector<StandingRow>>& final_tables,
268 std::uint16_t start_year);
270 void judgeSeason(std::span<const SeasonHistoryEntry> finished);
272 void finishSeasonReview();
275 void fillLineupGap(Team& team, const Player& departed);
277 void postLineupRepairs();
279 std::vector<UpcomingFixture> upcomingFixtures(TeamID team_id) const;
280
286 std::size_t fillMatchdaySquad(Lineup& lineup, TeamID team_id, MatchType type,
287 const GameDateValue& date,
288 bool recall_regulars) const;
289
291 void runCareerDay();
293 void recordCareerMatch(const Match& match);
294
295 // Matchday simulation helper
296 void simulateMatches(std::vector<Match>& matches,
297 bool include_managed = false);
304 void settleLevelTie(Match& match, MatchReport& report);
305
306 std::shared_ptr<DatabaseConnection> db_conn;
307 std::unique_ptr<RuntimeEditor::Extensions> extensions;
310 void discoverExtensions();
311 void serialize(bool probe);
312 std::shared_ptr<class GameData> gamedata;
324 uint8_t current_season = 1;
330 std::optional<SeasonReview> closing_review;
332 std::vector<std::pair<std::string, std::string>> lineup_repairs;
333};
Manages the match calendar for a season.
Definition calendar.h:133
Per-career state of the guidance features: first-week checklist, delegation policy,...
Definition guidance.h:32
DelegationPolicy delegation
Definition guidance.h:38
Owns the result pipeline of all competitions.
Definition competition_manager.h:40
bool delegated(Duty duty) const
Definition delegation.h:70
bool set(Duty duty, DutyOwner owner)
Definition delegation.cpp:66
Represents the core game state and logic.
Definition game.h:48
bool getAssistantFixesLineup() const
Definition game.h:121
bool canKickOff(TeamID team_id, MatchType type) const
Definition game.cpp:579
ManagerCareer & getCareer()
Definition game.h:178
Calendar calendar
Definition game.h:313
std::vector< std::pair< PlayerID, PlayerID > > previewMatchdaySquadFix(TeamID team_id, MatchType type) const
Definition game.cpp:568
const CareerDayEvents & getLastCareerEvents() const
Definition game.h:181
NationalDayEvents last_national_events
Definition game.h:321
uint16_t getManagedTeamId() const
Retrieves the ID of the team currently managed by the user.
Definition game.cpp:760
std::size_t fixMatchdaySquad(TeamID team_id, MatchType type, std::optional< GameDateValue > date=std::nullopt)
Definition game.cpp:559
void startNewSeason()
Definition game.cpp:740
WorldSimulation world
Definition game.h:315
TransferMarket & getTransfers()
Definition game.h:174
SeasonArchive season_archive
Definition game.h:329
void advanceDay()
Advances the game time by one day, simulating any matches or events scheduled for the current date.
Definition game.cpp:287
const NationalTeams & getNationalTeams() const
Definition game.h:157
std::optional< SeasonReview > closing_review
Definition game.h:330
int youngRegulars(TeamID team_id) const
Definition game_season.cpp:32
bool setMatchResult(const GameDateValue &date, TeamID home_id, TeamID away_id, uint8_t home_score, uint8_t away_score)
Definition game.cpp:487
void takeJob(TeamID team_id, const ManagerContract &contract)
Definition game.cpp:791
SeasonArchive & getSeasonArchive()
Definition game.h:141
ManagerCareer career
Definition game.h:317
Supporters supporters
Definition game.h:328
NationalManagement & getNationalJob()
Definition game.h:161
CompetitionManager competitions
Definition game.h:314
void setSimulationThreads(unsigned threads)
Definition game.h:212
std::shared_ptr< class GameData > gamedata
Definition game.h:312
void finishSeasonReview()
Definition game_season.cpp:240
MatchScheduler scheduler
Definition game.h:322
NationalManagement national_job
Definition game.h:320
void postLineupRepairs()
Definition game_season.cpp:78
NationalTeams international
Definition game.h:319
std::vector< PlayerID > ineligibleSelections(TeamID team_id, MatchType type) const
Definition game.cpp:549
const GameDateValue & getCurrentDate() const
Retrieves the current in-game date.
Definition game.cpp:752
const SeasonArchive & getSeasonArchive() const
Definition game.h:140
const Calendar & getCalendar() const
Retrieves the calendar containing all fixtures.
Definition game.cpp:754
std::unique_ptr< RuntimeEditor::Extensions > extensions
Definition game.h:307
const Supporters & getSupporters() const
Definition game.h:134
const WorldSimulation & getWorld() const
Definition game.h:171
const CareerGuidance & getGuidance() const
Definition game.h:128
void resetSimulationProgress()
Definition game.h:210
void leaveManagedTeam(DepartureReason reason)
Definition game.cpp:769
uint16_t managed_team_id
Definition game.h:325
void setAssistantFixesLineup(bool enabled)
Definition game.h:116
uint8_t current_season
Definition game.h:324
void discoverExtensions()
Definition game.cpp:141
void saveGame()
Saves the current game state, including calendar and game variables, to the database.
Definition game.cpp:224
unsigned getSimulationThreads() const
Definition game.h:216
bool isEligible(const Player &player, MatchType type, std::optional< GameDateValue > date=std::nullopt) const
Definition game.cpp:540
void loadGame()
Definition game.cpp:168
void serialize(bool probe)
Definition game.cpp:226
TransferMarket transfers
Definition game.h:316
int extensions_version
Definition game.h:308
void setManagedTeamId(uint16_t id)
Sets the team managed by the user.
Definition game.cpp:762
MedicalDesk & getMedical()
Definition game.h:131
std::shared_ptr< DatabaseConnection > db_conn
Definition game.h:306
void fillLineupGap(Team &team, const Player &departed)
Definition game_season.cpp:63
const NationalManagement & getNationalJob() const
Definition game.h:162
void handleSeasonTransition()
Definition game.cpp:734
const MedicalDesk & getMedical() const
Definition game.h:132
void endSeason()
Definition game.cpp:666
std::vector< UpcomingFixture > upcomingFixtures(TeamID team_id) const
Definition game.cpp:833
std::vector< std::pair< std::string, std::string > > lineup_repairs
Definition game.h:332
const NationalDayEvents & getLastNationalEvents() const
Definition game.h:164
CareerDayEvents last_career_events
Definition game.h:318
CareerGuidance guidance
Definition game.h:326
void simulateMatches(std::vector< Match > &matches, bool include_managed=false)
Definition game.cpp:356
CupRun cupRun(TeamID team_id) const
Definition game_season.cpp:43
WorldSimulation & getWorld()
Definition game.h:170
SimulationProgress getSimulationProgress() const
Definition game.h:206
const CompetitionManager & getCompetitions() const
Definition game.h:137
std::size_t fillMatchdaySquad(Lineup &lineup, TeamID team_id, MatchType type, const GameDateValue &date, bool recall_regulars) const
Definition game.cpp:587
const ManagerCareer & getCareer() const
Definition game.h:179
const TransferMarket & getTransfers() const
Definition game.h:175
void settleLevelTie(Match &match, MatchReport &report)
Definition game.cpp:457
void beginSeasonReview(const std::map< LeagueID, std::vector< StandingRow > > &final_tables, std::uint16_t start_year)
Definition game_season.cpp:106
int getCurrentSeason() const
Retrieves the current season number.
Definition game.cpp:758
RuntimeEditor::Payloads payload_extensions
Definition game.h:309
NationalTeams & getNationalTeams()
Definition game.h:158
GameDateValue currentDate
Definition game.h:323
void runCareerDay()
Definition game.cpp:806
CareerGuidance & getGuidance()
Definition game.h:127
void judgeSeason(std::span< const SeasonHistoryEntry > finished)
Definition game_season.cpp:167
void keepManagedSelectionEligible()
Definition game.cpp:336
void recordCareerMatch(const Match &match)
Definition game.cpp:818
MedicalDesk medical
Definition game.h:327
Manages the starting XI and reserves of a team.
Definition lineup.h:85
The human manager's career and the market for managers.
Definition manager_career.h:415
Simulates a batch of independent matches in parallel.
Definition match_scheduler.h:115
void setThreadCount(unsigned thread_count)
Definition match_scheduler.cpp:119
void resetProgress()
Definition match_scheduler.h:130
SimulationProgress getProgress() const
Definition match_scheduler.h:136
unsigned getThreadCount() const
Definition match_scheduler.h:122
Represents a football match between two teams.
Definition match.h:38
The medical staff's day-to-day work for the managed club: rest and minute-limit instructions,...
Definition medical_centre.h:200
National-team jobs of the human manager: vacancies, applications and offers, the job itself (results,...
Definition national_job.h:160
National-team calendar, call-ups, matches and records.
Definition national_teams.h:212
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
Definition runtime_editor.h:142
Final league tables of past seasons and the managed club's season reviews (tables SeasonTables and Se...
Definition season_review.h:175
The managed club's supporters: their mood is recomputed once a week from the facts and nudges the boa...
Definition supporters.h:114
Represents a football team.
Definition team.h:47
Deals, loans, pre-contracts, payments and history of the market.
Definition transfer_market.h:221
Everything that happens between matches.
Definition world_simulation.h:104
@ LineupFixes
const GameDateValue START_DATE(2025, 7, 2)
The starting date of the game.
DepartureReason
Why a spell in charge ended (values are persisted).
Definition manager_career.h:75
What changed during one simulated day.
Definition manager_career.h:302
Represents a specific date in the game world.
Definition gamedate.h:20
Definition game.h:147
bool still_in
Definition game.h:152
bool won
Definition game.h:151
std::optional< int > rounds_left
Definition game.h:150
Terms of a manager's employment.
Definition manager_career.h:104
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
What changed on the latest simulated day.
Definition national_job.h:107
Definition match_scheduler.h:102
MatchType
Represents the type or category of a match.
Definition types.h:40
uint8_t LeagueID
Type alias for League identifiers.
Definition types.h:15
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18