Player12
An open source football management simulator
Loading...
Searching...
No Matches
discipline.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 <set>
14#include <utility>
15#include <vector>
16
17#include "global/types.h"
18
19class GameData;
20struct MatchReport;
21
27{
30 uint8_t second_yellow_ban = 1;
31 uint8_t straight_red_ban = 1;
32 uint8_t repeat_red_extra = 1;
33};
34
44
54{
55 public:
56 explicit Discipline(DisciplineRules competition_rules = {})
57 : rules(competition_rules)
58 {
59 }
60
65 void processMatch(const MatchReport& report, const GameData& gamedata);
66
67 bool isSuspended(PlayerID player_id, MatchType scope) const;
68 uint8_t banMatches(PlayerID player_id, MatchType scope) const;
69
71 std::vector<DisciplinaryRecord> suspendedPlayers(
72 TeamID team_id, const GameData& gamedata) const;
73
75 void resetSeason();
76
77 std::vector<DisciplinaryRecord> records() const;
78 void restore(const std::vector<DisciplinaryRecord>& stored);
79
80 private:
81 using Key = std::pair<PlayerID, MatchType>;
82
83 void book(DisciplinaryRecord& record, unsigned yellows, unsigned reds) const;
84
86 std::map<Key, DisciplinaryRecord> by_player;
88 std::set<Key> active_bans;
89};
Yellow-card accumulation and red-card suspensions.
Definition discipline.h:54
std::map< Key, DisciplinaryRecord > by_player
Definition discipline.h:86
DisciplineRules rules
Definition discipline.h:85
void processMatch(const MatchReport &report, const GameData &gamedata)
Serves one match of every ban of the two teams, then books the cards of this match (so a red card is ...
Definition discipline.cpp:34
void book(DisciplinaryRecord &record, unsigned yellows, unsigned reds) const
Definition discipline.cpp:88
void resetSeason()
Definition discipline.cpp:143
Discipline(DisciplineRules competition_rules={})
Definition discipline.h:56
void restore(const std::vector< DisciplinaryRecord > &stored)
Definition discipline.cpp:162
std::pair< PlayerID, MatchType > Key
Definition discipline.h:81
bool isSuspended(PlayerID player_id, MatchType scope) const
Definition discipline.cpp:118
std::vector< DisciplinaryRecord > records() const
Definition discipline.cpp:154
std::set< Key > active_bans
Definition discipline.h:88
uint8_t banMatches(PlayerID player_id, MatchType scope) const
Definition discipline.cpp:123
std::vector< DisciplinaryRecord > suspendedPlayers(TeamID team_id, const GameData &gamedata) const
Definition discipline.cpp:129
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Cards and outstanding ban of a player in one competition type.
Definition discipline.h:37
uint8_t season_reds
Definition discipline.h:41
uint8_t ban_matches
Definition discipline.h:42
MatchType scope
Definition discipline.h:39
uint16_t season_yellows
Definition discipline.h:40
PlayerID player_id
Definition discipline.h:38
Suspension rules of a competition (every-fifth-yellow style).
Definition discipline.h:27
uint8_t repeat_red_extra
Definition discipline.h:32
uint8_t straight_red_ban
Definition discipline.h:31
uint8_t yellow_accumulation_ban
Definition discipline.h:29
uint8_t second_yellow_ban
Definition discipline.h:30
uint8_t yellow_card_threshold
Definition discipline.h:28
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
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
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21