|
Player12
An open source football management simulator
|
Deals, loans, pre-contracts, payments and history of the market. More...
#include <transfer_market.h>
Classes | |
| struct | AiNeed |
| struct | Deal |
Public Member Functions | |
| TransferMarket (std::shared_ptr< GameData > gamedata, WorldSimulation &world, const CompetitionManager &competitions) | |
| void | onDayAdvanced (const GameDateValue &date, TeamID managed_team_id) |
| void | forgetRemovedPlayers () |
| void | load (const std::shared_ptr< DatabaseConnection > &db_conn) |
| void | save (const std::shared_ptr< DatabaseConnection > &db_conn) const |
| void | onSaved () |
| TransferNegotiation::SaleContext | saleContext (PlayerID player_id, TeamID buyer_id, const GameDateValue &date, std::uint32_t listing_price) const |
| TransferNegotiation::PlayerContext | playerContext (PlayerID player_id, TeamID club_id, TransferNegotiation::ContractKind kind) const |
| SquadRole | projectedRole (PlayerID player_id, TeamID club_id) const |
| bool | wouldJoin (PlayerID player_id, TeamID club_id, TransferNegotiation::ContractKind kind) const |
| bool | completeTransfer (const Deal &deal, const GameDateValue &date, TeamID managed_team_id) |
| bool | startLoan (PlayerID player_id, TeamID borrower_id, const TransferNegotiation::LoanTerms &terms, const GameDateValue &date, TeamID managed_team_id) |
| bool | endLoan (PlayerID player_id, const GameDateValue &date, TeamID managed_team_id, bool recalled) |
| bool | exerciseLoanOption (PlayerID player_id, const GameDateValue &date, TeamID managed_team_id) |
| bool | releasePlayer (PlayerID player_id, const GameDateValue &date, TeamID managed_team_id) |
| bool | agreePreContract (PlayerID player_id, TeamID club_id, const TransferNegotiation::ContractOffer &terms, const GameDateValue &date, TeamID managed_team_id) |
| void | recordLegacyTransfer (PlayerID player_id, TeamID from_team, TeamID to_team, std::uint32_t fee, const GameDateValue &date) |
| bool | canBeTraded (PlayerID player_id) const |
| bool | loanWithinLimits (PlayerID player_id, TeamID parent, TeamID borrower) const |
| std::int64_t | committedPayables (TeamID team_id, const GameDateValue &date) const |
| std::int64_t | spendableBudget (TeamID team_id, const GameDateValue &date) const |
| void | removeFromLineup (Team &team, const Player &departed) const |
| std::int64_t | wageRoom (TeamID club_id) const |
| std::int64_t | nextSeasonWageRoom (TeamID club_id) const |
| std::int64_t | committedPreContractCosts (TeamID club_id) const |
| bool | keepsSquadFloor (TeamID club_id, PlayerID leaving, bool *goalkeeper=nullptr) const |
| bool | keepsAiKeepers (TeamID club_id, PlayerID leaving) const |
| std::size_t | seniorSquadSize (TeamID club_id) const |
| bool | renewContract (PlayerID player_id, const TransferNegotiation::ContractOffer &offer, const GameDateValue &date) |
| std::uint32_t | deservedWage (PlayerID player_id, TeamID club_id) const |
| LoanNegotiation::BorrowerContext | borrowerContext (PlayerID player_id, TeamID club_id, const GameDateValue &date) const |
| std::uint16_t | appearancesFor (PlayerID player_id, TeamID team_id) const |
| void | seedReleaseClauses () |
| void | seedSummerFreeAgents () |
| std::uint32_t | releaseClause (PlayerID player_id) const |
| void | setReleaseClause (PlayerID player_id, std::uint32_t clause) |
| bool | payReleaseClause (TeamID club_id, PlayerID player_id, const GameDateValue &date, TeamID managed_team_id) |
| bool | runAiClub (TeamID club_id, const std::unordered_map< PlayerID, TransferListing > &listings, const GameDateValue &date, TeamID managed_team_id, WorldRng &rng, bool free_agents_only) |
| void | listLoanProspects (TeamID club_id) |
| void | runAiPreContracts (const GameDateValue &date, TeamID managed_team_id, WorldRng &rng, int attempts) |
| void | runAiApproach (TeamID club_id, const GameDateValue &date, TeamID managed_team_id, WorldRng &rng) |
| const std::vector< IncomingOffer > & | incomingOffers () const |
| const IncomingOffer * | findIncomingOffer (std::uint32_t offer_id) const |
| std::uint32_t | addIncomingOffer (IncomingOffer offer) |
| bool | updateIncomingOffer (const IncomingOffer &offer) |
| bool | removeIncomingOffer (std::uint32_t offer_id) |
| std::vector< std::uint32_t > | dueOfferReplies (const GameDateValue &date) const |
| std::uint8_t | rivalBids (const IncomingOffer &offer) const |
| GameDateValue | answerDeadline (TeamID buyer, const GameDateValue &date, int days) const |
| TransferNegotiation::WindowInfo | clubWindow (TeamID club, const GameDateValue &date) const |
| void | closeTalks (PlayerID player_id, TeamID buyer, const GameDateValue &date) |
| bool | talksClosed (PlayerID player_id, TeamID buyer, const GameDateValue &date) const |
| const std::vector< TalksCooldown > & | closedTalks () const |
| const std::unordered_map< PlayerID, Negotiation > & | talks () const |
| const Negotiation * | findNegotiation (PlayerID player_id) const |
| void | setNegotiation (const Negotiation &negotiation) |
| void | removeNegotiation (PlayerID player_id) |
| const PlayerMarketFlags * | flags (PlayerID player_id) const |
| void | setLoanListed (PlayerID player_id, bool listed) |
| bool | isLoanListed (PlayerID player_id) const |
| void | setNotForSale (PlayerID player_id, const GameDateValue &until) |
| bool | isNotForSale (PlayerID player_id, const GameDateValue &date) const |
| const LoanDeal * | findLoan (PlayerID player_id) const |
| const std::unordered_map< PlayerID, LoanDeal > & | loans () const |
| const PreContractDeal * | findPreContract (PlayerID player_id) const |
| const std::unordered_map< PlayerID, PreContractDeal > & | preContracts () const |
| const std::vector< TransferRecord > & | history () const |
| std::vector< TransferRecord > | historyFor (PlayerID player_id) const |
| const std::vector< TransferObligation > & | obligations () const |
Static Public Member Functions | |
| static std::uint32_t | agentFee (const Deal &deal) |
| static bool | affordsWage (const Team &club, std::uint32_t weekly_wage, std::int64_t room) |
Static Public Attributes | |
| static constexpr std::size_t | MIN_SENIOR_SQUAD = 11 |
Private Member Functions | |
| Player * | mutablePlayer (PlayerID player_id) |
| std::string | teamName (TeamID team_id) const |
| void | movePlayer (PlayerID player_id, TeamID from_team, TeamID to_team, TeamID managed_team_id) |
| void | pay (TeamID payer, TeamID payee, std::int64_t amount, const GameDateValue &date) |
| std::int64_t | paySellOns (PlayerID player_id, TeamID seller, TeamID buyer, std::uint32_t fee, const GameDateValue &date) |
| void | addRecord (const TransferRecord &record) |
| void | post (const GameDateValue &date, InboxCategory category, std::string title_key, std::string body_key, std::vector< std::string > args, std::optional< PlayerID > player_id, std::optional< TeamID > team_id) |
| std::uint16_t | careerCount (PlayerID player_id, TeamID team_id, ObligationKind kind) const |
| PlayerMarketFlags & | mutableFlags (PlayerID player_id) |
| void | pruneFlags (PlayerID player_id) |
| void | clearOnMove (PlayerID player_id) |
| std::optional< AiNeed > | assessNeed (const std::vector< std::pair< double, PlayerID > > &ranked, float level_boost=0.0f) const |
| std::int64_t | aiWageRoom (TeamID club_id, bool next_season) const |
| std::int64_t | preContractCosts (TeamID club_id) const |
| bool | lastSeasonMove (TeamID club_id, bool promoted) const |
| bool | endContract (PlayerID player_id, const GameDateValue &date, TeamID managed_team_id, bool severance_due) |
| void | releaseOnRelegation (const GameDateValue &date, TeamID managed_team_id) |
| void | lowerFreeAgentExpectations () |
| void | listLoanProspects (const std::vector< std::pair< double, PlayerID > > &ranked) |
| bool | aiShedSurplus (TeamID club_id, const std::vector< std::pair< double, PlayerID > > &ranked, const GameDateValue &date, TeamID managed_team_id, WorldRng &rng) |
| bool | aiSignFreeAgent (TeamID club_id, const AiNeed &need, std::int64_t wage_room, const GameDateValue &date, TeamID managed_team_id) |
| bool | aiTakeLoan (TeamID club_id, const AiNeed &need, std::int64_t wage_room, const GameDateValue &date, TeamID managed_team_id, WorldRng &rng) |
| bool | aiBuy (TeamID club_id, const AiNeed &need, std::int64_t wage_room, const std::unordered_map< PlayerID, TransferListing > &listings, const GameDateValue &date, TeamID managed_team_id, WorldRng &rng) |
| void | payLoanWageShares (const GameDateValue &date) |
| void | processLoanEnds (const GameDateValue &date, TeamID managed_team_id) |
| void | executePreContracts (const GameDateValue &date, TeamID managed_team_id) |
| void | payDueInstalments (const GameDateValue &date, TeamID managed_team_id) |
| void | checkAddOns (const GameDateValue &date, TeamID managed_team_id) |
| void | checkPromises (const GameDateValue &date, TeamID managed_team_id) |
| void | expireOffers (const GameDateValue &date) |
| void | postNewsDigest (const GameDateValue &date, TeamID managed_team_id) |
| void | postDeadlineSummary (const GameDateValue &date, TeamID managed_team_id) |
| void | applyWageRises (const GameDateValue &date) |
| void | payAppearanceFees (const GameDateValue &date) |
| void | addContractExtras (PlayerID player_id, TeamID club_id, const TransferNegotiation::ContractOffer &contract, const GameDateValue &start) |
| void | settleLoanClause (const LoanDeal &loan, const GameDateValue &date, TeamID managed_team_id, bool charge) |
Static Private Member Functions | |
| static bool | aiAffordsWage (const Team &club, std::uint32_t weekly_wage, std::int64_t room) |
Private Attributes | |
| std::shared_ptr< GameData > | gamedata |
| WorldSimulation & | world |
| const CompetitionManager & | competitions |
| std::vector< TransferRecord > | records |
| std::size_t | persisted_records = 0 |
| std::vector< TransferObligation > | pending_obligations |
| std::unordered_map< PlayerID, LoanDeal > | active_loans |
| std::unordered_map< PlayerID, PreContractDeal > | pre_contracts |
| std::unordered_map< PlayerID, PlayerMarketFlags > | player_flags |
| std::vector< IncomingOffer > | incoming |
| std::unordered_map< PlayerID, Negotiation > | negotiations |
| std::vector< TalksCooldown > | cooldowns |
| std::uint32_t | next_id = 1 |
| std::mutex | payables_cache_mutex |
| std::unordered_map< TeamID, std::int64_t > | payables_cache |
| std::int32_t | payables_day = -1 |
| bool | payables_dirty = true |
Deals, loans, pre-contracts, payments and history of the market.
Owned by Game next to the world simulation. It executes structured moves (fees with instalments, add-ons and sell-on clauses, agent fees, signing bonuses, loans and releases), runs the scheduled parts of existing deals every day and drives the AI moves that do not go through the transfer list (free agents, loans, releases, pre-contracts and approaches for the managed club's players). All randomness comes from world RNG streams.
| TransferMarket::TransferMarket | ( | std::shared_ptr< GameData > | gamedata, |
| WorldSimulation & | world, | ||
| const CompetitionManager & | competitions | ||
| ) |
|
private |
Contract extras (rise, appearance money) of contract for the player at club_id from start; old clubs' extras lapse.
| std::uint32_t TransferMarket::addIncomingOffer | ( | IncomingOffer | offer | ) |
Adds an offer with a fresh id; a transfer offer without history gets its opening bid as the first round, and a default patience.
|
private |
|
inlinestatic |
weekly_wage fits room and the single-player share of the club's wage budget.
|
static |
Agent fee paid by the buyer: the one agreed in the contract, else 10% of a fee, or weeks of wage.
| bool TransferMarket::agreePreContract | ( | PlayerID | player_id, |
| TeamID | club_id, | ||
| const TransferNegotiation::ContractOffer & | terms, | ||
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
|
staticprivate |
A wage within room and the single-player share of the budget.
|
private |
|
private |
|
private |
|
private |
|
private |
Weekly wages an AI club can still commit: its wage budget less the payroll and the wages of the pre-contracts it has agreed. With next_season only contracts that run beyond this season count, and its players out on loan are back.
| GameDateValue TransferMarket::answerDeadline | ( | TeamID | buyer, |
| const GameDateValue & | date, | ||
| int | days | ||
| ) | const |
Last day to answer an offer of buyer made on date: days later, but never after the buyer's transfer window closes.
Appearances for team_id in his career (competitive matches).
|
private |
Yearly rises due on date and weekly appearance money.
|
private |
level_boost raises the level starters are measured against.
< Slots in a typical XI.
< Squad players wanted.
| LoanNegotiation::BorrowerContext TransferMarket::borrowerContext | ( | PlayerID | player_id, |
| TeamID | club_id, | ||
| const GameDateValue & | date | ||
| ) | const |
Context of club_id borrowing player_id from today (budget, wage room, how often he would play); ceiling and talks state left at 0.
| bool TransferMarket::canBeTraded | ( | PlayerID | player_id | ) | const |
Not on loan and not committed to another club.
|
private |
|
private |
|
private |
|
private |
|
inline |
| void TransferMarket::closeTalks | ( | PlayerID | player_id, |
| TeamID | buyer, | ||
| const GameDateValue & | date | ||
| ) |
Talks of buyer for player_id ended on date: the club does not come back for him for a while (at most until the window closes).
| WindowInfo TransferMarket::clubWindow | ( | TeamID | club, |
| const GameDateValue & | date | ||
| ) | const |
Transfer window of club's country on date: the buying club's window decides whether it can sign a player (TransferWindows).
| std::int64_t TransferMarket::committedPayables | ( | TeamID | team_id, |
| const GameDateValue & | date | ||
| ) | const |
Instalments a club owes from date until the season ends.
|
inline |
Signing bonuses and agent fees due on the club's agreed pre-contracts.
| bool TransferMarket::completeTransfer | ( | const Deal & | deal, |
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
Fee or free move with the full deal structure; false if invalid.
What players of his ability and age earn at club_id (the club's pay scale applied to his wage index); 0 when unknown.
| std::vector< std::uint32_t > TransferMarket::dueOfferReplies | ( | const GameDateValue & | date | ) | const |
Transfer offers whose buyer answers on or before date, by id.
|
private |
Terminates a contract; severance_due pays the remaining wages (a relegation clause ends it for free).
| bool TransferMarket::endLoan | ( | PlayerID | player_id, |
| const GameDateValue & | date, | ||
| TeamID | managed_team_id, | ||
| bool | recalled | ||
| ) |
Sends a loanee back (end of term or recall).
|
private |
| bool TransferMarket::exerciseLoanOption | ( | PlayerID | player_id, |
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
Borrower buys the loanee for the option fee.
|
private |
| const IncomingOffer * TransferMarket::findIncomingOffer | ( | std::uint32_t | offer_id | ) | const |
| const Negotiation * TransferMarket::findNegotiation | ( | PlayerID | player_id | ) | const |
| const PreContractDeal * TransferMarket::findPreContract | ( | PlayerID | player_id | ) | const |
| const PlayerMarketFlags * TransferMarket::flags | ( | PlayerID | player_id | ) | const |
| void TransferMarket::forgetRemovedPlayers | ( | ) |
Drops offers, talks, flags and cooldowns of players who no longer exist (retirement, youth releases).
|
inline |
Every move, oldest first.
| std::vector< TransferRecord > TransferMarket::historyFor | ( | PlayerID | player_id | ) | const |
Moves of one player, oldest first.
|
inline |
| bool TransferMarket::isLoanListed | ( | PlayerID | player_id | ) | const |
| bool TransferMarket::isNotForSale | ( | PlayerID | player_id, |
| const GameDateValue & | date | ||
| ) | const |
False when leaving is a senior goalkeeper and club_id would keep fewer than Market::MIN_AI_SENIOR_KEEPERS of them (applied to the AI's sales, loans and releases).
| bool TransferMarket::keepsSquadFloor | ( | TeamID | club_id, |
| PlayerID | leaving, | ||
| bool * | goalkeeper = nullptr |
||
| ) | const |
False when leaving going would leave club_id fewer than MIN_SENIOR_SQUAD senior players or no senior goalkeeper; goalkeeper tells which (null to ignore).
|
private |
Clubs promoted or relegated at the last season's close.
|
private |
| void TransferMarket::listLoanProspects | ( | TeamID | club_id | ) |
Offers an AI club's surplus prospects for loan (no move).
| void TransferMarket::load | ( | const std::shared_ptr< DatabaseConnection > & | db_conn | ) |
|
private |
|
private |
|
private |
|
inline |
Wage room next season: contracts running past 30 June and agreed pre-contracts count, players in their final year do not.
|
inline |
| void TransferMarket::onDayAdvanced | ( | const GameDateValue & | date, |
| TeamID | managed_team_id | ||
| ) |
Loan wages and returns, pre-contracts (1 July), instalments, add-ons, promises, offer expiry and the weekly news digest. Offers and talks of players who left football (retired, released youngsters) are dropped first.
| void TransferMarket::onSaved | ( | ) |
|
private |
|
private |
|
private |
|
private |
| bool TransferMarket::payReleaseClause | ( | TeamID | club_id, |
| PlayerID | player_id, | ||
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
An AI club pays a player's release clause in cash (within its budget and wage room; never leaving the managed squad short): his club cannot refuse and he joins on the terms he demands. True if he moved.
|
private |
Pays the sell-on clauses of seller's sale to buyer; a clause whose beneficiary is the buyer itself lapses unpaid.
| PlayerContext TransferMarket::playerContext | ( | PlayerID | player_id, |
| TeamID | club_id, | ||
| TransferNegotiation::ContractKind | kind | ||
| ) | const |
|
private |
|
private |
On the day a window shuts: the deals of its last days.
|
private |
|
private |
Signing bonuses and agent fees due on the club's pre-contracts.
|
inline |
|
private |
Role the player would have by ability rank at club_id.
|
private |
| void TransferMarket::recordLegacyTransfer | ( | PlayerID | player_id, |
| TeamID | from_team, | ||
| TeamID | to_team, | ||
| std::uint32_t | fee, | ||
| const GameDateValue & | date | ||
| ) |
History and sell-on clauses of a move made by the legacy path.
| std::uint32_t TransferMarket::releaseClause | ( | PlayerID | player_id | ) | const |
Release clause of a player (0 = none).
|
private |
| bool TransferMarket::releasePlayer | ( | PlayerID | player_id, |
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
Terminates the contract, paying the remaining wages.
Takes a departed player out of the managed club's line-up, filling his place without rebuilding the rest of the manager's selection.
| bool TransferMarket::removeIncomingOffer | ( | std::uint32_t | offer_id | ) |
| void TransferMarket::removeNegotiation | ( | PlayerID | player_id | ) |
| bool TransferMarket::renewContract | ( | PlayerID | player_id, |
| const TransferNegotiation::ContractOffer & | offer, | ||
| const GameDateValue & | date | ||
| ) |
Renews a player's contract at his club with offer: wage, seasons (the current one included), extras, release clause and promise; the signing bonus and agent fee are paid today. False if invalid.
| std::uint8_t TransferMarket::rivalBids | ( | const IncomingOffer & | offer | ) | const |
Other clubs with a transfer offer for the same player.
| void TransferMarket::runAiApproach | ( | TeamID | club_id, |
| const GameDateValue & | date, | ||
| TeamID | managed_team_id, | ||
| WorldRng & | rng | ||
| ) |
An AI club may bid for one of the managed club's players.
| bool TransferMarket::runAiClub | ( | TeamID | club_id, |
| const std::unordered_map< PlayerID, TransferListing > & | listings, | ||
| const GameDateValue & | date, | ||
| TeamID | managed_team_id, | ||
| WorldRng & | rng, | ||
| bool | free_agents_only | ||
| ) |
One AI club's business on a visit: sheds surplus (loan-listing prospects, releasing veterans), then fills its biggest need (a missing position or a weak starter) with a free agent, a loan or a structured fee deal with another AI club. Returns true when a player moved.
| void TransferMarket::runAiPreContracts | ( | const GameDateValue & | date, |
| TeamID | managed_team_id, | ||
| WorldRng & | rng, | ||
| int | attempts | ||
| ) |
AI clubs agree pre-contracts (1 January - 30 June).
| SaleContext TransferMarket::saleContext | ( | PlayerID | player_id, |
| TeamID | buyer_id, | ||
| const GameDateValue & | date, | ||
| std::uint32_t | listing_price | ||
| ) | const |
| void TransferMarket::save | ( | const std::shared_ptr< DatabaseConnection > & | db_conn | ) | const |
Writes the market state inside the caller's transaction.
| void TransferMarket::seedReleaseClauses | ( | ) |
Gives some ambitious players at modest clubs a release clause in a new world (deterministic from the world seed).
| void TransferMarket::seedSummerFreeAgents | ( | ) |
The 30 June expiries of a new world: some players outside each club's matchday squad start without a club (deterministic from the world seed; no history, no money).
| std::size_t TransferMarket::seniorSquadSize | ( | TeamID | club_id | ) | const |
Senior players of a club plus the pre-contracts joining it.
| void TransferMarket::setLoanListed | ( | PlayerID | player_id, |
| bool | listed | ||
| ) |
| void TransferMarket::setNegotiation | ( | const Negotiation & | negotiation | ) |
| void TransferMarket::setNotForSale | ( | PlayerID | player_id, |
| const GameDateValue & | until | ||
| ) |
Clubs are told the player is not for sale until until (they do not approach him before then).
| void TransferMarket::setReleaseClause | ( | PlayerID | player_id, |
| std::uint32_t | clause | ||
| ) |
|
private |
Settles the appearance clause of a loan ending on date (paid only when charge and he played too little).
| std::int64_t TransferMarket::spendableBudget | ( | TeamID | team_id, |
| const GameDateValue & | date | ||
| ) | const |
Transfer money a club can commit on date: the board's allowance capped by the cash left after the payroll reserve and the instalments still owed this season (ClubEconomy::availableTransferBudget); zero under a transfer embargo.
| bool TransferMarket::startLoan | ( | PlayerID | player_id, |
| TeamID | borrower_id, | ||
| const TransferNegotiation::LoanTerms & | terms, | ||
| const GameDateValue & | date, | ||
| TeamID | managed_team_id | ||
| ) |
|
inline |
Open talks of the managed club by player.
| bool TransferMarket::talksClosed | ( | PlayerID | player_id, |
| TeamID | buyer, | ||
| const GameDateValue & | date | ||
| ) | const |
|
private |
| bool TransferMarket::updateIncomingOffer | ( | const IncomingOffer & | offer | ) |
|
inline |
Weekly wages a club can still commit (budget less payroll and the wages of its agreed pre-contracts).
| bool TransferMarket::wouldJoin | ( | PlayerID | player_id, |
| TeamID | club_id, | ||
| TransferNegotiation::ContractKind | kind | ||
| ) | const |
True if the player accepts the terms he demands from club_id.
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |
Fewest senior players a managed squad may keep after a release or a sale.
|
private |
|
private |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |