Player12
An open source football management simulator
Loading...
Searching...
No Matches
Lineup Class Reference

Manages the starting XI and reserves of a team. More...

#include <lineup.h>

Classes

struct  PositionedPlayer
 
struct  StandIn
 A starter who was replaced because he could not play, and the player standing in for him until he can. More...
 

Public Member Functions

 Lineup ()
 Constructs a Lineup object.
 
void setGoalkeeper (const Player *gk)
 Sets the goalkeeper.
 
const Player * getGoalkeeper () const
 Gets the goalkeeper.
 
void addOutfieldPlayer (const Player *player, Vector2F position)
 Adds an outfield player to the pitch at the specified coordinate.
 
bool moveOutfieldPlayer (PlayerID playerID, Vector2F newPosition)
 Updates the position of an existing outfield player.
 
void removeOutfieldPlayer (PlayerID playerID)
 Removes an outfield player from the pitch.
 
bool removePlayer (PlayerID playerID)
 Drops every reference to a player: goalkeeper, outfield slot, bench and set-piece designations. Call it before the Player object is destroyed, since the lineup holds raw pointers.
 
bool swapPlayers (PlayerID benchPlayerID, PlayerID pitchPlayerID)
 Swaps a bench player with an outfield player.
 
const std::vector< PositionedPlayer > & getOutfieldPlayers () const
 Gets all positioned outfield players.
 
void setReserves (const std::vector< const Player * > &subs)
 Sets the substitutes. Starters and duplicates are skipped; more than MAX_SUBSTITUTES are cut down with chooseBench() (pass the candidates best first).
 
bool bringIn (const Player *player, PlayerID replaced)
 Puts player, who is not in the matchday squad, in place of the starter or substitute replaced, who leaves the squad.
 
const std::vector< const Player * > & getReserves () const
 Gets the reserve players.
 
void setStrategy (const Strategy &strat)
 Sets the strategy for this lineup.
 
const Strategy & getStrategy () const
 Gets the strategy for this lineup.
 
PlayerID getDesignated (SetPieceDuty duty) const
 Designated player of a duty (0 = automatic).
 
void setDesignated (SetPieceDuty duty, PlayerID playerID)
 Designates a player (0 = automatic) for a duty.
 
const SetPieceDesignations & getDesignations () const
 Every designation, indexed by SetPieceDuty.
 
void setDesignations (const SetPieceDesignations &designations)
 Replaces every designation (persistence).
 
const std::vector< StandIn > & getStandIns () const
 Stand-ins currently filling a regular's place in the XI.
 
void setStandIns (std::vector< StandIn > values)
 Replaces the stand-ins (persistence, matchday fixes).
 
std::vector< const Player * > starters () const
 Goalkeeper and outfield players of the XI (no null entries).
 
bool isStarter (PlayerID playerID) const
 True when the player is in the starting XI.
 
const Player * effectiveTaker (SetPieceDuty duty) const
 Who performs a dead-ball duty at kick-off: the designated player when he starts, otherwise the best starter for it (SetPieces::best). Leadership duties return the designated captain when he starts (the designated vice-captain stands in for an absent one), else nullptr: an automatic captain comes from the dressing-room hierarchy.
 
std::string toString () const
 Converts the lineup to a string representation for debugging.
 
void generateStartingXI (const class GameData &gamedata, const std::vector< PlayerID > &allPlayerIDs, const StatsConfig &stats_config)
 Generates a starting XI automatically.
 
void clear ()
 Clears the outfield players and goalkeeper.
 

Static Public Member Functions

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 injured ones, a reserve goalkeeper and one defender, midfielder and forward as cover, then the rest in order.
 
static PlayerRole roleAt (Vector2F position)
 The position a slot at position asks for: x from the own goal (defence, holding midfield, midfield, attacking midfield, attack), y from the left touchline (left flank, centre, right flank).
 

Static Public Attributes

static constexpr size_t MAX_SUBSTITUTES = 9
 Substitutes named for a match (the top-league norm).
 

Private Attributes

const Player * goalkeeper
 
std::vector< PositionedPlayer > outfield_players
 
std::vector< const Player * > reserves
 
Strategy strategy
 
SetPieceDesignations designations {}
 
std::vector< StandIn > stand_ins
 

Detailed Description

Manages the starting XI and reserves of a team.

This class will manage the starting 11 of the team, the reserves, possibly changing depending on the type of competition of the next match, the strategy and tactics of the team.

Constructor & Destructor Documentation

◆ Lineup()

Lineup::Lineup ( )

Constructs a Lineup object.

Member Function Documentation

◆ addOutfieldPlayer()

void Lineup::addOutfieldPlayer ( const Player *  player,
Vector2F  position 
)

Adds an outfield player to the pitch at the specified coordinate.

Parameters
playerPointer to the Player object.
positionThe position on the pitch (x, y in [0.0, 1.0]).

◆ bringIn()

bool Lineup::bringIn ( const Player *  player,
PlayerID  replaced 
)

Puts player, who is not in the matchday squad, in place of the starter or substitute replaced, who leaves the squad.

Returns
false when player is already selected or replaced is not.

◆ chooseBench()

std::vector< const Player * > Lineup::chooseBench ( std::span< const Player *const >  candidates)
static

A matchday bench of at most MAX_SUBSTITUTES from candidates (best first): available players before injured ones, a reserve goalkeeper and one defender, midfielder and forward as cover, then the rest in order.

◆ clear()

void Lineup::clear ( )
inline

Clears the outfield players and goalkeeper.

◆ effectiveTaker()

const Player * Lineup::effectiveTaker ( SetPieceDuty  duty) const

Who performs a dead-ball duty at kick-off: the designated player when he starts, otherwise the best starter for it (SetPieces::best). Leadership duties return the designated captain when he starts (the designated vice-captain stands in for an absent one), else nullptr: an automatic captain comes from the dressing-room hierarchy.

◆ generateStartingXI()

void Lineup::generateStartingXI ( const class GameData &  gamedata,
const std::vector< PlayerID > &  allPlayerIDs,
const StatsConfig &  stats_config 
)

Generates a starting XI automatically.

Parameters
gamedataThe game data containing player information.
allPlayerIDsA vector of all available player IDs.
stats_configThe stats configuration for evaluating players.

◆ getDesignated()

PlayerID Lineup::getDesignated ( SetPieceDuty  duty) const

Designated player of a duty (0 = automatic).

◆ getDesignations()

const SetPieceDesignations & Lineup::getDesignations ( ) const

Every designation, indexed by SetPieceDuty.

◆ getGoalkeeper()

const Player * Lineup::getGoalkeeper ( ) const

Gets the goalkeeper.

Returns
Pointer to the goalkeeper Player object.

◆ getOutfieldPlayers()

const std::vector< Lineup::PositionedPlayer > & Lineup::getOutfieldPlayers ( ) const

Gets all positioned outfield players.

Returns
A vector of positioned players.

◆ getReserves()

const std::vector< const Player * > & Lineup::getReserves ( ) const

Gets the reserve players.

Returns
A vector of pointers to the reserve Player objects.

◆ getStandIns()

const std::vector< StandIn > & Lineup::getStandIns ( ) const
inline

Stand-ins currently filling a regular's place in the XI.

◆ getStrategy()

const Strategy & Lineup::getStrategy ( ) const

Gets the strategy for this lineup.

Returns
The strategy.

◆ isStarter()

bool Lineup::isStarter ( PlayerID  playerID) const

True when the player is in the starting XI.

◆ moveOutfieldPlayer()

bool Lineup::moveOutfieldPlayer ( PlayerID  playerID,
Vector2F  newPosition 
)

Updates the position of an existing outfield player.

Parameters
playerIDThe ID of the player to move.
newPositionThe new position on the pitch.
Returns
true if the player was found and moved, false otherwise.

◆ removeOutfieldPlayer()

void Lineup::removeOutfieldPlayer ( PlayerID  playerID)

Removes an outfield player from the pitch.

Parameters
playerIDThe ID of the player to remove.

◆ removePlayer()

bool Lineup::removePlayer ( PlayerID  playerID)

Drops every reference to a player: goalkeeper, outfield slot, bench and set-piece designations. Call it before the Player object is destroyed, since the lineup holds raw pointers.

Returns
true if the player was referenced anywhere.

◆ roleAt()

PlayerRole Lineup::roleAt ( Vector2F  position)
static

The position a slot at position asks for: x from the own goal (defence, holding midfield, midfield, attacking midfield, attack), y from the left touchline (left flank, centre, right flank).

◆ setDesignated()

void Lineup::setDesignated ( SetPieceDuty  duty,
PlayerID  playerID 
)

Designates a player (0 = automatic) for a duty.

◆ setDesignations()

void Lineup::setDesignations ( const SetPieceDesignations &  designations)

Replaces every designation (persistence).

◆ setGoalkeeper()

void Lineup::setGoalkeeper ( const Player *  gk)

Sets the goalkeeper.

Parameters
gkPointer to the Player object.

◆ setReserves()

void Lineup::setReserves ( const std::vector< const Player * > &  subs)

Sets the substitutes. Starters and duplicates are skipped; more than MAX_SUBSTITUTES are cut down with chooseBench() (pass the candidates best first).

Parameters
subsA vector of pointers to the reserve Player objects.

◆ setStandIns()

void Lineup::setStandIns ( std::vector< StandIn >  values)
inline

Replaces the stand-ins (persistence, matchday fixes).

◆ setStrategy()

void Lineup::setStrategy ( const Strategy &  strat)

Sets the strategy for this lineup.

Parameters
stratThe strategy to set.

◆ starters()

std::vector< const Player * > Lineup::starters ( ) const

Goalkeeper and outfield players of the XI (no null entries).

◆ swapPlayers()

bool Lineup::swapPlayers ( PlayerID  benchPlayerID,
PlayerID  pitchPlayerID 
)

Swaps a bench player with an outfield player.

Parameters
benchPlayerIDThe ID of the substitute.
pitchPlayerIDThe ID of the current starting player.
Returns
true if successful, false otherwise.

◆ toString()

std::string Lineup::toString ( ) const

Converts the lineup to a string representation for debugging.

Returns
The string representation of the lineup.

Member Data Documentation

◆ designations

SetPieceDesignations Lineup::designations {}
private

◆ goalkeeper

const Player* Lineup::goalkeeper
private

◆ MAX_SUBSTITUTES

constexpr size_t Lineup::MAX_SUBSTITUTES = 9
staticconstexpr

Substitutes named for a match (the top-league norm).

◆ outfield_players

std::vector<PositionedPlayer> Lineup::outfield_players
private

◆ reserves

std::vector<const Player*> Lineup::reserves
private

◆ stand_ins

std::vector<StandIn> Lineup::stand_ins
private

◆ strategy

Strategy Lineup::strategy
private

The documentation for this class was generated from the following files: