Player12
An open source football management simulator
Loading...
Searching...
No Matches
calendar.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 <map>
13#include <vector>
14
15#include "gamedate.h"
16#include "match.h"
17
31{
32constexpr uint8_t MONDAY = 0;
33constexpr uint8_t TUESDAY = 1;
34constexpr uint8_t WEDNESDAY = 2;
35constexpr uint8_t THURSDAY = 3;
36constexpr uint8_t FRIDAY = 4;
37constexpr uint8_t SATURDAY = 5;
38constexpr uint8_t SUNDAY = 6;
40constexpr int MIN_REST_DAYS = 2;
43constexpr int MIN_REST_BEFORE_TIE = 3;
44
48int restDays(MatchType earlier, MatchType later);
49constexpr uint8_t SEASON_START_MONTH = 7;
50constexpr size_t MAX_CUP_ROUNDS = 8;
51constexpr size_t PRESEASON_FRIENDLIES = 4;
52
54uint8_t dayOfWeek(const GameDateValue& date);
55
57GameDateValue addDays(const GameDateValue& date, int days);
58
60uint16_t seasonStartYear(const GameDateValue& date);
61
63GameDateValue leagueStart(uint16_t season_year);
64
66GameDateValue leagueEnd(uint16_t season_year);
67
70{
73 std::vector<GameDateValue> match_days;
74 bool summer = false;
75};
76
78std::vector<InternationalWindow> internationalWindows(uint16_t season_year);
79
80bool isInternationalBreak(const GameDateValue& date);
81bool isWinterBreak(const GameDateValue& date);
82
85constexpr size_t CONTINENTAL_WEEKS = 16;
86
92std::vector<GameDateValue> continentalWeeks(uint16_t season_year);
93
95bool isContinentalWeek(const GameDateValue& date);
96
98bool isBlackout(const GameDateValue& date);
99
108std::vector<GameDateValue> leagueRoundDates(uint16_t season_year, size_t rounds,
109 uint8_t variant = 0);
110
112std::vector<GameDateValue> cupRoundDates(uint16_t season_year, size_t rounds);
113
118std::vector<GameDateValue> friendlyDates(const GameDateValue& from,
119 size_t count);
120
123} // namespace SeasonCalendar
124
133{
134 public:
138 Calendar() = default;
139
144 void generate(const class GameData& gamedata, const GameDateValue& startDate);
145
150 void addMatch(const Match& match);
151
156 const std::map<GameDateValue, std::vector<Match>>& getFullCalendar() const;
157
163 const std::vector<Match>& getMatchesForDate(const GameDateValue& date) const;
164 std::vector<Match>& getMatchesForDateMutable(const GameDateValue& date);
165
167 const Match* findMatch(const GameDateValue& date, TeamID home_id,
168 TeamID away_id) const;
169 Match* findMatch(const GameDateValue& date, TeamID home_id, TeamID away_id);
170
172 std::vector<Match> getTeamFixtures(TeamID team_id) const;
173
185 size_t protectRest(const GameDateValue& after);
186
190
191 private:
192 void generateSeasonFixtures(const class GameData& gamedata,
193 uint16_t season_year);
194
195 void generateFriendlies(const class GameData& gamedata,
196 const GameDateValue& startDate, size_t numFriendlies);
197
198 std::map<GameDateValue, std::vector<Match>> schedule;
199 bool rest_check_pending = false;
200};
Manages the match calendar for a season.
Definition calendar.h:133
size_t protectRest(const GameDateValue &after)
Keeps clubs rested around cup and continental ties.
Definition calendar.cpp:1171
std::map< GameDateValue, std::vector< Match > > schedule
Definition calendar.h:198
void markRestChecked()
Treats the current fixtures as already checked by protectRest() (fixtures loaded from a save keep the...
Definition calendar.h:189
void addMatch(const Match &match)
Adds a single match to the calendar.
Definition calendar.cpp:854
const std::vector< Match > & getMatchesForDate(const GameDateValue &date) const
Gets the matches scheduled for a specific date.
Definition calendar.cpp:868
Calendar()=default
Default constructor.
bool rest_check_pending
Definition calendar.h:199
void generate(const class GameData &gamedata, const GameDateValue &startDate)
Generates the full calendar of the season starting on a date.
Definition calendar.cpp:840
void generateFriendlies(const class GameData &gamedata, const GameDateValue &startDate, size_t numFriendlies)
Definition calendar.cpp:1334
const std::map< GameDateValue, std::vector< Match > > & getFullCalendar() const
Gets the full calendar schedule.
Definition calendar.cpp:862
std::vector< Match > getTeamFixtures(TeamID team_id) const
All fixtures of a team in date order.
Definition calendar.cpp:916
std::vector< Match > & getMatchesForDateMutable(const GameDateValue &date)
Definition calendar.cpp:880
const Match * findMatch(const GameDateValue &date, TeamID home_id, TeamID away_id) const
Finds a fixture by its natural key (date, home, away).
Definition calendar.cpp:886
void generateSeasonFixtures(const class GameData &gamedata, uint16_t season_year)
Definition calendar.cpp:930
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Represents a football match between two teams.
Definition match.h:38
Season date rules shared by the calendar and the competitions.
Definition calendar.h:31
constexpr uint8_t FRIDAY
Definition calendar.h:36
std::vector< InternationalWindow > internationalWindows(uint16_t season_year)
Windows of the season starting in season_year, by date.
Definition calendar.cpp:279
GameDateValue leagueEnd(uint16_t season_year)
Last regular league Saturday (on or before 24 May).
Definition calendar.cpp:272
GameDateValue nextFreeMidweek(const GameDateValue &date)
First Wednesday after date that is not in a break.
Definition calendar.cpp:466
constexpr size_t CONTINENTAL_WEEKS
Definition calendar.h:85
bool isInternationalBreak(const GameDateValue &date)
Definition calendar.cpp:303
bool isWinterBreak(const GameDateValue &date)
Definition calendar.cpp:334
bool isContinentalWeek(const GameDateValue &date)
True from Tuesday to Thursday of a continental club week.
Definition calendar.cpp:329
constexpr size_t PRESEASON_FRIENDLIES
Definition calendar.h:51
GameDateValue leagueStart(uint16_t season_year)
First league Saturday (first Saturday on or after 15 August).
Definition calendar.cpp:266
constexpr int MIN_REST_BEFORE_TIE
Definition calendar.h:43
constexpr uint8_t WEDNESDAY
Definition calendar.h:34
constexpr uint8_t THURSDAY
Definition calendar.h:35
std::vector< GameDateValue > leagueRoundDates(uint16_t season_year, size_t rounds, uint8_t variant=0)
Anchor date of each league round: a Saturday for weekend rounds (matches spread from Friday to Monday...
Definition calendar.cpp:374
constexpr uint8_t TUESDAY
Definition calendar.h:33
bool isBlackout(const GameDateValue &date)
No competitive fixtures may be scheduled on this date.
Definition calendar.cpp:342
constexpr int MIN_REST_DAYS
Definition calendar.h:40
std::vector< GameDateValue > continentalWeeks(uint16_t season_year)
Tuesday of every continental club week (see CONTINENTAL_WEEKS). Continental matches are played Tuesda...
Definition calendar.cpp:320
constexpr size_t MAX_CUP_ROUNDS
Definition calendar.h:50
uint16_t seasonStartYear(const GameDateValue &date)
Calendar year in which the season containing date started.
Definition calendar.cpp:259
constexpr uint8_t SEASON_START_MONTH
Definition calendar.h:49
constexpr uint8_t SATURDAY
Definition calendar.h:37
std::vector< GameDateValue > friendlyDates(const GameDateValue &from, size_t count)
Saturdays of the pre-season friendly weeks after from and before the league; each week's friendlies a...
Definition calendar.cpp:445
GameDateValue addDays(const GameDateValue &date, int days)
Adds (or subtracts) days in O(1).
Definition calendar.cpp:254
int restDays(MatchType earlier, MatchType later)
Definition calendar.cpp:458
std::vector< GameDateValue > cupRoundDates(uint16_t season_year, size_t rounds)
Date of each cup round; the last one (the final) is a Saturday.
Definition calendar.cpp:347
uint8_t dayOfWeek(const GameDateValue &date)
Weekday of a date, 0 = Monday ... 6 = Sunday.
Definition calendar.cpp:249
constexpr uint8_t SUNDAY
Definition calendar.h:38
constexpr uint8_t MONDAY
Definition calendar.h:32
Represents a specific date in the game world.
Definition gamedate.h:20
Days in which clubs release players to their national teams.
Definition calendar.h:70
bool summer
Definition calendar.h:74
GameDateValue end
Definition calendar.h:72
std::vector< GameDateValue > match_days
Definition calendar.h:73
GameDateValue start
Definition calendar.h:71
MatchType
Represents the type or category of a match.
Definition types.h:40
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18