Modern UI contract: press journal for business events

Business events cannot be derived from the almanac later, so a saved
journal notes them once: squad changes of the human clubs at a kickoff
(signed, free, sold, contract ended; clubs compared by identity across
the season's new draw positions), toto settlements, season change,
contract renewals and resigning. The news read merges it with the
almanac events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 18:22:50 +01:00
1 parent 9c436c753e
commit 651d262546
9 files changed
+318 -4

No files matched your search

+1 -1
View File
@@ -346,7 +346,7 @@ add_library(bmh_modern_content STATIC src/modern/content/world.cpp src/modern/co
src/modern/content/world_save.cpp
src/modern/content/world_expand.cpp
src/modern/content/statistics.cpp
src/modern/content/projections.cpp src/modern/content/ui_contract.cpp)
src/modern/content/projections.cpp src/modern/content/ui_contract.cpp src/modern/content/press_journal.cpp)
target_link_libraries(bmh_modern_content PUBLIC bmh_content bmh_season_modern PRIVATE bmh_miniz)
if(MSVC)
target_compile_options(bmh_modern_content PRIVATE /W4 /utf-8)
+1 -1
View File
@@ -35,7 +35,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `advertising` | 14 Banden (`ad:board/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
| `transfer` | die Transferliste (`listing:<n>`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Jahr, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen |
| `news` | Presseereignisse eines Teams (`teamId`, Vorgabe das Team am Schreibtisch), `from`/`until` (ISO, Vorgabe bis heute), `limit` (Vorgabe 50, die neuesten): `events` je `{id, type, date, scope, data, variant: null}` nach [Pressevertrag](../new_ui/integration/PRESS.md), `total`. Quelle ist der Almanach, darum gleich bei jedem Lesen und mit stabiler ID (`press-event:<Typ>:<Vorkommnis>:<Team>`). Typen: `match.result`, `cup.round_result`, `cup.final_result`, `cup.extra_time`, `cup.penalties`, `player.sent_off`, `player.injury`, `run.wins` (3/5/8/10/15), `run.unbeaten` (5/10/15/20/30), `run.winless` (5/8/10/15), `run.losses` (3/5/8/10), `league.position`, `league.champion`, `cup.won`, `indoor.won`. Fakten: `team`, `opponent`, `competition` (mit `kind`, `season`), `matchId`, `score {for, against}` aus Sicht des Teams, `venue`, `trailed`, `minute` (das entscheidende Tor), `outcome`, `round`, `shootout`, `player`, `matches`, `position`, `points`. Noch nicht: Derby, Auf-/Abstieg, Geschäftsereignisse (Transfers, Verträge, Finanzen, Stadion) |
| `news` | Presseereignisse eines Teams (`teamId`, Vorgabe das Team am Schreibtisch), `from`/`until` (ISO, Vorgabe bis heute), `limit` (Vorgabe 50, die neuesten): `events` je `{id, type, date, scope, data, variant: null}` nach [Pressevertrag](../new_ui/integration/PRESS.md), `total`. Quelle ist der Almanach, darum gleich bei jedem Lesen und mit stabiler ID (`press-event:<Typ>:<Vorkommnis>:<Team>`). Typen: `match.result`, `cup.round_result`, `cup.final_result`, `cup.extra_time`, `cup.penalties`, `player.sent_off`, `player.injury`, `run.wins` (3/5/8/10/15), `run.unbeaten` (5/10/15/20/30), `run.winless` (5/8/10/15), `run.losses` (3/5/8/10), `league.position`, `league.champion`, `cup.won`, `indoor.won`. Fakten: `team`, `opponent`, `competition` (mit `kind`, `season`), `matchId`, `score {for, against}` aus Sicht des Teams, `venue`, `trailed`, `minute` (das entscheidende Tor), `outcome`, `round`, `shootout`, `player`, `matches`, `position`, `points`. Dazu Geschäftsereignisse aus dem Pressejournal im Spielstand (`state/modern.json`, `press`): beim Anstoß aus dem Kadervergleich der menschlichen Vereine `transfer.signed` (`fromClub`), `transfer.free`, `transfer.sold` (`toClub`; auch ein freigegebener Spieler, der im selben Anstoß woanders unterschreibt), `contract.ended`; `toto.win`/`toto.loss` (`amount`); `career.season_finished`/`career.season_started`; aus bestätigten Befehlen `contract.extended` (`years`, `wage`) und `career.manager_resigned`. Ablösen kennt der Kadervergleich nicht (`fee: null`). Ohne Welt-IDs (Classic-Daten) heißt ein Verein `team:<Laufzeitnummer>`, die sich zum Saisonstart ändern kann. Noch nicht: Derby, Auf-/Abstieg, Finanzen, Stadion, Werbung |
| `calendar` | der Saisonkalender des Teams am Schreibtisch, `from`/`until` (ISO, Vorgabe der laufende Monat): `days` (Datum, `seasonDay`, `today`, `eventKinds`: `league`, `cup:<n>`, `replay`, `indoor`, `special`, `national`, `friendly`; `fixtureIds`) und `fixtures` (die eigenen Ligaspiele: `fixture:league-<Liga>-<Runde>-<Nr.>`, Wettbewerb, Runde, `originalDate`, `scheduledDate`, Heim/Gast, `status` `scheduled`/`played`/`rescheduled`/`postponed`, `result`). Verlegte und im Winter ausgefallene Spiele stehen am Nachholtag. Pokalspiele nur als `eventKinds`; Fehler `invalid_range` |
| `scheduling` | die verlegbaren eigenen Ligaspiele (`move:<Tag>-<Liga>-<Runde>-<Nr.>`, Datum, Runde, Heim/Gast, mögliche Zieldaten) und die verlegten, die sich zurücknehmen lassen |
| `friendly` | mit `opponentId`, optional `home`: das Angebot für ein Freundschaftsspiel (Heim/Gast, Kosten, Zahler, ob der Gegner einen menschlichen Manager hat) und die freien Daten der Saison; kein Zufall. Am Schreibtisch des Bundestrainers ein Länderspiel (`national: true`, Gegner ein anderes Nationalteam, dazu `ratings` beider Teams): das Original zieht für die Bewertung Zufall; der Read rechnet auf einer Kopie des Generators, die Buchung zieht dieselben Zahlen |
+12
View File
@@ -2,6 +2,7 @@
#include "formats/executable_layout.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/app/modern_session.hpp"
#include "modern/content/press_journal.hpp"
#include "modern/content/world_expand.hpp"
#include "modern/content/world_package.hpp"
#include "modern/content/world_save.hpp"
@@ -9341,6 +9342,7 @@ cli::Json ModernSession::finish_live(const std::string& request_id, uint64_t pre
}
g_.contract_screen = run.previous_contract_hook;
contract_expiry_presenter_installed_ = run.previous_contract_installed;
modern::journal_advance(g_, run.saved_state);
modern::ensure_ui_identities(g_);
ui_last_advance_ = std::make_pair(run.from_date, g_.date);
ui_last_awards_ = std::move(run.awards);
@@ -9845,6 +9847,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
return refuse(r.kind == TurnDeskKind::WaitingAtDesk ? "decision_pending" : "advance_failed",
"Weiter nicht möglich: " + reason);
}
modern::journal_advance(g_, saved_state);
modern::ensure_ui_identities(g_);
revision = previous + 1;
ui_last_advance_ = std::make_pair(saved_state.date, g_.date); // what read_live replays
@@ -10055,6 +10058,12 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
answer = modern::ui_command_result(request_id, previous, revision, {"contracts", "squad", "desktop"},
result.feedback.empty() ? (result.accepted ? "Vertrag verlängert." : "Angebot abgelehnt.")
: result.feedback);
if (result.accepted) {
const int club = g_.manager_teams[size_t(manager)];
modern::note_press(g_, "contract.extended", modern::ui_team_id(g_, club),
cli::Json::Object{{"team", modern::press_team(g_, club)}, {"player", modern::press_player(g_, r.player_id)},
{"years", int(r.term_column + 1)}, {"wage", modern::ui_money(r.monthly_salary)}});
}
if (!result.accepted) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
}
} else if (kind == "advertising.accept" || kind == "budget.commit") {
@@ -10337,6 +10346,9 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
? g_.memory.u8(::bmh::layout::OriginalManagerCount) : int(g_.manager_teams.size());
if (humans > 1)
return refuse("resign_not_supported_yet", "Aufgeben bei mehreren menschlichen Managern folgt noch.");
if (const int club = g_.manager_teams[size_t(manager)]; club >= 0)
modern::note_press(g_, "career.manager_resigned", modern::ui_team_id(g_, club),
cli::Json::Object{{"team", modern::press_team(g_, club)}, {"manager", modern::ui_manager_id(g_, manager)}});
turn_driver_.stage = TurnDriver::Stage::CareerComplete;
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"session", "desktop"},
+179
View File
@@ -0,0 +1,179 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/content/press_journal.hpp"
#include <cstdio>
#include <map>
#include <set>
#include <variant>
#include "formats/executable_layout.hpp"
#include "game/state.hpp"
#include "modern/content/ui_contract.hpp"
#include "modern/game/almanac.hpp"
namespace bmh::modern {
namespace {
using J = cli::Json;
using A = J::Array;
using O = J::Object;
constexpr size_t kJournalLimit = 4000; // the oldest entries go first beyond this
std::string iso(const ModernState& g, uint32_t counter) {
const AlmanacDate d = almanac_date(counter, g.display_start_year);
char out[16];
std::snprintf(out, sizeof out, "%04d-%02d-%02d", d.year, d.month, d.day);
return out;
}
std::string season_text(const ModernState& g) {
const int year = almanac_date(g.season_start, g.display_start_year).year;
char out[16];
std::snprintf(out, sizeof out, "%04d/%02d", year, (year + 1) % 100);
return out;
}
// Clubs are compared by their identity: the runtime team numbers are draw positions that change
// at the season's start. The identity is the world's club id, without a world the club's name
// (the original's club_ids are not unique).
std::string identity_of(const ModernState& g, int team) {
if (team < 0) return {};
if (size_t(team) < g.world_club_id.size() && !g.world_club_id[size_t(team)].empty()) return g.world_club_id[size_t(team)];
return std::string(g.club_name(team));
}
int team_of_identity(const ModernState& g, const std::string& identity) {
for (int t = 0; t < no_team(); ++t)
if (identity_of(g, t) == identity) return t;
return -1;
}
// The club (identity) of every player in the club squads.
std::map<int, std::string> player_clubs(const ModernState& g) {
std::map<int, std::string> out;
for (int t = 0; t < no_team(); ++t) { // clubs only: national squads list their players again
const SquadRange r = squad_range(t);
for (size_t row = 0; row < r.count && r.first + row < g.squad_slots.size(); ++row) {
const int p = g.squad_slots[r.first + row] & 0x0fff;
if (p != 0x0fff) out.emplace(p, identity_of(g, t)); // the first squad that lists him (a loan lists him twice)
}
}
return out;
}
// The clubs of the human managers. While one coaches the national team his club's manager
// record waits in slot 4 (national_coach_take_over), so it is read from there.
int club_of_manager(const ModernState& g, size_t m) {
int team = m < g.manager_teams.size() ? g.manager_teams[m] : -1;
if (team == no_team() && m == 0 && g.memory.has(::bmh::layout::CoachActive) && g.memory.u8(::bmh::layout::CoachActive) != 0) {
const size_t at = 4 * size_t(0xb0c) + 0x290;
if (at + 1 < g.manager_records.size()) team = int16_t(g.manager_records[at] | g.manager_records[at + 1] << 8);
}
return team >= 0 && team < league_clubs() ? team : -1;
}
// The identities of the human managers' clubs.
std::set<std::string> human_clubs(const ModernState& g) {
std::set<std::string> out;
for (size_t m = 0; m < g.manager_teams.size(); ++m)
if (const int team = club_of_manager(g, m); team >= 0) out.insert(identity_of(g, team));
return out;
}
} // namespace
J press_team(const ModernState& g, int team) {
std::string name = size_t(team) < g.world_club_name.size() ? g.world_club_name[size_t(team)] : std::string{};
if (name.empty()) name = almanac_utf8(g.club_name(team));
return O{{"id", ui_team_id(g, team)}, {"name", name}, {"kind", team >= no_team() ? "national" : "club"}};
}
J press_player(const ModernState& g, int player) {
const std::string first = size_t(player) < g.player_first.size() ? g.player_first[size_t(player)] : std::string{};
std::string last = size_t(player) < g.player_last.size() ? g.player_last[size_t(player)] : std::string{};
if (last.empty()) last = almanac_utf8(g.player_name(player));
return O{{"id", ui_player_id(g, player)}, {"name", first.empty() ? last : first + " " + last}};
}
void note_press(ModernState& g, const std::string& type, const std::string& team, J data) {
ModernState::PressEntry e;
e.id = "press-event:" + type + ":j" + std::to_string(++g.press_serial) + ":" + team;
e.type = type, e.team = team, e.date = g.date, e.data = cli::dump_json(data);
g.press.push_back(std::move(e));
if (g.press.size() > kJournalLimit) g.press.erase(g.press.begin(), g.press.begin() + (g.press.size() - kJournalLimit));
}
void journal_advance(ModernState& g, const ModernState& before) {
// the human clubs' squads: arrivals and departures
const std::map<int, std::string> was = player_clubs(before), now = player_clubs(g);
// the clubs of human managers in both states (a squad change is only seen on a club held throughout)
std::set<std::string> clubs, then = human_clubs(before);
for (const std::string& club : human_clubs(g))
if (then.count(club)) clubs.insert(club);
const auto team_entity = [&](const std::string& identity) {
const int t = team_of_identity(g, identity);
return t >= 0 ? press_team(g, t) : J(nullptr);
};
for (const std::string& club : clubs) {
const int team = team_of_identity(g, club);
const J me = press_team(g, team);
const std::string id = ui_team_id(g, team);
for (const auto& [p, identity] : now) {
if (identity != club) continue;
const auto old = was.find(p);
if (old != was.end() && old->second == club) continue;
if (old == was.end())
note_press(g, "transfer.free", id, O{{"team", me}, {"player", press_player(g, p)}, {"until", nullptr}});
else
note_press(g, "transfer.signed", id, O{{"team", me}, {"player", press_player(g, p)}, {"fromClub", team_entity(old->second)}, {"fee", nullptr}});
}
for (const auto& [p, identity] : was) {
if (identity != club) continue;
const auto next = now.find(p);
if (next != now.end() && next->second == club) continue;
if (next == now.end())
note_press(g, "contract.ended", id, O{{"team", me}, {"player", press_player(before, p)}});
else
note_press(g, "transfer.sold", id, O{{"team", me}, {"player", press_player(g, p)}, {"toClub", team_entity(next->second)}, {"fee", nullptr}});
}
}
// a new toto settlement of a club manager
for (size_t m = 0; m < g.pools.size() && m < before.pools.size() && m < g.manager_teams.size(); ++m) {
const auto& a = before.pools[m];
const auto& b = g.pools[m];
const int team = club_of_manager(g, m);
if (b.hits.empty() || (a.hits == b.hits && a.paid == b.paid && a.won == b.won) || team < 0) continue;
const std::string id = ui_team_id(g, team);
if (b.won > 0) note_press(g, "toto.win", id, O{{"team", press_team(g, team)}, {"amount", ui_money(b.won)}});
else if (b.paid > 0) note_press(g, "toto.loss", id, O{{"team", press_team(g, team)}, {"amount", ui_money(b.paid)}});
}
// a new season
if (g.season != before.season)
for (const std::string& club : human_clubs(g)) {
const int team = team_of_identity(g, club);
note_press(g, "career.season_finished", ui_team_id(g, team), O{{"team", press_team(g, team)}, {"season", season_text(before)}});
note_press(g, "career.season_started", ui_team_id(g, team), O{{"team", press_team(g, team)}, {"season", season_text(g)}});
}
}
A journal_events(const ModernState& g, const std::string& team, const std::string& from, const std::string& until) {
A out;
for (const auto& e : g.press) {
if (e.team != team) continue;
const std::string date = iso(g, e.date);
if (date < from || date > until) continue;
J data;
try { data = cli::parse_json(e.data); } catch (const std::exception&) { continue; }
const auto* d = data.object();
J scope = O{{"kind", "club"}, {"id", team}, {"name", nullptr}};
if (d && d->count("team")) {
const auto& t = *d->at("team").object();
scope = O{{"kind", t.at("kind")}, {"id", team}, {"name", t.at("name")}};
}
out.push_back(O{{"id", e.id}, {"type", e.type}, {"date", date}, {"scope", std::move(scope)}, {"data", std::move(data)},
{"variant", nullptr}});
}
return out;
}
} // namespace bmh::modern
+41
View File
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The press journal of a Modern career (docs/new_engine/ui-anbindung.md, read "news"; the
// interface's press contract is docs/new_ui/integration/PRESS.md).
//
// Match events come from the almanac (statistics.hpp, query_news). Business events cannot be
// derived later, so they are noted once when they happen and saved with the career
// (ModernState::press): their id stays the same on every read, a deleted article is never
// produced again. Noting draws no random number and changes nothing else of the game.
//
// Sources:
// - a kickoff (session.advance, also live): the squads of the human clubs before and after
// give transfer.signed (with fromClub, or transfer.free from the pool), transfer.sold
// (toClub) and contract.ended (to the pool); a new toto settlement gives toto.win /
// toto.loss; a season change career.season_finished and career.season_started;
// - confirmed commands: contract.extended (contract.offer), career.manager_resigned.
// Fees are not known from the squads: the transfer events carry no fee (the renderer's
// fee-undisclosed variants).
#include <string>
#include "cli/json.hpp"
#include "modern/game/modern_state.hpp"
namespace bmh::modern {
// Notes an event of `team` (contract team id) on today's date with its facts.
void note_press(ModernState& g, const std::string& type, const std::string& team, cli::Json data);
// The events of the kickoff from `before` to `g` (see above).
void journal_advance(ModernState& g, const ModernState& before);
// The journal's events of `team` with from <= date <= until (ISO), in the form of query_news.
cli::Json::Array journal_events(const ModernState& g, const std::string& team, const std::string& from,
const std::string& until);
// A team / a player as the press facts name them ({id, name, kind} / {id, name}).
cli::Json press_team(const ModernState& g, int team);
cli::Json press_player(const ModernState& g, int player);
} // namespace bmh::modern
+6 -1
View File
@@ -11,6 +11,7 @@
#include "game/state.hpp"
#include "game/table.hpp"
#include "modern/content/projections.hpp"
#include "modern/content/press_journal.hpp"
#include "modern/content/statistics.hpp"
#include "modern/content/world_package.hpp"
#include "modern/game/almanac.hpp"
@@ -382,12 +383,16 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
const int64_t limit = limit_field && limit_field->integer() && *limit_field->integer() > 0 ? *limit_field->integer() : 50;
J news = query_news(g, team_id(g, team), from, until);
A events = std::move(std::get<A>(std::get<O>(news.value).at("events").value));
for (J& e : journal_events(g, team_id(g, team), from, until)) events.push_back(std::move(e));
std::stable_sort(events.begin(), events.end(), [](const J& a, const J& b) {
return *std::get<O>(a.value).at("date").string() < *std::get<O>(b.value).at("date").string();
});
const size_t total = events.size();
if (events.size() > size_t(limit)) events.erase(events.begin(), events.end() - limit);
return snapshot(request_id, std::move(m),
O{{"kind", "news"}, {"teamId", team_id(g, team)}, {"from", from}, {"until", until}, {"total", int64_t(total)},
{"events", std::move(events)},
{"source", "almanac"}, {"note", "Spielereignisse, Serien und Saisonabschlüsse; Geschäftsereignisse folgen"}});
{"sources", A{J("almanac"), J("journal")}}});
}
if (kind == "calendar") {
// the season calendar of the desk's team: days from `from` to `until` (ISO dates, default
+21 -1
View File
@@ -71,6 +71,20 @@ std::vector<ModernState::ExclusiveSponsor> sponsors_json(const J& value) {
return out;
}
// The press journal (content/press_journal.hpp): the entries with their facts as JSON text.
J press_json(const std::vector<ModernState::PressEntry>& press) {
A out;
for (const auto& e : press)
out.push_back(O{{"id", e.id}, {"type", e.type}, {"team", e.team}, {"date", int64_t(e.date)}, {"data", e.data}});
return out;
}
std::vector<ModernState::PressEntry> press_json(const J& value) {
std::vector<ModernState::PressEntry> out;
for (const J& row : arr(value))
out.push_back({str(get(row, "id")), str(get(row, "type")), str(get(row, "team")), uint32_t(num(get(row, "date"))), str(get(row, "data"))});
return out;
}
// The Toto columns 2-6 and the last settlement per manager (docs/new_engine/toto.md).
J pools_json(const std::vector<ModernState::PoolsColumns>& pools) {
A out;
@@ -139,7 +153,9 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
{"career_id", state.career_id},
{"manager_ids", strings(state.manager_ids)},
{"manager_serial", int64_t(state.manager_serial)},
{"traffic_scale", int64_t(state.traffic_scale)}});
{"traffic_scale", int64_t(state.traffic_scale)},
{"press", press_json(state.press)},
{"press_serial", int64_t(state.press_serial)}});
// The almanac: finished seasons unchanged, the running one encoded now.
for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes;
if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current);
@@ -195,6 +211,10 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
out.state.manager_ids = strings(get(modern, "manager_ids"));
out.state.manager_serial = uint32_t(num(get(modern, "manager_serial")));
if (o->count("traffic_scale")) out.state.traffic_scale = uint8_t(num(get(modern, "traffic_scale")));
if (o->count("press")) {
out.state.press = press_json(get(modern, "press"));
out.state.press_serial = uint32_t(num(get(modern, "press_serial")));
}
}
for (const auto& [name, bytes] : docs) {
if (!name.starts_with("history/season-")) continue;
+11
View File
@@ -82,6 +82,17 @@ struct ModernState : GameState {
std::string career_id;
std::vector<std::string> manager_ids;
uint32_t manager_serial = 0;
// The press journal (content/press_journal.hpp): business events the almanac cannot give
// (transfers, contracts, toto, seasons, managers), noted once when they happen and saved, so
// the interface's news keep their ids. `data` is the event's facts as JSON text.
struct PressEntry {
std::string id, type, team; // team: the contract id of the scope team
uint32_t date = 0; // day counter
std::string data;
bool operator==(const PressEntry&) const = default;
};
std::vector<PressEntry> press;
uint32_t press_serial = 0;
// The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the
// four stages of a Modern world. Older Modern saves are converted when loaded.
uint8_t traffic_scale = 0;
+46
View File
@@ -6,10 +6,12 @@
#include <map>
#include <set>
#include <string>
#include <utility>
#include <variant>
#include "cli/json.hpp"
#include "modern/app/modern_session.hpp"
#include "modern/content/press_journal.hpp"
#include "modern/content/ui_contract.hpp"
#include "modern/game/save.hpp"
@@ -717,6 +719,50 @@ int main(int argc, char** argv) {
check(s(at(news, "messageType")) == "snapshot" && events && ids.size() == events->size(), "news with unique ids");
check(cli::dump_json(at(news, "data")) == cli::dump_json(at(again, "data")), "news the same on every read");
check(types["match.result"] > 0 && types["league.position"] > 0 && facts, "match results and the season's end in the news");
{
std::map<std::string, int> journal;
for (const auto& e : std::as_const(session).state().press) ++journal[e.type + "@" + e.team];
std::string all;
for (const auto& [t, n] : journal) all += t + " " + std::to_string(n) + ", ";
std::printf("(journal: %s)\n", all.c_str());
}
// the journal: the new season (noted at the kickoff that changed it)
check(types["career.season_started"] > 0, "business events from the journal");
// the journal's squad comparison on copies: a player of another club joins the human
// club (a signing), then goes back (a sale)
{
const modern::ModernState& start = std::as_const(session).state();
const int club = start.manager_teams.empty() ? -1 : start.manager_teams[0];
if (club >= 0 && club < modern::league_clubs()) {
const int other = club == 0 ? 1 : 0;
const SquadRange mine = squad_range(club), theirs = squad_range(other);
size_t free_row = mine.count, from_row = theirs.count;
for (size_t row = 0; row < mine.count && free_row == mine.count; ++row)
if ((start.squad_slots[mine.first + row] & 0x0fff) == 0x0fff) free_row = row;
for (size_t row = 0; row < theirs.count && from_row == theirs.count; ++row)
if ((start.squad_slots[theirs.first + row] & 0x0fff) != 0x0fff) from_row = row;
if (free_row < mine.count && from_row < theirs.count) {
const int p = start.squad_slots[theirs.first + from_row] & 0x0fff;
modern::ModernState joined = start;
joined.squad_slots[mine.first + free_row] = uint16_t((joined.squad_slots[mine.first + free_row] & 0xf000) | p);
joined.squad_slots[theirs.first + from_row] = uint16_t(joined.squad_slots[theirs.first + from_row] | 0x0fff);
modern::journal_advance(joined, start);
modern::ModernState back = joined;
back.squad_slots[mine.first + free_row] = start.squad_slots[mine.first + free_row];
back.squad_slots[theirs.first + from_row] = start.squad_slots[theirs.first + from_row];
modern::journal_advance(back, joined);
std::vector<std::string> types;
for (size_t k = start.press.size(); k < back.press.size(); ++k) types.push_back(back.press[k].type);
check(types == std::vector<std::string>{"transfer.signed", "transfer.sold"}, "journal: a signing and a sale");
const J ev = J(modern::journal_events(back, modern::ui_team_id(back, club), "0000", "9999"));
check(ev.array() && ev.array()->size() >= 2 &&
s(at(at(at(ev.array()->back(), "data"), "toClub"), "id")) == modern::ui_team_id(back, other),
"journal events readable");
}
} else {
std::printf("(journal test skipped: national desk)\n");
}
}
const J few = session.ui_read(O{{"kind", "news"}, {"limit", 3}}, rev);
check(at(at(few, "data"), "events").array() && at(at(few, "data"), "events").array()->size() == 3, "news limit");
}