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>
This commit is contained in:
1 parent
13bdc56f04
commit
6f55622307
53 files changed
+1392
-87
No files matched your search
@@ -43,6 +43,19 @@ public:
|
||||
if (!has(address)) blocks_[address].assign(size, 0);
|
||||
}
|
||||
|
||||
// Enlarges the block starting at `address` to `size` bytes (new bytes zero) when the space
|
||||
// up to the next block is free; a Modern world uses it for tables per club that have
|
||||
// room behind them. Throws std::out_of_range when the block is missing or too close.
|
||||
void grow_block(uint32_t address, size_t size) {
|
||||
auto it = blocks_.find(address);
|
||||
if (it == blocks_.end()) throw std::out_of_range("static memory: no block at " + hex(address));
|
||||
if (size <= it->second.size()) return;
|
||||
auto next = std::next(it);
|
||||
if (next != blocks_.end() && address + size > next->first)
|
||||
throw std::out_of_range("static memory: block " + hex(address) + " cannot grow into " + hex(next->first));
|
||||
it->second.resize(size, 0);
|
||||
}
|
||||
|
||||
bool has(uint32_t address) const {
|
||||
auto it = blocks_.upper_bound(address);
|
||||
if (it == blocks_.begin()) return false;
|
||||
|
||||
@@ -9,5 +9,7 @@
|
||||
namespace bmh {
|
||||
|
||||
inline std::atomic<const char*> turn_step{"start"};
|
||||
// The club the current step works on (diagnostics only; -1 = none).
|
||||
inline std::atomic<int> turn_team{-1};
|
||||
|
||||
} // namespace bmh
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "game/world_layout.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
@@ -29,6 +30,16 @@ WorldLayout classic_world_layout() {
|
||||
return w;
|
||||
}
|
||||
|
||||
int WorldLayout::team_of_slot(int slot) const {
|
||||
if (slot < 0) return -1;
|
||||
if (uint32_t(slot) < transfer_list) {
|
||||
const auto it = std::upper_bound(squad_start.begin(), squad_start.end(), uint32_t(slot));
|
||||
return int(it - squad_start.begin()) - 1;
|
||||
}
|
||||
if (uint32_t(slot) >= pool_end && uint32_t(slot) < pool_end + no_team_slots) return no_team();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const WorldLayout& world_layout() { return current(); }
|
||||
|
||||
void set_world_layout(WorldLayout layout) {
|
||||
|
||||
@@ -44,6 +44,9 @@ struct WorldLayout {
|
||||
int no_team() const { return first_foreign_cup() + foreign_cup_teams; }
|
||||
int total_teams() const { return no_team() + national_teams; }
|
||||
bool has_squad(int team) const { return (team >= 0 && team < league_teams) || team == no_team(); }
|
||||
// The team whose squad holds `slot`: a league club, no_team() for the no-club squad, -1 for
|
||||
// the pools and the reserve.
|
||||
int team_of_slot(int slot) const;
|
||||
};
|
||||
|
||||
// The original dimensions (V2.24 and the supported German and English editions).
|
||||
|
||||
@@ -281,7 +281,9 @@ void refresh_classic_inventory(Documents& out) {
|
||||
put(out, "x-classic/inventory.json", O{{"schema", "classic-inventory@1.0"}, {"entries", std::move(inventory)}});
|
||||
}
|
||||
|
||||
static ClassicData decode_classic(const Documents& out) {
|
||||
// `extended`: the world may hold players the data set added on top of the installation (a
|
||||
// Modern world); they carry no x-legacy words and are left to the Modern world loader.
|
||||
static ClassicData decode_classic(const Documents& out, bool extended = false) {
|
||||
using namespace detail;
|
||||
const auto startup = parse(out, "x-classic/startup.json");
|
||||
if (str(get(startup, "schema")) != "classic-startup@1.0" || str(get(startup, "layout")) != layout_id)
|
||||
@@ -340,6 +342,7 @@ static ClassicData decode_classic(const Documents& out) {
|
||||
db.players.resize(2574);
|
||||
std::set<size_t> player_ids;
|
||||
for (const auto &player : items(out, "players")) {
|
||||
if (extended && player.object() && !player.object()->contains("x-legacy")) continue;
|
||||
const auto &raw = get(player, "x-legacy");
|
||||
const auto id = num(get(raw, "player_index"));
|
||||
if (id < 0 || id >= 2574 || !player_ids.insert(size_t(id)).second)
|
||||
@@ -529,4 +532,5 @@ ClassicData load_classic(const Documents& out) {
|
||||
validate(out);
|
||||
return decode_classic(out);
|
||||
}
|
||||
ClassicData load_classic_payload(const Documents& out) { return decode_classic(out, true); }
|
||||
} // namespace bmh::obw
|
||||
@@ -15,4 +15,8 @@ void validate_classic(const Documents& out);
|
||||
// For an editor after deliberate changes. CRC32 detects damage, not authenticity.
|
||||
void refresh_classic_inventory(Documents& out);
|
||||
ClassicData load_classic(const Documents& out);
|
||||
// The Classic installation payload (x-classic, x-legacy, assets) of a world that is not a
|
||||
// sealed Classic package, such as a Modern world built on an imported installation. Only the
|
||||
// payload is checked; the world tables are the caller's business (docs/new_engine).
|
||||
ClassicData load_classic_payload(const Documents& out);
|
||||
} // namespace bmh::obw
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "modern/game/modern_state.hpp"
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_expand.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/game/balance_plan.hpp"
|
||||
#include "modern/game/bank_credit.hpp"
|
||||
#include "modern/game/career.hpp"
|
||||
@@ -590,6 +592,10 @@ ModernSession::ModernSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
session_id_ = next_session_id.fetch_add(1, std::memory_order_relaxed);
|
||||
initialize_club_modal_runtime();
|
||||
g_ = modern::startup_state(exe_, db_, read_file(data / "M3.MEN"), read_file(data / "M3.DAT"));
|
||||
// A Modern world: give the Classic start the dimensions and data of the world (M3).
|
||||
if (std::getenv("MODERN_DEBUG")) std::fprintf(stderr, "session: classic start built\n");
|
||||
if (const World* world = current_world()) world_report_ = expand_to_world(g_, *world);
|
||||
if (std::getenv("MODERN_DEBUG")) std::fprintf(stderr, "session: world expanded\n");
|
||||
if (const auto resource = content::find(data)) {
|
||||
g_.display_start_year = resource->content->start_year;
|
||||
content::set_display_start_year(data, g_.display_start_year);
|
||||
@@ -598,6 +604,7 @@ ModernSession::ModernSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
g_.texts = &texts_;
|
||||
g_.currency_suffix = exe_.cstring(::bmh::layout::CurrencySuffixText); // CurrencySuffixText
|
||||
modern::configure_training_camp_data(g_, exe_);
|
||||
if (const World* world = current_world()) install_training_camps(g_, *world);
|
||||
for (size_t i = 0; i < g_.credit_rate_table.size(); ++i) g_.credit_rate_table[i] = exe_.u8(::bmh::layout::BankCredit_BankCreditContext_RuntimeField3 + uint32_t(i));
|
||||
g_.credit_divisor = std::bit_cast<double>(uint64_t(exe_.u32(::bmh::layout::BankCredit_BankCreditContext_RuntimeField)) | uint64_t(exe_.u32(::bmh::layout::BankCredit_BankCreditContext_RuntimeField2)) << 32);
|
||||
g_.credit_rate_table_available = true;
|
||||
@@ -606,10 +613,14 @@ ModernSession::ModernSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
turn_driver_.desk_autosave = [this](const ModernState &state, WatcomRandom &random) {
|
||||
write_desk_autosave(state, random);
|
||||
};
|
||||
const bool trace = std::getenv("MODERN_DEBUG") != nullptr;
|
||||
if (trace) std::fprintf(stderr, "session: startup players\n");
|
||||
modern::startup_players(g_, game_, rand_); // CareerFirstSteps2
|
||||
MinuteReport report;
|
||||
if (trace) std::fprintf(stderr, "session: new career before dialog\n");
|
||||
if (!modern::new_career_before_dialog(g_, game_, rand_, report)) // InitializeCareer up to the dialog
|
||||
throw std::runtime_error("career start: " + report.reason);
|
||||
if (trace) std::fprintf(stderr, "session: career prepared\n");
|
||||
}
|
||||
|
||||
ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_seed,
|
||||
@@ -686,6 +697,7 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
|
||||
g_.texts = &texts_;
|
||||
g_.currency_suffix = exe_.cstring(::bmh::layout::CurrencySuffixText); // CurrencySuffixText
|
||||
modern::configure_training_camp_data(g_, exe_);
|
||||
if (const World* world = current_world()) install_training_camps(g_, *world);
|
||||
for (size_t i = 0; i < g_.credit_rate_table.size(); ++i) g_.credit_rate_table[i] = exe_.u8(::bmh::layout::BankCredit_BankCreditContext_RuntimeField3 + uint32_t(i));
|
||||
g_.credit_divisor = std::bit_cast<double>(uint64_t(exe_.u32(::bmh::layout::BankCredit_BankCreditContext_RuntimeField)) | uint64_t(exe_.u32(::bmh::layout::BankCredit_BankCreditContext_RuntimeField2)) << 32);
|
||||
g_.credit_rate_table_available = true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#pragma once
|
||||
#include "modern/content/world_expand.hpp"
|
||||
// The engine side of the UI's career handoff (src/ui/flow.hpp, ENGINE_BINDING.md).
|
||||
//
|
||||
// The original starts a career at program start (game/career.hpp): the data files are
|
||||
@@ -879,7 +880,11 @@ public:
|
||||
ui::SettingsState settings_projection(int manager, uint64_t revision) const {
|
||||
return ui::settings_from_game(state(), manager, revision, exe_, sound_capabilities_);
|
||||
}
|
||||
// What expanding the Classic start into the Modern world did (empty for Classic data).
|
||||
const ExpandReport& world_report() const { return world_report_; }
|
||||
|
||||
private:
|
||||
ExpandReport world_report_;
|
||||
std::optional<ui::SettingsSoundCapabilities> sound_capabilities_;
|
||||
std::optional<std::filesystem::path> autosave_directory_;
|
||||
std::string autosave_error_;
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/content/world.hpp"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "import/detail.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace obw::detail;
|
||||
|
||||
const J* find(const J& value, std::string_view key) {
|
||||
if (!value.object()) return nullptr;
|
||||
const auto it = value.object()->find(key);
|
||||
return it == value.object()->end() ? nullptr : &it->second;
|
||||
}
|
||||
std::string text(const J* value) {
|
||||
if (!value) return {};
|
||||
if (value->string()) return *value->string();
|
||||
if (const J* d = find(*value, "default"); d && d->string()) return *d->string();
|
||||
return {};
|
||||
}
|
||||
int integer(const J* value, int fallback = 0) {
|
||||
return value && value->integer() ? int(*value->integer()) : fallback;
|
||||
}
|
||||
int age_on(const std::string& born, const std::string& date) {
|
||||
int by = 0, bm = 0, bd = 0, y = 0, m = 0, d = 0;
|
||||
if (std::sscanf(born.c_str(), "%d-%d-%d", &by, &bm, &bd) != 3 || std::sscanf(date.c_str(), "%d-%d-%d", &y, &m, &d) != 3)
|
||||
return -1;
|
||||
return y - by - ((m < bm || (m == bm && d < bd)) ? 1 : 0);
|
||||
}
|
||||
int position_of(const std::string& p) {
|
||||
if (p == "gk") return 0;
|
||||
if (p == "def") return 1;
|
||||
if (p == "mid") return 2;
|
||||
if (p == "fwd") return 3;
|
||||
fail("unknown player position: " + p);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const WorldClub* World::club(const std::string& id) const {
|
||||
const auto it = club_by_id.find(id);
|
||||
return it == club_by_id.end() ? nullptr : &clubs[it->second];
|
||||
}
|
||||
|
||||
World read_world(const obw::Documents& documents) {
|
||||
World w;
|
||||
const J manifest = parse(documents, "manifest.json");
|
||||
w.id = str(get(manifest, "id"));
|
||||
w.title = text(find(manifest, "title"));
|
||||
w.start_date = str(get(manifest, "start_date"));
|
||||
w.start_year = std::stoi(w.start_date.substr(0, 4));
|
||||
for (const J& r : arr(get(manifest, "requires"))) w.requires_.push_back(str(r));
|
||||
for (const char* extension : {"x-diamond-modern", "x-world"})
|
||||
if (const J* x = find(manifest, extension)) w.data_revision = text(find(*x, "data_revision"));
|
||||
|
||||
for (const J& n : items(documents, "nations"))
|
||||
if (const J* legacy = find(n, "x-legacy"); legacy && find(*legacy, "nationality_index"))
|
||||
w.nationality[str(get(n, "id"))] = integer(find(*legacy, "nationality_index"));
|
||||
|
||||
std::map<std::string, std::vector<std::string>> dates;
|
||||
for (const J& c : items(documents, "calendar")) {
|
||||
const J* list = find(c, "dates");
|
||||
if (!list || !list->array()) continue;
|
||||
auto& out = dates[str(get(c, "id"))];
|
||||
for (const J& d : arr(*list)) out.push_back(str(d));
|
||||
}
|
||||
|
||||
w.leagues.resize(9);
|
||||
for (const J& c : items(documents, "competitions")) {
|
||||
if (text(find(c, "type")) != "league") continue;
|
||||
const J* legacy = find(c, "x-legacy");
|
||||
const int index = legacy ? integer(find(*legacy, "league_index"), -1) : -1;
|
||||
if (index < 0 || index >= 9) fail("league without a league index: " + text(find(c, "id")));
|
||||
WorldLeague& l = w.leagues[size_t(index)];
|
||||
if (l.index >= 0) fail("two leagues with index " + std::to_string(index));
|
||||
l.index = index;
|
||||
l.id = str(get(c, "id"));
|
||||
l.name = text(find(c, "name"));
|
||||
for (const J& m : arr(get(c, "members"))) l.members.push_back(str(m));
|
||||
const auto& stages = arr(get(c, "stages"));
|
||||
if (stages.size() != 1) fail("league with more than one stage: " + l.id);
|
||||
l.generator = text(find(stages[0], "generator"));
|
||||
const std::string calendar = text(find(stages[0], "matchdays"));
|
||||
if (const auto it = dates.find(calendar); it != dates.end()) l.dates = it->second;
|
||||
}
|
||||
for (const WorldLeague& l : w.leagues)
|
||||
if (l.index < 0) fail("the world needs the nine Classic leagues");
|
||||
|
||||
for (const J& c : items(documents, "clubs")) {
|
||||
WorldClub club;
|
||||
club.id = str(get(c, "id"));
|
||||
club.name = text(find(c, "name"));
|
||||
club.short_name = text(find(c, "short"));
|
||||
club.nation = text(find(c, "nation"));
|
||||
club.crest = text(find(c, "crest"));
|
||||
club.competition = text(find(c, "competition"));
|
||||
if (const J* legacy = find(c, "x-legacy")) {
|
||||
club.legacy_index = integer(find(*legacy, "team_index"), -1);
|
||||
club.kit_selector = integer(find(*legacy, "kit_selector"), -1);
|
||||
}
|
||||
if (const J* kit = find(c, "kit")) club.kit_selector = integer(find(*kit, "selector"), club.kit_selector);
|
||||
w.club_by_id[club.id] = w.clubs.size();
|
||||
w.clubs.push_back(std::move(club));
|
||||
}
|
||||
|
||||
// Training camps (data format F4): only a catalogue with maps replaces the built-in one; the
|
||||
// eight Classic resorts of an imported installation carry no map.
|
||||
for (const J& r : items(documents, "rules")) {
|
||||
if (text(find(r, "id")) != "rule:training-camps" || !find(r, "maps")) continue;
|
||||
CampCatalogue catalogue;
|
||||
for (const J& m : arr(get(r, "maps"))) {
|
||||
CampMap map;
|
||||
map.id = str(get(m, "id"));
|
||||
map.name = text(find(m, "name"));
|
||||
if (const J* v = find(m, "width"); v && v->integer()) map.width = int(*v->integer());
|
||||
if (const J* v = find(m, "height"); v && v->integer()) map.height = int(*v->integer());
|
||||
catalogue.maps.push_back(std::move(map));
|
||||
}
|
||||
for (const J& c : arr(get(r, "resorts"))) {
|
||||
TrainingCamp camp;
|
||||
camp.id = str(get(c, "id"));
|
||||
camp.map = str(get(c, "map"));
|
||||
if (const J* v = find(c, "x"); v && v->integer()) camp.x = int(*v->integer());
|
||||
if (const J* v = find(c, "y"); v && v->integer()) camp.y = int(*v->integer());
|
||||
camp.name = text(find(c, "name"));
|
||||
camp.place = text(find(c, "place"));
|
||||
camp.country = text(find(c, "country"));
|
||||
camp.base_price = integer(find(c, "base_price"));
|
||||
const auto& quality = arr(get(c, "quality"));
|
||||
if (quality.size() != 4) fail("training camp needs four quality grades: " + camp.id);
|
||||
for (size_t k = 0; k < 4; ++k) {
|
||||
const auto grade = num(quality[k]);
|
||||
if (grade < 0 || grade > 6) fail("training camp grade outside 0-6: " + camp.id);
|
||||
camp.quality[k] = uint8_t(grade);
|
||||
}
|
||||
if (camp.base_price < 0) fail("negative training camp price: " + camp.id);
|
||||
catalogue.camps.push_back(std::move(camp));
|
||||
}
|
||||
w.camps = std::move(catalogue);
|
||||
}
|
||||
|
||||
for (const J& p : items(documents, "players")) {
|
||||
WorldPlayer pl;
|
||||
pl.id = str(get(p, "id"));
|
||||
const J& name = get(p, "name");
|
||||
pl.first = text(find(name, "first"));
|
||||
pl.last = text(find(name, "last"));
|
||||
pl.team = text(find(p, "team"));
|
||||
pl.squad_order = integer(find(p, "squad_order"), -1);
|
||||
const auto& positions = arr(get(p, "positions"));
|
||||
if (positions.empty()) fail("player without position: " + pl.id);
|
||||
pl.position = position_of(str(positions[0]));
|
||||
const auto& nations = arr(get(p, "nationalities"));
|
||||
if (!nations.empty()) pl.nation = str(nations[0]);
|
||||
if (const J* born = find(p, "born")) pl.age = age_on(str(*born), w.start_date);
|
||||
else if (const J* at = find(p, "age_at_start")) pl.age = integer(find(*at, "years"), -1);
|
||||
pl.photo = text(find(p, "photo"));
|
||||
const J& a = get(p, "attributes");
|
||||
pl.technique = integer(find(a, "technique"));
|
||||
pl.condition = integer(find(a, "condition"));
|
||||
pl.form = integer(find(a, "form"));
|
||||
pl.bonus = integer(find(a, "bonus"));
|
||||
pl.teamplay = integer(find(a, "teamplay"));
|
||||
pl.speed = integer(find(a, "speed"));
|
||||
pl.shooting = integer(find(a, "shooting"));
|
||||
pl.passing = integer(find(a, "passing"));
|
||||
pl.tackling = integer(find(a, "tackling"));
|
||||
pl.free_kick = integer(find(a, "free_kick"));
|
||||
pl.corner = integer(find(a, "corner"));
|
||||
if (const J* legacy = find(p, "x-legacy"); legacy && find(*legacy, "player_index")) {
|
||||
pl.legacy = true;
|
||||
pl.legacy_index = integer(find(*legacy, "player_index"), -1);
|
||||
const auto word = [&](const char* key) {
|
||||
const J* v = find(*legacy, key);
|
||||
return v && v->integer() ? uint32_t(*v->integer()) : 0u;
|
||||
};
|
||||
pl.w35c = word("condition_technique_form_word");
|
||||
pl.w368 = word("skill_word");
|
||||
pl.w364 = word("identity_word");
|
||||
}
|
||||
w.players.push_back(std::move(pl));
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,75 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// The world of a Modern data set (docs/new_engine, M3): the parts of the OBW tables the
|
||||
// Modern season core needs, read once when a world is opened. Identities are the stable
|
||||
// OBW ids; runtime team and player indices are assigned by the world loader.
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "import/obw.hpp"
|
||||
#include "modern/game/training_camps.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct WorldLeague {
|
||||
std::string id; // comp:...
|
||||
std::string name;
|
||||
int index = -1; // league 0-8 (x-legacy.league_index)
|
||||
std::vector<std::string> members; // club ids in table order
|
||||
std::string generator; // legacy:<n> or round-robin
|
||||
std::vector<std::string> dates; // explicit league dates, empty = Classic calendar
|
||||
};
|
||||
|
||||
struct WorldClub {
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string short_name;
|
||||
std::string nation;
|
||||
std::string crest;
|
||||
std::string competition; // league id for league clubs
|
||||
int legacy_index = -1; // Classic team id, -1 for clubs added by the data set
|
||||
int kit_selector = -1;
|
||||
};
|
||||
|
||||
struct WorldPlayer {
|
||||
std::string id;
|
||||
std::string first, last;
|
||||
std::string team; // club id, empty = no club
|
||||
int squad_order = -1;
|
||||
int position = 0; // 0 GK, 1 DEF, 2 MID, 3 FWD
|
||||
std::string nation; // first nationality
|
||||
int age = -1; // age on the start date
|
||||
std::string photo;
|
||||
// Attributes of bmh-classic@1.
|
||||
int technique = 0, condition = 0, form = 0, bonus = 0;
|
||||
int teamplay = 0, speed = 0, shooting = 0, passing = 0, tackling = 0, free_kick = 0, corner = 0;
|
||||
// The original database words of an imported player (x-legacy).
|
||||
bool legacy = false;
|
||||
int legacy_index = -1;
|
||||
uint32_t w35c = 0, w368 = 0, w364 = 0;
|
||||
};
|
||||
|
||||
struct World {
|
||||
std::string id, title, data_revision;
|
||||
std::vector<std::string> requires_;
|
||||
int start_year = 2026;
|
||||
std::string start_date;
|
||||
std::vector<WorldLeague> leagues; // by league index 0-8
|
||||
std::vector<WorldClub> clubs;
|
||||
std::vector<WorldPlayer> players;
|
||||
std::map<std::string, int> nationality; // nation id -> Classic nationality code (0 = Germany)
|
||||
std::map<std::string, size_t> club_by_id; // club id -> index in clubs
|
||||
// rule:training-camps with maps and camp details (data format F4); empty = built-in catalogue.
|
||||
std::optional<CampCatalogue> camps;
|
||||
|
||||
const WorldClub* club(const std::string& id) const;
|
||||
};
|
||||
|
||||
// Reads the world tables. Throws FormatError for missing or malformed required fields.
|
||||
World read_world(const obw::Documents& documents);
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,415 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/content/world_expand.hpp"
|
||||
// OpenBMH deviates from the original: Modern worlds have league sizes, clubs and players of their own; players whose nation has no single-byte nationality code carry a substitute foreign code.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/table.hpp"
|
||||
#include "import/detail.hpp"
|
||||
#include "modern/game/world_calendar.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
namespace {
|
||||
|
||||
using obw::detail::fail;
|
||||
|
||||
// MODERN_DEBUG=1 traces the expansion stages on stderr.
|
||||
void stage(const char* name) {
|
||||
static const bool on = std::getenv("MODERN_DEBUG") != nullptr;
|
||||
if (on) std::fprintf(stderr, "expand: %s\n", name);
|
||||
}
|
||||
|
||||
constexpr int kSquadSlots = 24;
|
||||
|
||||
// Decodes one UTF-8 code point; returns U+FFFD for malformed input.
|
||||
char32_t next_code_point(const std::string& s, size_t& i) {
|
||||
const auto byte = [&](size_t k) { return k < s.size() ? uint8_t(s[k]) : uint8_t(0); };
|
||||
const uint8_t b = byte(i);
|
||||
if (b < 0x80) return ++i, b;
|
||||
if ((b >> 5) == 6 && (byte(i + 1) >> 6) == 2) {
|
||||
const char32_t c = char32_t(b & 0x1f) << 6 | (byte(i + 1) & 0x3f);
|
||||
i += 2;
|
||||
return c;
|
||||
}
|
||||
if ((b >> 4) == 14 && (byte(i + 1) >> 6) == 2 && (byte(i + 2) >> 6) == 2) {
|
||||
const char32_t c = char32_t(b & 0x0f) << 12 | char32_t(byte(i + 1) & 0x3f) << 6 | (byte(i + 2) & 0x3f);
|
||||
i += 3;
|
||||
return c;
|
||||
}
|
||||
++i;
|
||||
while (i < s.size() && (byte(i) >> 6) == 2) ++i;
|
||||
return 0xfffd;
|
||||
}
|
||||
|
||||
// Letters of Latin Extended-A and similar that have no single-byte form: their base letter.
|
||||
char base_letter(char32_t c) {
|
||||
static const std::map<char32_t, char> letters = {
|
||||
{0x0106, 'C'}, {0x0107, 'c'}, {0x010c, 'C'}, {0x010d, 'c'}, {0x0110, 'D'}, {0x0111, 'd'},
|
||||
{0x0118, 'E'}, {0x0119, 'e'}, {0x011a, 'E'}, {0x011b, 'e'}, {0x011e, 'G'}, {0x011f, 'g'},
|
||||
{0x0130, 'I'}, {0x0131, 'i'}, {0x0141, 'L'}, {0x0142, 'l'}, {0x0143, 'N'}, {0x0144, 'n'},
|
||||
{0x0147, 'N'}, {0x0148, 'n'}, {0x0150, 'O'}, {0x0151, 'o'}, {0x0158, 'R'}, {0x0159, 'r'},
|
||||
{0x015a, 'S'}, {0x015b, 's'}, {0x015e, 'S'}, {0x015f, 's'}, {0x0160, 'S'}, {0x0161, 's'},
|
||||
{0x0162, 'T'}, {0x0163, 't'}, {0x0164, 'T'}, {0x0165, 't'}, {0x016e, 'U'}, {0x016f, 'u'},
|
||||
{0x0170, 'U'}, {0x0171, 'u'}, {0x0179, 'Z'}, {0x017a, 'z'}, {0x017b, 'Z'}, {0x017c, 'z'},
|
||||
{0x017d, 'Z'}, {0x017e, 'z'}, {0x0219, 's'}, {0x0218, 'S'}, {0x021b, 't'}, {0x021a, 'T'},
|
||||
{0x2019, '\''}, {0x2013, '-'}, {0x2014, '-'}};
|
||||
const auto it = letters.find(c);
|
||||
return it == letters.end() ? '?' : it->second;
|
||||
}
|
||||
|
||||
std::string upper(const std::string& legacy) {
|
||||
std::string out = legacy;
|
||||
for (char& ch : out) {
|
||||
if (ch >= 'a' && ch <= 'z') ch = char(ch - 'a' + 'A');
|
||||
else if (ch == '{') ch = '['; // ä -> Ä
|
||||
else if (ch == '|') ch = '\\'; // ö -> Ö
|
||||
else if (ch == '}') ch = ']'; // ü -> Ü
|
||||
else if (uint8_t(ch) >= 0xe0 && uint8_t(ch) != 0xf7) ch = char(uint8_t(ch) - 0x20); // Latin-1
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Appends a zero-terminated name to a pool and returns its offset (pools use u16 offsets).
|
||||
uint16_t append_name(std::vector<uint8_t>& pool, const std::string& name) {
|
||||
if (pool.size() + name.size() + 1 > 0xffff) fail("name pool full (64 KB)");
|
||||
const auto at = uint16_t(pool.size());
|
||||
pool.insert(pool.end(), name.begin(), name.end());
|
||||
pool.push_back(0);
|
||||
return at;
|
||||
}
|
||||
|
||||
// Copies per-team records of `width` bytes into the new id order; ids without an old record
|
||||
// copy the record of their template id (the new id of an original club of the same league).
|
||||
std::vector<uint8_t> remap_records(const std::vector<uint8_t>& old, size_t width, int old_count, int new_count,
|
||||
const std::vector<int>& to_new, const std::vector<int>& template_of) {
|
||||
std::vector<uint8_t> out(size_t(new_count) * width, 0);
|
||||
std::vector<bool> filled(size_t(new_count), false);
|
||||
for (int t = 0; t < old_count && size_t(t + 1) * width <= old.size(); ++t) {
|
||||
const int n = to_new[size_t(t)];
|
||||
if (n < 0 || n >= new_count) continue;
|
||||
std::copy_n(old.begin() + long(size_t(t) * width), width, out.begin() + long(size_t(n) * width));
|
||||
filled[size_t(n)] = true;
|
||||
}
|
||||
for (int n = 0; n < new_count; ++n)
|
||||
if (!filled[size_t(n)] && template_of[size_t(n)] >= 0 && filled[size_t(template_of[size_t(n)])])
|
||||
std::copy_n(out.begin() + long(size_t(template_of[size_t(n)]) * width), width,
|
||||
out.begin() + long(size_t(n) * width));
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<uint16_t> remap_words(const std::vector<uint16_t>& old, int new_count, const std::vector<int>& to_new,
|
||||
const std::vector<int>& template_of) {
|
||||
std::vector<uint8_t> bytes;
|
||||
for (const uint16_t w : old) bytes.push_back(uint8_t(w)), bytes.push_back(uint8_t(w >> 8));
|
||||
const auto out = remap_records(bytes, 2, int(old.size()), new_count, to_new, template_of);
|
||||
std::vector<uint16_t> words;
|
||||
for (size_t i = 0; i + 1 < out.size(); i += 2) words.push_back(uint16_t(out[i] | out[i + 1] << 8));
|
||||
return words;
|
||||
}
|
||||
|
||||
void remap_memory(StaticMemory& mem, uint32_t address, size_t width, int old_count, int new_count,
|
||||
const std::vector<int>& to_new, const std::vector<int>& template_of, bool grow) {
|
||||
if (!mem.has(address)) return;
|
||||
std::vector<uint8_t> old;
|
||||
for (int i = 0; i < old_count * int(width) && mem.has(address + uint32_t(i)); ++i) old.push_back(mem.u8(address + uint32_t(i)));
|
||||
const auto out = remap_records(old, width, old_count, new_count, to_new, template_of);
|
||||
if (grow) mem.grow_block(address, out.size());
|
||||
for (size_t i = 0; i < out.size() && mem.has(address + uint32_t(i)); ++i) mem.set8(address + uint32_t(i), out[i]);
|
||||
}
|
||||
|
||||
WorldLayout modern_layout(int league_clubs, int german_clubs) {
|
||||
WorldLayout w;
|
||||
w.league_teams = league_clubs;
|
||||
w.german_teams = german_clubs;
|
||||
w.squad_start.clear();
|
||||
w.squad_size.clear();
|
||||
for (int t = 0; t < league_clubs; ++t) {
|
||||
w.squad_start.push_back(uint32_t(t) * kSquadSlots);
|
||||
w.squad_size.push_back(kSquadSlots);
|
||||
}
|
||||
w.transfer_list = uint32_t(league_clubs) * kSquadSlots;
|
||||
w.free_agents = w.transfer_list + 44;
|
||||
w.foreign_offers = w.free_agents + 80;
|
||||
w.pool_end = w.foreign_offers + 20;
|
||||
w.total_slots = w.pool_end + w.no_team_slots + 54;
|
||||
return w;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string legacy_encoding(const std::string& utf8) {
|
||||
std::string out;
|
||||
for (size_t i = 0; i < utf8.size();) {
|
||||
const char32_t c = next_code_point(utf8, i);
|
||||
switch (c) {
|
||||
case U'Ä': out += '['; break;
|
||||
case U'Ö': out += '\\'; break;
|
||||
case U'Ü': out += ']'; break;
|
||||
case U'ä': out += '{'; break;
|
||||
case U'ö': out += '|'; break;
|
||||
case U'ü': out += '}'; break;
|
||||
case U'ß': out += '~'; break;
|
||||
default:
|
||||
if (c < 0x80 && c != '[' && c != '\\' && c != ']' && c != '{' && c != '|' && c != '}' && c != '~')
|
||||
out += char(c);
|
||||
else if (c >= 0xc0 && c <= 0xff)
|
||||
out += char(uint8_t(c)); // Latin-1 letters, as the Classic pools store them
|
||||
else
|
||||
out += base_letter(c);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
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");
|
||||
ExpandReport report;
|
||||
|
||||
// --- team ids: league clubs in the order of the world's leagues ----------------------
|
||||
int league_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());
|
||||
}
|
||||
const int added = league_clubs - old.league_teams;
|
||||
if (added < 0) fail("a Modern world cannot have fewer league clubs than Classic");
|
||||
const int new_total = old.total_teams() + added;
|
||||
std::vector<int> to_new(size_t(old.total_teams()), -1); // Classic id -> new id
|
||||
std::vector<int> template_of(size_t(new_total), -1); // new id -> template new id
|
||||
std::vector<const WorldClub*> club_at(size_t(new_total), nullptr);
|
||||
for (int t = old.league_teams; t < old.total_teams(); ++t) to_new[size_t(t)] = t + added;
|
||||
int id = 0;
|
||||
for (const WorldLeague& l : world.leagues) {
|
||||
int template_id = -1;
|
||||
const int first = id;
|
||||
for (const std::string& member : l.members) {
|
||||
const WorldClub* c = world.club(member);
|
||||
if (!c) fail("unknown league member " + member);
|
||||
if (c->legacy_index >= old.league_teams) fail("club " + member + " is not a Classic league club");
|
||||
if (c->legacy_index >= 0) {
|
||||
if (to_new[size_t(c->legacy_index)] >= 0) fail("Classic club in two leagues: " + member);
|
||||
to_new[size_t(c->legacy_index)] = id;
|
||||
if (template_id < 0) template_id = id;
|
||||
}
|
||||
club_at[size_t(id)] = c;
|
||||
++id;
|
||||
}
|
||||
for (int n = first; n < id; ++n)
|
||||
if (!club_at[size_t(n)] || club_at[size_t(n)]->legacy_index < 0) template_of[size_t(n)] = template_id;
|
||||
if (template_id < 0 && id > first) fail("league without an original club: " + l.id);
|
||||
}
|
||||
for (int t = 0; t < old.league_teams; ++t)
|
||||
if (to_new[size_t(t)] < 0) fail("Classic league club " + std::to_string(t) + " is missing from the world's leagues");
|
||||
for (const WorldClub& c : world.clubs)
|
||||
if (c.legacy_index >= old.league_teams && c.legacy_index < old.total_teams())
|
||||
club_at[size_t(to_new[size_t(c.legacy_index)])] = &c;
|
||||
report.league_clubs = league_clubs;
|
||||
report.added_clubs = added;
|
||||
|
||||
stage("team ids");
|
||||
// --- per-team tables -----------------------------------------------------------------
|
||||
const int records = old.first_foreign_cup() + added; // clubs with records (league + amateurs)
|
||||
g.team_morale = remap_records(g.team_morale, 1, old.total_teams(), new_total, to_new, template_of);
|
||||
g.team_flags = remap_words(g.team_flags, new_total, to_new, template_of);
|
||||
g.club_heap_78 = remap_records(g.club_heap_78, 2, old.total_teams(), new_total, to_new, template_of);
|
||||
g.club_heap_bc = remap_records(g.club_heap_bc, 2, old.first_foreign_cup(), records, to_new, template_of);
|
||||
g.club_heap_b8 = remap_records(g.club_heap_b8, 1, old.first_foreign_cup(), records, to_new, template_of);
|
||||
if (!g.club_table.empty())
|
||||
g.club_table = remap_records(g.club_table, 0x4a, old.first_foreign_cup(), records, to_new, template_of);
|
||||
{
|
||||
std::vector<int> no_template(template_of.size(), -1);
|
||||
g.position_history = remap_records(g.position_history, 0x1a, old.league_teams, league_clubs, to_new, no_template);
|
||||
std::vector<uint8_t> results;
|
||||
const size_t managers = g.manager_results.size() / 0x690;
|
||||
for (size_t m = 0; m < managers; ++m) {
|
||||
const std::vector<uint8_t> one(g.manager_results.begin() + long(m * 0x690),
|
||||
g.manager_results.begin() + long((m + 1) * 0x690));
|
||||
const auto moved = remap_records(one, 10, old.first_foreign_cup(), records, to_new, no_template);
|
||||
results.insert(results.end(), moved.begin(), moved.end());
|
||||
}
|
||||
g.manager_results = std::move(results);
|
||||
}
|
||||
// Club names: Classic clubs keep their pool entries; added clubs get one.
|
||||
std::vector<uint16_t> club_ids(size_t(new_total), 0);
|
||||
for (int t = 0; t < old.total_teams() && size_t(t) < g.club_ids.size(); ++t)
|
||||
club_ids[size_t(to_new[size_t(t)])] = g.club_ids[size_t(t)];
|
||||
for (int n = 0; n < new_total; ++n)
|
||||
if (template_of[size_t(n)] >= 0 && club_at[size_t(n)])
|
||||
club_ids[size_t(n)] = append_name(g.club_names, upper(legacy_encoding(club_at[size_t(n)]->name)));
|
||||
g.club_ids = std::move(club_ids);
|
||||
remap_memory(g.memory, ::bmh::layout::ClubShortNameOffsets, 1, old.first_foreign_cup(), records, to_new, template_of, true);
|
||||
for (int n = 0; n < records; ++n) // added clubs: the short name is the start of the name
|
||||
if (template_of[size_t(n)] >= 0 && club_at[size_t(n)])
|
||||
g.memory.set8(::bmh::layout::ClubShortNameOffsets + uint32_t(n),
|
||||
uint8_t(std::min<size_t>(legacy_encoding(club_at[size_t(n)]->name).size(), 16) - 1));
|
||||
{ // Card counters per league club (fair-play table): 2 bytes each, room behind the block.
|
||||
std::vector<int> no_template(template_of.size(), -1);
|
||||
remap_memory(g.memory, ::bmh::layout::DeskRecords_Teams_RuntimeField, 2, old.league_teams, league_clubs, to_new,
|
||||
no_template, true);
|
||||
}
|
||||
// Kit selectors are only moved on promotion; the block has no room for more clubs.
|
||||
remap_memory(g.memory, ::bmh::layout::ClubKitSelectors, 1, old.total_teams(), old.total_teams(), to_new, template_of, false);
|
||||
|
||||
stage("per-team tables");
|
||||
// --- players -------------------------------------------------------------------------
|
||||
std::map<std::string, int> player_index;
|
||||
std::vector<const WorldPlayer*> player_at;
|
||||
for (const WorldPlayer& p : world.players)
|
||||
if (p.legacy) {
|
||||
if (p.legacy_index < 0 || size_t(p.legacy_index) >= g.players.size()) fail("invalid original player " + p.id);
|
||||
player_index[p.id] = p.legacy_index;
|
||||
}
|
||||
int next_player = int(g.players.size());
|
||||
for (const WorldPlayer& p : world.players)
|
||||
if (!p.legacy) player_index[p.id] = next_player++;
|
||||
if (next_player > 0xFFE) fail("too many players for 12-bit player ids");
|
||||
player_at.assign(size_t(next_player), nullptr);
|
||||
for (const WorldPlayer& p : world.players) player_at[size_t(player_index[p.id])] = &p;
|
||||
const size_t original_players = g.players.size();
|
||||
g.players.resize(size_t(next_player));
|
||||
g.player_name_offsets.resize(size_t(next_player), 0);
|
||||
g.player_cards.resize(size_t(next_player), 0);
|
||||
if (g.player_bonus.size() < size_t(next_player) + 0x36) g.player_bonus.resize(size_t(next_player) + 0x36, 0);
|
||||
for (size_t i = original_players; i < size_t(next_player); ++i) {
|
||||
const WorldPlayer& p = *player_at[i];
|
||||
const auto clamp7 = [](int v) { return uint32_t(std::clamp(v, 0, 127)); };
|
||||
const auto skill = [](int v) { return uint32_t(std::clamp(v, 0, 3)); };
|
||||
int nationality = 31;
|
||||
if (const auto it = world.nationality.find(p.nation); it != world.nationality.end() && it->second < 32)
|
||||
nationality = it->second;
|
||||
else
|
||||
++report.fallback_nationalities;
|
||||
const int age = std::clamp(p.age < 0 ? 24 : p.age, 16, 47);
|
||||
Player& pl = g.players[i];
|
||||
pl.w35c = clamp7(p.form) | clamp7(p.technique) << 7 | clamp7(p.condition) << 14;
|
||||
pl.w368 = skill(p.teamplay) | skill(p.speed) << 2 | skill(p.shooting) << 4 | skill(p.passing) << 6 |
|
||||
skill(p.tackling) << 8 | skill(p.free_kick) << 10 | skill(p.corner) << 12 | uint32_t(nationality) << 27;
|
||||
pl.w364 = uint32_t(p.position & 3) | uint32_t(age - 16) << 21;
|
||||
g.player_bonus[i] = uint8_t(std::clamp(p.bonus, 0, 50));
|
||||
g.player_name_offsets[i] = append_name(g.player_names, upper(legacy_encoding(p.last)));
|
||||
++report.added_players;
|
||||
}
|
||||
|
||||
stage("players");
|
||||
// --- layout, squads, league sizes ----------------------------------------------------
|
||||
WorldLayout layout = modern_layout(league_clubs, old.german_teams);
|
||||
std::vector<uint16_t> slots(layout.total_slots, kEmptySlot);
|
||||
// The pools behind the squads keep their Classic contents and order: transfer list, free
|
||||
// agents, foreign offers, the no-club squad and the 54 reserve players the career start
|
||||
// generates (the world lists those as players without a club).
|
||||
std::vector<bool> pooled(size_t(next_player), false);
|
||||
for (uint32_t s = old.transfer_list; s < old.total_slots && s < g.squad_slots.size(); ++s) {
|
||||
const uint16_t v = g.squad_slots[s];
|
||||
slots[layout.transfer_list + (s - old.transfer_list)] = v;
|
||||
if ((v & 0x0FFF) != 0x0FFF && size_t(v & 0x0FFF) < pooled.size()) pooled[size_t(v & 0x0FFF)] = true;
|
||||
}
|
||||
std::map<std::string, std::vector<std::pair<int, int>>> squads; // club id -> (order, player)
|
||||
std::vector<int> free_agents; // players the world adds without a club
|
||||
for (const WorldPlayer& p : world.players) {
|
||||
const int pid = player_index[p.id];
|
||||
if (p.team.empty()) {
|
||||
if (!pooled[size_t(pid)]) free_agents.push_back(pid);
|
||||
continue;
|
||||
}
|
||||
squads[p.team].push_back({p.squad_order < 0 ? 999 : p.squad_order, pid});
|
||||
}
|
||||
for (int t = 0; t < league_clubs; ++t) {
|
||||
auto& squad = squads[club_at[size_t(t)]->id];
|
||||
std::stable_sort(squad.begin(), squad.end());
|
||||
if (squad.size() > size_t(kSquadSlots)) fail("squad larger than 24 players: " + club_at[size_t(t)]->id);
|
||||
for (size_t k = 0; k < squad.size(); ++k) slots[layout.squad_start[size_t(t)] + k] = uint16_t(squad[k].second);
|
||||
}
|
||||
for (const auto& [club, squad] : squads) {
|
||||
const WorldClub* c = world.club(club);
|
||||
if (!c || std::find(club_at.begin(), club_at.begin() + league_clubs, c) == club_at.begin() + league_clubs)
|
||||
for (const auto& entry : squad) free_agents.push_back(entry.second); // players of squadless clubs
|
||||
}
|
||||
size_t free_slot = layout.free_agents;
|
||||
for (const int pid : free_agents) {
|
||||
while (free_slot < layout.foreign_offers && slots[free_slot] != kEmptySlot) ++free_slot;
|
||||
if (free_slot == layout.foreign_offers) fail("no free-agent slot left for the world's players without a club");
|
||||
slots[free_slot++] = uint16_t(pid);
|
||||
}
|
||||
report.free_agents = int(free_agents.size());
|
||||
{ // Every player holds at most one slot (squad, pool or reserve).
|
||||
std::vector<int> seen(size_t(next_player), -1);
|
||||
for (size_t s = 0; s < slots.size(); ++s) {
|
||||
const int pid = slots[s] & 0x0FFF;
|
||||
if (pid == 0x0FFF) continue;
|
||||
if (size_t(pid) >= seen.size()) fail("slot " + std::to_string(s) + " names an unknown player");
|
||||
if (seen[size_t(pid)] >= 0)
|
||||
fail("player " + std::to_string(pid) + " in slots " + std::to_string(seen[size_t(pid)]) + " and " +
|
||||
std::to_string(s));
|
||||
seen[size_t(pid)] = int(s);
|
||||
}
|
||||
}
|
||||
g.squad_slots = std::move(slots);
|
||||
|
||||
stage("squads");
|
||||
set_world_layout(layout);
|
||||
kLeagueTablesPerLeague = true;
|
||||
set_league_sizes(sizes);
|
||||
kNewcomerFirst = layout.first_amateur();
|
||||
|
||||
stage("layout and league sizes");
|
||||
// --- league dates of the international group (calendar bit 4) -------------------------
|
||||
const WorldLeague* dated = nullptr;
|
||||
for (const WorldLeague& l : world.leagues)
|
||||
if (l.index >= 5 && (!dated || l.dates.size() > dated->dates.size())) dated = &l;
|
||||
if (dated && !dated->dates.empty()) {
|
||||
std::vector<int> days;
|
||||
for (const std::string& d : dated->dates) {
|
||||
const int day = season_day_of(d, world.start_year);
|
||||
if (day < 0) fail("invalid league date " + d);
|
||||
days.push_back(day);
|
||||
}
|
||||
if (int(days.size()) < league_matchdays(dated->index)) fail("fewer league dates than matchdays: " + dated->id);
|
||||
for (std::string& moved : install_league_dates(g, 4, days).moved) report.notes.push_back(std::move(moved));
|
||||
}
|
||||
|
||||
stage("league dates");
|
||||
// --- Modern names and identities -----------------------------------------------------
|
||||
g.world_club_id.assign(size_t(new_total), {});
|
||||
g.world_club_name.assign(size_t(new_total), {});
|
||||
g.world_club_short.assign(size_t(new_total), {});
|
||||
for (int n = 0; n < new_total; ++n)
|
||||
if (const WorldClub* c = club_at[size_t(n)]) {
|
||||
g.world_club_id[size_t(n)] = c->id;
|
||||
g.world_club_name[size_t(n)] = c->name;
|
||||
g.world_club_short[size_t(n)] = c->short_name.empty() ? c->name : c->short_name;
|
||||
}
|
||||
g.world_player_id.assign(size_t(next_player), {});
|
||||
g.player_first.assign(size_t(next_player), {});
|
||||
g.player_last.assign(size_t(next_player), {});
|
||||
g.player_nation.assign(size_t(next_player), {});
|
||||
for (size_t i = 0; i < player_at.size(); ++i)
|
||||
if (const WorldPlayer* p = player_at[i]) {
|
||||
g.world_player_id[i] = p->id;
|
||||
g.player_first[i] = p->first;
|
||||
g.player_last[i] = p->last;
|
||||
g.player_nation[i] = p->nation;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
void install_training_camps(ModernState& g, const World& world) {
|
||||
const CampCatalogue& catalogue = world.camps ? *world.camps : default_camp_catalogue();
|
||||
if (catalogue.camps.empty()) obw::detail::fail("the training camp catalogue is empty");
|
||||
g.camp_maps = catalogue.maps;
|
||||
g.training_camps = catalogue.camps;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// Turns the Classic start of a Modern world into the Modern world (docs/new_engine, M3).
|
||||
//
|
||||
// The Classic start (startup_state from the world's Classic payload) has the original
|
||||
// dimensions: 138 league clubs, 2574 players. expand_to_world gives it the dimensions of the
|
||||
// world: league clubs in the order of the world's league members (international leagues of
|
||||
// 20/20/18/20 move the ids of every club behind them), the added clubs and players, squads of
|
||||
// 24 slots for every league club built from the world's squads, the world layout, the league
|
||||
// sizes and the league dates. Clubs the data set added take the per-club starting values of
|
||||
// an original club of the same league.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "modern/content/world.hpp"
|
||||
#include "modern/game/modern_state.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct ExpandReport {
|
||||
int league_clubs = 0, added_clubs = 0, added_players = 0, free_agents = 0;
|
||||
int fallback_nationalities = 0; // players whose nation has no Classic code
|
||||
std::vector<std::string> notes; // moved league dates and similar remarks
|
||||
};
|
||||
|
||||
// Requires the Classic layout (a fresh startup state) and installs the world's layout,
|
||||
// league sizes and calendar. Throws FormatError when the world does not fit.
|
||||
ExpandReport expand_to_world(ModernState& g, 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);
|
||||
|
||||
// The UTF-8 text of a name in the single-byte encoding of the engine texts (ISO 646-DE;
|
||||
// letters outside it lose their accents, other characters become '?').
|
||||
std::string legacy_encoding(const std::string& utf8);
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,81 @@
|
||||
// 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
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// Opening a Modern world package (docs/new_engine, M3, data format F1).
|
||||
//
|
||||
// A Modern world is an OBW world built on an imported Classic installation: its Classic
|
||||
// payload (x-classic, x-legacy, assets) provides the original executable data, database,
|
||||
// texts and artwork; its world tables (clubs, leagues, players, ...) describe the Modern
|
||||
// world. The Modern engine opens only such worlds; sealed Classic packages are refused.
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include "formats/content.hpp"
|
||||
#include "modern/content/world.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct WorldPackage {
|
||||
std::shared_ptr<const content::Classic> classic; // mounted for the original data files
|
||||
std::shared_ptr<const World> world;
|
||||
};
|
||||
|
||||
// Reads and checks a Modern world package. Throws FormatError when the package is not a
|
||||
// Modern world (no runtime:modern-v1 / editor:world-v1 requirement, a sealed Classic
|
||||
// package, or no Classic payload).
|
||||
WorldPackage open_world_package(const std::filesystem::path& file);
|
||||
|
||||
// The world of the running Modern game (one game per process), set by the session.
|
||||
const World* current_world();
|
||||
void set_current_world(std::shared_ptr<const World> world);
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -196,7 +196,7 @@ bool new_career_players(ModernState& g, GameRandom& game, WatcomRandom& rand, Mi
|
||||
p.w364 |= uint32_t(rand.range(4, 0x10)) << 21;
|
||||
p.w368 = (p.w368 & 0xffffc000u) + uint32_t(rand.range(0, 0x3fff));
|
||||
}
|
||||
for (int slot = 3096; slot < 3096 + 0x36; slot++)
|
||||
for (int slot = int(pool_end_slot() + 24); slot < int(pool_end_slot() + 24) + 0x36; slot++)
|
||||
if (!modern::release_player(g, slot, game, rand, report)) return false;
|
||||
return !report.unsupported;
|
||||
}
|
||||
@@ -412,7 +412,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
|
||||
choice.portrait < 0 || choice.portrait > 11 || choice.name.size() > 24 ||
|
||||
g.tactics.size() < size_t(m + 1) * 0x840 ||
|
||||
g.manager_ratings.size() < size_t(m + 1) * 0x3c ||
|
||||
g.manager_results.size() < g.manager_teams.size() * 0x690 ||
|
||||
g.manager_results.size() < g.manager_teams.size() * manager_history_stride() ||
|
||||
g.squad_slots.size() < total_squad_slots() || g.club_ids.size() < size_t(first_foreign_cup()) ||
|
||||
g.team_morale.size() < size_t(first_foreign_cup()) || g.team_flags.size() < size_t(first_foreign_cup()) ||
|
||||
g.club_heap_bc.size() < size_t(first_foreign_cup()) * 2 || g.club_heap_78.size() < size_t(first_foreign_cup()) * 2 ||
|
||||
@@ -530,7 +530,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
|
||||
modern::new_board_entry(g, m, int(i), int(slot), rand);
|
||||
g.tactics.at(size_t(m) * 0x840 + i * 0x58 + 0xd) = 100;
|
||||
}
|
||||
for (size_t i = 0; i < 0x690; i++) g.manager_results.at(size_t(m) * 0x690 + i) = 0xff;
|
||||
for (size_t i = 0; i < manager_history_stride(); i++) g.manager_results.at(size_t(m) * manager_history_stride() + i) = 0xff;
|
||||
const uint8_t level = mem.u8(::bmh::layout::Difficulty);
|
||||
const uint32_t money = level == 0 ? 50000000u : 4000000u - level * 200000u;
|
||||
put32(r, rec + 0x314, money);
|
||||
|
||||
@@ -32,10 +32,7 @@ int source_manager(const ModernState& g, int club) {
|
||||
|
||||
int club_of_slot(int slot) {
|
||||
if (slot < 0) return -1;
|
||||
if (slot < 90 * 24) return slot / 24;
|
||||
if (slot < 90 * 24 + 48 * 16) return (slot - 90 * 8) / 16;
|
||||
if (slot >= pool_end_slot() && slot < pool_end_slot() + 24) return no_team();
|
||||
return -1;
|
||||
return world_layout().team_of_slot(slot); // squads, no-club squad, else -1
|
||||
}
|
||||
|
||||
std::array<uint8_t, kBoardRow> board_copy(const ModernState& g, int manager, int row) {
|
||||
|
||||
@@ -507,13 +507,23 @@ void configure_training_camp_data(ModernState& g, const LeImage& exe) {
|
||||
}
|
||||
g.training_camp_base_prices = prices;
|
||||
g.training_camp_quality = quality;
|
||||
// The Modern catalogue starts as the eight original resorts; a Modern world replaces it.
|
||||
g.camp_maps.clear();
|
||||
g.training_camps.clear();
|
||||
for (size_t resort = 0; resort < prices.size(); ++resort) {
|
||||
TrainingCamp camp;
|
||||
camp.id = "resort:" + std::to_string(resort);
|
||||
camp.base_price = prices[resort];
|
||||
camp.quality = quality[resort];
|
||||
g.training_camps.push_back(std::move(camp));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t training_camp_price(const ModernState& g, int manager, int resort) {
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || resort < 0 || resort >= kTrainingCampResorts)
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || resort < 0 || size_t(resort) >= g.training_camps.size())
|
||||
throw FormatError("training camp: invalid manager or resort");
|
||||
const int team = int8_t(g.manager_records.at(size_t(manager) * kRecordSize + kTeam));
|
||||
return g.training_camp_base_prices[size_t(resort)] + team_average(g, team, 0xff).players * 5000;
|
||||
return g.training_camps[size_t(resort)].base_price + team_average(g, team, 0xff).players * 5000;
|
||||
}
|
||||
|
||||
bool set_training_camp_focus(ModernState& g, int manager, const std::array<uint8_t, 4>& focus) {
|
||||
@@ -1450,7 +1460,7 @@ TrainingCampBookingBlock training_camp_booking_block(const ModernState& g, int m
|
||||
}
|
||||
|
||||
bool book_training_camp(ModernState& g, int manager, int resort, WatcomRandom& rand) {
|
||||
if (resort < 0 || resort >= kTrainingCampResorts ||
|
||||
if (resort < 0 || size_t(resort) >= g.training_camps.size() ||
|
||||
modern::training_camp_booking_block(g, manager) != TrainingCampBookingBlock::none) return false;
|
||||
const int32_t cost = modern::training_camp_price(g, manager, resort);
|
||||
if (!modern::book_money(g, manager, cost, false)) return false;
|
||||
@@ -1465,7 +1475,7 @@ bool book_training_camp(ModernState& g, int manager, int resort, WatcomRandom& r
|
||||
void training_camp_effect(ModernState& g, int manager, int resort, WatcomRandom& rand) {
|
||||
const size_t rec = size_t(manager) * kRecordSize;
|
||||
const int team = int8_t(g.manager_records.at(rec + kTeam));
|
||||
const auto& grade = g.training_camp_quality[size_t(resort)];
|
||||
const auto& grade = g.training_camps.at(size_t(resort)).quality;
|
||||
|
||||
// Morale (bits 0-5) + 12 * grade * 20 %, clamped to 0..0x2f (ClampSignedWord with a word
|
||||
// sum of the sign extended byte); the flag bits 6-7 are kept.
|
||||
@@ -1496,15 +1506,26 @@ void training_camp_effect(ModernState& g, int manager, int resort, WatcomRandom&
|
||||
for (int i = 0; i < 5; i++) {
|
||||
const int lo = delta[i] < 0 ? 0 : 8;
|
||||
if (rand.range(0, 100) <= chance) {
|
||||
// values below 83..87 (88 in the better resorts 6 and 7) can still improve
|
||||
const int limit = rand.range(0x53, 0x57) + (resort >= 6 ? 1 : 0);
|
||||
// OpenBMH deviates from the original: Modern training camps have grades up to six stars with a capped step, a higher limit and recovery extras.
|
||||
// values below 83..87 can still improve. Classic raises the limit by 1 in its two best
|
||||
// resorts (6 and 7, the only ones with pitch grade 5); Modern ties it to the grades:
|
||||
// pitch 5 or more +1, pitch and fitness both 6 one more (docs/new_engine/trainingslager.md).
|
||||
const int limit = rand.range(0x53, 0x57) + (grade[0] >= 5 ? 1 : 0) + (grade[0] >= 6 && grade[1] >= 6 ? 1 : 0);
|
||||
if (v[i] < limit) {
|
||||
const int k = rand.range(lo, delta[i] + 8);
|
||||
// Grade 6 can draw beyond the step table; its top step (+5) is the maximum.
|
||||
const int k = std::min(rand.range(lo, delta[i] + 8), 23);
|
||||
v[i] = int8_t(v[i] + int8_t(kStep[k] * kDirection[i]));
|
||||
}
|
||||
}
|
||||
v[i] = std::clamp<int8_t>(v[i], 0, 0x63); // Int8T
|
||||
}
|
||||
// Six-star extras (Modern): catering 6 adds up to one point of condition, lodging 6 shortens
|
||||
// a running injury (w364 bits 16-20, weeks) by one week, never below one.
|
||||
if (grade[2] >= 6) v[0] = std::min<int8_t>(int8_t(v[0] + 1), 0x63);
|
||||
if (grade[3] >= 6) {
|
||||
const uint32_t weeks = p.w364 >> 16 & 0x1f;
|
||||
if (weeks > 1) p.w364 = (p.w364 & ~(0x1fu << 16)) | (weeks - 1) << 16;
|
||||
}
|
||||
p.w35c = (p.w35c & 0xffe00000u) | uint32_t(v[0]) << 14 | uint32_t(v[1]) << 7 | uint32_t(v[2]);
|
||||
board[0xf] = uint8_t(v[3]);
|
||||
board[0xe] = uint8_t((board[0xe] & 0xc0) | std::min<uint8_t>(uint8_t(v[4]), 0x3f));
|
||||
|
||||
@@ -670,7 +670,7 @@ void manager_match_record(ModernState& g, const MatchGroup& grp, int m, int home
|
||||
modern::rate_manager(g, int(k), rating, 0);
|
||||
}
|
||||
if (opp < first_foreign_cup()) {
|
||||
size_t at = k * 0x690 + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
size_t at = k * manager_history_stride() + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
std::copy_backward(g.manager_results.begin() + at, g.manager_results.begin() + at + 4,
|
||||
g.manager_results.begin() + at + 5);
|
||||
g.manager_results.at(at) = uint8_t(own + (against << 4));
|
||||
|
||||
@@ -177,10 +177,16 @@ void match_weather(MatchGroup& grp, int m, const MatchdayContext& ctx, GameRando
|
||||
if (int16_t(home) < no_team() && uint16_t(away) < no_team() && !(grp.desc.at(1) & 0x80)) {
|
||||
// Range(1): a referee not yet chosen today
|
||||
std::vector<uint8_t>& refs = *ctx.referees;
|
||||
// OpenBMH deviates from the original: in Modern worlds a referee may take a second match on a day with more matches than referees.
|
||||
// Modern: a day can have more matches than the 49 referees (larger international
|
||||
// leagues on the dates of the German leagues). Once every referee has a match, one
|
||||
// may referee a second match that day (DIFFERENCES.md); Classic draws until a free one.
|
||||
bool free_referee = false;
|
||||
for (int k = 1; k <= 0x31 && !free_referee; ++k) free_referee = !(refs.at(size_t(k)) & 0x80);
|
||||
int r;
|
||||
do {
|
||||
r = game.range(1, 0x31);
|
||||
} while (refs.at(size_t(r)) & 0x80);
|
||||
} while (free_referee && (refs.at(size_t(r)) & 0x80));
|
||||
refs.at(size_t(r)) |= 0x80;
|
||||
grp.desc.at(0x10 + size_t(m)) = uint8_t(r);
|
||||
}
|
||||
@@ -601,8 +607,11 @@ std::vector<MatchGroup> setup_matchday(ModernState& g, uint32_t competitions, co
|
||||
for (int i = 0; i < grp.matches() * 2; i++) {
|
||||
if (i < grp.matches()) modern::match_weather(grp, i, ctx, game, rand);
|
||||
const int team = grp.fixtures.at(size_t(i));
|
||||
turn_team = team;
|
||||
turn_step = "setup: prepare team";
|
||||
modern::prepare_team(g, team, cls, i);
|
||||
try {
|
||||
turn_step = "setup: line-up";
|
||||
auto_lineup(g, team, 100);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
report.fail(e.what());
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
// Modern-only data (world layout, UTF-8 names, ...) is added here, never to GameState.
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "game/state.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "modern/game/training_camps.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
@@ -31,7 +34,21 @@ inline size_t total_squad_slots() { return world_layout().total_slots; }
|
||||
// The callbacks the shared match core uses for season functions (SeasonHooks).
|
||||
const SeasonHooks& season_hooks();
|
||||
|
||||
// The form history per manager (manager_results) holds 10 bytes per club with a record
|
||||
// (Classic: 168 clubs, stride 0x690).
|
||||
inline size_t manager_history_stride() { return size_t(first_foreign_cup()) * 10; }
|
||||
|
||||
struct ModernState : GameState {
|
||||
// --- Modern world (docs/new_engine, M3); empty when the game runs on Classic data -------
|
||||
// UTF-8 names and OBW identities by runtime index. The single-byte name pools of
|
||||
// GameState stay for the engine texts; interfaces show these.
|
||||
std::vector<std::string> world_club_id, world_club_name, world_club_short; // per team
|
||||
std::vector<std::string> world_player_id, player_first, player_last; // per player
|
||||
std::vector<std::string> player_nation; // nation id per player
|
||||
// Training camps (M4): Classic data gives the eight original resorts, a Modern world its catalogue.
|
||||
std::vector<CampMap> camp_maps;
|
||||
std::vector<TrainingCamp> training_camps;
|
||||
|
||||
ModernState() { season_hooks = &modern::season_hooks(); }
|
||||
// Takes over a state built by shared code (save loading, career setup).
|
||||
ModernState(GameState&& g) : GameState(std::move(g)) { season_hooks = &modern::season_hooks(); }
|
||||
|
||||
@@ -830,7 +830,7 @@ void change_places(ModernState& g, int a, int b) {
|
||||
const uint16_t w = v == uint16_t(a) ? uint16_t(b) : v == uint16_t(b) ? uint16_t(a) : v;
|
||||
g.manager_records.at(at) = uint8_t(w), g.manager_records.at(at + 1) = uint8_t(w >> 8);
|
||||
}
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * 0x690, size_t(b) * 10 + m * 0x690, 10);
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * manager_history_stride(), size_t(b) * 10 + m * manager_history_stride(), 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/game/training_camps.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
const CampCatalogue& default_camp_catalogue() {
|
||||
// Names, places, prices and grades are fictional interface data
|
||||
// (docs/new_ui/desktop/trainingcamp); the ids 0-17 are the interface's ids.
|
||||
static const CampCatalogue catalogue = [] {
|
||||
CampCatalogue c;
|
||||
c.maps = {{"map:de", "Deutschland", {}, {}}, {"map:eu", "Europa", {}, {}}, {"map:me", "Naher Osten", {}, {}}};
|
||||
const auto camp = [&](int id, const char* map, const char* name, const char* place, const char* country,
|
||||
std::array<uint8_t, 4> quality, int32_t price) {
|
||||
TrainingCamp t;
|
||||
t.id = "resort:" + std::to_string(id);
|
||||
t.map = map;
|
||||
t.name = name;
|
||||
t.place = place;
|
||||
t.country = country;
|
||||
t.quality = quality;
|
||||
t.base_price = price;
|
||||
c.camps.push_back(t);
|
||||
};
|
||||
camp(0, "map:eu", "Kraftmühle Łódź", "Łódź", "nation:pl", {4, 4, 4, 4}, 410000);
|
||||
camp(1, "map:eu", "Vitalpark Vinadio", "Vinadio", "nation:it", {4, 4, 4, 3}, 450000);
|
||||
camp(2, "map:eu", "Kraftwerk Stettin", "Stettin", "nation:pl", {4, 4, 3, 4}, 420000);
|
||||
camp(3, "map:de", "Wellness Resort Ulm", "Ulm", "nation:de", {2, 3, 2, 2}, 145000);
|
||||
camp(4, "map:eu", "Sportzentrum Groningen", "Groningen", "nation:nl", {4, 4, 4, 4}, 485000);
|
||||
camp(5, "map:de", "Ball-Arena Potsdam", "Potsdam", "nation:de", {3, 2, 3, 2}, 175000);
|
||||
camp(6, "map:eu", "Camp Royal Saint-Denis", "Saint-Denis", "nation:fr", {5, 4, 5, 4}, 650000);
|
||||
camp(7, "map:eu", "Elite-Fußballcamp Ancona", "Ancona", "nation:it", {5, 5, 5, 5}, 840000);
|
||||
camp(8, "map:de", "Sportpark Sauerland", "Schmallenberg", "nation:de", {1, 1, 1, 1}, 25000);
|
||||
camp(9, "map:de", "Trainingshof Harz", "Goslar", "nation:de", {2, 2, 2, 2}, 55000);
|
||||
camp(10, "map:de", "Alpencamp Allgäu", "Kempten", "nation:de", {3, 3, 2, 3}, 195000);
|
||||
camp(11, "map:de", "Leistungszentrum Schwarzwald", "Freiburg", "nation:de", {5, 5, 4, 5}, 490000);
|
||||
camp(12, "map:eu", "Algarve Performance Camp", "Faro", "nation:pt", {5, 4, 5, 5}, 920000);
|
||||
camp(13, "map:eu", "Costa del Sol Sport Resort", "Málaga", "nation:es", {5, 5, 5, 4}, 895000);
|
||||
camp(14, "map:me", "Doha Elite Football Resort", "Doha", "nation:qa", {6, 6, 6, 6}, 2800000);
|
||||
camp(15, "map:me", "Abu Dhabi Royal Training", "Abu Dhabi", "nation:ae", {6, 6, 6, 6}, 3200000);
|
||||
camp(16, "map:me", "Dubai Platinum Sports Camp", "Dubai", "nation:ae", {6, 6, 6, 6}, 3600000);
|
||||
camp(17, "map:eu", "Riviera Trainingscamp Belek", "Belek", "nation:tr", {5, 5, 5, 4}, 790000);
|
||||
return c;
|
||||
}();
|
||||
return catalogue;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// Training camp catalogue of the Modern season core (docs/new_engine/trainingslager.md, M4).
|
||||
//
|
||||
// Classic has eight resorts with four quality grades 1-5 read from the executable. Modern
|
||||
// worlds list their camps in rule:training-camps: map (Germany, Europe, Middle East, ...),
|
||||
// position on that map, place, country, base price and the four grades 0-6 (pitch, fitness,
|
||||
// catering, lodging). A world without such a catalogue gets the built-in, fictional
|
||||
// catalogue of 18 camps the Modern interface was designed with.
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct CampMap {
|
||||
std::string id; // map:de, map:eu, map:me
|
||||
std::string name;
|
||||
std::optional<int> width, height; // coordinate system, once the interface defines it
|
||||
};
|
||||
|
||||
struct TrainingCamp {
|
||||
std::string id; // resort:<n>
|
||||
std::string map; // CampMap id
|
||||
std::optional<int> x, y; // position on the map, null until the interface sets it
|
||||
std::string name, place, country;
|
||||
int32_t base_price = 0; // the price is base_price + 5000 per squad player
|
||||
std::array<uint8_t, 4> quality{}; // pitch, fitness, catering, lodging (0-6)
|
||||
};
|
||||
|
||||
struct CampCatalogue {
|
||||
std::vector<CampMap> maps;
|
||||
std::vector<TrainingCamp> camps;
|
||||
};
|
||||
|
||||
// The built-in catalogue: 18 fictional camps on three maps (Germany 6, Europe 9, Middle East 3).
|
||||
const CampCatalogue& default_camp_catalogue();
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -153,9 +153,8 @@ int squad_count(const ModernState& g, int team, int flags) {
|
||||
|
||||
// SlotTeam: club of an absolute squad slot (-1 for the pool).
|
||||
int slot_team(int slot) {
|
||||
if (slot < german_clubs() * 24) return slot / 24;
|
||||
if (slot < int(transfer_list_slot())) return (slot - german_clubs() * 24) / 16 + german_clubs();
|
||||
return -1;
|
||||
// WorldLayout: Classic gives 24 slots to the German clubs and 16 to the international ones.
|
||||
return slot >= 0 && uint32_t(slot) < transfer_list_slot() ? world_layout().team_of_slot(slot) : -1;
|
||||
}
|
||||
|
||||
// Add32 / FacilityRating2: the club's rating of its facilities.
|
||||
@@ -968,7 +967,7 @@ static bool remove_from_seller_impl(ModernState& g, int seller, int player, Minu
|
||||
report.fail("transfer: the player is not in the seller's squad (internal error 0x21)");
|
||||
return false;
|
||||
}
|
||||
for (size_t s = transfer_list_slot(); s < 2972; s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
for (size_t s = transfer_list_slot(); s < free_agent_slot(); s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
if ((g.squad_slots[s] & 0xFFF) == player) g.squad_slots[s] = 0xFFF;
|
||||
for (size_t s = at; s + 1 < range.first + range.count; s++) g.squad_slots[s] = g.squad_slots[s + 1];
|
||||
g.squad_slots[range.first + range.count - 1] = 0xFFF;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/achievements.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -184,7 +185,7 @@ Image AchievementsScreen::render()const{
|
||||
for(int season=0;season<state_.season_count;++season){
|
||||
const auto& row=state_.seasons[size_t(season)];const int x=0x41+season*4;
|
||||
if(row.league_result<0xfe){
|
||||
int remaining=(int(exe_.u16(::bmh::layout::TeamsWithSquads))-0x12)-row.league_result;
|
||||
int remaining=(world_layout().german_teams-0x12)-row.league_result;
|
||||
int y=baselines[0]-1, color_index=0, step_index=4;
|
||||
while(remaining>=0){
|
||||
const int step=exe_.u8(::bmh::layout::LeagueSizes+uint32_t(step_index));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/club_info.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -46,7 +47,7 @@ int source_manager_of(const GameState& game, int team) {
|
||||
const int manager = game.manager_of(team);
|
||||
if (manager >= 0) return manager;
|
||||
constexpr size_t fifth_team_offset = size_t(4) * 0xb0c + 0x290;
|
||||
if (!game.manager_teams.empty() && game.manager_teams.front() == kNoTeam &&
|
||||
if (!game.manager_teams.empty() && game.manager_teams.front() == no_team() &&
|
||||
game.manager_records.size() >= fifth_team_offset + 2) {
|
||||
const uint16_t fifth_team = uint16_t(game.manager_records[fifth_team_offset] |
|
||||
uint16_t(game.manager_records[fifth_team_offset + 1]) << 8);
|
||||
@@ -59,14 +60,14 @@ int source_manager_of(const GameState& game, int team) {
|
||||
ClubInfoProjection club_info_from_game(const GameState& g, int team,
|
||||
const ClubInfoEntry& entry, const LeImage& exe,
|
||||
const TextDb&) {
|
||||
if (team < 0 || team > kNoTeam) throw FormatError("club info: runtime team outside Original range");
|
||||
if (team < 0 || team > no_team()) throw FormatError("club info: runtime team outside Original range");
|
||||
ClubInfoProjection out;
|
||||
out.runtime_team = team;
|
||||
out.original_club_name = g.club_name(team);
|
||||
out.gradient_text = g.memory.u8(::bmh::layout::TextGradientDisabled) == 0 && exe.u8(::bmh::layout::TextGradientMode) == 2;
|
||||
out.decorated_background = g.memory.u8(::bmh::layout::PlainBackground) == 0;
|
||||
out.has_squad = team == kNoTeam || team < exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
if (team != kNoTeam && team >= exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField)) {
|
||||
out.has_squad = team == no_team() || team < world_layout().league_teams;
|
||||
if (team != no_team() && team >= world_layout().league_teams) {
|
||||
out.has_squad = false;
|
||||
out.category = team >= 0 && size_t(team) < g.team_morale.size()
|
||||
? uint8_t((g.team_morale[size_t(team)] >> 6) & 3) : 0;
|
||||
@@ -80,7 +81,7 @@ ClubInfoProjection club_info_from_game(const GameState& g, int team,
|
||||
? uint8_t((g.team_morale[size_t(team)] >> 6) & 3) : 0;
|
||||
const int manager = source_manager_of(g, team);
|
||||
std::vector<int> loan_records;
|
||||
if (manager >= 0 && team != kNoTeam &&
|
||||
if (manager >= 0 && team != no_team() &&
|
||||
g.memory.has(::bmh::layout::Career_CareerManagersEnd_RuntimeField + 0x17) && g.memory.has(::bmh::layout::ClubInfo_FormatError_RuntimeField2 + 0x0b) && g.memory.has(::bmh::layout::ClubInfo_FormatError_RuntimeField + 0x41f)) {
|
||||
for (int loan = 0; loan < 12; ++loan)
|
||||
if (g.memory.u16(::bmh::layout::Career_CareerManagersEnd_RuntimeField + uint32_t(loan) * 2) != 0x0fff &&
|
||||
@@ -120,7 +121,7 @@ ClubInfoProjection club_info_from_game(const GameState& g, int team,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player.player_id >= 0 && manager >= 0 && team != kNoTeam) {
|
||||
if (player.player_id >= 0 && manager >= 0 && team != no_team()) {
|
||||
for (int offer = 0; offer < 4; ++offer) {
|
||||
const uint32_t address = ::bmh::layout::OfferSlots + uint32_t(offer) * 4;
|
||||
if (g.memory.has(address + 3)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/contracts.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
|
||||
@@ -88,7 +89,7 @@ ContractsState contracts_from_game(const GameState& game, int manager_slot, uint
|
||||
size_t(manager_slot) * kManagerRecord + kManagerRecord > game.manager_records.size())
|
||||
throw FormatError("contracts: invalid manager slot");
|
||||
const int team = game.manager_teams[size_t(manager_slot)];
|
||||
if (team == kNoTeam) throw FormatError("contracts: Vereinsverträge sind für Nationalteams nicht verfügbar");
|
||||
if (team == no_team()) throw FormatError("contracts: Vereinsverträge sind für Nationalteams nicht verfügbar");
|
||||
const SquadRange range = squad_range(team);
|
||||
const size_t board = size_t(manager_slot) * kBoard;
|
||||
if (range.count > 24 || range.first + range.count > game.squad_slots.size() || board + range.count * kBoardSlot > game.tactics.size())
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/cup_draw.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -51,7 +52,7 @@ void source_frame(Image& out,int x,int y) {
|
||||
for(int yy=y-1;yy<=y+38;++yy)if(yy>=0&&yy<out.height&&x+38>=0&&x+38<out.width)out.at(x+38,yy)=0x40;
|
||||
}
|
||||
int region_for_team(int id) {
|
||||
if(id==kNoTeam)return 0;
|
||||
if(id==no_team())return 0;
|
||||
int t=id;
|
||||
for(int league=0;league<kLeagueCount;++league){t-=kLeagueSizes[league];if(t<0)return league>=5?league-5+1:0;}
|
||||
if(t-kCupOnlyTeams>=0)return (t-kCupOnlyTeams)/7-5+10;
|
||||
@@ -152,7 +153,7 @@ CupDrawProjection cup_draw_from_game(const GameState& game,const SeasonCupDrawEv
|
||||
context+=original_to_utf8(exe.cstring(::bmh::layout::CupDraw_FormatError_ExecutableField));
|
||||
} else {
|
||||
std::array<int,5> values{};
|
||||
if(id>=168&&id!=kNoTeam) {
|
||||
if(id>=168&&id!=no_team()) {
|
||||
const auto snapshot=std::find_if(event.group_average_snapshots.begin(),event.group_average_snapshots.end(),
|
||||
[&](const auto& v){return v.runtime_id==id;});
|
||||
if(snapshot==event.group_average_snapshots.end())
|
||||
|
||||
+14
-12
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/desk_state.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -82,7 +83,7 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
// TablePosition returns rank 2 for this special national row;
|
||||
// QuoteNationalFriendlyMatch uses its native no-team squad (no random rating).
|
||||
curve.current_position = 2;
|
||||
if (game) curve.strength = team_average(*game, kNoTeam, 0x1ff).value;
|
||||
if (game) curve.strength = team_average(*game, no_team(), 0x1ff).value;
|
||||
return;
|
||||
}
|
||||
const int league = executable_league(exe, team);
|
||||
@@ -186,7 +187,7 @@ DeskState project(const StaticMemory& memory, const Tables& t, const LeImage& ex
|
||||
identity.league = t.managers.at(manager_base + 0x210);
|
||||
identity.portrait = t.managers.at(manager_base + 0x221);
|
||||
identity.badge = word(t.badges, size_t(team) * 2) & 0x1ff;
|
||||
if ((team != kNoTeam && identity.league > 8) || identity.portrait > 11)
|
||||
if ((team != no_team() && identity.league > 8) || identity.portrait > 11)
|
||||
throw FormatError("desk: invalid manager identity");
|
||||
d.managers.push_back(std::move(identity));
|
||||
}
|
||||
@@ -194,7 +195,7 @@ DeskState project(const StaticMemory& memory, const Tables& t, const LeImage& ex
|
||||
if (t.managers.size() < base + 0xb0c || t.options.size() < size_t(d.manager_slot + 1) * 5)
|
||||
throw FormatError("desk: truncated manager records/options");
|
||||
d.runtime_club = t.teams.at(d.manager_slot);
|
||||
d.national_team = d.runtime_club == kNoTeam;
|
||||
d.national_team = d.runtime_club == no_team();
|
||||
d.national_coach_takeover = memory.has(::bmh::layout::CoachActive) && memory.u8(::bmh::layout::CoachActive) != 0;
|
||||
if (d.national_team && d.national_coach_takeover) {
|
||||
const int saved_manager_count = memory.has(::bmh::layout::OriginalManagerCount) ? memory.u8(::bmh::layout::OriginalManagerCount) : 0;
|
||||
@@ -209,7 +210,7 @@ DeskState project(const StaticMemory& memory, const Tables& t, const LeImage& ex
|
||||
if (t.managers.size() < manager_base + 0x292)
|
||||
throw FormatError("desk: truncated saved manager roster during national takeover");
|
||||
const int team = word(t.managers, manager_base + 0x290);
|
||||
if (team < 0 || team >= int(t.name_offsets.size()) || team == kNoTeam ||
|
||||
if (team < 0 || team >= int(t.name_offsets.size()) || team == no_team() ||
|
||||
t.badges.size() < size_t(team + 1) * 2)
|
||||
throw FormatError("desk: invalid home club in national return roster");
|
||||
DeskManagerIdentity original;
|
||||
@@ -303,10 +304,11 @@ DeskState project(const StaticMemory& memory, const Tables& t, const LeImage& ex
|
||||
uint8_t remaining = 18;
|
||||
for (size_t kind = 6; kind < 13; ++kind) remaining = uint8_t(remaining - t.managers.at(base + 0xc5 + kind));
|
||||
d.warnings[3] = remaining < 4;
|
||||
const int max24 = exe.u16(::bmh::layout::TeamsWithSquads), league_teams = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
if (!d.national_team && d.runtime_club >= league_teams) throw FormatError("desk: cup-only squad projection not supported");
|
||||
const size_t first = d.national_team ? 3072 : size_t(d.runtime_club < max24 ? d.runtime_club * 24 : d.runtime_club * 16 + max24 * 8);
|
||||
const size_t count = d.national_team ? 24 : (d.runtime_club < max24 ? 24 : 16);
|
||||
const int league_teams = world_layout().league_teams; // WorldLayout: Classic = executable TeamsWithSquads/DispatchLineup values
|
||||
if (!d.national_team && d.runtime_club >= league_teams) throw FormatError("desk: cup-only squad projection not supported (club " + std::to_string(d.runtime_club) + ")");
|
||||
const SquadRange squad_slots = squad_range(d.national_team ? no_team() : d.runtime_club);
|
||||
const size_t first = squad_slots.first;
|
||||
const size_t count = squad_slots.count;
|
||||
if (t.squads.size() < first + count || t.tactics.size() < size_t(d.manager_slot) * 0x840 + count * 0x58)
|
||||
throw FormatError("desk: truncated squad/tactics");
|
||||
int lineup = 0, reserve = 0, condition = 0, technique = 0, form = 0, morale = 0;
|
||||
@@ -425,10 +427,10 @@ void validate_desk_state(const DeskState& d) {
|
||||
if (team < 0 || !unique.insert(team).second || manager.runtime_club != team ||
|
||||
manager.club_identity_key < 0 || !unique_identities.insert(manager.club_identity_key).second ||
|
||||
manager.portrait < 0 || manager.portrait > 11 ||
|
||||
(team != kNoTeam && (manager.league < 0 || manager.league > 8)))
|
||||
(team != no_team() && (manager.league < 0 || manager.league > 8)))
|
||||
throw FormatError("desk: invalid or duplicate manager runtime club");
|
||||
}
|
||||
const bool national = d.runtime_club == kNoTeam;
|
||||
const bool national = d.runtime_club == no_team();
|
||||
if (d.table_position && (*d.table_position < 0 || *d.table_position > 31))
|
||||
throw FormatError("desk: invalid Source table position");
|
||||
if (d.national_team != national ||
|
||||
@@ -440,7 +442,7 @@ void validate_desk_state(const DeskState& d) {
|
||||
throw FormatError("desk: missing national return roster");
|
||||
std::set<int> return_keys;
|
||||
for (const auto& manager : d.national_return_roster)
|
||||
if (manager.runtime_club < 0 || manager.runtime_club >= kNoTeam ||
|
||||
if (manager.runtime_club < 0 || manager.runtime_club >= no_team() ||
|
||||
manager.club_identity_key < 0 || !return_keys.insert(manager.club_identity_key).second ||
|
||||
manager.portrait < 0 || manager.portrait > 11 || manager.league < 0 || manager.league > 8)
|
||||
throw FormatError("desk: invalid national return roster identity");
|
||||
@@ -516,7 +518,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
exe, g.level, g.date, g.season_day(), g.season, revision);
|
||||
// DeskDate only auto-opens for an ordinary club manager; the national
|
||||
// runtime (0x165) suppresses this consumer while manual mailbox access remains valid.
|
||||
if (d.runtime_club != kNoTeam && d.manager_slot >= 0 && d.manager_slot < 32 && g.memory.has(::bmh::layout::MailboxRecipientMask))
|
||||
if (d.runtime_club != no_team() && d.manager_slot >= 0 && d.manager_slot < 32 && g.memory.has(::bmh::layout::MailboxRecipientMask))
|
||||
d.mailbox_notification_pending = (g.memory.u32(::bmh::layout::MailboxRecipientMask) & (uint32_t(1) << d.manager_slot)) != 0;
|
||||
d.date.year += g.display_start_year - exe.display_start_year();
|
||||
project_table_position(d, g);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/environment.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -59,7 +60,7 @@ EnvironmentView environment_from_game(const bmh::GameState& game, uint64_t revis
|
||||
if (manager < 0 || size_t(manager) >= game.manager_teams.size())
|
||||
throw FormatError("environment: active manager is outside the source roster");
|
||||
const int team = game.manager_teams[size_t(manager)];
|
||||
if (team < 0 || team == kNoTeam) throw FormatError("environment: no club environment for this manager");
|
||||
if (team < 0 || team == no_team()) throw FormatError("environment: no club environment for this manager");
|
||||
EnvironmentView view;
|
||||
view.manager_slot = manager;
|
||||
view.runtime_club = team;
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "ui/flow.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/source_hold.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -93,7 +94,7 @@ void validate_confirmed_desk(const std::vector<ManagerChoice>& choices,
|
||||
const std::vector<DeskManagerIdentity>& previous_national_roster,
|
||||
bool allow_turn_handoff, const DeskState& desk) {
|
||||
validate_desk_state(desk);
|
||||
const bool previous_national = previous.size() == 1 && previous[0].runtime_club == kNoTeam &&
|
||||
const bool previous_national = previous.size() == 1 && previous[0].runtime_club == no_team() &&
|
||||
(desk.options.world || previous_national_coach_takeover);
|
||||
const bool incoming_national = desk.national_team &&
|
||||
(desk.options.world || desk.national_coach_takeover);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "ui/friendly_match.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -78,7 +79,7 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
font_(load_font(asset_path(data / "F", "BMH2.FNT"))),
|
||||
exe_(load_le(asset_path(data, "BMH.exe"))),
|
||||
data_(data), next_request_id_(state_.first_request_id) {
|
||||
const bool valid_national_slot = state_.national_team && state_.runtime_team == bmh::kNoTeam;
|
||||
const bool valid_national_slot = state_.national_team && state_.runtime_team == bmh::no_team();
|
||||
if (state_.manager_slot < 0 || state_.manager_slot > 3 || state_.runtime_team < 0 ||
|
||||
(state_.runtime_team >= 168 && !valid_national_slot) ||
|
||||
state_.revision == UINT64_MAX || !state_.first_request_id || state_.planner_count < 0 ||
|
||||
@@ -87,7 +88,7 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
if (!state_.mode_three) {
|
||||
stage_ = FriendlyStage::unavailable;
|
||||
feedback_ = "Freundschaftsspiele sind nur in Modus III verfuegbar.";
|
||||
} else if (state_.national_team || state_.runtime_team == bmh::kNoTeam) {
|
||||
} else if (state_.national_team || state_.runtime_team == bmh::no_team()) {
|
||||
stage_ = FriendlyStage::unavailable;
|
||||
feedback_ = "Freundschaftsspiele fuer die Nationalmannschaft sind hier nicht verfuegbar.";
|
||||
} else if (desk_menu_kind_ != 6) {
|
||||
@@ -108,14 +109,14 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
FriendlyQuoteProjection national_quote, NationalFriendlyBookingRequest national_booking,
|
||||
int desk_menu_kind)
|
||||
: FriendlyMatchScreen(data, std::move(state), desk_menu_kind) {
|
||||
const bool source_owner = desk_menu_kind == 6 && national_quote.runtime_team == bmh::kNoTeam &&
|
||||
const bool source_owner = desk_menu_kind == 6 && national_quote.runtime_team == bmh::no_team() &&
|
||||
national_booking.owner.menu_kind == 6 && national_booking.owner.manager == national_quote.manager_slot &&
|
||||
national_booking.owner.runtime_team == bmh::kNoTeam &&
|
||||
national_booking.owner.runtime_team == bmh::no_team() &&
|
||||
national_booking.owner.revision == national_quote.revision &&
|
||||
national_booking.quote.terms.opponent == national_quote.opponent &&
|
||||
national_booking.quote.terms.manager_home == national_quote.manager_home &&
|
||||
national_booking.quote.terms.planner_count == national_quote.planner_count;
|
||||
if (!source_owner || !state_.national_team || state_.runtime_team != bmh::kNoTeam ||
|
||||
if (!source_owner || !state_.national_team || state_.runtime_team != bmh::no_team() ||
|
||||
state_.manager_slot != national_quote.manager_slot || state_.revision != national_quote.revision ||
|
||||
national_quote.dates.size() != 366 || national_quote.cost < 0 ||
|
||||
national_booking.quote.terms.status != bmh::FriendlyQuoteStatus::quoted ||
|
||||
@@ -124,8 +125,8 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
feedback_ = "Diese Freundschaftsspielanfrage ist nicht mehr aktuell.";
|
||||
return;
|
||||
}
|
||||
const int expected_home = national_quote.manager_home ? bmh::kNoTeam : national_quote.opponent;
|
||||
const int expected_away = national_quote.manager_home ? national_quote.opponent : bmh::kNoTeam;
|
||||
const int expected_home = national_quote.manager_home ? bmh::no_team() : national_quote.opponent;
|
||||
const int expected_away = national_quote.manager_home ? national_quote.opponent : bmh::no_team();
|
||||
if (national_quote.home_team != expected_home || national_quote.away_team != expected_away ||
|
||||
national_quote.payer_manager != national_booking.quote.terms.payer_manager ||
|
||||
national_quote.opponent_manager != national_booking.quote.terms.opponent_manager ||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/incoming_transfer.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
|
||||
@@ -95,7 +96,7 @@ IncomingTransferDecisionState incoming_transfer_decision_from_game_impl(
|
||||
: view.list_entry >= 0 && view.list_entry < (view.source_outgoing_editor_context ? 44 : 40);
|
||||
if (!view.valid || !entry_valid ||
|
||||
view.player < 0 || size_t(view.player) >= game.players.size() ||
|
||||
(view.seller != 0x0fff && view.seller != kNoTeam && (view.seller < 0 || size_t(view.seller) >= game.club_ids.size())) ||
|
||||
(view.seller != 0x0fff && view.seller != no_team() && (view.seller < 0 || size_t(view.seller) >= game.club_ids.size())) ||
|
||||
view.seller_manager < -1 || view.viewer_manager < -1 ||
|
||||
view.preferred_bid_index < -1 || view.preferred_bid_index >= 4)
|
||||
throw FormatError("incoming transfer: invalid decision context");
|
||||
@@ -113,10 +114,10 @@ IncomingTransferDecisionState incoming_transfer_decision_from_game_impl(
|
||||
out.has_preferred_bid = view.has_preferred_bid;
|
||||
out.preferred_bid_passed_random_check = view.preferred_bid_passed_random_check;
|
||||
out.player_name = game.player_name(view.player);
|
||||
out.seller_name = (view.seller == 0x0fff || view.seller == kNoTeam) ? std::string() : game.club_name(view.seller);
|
||||
out.seller_name = (view.seller == 0x0fff || view.seller == no_team()) ? std::string() : game.club_name(view.seller);
|
||||
// ClubName2 derives this label from the seller team token. A club is
|
||||
// named directly; the player-pool token resolves to the original adviser.
|
||||
out.negotiator_name = (view.seller == 0x0fff || view.seller == kNoTeam)
|
||||
out.negotiator_name = (view.seller == 0x0fff || view.seller == no_team())
|
||||
? (game.texts ? (*game.texts)[925] : "SPIELERBERATER")
|
||||
: out.seller_name;
|
||||
out.age = game.players[size_t(view.player)].age();
|
||||
|
||||
+6
-4
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/lineup.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -37,14 +38,15 @@ LineupState project(const StaticMemory& memory, const LeImage& exe, const std::v
|
||||
if (out.manager_slot < 0 || out.manager_slot > 3 || size_t(out.manager_slot) >= teams.size())
|
||||
throw FormatError("lineup: unsupported active manager");
|
||||
out.runtime_club = teams.at(out.manager_slot);
|
||||
const int split = exe.u16(::bmh::layout::TeamsWithSquads), limit = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
const bool national = out.runtime_club == kNoTeam && out.manager_slot == 0 && teams.size() == 1 &&
|
||||
const int limit = world_layout().league_teams; // WorldLayout: Classic = executable DispatchLineup value
|
||||
const bool national = out.runtime_club == no_team() && out.manager_slot == 0 && teams.size() == 1 &&
|
||||
((memory.u32(::bmh::layout::CompetitionSelection) & 2) != 0 ||
|
||||
(memory.has(::bmh::layout::CoachActive) && memory.u8(::bmh::layout::CoachActive) != 0));
|
||||
if (out.runtime_club < 0 || (out.runtime_club >= limit && !national))
|
||||
throw FormatError("lineup: only domestic league squads are supported");
|
||||
const size_t count = national || out.runtime_club < split ? 24 : 16;
|
||||
const size_t first = national ? 3072 : out.runtime_club < split ? size_t(out.runtime_club) * 24 : size_t(out.runtime_club) * 16 + split * 8;
|
||||
const SquadRange squad_slots = squad_range(national ? no_team() : out.runtime_club);
|
||||
const size_t count = squad_slots.count;
|
||||
const size_t first = squad_slots.first;
|
||||
const size_t board_base = size_t(out.manager_slot) * 0x840;
|
||||
if (first + count > squad.size() || board_base + count * 0x58 > tactics.size() || size_t(out.manager_slot) * 5 >= options.size())
|
||||
throw FormatError("lineup: truncated squad/tactics/options");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/live_matchday.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -51,7 +52,7 @@ std::string original(std::string_view utf8) {
|
||||
int placed_players(const GameState& state, int team) {
|
||||
// SquadRange3 returns 11 for every non-league field team, except the special no-team squad.
|
||||
const SquadRange range = squad_range(team);
|
||||
if (range.count == 0 && team != kNoTeam) return 11;
|
||||
if (range.count == 0 && team != no_team()) return 11;
|
||||
uint8_t count = 0;
|
||||
const size_t end = std::min(state.squad_slots.size(), range.first + range.count);
|
||||
for (size_t slot = range.first; slot < end; ++slot) {
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -150,7 +151,7 @@ ManagerScreen::ManagerScreen(const std::filesystem::path& data, int slot, const
|
||||
if (exe_.u8(::bmh::layout::Manager_FormatError_RuntimeField + i * 2) < 'B') ++text_id;
|
||||
if (last_[i] - first_[i] >= 20) throw FormatError("manager: league exceeds picker grid");
|
||||
}
|
||||
first_[5] = exe_.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField); last_[5] = first_[5] + 19;
|
||||
first_[5] = world_layout().league_teams; last_[5] = first_[5] + 19;
|
||||
first_[6] = first_[5] + 20; last_[6] = first_[5] + exe_.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6) - 1;
|
||||
leagues_[5] = texts_[(::bmh::layout::Manager_FormatError_TextPointer - ::bmh::layout::TextPointerTable) / 4]; leagues_[6] = leagues_[5];
|
||||
if (leagues_[6].empty()) throw FormatError("manager: missing extra-team label");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/other_games_state.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -164,7 +165,7 @@ int source_league(const LeImage& exe, int team) {
|
||||
}
|
||||
|
||||
uint8_t source_country(const LeImage& exe, int team) {
|
||||
if (team == kNoTeam) return 0;
|
||||
if (team == no_team()) return 0;
|
||||
if (team < 0) invalid("negative team for Source country lookup");
|
||||
int remaining = team;
|
||||
const int domestic_cutoff = exe.u8(::bmh::layout::LeaguePairings_LeaguePairingsConstants_RuntimeField);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/pending_offer.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -20,7 +21,7 @@ int pending_offer_owner_team(const GameState& game, int manager) {
|
||||
// AdvanceTurn restores NextDeskManager[0] after the temporary one-manager national
|
||||
// desk. Records1..3 still exist even though they have no runtime desk.
|
||||
const bool retained = manager > 0 && manager < 4 &&
|
||||
game.manager_teams.size() == 1 && game.manager_teams[0] == kNoTeam &&
|
||||
game.manager_teams.size() == 1 && game.manager_teams[0] == no_team() &&
|
||||
game.memory.has(::bmh::layout::CoachActive) && game.memory.u8(::bmh::layout::CoachActive) != 0 &&
|
||||
game.memory.has(::bmh::layout::ManagerCount) && game.memory.u8(::bmh::layout::ManagerCount) == 1 &&
|
||||
game.memory.has(::bmh::layout::OriginalManagerCount) && game.memory.u8(::bmh::layout::OriginalManagerCount) <= 4 &&
|
||||
@@ -40,7 +41,7 @@ int pending_offer_owner_team(const GameState& game, int manager) {
|
||||
|
||||
bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int expected_team) {
|
||||
if (raw_offer_slot < 0 || raw_offer_slot >= 4 ||
|
||||
game.manager_teams.size() != 1 || game.manager_teams[0] != kNoTeam ||
|
||||
game.manager_teams.size() != 1 || game.manager_teams[0] != no_team() ||
|
||||
!game.memory.has(::bmh::layout::CoachActive) || game.memory.u8(::bmh::layout::CoachActive) == 0 ||
|
||||
!game.memory.has(::bmh::layout::ManagerCount) || game.memory.u8(::bmh::layout::ManagerCount) != 1 ||
|
||||
!game.memory.has(::bmh::layout::OriginalManagerCount) || game.memory.u8(::bmh::layout::OriginalManagerCount) < 1 || game.memory.u8(::bmh::layout::OriginalManagerCount) > 4 ||
|
||||
@@ -59,7 +60,7 @@ bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int ex
|
||||
const uint32_t offer = ::bmh::layout::OfferSlots + uint32_t(raw_offer_slot) * 4;
|
||||
const uint32_t list = ::bmh::layout::EditorList + uint32_t(raw_offer_slot + 40) * 0x58;
|
||||
const size_t pool = 0xb70 + size_t(raw_offer_slot + 40);
|
||||
if (team_at(0) != kNoTeam || buyer >= 138 || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
if (team_at(0) != no_team() || buyer >= 138 || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
!game.memory.has(list + 0x57) || pool >= game.squad_slots.size())
|
||||
return false;
|
||||
const uint32_t word = game.memory.u32(offer);
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/pitch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -58,7 +59,7 @@ PitchExtras extras(const StaticMemory& memory,const Bytes& managers,const Bytes&
|
||||
const int count=memory.u8(::bmh::layout::ManagerCount);
|
||||
if(count<1||count>4||e.manager_slot>=count||teams.size()!=size_t(count))throw FormatError("pitch: invalid active manager");
|
||||
e.runtime_club=teams.at(e.manager_slot);
|
||||
if(e.runtime_club<0||e.runtime_club>=exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField))throw FormatError("pitch: unsupported club");
|
||||
if(e.runtime_club<0||e.runtime_club>=world_layout().league_teams)throw FormatError("pitch: unsupported club");
|
||||
const size_t m=size_t(e.manager_slot)*0xb0c,f=size_t(e.manager_slot)*0x160;
|
||||
if(managers.size()<m+0xb0c||formations.size()<f+0x160||badges.size()<size_t(e.runtime_club+1)*2)
|
||||
throw FormatError("pitch: truncated manager/formations/badges");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/player_card.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -45,7 +46,7 @@ PlayerCardState project(LineupState lineup,const LeImage& exe,int row,const Byte
|
||||
const int nation=p.attributes.nationality()+((p.bonus&0x80)?32:0);
|
||||
const size_t nation_club=exe.u16(::bmh::layout::ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3)+exe.u16(::bmh::layout::NoTeamSquadStart)+nation;
|
||||
out.nationality_name=pool_name(names,offsets.at(nation_club));
|
||||
if (out.lineup.runtime_club == kNoTeam) {
|
||||
if (out.lineup.runtime_club == no_team()) {
|
||||
// The national runtime slot is absent from the ordinary short-name
|
||||
// table; its projected club name is already the full country label.
|
||||
out.club_short_name=out.lineup.club_name;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/flow.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -319,9 +320,9 @@ void StartupFlow::show_national_friendly_picker(WorldCupStatisticsProjection pro
|
||||
if (!desktop_ || !engine_attached_ || in_preparation_menu() || in_readonly_view() || matchday_results_ ||
|
||||
!desktop_->pending() || *desktop_->pending() != owner || owner.kind != DeskRequestKind::open_menu ||
|
||||
owner.menu_kind != 6 || owner.revision != desktop_->state().revision ||
|
||||
owner.manager_slot != desktop_->state().manager_slot || runtime_team != bmh::kNoTeam ||
|
||||
owner.manager_slot != desktop_->state().manager_slot || runtime_team != bmh::no_team() ||
|
||||
size_t(owner.manager_slot) >= desktop_->state().manager_teams.size() ||
|
||||
desktop_->state().manager_teams[size_t(owner.manager_slot)] != bmh::kNoTeam ||
|
||||
desktop_->state().manager_teams[size_t(owner.manager_slot)] != bmh::no_team() ||
|
||||
!projection.can_select_opponent || next_friendly_request_id_ == UINT64_MAX)
|
||||
throw FormatError("national friendly: expected the active menu-6 national caller");
|
||||
NationalFriendlyUiOwner ui_owner{6, owner.manager_slot, runtime_team,
|
||||
@@ -361,7 +362,7 @@ void StartupFlow::show_national_friendly_calendar(FriendlyMatchState state,
|
||||
booking.quote.terms.status!=FriendlyQuoteStatus::quoted||
|
||||
national_friendly_desk_owner_.revision!=desktop_->state().revision||
|
||||
national_friendly_desk_owner_.manager_slot!=state.manager_slot||
|
||||
state.runtime_team!=bmh::kNoTeam||!state.national_team||state.revision!=desktop_->state().revision||
|
||||
state.runtime_team!=bmh::no_team()||!state.national_team||state.revision!=desktop_->state().revision||
|
||||
state.manager_slot!=desktop_->state().manager_slot||quote.request_id!=booking.owner.request_id||
|
||||
quote.revision!=booking.owner.revision||quote.opponent!=booking.quote.terms.opponent||
|
||||
quote.manager_slot!=booking.owner.manager||state.manager_name!=original_to_utf8(desktop_->state().manager_name)||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/tactics.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -34,11 +35,11 @@ TacticsState project(const StaticMemory& memory, const Bytes& managers, const By
|
||||
throw FormatError("tactics: truncated manager/board/options");
|
||||
TacticsState s;
|
||||
s.manager_slot = slot; s.runtime_club = teams.at(slot); s.revision = revision;
|
||||
const bool national = s.runtime_club == kNoTeam && slot == 0 && count == 1 &&
|
||||
const bool national = s.runtime_club == no_team() && slot == 0 && count == 1 &&
|
||||
((memory.u32(::bmh::layout::CompetitionSelection) & 2) != 0 ||
|
||||
(memory.has(::bmh::layout::CoachActive) && memory.u8(::bmh::layout::CoachActive) != 0));
|
||||
if (s.runtime_club < 0 || s.runtime_club >= int(offsets.size()) ||
|
||||
(s.runtime_club == kNoTeam && !national))
|
||||
(s.runtime_club == no_team() && !national))
|
||||
throw FormatError("tactics: unsupported runtime club");
|
||||
s.manager_name = bounded_string(managers, manager + 0xa8, 26);
|
||||
s.club_name = bounded_string(names, offsets.at(s.runtime_club), names.size());
|
||||
|
||||
+5
-3
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "ui/training.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -56,10 +57,11 @@ TrainingState project(const StaticMemory& memory, const Bytes& records, const By
|
||||
if (manager_count < 1 || manager_count > 4 || s.manager_slot >= manager_count || teams.size() != size_t(manager_count))
|
||||
throw FormatError("training: inconsistent active manager");
|
||||
s.runtime_club = teams.at(s.manager_slot);
|
||||
const int max24 = exe.u16(::bmh::layout::TeamsWithSquads), max16 = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
const int max16 = world_layout().league_teams; // WorldLayout: Classic = executable DispatchLineup value
|
||||
if (s.runtime_club < 0 || s.runtime_club >= max16) throw FormatError("training: national/cup-only squad unsupported");
|
||||
s.squad_capacity = s.runtime_club < max24 ? 24 : 16;
|
||||
const size_t first = size_t(s.runtime_club < max24 ? s.runtime_club * 24 : s.runtime_club * 16 + max24 * 8);
|
||||
const SquadRange squad_slots = squad_range(s.runtime_club);
|
||||
s.squad_capacity = int(squad_slots.count);
|
||||
const size_t first = squad_slots.first;
|
||||
const size_t manager = size_t(s.manager_slot) * 0xb0c, board = size_t(s.manager_slot) * 0x840;
|
||||
if (records.size() < manager + 0xb0c || tactics.size() < board + size_t(s.squad_capacity) * 0x58 ||
|
||||
options.size() < size_t(s.manager_slot + 1) * 5 || squads.size() < first + size_t(s.squad_capacity))
|
||||
|
||||
Reference in new issue
Block a user