Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_rules.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 <cstdint>
13
14#include "model/match_events.h"
15
21namespace MatchRules
22{
25{
26 int goals = 0;
28 int cards = 0;
29 int injuries = 0;
30 int penalties = 0;
31};
32
35int computeAddedMinutes(const StoppageLog& log, int period);
36
38float periodStartMinute(int period);
40float periodEndMinute(int period);
41
48{
49 bool required = false;
54 bool extraTime = true;
55};
56
62bool shootoutDecided(int homeGoals, int homeKicks, int awayGoals,
63 int awayKicks);
64
69float computeMatchRating(const PlayerMatchStats& stats, bool goalkeeper,
70 bool defender, int teamGoalDifference);
71
73float playerHeightMetres(std::uint8_t heightCentimetres);
74
76float headerReachMetres(float heightMetres, float physicality);
77
79float goalkeeperReachMetres(float heightMetres, float goalkeeping);
81float goalkeeperHandlingRadiusMetres(float heightMetres, float goalkeeping,
82 float ballHeightMetres,
83 bool diving = false);
84
86float aerialDuelStrength(float heightMetres, float physicality,
87 float ballHeightMetres);
88
89enum class FoulSanction : std::uint8_t
90{
91 NONE,
92 YELLOW,
94 RED
95};
96
98{
100 float severityRoll = 0.0f;
101 float cardRoll = 0.0f;
103 float strictness = 1.0f;
105 bool tactical = false;
107 bool denyingGoalChance = false;
109 bool inPenaltyArea = false;
111 bool offenderIsAway = false;
113 float venueBiasScale = 1.0f;
114};
115
117
120{
121 float defending = 0.5f;
122 float dribbling = 0.5f;
124 float carrierPhysicality = 0.5f;
126 float pressing = 0.5f;
128 float riskTaking = 0.5f;
130 float exposure = 0.0f;
132 bool shielding = false;
133 bool sliding = false;
134 bool fromBehind = false;
135 bool inPenaltyArea = false;
136 bool defenderBooked = false;
137};
138
140float tackleWinChance(const TackleContext& context);
141
146float tackleFoulPropensity(const TackleContext& context);
147
152inline float staminaDrainPerSecond(float speedRatio, float endurance,
153 float pressingIntensity)
154{
155 using P = MatchTuning::Fatigue;
156 const float ratio = std::clamp(speedRatio, 0.0f, 1.5f);
157 const float sprint = std::max(0.0f, ratio - P::SPRINT_THRESHOLD) /
158 (1.0f - P::SPRINT_THRESHOLD);
159 const float work =
160 P::IDLE_DRAIN + ratio * ratio * P::RUNNING_DRAIN +
161 sprint * P::SPRINT_DRAIN +
162 std::clamp(pressingIntensity, 0.0f, 1.0f) * P::PRESSING_DRAIN;
163 return work * (P::ENDURANCE_BASE -
164 std::clamp(endurance, 0.0f, 1.0f) * P::ENDURANCE_RELIEF);
165}
166} // namespace MatchRules
Definition match_rules.cpp:80
bool shootoutDecided(int homeGoals, int homeKicks, int awayGoals, int awayKicks)
Definition match_rules.cpp:117
float goalkeeperHandlingRadiusMetres(float heightMetres, float goalkeeping, float ballHeightMetres, bool diving)
Definition match_rules.cpp:201
float staminaDrainPerSecond(float speedRatio, float endurance, float pressingIntensity)
Definition match_rules.h:152
FoulSanction decideFoulSanction(const FoulContext &context)
Definition match_rules.cpp:236
float tackleFoulPropensity(const TackleContext &context)
Definition match_rules.cpp:285
float goalkeeperReachMetres(float heightMetres, float goalkeeping)
Definition match_rules.cpp:193
float aerialDuelStrength(float heightMetres, float physicality, float ballHeightMetres)
Definition match_rules.cpp:224
float computeMatchRating(const PlayerMatchStats &stats, bool goalkeeper, bool defender, int teamGoalDifference)
Definition match_rules.cpp:130
float periodStartMinute(int period)
Definition match_rules.cpp:99
float periodEndMinute(int period)
Definition match_rules.cpp:108
int computeAddedMinutes(const StoppageLog &log, int period)
Definition match_rules.cpp:81
float playerHeightMetres(std::uint8_t heightCentimetres)
Definition match_rules.cpp:178
float headerReachMetres(float heightMetres, float physicality)
Definition match_rules.cpp:186
float tackleWinChance(const TackleContext &context)
Definition match_rules.cpp:267
FoulSanction
Definition match_rules.h:90
Definition match_rules.h:98
bool offenderIsAway
Definition match_rules.h:111
float cardRoll
Definition match_rules.h:101
float severityRoll
Definition match_rules.h:100
float venueBiasScale
Definition match_rules.h:113
bool denyingGoalChance
Definition match_rules.h:107
bool offenderAlreadyBooked
Definition match_rules.h:110
float strictness
Definition match_rules.h:103
bool inPenaltyArea
Definition match_rules.h:109
bool tactical
Definition match_rules.h:105
Definition match_rules.h:48
int homeAggregate
Definition match_rules.h:51
bool extraTime
Definition match_rules.h:54
bool required
Definition match_rules.h:49
int awayAggregate
Definition match_rules.h:52
Definition match_rules.h:25
int goals
Definition match_rules.h:26
int cards
Definition match_rules.h:28
int injuries
Definition match_rules.h:29
int substitutions
Definition match_rules.h:27
int penalties
Definition match_rules.h:30
Definition match_rules.h:120
float exposure
Definition match_rules.h:130
float defending
Definition match_rules.h:121
bool defenderBooked
Definition match_rules.h:136
bool fromBehind
Definition match_rules.h:134
float defenderPhysicality
Definition match_rules.h:123
float pressing
Definition match_rules.h:126
bool sliding
Definition match_rules.h:133
float dribbling
Definition match_rules.h:122
float carrierPhysicality
Definition match_rules.h:124
bool shielding
Definition match_rules.h:132
float riskTaking
Definition match_rules.h:128
bool inPenaltyArea
Definition match_rules.h:135
Definition match_tuning.h:1026
Definition match_events.h:122