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:
ClaudeandClaude Opus 5.5 committed 2026-10-23 22:43:25 +02:00
1 parent 13bdc56f04
commit 6f55622307
53 files changed
+1392 -87

No files matched your search

+16 -1
View File
@@ -341,8 +341,19 @@ add_subdirectory(src/import)
# Modern session: fork of the Classic CareerSession on the Modern season core. It still
# uses the Classic UI projections until the Modern projections exist (docs/new_engine).
# Modern world packages: the world tables and the Classic payload of a Modern data set.
add_library(bmh_modern_content STATIC src/modern/content/world.cpp src/modern/content/world_package.cpp
src/modern/content/world_expand.cpp)
target_link_libraries(bmh_modern_content PUBLIC bmh_content bmh_season_modern PRIVATE bmh_miniz)
if(MSVC)
target_compile_options(bmh_modern_content PRIVATE /W4 /utf-8)
endif()
add_executable(modern_world_info tests/modern_world_info.cpp)
target_link_libraries(modern_world_info PRIVATE bmh_modern_content)
add_library(bmh_modern_session STATIC src/modern/app/modern_session.cpp)
target_link_libraries(bmh_modern_session PUBLIC bmh_season_modern bmhui)
target_link_libraries(bmh_modern_session PUBLIC bmh_season_modern bmh_modern_content bmhui)
if(MSVC)
target_compile_options(bmh_modern_session PRIVATE /W4 /utf-8 /bigobj)
else()
@@ -1152,6 +1163,10 @@ if(MSVC)
endif()
add_test(NAME quit_confirmation_unit_tests COMMAND quit_confirmation_unit_tests)
add_executable(modern_camp_tests tests/modern_camp_tests.cpp)
target_link_libraries(modern_camp_tests PRIVATE bmh_season_modern)
add_test(NAME modern_camp_tests COMMAND modern_camp_tests)
add_executable(modern_calendar_tests tests/modern_calendar_tests.cpp)
target_link_libraries(modern_calendar_tests PRIVATE bmh_season_modern)
add_test(NAME modern_calendar_tests COMMAND modern_calendar_tests)
+17
View File
@@ -28,6 +28,23 @@ describe deliberate changes; they are not a list of every known compatibility li
- [src/game/week.hpp](../src/game/week.hpp): uses the enhanced assistant-training rules, retaining the selected skill until it reaches its maximum.
- [src/game/weekly.cpp](../src/game/weekly.cpp): uses the supported weekly-event configuration, with its rule switch disabled.
- [src/game/weekly.hpp](../src/game/weekly.hpp): uses the supported weekly processing and transfer rule profile.
- [src/modern/app/modern_session.cpp](../src/modern/app/modern_session.cpp): supports designated set-piece record initialization and validation.
- [src/modern/app/modern_session.cpp](../src/modern/app/modern_session.cpp): native saves do not consume gameplay randomness for encryption.
- [src/modern/content/world_expand.cpp](../src/modern/content/world_expand.cpp): 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.
- [src/modern/game/career.cpp](../src/modern/game/career.cpp): skips reserved calendar positions when assigning a joining manager to a club.
- [src/modern/game/career.hpp](../src/modern/game/career.hpp): uses the supported player-generation ranges and excludes reserved calendar positions when assigning managers.
- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): uses the supported transfer-fee arithmetic and designated set-piece fields.
- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): Modern training camps have grades up to six stars with a capped step, a higher limit and recovery extras.
- [src/modern/game/desk_actions.hpp](../src/modern/game/desk_actions.hpp): supports designated set-piece records and the supported transfer-editor rules.
- [src/modern/game/environment.hpp](../src/modern/game/environment.hpp): uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands.
- [src/modern/game/highscore.cpp](../src/modern/game/highscore.cpp): reads the supported edition-specific high-score format from the loaded image.
- [src/modern/game/matchday_setup.cpp](../src/modern/game/matchday_setup.cpp): in Modern worlds a referee may take a second match on a day with more matches than referees.
- [src/modern/game/season.cpp](../src/modern/game/season.cpp): retains the enhanced academy player-generation strength bands with monthly youth budgets.
- [src/modern/game/season.hpp](../src/modern/game/season.hpp): retains the enhanced academy player-generation strength bands with monthly youth budgets.
- [src/modern/game/week.cpp](../src/modern/game/week.cpp): uses the enhanced training rules: focus strength is at least five below its target, and completed skills rotate to another focus.
- [src/modern/game/week.hpp](../src/modern/game/week.hpp): uses the enhanced assistant-training rules, retaining the selected skill until it reaches its maximum.
- [src/modern/game/weekly.cpp](../src/modern/game/weekly.cpp): uses the supported weekly-event configuration, with its rule switch disabled.
- [src/modern/game/weekly.hpp](../src/modern/game/weekly.hpp): uses the supported weekly processing and transfer rule profile.
- [src/ui/league_table.hpp](../src/ui/league_table.hpp): uses three points for a win in the supported rule profile.
- [src/ui/pitch.cpp](../src/ui/pitch.cpp): supports owner-bound designated set-piece selection in the extended manager record.
- [src/ui/save_load.cpp](../src/ui/save_load.cpp): focuses the host save filename on entry and selects an existing name for replacement.
+2 -2
View File
@@ -54,8 +54,8 @@ Für 0.3 gilt außerdem:
| M0 | Classic-Referenz festhalten, Datensatz lokal bereitstellen | erledigt (Classic-Regressionen des öffentlichen Codes: Issue #14) |
| M1 | `WorldLayout`, Abzweig `src/modern/` | Abzweig und Layout erledigt; vereinsbezogene Speicherblöcke folgen mit M3 |
| M2 | Spielpläne je Liga, Kalender mit 38 Spieltagen | Engine-Teil erledigt (Tabelle je Ligagröße, Ligatermine, Aussetzen); Test mit echten Daten in M3 |
| M3 | Modern-Weltlader, Namen (Vor-/Nachname, UTF-8), Asset-Schlüssel | offen |
| M4 | Trainingslager: 18 Lager, drei Regionen, 6-Sterne-Wirkung | offen |
| M3 | Modern-Weltlader, Namen (Vor-/Nachname, UTF-8), Asset-Schlüssel | Weltlader erledigt: Modern-Datensatz spielt zwei Saisons; Namen/Assets für die UI liegen in `ModernState`, Spielstände folgen mit M6 |
| M4 | Trainingslager: 18 Lager, drei Karten, 6-Sterne-Wirkung | Engine erledigt (Katalog, Preis, 6-Sterne-Wirkung, Test); Saisonwirkung wird in M7 gemessen |
| M5 | Datenrevision 1.4 des Modern-Datensatzes (privat), Wirtschaftsprüfung | offen |
| M6 | Modern-Spielstände (`modern-career-v1`), Projektionen für die UI | offen |
| M7 | Balance-Läufe und Anpassungen | offen |
+14 -5
View File
@@ -12,14 +12,15 @@ Status: *geplant* (noch nicht in der Engine), *umgesetzt* (Engine liest/prüft e
| Nr. | Bereich | Änderung | Phase | Status |
|---|---|---|---|---|
| F1 | Manifest | Laufzeit `runtime:modern-v1`, spielbare Modern-Welt | M3 | geplant |
| F1 | Manifest | Laufzeit `runtime:modern-v1`, spielbare Modern-Welt | M3 | Engine: lädt `runtime:modern-v1` und vorerst auch `editor:world-v1`; lehnt Classic-Pakete ab |
| F2 | Ligen | Größe je Liga frei (12–20), Generator je Liga | M2 | Engine: Größe je Liga umgesetzt; Generator vorerst Tabelle passender Größe |
| F3 | Kalender | Ligatermine als Datumsliste | M2 | Engine-Funktion umgesetzt; Anbindung an den Weltlader mit M3 |
| F4 | Trainingslager | Katalog mit Karte und X/Y-Lage, Ort, Bild, Qualität 0–6 | M4 | geplant |
| F5 | Namen | Vor- und Nachname Pflicht, UTF-8 | M3 | geplant |
| F6 | Kader | bis 24 Plätze je Verein, Mindestgröße | M3 | geplant |
| F4 | Trainingslager | Katalog mit Karte und X/Y-Lage, Ort, Bild, Qualität 0–6 | M4 | Engine: liest den erweiterten Katalog; ohne Katalog gilt die eingebaute Vorgabe (18 Lager) |
| F5 | Namen | Vor- und Nachname Pflicht, UTF-8 | M3 | Engine: gelesen, in `ModernState` |
| F6 | Kader | bis 24 Plätze je Verein, Mindestgröße | M3 | Engine: 24 Plätze je Ligaverein; mehr als 24 Spieler werden abgelehnt |
| F7 | Finanzen | Finanzangaben für Vereine ohne Classic-Startregel | M5 | geplant |
| F8 | Spielstand | `save_profile: modern-career-v1` | M6 | geplant |
| F9 | Schiedsrichter | eigener Schiedsrichter-Pool der Welt, mehr als 49 | M5 | geplant (Engine nutzt bis dahin 49 und lässt Doppeleinsätze zu) |
## F1 · Manifest
@@ -79,7 +80,7 @@ Die bestehende Regel `rule:training-camps` (Typ `training_camps`) bleibt und wir
- Weitere Pflichtfelder für Modern: `name`, `place`, `country`. Geografische Koordinaten werden nicht gespeichert.
- Standardkarten und Resortbilder sind GUI-Ressourcen und werden anhand von Karten-/Lager-ID zugeordnet; sie sind keine Pflichtinhalte der Welt. `image` ist optional und nur für ein ausdrücklich in der Welt geliefertes Bild vorgesehen. Wenn gesetzt, muss der Asset-Schlüssel im normalen OBW-Asset-Index auflösbar sein. Siehe [GUI-/Welt-Trennung](../new_ui/assets.md).
- Die IDs `resort:0` bis `resort:17` entsprechen den IDs 0–17 der Oberfläche und werden nicht umsortiert.
- Fehlt die Regel in einer Modern-Welt, gilt die öffentliche Vorgabe `assets/modern/rules/training_camps.json` mit den 18 fiktiven Lagern.
- Fehlt die Regel in einer Modern-Welt, gilt die in die Engine eingebaute Vorgabe (`src/modern/game/training_camps.cpp`) mit den 18 fiktiven Lagern.
- **Editor:** Kartenliste und Lager bearbeiten: Karte (Pflicht), `x`/`y` (leer erlaubt, solange die Karte keine Maße hat), vier Qualitätswerte (0–6), Preis, Ort, Land und optionales datensatzspezifisches Bild. Prüfung auf eindeutige IDs, gültige Karte und Nation, Qualitäten im Bereich, auflösbare explizite Bildreferenzen und Koordinaten innerhalb der Kartenmaße, sobald diese gesetzt sind. Ein fehlendes `image` ist kein Fehler; feste GUI-Motive müssen nicht in den Datensatz kopiert werden.
## F5 · Namen
@@ -106,6 +107,14 @@ Die bestehende Regel `rule:training-camps` (Typ `training_camps`) bleibt und wir
- Modern-Spielstände sind `.obs` mit `save_profile: modern-career-v1`; Aufbau wie Classic-Spielstände (`state/…`, Integritätsdatei), aber mit dem Modern-Zustand und den Dimensionen der Welt.
- **Editor:** öffnet keine Spielstände; keine Änderung.
## F9 · Schiedsrichter
- Heute kommen die 49 Schiedsrichter (plus Platzhalter 0) aus der Original-Datenbank: Namen im Namenspool, je ein Eigenschaftsbyte (`RefereeProperties`). Pro Spieltag erhält jedes Spiel einen noch freien Schiedsrichter. Mit den vergrößerten internationalen Ligen gibt es Tage mit bis zu 84 Ligaspielen; die Engine lässt deshalb vorübergehend Doppeleinsätze zu.
- Geplant für Datenrevision 1.4: Die Welt führt Schiedsrichter als `staff`-Zeilen mit `role: referee`, Name (Vor- und Nachname), Nation und `x-legacy.referee_index` für die Originale. Neu ist ein Eigenschaftswert `strictness` (0–255, Bedeutung wie das Original-Eigenschaftsbyte).
- Empfehlung: mindestens 100 Schiedsrichter, damit auch Tage mit Pokalspielen ohne Doppeleinsatz auskommen.
- **Engine (mit M5):** Poolgröße aus der Welt statt fest 49; Eigenschaften und Namen aus den `staff`-Zeilen; Doppeleinsatz nur noch als Rückfall, wenn der Pool trotzdem erschöpft ist.
- **Editor:** Schiedsrichterliste anzeigen und bearbeiten (Name, Nation, Strenge), neue Schiedsrichter anlegen; Prüfung auf eindeutige IDs und Strenge im Bereich.
## Modern-Prüfung (Engine und Editor)
Eine Welt ist als Modern-Welt spielbar, wenn:
+12 -1
View File
@@ -38,6 +38,17 @@ Referenz aus M0.
**Abnahme:** Der Modern-Datensatz startet eine Karriere mit einem deutschen Verein; Kader, Namen und Ligen stimmen mit den Welttabellen überein.
**Umsetzung (Stand 24. Oktober 2026):**
- `src/modern/content/world.*`: typisierte Sicht auf die Welttabellen (Ligen, Vereine, Spieler, Nationen, Ligatermine).
- `src/modern/content/world_package.*`: liest aus dem Paket nur, was die Engine braucht (Manifest, Welttabellen, Classic-Nutzdaten, Classic-Grafiken); HD-Wappen und -Porträts bleiben im Archiv. Der Classic-Startzustand entsteht aus den unveränderten `x-classic`/`x-legacy`-Daten.
- `src/modern/content/world_expand.*`: bringt den Classic-Start auf die Welt. Vereins-IDs folgen den Ligamitgliedern (die vergrößerten internationalen Ligen verschieben alle IDs dahinter um 30); Tabellen pro Verein werden umgerechnet, neue Vereine übernehmen die Startwerte eines Originalvereins derselben Liga; neue Spieler erhalten ihre Werte aus den `bmh-classic@1`-Attributen; jeder Ligaverein hat 24 Kaderplätze; die Pools hinter den Kadern (Transferliste, vereinslos, Ausland, Nationalteam, 54 Reservespieler) behalten Inhalt und Reihenfolge.
- Namen und OBW-IDs für die UI liegen in `ModernState` (`world_club_name`, `player_first`, `player_last`, …); die Engine-Texte nutzen weiter die Einzelbyte-Namenspools, in die neue Namen angehängt werden.
- Probelauf: `modern_season_sim <Welt.obw> [Spielzüge] [Verein] [Startwert]`; `MODERN_DEBUG=1` zeigt die Ladeschritte, `MODERN_WATCH=<Sekunden>` meldet regelmäßig den Engine-Schritt (Endlosschleifen finden).
- Ergebnis mit dem Modern-Datensatz 1.3: zwei Saisons, rund 5.300 Spiele; alle Ligen spielen ihre Runden vollständig (deutsche Ligen 34, LaLiga/Premier League/Serie A 38, Ligue 1 34).
- Dabei gefunden und behoben: der Schiedsrichterpool (49) reicht nicht für Tage mit deutschen und vergrößerten internationalen Ligen (Modern-Abweichung), die Fairplay-Tabelle pro Ligaverein ist mitgewachsen, Kaderzuordnung über das Layout statt fester 24/16-Arithmetik.
- Offen für M6: Modern-Spielstände; die Session nutzt übergangsweise die Classic-UI-Projektionen, die dafür auf das Layout umgestellt sind.
## M4 · Trainingslager
Siehe [Trainingslager](trainingslager.md): Katalog aus den Daten, drei Regionen, Qualitätswerte 0–6, unveränderte Preisformel und Aufenthaltsgrenzen, begrenzte 6-Sterne-Wirkung.
@@ -46,7 +57,7 @@ Siehe [Trainingslager](trainingslager.md): Katalog aus den Daten, drei Regionen,
## M5 · Datenrevision 1.4 (privat)
- Neue, nummerierte Migration des Modern-Datensatzes nach dem bestehenden Migrationsvertrag (Eingangs-Hash, Bericht, unabhängige Prüfung, Editor-Roundtrip): `runtime:modern-v1`, spielbar, Trainingslager-Katalog, Kalenderangaben für 38 Spieltage, Finanzangaben auch für die 30 neuen Vereine.
- Neue, nummerierte Migration des Modern-Datensatzes nach dem bestehenden Migrationsvertrag (Eingangs-Hash, Bericht, unabhängige Prüfung, Editor-Roundtrip): `runtime:modern-v1`, spielbar, Trainingslager-Katalog, Kalenderangaben für 38 Spieltage, Finanzangaben auch für die 30 neuen Vereine, ein größerer Schiedsrichter-Pool (mindestens 100, [Datenformat F9](datenformat.md#f9--schiedsrichter)) samt Engine-Anbindung.
- Werkzeug: C++ (`openbmh_world_migrate`) oder das bestehende Migrationswerkzeug der Datenpflege; vor Beginn abstimmen.
**Abnahme:** Prüfbericht ohne Fehler; Editor öffnet und speichert verlustfrei.
+10 -1
View File
@@ -21,7 +21,7 @@ Quelle: `src/game/desk_actions.cpp` (`training_camp_price`, `book_training_camp`
## Modern: Katalog aus den Daten
Der Katalog steht im Modern-Datensatz unter `rules.training_camps`. Fehlt er,
gilt die öffentliche Vorgabe `assets/modern/rules/training_camps.json` mit den
gilt die in die Engine eingebaute Vorgabe (`src/modern/game/training_camps.cpp`) mit den
18 fiktiven Lagern der Oberfläche.
Der Katalog erweitert die bestehende Regel `rule:training-camps` (Liste
@@ -63,6 +63,15 @@ Prüfung in M4 und M7: Ein Spitzenteam, das pro Saison dreimal ein
Schnitt höchstens um etwa einen Tabellenplatz. Andernfalls werden die Punkte 2
und 3 abgeschwächt. Das Ergebnis wird hier und in [DIFFERENCES](../DIFFERENCES.md) festgehalten.
## Umsetzung (M4, Stand 24. Oktober 2026)
- Katalog in `ModernState::camp_maps` und `ModernState::training_camps` (`src/modern/game/training_camps.hpp`); Index = Lager-Index der Buchung.
- Preis, Buchung und Wirkung in `src/modern/game/desk_actions.cpp` (`training_camp_price`, `book_training_camp`, `training_camp_effect`).
- Die 6-Sterne-Regeln sind wie oben umgesetzt: Stufenindex auf das Tabellenende gedeckelt, Leistungsdach +1 ab Platz 5 und +1 bei Platz und Fitness 6, Verpflegung 6 bis +1 Kondition, Unterkunft 6 eine Woche weniger Verletzung.
- Mit Classic-Daten unverändert: Nur die Original-Lager 6 und 7 haben Platz 5, das alte Kriterium „Index ab 6“ trifft dieselben Lager.
- Test: `modern_camp_tests` (Katalog, Deckelung, Verpflegung, Unterkunft).
- Offen: Messung der Saisonwirkung (M7) und die Projektion für die UI (M6).
## Für die Oberfläche
Die Modern-Session liefert Katalog, Buchungsstand (Aufenthalte dieser Saison,
+13
View File
@@ -23,6 +23,19 @@ und womit die UI bis dahin arbeitet.
Der bestehende POC (`modern::Model` mit `Snapshot`, gesichert unter Tag `archive/modern-poc-0.2`) kann weitergeführt werden. Er hängt künftig an der `ModernSession` statt an der Classic-`CareerSession`. Wird der POC übernommen, wandert er nach `src/modern/ui/`.
## Modern-Welt laden (ab M3)
```cpp
auto package = bmh::modern::open_world_package(path); // modern/content/world_package.hpp
bmh::content::Mount mount(path, package.classic); // Original-Datenbereiche unter dem Paketpfad
bmh::modern::set_current_world(package.world); // eine Welt pro Prozess
bmh::modern::app::ModernSession session(path, seed); // erweitert den Start auf die Welt
```
- `ModernState` (`session.state()`) hält pro Laufzeit-Index die UTF-8-Namen und OBW-IDs: `world_club_id`, `world_club_name`, `world_club_short` (pro Verein), `world_player_id`, `player_first`, `player_last`, `player_nation` (pro Spieler). Die Bildschlüssel stehen in der Welt (`current_world()->clubs[...].crest`, Spieler `photo`).
- HD-Bilder liest die UI selbst aus dem Paket; die Engine lädt sie nicht.
- Bis die Projektionen unten fertig sind, liefert die Session noch die Classic-UI-Projektionen; sie sind auf variable Ligagrößen umgestellt.
## Projektionen und Aktionen
| Bereich | Projektion | Aktionen | Ab Phase |
+13
View File
@@ -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;
+2
View File
@@ -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
+11
View File
@@ -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) {
+3
View File
@@ -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).
+5 -1
View File
@@ -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
+4
View File
@@ -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
+12
View File
@@ -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;
+5
View File
@@ -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_;
+190
View File
@@ -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
+75
View File
@@ -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
+415
View File
@@ -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
+39
View File
@@ -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
+81
View File
@@ -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
+32
View File
@@ -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
+3 -3
View File
@@ -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);
+1 -4
View File
@@ -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) {
+28 -7
View File
@@ -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));
+1 -1
View File
@@ -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));
+10 -1
View File
@@ -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());
+17
View File
@@ -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(); }
+1 -1
View File
@@ -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);
}
}
+47
View File
@@ -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
+42
View File
@@ -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
+3 -4
View File
@@ -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;
+2 -1
View File
@@ -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));
+7 -6
View File
@@ -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)) {
+2 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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);
+2 -1
View File
@@ -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
View File
@@ -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);
+8 -7
View File
@@ -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 ||
+4 -3
View File
@@ -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
View File
@@ -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");
+2 -1
View File
@@ -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
View File
@@ -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");
+2 -1
View File
@@ -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);
+4 -3
View File
@@ -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
View File
@@ -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");
+2 -1
View File
@@ -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;
+4 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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))
+103
View File
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: GPL-3.0-only
// Modern training camps (docs/new_engine/trainingslager.md, M4) on a synthetic squad:
// the built-in catalogue, the step cap at six stars, the catering and lodging extras.
#include <cstdio>
#include <set>
#include <string>
#include "game/random.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/training_camps.hpp"
using namespace bmh;
using namespace bmh::modern;
namespace {
int failures = 0;
void check(bool ok, const char* what) {
if (!ok) {
std::fprintf(stderr, "FAIL: %s\n", what);
++failures;
}
}
// Manager 0 coaches club 0 (Classic layout: 24 slots), 20 players, one of them injured.
ModernState squad() {
ModernState g;
g.manager_teams = {0};
g.manager_records.assign(5 * 0xb0c, 0);
g.manager_records[0x290] = 0; // club
for (int u = 0; u < 3; ++u) g.manager_records[0xc1 + size_t(u)] = 15; // focus
g.manager_records[0xc1 + 3] = 0; // recovery = 15 - 45 / 3
g.team_morale.assign(419, 0x10);
g.tactics.assign(4 * 0x840, 0x20);
g.squad_slots.assign(3150, kEmptySlot);
for (int i = 0; i < 20; ++i) {
Player p;
p.w35c = uint32_t(40 + i) | uint32_t(50 + i) << 7 | uint32_t(60 + i) << 14; // form, technique, condition
p.w364 = uint32_t(i % 4) | uint32_t(9) << 21; // raw age 9
g.players.push_back(p);
g.squad_slots[size_t(i)] = uint16_t(i);
}
g.players[3].w364 |= 3u << 16; // injured for three weeks
return g;
}
TrainingCamp camp(std::array<uint8_t, 4> quality) {
TrainingCamp c;
c.id = "resort:test";
c.quality = quality;
c.base_price = 100000;
return c;
}
ModernState after_camp(std::array<uint8_t, 4> quality, uint32_t seed) {
ModernState g = squad();
g.training_camps = {camp(quality)};
WatcomRandom rand(seed);
training_camp_effect(g, 0, 0, rand);
return g;
}
} // namespace
int main() {
const CampCatalogue& d = default_camp_catalogue();
check(d.camps.size() == 18 && d.maps.size() == 3, "18 camps on three maps");
std::set<std::string> ids, maps;
int six_star = 0;
for (const auto& m : d.maps) maps.insert(m.id);
for (const auto& c : d.camps) {
ids.insert(c.id);
check(maps.count(c.map) == 1, "every camp is on a known map");
check(!c.x && !c.y, "positions stay open until the interface sets them");
for (const uint8_t q : c.quality) check(q <= 6, "grades 0-6");
six_star += c.quality == std::array<uint8_t, 4>{6, 6, 6, 6};
}
check(ids.size() == 18 && ids.count("resort:0") && ids.count("resort:17"), "ids resort:0-17");
check(six_star == 3, "three six-star camps (Middle East)");
for (uint32_t seed = 1; seed <= 20; ++seed) {
// Six stars with full focus would index beyond the step table without the cap.
const ModernState top = after_camp({6, 6, 6, 6}, seed);
for (int i = 0; i < 20; ++i)
check(top.players[size_t(i)].technique() <= 99 && top.players[size_t(i)].condition() <= 99,
"values stay within 0-99");
// Catering 6 adds exactly one point of condition to the same draws.
const ModernState five = after_camp({5, 5, 5, 5}, seed);
const ModernState catering = after_camp({5, 5, 6, 5}, seed);
for (int i = 0; i < 20; ++i) {
const int a = five.players[size_t(i)].condition(), b = catering.players[size_t(i)].condition();
check(b == std::min(a + 1, 99), "catering 6: one more point of condition");
check(five.players[size_t(i)].technique() == catering.players[size_t(i)].technique(),
"catering does not change technique");
}
check((catering.team_morale[0] & 0x3f) == std::min(0x10 + 14, 0x2f) &&
(five.team_morale[0] & 0x3f) == 0x10 + 12, "morale +14 at six stars, +12 at five");
// Lodging 6 shortens the injury by one week; five stars leave it.
check((after_camp({5, 5, 5, 6}, seed).players[3].w364 >> 16 & 0x1f) == 2, "lodging 6: one week less injury");
check((five.players[3].w364 >> 16 & 0x1f) == 3, "lodging 5: injury unchanged");
}
if (failures) return 1;
std::puts("modern camp checks passed");
return 0;
}
+36 -1
View File
@@ -19,6 +19,11 @@
#include <string>
#include "modern/app/modern_session.hpp"
#include "modern/content/world_package.hpp"
#include <chrono>
#include <memory>
#include <thread>
#include "game/trace.hpp"
#include "modern/game/desk_actions.hpp"
#include "game/lineup.hpp"
#include "modern/game/matchday.hpp"
@@ -142,6 +147,16 @@ void check_results(const TurnResultSnapshot& r, const std::string& when, Checks&
} // namespace
int main(int argc, char** argv) {
// MODERN_WATCH=seconds: report the engine step periodically (finding endless loops).
if (const char* watch = std::getenv("MODERN_WATCH")) {
const int seconds = std::max(1, std::atoi(watch));
std::thread([seconds] {
for (;;) {
std::this_thread::sleep_for(std::chrono::seconds(seconds));
std::fprintf(stderr, "watch: %s (club %d)\n", bmh::turn_step.load(), bmh::turn_team.load());
}
}).detach();
}
if (argc < 2) {
std::printf("usage: season_sim <BMH data dir> [turns] [master club] [watcom seed] [strength]\n");
return 2;
@@ -151,6 +166,13 @@ int main(int argc, char** argv) {
std::string gap;
int played = 0, goals = 0, matches = 0, seasons = 0;
try {
// A Modern world package (.obw) is opened, mounted and expanded by the session.
std::unique_ptr<content::Mount> mount;
if (std::string(argv[1]).size() > 4 && std::string(argv[1]).substr(std::string(argv[1]).size() - 4) == ".obw") {
auto package = modern::open_world_package(argv[1]);
mount = std::make_unique<content::Mount>(argv[1], package.classic);
modern::set_current_world(package.world);
}
modern::app::ModernSession session(argv[1], argc > 4 ? uint32_t(std::stoul(argv[4])) : 1u);
ui::SetupOptions options; // 5 seasons, level 2, one manager, mode III, league and world
ui::ManagerChoice choice;
@@ -158,6 +180,12 @@ int main(int argc, char** argv) {
choice.master_club = argc > 3 ? std::atoi(argv[3]) : 0;
choice.strength = argc > 5 ? std::atoi(argv[5]) : 2;
std::string error;
if (modern::current_world()) {
const auto& r = session.world_report();
std::printf("modern world: %d league clubs (%d added), %d added players, %d free agents, %d fallback nationalities\n",
r.league_clubs, r.added_clubs, r.added_players, r.free_agents, r.fallback_nationalities);
for (const auto& note : r.notes) std::printf(" league date moved: %s\n", note.c_str());
}
if (!session.confirm_manager(options, choice, error)) throw std::runtime_error("manager: " + error);
ui::CareerInitializationResult init;
if (!session.finish(init, error)) throw std::runtime_error("career start: " + error);
@@ -327,6 +355,12 @@ int main(int argc, char** argv) {
modern::table_position(g, g.manager_teams.at(0)), money(g, 0));
if (r.kind == TurnDeskKind::SeasonEndDesk) {
print_first_league_results(g, "season end");
if (modern::current_world()) { // rounds played per league against its matchdays
std::printf("season end rounds:");
for (int l = 0; l < kLeagueCount; ++l)
std::printf(" %d:%d/%d", l, int(g.league_rounds.at(size_t(l))), league_matchdays(l));
std::printf("\n");
}
++seasons;
} // (the next kickoff runs the season change)
}
@@ -353,6 +387,7 @@ int main(int argc, char** argv) {
if (matches >= 500 && (double(goals) / matches < 2.0 || double(goals) / matches > 4.0))
checks.fail("goals per match outside 2.0-4.0", std::to_string(double(goals) / matches));
for (const auto& [kind, n] : checks.counts) std::printf("VIOLATION %-32s %4d x, first: %s\n", kind.c_str(), n, checks.first[kind].c_str());
if (!gap.empty()) std::printf("STOPPED: %s\n", gap.c_str());
if (!gap.empty())
std::printf("STOPPED: %s (engine step: %s, club %d)\n", gap.c_str(), bmh::turn_step.load(), bmh::turn_team.load());
return !gap.empty() ? 2 : checks.counts.empty() ? 0 : 1;
}
+53
View File
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0-only
// modern_world_info <world.obw> - opens a Modern world package and prints its leagues, clubs
// and players (docs/new_engine, M3). Exit code 0 when the package opens, 1 otherwise.
#include <cstdio>
#include <exception>
#include <map>
#include "modern/content/world_package.hpp"
int main(int argc, char** argv) {
if (argc != 2) {
std::fprintf(stderr, "usage: modern_world_info WORLD.obw\n");
return 2;
}
try {
const auto package = bmh::modern::open_world_package(argv[1]);
const auto& w = *package.world;
std::printf("world %s, revision %s, start %s, content %s\n", w.id.c_str(),
w.data_revision.empty() ? "-" : w.data_revision.c_str(), w.start_date.c_str(),
package.classic->content_id.c_str());
int league_clubs = 0;
for (const auto& l : w.leagues) {
int added = 0;
for (const auto& m : l.members)
if (const auto* c = w.club(m); c && c->legacy_index < 0) ++added;
std::printf("league %d %-28s %2zu clubs (%d added), %s, %zu dates\n", l.index, l.name.c_str(),
l.members.size(), added, l.generator.c_str(), l.dates.size());
league_clubs += int(l.members.size());
}
int legacy = 0, without_team = 0, coded = 0;
std::map<std::string, int> squads;
for (const auto& p : w.players) {
legacy += p.legacy;
if (p.team.empty()) ++without_team;
else ++squads[p.team];
coded += w.nationality.count(p.nation) && w.nationality.at(p.nation) < 32;
}
int largest = 0, smallest = 99;
for (const auto& l : w.leagues)
for (const auto& m : l.members) {
const int n = squads.count(m) ? squads.at(m) : 0;
largest = std::max(largest, n);
smallest = std::min(smallest, n);
}
std::printf("%d league clubs, %zu clubs in all; %zu players (%d original, %d without club, "
"%d with a Classic nationality code); league squads %d-%d\n",
league_clubs, w.clubs.size(), w.players.size(), legacy, without_team, coded, smallest, largest);
return 0;
} catch (const std::exception& e) {
std::fprintf(stderr, "cannot open world: %s\n", e.what());
return 1;
}
}