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

Persistent career identity, attributes, traits and day-to-day state. More...

#include <player.h>

Classes

struct  MarketValueCache
 

Public Member Functions

 Player (PlayerID new_id, TeamID new_team_id, std::string_view new_first_name, std::string_view new_last_name, PlayerRole new_role, Language new_nationality, uint32_t new_wage, uint32_t new_status, uint8_t new_age, uint8_t new_contract_years, uint8_t new_height, Foot new_foot, std::map< std::string, float > new_stats)
 Constructs a Player object.
 
PlayerID getId () const
 Gets the player's ID.
 
TeamID getTeamId () const
 Gets the ID of the player's team.
 
void setTeamId (TeamID id)
 Sets the ID of the player's team.
 
std::string getName () const
 Gets the player's full name.
 
const std::string & getFirstName () const
 Gets the player's first name.
 
const std::string & getLastName () const
 Gets the player's last name.
 
int getAge () const
 Gets the player's age.
 
void setAge (uint8_t new_age)
 Sets the player's age.
 
PlayerRole getRole () const
 Gets the player's role.
 
Language getNationality () const
 Gets the player's nationality.
 
uint32_t getWage () const
 Gets the player's wage.
 
void setWage (uint32_t wage)
 
uint8_t getContractYears () const
 Gets the player's remaining contract years.
 
void setContractYears (uint8_t years)
 
bool advanceContractYear ()
 
uint8_t getHeight () const
 Gets the player's height.
 
Foot getFoot () const
 Gets the player's preferred foot.
 
uint32_t getStatus () const
 Gets the player's status.
 
double getOverall (const StatsConfig &stats_config) const
 Calculates the player's overall rating based on stats and configuration.
 
const std::map< std::string, float > & getStats () const
 Gets the player's stats map.
 
void setStats (const std::map< std::string, float > &new_stats)
 Sets the player's stats map.
 
void agePlayer ()
 Increases the player's age by 1 and applies yearly ageing.
 
void train (const std::vector< std::string > &focus_stats, float amount=PLAYER_STAT_INCREASE_BASE)
 Improves every listed stat by amount (clamped to the maximum).
 
float getPotential () const
 Hidden potential on the overall-rating scale (never shown raw).
 
void setPotential (float potential)
 Sets the hidden potential.
 
const PlayerTraits & getTraits () const
 Hidden personality traits.
 
void setTraits (const PlayerTraits &traits)
 Replaces the hidden personality traits.
 
const PlayerDynamics & getDynamics () const
 Condition, sharpness, morale, injury and form state.
 
PlayerDynamics & mutableDynamics ()
 Mutable dynamic state for the world simulation.
 
bool isAvailable () const
 True when the player is fit enough to be selected.
 
float getForm () const
 Average of the recent match ratings, 0 when none.
 
void pushMatchRating (float rating)
 Records a match rating (1-10) in the recent form window.
 
uint32_t getMarketValue () const
 Gets the player's market value.
 
void updateMarketValue (const StatsConfig &stats_config) const
 Updates the player's market value.
 
void setTransferStatus (TransferStatus status)
 Sets the player's transfer status.
 
TransferStatus getTransferStatus () const
 Gets the player's transfer status.
 
void setAcademyPlayer (bool academy)
 Marks the player as part of his club's academy: he is not a first-team player (squad counts, automatic line-ups).
 
bool isAcademyPlayer () const
 True for U18 players and intake trialists.
 
std::uint8_t getSquadNumber () const
 Squad number (1-99), 0 when he has none (academy players).
 
void setSquadNumber (std::uint8_t number)
 Sets the squad number; uniqueness is kept by GameData.
 

Static Public Member Functions

static double valueFor (double overall, double potential, int age, double contract_years)
 Market value model shared by own players and scouting estimates: ability, an inverted-U age curve, a potential premium that fades out between 22 and 25, and the remaining contract length.
 

Static Public Attributes

static constexpr uint32_t TRANSFER_LISTED_BIT = 0x01U
 Bitmask bit for transfer-listed status.
 
static constexpr uint32_t ACADEMY_BIT = 0x02U
 Bitmask bit for players of a youth academy (U18 or trialist).
 

Private Attributes

PlayerID _id
 
TeamID _team_id
 
uint32_t _wage
 
uint32_t _status
 
MarketValueCache _cached_market_value
 
std::string _first_name
 
std::string _last_name
 
PlayerRole _role
 
Language _nationality
 
TransferStatus _transfer_status = TransferStatus::NotListed
 
uint8_t _age
 
uint8_t _contract_years
 
uint8_t _height
 
Foot _foot
 
std::uint8_t _squad_number = 0
 
float _potential = 0.0f
 
PlayerTraits _traits
 
PlayerDynamics _dynamics
 
std::map< std::string, float > _stats
 

Detailed Description

Persistent career identity, attributes, traits and day-to-day state.

On-pitch positions, intentions and live fatigue belong to MatchPlayer in match_engine.h. The engine borrows this Player as read-only input and the career later applies its match consequences. PlayerAgent models contract negotiations, not on-pitch AI. See docs/development/player-behavior.md. Concurrent const queries may refresh the price cache. Attribute mutations require exclusive career ownership, as with other persistent model state.

Constructor & Destructor Documentation

◆ Player()

Player::Player ( PlayerID  new_id,
TeamID  new_team_id,
std::string_view  new_first_name,
std::string_view  new_last_name,
PlayerRole  new_role,
Language  new_nationality,
uint32_t  new_wage,
uint32_t  new_status,
uint8_t  new_age,
uint8_t  new_contract_years,
uint8_t  new_height,
Foot  new_foot,
std::map< std::string, float >  new_stats 
)

Constructs a Player object.

Parameters
new_idThe unique ID for the player.
new_team_idThe ID of the team the player belongs to.
new_first_nameThe player's first name.
new_last_nameThe player's last name.
new_roleThe player's role (e.g., ST, CB).
new_nationalityThe player's nationality.
new_wageThe player's wage.
new_statusThe player's status.
new_ageThe player's age.
new_contract_yearsYears remaining on the contract.
new_heightThe player's height in cm.
new_footThe player's preferred foot.
new_statsA map of the player's attributes/stats.

Member Function Documentation

◆ advanceContractYear()

bool Player::advanceContractYear ( )

Decrements a non-zero contract and returns true when it expires.

◆ agePlayer()

void Player::agePlayer ( )

Increases the player's age by 1 and applies yearly ageing.

Physical attributes decline first (-1%/year at 30-32, -3%/year after 32, stamina at half rate), technical attributes from 32 and vision from 35. Professional players decline more slowly.

◆ getAge()

int Player::getAge ( ) const

Gets the player's age.

◆ getContractYears()

uint8_t Player::getContractYears ( ) const

Gets the player's remaining contract years.

◆ getDynamics()

const PlayerDynamics & Player::getDynamics ( ) const

Condition, sharpness, morale, injury and form state.

◆ getFirstName()

const std::string & Player::getFirstName ( ) const

Gets the player's first name.

◆ getFoot()

Foot Player::getFoot ( ) const

Gets the player's preferred foot.

◆ getForm()

float Player::getForm ( ) const

Average of the recent match ratings, 0 when none.

◆ getHeight()

uint8_t Player::getHeight ( ) const

Gets the player's height.

◆ getId()

uint32_t Player::getId ( ) const

Gets the player's ID.

◆ getLastName()

const std::string & Player::getLastName ( ) const

Gets the player's last name.

◆ getMarketValue()

uint32_t Player::getMarketValue ( ) const

Gets the player's market value.

◆ getName()

std::string Player::getName ( ) const

Gets the player's full name.

◆ getNationality()

Language Player::getNationality ( ) const

Gets the player's nationality.

◆ getOverall()

double Player::getOverall ( const StatsConfig &  stats_config) const

Calculates the player's overall rating based on stats and configuration.

Parameters
stats_configConfiguration weights for the stats.
Returns
The overall rating.

◆ getPotential()

float Player::getPotential ( ) const

Hidden potential on the overall-rating scale (never shown raw).

◆ getRole()

PlayerRole Player::getRole ( ) const

Gets the player's role.

◆ getSquadNumber()

std::uint8_t Player::getSquadNumber ( ) const
inline

Squad number (1-99), 0 when he has none (academy players).

◆ getStats()

const std::map< std::string, float > & Player::getStats ( ) const

Gets the player's stats map.

◆ getStatus()

uint32_t Player::getStatus ( ) const

Gets the player's status.

◆ getTeamId()

TeamID Player::getTeamId ( ) const

Gets the ID of the player's team.

◆ getTraits()

const PlayerTraits & Player::getTraits ( ) const

Hidden personality traits.

◆ getTransferStatus()

TransferStatus Player::getTransferStatus ( ) const

Gets the player's transfer status.

◆ getWage()

uint32_t Player::getWage ( ) const

Gets the player's wage.

◆ isAcademyPlayer()

bool Player::isAcademyPlayer ( ) const

True for U18 players and intake trialists.

◆ isAvailable()

bool Player::isAvailable ( ) const

True when the player is fit enough to be selected.

◆ mutableDynamics()

PlayerDynamics & Player::mutableDynamics ( )

Mutable dynamic state for the world simulation.

◆ pushMatchRating()

void Player::pushMatchRating ( float  rating)

Records a match rating (1-10) in the recent form window.

◆ setAcademyPlayer()

void Player::setAcademyPlayer ( bool  academy)

Marks the player as part of his club's academy: he is not a first-team player (squad counts, automatic line-ups).

◆ setAge()

void Player::setAge ( uint8_t  new_age)

Sets the player's age.

◆ setContractYears()

void Player::setContractYears ( uint8_t  years)

Updates the remaining contract duration.

◆ setPotential()

void Player::setPotential ( float  potential)

Sets the hidden potential.

◆ setSquadNumber()

void Player::setSquadNumber ( std::uint8_t  number)
inline

Sets the squad number; uniqueness is kept by GameData.

◆ setStats()

void Player::setStats ( const std::map< std::string, float > &  new_stats)

Sets the player's stats map.

◆ setTeamId()

void Player::setTeamId ( TeamID  id)

Sets the ID of the player's team.

◆ setTraits()

void Player::setTraits ( const PlayerTraits &  traits)

Replaces the hidden personality traits.

◆ setTransferStatus()

void Player::setTransferStatus ( TransferStatus  status)

Sets the player's transfer status.

◆ setWage()

void Player::setWage ( uint32_t  wage)

Updates the weekly wage after a successful contract negotiation.

◆ train()

void Player::train ( const std::vector< std::string > &  focus_stats,
float  amount = PLAYER_STAT_INCREASE_BASE 
)

Improves every listed stat by amount (clamped to the maximum).

Because role weights sum to one, training all of a role's focus stats by x raises the overall rating by x.

◆ updateMarketValue()

void Player::updateMarketValue ( const StatsConfig &  stats_config) const

Updates the player's market value.

Parameters
stats_configThe stats configuration to use for the calculation.

◆ valueFor()

double Player::valueFor ( double  overall,
double  potential,
int  age,
double  contract_years 
)
static

Market value model shared by own players and scouting estimates: ability, an inverted-U age curve, a potential premium that fades out between 22 and 25, and the remaining contract length.

Returns
Value in euros, within EUR 10K - 250M.

Member Data Documentation

◆ _age

uint8_t Player::_age
private

◆ _cached_market_value

MarketValueCache Player::_cached_market_value
private

◆ _contract_years

uint8_t Player::_contract_years
private

◆ _dynamics

PlayerDynamics Player::_dynamics
private

◆ _first_name

std::string Player::_first_name
private

◆ _foot

Foot Player::_foot
private

◆ _height

uint8_t Player::_height
private

◆ _id

PlayerID Player::_id
private

◆ _last_name

std::string Player::_last_name
private

◆ _nationality

Language Player::_nationality
private

◆ _potential

float Player::_potential = 0.0f
private

◆ _role

PlayerRole Player::_role
private

◆ _squad_number

std::uint8_t Player::_squad_number = 0
private

◆ _stats

std::map<std::string, float> Player::_stats
private

◆ _status

uint32_t Player::_status
private

◆ _team_id

TeamID Player::_team_id
private

◆ _traits

PlayerTraits Player::_traits
private

◆ _transfer_status

TransferStatus Player::_transfer_status = TransferStatus::NotListed
private

◆ _wage

uint32_t Player::_wage
private

◆ ACADEMY_BIT

constexpr uint32_t Player::ACADEMY_BIT = 0x02U
staticconstexpr

Bitmask bit for players of a youth academy (U18 or trialist).

◆ TRANSFER_LISTED_BIT

constexpr uint32_t Player::TRANSFER_LISTED_BIT = 0x01U
staticconstexpr

Bitmask bit for transfer-listed status.


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