From 4639fe5a91a29248306a25faf453dad4588032b3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 24 Oct 2026 10:52:44 +0200 Subject: [PATCH] Add the base read queries for the new UI; fix ages and save limits - ModernSession::read(request): status, leagues, table, fixtures and squad as JSON with the same club/player/league objects everywhere (docs/new_engine/ui-abfragen.md); the statistics answer through it. Further queries follow per menu once the GUI is finished. - Ages: data set 1.3 gives ages only for the 840 added players (birth dates); the 2574 original players carry the placeholder 16 and now get their age drawn as in the original (human squad 20-25) instead of all being 16. Birth dates for all players go into data 1.4. - Saves of Modern matchdays with more than six match groups (nine leagues on one day) were refused on loading; Classic keeps six. Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 3 +- docs/new_engine/balance.md | 2 +- docs/new_engine/phasen.md | 1 + docs/new_engine/ui-abfragen.md | 36 +++++ src/content/save.cpp | 6 +- src/modern/app/modern_session.hpp | 6 + src/modern/content/projections.cpp | 242 ++++++++++++++++++++++++++++ src/modern/content/projections.hpp | 21 +++ src/modern/content/world_expand.cpp | 4 + src/modern/game/career.cpp | 11 +- src/modern/game/modern_state.hpp | 8 + tests/modern_season_sim.cpp | 12 ++ 12 files changed, 344 insertions(+), 8 deletions(-) create mode 100644 docs/new_engine/ui-abfragen.md create mode 100644 src/modern/content/projections.cpp create mode 100644 src/modern/content/projections.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ba5c3..82adaaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,7 +345,8 @@ add_subdirectory(src/import) add_library(bmh_modern_content STATIC src/modern/content/world.cpp src/modern/content/world_package.cpp src/modern/content/world_save.cpp src/modern/content/world_expand.cpp - src/modern/content/statistics.cpp) + src/modern/content/statistics.cpp + src/modern/content/projections.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) diff --git a/docs/new_engine/balance.md b/docs/new_engine/balance.md index df03a84..8b76a9f 100644 --- a/docs/new_engine/balance.md +++ b/docs/new_engine/balance.md @@ -32,7 +32,7 @@ Messwerkzeug: `MODERN_SPREAD=1 modern_season_sim 1 0 1` zeigt die Ver Das Original würfelt beim Start auch das Alter (20–32, der Verein des Menschen 20–25) und die sieben Fähigkeiten (Teamplay, Tempo, Schuss, Passspiel, Zweikampf, Freistoß, Ecke; je 0–3) neu. -- **Alter:** Datensatzspieler behalten ihr Alter (`new_career_players`, `career_add_manager`). +- **Alter:** Datensatzspieler behalten ihr Alter, wenn der Datensatz eines liefert (Geburtsdatum; `world_age_known`, `new_career_players`, `career_add_manager`). Im Datensatz 1.3 haben das nur die 840 ergänzten Spieler; die 2.574 Originalspieler stehen auf dem Platzhalter 16 und bekommen ihr Alter wie im Original gewürfelt (Kader des Menschen 20–25). Echte Alter für alle brauchen Geburtsdaten im Datensatz (Aufgabe für 1.4). - **Fähigkeiten:** Der Datensatz 1.3 hat keine (alle 0, auch `x-legacy.skill_word`). Sie werden daher wie im Original gewürfelt (Mittel 1,5); nur Fähigkeiten, die ein Datensatz liefert (nicht alle 0), bleiben. Ein erster Versuch, sie zu „behalten“, ließ alle Spieler ohne Fähigkeiten spielen: 0,1–0,5 Tore pro Spiel weniger in jedem Wettbewerb. Tore pro Spiel je Wettbewerb (zwei Saisons, Seed 1): diff --git a/docs/new_engine/phasen.md b/docs/new_engine/phasen.md index acdfbff..2c75a5e 100644 --- a/docs/new_engine/phasen.md +++ b/docs/new_engine/phasen.md @@ -69,6 +69,7 @@ Siehe [Trainingslager](trainingslager.md): Katalog aus den Daten, drei Regionen, 2. Trainingslager: Regel `rule:training-camps` mit `maps` (Deutschland, Europa, Naher Osten) und den 18 Lagern aus `docs/new_ui/desktop/trainingcamp` nach [F4](datenformat.md#f4--trainingslager); `x`/`y` bleiben `null`. Vorlage für Werte und IDs (`resort:0..17`): `default_camp_catalogue()` in `src/modern/game/training_camps.cpp`. 3. Schiedsrichter: mindestens 50 neue `staff`-Zeilen (`role: referee`, ohne `x-legacy`) nach [F9](datenformat.md#f9--schiedsrichter), fiktive Namen, `attributes.strictness` und `attributes.perception` je 0–3 ähnlich verteilt wie bei den 49 Originalen (`x-legacy.property`: Bits 3–4 bzw. 0–1). 4. Stabile IDs: Vereins-, Spieler- und Schiedsrichter-IDs aus 1.3 unverändert lassen (der Almanach und die Spielstände beziehen sich darauf). +4a. Geburtsdaten auch für die 2.574 Originalspieler (heute Platzhalter-Alter 16). Die Engine übernimmt das Alter dann beim Karrierestart, statt es zu würfeln ([Balance](balance.md)). 5. Bericht, Prüfung und Editor-Roundtrip wie bei 1.3; Eintrag in `DIAMOND_MIGRATIONS.md`. Danach: `modern_season_sim` mit der neuen Welt (zwei Saisons, `SIM_CONTRACTS=1`) muss ohne Doppeleinsätze von Schiedsrichtern und mit den 18 Lagern laufen; das prüfe ich. diff --git a/docs/new_engine/ui-abfragen.md b/docs/new_engine/ui-abfragen.md new file mode 100644 index 0000000..90aba35 --- /dev/null +++ b/docs/new_engine/ui-abfragen.md @@ -0,0 +1,36 @@ +# Abfragen für die neue Oberfläche (M6) + +Michaels Entscheidung: Die neue Oberfläche wird **je Menü** an die Modern-Engine angebunden. Jedes Menü bekommt feste Abfragen (und später Aktionen), die die Engine baut und hier dokumentiert; Codex stellt Menü für Menü vom Demo auf die Abfrage um. Die Demo bleibt nutzbar. + +**Reihenfolge (Michael):** Zuerst wird die GUI mit Demodaten fertig gebaut. Danach legt Codex je Menü fest, welche Daten es braucht, und die Engine liefert die passende Abfrage. Später soll alles auf ein durchgehendes JSON-Format umgestellt werden; die Antworten verwenden deshalb schon jetzt überall dieselben Teilobjekte, damit sie sich zu einem gemeinsamen JSON-Zustand zusammensetzen lassen. + +## Vertrag + +- Einstieg: `ModernSession::read(request)`, Anfrage und Antwort sind JSON (`cli::Json`). Die Antwort ist `{ok: true, …}` oder `{ok: false, error}`. +- Nur lesend: keine Zufallszahlen, keine Änderung am Spiel, keine neue Revision. +- Abfragen für den Manager am Schreibtisch (`ActiveManager`). +- Gemeinsame Teilobjekte (in allen Antworten gleich): + - `club`: `{id, name, short}` (Welt-ID, UTF-8) + - `player`: `{id, name}` (stabile Spieler-ID, Vor- und Nachname) + - `league`: `{index, id, name}` + - Datum ISO `YYYY-MM-DD`, Saison `"2026/27"`, Geld in Euro als ganze Zahl. + +## Grundabfragen (Stand 24.10.2026) + +| Anfrage | Antwort | +|---|---| +| `{kind: "status"}` | `manager {index, name}`, `club` (oder `null`, z. B. am Bundestrainer-Schreibtisch), `league`, `place`, `date`, `season`, `money` | +| `{kind: "leagues"}` | `leagues: [{index, id, name, clubs, matchdays, played}]` | +| `{kind: "table", league}` | `league`, `played`, `rows: [{rank, club, played, won, drawn, lost, goals_for, goals_against, points}]` (aktueller Stand, mit Punktabzug) | +| `{kind: "fixtures", league, matchday?}` | `league`, `matchday`, `matches: [{home, away, result: [h, a] \| null, status: open \| played \| postponed}]`; ohne `matchday` der nächste | +| `{kind: "squad", club?}` | `club`, `players: [{slot, player, nation, position (gk/def/mid/fwd), age, technique, condition, form, strength, skills {teamplay, speed, shooting, passing, tackling, free_kick, corner}, lineup (start/bench/none), injured_weeks, banned_weeks}]`; ohne `club` der eigene Verein, sonst Welt-ID oder Laufzeitindex | +| `competitions`, `winners`, `player_stats` | siehe [Spielstatistik](statistik.md) | + +`league` darf der Ligaindex (0–8) oder die Liga-ID der Welt sein. Fehler: `invalid_request`, `invalid_manager`, `invalid_league`, `invalid_matchday`, `invalid_club`, `unavailable`. + +Code: `src/modern/content/projections.hpp/.cpp`. Prüfen: `MODERN_STATS=1 modern_season_sim 20 0 1` zeigt Beispielanfragen und Antworten. + +## Nächste Schritte + +- Je Menü der fertigen GUI: Codex nennt die benötigten Felder (am einfachsten als Beispiel-JSON aus der Demo), die Engine baut die Abfrage, beide Seiten testen gegen dasselbe Beispiel. +- Aktionen (`ModernSession::apply`) nach demselben Muster, mit Revision wie bei den bestehenden Desk-Aktionen. diff --git a/src/content/save.cpp b/src/content/save.cpp index fd6562a..5c7eb05 100644 --- a/src/content/save.cpp +++ b/src/content/save.cpp @@ -2,6 +2,7 @@ #include "content/save.hpp" #include "import/detail.hpp" #include "game/save.hpp" +#include "game/world_layout.hpp" #include #include #include @@ -107,7 +108,10 @@ J groups_json(const std::vector &groups) { std::vector groups_json(const J &j) { std::vector groups; const auto &rows = arr(j); - if (rows.size() > 6) + // The original has six group descriptors. A Modern world plays more competitions on one + // day (nine leagues and the cups); its groups beyond the sixth live in the turn driver. + const size_t max_groups = world_layout().league_teams == classic_world_layout().league_teams ? 6 : 16; + if (rows.size() > max_groups) fail("too many match groups"); for (const auto &row : rows) groups.push_back(group_json(row)); diff --git a/src/modern/app/modern_session.hpp b/src/modern/app/modern_session.hpp index 2a6bcce..a76c80b 100644 --- a/src/modern/app/modern_session.hpp +++ b/src/modern/app/modern_session.hpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #pragma once +#include "modern/content/projections.hpp" #include "modern/content/statistics.hpp" #include "modern/content/world_expand.hpp" // The engine side of the UI's career handoff (src/ui/flow.hpp, ENGINE_BINDING.md). @@ -817,6 +818,11 @@ public: // The game statistics menu (docs/new_engine/statistik.md): winners by season, player // statistics per competition. Read-only; answers {ok, ...} or {ok: false, error}. cli::Json read_statistics(const cli::Json& request) const { return query_statistics(g_, request); } + // The read queries of the new interface (docs/new_engine/ui-abfragen.md): status, leagues, + // table, fixtures, squad and the statistics, for the manager at the desk. Read-only. + cli::Json read(const cli::Json& request) const { + return query_projection(g_, int(g_.memory.has(::bmh::layout::ActiveManager) ? g_.memory.u8(::bmh::layout::ActiveManager) : 0), request); + } ModernState& state() { return g_; } const TurnResultSnapshot& last_turn_results() const { return turn_driver_.last_results; } // Owned presentation for the event completed by the last accepted kickoff. diff --git a/src/modern/content/projections.cpp b/src/modern/content/projections.cpp new file mode 100644 index 0000000..3a57258 --- /dev/null +++ b/src/modern/content/projections.cpp @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/content/projections.hpp" + +#include +#include +#include +#include +#include + +#include "game/schedule.hpp" +#include "game/table.hpp" +#include "modern/content/statistics.hpp" +#include "modern/game/almanac.hpp" +#include "modern/game/matchday.hpp" + +namespace bmh::modern { + +namespace { + +using J = cli::Json; +using A = J::Array; +using O = J::Object; + +constexpr size_t kRecord = 0xb0c; +constexpr size_t kResultsPerLeague = 0x17c; // 38 rounds x 10 matches + +J error(const char* code) { return O{{"ok", false}, {"error", code}}; } + +const J* field(const J& request, const char* key) { + const auto* o = request.object(); + if (!o) return nullptr; + const auto it = o->find(key); + return it == o->end() ? nullptr : &it->second; +} + +const std::string& entry(const std::vector& v, size_t i) { + static const std::string none; + return i < v.size() ? v[i] : none; +} + +// The forms shared by every answer (the parts of a later complete JSON state): +// club {id, name, short}, player {id, name}, league {index, id, name}. +J club_json(const ModernState& g, int team) { + std::string id = entry(g.world_club_id, size_t(team)), name = entry(g.world_club_name, size_t(team)), + short_name = entry(g.world_club_short, size_t(team)); + if (id.empty()) id = "team:" + std::to_string(team); + if (name.empty()) name = almanac_utf8(g.club_name(team)); + if (short_name.empty()) short_name = name; + return O{{"id", id}, {"name", name}, {"short", short_name}}; +} + +std::string player_name(const ModernState& g, int player) { + const std::string& first = entry(g.player_first, size_t(player)); + std::string last = entry(g.player_last, size_t(player)); + if (last.empty()) last = almanac_utf8(g.player_name(player)); + return first.empty() ? last : first + " " + last; +} + +J league_json(const ModernState& g, int league) { + std::string id = entry(g.world_league_id, size_t(league)), name = entry(g.world_league_name, size_t(league)); + if (id.empty()) id = "league:" + std::to_string(league); + if (name.empty()) name = "Liga " + std::to_string(league + 1); + return O{{"index", league}, {"id", id}, {"name", name}}; +} + +// A league by index (number) or by the world's league id (string); -1 if unknown. +int league_of_request(const ModernState& g, const J* value) { + if (!value) return -1; + if (value->integer()) { + const int64_t l = *value->integer(); + return l >= 0 && l < kLeagueCount ? int(l) : -1; + } + if (value->string()) { + for (int l = 0; l < kLeagueCount; ++l) + if (std::get(league_json(g, l).value).at("id").string() && + *std::get(league_json(g, l).value).at("id").string() == *value->string()) + return l; + } + return -1; +} + +std::string iso_date(const ModernState& g) { + const AlmanacDate d = almanac_date(g.date, g.display_start_year); + char out[16]; + std::snprintf(out, sizeof out, "%04d-%02d-%02d", d.year, d.month, d.day); + return out; +} + +std::string season_label(const ModernState& g) { + const int start = g.display_start_year + g.season, next = (start + 1) % 100; + return std::to_string(start) + "/" + (next < 10 ? "0" : "") + std::to_string(next); +} + +int32_t money_of(const ModernState& g, int manager) { + const size_t at = size_t(manager) * kRecord + 0x314; + if (at + 3 >= g.manager_records.size()) return 0; + return int32_t(uint32_t(g.manager_records[at]) | uint32_t(g.manager_records[at + 1]) << 8 | + uint32_t(g.manager_records[at + 2]) << 16 | uint32_t(g.manager_records[at + 3]) << 24); +} + +std::string manager_name(const ModernState& g, int manager) { + std::string name; + const size_t at = size_t(manager) * kRecord + 0xa8; + for (size_t i = 0; i < 30 && at + i < g.manager_records.size() && g.manager_records[at + i]; ++i) + name.push_back(char(g.manager_records[at + i])); + return almanac_utf8(name); +} + +J status(const ModernState& g, int manager) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return error("invalid_manager"); + const int team = g.manager_teams[size_t(manager)]; + O out{{"ok", true}, {"manager", O{{"index", manager}, {"name", manager_name(g, manager)}}}, + {"date", iso_date(g)}, {"season", season_label(g)}, {"money", int64_t(money_of(g, manager))}}; + if (team >= 0 && team < league_clubs()) { + const int league = team_league(team); + out["club"] = club_json(g, team); + out["league"] = league_json(g, league); + out["place"] = int(table_position(g, team)) + 1; + } else { + out["club"] = nullptr; // e.g. at the national coach's desk + } + return out; +} + +J leagues(const ModernState& g) { + A out; + for (int l = 0; l < kLeagueCount; ++l) { + J league = league_json(g, l); + auto& o = std::get(league.value); + o["clubs"] = int(kLeagueSizes[l]); + o["matchdays"] = league_matchdays(l); + o["played"] = l < int(g.league_rounds.size()) ? int(g.league_rounds[size_t(l)]) : 0; + out.push_back(std::move(league)); + } + return O{{"ok", true}, {"leagues", std::move(out)}}; +} + +J table(const ModernState& g, int league) { + const int played = league < int(g.league_rounds.size()) ? int(g.league_rounds[size_t(league)]) : 0; + const LeagueTable t = compute_league_table(g, league, 0, played, 7, 1); + const int first = league_first_team(league); + std::vector order(size_t(t.size)); + for (int i = 0; i < t.size; ++i) order[size_t(i)] = i; + std::stable_sort(order.begin(), order.end(), [&](int a, int b) { return t.rank(a) < t.rank(b); }); + A rows; + for (int i : order) { + const int games = t.games(i), won = t.wins[size_t(i)], lost = t.defeats[size_t(i)]; + rows.push_back(O{{"rank", t.rank(i) + 1}, {"club", club_json(g, first + i)}, {"played", games}, {"won", won}, + {"drawn", std::max(0, games - won - lost)}, {"lost", lost}, + {"goals_for", int(t.goals_for[size_t(i)])}, {"goals_against", int(t.goals_against[size_t(i)])}, + {"points", int(t.points[size_t(i)])}}); + } + return O{{"ok", true}, {"league", league_json(g, league)}, {"played", played}, {"rows", std::move(rows)}}; +} + +J fixtures(const ModernState& g, int league, int matchday) { + const int matchdays = league_matchdays(league); + if (matchday < 1 || matchday > matchdays) return error("invalid_matchday"); + A out; + const auto fx = league_fixtures(league, matchday); + for (size_t m = 0; m < fx.size(); ++m) { + const size_t at = size_t(league) * kResultsPerLeague + size_t(matchday - 1) * 10 + m; + const uint8_t r = at < g.results.size() ? g.results[at] : kNotPlayed; + O match{{"home", club_json(g, fx[m].home)}, {"away", club_json(g, fx[m].away)}}; + if (r == kNotPlayed) { + match["result"] = nullptr, match["status"] = "open"; + } else if (r == 0xcd) { + match["result"] = nullptr, match["status"] = "postponed"; + } else { + match["result"] = A{J(int(r >> 4)), J(int(r & 0xf))}, match["status"] = "played"; + } + out.push_back(std::move(match)); + } + return O{{"ok", true}, {"league", league_json(g, league)}, {"matchday", matchday}, {"matches", std::move(out)}}; +} + +J squad(const ModernState& g, int team) { + if (team < 0 || team >= league_clubs()) return error("invalid_club"); + static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"}; + static constexpr const char* kSkills[7] = {"teamplay", "speed", "shooting", "passing", "tackling", "free_kick", "corner"}; + A players; + const SquadRange r = squad_range(team); + for (size_t s = r.first; s < r.first + r.count; ++s) { + const uint16_t e = g.squad_slots.at(s); + const int id = e & 0x0fff; + if (id == 0x0fff) continue; + const Player& p = g.players.at(size_t(id)); + O skills; + for (int k = 0; k < 7; ++k) skills[kSkills[k]] = int(p.w368 >> (2 * k) & 3); + std::string pid = entry(g.world_player_id, size_t(id)); + if (pid.empty()) pid = "player:legacy-" + std::to_string(id); + const uint32_t absence = p.w364 >> 16 & 0x1f; // weeks out; bit 4: banned instead of injured + players.push_back(O{{"slot", int(s - r.first)}, {"player", O{{"id", pid}, {"name", player_name(g, id)}}}, + {"nation", entry(g.player_nation, size_t(id))}, {"position", kPositions[p.position()]}, + {"age", p.age()}, {"technique", p.technique()}, {"condition", p.condition()}, + {"form", p.form()}, {"strength", p.strength()}, {"skills", std::move(skills)}, + {"lineup", (e & 0x8000) ? "start" : (e & 0x4000) ? "bench" : "none"}, + {"injured_weeks", (absence & 0x10) ? 0 : int(absence)}, + {"banned_weeks", (absence & 0x10) ? int(absence & 0xf) : 0}}); + } + return O{{"ok", true}, {"club", club_json(g, team)}, {"players", std::move(players)}}; +} + +} // namespace + +cli::Json query_projection(const ModernState& g, int manager, const cli::Json& request) { + const J* kind = field(request, "kind"); + if (!kind || !kind->string()) return error("invalid_request"); + const std::string& k = *kind->string(); + try { + if (k == "status") return status(g, manager); + if (k == "leagues") return leagues(g); + if (k == "table" || k == "fixtures") { + const int league = league_of_request(g, field(request, "league")); + if (league < 0) return error("invalid_league"); + if (k == "table") return table(g, league); + const J* md = field(request, "matchday"); + if (md && !md->integer()) return error("invalid_request"); + const int played = league < int(g.league_rounds.size()) ? int(g.league_rounds[size_t(league)]) : 0; + // without a matchday: the next one to play (the last one after the season) + return fixtures(g, league, md ? int(*md->integer()) : std::min(played + 1, league_matchdays(league))); + } + if (k == "squad") { + const J* club = field(request, "club"); + int team = manager >= 0 && size_t(manager) < g.manager_teams.size() ? g.manager_teams[size_t(manager)] : -1; + if (club) { + team = -1; + if (club->integer()) team = int(*club->integer()); + else if (club->string()) + for (size_t t = 0; t < g.world_club_id.size(); ++t) + if (g.world_club_id[t] == *club->string()) team = int(t); + } + return squad(g, team); + } + if (k == "competitions" || k == "winners" || k == "player_stats") return query_statistics(g, request); + return error("invalid_request"); + } catch (const std::exception&) { + return error("unavailable"); + } +} + +} // namespace bmh::modern diff --git a/src/modern/content/projections.hpp b/src/modern/content/projections.hpp new file mode 100644 index 0000000..608556b --- /dev/null +++ b/src/modern/content/projections.hpp @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// Read-only queries of the Modern session for the new interface, one per menu +// (docs/new_engine/ui-abfragen.md). Each takes a JSON request with a `kind` and answers +// {ok: true, ...} or {ok: false, error}; none changes the game, draws random numbers or +// moves the revision. The game statistics (statistics.hpp) answer through the same entry. +// +// {kind: "status"} the desk's status bar: club, manager, date, money +// {kind: "leagues"} the leagues with size, matchdays and progress +// {kind: "table", league} a league's current table +// {kind: "fixtures", league, matchday?} a matchday's pairings and results +// {kind: "squad", club?} a squad with names, values and fitness + +#include "cli/json.hpp" +#include "modern/game/modern_state.hpp" + +namespace bmh::modern { + +cli::Json query_projection(const ModernState& g, int manager, const cli::Json& request); + +} // namespace bmh::modern diff --git a/src/modern/content/world_expand.cpp b/src/modern/content/world_expand.cpp index 13eefe1..fb19acb 100644 --- a/src/modern/content/world_expand.cpp +++ b/src/modern/content/world_expand.cpp @@ -305,6 +305,10 @@ ExpandReport expand_to_world(ModernState& g, const World& world) { else ++report.fallback_nationalities; const int age = std::clamp(p.age < 0 ? 24 : p.age, 16, 47); + if (p.age >= 0) { // a birth date: the career start keeps this age (balance.md) + if (g.world_age_known.size() < size_t(next_player)) g.world_age_known.resize(size_t(next_player), false); + g.world_age_known[i] = true; + } 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 | diff --git a/src/modern/game/career.cpp b/src/modern/game/career.cpp index 88c3047..d58bfed 100644 --- a/src/modern/game/career.cpp +++ b/src/modern/game/career.cpp @@ -277,10 +277,11 @@ bool new_career_players(ModernState& g, GameRandom& game, WatcomRandom& rand, Mi if (id == 0x0fff) continue; Player& p = g.players.at(size_t(id)); const uint32_t age = uint32_t(rand.range(4, 0x10)), skills = uint32_t(rand.range(0, 0x3fff)); - // Modern (balance.md): a player of the data set keeps his age; his seven skills are drawn - // as in the original unless the data set gives him some (data sets have none so far). + // Modern (balance.md): a player of the data set keeps the age and the seven skills the + // data set gives him; what it leaves at 0 is drawn as in the original (data set 1.3 has + // ages only for the players it added, skills for nobody). const bool world = keeps_world_values(g, id); - if (!world) p.w364 |= age << 21; + if (!keeps_world_age(g, id)) p.w364 = (p.w364 & ~(0x1fu << 21)) | age << 21; if (!world || (p.w368 & 0x3fff) == 0) p.w368 = (p.w368 & 0xffffc000u) + skills; } for (int slot = int(pool_end_slot() + 24); slot < int(pool_end_slot() + 24) + 0x36; slot++) @@ -600,7 +601,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM for (int i = 0; i < players; i++) { const size_t slot = squad.first + size_t(i); Player& p = g.players.at(size_t(g.squad_slots.at(slot) & 0x0fff)); - if (!keeps_world_values(g, g.squad_slots.at(slot) & 0x0fff)) { // Modern: the data set's age stays + if (!keeps_world_age(g, g.squad_slots.at(slot) & 0x0fff)) { // Modern: an age of the data set stays p.w364 &= ~(0x1fu << 21); p.w364 |= uint32_t(rand.range(4, 9)) << 21; } @@ -619,7 +620,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM const int id = g.squad_slots.at(slot) & 0x0fff; if (id == 0x0fff) continue; Player& p = g.players.at(size_t(id)); - if (!keeps_world_values(g, id)) { // Modern: the data set's age stays + if (!keeps_world_age(g, id)) { // Modern: an age of the data set stays p.w364 &= ~(0x1fu << 21); p.w364 |= uint32_t(rand.range(4, 9)) << 21; } diff --git a/src/modern/game/modern_state.hpp b/src/modern/game/modern_state.hpp index b3daaf9..b1a4e3d 100644 --- a/src/modern/game/modern_state.hpp +++ b/src/modern/game/modern_state.hpp @@ -52,6 +52,9 @@ struct ModernState : GameState { std::vector training_camps; // The football almanac (docs/new_engine/almanach.md): every match of the career. Almanac almanac; + // Players whose age the data set gives (birth date); the others carry a placeholder the + // career start replaces as in the original. Needed only while a career starts (not saved). + std::vector world_age_known; ModernState() { season_hooks = &modern::season_hooks(); } // Takes over a state built by shared code (save loading, career setup). @@ -66,4 +69,9 @@ inline bool keeps_world_values(const ModernState& g, int player) { !g.world_player_id[size_t(player)].starts_with("player:gen-"); } +// A player of the data set whose age it gives (balance.md). +inline bool keeps_world_age(const ModernState& g, int player) { + return keeps_world_values(g, player) && size_t(player) < g.world_age_known.size() && g.world_age_known[size_t(player)]; +} + } // namespace bmh::modern diff --git a/tests/modern_season_sim.cpp b/tests/modern_season_sim.cpp index 93198df..40e536c 100644 --- a/tests/modern_season_sim.cpp +++ b/tests/modern_season_sim.cpp @@ -606,6 +606,18 @@ int main(int argc, char** argv) { ask({{"kind", "player_stats"}, {"competition", g.world_league_id.empty() ? "league:0" : g.world_league_id[0]}, {"sort", "yellow"}, {"limit", 3}}); ask({{"kind", "player_stats"}, {"competition", "x"}, {"sort", "dribbles"}}); + // the read queries of the new interface (docs/new_engine/ui-abfragen.md) + const auto read = [&](const cli::Json::Object& request) { + std::string answer = cli::dump_json(session.read(request)); + if (answer.size() > 8000) answer = answer.substr(0, 8000) + " ..."; + std::printf("read %s\n -> %s\n", cli::dump_json(request).c_str(), answer.c_str()); + }; + read({{"kind", "status"}}); + read({{"kind", "leagues"}}); + read({{"kind", "table"}, {"league", 0}}); + read({{"kind", "fixtures"}, {"league", 0}, {"matchday", 1}}); + read({{"kind", "squad"}}); + read({{"kind", "table"}, {"league", 42}}); } if (std::getenv("SIM_ADVERTISING")) std::printf("%d advertising contracts accepted (SIM_ADVERTISING=1)\n", ad_contracts); if (std::getenv("SIM_CAMP")) std::printf("%d training camp stays (SIM_CAMP=%s)\n", camp_stays, std::getenv("SIM_CAMP"));