Player12
An open source football management simulator
Loading...
Searching...
No Matches
preseason.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 <cstdint>
12#include <memory>
13#include <optional>
14#include <vector>
15
16#include "global/types.h"
17#include "model/gamedate.h"
18
19class Calendar;
21class GameData;
22class Inbox;
23struct MatchReport;
24
26enum class TrainingCamp : std::uint8_t
27{
28 None = 0,
30 Abroad,
31 COUNT
32};
33
35enum class OpponentLevel : std::uint8_t
36{
37 Weaker = 0,
38 Similar,
40 COUNT
41};
42
45{
48 bool home = true;
49 bool tour = false;
50 bool editable = false;
51};
52
55{
57 std::uint8_t reputation = 0;
58 bool abroad = false;
59};
60
63{
65 std::int64_t cost = 0;
66 float sharpness = 0.0f;
67 float familiarity = 0.0f;
68 float morale = 0.0f;
71 bool available = false;
72};
73
81
84{
85 std::uint16_t season_year = 0;
87 std::int64_t camp_cost = 0;
89 bool camp_applied = false;
90 std::vector<GameDateValue> tour_dates;
91 std::uint8_t tour_matches = 0;
92 bool tour_reputation = false;
93};
94
105namespace Preseason
106{
107inline constexpr int TOUR_MATCHES_FOR_REPUTATION = 2;
109inline constexpr int LEVEL_GAP = 8;
110inline constexpr int CAMP_DAYS = 6;
111
113CampQuote campQuote(TrainingCamp camp, double season_income,
114 const GameDateValue& first_friendly);
115
117std::int64_t tourFee(double season_income, std::uint8_t opponent_reputation);
118
120bool levelMatches(OpponentLevel level, std::uint8_t own, std::uint8_t other);
121} // namespace Preseason
122
135{
136 public:
138 std::vector<FriendlySlot> friendlies(const Calendar& calendar,
139 TeamID managed_team_id,
140 const GameDateValue& today) const;
141
144 std::vector<OpponentOption> opponents(const GameData& gamedata,
145 const Calendar& calendar,
146 TeamID managed_team_id,
147 const GameDateValue& date,
148 OpponentLevel level, bool abroad) const;
149
154 bool setFriendly(Calendar& calendar, const GameData& gamedata,
155 TeamID managed_team_id, const GameDateValue& date,
156 TeamID opponent_id, bool home, bool tour,
157 const GameDateValue& today);
158
161 std::vector<FriendlySuggestion> suggest(const GameData& gamedata,
162 const Calendar& calendar,
163 TeamID managed_team_id,
164 const GameDateValue& today) const;
165
167 TrainingCamp suggestCamp(const GameData& gamedata, const Calendar& calendar,
168 TeamID managed_team_id,
169 const GameDateValue& today) const;
170
171 CampQuote campQuote(const GameData& gamedata, const Calendar& calendar,
172 TeamID managed_team_id, TrainingCamp camp) const;
173
178 bool bookCamp(GameData& gamedata, const Calendar& calendar,
179 TeamID managed_team_id, TrainingCamp camp,
180 const GameDateValue& today);
181
183 void onDay(GameData& gamedata, const GameDateValue& date,
184 TeamID managed_team_id, Inbox& inbox);
185
187 void onMatchPlayed(GameData& gamedata, const MatchReport& report,
188 TeamID managed_team_id);
189
191 void onSeasonStart(std::uint16_t season_year);
192
193 const PreseasonState& getState() const { return state; }
194
195 void clear();
196 void load(const std::shared_ptr<DatabaseConnection>& db_conn);
197 void save(const std::shared_ptr<DatabaseConnection>& db_conn) const;
198
199 private:
200 std::optional<GameDateValue> firstFriendly(const Calendar& calendar,
201 TeamID managed_team_id) const;
202
204};
Manages the match calendar for a season.
Definition calendar.h:133
Manages the SQLite database connection and transaction lifecycle.
Definition database_connection.h:24
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Chronological list of messages with read tracking.
Definition inbox.h:113
Friendlies, tour and training camp of the managed club.
Definition preseason.h:135
void load(const std::shared_ptr< DatabaseConnection > &db_conn)
Definition preseason.cpp:485
void clear()
Definition preseason.cpp:483
void save(const std::shared_ptr< DatabaseConnection > &db_conn) const
Definition preseason.cpp:514
CampQuote campQuote(const GameData &gamedata, const Calendar &calendar, TeamID managed_team_id, TrainingCamp camp) const
Definition preseason.cpp:357
const PreseasonState & getState() const
Definition preseason.h:193
PreseasonState state
Definition preseason.h:203
std::optional< GameDateValue > firstFriendly(const Calendar &calendar, TeamID managed_team_id) const
Definition preseason.cpp:180
void onSeasonStart(std::uint16_t season_year)
Definition preseason.cpp:477
void onMatchPlayed(GameData &gamedata, const MatchReport &report, TeamID managed_team_id)
Definition preseason.cpp:449
std::vector< OpponentOption > opponents(const GameData &gamedata, const Calendar &calendar, TeamID managed_team_id, const GameDateValue &date, OpponentLevel level, bool abroad) const
Definition preseason.cpp:191
std::vector< FriendlySuggestion > suggest(const GameData &gamedata, const Calendar &calendar, TeamID managed_team_id, const GameDateValue &today) const
Definition preseason.cpp:314
TrainingCamp suggestCamp(const GameData &gamedata, const Calendar &calendar, TeamID managed_team_id, const GameDateValue &today) const
Definition preseason.cpp:369
bool bookCamp(GameData &gamedata, const Calendar &calendar, TeamID managed_team_id, TrainingCamp camp, const GameDateValue &today)
Definition preseason.cpp:395
bool setFriendly(Calendar &calendar, const GameData &gamedata, TeamID managed_team_id, const GameDateValue &date, TeamID opponent_id, bool home, bool tour, const GameDateValue &today)
Definition preseason.cpp:242
void onDay(GameData &gamedata, const GameDateValue &date, TeamID managed_team_id, Inbox &inbox)
Definition preseason.cpp:417
std::vector< FriendlySlot > friendlies(const Calendar &calendar, TeamID managed_team_id, const GameDateValue &today) const
Definition preseason.cpp:157
Pricing of camps and tours.
Definition preseason.cpp:97
bool levelMatches(OpponentLevel level, std::uint8_t own, std::uint8_t other)
Definition preseason.cpp:139
std::int64_t tourFee(double season_income, std::uint8_t opponent_reputation)
Definition preseason.cpp:130
constexpr int LEVEL_GAP
Definition preseason.h:109
constexpr int CAMP_DAYS
Definition preseason.h:110
CampQuote campQuote(TrainingCamp camp, double season_income, const GameDateValue &first_friendly)
Definition preseason.cpp:98
constexpr int TOUR_MATCHES_FOR_REPUTATION
Definition preseason.h:107
TrainingCamp
Pre-season training camp (values are persisted).
Definition preseason.h:27
OpponentLevel
Opponent strength relative to the managed club.
Definition preseason.h:36
Cost, dates and effect of a training camp.
Definition preseason.h:63
GameDateValue end
Definition preseason.h:70
TrainingCamp camp
Definition preseason.h:64
GameDateValue start
Definition preseason.h:69
float sharpness
Definition preseason.h:66
float familiarity
Definition preseason.h:67
bool available
Definition preseason.h:71
std::int64_t cost
Definition preseason.h:65
float morale
Definition preseason.h:68
A pre-season friendly of the managed club.
Definition preseason.h:45
TeamID opponent_id
Definition preseason.h:47
GameDateValue date
Definition preseason.h:46
bool tour
Definition preseason.h:49
bool editable
Definition preseason.h:50
bool home
Definition preseason.h:48
A suggested friendly (the assistant's plan).
Definition preseason.h:76
bool home
Definition preseason.h:79
GameDateValue date
Definition preseason.h:77
TeamID opponent_id
Definition preseason.h:78
Represents a specific date in the game world.
Definition gamedate.h:20
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
A club that can be invited to a friendly.
Definition preseason.h:55
TeamID team_id
Definition preseason.h:56
std::uint8_t reputation
Definition preseason.h:57
bool abroad
Definition preseason.h:58
The season's pre-season choices (persisted).
Definition preseason.h:84
std::int64_t camp_cost
Definition preseason.h:87
std::uint16_t season_year
Definition preseason.h:85
std::uint8_t tour_matches
Definition preseason.h:91
GameDateValue camp_end
Definition preseason.h:88
std::vector< GameDateValue > tour_dates
Definition preseason.h:90
TrainingCamp camp
Definition preseason.h:86
bool tour_reputation
Definition preseason.h:92
bool camp_applied
Definition preseason.h:89
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18