Player12
An open source football management simulator
Loading...
Searching...
No Matches
formation.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 <span>
13#include <unordered_set>
14#include <vector>
15
16#include "global/stats_config.h"
17#include "global/types.h"
18
19class Lineup;
20class Player;
21
28namespace Formation
29{
30
37
39struct Preset
40{
41 const char* name;
42 std::array<Slot, 10> slots;
43};
44
46extern const std::array<Preset, 5> PRESETS;
47
53float roleFit(PlayerRole actual, PlayerRole expected);
54
59void applyPreset(Lineup& lineup, const Preset& preset,
60 const StatsConfig& config);
61
66void autoPick(Lineup& lineup, const Preset& preset,
67 std::span<const Player* const> squad, const StatsConfig& config);
68
73void autoPickAvailable(Lineup& lineup, const Preset& preset,
74 std::span<const Player* const> squad,
75 const std::unordered_set<PlayerID>& unavailable,
76 const StatsConfig& config);
77
79size_t unavailableStarters(const Lineup& lineup,
80 const std::unordered_set<PlayerID>& unavailable);
81
86int detectPreset(const Lineup& lineup);
87
88} // namespace Formation
Manages the starting XI and reserves of a team.
Definition lineup.h:85
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
Formation presets and XI selection built on the Lineup API.
Definition formation.cpp:95
const std::array< Preset, 5 > PRESETS
4-4-2, 4-3-3, 4-2-3-1, 3-5-2 and 5-3-2.
Definition formation.cpp:98
int detectPreset(const Lineup &lineup)
Index of the preset matching the current positions, or -1 when the shape has been customised.
Definition formation.cpp:251
size_t unavailableStarters(const Lineup &lineup, const std::unordered_set< PlayerID > &unavailable)
Selected starters (goalkeeper and outfield) found in the set.
Definition formation.cpp:238
void autoPickAvailable(Lineup &lineup, const Preset &preset, std::span< const Player *const > squad, const std::unordered_set< PlayerID > &unavailable, const StatsConfig &config)
autoPick() that leaves unavailable players (injured, suspended) out of the matchday squad (the lineup...
Definition formation.cpp:226
void applyPreset(Lineup &lineup, const Preset &preset, const StatsConfig &config)
Moves the current outfield players into the preset's slots, keeping the same eleven and matching play...
Definition formation.cpp:149
void autoPick(Lineup &lineup, const Preset &preset, std::span< const Player *const > squad, const StatsConfig &config)
Chooses the best goalkeeper and ten outfield players from the squad for the preset,...
Definition formation.cpp:177
float roleFit(PlayerRole actual, PlayerRole expected)
How well a player's natural role suits a slot role, in [0, 1]. 1 means natural; adjacent roles score ...
Definition formation.cpp:122
Contains structures to simplify JSON parsing and loading of player statistics.
A named arrangement of ten outfield slots.
Definition formation.h:40
const char * name
Definition formation.h:41
std::array< Slot, 10 > slots
Definition formation.h:42
One outfield slot of a formation.
Definition formation.h:33
PlayerRole role
Definition formation.h:34
Vector2F position
Definition formation.h:35
Configuration mapping roles to their focus areas and listing all possible stats.
Definition stats_config.h:42
A simple 2D float vector for pitch coordinates.
Definition types.h:84
PlayerRole
Represents a specific tactical role on the pitch.
Definition types.h:63