Save and load Modern careers (M6)
Modern saves (save_profile modern-career-v1) name their world by id and data revision and hold the career only; loading reinstalls the world dimensions. Club names now follow promotion and relegation. The season sim gains MODERN_SAVE_CHECK for a save/load round trip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f55622307
commit
28b59d9890
11 files changed
+265
-14
No files matched your search
@@ -343,6 +343,7 @@ add_subdirectory(src/import)
|
||||
# uses the Classic UI projections until the Modern projections exist (docs/new_engine).
|
||||
# Modern world packages: the world tables and the Classic payload of a Modern data set.
|
||||
add_library(bmh_modern_content STATIC src/modern/content/world.cpp src/modern/content/world_package.cpp
|
||||
src/modern/content/world_save.cpp
|
||||
src/modern/content/world_expand.cpp)
|
||||
target_link_libraries(bmh_modern_content PUBLIC bmh_content bmh_season_modern PRIVATE bmh_miniz)
|
||||
if(MSVC)
|
||||
|
||||
@@ -57,7 +57,7 @@ Für 0.3 gilt außerdem:
|
||||
| M3 | Modern-Weltlader, Namen (Vor-/Nachname, UTF-8), Asset-Schlüssel | Weltlader erledigt: Modern-Datensatz spielt zwei Saisons; Namen/Assets für die UI liegen in `ModernState`, Spielstände folgen mit M6 |
|
||||
| M4 | Trainingslager: 18 Lager, drei Karten, 6-Sterne-Wirkung | Engine erledigt (Katalog, Preis, 6-Sterne-Wirkung, Test); Saisonwirkung wird in M7 gemessen |
|
||||
| M5 | Datenrevision 1.4 des Modern-Datensatzes (privat), Wirtschaftsprüfung | offen |
|
||||
| M6 | Modern-Spielstände (`modern-career-v1`), Projektionen für die UI | offen |
|
||||
| M6 | Modern-Spielstände (`modern-career-v1`), Projektionen für die UI | Spielstände erledigt (Rundreise identisch); Projektionen offen |
|
||||
| M7 | Balance-Läufe und Anpassungen | offen |
|
||||
|
||||
Details und Abnahmekriterien stehen in [Phasen](phasen.md).
|
||||
@@ -19,7 +19,7 @@ Status: *geplant* (noch nicht in der Engine), *umgesetzt* (Engine liest/prüft e
|
||||
| F5 | Namen | Vor- und Nachname Pflicht, UTF-8 | M3 | Engine: gelesen, in `ModernState` |
|
||||
| F6 | Kader | bis 24 Plätze je Verein, Mindestgröße | M3 | Engine: 24 Plätze je Ligaverein; mehr als 24 Spieler werden abgelehnt |
|
||||
| F7 | Finanzen | Finanzangaben für Vereine ohne Classic-Startregel | M5 | geplant |
|
||||
| F8 | Spielstand | `save_profile: modern-career-v1` | M6 | geplant |
|
||||
| F8 | Spielstand | `save_profile: modern-career-v1` | M6 | Engine erledigt: Spielstand nennt seine Welt (ID, Revision), enthält nur die Karriere |
|
||||
| F9 | Schiedsrichter | eigener Schiedsrichter-Pool der Welt, mehr als 49 | M5 | geplant (Engine nutzt bis dahin 49 und lässt Doppeleinsätze zu) |
|
||||
|
||||
## F1 · Manifest
|
||||
@@ -105,6 +105,9 @@ Die bestehende Regel `rule:training-camps` (Typ `training_camps`) bleibt und wir
|
||||
## F8 · Spielstand
|
||||
|
||||
- Modern-Spielstände sind `.obs` mit `save_profile: modern-career-v1`; Aufbau wie Classic-Spielstände (`state/…`, Integritätsdatei), aber mit dem Modern-Zustand und den Dimensionen der Welt.
|
||||
- Anders als ein Classic-Spielstand enthält ein Modern-Spielstand **nicht** die Welt (sie ist samt HD-Bildern mehrere hundert MB groß). Das Manifest nennt sie unter `world` (`id`, `data_revision`, `title`); geladen wird nur mit genau dieser Welt.
|
||||
- Einträge: `state/career.json` (Spielzustand), `state/modern.json` (Schema `modern-state@1.0`: Vereins- und Spieler-IDs, UTF-8-Namen, Nationen je Laufzeit-Index), `state/rng.json`, `state/driver.json`, `state/session.json`, `state/information.json`, `state/integrity.json`. Rund 210 KB.
|
||||
- Ändert sich die Datenrevision, passt ein alter Spielstand nicht mehr; eine Spielstand-Migration ist noch nicht vorgesehen.
|
||||
- **Editor:** öffnet keine Spielstände; keine Änderung.
|
||||
|
||||
## F9 · Schiedsrichter
|
||||
|
||||
@@ -69,6 +69,13 @@ Siehe [Trainingslager](trainingslager.md): Katalog aus den Daten, drei Regionen,
|
||||
|
||||
**Abnahme:** Speichern und Laden mitten in der Saison setzt identisch fort; UI-Projektionen haben Tests mit synthetischen Welten.
|
||||
|
||||
**Umsetzung Spielstände (erledigt):**
|
||||
- `src/modern/content/world_save.*`: `save_world_career` / `load_world_career`. Der Spielstand nennt seine Welt (ID und Datenrevision) und enthält nur die Karriere (Format siehe [Datenformat F8](datenformat.md)).
|
||||
- Laden: `ModernSession` setzt zuerst das Classic-Layout zurück, liest den Spielstand und ruft dann `install_world_dimensions(world)` auf (aus `expand_to_world` herausgelöst), damit Layout, Ligagrößen und Kalender wieder zur Welt passen.
|
||||
- Autosave und `save_game` schreiben über `save_world_career`, sobald eine Welt geladen ist (`current_world()`).
|
||||
- Fehler behoben: Beim Auf- und Abstieg (`ClubsChangePlaces`) wurden die Modern-Namen (`world_club_id/name/short`) nicht mitgetauscht.
|
||||
- Prüfung: `MODERN_SAVE_CHECK=N modern_season_sim …` speichert nach Zug N, lädt in eine zweite Session und vergleicht Zustand, Namen und Layout. Nach Zug 30 und 58 identisch; zwei Saisons mit `SIM_CONTRACTS=1`: 0 von 168 Vereinsnamen falsch.
|
||||
|
||||
## M7 · Balance
|
||||
|
||||
- Konsolen-Langläufe mit dem Modern-Datensatz (mehrere Startkonstellationen, je zehn Saisons): Tore pro Spiel, Punkteverteilung je Liga, Ermüdung und Verletzungen bei 38 statt 22 Spieltagen, Marktwerte und Gehälter, Finanzen des menschlichen Vereins, Wirkung der Trainingslager.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_expand.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/content/world_save.hpp"
|
||||
#include "modern/game/balance_plan.hpp"
|
||||
#include "modern/game/bank_credit.hpp"
|
||||
#include "modern/game/career.hpp"
|
||||
@@ -584,6 +585,8 @@ ModernSession::ModernSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
db_(load_database(data / "M3D.MAN")),
|
||||
texts_(load_textd(data / "TEXTD.BLK")),
|
||||
rand_(watcom_seed) {
|
||||
set_world_layout(classic_world_layout()); // a previous game in this process may have left a world
|
||||
kLeagueTablesPerLeague = false;
|
||||
install_league_sizes(exe_);
|
||||
turn_driver_.alternate_match_event_roll = exe_.u8(::bmh::layout::AlternateEventRoll) != 0;
|
||||
turn_driver_.disable_match_events = exe_.u8(::bmh::layout::MatchEventsDisabled) != 0;
|
||||
@@ -627,6 +630,8 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
|
||||
const std::filesystem::path &save_path, bool importing_legacy)
|
||||
: data_directory_(data), exe_(load_le(data / "BMH.exe")), db_(load_database(data / "M3D.MAN")),
|
||||
texts_(load_textd(data / "TEXTD.BLK")), rand_(watcom_seed) {
|
||||
set_world_layout(classic_world_layout()); // a previous game in this process may have left a world
|
||||
kLeagueTablesPerLeague = false;
|
||||
install_league_sizes(exe_);
|
||||
turn_driver_.alternate_match_event_roll = exe_.u8(::bmh::layout::AlternateEventRoll) != 0;
|
||||
turn_driver_.disable_match_events = exe_.u8(::bmh::layout::MatchEventsDisabled) != 0;
|
||||
@@ -639,10 +644,23 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
|
||||
if (const auto resource = content::find(data); resource && !importing_legacy) {
|
||||
if (content::key(save_path.extension()) != ".obs")
|
||||
throw FormatError("0.2 loads native OBS saves; use Add to migrate legacy games");
|
||||
native = content::load_career(save_path, *resource->content);
|
||||
g_ = std::move(native->state);
|
||||
rand_ = native->random;
|
||||
game_ = native->game;
|
||||
if (const World* world = current_world()) {
|
||||
// A Modern career: the save names its world; the dimensions come from the world.
|
||||
auto saved = load_world_career(save_path, *world);
|
||||
install_world_dimensions(*world);
|
||||
g_ = std::move(saved.state);
|
||||
rand_ = saved.random;
|
||||
game_ = saved.game;
|
||||
native.emplace();
|
||||
native->driver = std::move(saved.driver);
|
||||
native->session = std::move(saved.session);
|
||||
native->header = std::move(saved.header);
|
||||
} else {
|
||||
native = content::load_career(save_path, *resource->content);
|
||||
g_ = std::move(native->state);
|
||||
rand_ = native->random;
|
||||
game_ = native->game;
|
||||
}
|
||||
} else {
|
||||
const Savegame file = load_savegame(save_path);
|
||||
original_english_save = file.version == "V2.20";
|
||||
@@ -7791,8 +7809,12 @@ void ModernSession::flush_native_autosave() {
|
||||
const auto resource = content::find(data_directory_);
|
||||
if (!resource)
|
||||
throw FormatError("Native content unavailable");
|
||||
content::save_career(*autosave_directory_ / "AUTOSAVE.obs", *resource->content, g_, rand_, game_,
|
||||
turn_driver_, true, native_session_context());
|
||||
if (const World* world = current_world())
|
||||
save_world_career(*autosave_directory_ / "AUTOSAVE.obs", *world, g_, rand_, game_, turn_driver_, true,
|
||||
native_session_context());
|
||||
else
|
||||
content::save_career(*autosave_directory_ / "AUTOSAVE.obs", *resource->content, g_, rand_, game_,
|
||||
turn_driver_, true, native_session_context());
|
||||
} catch (const std::exception &e) {
|
||||
autosave_error_ = e.what();
|
||||
}
|
||||
@@ -7825,8 +7847,11 @@ bool ModernSession::save_game(const std::filesystem::path& path, int manager_slo
|
||||
if (ec || (exists && !overwrite)) { error = exists ? "overwrite_confirmation_required" : "save_target_unavailable"; return false; }
|
||||
try {
|
||||
if (const auto resource = content::find(data_directory_)) {
|
||||
content::save_career(path, *resource->content, g_, rand_, game_, turn_driver_, overwrite,
|
||||
native_session_context());
|
||||
if (const World* world = current_world())
|
||||
save_world_career(path, *world, g_, rand_, game_, turn_driver_, overwrite, native_session_context());
|
||||
else
|
||||
content::save_career(path, *resource->content, g_, rand_, game_, turn_driver_, overwrite,
|
||||
native_session_context());
|
||||
return true;
|
||||
}
|
||||
WatcomRandom staged_rand = rand_;
|
||||
|
||||
@@ -168,6 +168,22 @@ std::string legacy_encoding(const std::string& utf8) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void install_world_dimensions(const World& world) {
|
||||
int league_clubs = 0, german_clubs = 0;
|
||||
uint8_t sizes[kLeagueCount] = {};
|
||||
for (const WorldLeague& l : world.leagues) {
|
||||
sizes[l.index] = uint8_t(l.members.size());
|
||||
league_clubs += int(l.members.size());
|
||||
if (l.index < 5) german_clubs += int(l.members.size());
|
||||
}
|
||||
WorldLayout layout = modern_layout(league_clubs, german_clubs);
|
||||
// The league sizes are checked against the layout and need the per-league fixture tables.
|
||||
kLeagueTablesPerLeague = true;
|
||||
set_world_layout(layout);
|
||||
set_league_sizes(sizes);
|
||||
kNewcomerFirst = world_layout().first_amateur();
|
||||
}
|
||||
|
||||
ExpandReport expand_to_world(ModernState& g, const World& world) {
|
||||
const WorldLayout old = world_layout();
|
||||
if (old.league_teams != 138 || old.total_teams() != 419) fail("the world expands a Classic start state only");
|
||||
@@ -355,10 +371,7 @@ ExpandReport expand_to_world(ModernState& g, const World& world) {
|
||||
g.squad_slots = std::move(slots);
|
||||
|
||||
stage("squads");
|
||||
set_world_layout(layout);
|
||||
kLeagueTablesPerLeague = true;
|
||||
set_league_sizes(sizes);
|
||||
kNewcomerFirst = layout.first_amateur();
|
||||
install_world_dimensions(world);
|
||||
|
||||
stage("layout and league sizes");
|
||||
// --- league dates of the international group (calendar bit 4) -------------------------
|
||||
|
||||
@@ -28,6 +28,11 @@ struct ExpandReport {
|
||||
// league sizes and calendar. Throws FormatError when the world does not fit.
|
||||
ExpandReport expand_to_world(ModernState& g, const World& world);
|
||||
|
||||
// Installs the dimensions of the world for a running Modern game: layout, league sizes, the
|
||||
// per-league fixture tables and the first newcomer club. A new career gets them from
|
||||
// expand_to_world, a loaded one from the session.
|
||||
void install_world_dimensions(const World& world);
|
||||
|
||||
// Installs the world's training camp catalogue, or the built-in one when the world has none
|
||||
// (docs/new_engine/trainingslager.md). Classic data keeps the eight original resorts.
|
||||
void install_training_camps(ModernState& g, const World& world);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/content/world_save.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <utility>
|
||||
|
||||
#include "content/digest.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "content/save.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "import/detail.hpp"
|
||||
#include "modern/game/save.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace obw::detail;
|
||||
|
||||
J generator(uint32_t seed, uint64_t calls) {
|
||||
return O{{"seed", int64_t(seed)}, {"calls", std::to_string(calls)}};
|
||||
}
|
||||
uint64_t draw_count(const J& value) {
|
||||
const auto s = str(get(value, "calls"));
|
||||
if (s.empty() || s.size() > 20 || !std::all_of(s.begin(), s.end(), [](unsigned char c) { return c >= '0' && c <= '9'; }))
|
||||
fail("invalid random draw counter");
|
||||
return std::stoull(s);
|
||||
}
|
||||
uint32_t seed_of(const J& value) {
|
||||
const auto n = num(get(value, "seed"));
|
||||
if (n < 0 || n > int64_t(UINT32_MAX)) fail("invalid random seed");
|
||||
return uint32_t(n);
|
||||
}
|
||||
J strings(const std::vector<std::string>& values) {
|
||||
A out;
|
||||
for (const auto& v : values) out.push_back(v);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::string> strings(const J& value) {
|
||||
std::vector<std::string> out;
|
||||
for (const J& v : arr(value)) out.push_back(str(v));
|
||||
return out;
|
||||
}
|
||||
std::string world_identity(const World& world) { return world.id + "@" + world.data_revision; }
|
||||
|
||||
} // namespace
|
||||
|
||||
void save_world_career(const std::filesystem::path& path, const World& world, const ModernState& state,
|
||||
const WatcomRandom& random, const GameRandom& game, const TurnDriver& driver, bool overwrite,
|
||||
const cli::Json& session) {
|
||||
if (driver.stage != TurnDriver::Stage::Empty && driver.stage != TurnDriver::Stage::MatchdayDesks &&
|
||||
driver.stage != TurnDriver::Stage::SeasonEndDesk)
|
||||
fail("save unavailable outside a manager desk");
|
||||
obw::Documents docs;
|
||||
put(docs, "manifest.json",
|
||||
O{{"format", "openbmh-world"}, {"format_version", "1.1"}, {"kind", "save"},
|
||||
{"save_profile", "modern-career-v1"}, {"requires", A{J("runtime:modern-v1")}},
|
||||
{"world", O{{"id", world.id}, {"data_revision", world.data_revision}, {"title", world.title}}}});
|
||||
put(docs, "state/career.json", encode_native_state(state));
|
||||
put(docs, "state/modern.json",
|
||||
O{{"schema", "modern-state@1.0"},
|
||||
{"club_ids", strings(state.world_club_id)},
|
||||
{"club_names", strings(state.world_club_name)},
|
||||
{"club_short_names", strings(state.world_club_short)},
|
||||
{"player_ids", strings(state.world_player_id)},
|
||||
{"player_first", strings(state.player_first)},
|
||||
{"player_last", strings(state.player_last)},
|
||||
{"player_nations", strings(state.player_nation)}});
|
||||
put(docs, "state/rng.json",
|
||||
O{{"schema", "classic-rng@1.0"},
|
||||
{"watcom", generator(random.seed(), random.calls())},
|
||||
{"game", generator(uint32_t(game.seed()), game.calls())}});
|
||||
put(docs, "state/session.json", session);
|
||||
put(docs, "state/driver.json", content::driver_checkpoint(driver));
|
||||
put(docs, "state/information.json", encode_native_bytes(modern::save_header(state)));
|
||||
O checks;
|
||||
for (const auto& [name, value] : docs)
|
||||
if (name.starts_with("state/")) checks[name] = content::sha256(value);
|
||||
put(docs, "state/integrity.json", O{{"schema", "save-integrity@1.0"}, {"entries", std::move(checks)}});
|
||||
content::write_archive(docs, path, overwrite);
|
||||
}
|
||||
|
||||
SavedWorldCareer load_world_career(const std::filesystem::path& path, const World& world) {
|
||||
const auto docs = content::read_archive(path);
|
||||
const auto manifest = parse(docs, "manifest.json");
|
||||
if (str(get(manifest, "kind")) != "save" || str(get(manifest, "save_profile")) != "modern-career-v1")
|
||||
fail("not a Modern career save");
|
||||
const auto& saved_world = get(manifest, "world");
|
||||
if (str(get(saved_world, "id")) != world.id || str(get(saved_world, "data_revision")) != world.data_revision)
|
||||
fail("the save belongs to another world: " + str(get(saved_world, "id")) + "@" +
|
||||
str(get(saved_world, "data_revision")) + ", loaded " + world_identity(world));
|
||||
const auto integrity = parse(docs, "state/integrity.json");
|
||||
if (str(get(integrity, "schema")) != "save-integrity@1.0") fail("unsupported save integrity");
|
||||
O checks;
|
||||
for (const auto& [name, value] : docs)
|
||||
if (name.starts_with("state/") && name != "state/integrity.json") checks[name] = content::sha256(value);
|
||||
if (cli::dump_json(get(integrity, "entries")) != cli::dump_json(checks)) fail("damaged Modern save");
|
||||
|
||||
SavedWorldCareer out;
|
||||
out.state = ModernState(decode_native_state(parse(docs, "state/career.json")));
|
||||
const auto modern = parse(docs, "state/modern.json");
|
||||
if (str(get(modern, "schema")) != "modern-state@1.0") fail("unsupported Modern state");
|
||||
out.state.world_club_id = strings(get(modern, "club_ids"));
|
||||
out.state.world_club_name = strings(get(modern, "club_names"));
|
||||
out.state.world_club_short = strings(get(modern, "club_short_names"));
|
||||
out.state.world_player_id = strings(get(modern, "player_ids"));
|
||||
out.state.player_first = strings(get(modern, "player_first"));
|
||||
out.state.player_last = strings(get(modern, "player_last"));
|
||||
out.state.player_nation = strings(get(modern, "player_nations"));
|
||||
if (out.state.world_player_id.size() != out.state.players.size() ||
|
||||
out.state.world_club_id.size() != out.state.club_ids.size())
|
||||
fail("Modern names do not match the saved state");
|
||||
const auto generators = parse(docs, "state/rng.json");
|
||||
if (str(get(generators, "schema")) != "classic-rng@1.0") fail("unsupported RNG checkpoint");
|
||||
out.random.restore(seed_of(get(generators, "watcom")), draw_count(get(generators, "watcom")));
|
||||
out.game.restore(std::bit_cast<int32_t>(seed_of(get(generators, "game"))), draw_count(get(generators, "game")));
|
||||
out.session = parse(docs, "state/session.json");
|
||||
out.driver = parse(docs, "state/driver.json");
|
||||
out.header = decode_native_bytes(parse(docs, "state/information.json"), 172);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// Saves of Modern careers (docs/new_engine, M6; data format F8: save_profile modern-career-v1).
|
||||
//
|
||||
// A Classic save embeds its sealed world. A Modern world is large (artwork included), so a
|
||||
// Modern save names its world (id, data revision) and holds the career only: the game state,
|
||||
// the Modern additions (names and identities by runtime index), both random generators, the
|
||||
// turn driver and the session context. Loading needs the same world.
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "cli/json.hpp"
|
||||
#include "game/random.hpp"
|
||||
#include "game/turn_driver.hpp"
|
||||
#include "modern/content/world.hpp"
|
||||
#include "modern/game/modern_state.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct SavedWorldCareer {
|
||||
ModernState state;
|
||||
WatcomRandom random{0};
|
||||
GameRandom game{0};
|
||||
cli::Json driver, session;
|
||||
Bytes header;
|
||||
};
|
||||
|
||||
void save_world_career(const std::filesystem::path& path, const World& world, const ModernState& state,
|
||||
const WatcomRandom& random, const GameRandom& game, const TurnDriver& driver, bool overwrite,
|
||||
const cli::Json& session = {});
|
||||
|
||||
// Throws FormatError when the save is damaged, not a Modern save or belongs to another world.
|
||||
SavedWorldCareer load_world_career(const std::filesystem::path& path, const World& world);
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -788,6 +788,9 @@ void change_places(ModernState& g, int a, int b) {
|
||||
}
|
||||
if (!g.club_table.empty() && a < first_foreign_cup() && b < first_foreign_cup()) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
|
||||
std::swap(g.club_ids.at(size_t(a)), g.club_ids.at(size_t(b)));
|
||||
// Modern world names and identities move with the club (empty with Classic data).
|
||||
for (auto* names : {&g.world_club_id, &g.world_club_name, &g.world_club_short})
|
||||
if (size_t(std::max(a, b)) < names->size()) std::swap((*names)[size_t(a)], (*names)[size_t(b)]);
|
||||
swap_bytes(g.club_heap_bc, size_t(a) * 2, size_t(b) * 2, 2);
|
||||
std::swap(g.team_morale.at(size_t(a)), g.team_morale.at(size_t(b)));
|
||||
swap_mem8(::bmh::layout::ClubShortNameOffsets);
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include "game/trace.hpp"
|
||||
#include <filesystem>
|
||||
#include "cli/json.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "modern/game/desk_actions.hpp"
|
||||
#include "game/lineup.hpp"
|
||||
#include "modern/game/matchday.hpp"
|
||||
@@ -356,6 +360,15 @@ int main(int argc, char** argv) {
|
||||
if (r.kind == TurnDeskKind::SeasonEndDesk) {
|
||||
print_first_league_results(g, "season end");
|
||||
if (modern::current_world()) { // rounds played per league against its matchdays
|
||||
// The Modern names must move with the clubs (promotion swaps club places): the
|
||||
// pairs of engine name and world name recorded at the start stay together.
|
||||
static std::map<std::string, std::string> pairs;
|
||||
if (pairs.empty())
|
||||
for (int t = 0; t < modern::league_clubs(); ++t) pairs[g.club_name(t)] = g.world_club_name.at(size_t(t));
|
||||
int mismatched = 0;
|
||||
for (int t = 0; t < modern::league_clubs(); ++t)
|
||||
if (pairs.count(g.club_name(t)) && pairs[g.club_name(t)] != g.world_club_name.at(size_t(t))) ++mismatched;
|
||||
std::printf("season end names: %d of %d league clubs mismatched\n", mismatched, modern::league_clubs());
|
||||
std::printf("season end rounds:");
|
||||
for (int l = 0; l < kLeagueCount; ++l)
|
||||
std::printf(" %d:%d/%d", l, int(g.league_rounds.at(size_t(l))), league_matchdays(l));
|
||||
@@ -363,6 +376,28 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
++seasons;
|
||||
} // (the next kickoff runs the season change)
|
||||
// MODERN_SAVE_CHECK=<turn>: save at that desk, load the save into a second session and
|
||||
// compare the complete state (native state, Modern names, generators, dimensions).
|
||||
if (const char* at = std::getenv("MODERN_SAVE_CHECK"); at && played == std::atoi(at)) {
|
||||
const auto file = std::filesystem::temp_directory_path() / "modern_save_check.obs";
|
||||
std::string save_error;
|
||||
if (!session.save_game(file, int(g.memory.u8(::bmh::layout::ActiveManager)), true, save_error)) {
|
||||
std::printf("save check: save failed (%s)\n", save_error.c_str());
|
||||
} else {
|
||||
const auto before = cli::dump_json(encode_native_state(g));
|
||||
const WorldLayout layout = world_layout();
|
||||
modern::app::ModernSession loaded(argv[1], argc > 4 ? uint32_t(std::stoul(argv[4])) : 1u, file, false);
|
||||
const auto& h = loaded.state();
|
||||
const bool same_state = cli::dump_json(encode_native_state(h)) == before;
|
||||
const bool same_names = h.world_club_name == g.world_club_name && h.player_first == g.player_first &&
|
||||
h.player_last == g.player_last && h.world_player_id == g.world_player_id;
|
||||
const bool same_layout = world_layout().league_teams == layout.league_teams &&
|
||||
world_layout().total_slots == layout.total_slots;
|
||||
std::printf("save check at turn %d: state %s, names %s, layout %s, %ju bytes\n", played,
|
||||
same_state ? "same" : "DIFFERS", same_names ? "same" : "DIFFER",
|
||||
same_layout ? "same" : "DIFFERS", uintmax_t(std::filesystem::file_size(file)));
|
||||
}
|
||||
}
|
||||
}
|
||||
print_first_league_results(g, "run end");
|
||||
if (std::getenv("SIM_ADVERTISING")) std::printf("%d advertising contracts accepted (SIM_ADVERTISING=1)\n", ad_contracts);
|
||||
|
||||
Reference in new issue
Block a user