Player12
An open source football management simulator
Loading...
Searching...
No Matches
lineup.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#include <array>
11#include <span>
12#include <string>
13#include <utility>
14#include <vector>
15
16#include "global/global.h"
17#include "global/types.h"
18#include "player.h"
19#include "strategy.h"
20
26enum class SetPieceDuty : uint8_t
27{
28 Captain,
31 FreeKicks,
35 COUNT
36};
37
38inline constexpr size_t SET_PIECE_DUTY_COUNT =
39 static_cast<size_t>(std::to_underlying(SetPieceDuty::COUNT));
40
42using SetPieceDesignations = std::array<PlayerID, SET_PIECE_DUTY_COUNT>;
43
51namespace SetPieces
52{
54const char* dutyKey(SetPieceDuty duty);
55
57bool isLeadership(SetPieceDuty duty);
58
65float score(SetPieceDuty duty, const Player& player);
66
71const Player* best(SetPieceDuty duty,
72 const std::vector<const Player*>& candidates);
73} // namespace SetPieces
74
84class Lineup
85{
86 public:
90 Lineup();
91
92 // Goalkeeper
97 void setGoalkeeper(const Player* gk);
98
103 const Player* getGoalkeeper() const;
104
105 // Outfield Players
111
117 void addOutfieldPlayer(const Player* player, Vector2F position);
118
125 bool moveOutfieldPlayer(PlayerID playerID, Vector2F newPosition);
126
131 void removeOutfieldPlayer(PlayerID playerID);
132
139 bool removePlayer(PlayerID playerID);
140
147 bool swapPlayers(PlayerID benchPlayerID, PlayerID pitchPlayerID);
148
153 const std::vector<PositionedPlayer>& getOutfieldPlayers() const;
154
155 // Reserves
157 static constexpr size_t MAX_SUBSTITUTES = 9;
158
165 void setReserves(const std::vector<const Player*>& subs);
166
173 static std::vector<const Player*> chooseBench(
174 std::span<const Player* const> candidates);
175
181 bool bringIn(const Player* player, PlayerID replaced);
182
187 const std::vector<const Player*>& getReserves() const;
188
189 // Strategy
194 void setStrategy(const Strategy& strat);
195
200 const Strategy& getStrategy() const;
201
202 // Captain and set-piece takers
205
207 void setDesignated(SetPieceDuty duty, PlayerID playerID);
208
211
214
219 struct StandIn
220 {
223 bool operator==(const StandIn&) const = default;
224 };
225
227 const std::vector<StandIn>& getStandIns() const { return stand_ins; }
228
230 void setStandIns(std::vector<StandIn> values)
231 {
232 stand_ins = std::move(values);
233 }
234
240 static PlayerRole roleAt(Vector2F position);
241
243 std::vector<const Player*> starters() const;
244
246 bool isStarter(PlayerID playerID) const;
247
255 const Player* effectiveTaker(SetPieceDuty duty) const;
256
257 // Debug / visualisation
262 std::string toString() const;
263
270 void generateStartingXI(const class GameData& gamedata,
271 const std::vector<PlayerID>& allPlayerIDs,
272 const StatsConfig& stats_config);
273
277 void clear()
278 {
279 goalkeeper = nullptr;
280 outfield_players.clear();
281 stand_ins.clear();
282 }
283
284 private:
286 std::vector<PositionedPlayer> outfield_players;
287 std::vector<const Player*> reserves;
290 std::vector<StandIn> stand_ins;
291};
292
293/***************************************************************
294 * This is how to visualise the grid where to place the players:
295 *
296 * GK: (always separate, fixed role)
297 *
298 * Row 0 → furthest forward (attacking line)
299 * Row 4 → deepest outfield line (defensive line)
300 *
301 * Example 5×5 grid (row × col):
302 *
303 * (0,0) (0,1) (0,2) (0,3) (0,4)
304 * (1,0) (1,1) (1,2) (1,3) (1,4)
305 * (2,0) (2,1) (2,2) (2,3) (2,4)
306 * (3,0) (3,1) (3,2) (3,3) (3,4)
307 * (4,0) (4,1) (4,2) (4,3) (4,4)
308 *
309 * To place a player in a position, use:
310 * index = row * LINEUP_GRID_COLS + col;
311 *
312 * Example: Striker at (0,2) → index = 0 * 5 + 2 = 2
313 * Left-back at (4,0) → index = 4 * 5 + 0 = 20
314 *
315 ***************************************************************/
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
void clear()
Clears the outfield players and goalkeeper.
Definition lineup.h:277
bool removePlayer(PlayerID playerID)
Drops every reference to a player: goalkeeper, outfield slot, bench and set-piece designations....
Definition lineup.cpp:80
const Player * goalkeeper
Definition lineup.h:285
Lineup()
Constructs a Lineup object.
Definition lineup.cpp:22
void setDesignations(const SetPieceDesignations &designations)
Replaces every designation (persistence).
Definition lineup.cpp:421
bool isStarter(PlayerID playerID) const
True when the player is in the starting XI.
Definition lineup.cpp:436
PlayerID getDesignated(SetPieceDuty duty) const
Designated player of a duty (0 = automatic).
Definition lineup.cpp:396
std::vector< PositionedPlayer > outfield_players
Definition lineup.h:286
const SetPieceDesignations & getDesignations() const
Every designation, indexed by SetPieceDuty.
Definition lineup.cpp:416
void setGoalkeeper(const Player *gk)
Sets the goalkeeper.
Definition lineup.cpp:25
SetPieceDesignations designations
Definition lineup.h:289
const Strategy & getStrategy() const
Gets the strategy for this lineup.
Definition lineup.cpp:298
bool swapPlayers(PlayerID benchPlayerID, PlayerID pitchPlayerID)
Swaps a bench player with an outfield player.
Definition lineup.cpp:136
void setStrategy(const Strategy &strat)
Sets the strategy for this lineup.
Definition lineup.cpp:296
std::vector< const Player * > starters() const
Goalkeeper and outfield players of the XI (no null entries).
Definition lineup.cpp:426
void setStandIns(std::vector< StandIn > values)
Replaces the stand-ins (persistence, matchday fixes).
Definition lineup.h:230
static PlayerRole roleAt(Vector2F position)
The position a slot at position asks for: x from the own goal (defence, holding midfield,...
Definition lineup.cpp:106
static std::vector< const Player * > chooseBench(std::span< const Player *const > candidates)
A matchday bench of at most MAX_SUBSTITUTES from candidates (best first): available players before in...
Definition lineup.cpp:191
const Player * getGoalkeeper() const
Gets the goalkeeper.
Definition lineup.cpp:36
const std::vector< PositionedPlayer > & getOutfieldPlayers() const
Gets all positioned outfield players.
Definition lineup.cpp:131
const std::vector< StandIn > & getStandIns() const
Stand-ins currently filling a regular's place in the XI.
Definition lineup.h:227
void setDesignated(SetPieceDuty duty, PlayerID playerID)
Designates a player (0 = automatic) for a duty.
Definition lineup.cpp:403
Strategy strategy
Definition lineup.h:288
bool bringIn(const Player *player, PlayerID replaced)
Puts player, who is not in the matchday squad, in place of the starter or substitute replaced,...
Definition lineup.cpp:255
void generateStartingXI(const class GameData &gamedata, const std::vector< PlayerID > &allPlayerIDs, const StatsConfig &stats_config)
Generates a starting XI automatically.
Definition lineup.cpp:496
const Player * effectiveTaker(SetPieceDuty duty) const
Who performs a dead-ball duty at kick-off: the designated player when he starts, otherwise the best s...
Definition lineup.cpp:445
void setReserves(const std::vector< const Player * > &subs)
Sets the substitutes. Starters and duplicates are skipped; more than MAX_SUBSTITUTES are cut down wit...
Definition lineup.cpp:169
void addOutfieldPlayer(const Player *player, Vector2F position)
Adds an outfield player to the pitch at the specified coordinate.
Definition lineup.cpp:39
std::vector< StandIn > stand_ins
Definition lineup.h:290
void removeOutfieldPlayer(PlayerID playerID)
Removes an outfield player from the pitch.
Definition lineup.cpp:72
bool moveOutfieldPlayer(PlayerID playerID, Vector2F newPosition)
Updates the position of an existing outfield player.
Definition lineup.cpp:58
std::string toString() const
Converts the lineup to a string representation for debugging.
Definition lineup.cpp:473
static constexpr size_t MAX_SUBSTITUTES
Substitutes named for a match (the top-league norm).
Definition lineup.h:157
const std::vector< const Player * > & getReserves() const
Gets the reserve players.
Definition lineup.cpp:290
std::vector< const Player * > reserves
Definition lineup.h:287
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
Represents the tactical setup of a team for a match.
Definition strategy.h:61
std::array< PlayerID, SET_PIECE_DUTY_COUNT > SetPieceDesignations
Player designated for each duty; 0 = chosen automatically.
Definition lineup.h:42
SetPieceDuty
Leadership and dead-ball duties the manager can hand out (values are persisted in the lineup).
Definition lineup.h:27
constexpr size_t SET_PIECE_DUTY_COUNT
Definition lineup.h:38
Attribute-based suitability of players for set-piece duties.
Definition lineup.h:52
float score(SetPieceDuty duty, const Player &player)
Definition lineup.cpp:341
bool isLeadership(SetPieceDuty duty)
Definition lineup.cpp:335
const Player * best(SetPieceDuty duty, const std::vector< const Player * > &candidates)
Definition lineup.cpp:376
const char * dutyKey(SetPieceDuty duty)
Definition lineup.cpp:310
Definition lineup.h:107
Vector2F position
Definition lineup.h:109
const Player * player
Definition lineup.h:108
A starter who was replaced because he could not play, and the player standing in for him until he can...
Definition lineup.h:220
PlayerID regular
Definition lineup.h:221
bool operator==(const StandIn &) const =default
PlayerID stand_in
Definition lineup.h:222
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
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