Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_changes.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 <array>
12#include <cstddef>
13#include <cstdint>
14#include <span>
15#include <vector>
16
17#include "global/stats_config.h"
18#include "global/types.h"
20#include "model/match_engine.h"
21#include "model/strategy.h"
22
23class Player;
24
33namespace MatchChanges
34{
35
37enum class Refusal : std::uint8_t
38{
39 NONE,
42 LIMIT,
44 WINDOWS,
46 NOT_NOW,
55};
56
58const char* refusalKey(Refusal refusal);
59
61int maxSubstitutions(const MatchEngine& engine);
62
64int maxWindows(const MatchEngine& engine);
65
70Refusal rulesRefusal(const MatchEngine& engine, bool home, int planned);
71
73bool atStoppage(const MatchEngine& engine);
74
81
88
94{
95 public:
101 [[nodiscard]] Refusal check(const MatchEngine& engine, bool home,
102 std::span<const Player* const> bench,
103 PlayerID out, PlayerID in) const;
104
106 Refusal add(const MatchEngine& engine, bool home,
107 std::span<const Player* const> bench, PlayerID out, PlayerID in);
108
110 bool remove(std::size_t index);
111
113 void clear();
114
115 [[nodiscard]] std::span<const PlannedSubstitution> entries() const
116 {
117 return planned;
118 }
119 [[nodiscard]] bool empty() const { return planned.empty(); }
121 [[nodiscard]] bool involves(PlayerID player) const;
123 [[nodiscard]] PlayerID replacementFor(PlayerID out) const;
124
126 void confirm() { confirmed = !planned.empty(); }
127 [[nodiscard]] bool isConfirmed() const { return confirmed; }
128
134 std::vector<SubstitutionOutcome> apply(MatchEngine& engine, bool home,
135 std::span<const Player* const> bench);
136
141 std::vector<SubstitutionOutcome> applyIfDue(
142 MatchEngine& engine, bool home, std::span<const Player* const> bench);
143
144 private:
145 std::vector<PlannedSubstitution> planned;
146 bool confirmed = false;
147};
148
150enum SuggestionReason : std::uint8_t
151{
152 SUGGEST_INJURED = 1U << 0U,
153 SUGGEST_TIRED = 1U << 1U,
154 SUGGEST_BOOKED = 1U << 2U
156
159{
162 std::uint8_t reasons = 0;
164 float condition = 1.0f;
165};
166
174std::vector<Suggestion> suggestSubstitutions(
175 const MatchEngine& engine, bool home, std::span<const Player* const> bench,
176 const SubstitutionPlan& plan, const StatsConfig& config,
177 std::size_t maximum);
178
183float positionFit(PlayerRole substitute, PlayerRole position);
184
187{
188 const char* nameKey;
189 const char* descriptionKey;
191};
192
194inline constexpr std::array<TacticPreset, 4> TACTIC_PRESETS{{
195 {"TACTIC_BALANCED",
196 "TACTIC_BALANCED_HELP",
197 {0.50f, 0.50f, 0.50f, 0.50f, 0.50f}},
198 {"TACTIC_FRONT_FOOT",
199 "TACTIC_FRONT_FOOT_HELP",
200 {0.82f, 0.72f, 0.76f, 0.68f, 0.64f}},
201 {"TACTIC_COUNTER",
202 "TACTIC_COUNTER_HELP",
203 {0.38f, 0.68f, 0.62f, 0.58f, 0.42f}},
204 {"TACTIC_CONTROL",
205 "TACTIC_CONTROL_HELP",
206 {0.62f, 0.34f, 0.44f, 0.72f, 0.72f}},
207}};
208
211{
212 const char* key;
213 const char* id;
215 const char* helpKey;
216};
217
218inline constexpr std::array<SliderInfo, 5> TACTIC_SLIDERS{{
219 {"STRATEGY_PRESSING", "pressing", &StrategySliders::pressing,
220 "TACTIC_PRESSING_HELP"},
221 {"STRATEGY_RISK_TAKING", "risk", &StrategySliders::riskTaking,
222 "TACTIC_RISK_HELP"},
223 {"STRATEGY_OFFENSIVE_BIAS", "offensive", &StrategySliders::offensiveBias,
224 "TACTIC_OFFENSIVE_HELP"},
225 {"STRATEGY_WIDTH_USAGE", "width", &StrategySliders::widthUsage,
226 "TACTIC_WIDTH_HELP"},
227 {"STRATEGY_COMPACTNESS", "compactness", &StrategySliders::compactness,
228 "TACTIC_COMPACTNESS_HELP"},
229}};
230
232bool sameSliders(const StrategySliders& left, const StrategySliders& right);
233
235int detectTacticPreset(const StrategySliders& sliders);
236
238int detectFormation(std::span<const Vector2F> shape);
239
246std::vector<Vector2F> formationFor(const MatchEngine& engine, bool home,
247 const Formation::Preset& preset);
248
253float reshapeCost(std::span<const Vector2F> from, std::span<const Vector2F> to);
254
257{
259 const char* labelKey;
260 const char* hintKey;
261};
262
264inline constexpr std::array<ShoutInfo, 11> SHOUTS{{
265 {MatchShout::ENCOURAGE, "SHOUT_ENCOURAGE", "SHOUT_ENCOURAGE_HINT"},
266 {MatchShout::DEMAND_MORE, "SHOUT_DEMAND_MORE", "SHOUT_DEMAND_MORE_HINT"},
267 {MatchShout::CALM_DOWN, "SHOUT_CALM_DOWN", "SHOUT_CALM_DOWN_HINT"},
268 {MatchShout::PUSH_HIGHER, "SHOUT_PUSH_HIGHER", "SHOUT_PUSH_HIGHER_HINT"},
269 {MatchShout::DROP_DEEPER, "SHOUT_DROP_DEEPER", "SHOUT_DROP_DEEPER_HINT"},
270 {MatchShout::PRESS_MORE, "SHOUT_PRESS_MORE", "SHOUT_PRESS_MORE_HINT"},
271 {MatchShout::STAND_OFF, "SHOUT_STAND_OFF", "SHOUT_STAND_OFF_HINT"},
272 {MatchShout::KEEP_POSSESSION, "SHOUT_KEEP_POSSESSION",
273 "SHOUT_KEEP_POSSESSION_HINT"},
274 {MatchShout::HIT_ON_COUNTER, "SHOUT_HIT_ON_COUNTER",
275 "SHOUT_HIT_ON_COUNTER_HINT"},
276 {MatchShout::WORK_BALL_INTO_BOX, "SHOUT_WORK_BALL_INTO_BOX",
277 "SHOUT_WORK_BALL_INTO_BOX_HINT"},
278 {MatchShout::SHOOT_ON_SIGHT, "SHOUT_SHOOT_ON_SIGHT",
279 "SHOUT_SHOOT_ON_SIGHT_HINT"},
280}};
281
282} // namespace MatchChanges
Substitutions queued by the manager and made together, so they share one stoppage and one window.
Definition match_changes.h:94
std::vector< PlannedSubstitution > planned
Definition match_changes.h:145
bool isConfirmed() const
Definition match_changes.h:127
void clear()
Drops every planned change and the confirmation.
Definition match_changes.cpp:178
bool involves(PlayerID player) const
The player is leaving or coming on in a planned change.
Definition match_changes.cpp:184
void confirm()
Hands the plan to the referee: made at the next stoppage.
Definition match_changes.h:126
std::span< const PlannedSubstitution > entries() const
Definition match_changes.h:115
std::vector< SubstitutionOutcome > apply(MatchEngine &engine, bool home, std::span< const Player *const > bench)
Makes every planned change now, in order, without advancing the engine in between (so they count as o...
Definition match_changes.cpp:199
std::vector< SubstitutionOutcome > applyIfDue(MatchEngine &engine, bool home, std::span< const Player *const > bench)
apply() once the plan is confirmed and play has stopped; nothing (an empty result) otherwise.
Definition match_changes.cpp:223
PlayerID replacementFor(PlayerID out) const
Planned replacement of an outgoing player (0 when none).
Definition match_changes.cpp:192
bool remove(std::size_t index)
Drops one planned change (false for a bad index).
Definition match_changes.cpp:170
Refusal add(const MatchEngine &engine, bool home, std::span< const Player *const > bench, PlayerID out, PlayerID in)
check() and, when allowed, appends the change.
Definition match_changes.cpp:161
bool confirmed
Definition match_changes.h:146
Refusal check(const MatchEngine &engine, bool home, std::span< const Player *const > bench, PlayerID out, PlayerID in) const
Whether out can be replaced by in given the rules and the changes already planned (nothing is added).
Definition match_changes.cpp:145
bool empty() const
Definition match_changes.h:119
Definition match_engine.h:517
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
MatchShout
Definition match_engine.h:333
@ WORK_BALL_INTO_BOX
Touchline decisions of the live match, independent of the widgets: planned substitutions made togethe...
Definition match_changes.cpp:20
float reshapeCost(std::span< const Vector2F > from, std::span< const Vector2F > to)
Tactical familiarity the side gives up for a while when its shape changes from from to to,...
Definition match_changes.cpp:431
constexpr std::array< ShoutInfo, 11 > SHOUTS
Every shout, in bar order (Shift+1 .. Shift+0, Shift+-).
Definition match_changes.h:264
Refusal rulesRefusal(const MatchEngine &engine, bool home, int planned)
Refusal from the match rules alone (limit, windows, full time) for one more change when planned chang...
Definition match_changes.cpp:101
std::vector< Vector2F > formationFor(const MatchEngine &engine, bool home, const Formation::Preset &preset)
The side's current shape rearranged as preset: each occupied slot gets the preset position that best ...
Definition match_changes.cpp:373
const char * refusalKey(Refusal refusal)
Language key explaining a refusal (LIMIT and WINDOWS take d).
Definition match_changes.cpp:74
int detectFormation(std::span< const Vector2F > shape)
Index of the formation preset with this shape, or -1 (custom).
Definition match_changes.cpp:343
constexpr std::array< SliderInfo, 5 > TACTIC_SLIDERS
Definition match_changes.h:218
float positionFit(PlayerRole substitute, PlayerRole position)
Suitability of a substitute for the outgoing player's position in [0, 1] (the natural role fit,...
Definition match_changes.cpp:230
int detectTacticPreset(const StrategySliders &sliders)
Index of the preset with these sliders, or -1 (custom).
Definition match_changes.cpp:335
Refusal
Why a change cannot be made (NONE when it can).
Definition match_changes.h:38
constexpr std::array< TacticPreset, 4 > TACTIC_PRESETS
Balanced, front foot, counter and control.
Definition match_changes.h:194
SuggestionReason
Reasons behind a suggested substitution (bit flags).
Definition match_changes.h:151
@ SUGGEST_BOOKED
Definition match_changes.h:154
@ SUGGEST_TIRED
Definition match_changes.h:153
@ SUGGEST_INJURED
Definition match_changes.h:152
bool atStoppage(const MatchEngine &engine)
Play is stopped: planned changes can be made without waiting.
Definition match_changes.cpp:131
bool sameSliders(const StrategySliders &left, const StrategySliders &right)
Every slider within a small tolerance.
Definition match_changes.cpp:324
int maxWindows(const MatchEngine &engine)
Substitution windows of a side in this match (one more in ET).
Definition match_changes.cpp:123
std::vector< Suggestion > suggestSubstitutions(const MatchEngine &engine, bool home, std::span< const Player *const > bench, const SubstitutionPlan &plan, const StatsConfig &config, std::size_t maximum)
Up to maximum substitutions the assistant would make now: injured players first, then tired ones and ...
Definition match_changes.cpp:235
int maxSubstitutions(const MatchEngine &engine)
Substitutions a side may make in this match (one more in ET).
Definition match_changes.cpp:115
int index
Definition runtime_editor.cpp:94
std::int64_t maximum
Definition runtime_editor_validation.cpp:47
Contains structures to simplify JSON parsing and loading of player statistics.
A named arrangement of ten outfield slots.
Definition formation.h:40
One planned substitution.
Definition match_changes.h:77
PlayerID in
Definition match_changes.h:79
PlayerID out
Definition match_changes.h:78
One touchline shout: its labels and keyboard slot.
Definition match_changes.h:257
MatchShout shout
Definition match_changes.h:258
const char * labelKey
Definition match_changes.h:259
const char * hintKey
Definition match_changes.h:260
One strategy slider: label, help and the member it edits.
Definition match_changes.h:211
float StrategySliders::* value
Definition match_changes.h:214
const char * helpKey
Definition match_changes.h:215
const char * key
Definition match_changes.h:212
const char * id
Definition match_changes.h:213
Result of one planned change once it was attempted.
Definition match_changes.h:84
PlannedSubstitution change
Definition match_changes.h:85
Refusal refusal
Definition match_changes.h:86
The assistant's proposal: replace out with in.
Definition match_changes.h:159
PlayerID in
Definition match_changes.h:161
PlayerID out
Definition match_changes.h:160
std::uint8_t reasons
Definition match_changes.h:162
float condition
Definition match_changes.h:164
A named set of the five strategy sliders.
Definition match_changes.h:187
const char * nameKey
Definition match_changes.h:188
StrategySliders sliders
Definition match_changes.h:190
const char * descriptionKey
Definition match_changes.h:189
Configuration mapping roles to their focus areas and listing all possible stats.
Definition stats_config.h:42
Team-wide tactical preferences in [0, 1].
Definition strategy.h:27
float pressing
Definition strategy.h:28
float widthUsage
Definition strategy.h:33
float compactness
Definition strategy.h:34
float riskTaking
Definition strategy.h:29
float offensiveBias
Definition strategy.h:31
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21
PlayerRole
Represents a specific tactical role on the pitch.
Definition types.h:63