Player12
An open source football management simulator
Loading...
Searching...
No Matches
supporters.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 TransferMarket;
23class WorldSimulation;
24struct BoardState;
25
27enum class SupporterFactor : std::uint8_t
28{
29 Results = 0,
30 Derby,
32 StarSale,
34 COUNT
35};
36
39{
41 std::vector<float> result_deltas;
43 std::vector<int> derby_points;
45 float ticket_ratio = 1.0f;
47 int star_sales = 0;
49};
50
57
60{
61 float index = 55.0f;
63 std::vector<SupporterReason> reasons;
64};
65
70{
72inline constexpr float NEUTRAL = 55.0f;
74inline constexpr float MAX_BOARD_NUDGE = 0.25f;
76inline constexpr float BOARD_DEAD_ZONE = 15.0f;
78inline constexpr int STAR_WINDOW_DAYS = 120;
80inline constexpr int STAR_RANK = 3;
81
88
90float settle(float previous, float target);
91
96float boardNudge(float index);
97
99const char* moodKey(float index);
100
102const char* reasonKey(const SupporterReason& reason);
103} // namespace SupporterModel
104
114{
115 public:
117 const SupporterMood& mood() const { return current; }
119 TeamID team() const { return team_id; }
121 std::int32_t updatedOn() const { return updated_day; }
122
128 void onDayEnd(const GameData& gamedata, const GameDateValue& date,
129 TeamID managed_team_id, const Calendar& calendar,
130 const TransferMarket& transfers, WorldSimulation& world);
131
137 float update(TeamID new_team_id, std::int32_t day,
138 const SupporterFacts& facts);
139
141 static SupporterFacts gather(const GameData& gamedata,
142 const GameDateValue& date, TeamID team_id,
143 const BoardState& board,
144 const Calendar& calendar,
145 const TransferMarket& transfers,
146 std::optional<TeamID> rival);
147
148 void load(const std::shared_ptr<DatabaseConnection>& db_conn);
150 void save(const std::shared_ptr<DatabaseConnection>& db_conn) const;
151
152 private:
154 std::int32_t updated_day = 0;
156};
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
The managed club's supporters: their mood is recomputed once a week from the facts and nudges the boa...
Definition supporters.h:114
void save(const std::shared_ptr< DatabaseConnection > &db_conn) const
Definition supporters.cpp:316
TeamID team_id
Definition supporters.h:153
static SupporterFacts gather(const GameData &gamedata, const GameDateValue &date, TeamID team_id, const BoardState &board, const Calendar &calendar, const TransferMarket &transfers, std::optional< TeamID > rival)
Definition supporters.cpp:179
std::int32_t updated_day
Definition supporters.h:154
float update(TeamID new_team_id, std::int32_t day, const SupporterFacts &facts)
Definition supporters.cpp:166
std::int32_t updatedOn() const
Definition supporters.h:121
void load(const std::shared_ptr< DatabaseConnection > &db_conn)
Definition supporters.cpp:286
const SupporterMood & mood() const
Definition supporters.h:117
SupporterMood current
Definition supporters.h:155
void onDayEnd(const GameData &gamedata, const GameDateValue &date, TeamID managed_team_id, const Calendar &calendar, const TransferMarket &transfers, WorldSimulation &world)
Definition supporters.cpp:267
TeamID team() const
Definition supporters.h:119
Deals, loans, pre-contracts, payments and history of the market.
Definition transfer_market.h:221
Everything that happens between matches.
Definition world_simulation.h:104
bool day
Definition match_stadium_3d.cpp:447
Pure supporter rules (no game state), unit tested in isolation.
Definition supporters.h:70
constexpr float NEUTRAL
Definition supporters.h:72
const char * reasonKey(const SupporterReason &reason)
Definition supporters.cpp:138
constexpr float MAX_BOARD_NUDGE
Definition supporters.h:74
SupporterMood evaluate(const SupporterFacts &facts)
Definition supporters.cpp:68
float boardNudge(float index)
Definition supporters.cpp:120
constexpr int STAR_RANK
Definition supporters.h:80
constexpr float BOARD_DEAD_ZONE
Definition supporters.h:76
const char * moodKey(float index)
Definition supporters.cpp:129
float settle(float previous, float target)
Definition supporters.cpp:115
constexpr int STAR_WINDOW_DAYS
Definition supporters.h:78
int index
Definition runtime_editor.cpp:94
The board's view of the manager of the managed club.
Definition board.h:69
Represents a specific date in the game world.
Definition gamedate.h:20
Observable facts the supporters judge the club by.
Definition supporters.h:39
int star_sales
Definition supporters.h:47
std::vector< float > result_deltas
Definition supporters.h:41
float ticket_ratio
Definition supporters.h:45
int star_signings
Definition supporters.h:48
std::vector< int > derby_points
Definition supporters.h:43
The supporters' mood: a 0-100 index and why it is there.
Definition supporters.h:60
std::vector< SupporterReason > reasons
Definition supporters.h:63
float index
Definition supporters.h:61
One factor and how many index points it is worth.
Definition supporters.h:53
SupporterFactor factor
Definition supporters.h:54
float points
Definition supporters.h:55
SupporterFactor
What moves the supporters (values are persisted).
Definition supporters.h:28
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18