Player12
An open source football management simulator
Loading...
Searching...
No Matches
finances.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 <array>
12#include <cstddef>
13#include <cstdint>
14#include <span>
15#include <utility>
16#include <vector>
17
18#include "model/gamedate.h"
19
20class Team;
21class GameData;
22
27enum class FinanceCategory : std::uint8_t
28{
31 Wages,
34 Matchday,
39 Staff,
41 COUNT
42};
43
45inline constexpr std::size_t FINANCE_CATEGORY_COUNT =
46 static_cast<std::size_t>(std::to_underlying(FinanceCategory::COUNT));
47
49const char* financeCategoryKey(FinanceCategory category);
50
61
67{
68 std::array<std::int64_t, FINANCE_CATEGORY_COUNT> by_category{};
69 std::int64_t income = 0;
70 std::int64_t expenses = 0;
71 std::int64_t net() const { return income - expenses; }
72};
73
83{
84 public:
90 explicit Finances(std::int64_t opening_balance,
91 GameDateValue opening_date = GameDateValue(2025, 7, 2));
92
99 void record(const GameDateValue& date, FinanceCategory category,
100 std::int64_t amount);
101
104
111 void addBalance(std::int64_t amount);
112
114 std::int64_t getBalance() const noexcept;
115
117 std::int64_t getTransferBudget() const noexcept;
118
120 void setTransferBudget(std::int64_t budget);
121
123 std::int64_t getWageBudget() const noexcept;
124
126 void setWageBudget(std::int64_t weekly_budget);
127
135 bool moveTransferToWageBudget(std::int64_t transfer_amount,
136 std::int64_t current_weekly_wages);
137
139 const std::vector<FinanceTransaction>& getLedger() const noexcept;
140
142 std::int64_t ledgerTotal() const;
143
145 std::int64_t balanceAt(const GameDateValue& date) const;
146
149 const GameDateValue& to) const;
150
155 int64_t getCurrentWageSpending(const GameData& gamedata,
156 const Team& team) const;
157
158 // Persistence helpers
159
161 void restoreLedger(std::vector<FinanceTransaction> ledger);
162
164 std::span<const FinanceTransaction> pendingTransactions() const;
165
167 std::size_t persistedCount() const noexcept;
168
170 void markPersisted() noexcept;
171
172 private:
173 std::int64_t balance = 0;
174 std::int64_t transfer_budget = 0;
175 std::int64_t wage_budget = 0;
176 std::vector<FinanceTransaction> ledger;
177 std::size_t persisted = 0;
178};
A club's balance, budgets and dated transaction ledger.
Definition finances.h:83
void setTransferBudget(std::int64_t budget)
Sets the transfer allowance.
Definition finances.cpp:102
std::int64_t balance
Definition finances.h:173
void markPersisted() noexcept
Definition finances.cpp:203
int64_t getCurrentWageSpending(const GameData &gamedata, const Team &team) const
Gets the current total wage spending of the team.
Definition finances.cpp:171
std::span< const FinanceTransaction > pendingTransactions() const
Definition finances.cpp:196
std::int64_t wage_budget
Definition finances.h:175
std::vector< FinanceTransaction > ledger
Definition finances.h:176
std::size_t persistedCount() const noexcept
Definition finances.cpp:201
std::int64_t getBalance() const noexcept
Current cash.
Definition finances.cpp:95
std::int64_t getTransferBudget() const noexcept
Remaining transfer allowance for this season.
Definition finances.cpp:97
std::int64_t balanceAt(const GameDateValue &date) const
Balance from the transactions dated on or before date.
Definition finances.cpp:140
std::int64_t ledgerTotal() const
Sum of all ledger amounts (equals the balance).
Definition finances.cpp:132
std::size_t persisted
Definition finances.h:177
FinanceSummary summarize(const GameDateValue &from, const GameDateValue &to) const
Totals of the transactions dated in [from, to].
Definition finances.cpp:151
const std::vector< FinanceTransaction > & getLedger() const noexcept
All transactions in recording order (chronological).
Definition finances.cpp:127
bool moveTransferToWageBudget(std::int64_t transfer_amount, std::int64_t current_weekly_wages)
Moves money between the two budgets at 52 weeks per season.
Definition finances.cpp:114
void setWageBudget(std::int64_t weekly_budget)
Sets the weekly wage allowance.
Definition finances.cpp:109
void addBalance(std::int64_t amount)
Owner investment dated at the newest transaction.
Definition finances.cpp:83
bool revertLastTransaction()
Definition finances.cpp:63
std::int64_t getWageBudget() const noexcept
Weekly wage allowance (cap on the total weekly payroll).
Definition finances.cpp:107
void record(const GameDateValue &date, FinanceCategory category, std::int64_t amount)
Records a dated transaction and updates the balance.
Definition finances.cpp:51
std::int64_t transfer_budget
Definition finances.h:174
void restoreLedger(std::vector< FinanceTransaction > ledger)
Definition finances.cpp:189
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Represents a football team.
Definition team.h:47
FinanceCategory
Ledger categories (values are persisted).
Definition finances.h:28
const char * financeCategoryKey(FinanceCategory category)
Definition finances.cpp:39
constexpr std::size_t FINANCE_CATEGORY_COUNT
Definition finances.h:45
Per-category totals of a ledger range.
Definition finances.h:67
std::int64_t expenses
Definition finances.h:70
std::array< std::int64_t, FINANCE_CATEGORY_COUNT > by_category
Definition finances.h:68
std::int64_t net() const
Definition finances.h:71
std::int64_t income
Definition finances.h:69
One dated ledger entry; positive amounts are income.
Definition finances.h:56
std::int64_t amount
Definition finances.h:59
FinanceCategory category
Definition finances.h:58
GameDateValue date
Definition finances.h:57
Represents a specific date in the game world.
Definition gamedate.h:20