Player12
An open source football management simulator
Loading...
Searching...
No Matches
staff.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 <algorithm>
12#include <array>
13#include <cstddef>
14#include <cstdint>
15#include <mutex>
16#include <span>
17#include <string>
18#include <unordered_map>
19#include <utility>
20#include <vector>
21
22#include "global/languages.h"
23#include "global/types.h"
24
25class GameData;
26class Team;
27struct LeagueEconomy;
28
30using StaffID = std::uint32_t;
31
33enum class StaffRole : std::uint8_t
34{
41 Physio,
43 Scout,
45 COUNT
46};
47
48inline constexpr std::size_t STAFF_ROLE_COUNT =
49 static_cast<std::size_t>(std::to_underlying(StaffRole::COUNT));
50
52enum class StaffAttribute : std::uint8_t
53{
54 Attacking = 0,
55 Defending,
56 Fitness,
58 Tactical,
64 COUNT
65};
66
67inline constexpr std::size_t STAFF_ATTRIBUTE_COUNT =
68 static_cast<std::size_t>(std::to_underlying(StaffAttribute::COUNT));
69
78{
79 StaffID id = 0;
81 std::string first_name;
82 std::string last_name;
84 std::uint8_t age = 40;
86 std::array<std::uint8_t, STAFF_ATTRIBUTE_COUNT> attributes{};
87 std::uint32_t wage = 0;
88 std::uint8_t contract_years = 0;
89
90 std::string name() const { return first_name + " " + last_name; }
91 std::uint8_t attribute(StaffAttribute which) const
92 {
93 return attributes[static_cast<std::size_t>(std::to_underlying(which))];
94 }
95};
96
105{
106 float coaching_fitness = 0.25f;
107 float coaching_attacking = 0.25f;
108 float coaching_defending = 0.25f;
109 float coaching_tactical = 0.25f;
110 float coaching_goalkeeping = 0.25f;
111 float coaching_youth = 0.25f;
113 float training_quality = 0.25f;
115 float injury_prevention = 1.08f;
117 float layoff_multiplier = 1.12f;
125 float scouting_accuracy = 0.0f;
127 float familiarity_rate = 0.8f;
128 std::int64_t weekly_payroll = 0;
129};
130
138{
139 public:
140 bool empty() const { return members.empty(); }
141 void clear();
142
144 StaffID allocateId() { return next_id++; }
145
147 StaffID peekNextId() const { return next_id; }
148
150 void restoreNextId(StaffID id) { next_id = std::max(next_id, id); }
151
153 void add(StaffMember member);
154
156 bool remove(StaffID id);
157
158 const StaffMember* find(StaffID id) const;
159
163
164 const std::unordered_map<StaffID, StaffMember>& all() const
165 {
166 return members;
167 }
168
170 std::vector<const StaffMember*> clubStaff(TeamID team_id) const;
171
173 std::vector<const StaffMember*> market() const;
174
176 std::size_t roleCount(TeamID team_id, StaffRole role) const;
177
179 StaffEffects effects(TeamID team_id) const;
180
183 {
184 const std::scoped_lock lock(cache_mutex);
185 cache_valid = false;
186 }
187
189 void restore(std::vector<StaffMember> loaded);
190
191 private:
192 void rebuildCache() const;
193
194 std::unordered_map<StaffID, StaffMember> members;
195 mutable std::mutex cache_mutex;
196 mutable std::unordered_map<TeamID, StaffEffects> effects_cache;
197 mutable bool cache_valid = false;
199};
200
205namespace StaffModel
206{
208inline constexpr std::array<std::uint8_t, STAFF_ROLE_COUNT> ROLE_LIMITS = {
209 1, 2, 2, 2, 1, 2, 4, 2, 6, 1};
210
212inline constexpr std::size_t MARKET_SIZE = 70;
213
215inline constexpr double FOOTBALL_STAFF_SHARE = 0.35;
216
218std::uint8_t rating(const StaffMember& member);
219
221std::array<StaffAttribute, 2> keyAttributes(StaffRole role);
222
224StaffEffects computeEffects(std::span<const StaffMember* const> staff);
225
227std::uint32_t marketWage(const StaffMember& member);
228
230std::uint32_t renewalWage(const StaffMember& member);
231
233std::int64_t severance(const StaffMember& member);
234
236std::array<std::uint8_t, STAFF_ROLE_COUNT> roleCounts(std::uint8_t reputation);
237
242std::vector<StaffMember> generateClubStaff(const Team& team,
243 const LeagueEconomy& economy,
244 std::uint64_t world_seed,
245 StaffRoster& roster);
246
249void generateWorld(GameData& gamedata);
250
252void refreshMarket(GameData& gamedata, std::int32_t ordinal);
253
259std::vector<std::string> seasonEnd(GameData& gamedata, TeamID managed_team_id,
260 std::uint16_t year);
261
266float potentialErrorSd(float scouting_accuracy);
267
269const char* roleKey(StaffRole role);
270const char* roleDescriptionKey(StaffRole role);
271const char* attributeKey(StaffAttribute attribute);
272} // namespace StaffModel
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Every staff member of the world with per-club effect caches. Concurrent effects queries return indepe...
Definition staff.h:138
std::size_t roleCount(TeamID team_id, StaffRole role) const
Definition staff.cpp:270
void restoreNextId(StaffID id)
Definition staff.h:150
std::unordered_map< TeamID, StaffEffects > effects_cache
Definition staff.h:196
std::mutex cache_mutex
Definition staff.h:195
void clear()
Definition staff.cpp:197
bool empty() const
Definition staff.h:140
bool cache_valid
Definition staff.h:197
const std::unordered_map< StaffID, StaffMember > & all() const
Definition staff.h:164
void restore(std::vector< StaffMember > loaded)
Definition staff.cpp:306
bool remove(StaffID id)
Definition staff.cpp:215
void invalidate()
Definition staff.h:182
StaffEffects effects(TeamID team_id) const
Definition staff.cpp:295
std::vector< const StaffMember * > market() const
Definition staff.cpp:261
StaffID next_id
Definition staff.h:198
StaffID allocateId()
Definition staff.h:144
void rebuildCache() const
Definition staff.cpp:280
std::unordered_map< StaffID, StaffMember > members
Definition staff.h:194
const StaffMember * find(StaffID id) const
Definition staff.cpp:222
void add(StaffMember member)
Definition staff.cpp:206
std::vector< const StaffMember * > clubStaff(TeamID team_id) const
Definition staff.cpp:250
StaffID peekNextId() const
Definition staff.h:147
Represents a football team.
Definition team.h:47
Language
Enum representing supported languages in the game.
Definition languages.h:24
Staff ratings, effects, generation, wages and contracts.
Definition staff.cpp:317
std::uint32_t marketWage(const StaffMember &member)
Definition staff.cpp:432
const char * roleKey(StaffRole role)
Definition staff.cpp:618
std::int64_t severance(const StaffMember &member)
Definition staff.cpp:446
std::uint32_t renewalWage(const StaffMember &member)
Definition staff.cpp:440
void refreshMarket(GameData &gamedata, std::int32_t ordinal)
Definition staff.cpp:525
std::array< StaffAttribute, 2 > keyAttributes(StaffRole role)
Definition staff.cpp:318
const char * attributeKey(StaffAttribute attribute)
Definition staff.cpp:678
std::uint8_t rating(const StaffMember &member)
Definition staff.cpp:348
void generateWorld(GameData &gamedata)
Definition staff.cpp:506
const char * roleDescriptionKey(StaffRole role)
Definition staff.cpp:648
std::vector< std::string > seasonEnd(GameData &gamedata, TeamID managed_team_id, std::uint16_t year)
Definition staff.cpp:541
std::array< std::uint8_t, STAFF_ROLE_COUNT > roleCounts(std::uint8_t reputation)
Definition staff.cpp:455
constexpr std::array< std::uint8_t, STAFF_ROLE_COUNT > ROLE_LIMITS
Definition staff.h:208
float potentialErrorSd(float scouting_accuracy)
Definition staff.cpp:612
StaffEffects computeEffects(std::span< const StaffMember *const > staff)
Definition staff.cpp:356
constexpr double FOOTBALL_STAFF_SHARE
Definition staff.h:215
constexpr std::size_t MARKET_SIZE
Definition staff.h:212
std::vector< StaffMember > generateClubStaff(const Team &team, const LeagueEconomy &economy, std::uint64_t world_seed, StaffRoster &roster)
Definition staff.cpp:464
std::uint32_t StaffID
Type alias for staff identifiers.
Definition staff.h:30
constexpr std::size_t STAFF_ROLE_COUNT
Definition staff.h:48
constexpr std::size_t STAFF_ATTRIBUTE_COUNT
Definition staff.h:67
StaffAttribute
Staff attributes on a 1-100 scale (order is persisted).
Definition staff.h:53
StaffRole
Staff roles (values are persisted).
Definition staff.h:34
@ AssistantManager
@ GoalkeepingCoach
Aggregates needed to split a league's money between its clubs.
Definition club_economy.h:26
What a club's staff does for the squad (all bounded).
Definition staff.h:105
float injury_prevention
Definition staff.h:115
std::int64_t weekly_payroll
Definition staff.h:128
float layoff_multiplier
Definition staff.h:117
float coaching_goalkeeping
Definition staff.h:110
float youth_potential_bonus
Definition staff.h:119
float coaching_tactical
Definition staff.h:109
float scouting_accuracy
Definition staff.h:125
float coaching_defending
Definition staff.h:108
float coaching_youth
Definition staff.h:111
float training_quality
Definition staff.h:113
float familiarity_rate
Definition staff.h:127
float coaching_fitness
Definition staff.h:106
float coaching_attacking
Definition staff.h:107
A coach, medic, scout or academy manager.
Definition staff.h:78
std::string last_name
Definition staff.h:82
std::array< std::uint8_t, STAFF_ATTRIBUTE_COUNT > attributes
Definition staff.h:86
std::uint32_t wage
Definition staff.h:87
Language nationality
Definition staff.h:83
std::uint8_t age
Definition staff.h:84
std::uint8_t contract_years
Definition staff.h:88
std::string name() const
Definition staff.h:90
std::string first_name
Definition staff.h:81
TeamID team_id
Definition staff.h:80
std::uint8_t attribute(StaffAttribute which) const
Definition staff.h:91
StaffRole role
Definition staff.h:85
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18