Player12
An open source football management simulator
Loading...
Searching...
No Matches
news_feed.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 <cstddef>
12#include <cstdint>
13#include <optional>
14#include <span>
15#include <string>
16#include <vector>
17
18#include "global/types.h"
19#include "model/awards.h"
20#include "model/gamedate.h"
21#include "model/inbox.h"
23#include "model/match.h"
24#include "model/records.h"
27
28class Calendar;
29class Game;
30class GameData;
31
33enum class NewsKind : std::uint8_t
34{
35 Transfer = 0,
36 Manager,
37 Race,
38 Upset,
39 Record,
40 Award,
41 COUNT
42};
43
45const char* newsKindKey(NewsKind kind);
46
49{
51 LeagueID id = 0;
52
53 bool operator==(const NewsCompetition& other) const = default;
54};
55
84
87{
88 const GameData* gamedata = nullptr;
90 const Calendar* calendar = nullptr;
91 std::span<const TransferRecord> transfers;
93 std::span<const ManagerStint> stints;
94 std::string manager_name;
96 std::span<const AiManager> managers;
97 std::span<const Vacancy> vacancies;
99 std::span<const InboxMessage> inbox;
100 std::span<const AwardRecord> awards;
102 std::span<const RecordEntry> records;
103 std::span<const SeasonHistoryEntry> history;
107};
108
111{
112 std::optional<LeagueID> country;
113 std::optional<NewsCompetition> competition;
114 std::optional<NewsKind> kind;
115
116 bool matches(const NewsItem& item) const;
117};
118
126namespace NewsFeed
127{
129inline constexpr std::uint32_t MAJOR_FEE = 12'000'000;
131inline constexpr int UPSET_REPUTATION_GAP = 18;
133inline constexpr std::uint16_t LEADER_MIN_PLAYED = 6;
135inline constexpr int RACE_GAMES_LEFT = 8;
136inline constexpr int RACE_POINTS_GAP = 3;
137
139std::vector<NewsItem> build(const NewsSources& sources,
140 const GameDateValue& from, const GameDateValue& to);
141
148std::vector<NewsItem> forGame(const Game& game, const GameData& gamedata);
149
151std::vector<std::size_t> filter(std::span<const NewsItem> items,
152 const NewsFilter& filter);
153
155std::size_t variant(NewsKind kind, std::uint32_t first, std::uint32_t second,
156 const GameDateValue& date, std::size_t count);
157} // namespace NewsFeed
Manages the match calendar for a season.
Definition calendar.h:133
Singleton class that acts as an in-memory cache for the database state.
Definition gamedata.h:43
Represents the core game state and logic.
Definition game.h:48
The world news feed: dated stories derived from saved data.
Definition news_feed.h:127
std::vector< std::size_t > filter(std::span< const NewsItem > items, const NewsFilter &filter)
Definition news_feed.cpp:825
constexpr std::uint16_t LEADER_MIN_PLAYED
Definition news_feed.h:133
constexpr int RACE_GAMES_LEFT
Definition news_feed.h:135
std::vector< NewsItem > build(const NewsSources &sources, const GameDateValue &from, const GameDateValue &to)
Definition news_feed.cpp:745
std::size_t variant(NewsKind kind, std::uint32_t first, std::uint32_t second, const GameDateValue &date, std::size_t count)
Definition news_feed.cpp:731
std::vector< NewsItem > forGame(const Game &game, const GameData &gamedata)
Definition news_feed.cpp:784
constexpr std::uint32_t MAJOR_FEE
Definition news_feed.h:129
constexpr int UPSET_REPUTATION_GAP
Definition news_feed.h:131
constexpr int RACE_POINTS_GAP
Definition news_feed.h:136
const char * newsKindKey(NewsKind kind)
Definition news_feed.cpp:696
NewsKind
What a news story is about (filter of the news screen).
Definition news_feed.h:34
Represents a specific date in the game world.
Definition gamedate.h:20
A competition a story belongs to (id 0: none).
Definition news_feed.h:49
bool operator==(const NewsCompetition &other) const =default
MatchType type
Definition news_feed.h:50
What the news screen shows (unset fields: everything).
Definition news_feed.h:111
std::optional< LeagueID > country
Definition news_feed.h:112
bool matches(const NewsItem &item) const
Definition news_feed.cpp:724
std::optional< NewsCompetition > competition
Definition news_feed.h:113
std::optional< NewsKind > kind
Definition news_feed.h:114
One story of the world news feed.
Definition news_feed.h:64
TeamID other_team_id
Definition news_feed.h:73
std::vector< std::string > args
Definition news_feed.h:70
std::string headline() const
Definition news_feed.cpp:719
GameDateValue date
Definition news_feed.h:65
TeamID away_id
Definition news_feed.h:78
NewsCompetition competition
Definition news_feed.h:68
NewsKind kind
Definition news_feed.h:66
std::string headline_key
Definition news_feed.h:69
PlayerID player_id
Definition news_feed.h:71
TeamID team_id
Definition news_feed.h:72
LeagueID country
Definition news_feed.h:67
std::uint32_t weight
Definition news_feed.h:79
GameDateValue match_date
Definition news_feed.h:76
bool has_match
Definition news_feed.h:75
TeamID home_id
Definition news_feed.h:77
The saved facts the feed is built from.
Definition news_feed.h:87
std::span< const SeasonHistoryEntry > history
Definition news_feed.h:103
std::span< const Vacancy > vacancies
Definition news_feed.h:97
const Calendar * calendar
Definition news_feed.h:90
std::span< const RecordEntry > records
Definition news_feed.h:102
std::string manager_name
Definition news_feed.h:94
std::span< const ManagerStint > stints
Definition news_feed.h:93
std::span< const InboxMessage > inbox
Definition news_feed.h:99
TeamID managed_team
Definition news_feed.h:104
GameDateValue world_start
Definition news_feed.h:106
std::span< const AiManager > managers
Definition news_feed.h:96
const GameData * gamedata
Definition news_feed.h:88
std::span< const TransferRecord > transfers
Definition news_feed.h:91
std::span< const AwardRecord > awards
Definition news_feed.h:100
MatchType
Represents the type or category of a match.
Definition types.h:40
uint8_t LeagueID
Type alias for League identifiers.
Definition types.h:15
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21