Files
Dreierpack-Manager/src/modern/content/world_package.cpp
T
ClaudeandClaude Opus 5.5 6f55622307 Load Modern worlds and add Modern training camps (M3, M4)
M3 - Modern world loader:
- modern/content/world: typed view of the world tables (leagues, clubs,
  players, nations, league dates, training camp catalogue).
- modern/content/world_package: opens a Modern world (runtime:modern-v1, or
  editor:world-v1 until data revision 1.4), reads only the engine entries and
  decodes the Classic payload (import: load_classic_payload).
- modern/content/world_expand: turns the Classic start into the world: club
  ids in the order of the world's leagues, per-club tables remapped (added
  clubs copy an original club of their league), added players from their
  attributes, 24 squad slots per league club, pools kept, layout, league
  sizes and league dates installed; UTF-8 names and OBW ids in ModernState.
- Fixes found by playing the Modern data set: referee pool exhausted on days
  with German and larger international leagues (Modern deviation), card
  table per league club grown, slot-to-team lookup via WorldLayout, form
  history stride from the layout, remaining slot literals.
- Classic UI projections used by the session read the layout instead of
  executable constants (Classic values unchanged).
- modern_season_sim opens .obw worlds; MODERN_DEBUG / MODERN_WATCH tracing.

M4 - training camps:
- Catalogue in ModernState (built-in 18 fictional camps on three maps, or the
  world's extended catalogue); price, booking and effect use it.
- Six-star grades: step index capped, limit +1 from pitch 5 and +1 with pitch
  and fitness 6, catering 6 one more point of condition, lodging 6 one week
  less injury. Classic data behaves as before. modern_camp_tests.

Verified: 190 tests pass; Classic replay regression identical to the M0
baseline; season_sim and modern_season_sim identical with Classic data; the
Modern data set plays full seasons (leagues 34/38/34 rounds).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 22:43:25 +02:00

82 lines
3.6 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
#include "modern/content/world_package.hpp"
#include <algorithm>
#include "import/classic.hpp"
#include "import/detail.hpp"
namespace bmh::modern {
namespace {
std::shared_ptr<const World>& current() {
static std::shared_ptr<const World> world;
return world;
}
// The entries the engine needs. High-resolution artwork (crests, portraits, trophies) stays in
// the archive: interfaces read it from there by asset key, the engine never does.
bool engine_entry(const std::string& name) {
for (const char* prefix : {"world/", "x-classic/", "x-legacy/", "locale/", "assets/classic/"})
if (name.rfind(prefix, 0) == 0) return true;
return name == "manifest.json" || name == "assets/index.json";
}
obw::Documents read_engine_entries(const std::filesystem::path& file) {
using obw::detail::fail;
namespace fs = std::filesystem;
if (fs::is_symlink(fs::symlink_status(file)) || !fs::is_regular_file(file)) fail("invalid world archive");
mz_zip_archive zip{};
if (!mz_zip_reader_init_file(&zip, file.string().c_str(), 0)) fail("invalid ZIP archive");
struct End {
mz_zip_archive* zip;
~End() { mz_zip_reader_end(zip); }
} end{&zip};
obw::Documents out;
uint64_t total = 0;
const auto count = mz_zip_reader_get_num_files(&zip);
if (count > 65536) fail("too many archive entries");
for (mz_uint i = 0; i < count; ++i) {
mz_zip_archive_file_stat stat{};
if (!mz_zip_reader_file_stat(&zip, i, &stat)) fail("cannot read entry metadata");
if (stat.m_is_directory || !engine_entry(stat.m_filename)) continue;
const std::string name = stat.m_filename;
if (!obw::detail::safe_path(name) || stat.m_uncomp_size > 64ull * 1024 * 1024 ||
(total += stat.m_uncomp_size) > 256ull * 1024 * 1024)
fail("unsafe or oversized archive entry");
std::string value(size_t(stat.m_uncomp_size), '\0');
if (!mz_zip_reader_extract_to_mem(&zip, i, value.data(), value.size(), 0)) fail("damaged ZIP entry");
if (!out.emplace(name, std::move(value)).second) fail("duplicate archive entry");
}
return out;
}
} // namespace
WorldPackage open_world_package(const std::filesystem::path& file) {
using obw::detail::fail;
auto docs = read_engine_entries(file);
World world = read_world(docs);
const auto needs = [&](const char* r) {
return std::find(world.requires_.begin(), world.requires_.end(), r) != world.requires_.end();
};
// Data revision 1.4 marks playable worlds with runtime:modern-v1; earlier editor worlds
// (editor:world-v1) are accepted for development (docs/new_engine/datenformat.md F1).
if (!needs("runtime:modern-v1") && !needs("editor:world-v1"))
fail("not a Modern world: requires neither runtime:modern-v1 nor editor:world-v1");
if (needs("runtime:classic-v1")) fail("a Classic package runs in Classic, not in the Modern engine");
auto classic = std::make_shared<content::Classic>(obw::load_classic_payload(docs));
classic->content_id = world.id + (world.data_revision.empty() ? "" : "@" + world.data_revision);
classic->start_year = world.start_year;
classic->executable.set_display_start_year(world.start_year);
classic->documents = std::move(docs);
WorldPackage out;
out.classic = std::move(classic);
out.world = std::make_shared<const World>(std::move(world));
return out;
}
const World* current_world() { return current().get(); }
void set_current_world(std::shared_ptr<const World> world) { current() = std::move(world); }
} // namespace bmh::modern