Player12
An open source football management simulator
Loading...
Searching...
No Matches
match.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 <functional>
14#include <optional>
15#include <span>
16#include <utility>
17#include <vector>
18
19#include "gamedate.h"
20#include "global/stats_config.h"
21#include "global/types.h"
22
23class GameData;
24class Lineup;
25class MatchEngine;
26class MedicalDesk;
27class Player;
28struct MatchReport;
32
37class Match
38{
39 public:
50 Match(TeamID home_id, TeamID away_id, GameDateValue date, MatchType type,
51 LeagueID competition = 0, uint8_t stage = 0);
52
64 void simulate(const GameData& game_data, MatchReport* report = nullptr,
65 std::vector<PlayerMatchConsequence>* consequences = nullptr);
66
72 std::optional<MatchSimulationInput> prepareSimulation(
73 const GameData& game_data) const;
74
80
85 TeamID getHomeTeamId() const;
86
91 TeamID getAwayTeamId() const;
92
97 uint8_t getHomeScore() const;
98
103 uint8_t getAwayScore() const;
104
109 MatchType getMatchType() const;
110
115 const GameDateValue& getDate() const;
116
121 bool isPlayed() const;
122
123 void setPlayedResult(uint8_t h, uint8_t a);
124
126 void setKnockoutResult(uint8_t h, uint8_t a, bool extra_time,
127 std::optional<std::pair<uint8_t, uint8_t>> penalties);
128
134 uint16_t getKickoff() const;
136 void setKickoff(uint16_t minutes) { kickoff = minutes; }
138 uint16_t getScheduledKickoff() const { return kickoff; }
139
142 uint8_t getStage() const { return stage; }
143
145 bool isKnockout() const { return match_type == MatchType::CUP; }
146 bool wentToExtraTime() const { return extra_time; }
147 bool wentToPenalties() const { return penalties; }
148 uint8_t getHomePenalties() const { return home_penalties; }
149 uint8_t getAwayPenalties() const { return away_penalties; }
150
152 std::optional<TeamID> getWinnerId() const;
153
155 uint32_t getSeed() const;
156
158 void writeResultTo(MatchReport& report) const;
159
160 private:
165 uint8_t home_score;
166 uint8_t away_score = 0;
168 uint8_t stage;
169 uint16_t kickoff = 0;
170 uint8_t home_penalties = 0;
171 uint8_t away_penalties = 0;
172 bool extra_time = false;
173 bool penalties = false;
174 bool _played = false;
175};
176
183{
184using Eligibility = std::function<bool(const Player&)>;
185
187std::vector<PlayerID> ineligible(const Lineup& lineup,
188 const Eligibility& eligible);
189
194float slotScore(const Player& player, PlayerRole slot,
195 const StatsConfig& config);
196
204std::size_t replaceIneligible(Lineup& lineup,
205 std::span<const Player* const> squad,
206 const Eligibility& eligible,
207 const StatsConfig& config);
208
218std::size_t recallRegulars(Lineup& lineup, std::span<const Player* const> squad,
219 const Eligibility& eligible,
220 const StatsConfig& config);
221
227void recordStandIns(const Lineup& before, Lineup& after);
228
233std::vector<std::pair<PlayerID, PlayerID>> replacements(const Lineup& before,
234 const Lineup& after);
235
238void carryCondition(MatchEngine& engine, const Lineup& lineup);
239
241std::vector<PlayerMatchConsequence> consequences(const MatchEngine& engine);
242
245std::vector<std::pair<PlayerID, std::uint8_t>> medicalFlags(
246 const MedicalDesk& medical, const Lineup& lineup);
247} // namespace MatchdaySquad
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Manages the starting XI and reserves of a team.
Definition lineup.h:85
Definition match_engine.h:517
Represents a football match between two teams.
Definition match.h:38
void setCompetitionId(LeagueID id)
Definition match.h:141
MatchReport applySimulation(MatchSimulationResult result)
Definition match.cpp:110
uint16_t getKickoff() const
Definition match.cpp:47
bool isPlayed() const
Checks if the match has been played.
Definition match.cpp:185
const GameDateValue & getDate() const
Gets the date of the match.
Definition match.cpp:183
std::optional< TeamID > getWinnerId() const
Definition match.cpp:139
void setKickoff(uint16_t minutes)
Definition match.h:136
uint8_t away_penalties
Definition match.h:171
void writeResultTo(MatchReport &report) const
Definition match.cpp:149
uint8_t getAwayScore() const
Gets the away team's score.
Definition match.cpp:181
uint8_t stage
Definition match.h:168
LeagueID competition_id
Definition match.h:167
uint8_t getStage() const
Definition match.h:142
uint8_t getHomePenalties() const
Definition match.h:148
uint8_t getHomeScore() const
Gets the home team's score.
Definition match.cpp:180
TeamID home_team_id
Definition match.h:161
uint8_t home_score
Definition match.h:165
LeagueID getCompetitionId() const
Definition match.h:140
uint32_t getSeed() const
Definition match.cpp:39
void setPlayedResult(uint8_t h, uint8_t a)
Definition match.cpp:121
std::optional< MatchSimulationInput > prepareSimulation(const GameData &game_data) const
Definition match.cpp:83
bool penalties
Definition match.h:173
TeamID away_team_id
Definition match.h:162
uint16_t getScheduledKickoff() const
Definition match.h:138
TeamID getAwayTeamId() const
Gets the ID of the away team.
Definition match.cpp:179
bool isKnockout() const
Definition match.h:145
uint16_t kickoff
Definition match.h:169
MatchType getMatchType() const
Gets the type of the match.
Definition match.cpp:182
uint8_t away_score
Definition match.h:166
TeamID getHomeTeamId() const
Gets the ID of the home team.
Definition match.cpp:178
void simulate(const GameData &game_data, MatchReport *report=nullptr, std::vector< PlayerMatchConsequence > *consequences=nullptr)
Simulates the match using the provided game data.
Definition match.cpp:70
bool extra_time
Definition match.h:172
bool wentToExtraTime() const
Definition match.h:146
void setKnockoutResult(uint8_t h, uint8_t a, bool extra_time, std::optional< std::pair< uint8_t, uint8_t > > penalties)
Definition match.cpp:128
uint8_t home_penalties
Definition match.h:170
MatchType match_type
Definition match.h:164
bool wentToPenalties() const
Definition match.h:147
GameDateValue match_date
Definition match.h:163
uint8_t getAwayPenalties() const
Definition match.h:149
bool _played
Definition match.h:174
The medical staff's day-to-day work for the managed club: rest and minute-limit instructions,...
Definition medical_centre.h:200
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
Definition match.h:183
std::size_t recallRegulars(Lineup &lineup, std::span< const Player *const > squad, const Eligibility &eligible, const StatsConfig &config)
Definition match.cpp:432
void recordStandIns(const Lineup &before, Lineup &after)
Definition match.cpp:473
std::function< bool(const Player &)> Eligibility
Definition match.h:184
std::vector< PlayerID > ineligible(const Lineup &lineup, const Eligibility &eligible)
Definition match.cpp:275
std::vector< std::pair< PlayerID, PlayerID > > replacements(const Lineup &before, const Lineup &after)
Definition match.cpp:497
std::vector< PlayerMatchConsequence > consequences(const MatchEngine &engine)
Definition match.cpp:554
void carryCondition(MatchEngine &engine, const Lineup &lineup)
Definition match.cpp:539
std::vector< std::pair< PlayerID, std::uint8_t > > medicalFlags(const MedicalDesk &medical, const Lineup &lineup)
Definition match.cpp:523
std::size_t replaceIneligible(Lineup &lineup, std::span< const Player *const > squad, const Eligibility &eligible, const StatsConfig &config)
Definition match.cpp:290
float slotScore(const Player &player, PlayerRole slot, const StatsConfig &config)
Definition match.cpp:268
Contains structures to simplify JSON parsing and loading of player statistics.
Represents a specific date in the game world.
Definition gamedate.h:20
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
Definition match_scheduler.h:37
Definition match_scheduler.h:72
Physical outcome of one player's match.
Definition world_simulation.h:58
Configuration mapping roles to their focus areas and listing all possible stats.
Definition stats_config.h:42
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
PlayerRole
Represents a specific tactical role on the pitch.
Definition types.h:63