From 0046ab90d069070e5eb497293abe0cb9d1c9dde2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 09:53:31 +0100 Subject: [PATCH] Modern: the traffic access has four stages The Modern interface shows four stages for the traffic access, the original has three. A Modern world (WorldLayout::traffic_stages = 4) keeps the condition byte in steps of 64 (64, 128, 192, 255) and offers a build up to stage 3; every stage weighs as one original stage. New careers convert the original start table, older Modern saves are converted on load (traffic_scale). Classic data keeps three stages; the Classic equivalence is unchanged. Also: the live ticker takes the matches from the desk day on. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/modern-engine.yml | 4 +-- CMakeLists.txt | 3 ++ docs/new_engine/balance.md | 9 +++++ docs/new_engine/ui-anbindung.md | 2 +- src/cli/console/windows_money.cpp | 6 +++- src/game/world_layout.hpp | 3 ++ src/modern/app/modern_session.cpp | 14 ++++++-- src/modern/app/modern_session.hpp | 1 + src/modern/content/world_expand.cpp | 1 + src/modern/content/world_save.cpp | 4 ++- src/modern/game/balance_plan.cpp | 3 +- src/modern/game/career.cpp | 3 +- src/modern/game/matchday_setup.cpp | 5 +-- src/modern/game/modern_state.hpp | 3 ++ src/modern/game/month.cpp | 3 +- src/modern/game/traffic.hpp | 51 +++++++++++++++++++++++++++++ src/modern/game/weekly.cpp | 7 ++-- tests/modern_traffic_tests.cpp | 48 +++++++++++++++++++++++++++ 18 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 src/modern/game/traffic.hpp create mode 100644 tests/modern_traffic_tests.cpp diff --git a/.github/workflows/modern-engine.yml b/.github/workflows/modern-engine.yml index 39d0ef0..04a2915 100644 --- a/.github/workflows/modern-engine.yml +++ b/.github/workflows/modern-engine.yml @@ -54,9 +54,9 @@ jobs: - name: Configure without game data run: cmake -S . -B build-engine -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA= - name: Compile the Modern console, simulator and engine tests - run: cmake --build build-engine --target openbmh_modern_cli modern_season_sim modern_world_info modern_camp_tests modern_almanac_tests modern_toto_tests modern_calendar_tests --parallel 2 + run: cmake --build build-engine --target openbmh_modern_cli modern_season_sim modern_world_info modern_camp_tests modern_almanac_tests modern_toto_tests modern_calendar_tests modern_traffic_tests --parallel 2 - name: Run the data-free Modern engine tests - run: ctest --test-dir build-engine -R "^modern_(camp|almanac|toto|calendar)_tests$" --output-on-failure --output-junit modern-engine-results.xml + run: ctest --test-dir build-engine -R "^modern_(camp|almanac|toto|calendar|traffic)_tests$" --output-on-failure --output-junit modern-engine-results.xml - name: Upload test report if: always() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 067f254..760dccd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1220,6 +1220,9 @@ add_executable(modern_toto_tests tests/modern_toto_tests.cpp) target_link_libraries(modern_toto_tests PRIVATE bmh_season_modern) add_test(NAME modern_toto_tests COMMAND modern_toto_tests) +add_executable(modern_traffic_tests tests/modern_traffic_tests.cpp) +target_link_libraries(modern_traffic_tests PRIVATE bmh_season_modern) +add_test(NAME modern_traffic_tests COMMAND modern_traffic_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) diff --git a/docs/new_engine/balance.md b/docs/new_engine/balance.md index a1bba42..67f4561 100644 --- a/docs/new_engine/balance.md +++ b/docs/new_engine/balance.md @@ -115,6 +115,15 @@ Ergebnis: keine Prüfverletzung, keine Fehler bei Verträgen, Werbung und Lagern Keine Regeländerung nötig. +## Stadion: Verkehrsanbindung mit vier Stufen + +Die Modern-Oberfläche zeigt für die Verkehrsanbindung vier Ausbaustufen, das Original hat drei (Zustandsbyte in Schritten von 0x55: 85, 170, 255; Angebot unter 171). In einer Modern-Welt (`WorldLayout::traffic_stages = 4`) gilt deshalb (`src/modern/game/traffic.hpp`, 27.10.2026): + +- Schritte von 64: Stufe 1–4 bei 64, 128, 192, 255; ein Ausbau wird bis Stufe 3 angeboten. Jeder Ausbau kostet wie im Original (Grundpreis 2,5 Mio. €, 45 Tage). +- Jede Stufe wirkt wie eine Original-Stufe (Einnahmen je Zuschauer, Monatseinnahmen, Zuschauerstufe von 25.000); die vierte Stufe ist ein zusätzlicher Schritt. +- Neue Karrieren starten mit der Stufe der Original-Starttabelle; ältere Modern-Spielstände werden beim Laden in die neue Skala umgerechnet (`traffic_scale` in `state/modern.json`). +- Mit Classic-Daten bleibt es bei drei Stufen (Gleichheitstest unverändert). Test: `modern_traffic_tests`. + ## Offen - Langläufe mit einem aktiven Manager (Transfers, Aufstellung), sobald die Konsole oder die UI das automatisiert erlaubt. - Spieler in den Pools (vereinslos) aus dem Datensatz behalten ihre Rohwerte; der Datensatz 1.3 hat keine. diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index 79ce43a..5cb1371 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -33,7 +33,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht | `training` | Bälle je Spielertyp und Trainingsbereich (1–3) mit den Grenzen, je Spieler Intensität und Schwerpunkt, ob das Training eingerichtet ist, Automatik-Bits | | `contracts` | je Spieler Restlaufzeit, Monatsgehalt, Versicherung, Prämien; das offene Angebot (`quote`: ID, Spieler, Monatsforderung für 1–4 Jahre, Höchstgehalt 200.000 €) | | `advertising` | 14 Banden (`ad:board/`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad--`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals | -| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` 0–3, sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) | +| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) | | `transfer` | die Transferliste (`listing:`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Jahr, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen | | `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung | | `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) | diff --git a/src/cli/console/windows_money.cpp b/src/cli/console/windows_money.cpp index 8bf71dd..bbad7e0 100644 --- a/src/cli/console/windows_money.cpp +++ b/src/cli/console/windows_money.cpp @@ -12,6 +12,7 @@ #include #include "app/window_actions.hpp" +#include "game/world_layout.hpp" #include "cli/console/console.hpp" #include "cli/console/detail.hpp" #include "game/bank_credit.hpp" @@ -324,7 +325,10 @@ void Console::register_money_commands() { // condition byte to the next multiple of 85 (85, 170, 255; ageing lowers it), and an // offer exists below 171. The other objects are built once. std::string state = s.level[o] != 0 ? "built" : "-"; - if (o == 0 && s.level[0] != 0) state = "stage " + std::to_string((s.level[0] - 1) / 85 + 1) + " of 3"; + if (o == 0 && s.level[0] != 0) { // three stages in steps of 85; a Modern world: four in steps of 64 + const int stages = bmh::world_layout().traffic_stages, step = stages == 4 ? 64 : 85; + state = "stage " + std::to_string((s.level[0] - 1) / step + 1) + " of " + std::to_string(stages); + } rows.push_back({std::to_string(o), text(kPeripheryNames + int(o)), building ? "building" : state, std::to_string(s.days[o])}); } diff --git a/src/game/world_layout.hpp b/src/game/world_layout.hpp index 4abb43f..e973599 100644 --- a/src/game/world_layout.hpp +++ b/src/game/world_layout.hpp @@ -42,6 +42,9 @@ struct WorldLayout { // national_start: team no_team() + n at national_start + (n - 1) * national_slots). Classic: none, // the national teams play without players. uint32_t national_start = 0, national_slots = 0; + // Stages of the traffic access (periphery object 0): Classic 3 (condition byte in steps of + // 0x55), a Modern world 4 (steps of 64; the Modern interface shows four). + int traffic_stages = 3; int first_amateur() const { return league_teams; } int first_foreign_cup() const { return league_teams + amateur_teams; } diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 63894e9..4ece9fc 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -654,6 +654,13 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_ // saves from before the national squads end at the reserve: the national squads // start empty (those teams play with their drawn rating until the next nomination) if (g_.squad_slots.size() < world_layout().total_slots) g_.squad_slots.resize(world_layout().total_slots, 0x0fff); + // saves from before the four traffic stages keep the original's scale: convert each + // manager record's traffic access byte to its stage in the new scale + if (modern::four_traffic_stages() && g_.traffic_scale != 64) { + for (size_t rec = 0; rec + 0xb0c <= g_.manager_records.size(); rec += 0xb0c) + g_.manager_records[rec] = modern::traffic_from_original(g_.manager_records[rec]); + g_.traffic_scale = 64; + } rand_ = saved.random; game_ = saved.game; native.emplace(); @@ -4320,6 +4327,7 @@ bool ModernSession::finish(ui::CareerInitializationResult& result, std::string& // Both UI projections must reflect the freshly initialized driver cursor. // Reuse its prepared groups; these projections do not prepare an event or draw RNG. modern::ensure_ui_identities(g_); // career and manager ids of the interface contract + if (modern::four_traffic_stages()) g_.traffic_scale = 64; // the start built the traffic access in that scale result.desktop = desktop_projection(1); result.preparation = preparation_projection(1); for (size_t m = 0; m < managers_.size(); ++m) @@ -8387,7 +8395,7 @@ bool ModernSession::dispatch_stadium(const ui::StadiumRequest& supplied_request, request.object >= 14 || !plain(request.object)) return invalid("invalid_periphery_offer"); const size_t object = size_t(request.object); const uint8_t level = g_.manager_records[record + object]; - if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? level >= 0xab : level != 0)) + if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? !modern::traffic_buildable(level) : level != 0)) return invalid("periphery_unavailable"); const int32_t price = modern::periphery_offer(g_, request.object, game_); if (price <= 0) return invalid("invalid_periphery_price"); @@ -8403,7 +8411,7 @@ bool ModernSession::dispatch_stadium(const ui::StadiumRequest& supplied_request, if (request.kind == ui::StadiumRequestKind::build_periphery) { const size_t object = size_t(request.object); const uint8_t level = g_.manager_records[record + object]; - if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? level >= 0xab : level != 0)) + if (g_.manager_records[record + 0x1e + object] != 0 || (object == 0 ? !modern::traffic_buildable(level) : level != 0)) return invalid("periphery_unavailable"); // ConstructionPricePercent consumes this genuine JA even when PayConstruction's // payment fails. The Source presenter runs before the quote @@ -8924,7 +8932,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co for (size_t o = 0; o < 14; ++o) { const int level = st.level[o]; O row{{"id", "periphery:" + std::to_string(o)}, {"name", text(720 + o)}, {"constructionDays", int(st.days[o])}}; - if (o == 0) row["stage"] = level == 0 ? 0 : (level - 1) / 85 + 1, row["maxStage"] = 3; + if (o == 0) row["stage"] = modern::traffic_stage(level), row["maxStage"] = world_layout().traffic_stages; else row["built"] = level != 0; periphery.push_back(std::move(row)); } diff --git a/src/modern/app/modern_session.hpp b/src/modern/app/modern_session.hpp index f59d774..3677ecd 100644 --- a/src/modern/app/modern_session.hpp +++ b/src/modern/app/modern_session.hpp @@ -4,6 +4,7 @@ #include "modern/content/projections.hpp" #include "modern/content/statistics.hpp" #include "modern/content/ui_contract.hpp" +#include "modern/game/traffic.hpp" #include "modern/content/world_expand.hpp" // The engine side of the UI's career handoff (src/ui/flow.hpp, ENGINE_BINDING.md). // diff --git a/src/modern/content/world_expand.cpp b/src/modern/content/world_expand.cpp index e4cf542..6966bc2 100644 --- a/src/modern/content/world_expand.cpp +++ b/src/modern/content/world_expand.cpp @@ -142,6 +142,7 @@ WorldLayout modern_layout(int league_clubs, int german_clubs) { // no_team, filled on the international days from the players of its nationality w.national_start = w.pool_end + w.no_team_slots + 54; w.national_slots = kSquadSlots; + w.traffic_stages = 4; // the four stages of the Modern interface (modern/game/traffic.hpp) w.total_slots = w.national_start + uint32_t(w.national_teams - 1) * w.national_slots; return w; } diff --git a/src/modern/content/world_save.cpp b/src/modern/content/world_save.cpp index 780c576..082a84e 100644 --- a/src/modern/content/world_save.cpp +++ b/src/modern/content/world_save.cpp @@ -138,7 +138,8 @@ void save_world_career(const std::filesystem::path& path, const World& world, co {"exclusive_sponsors", sponsors_json(state.exclusive_sponsors)}, {"career_id", state.career_id}, {"manager_ids", strings(state.manager_ids)}, - {"manager_serial", int64_t(state.manager_serial)}}); + {"manager_serial", int64_t(state.manager_serial)}, + {"traffic_scale", int64_t(state.traffic_scale)}}); // The almanac: finished seasons unchanged, the running one encoded now. for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes; if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current); @@ -193,6 +194,7 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl out.state.career_id = str(get(modern, "career_id")); out.state.manager_ids = strings(get(modern, "manager_ids")); out.state.manager_serial = uint32_t(num(get(modern, "manager_serial"))); + if (o->count("traffic_scale")) out.state.traffic_scale = uint8_t(num(get(modern, "traffic_scale"))); } for (const auto& [name, bytes] : docs) { if (!name.starts_with("history/season-")) continue; diff --git a/src/modern/game/balance_plan.cpp b/src/modern/game/balance_plan.cpp index b206492..21f7cab 100644 --- a/src/modern/game/balance_plan.cpp +++ b/src/modern/game/balance_plan.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "modern/game/traffic.hpp" #include "modern/game/modern_state.hpp" #include "modern/game/environment.hpp" #include "modern/game/balance_plan.hpp" @@ -50,7 +51,7 @@ int32_t wrap(int64_t v) { return int32_t(uint32_t(uint64_t(v))); } // Add32: the level of a facility (facility 0: its size step) uint32_t facility_level(const ModernState& g, int m, int k) { const uint8_t v = rec8(g, m, size_t(k)); - return k == 0 ? uint32_t((v - 1) / 0x55 + 1) & 0xff : 1; + return k == 0 ? uint32_t(traffic_stage(v)) & 0xff : 1; // the traffic access by its stage (traffic.hpp) } // DailyInterest2(0): the interest of one day without booking it - negative is income diff --git a/src/modern/game/career.cpp b/src/modern/game/career.cpp index d58bfed..0f1cae3 100644 --- a/src/modern/game/career.cpp +++ b/src/modern/game/career.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "modern/game/traffic.hpp" #include "modern/game/modern_state.hpp" #include "modern/game/career.hpp" @@ -446,7 +447,7 @@ void build_stadium(ModernState& g, const LeImage& exe, int m, int league, int mo const uint8_t level = mode == 1 ? 3 : exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(i + league * 0x17)); if (i == 0x10 || i == 0x11 || level == 0) continue; if (i == 0) { - rec[0] = uint8_t(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(league * 0x17)) + (mode == 1 ? 0x55 : 0)); + rec[0] = traffic_from_original(uint8_t(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField + uint32_t(league * 0x17)) + (mode == 1 ? 0x55 : 0))); } else { rec[i] = uint8_t(rand.range(exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField2 + uint32_t(i * 5)), exe.u8(::bmh::layout::Career_BuildStadium_RuntimeField3 + uint32_t(i * 5))) << 2); } diff --git a/src/modern/game/matchday_setup.cpp b/src/modern/game/matchday_setup.cpp index fdc0c32..c62c7c3 100644 --- a/src/modern/game/matchday_setup.cpp +++ b/src/modern/game/matchday_setup.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "modern/game/traffic.hpp" #include "modern/game/modern_state.hpp" #include "modern/game/matchday_setup.hpp" #include "game/trace.hpp" @@ -108,7 +109,7 @@ int32_t catering_income(const ModernState& g, int manager, int32_t spectators, W for (int k = 0; k < 14; k++) { const uint8_t v = g.manager_records.at(rec + size_t(k)); if (v == 0) continue; - const uint32_t level = k == 0 ? uint32_t((v - 1) / 0x55 + 1) & 0xFF : 1; // Add32 + const uint32_t level = k == 0 ? uint32_t(traffic_stage(v)) & 0xFF : 1; // Add32 (traffic.hpp) sum += kPerVisitor[k] * uint32_t(spectators) * level / 100; } if (sum != 0) sum = uint32_t(rand.range(0x55, 0x73)) * sum / 100; @@ -724,7 +725,7 @@ int attendance(ModernState& g, int home, int away, int bits, int temperature, in for (int k = 0; k < 10; k++) { const int v = r8(size_t(k)); // MatchdaySetupRuntimeField6[0] is overwritten with the step of the stadium size - const int32_t step = k == 0 ? int32_t(v / 0x55 * 25000) : kStadiumSteps[k]; + const int32_t step = k == 0 ? int32_t(traffic_full_stages(v) * 25000) : kStadiumSteps[k]; if (step < n && (v == 0 || k == 0)) n -= n / rand.range(10, 20); } const int wet = int(uint32_t(100 - covered) * uint32_t(uint8_t(rain)) * 8) / 100; diff --git a/src/modern/game/modern_state.hpp b/src/modern/game/modern_state.hpp index 1f0141d..0fab9d6 100644 --- a/src/modern/game/modern_state.hpp +++ b/src/modern/game/modern_state.hpp @@ -82,6 +82,9 @@ struct ModernState : GameState { std::string career_id; std::vector manager_ids; uint32_t manager_serial = 0; + // The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the + // four stages of a Modern world. Older Modern saves are converted when loaded. + uint8_t traffic_scale = 0; // 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; diff --git a/src/modern/game/month.cpp b/src/modern/game/month.cpp index 4481ec3..37a76c4 100644 --- a/src/modern/game/month.cpp +++ b/src/modern/game/month.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "modern/game/traffic.hpp" #include "modern/game/modern_state.hpp" #include "modern/game/environment.hpp" #include "modern/game/month.hpp" @@ -531,7 +532,7 @@ int32_t monthly_income(ModernState& g, int m) { for (int k = 0; k < 6; k++) { const uint8_t v = r.at(rec + size_t(k)); if (v == 0) continue; - const int level = k == 0 ? ((v - 1) / 0x55 + 1) & 0xFF : 1; // Add32 + const int level = k == 0 ? traffic_stage(v) & 0xFF : 1; // Add32 (traffic.hpp) sum += level * kFacilityIncome[k]; } add32(r, rec + 0x86c, sum); diff --git a/src/modern/game/traffic.hpp b/src/modern/game/traffic.hpp new file mode 100644 index 0000000..704c1e4 --- /dev/null +++ b/src/modern/game/traffic.hpp @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// The traffic access (Verkehrsanbindung, stadium periphery object 0, manager record +0x00): +// the only periphery object with stages. Its condition byte grows by one stage per finished +// build and sinks with the stadium's ageing; a stage counts while the byte is above the stage +// below it. +// +// The original has three stages in steps of 0x55 (85, 170, 255; a new build is offered below +// 0xab). A Modern world has four, as the Modern interface shows them: steps of 64 (64, 128, +// 192, 255; a build is offered below 193). Every stage weighs as much as one original stage +// (income per visitor, monthly income, the attendance step). Classic data in the Modern core +// keeps the original three (WorldLayout::traffic_stages). + +#include +#include + +#include "game/world_layout.hpp" + +namespace bmh::modern { + +inline bool four_traffic_stages() { return world_layout().traffic_stages == 4; } +inline int traffic_step() { return four_traffic_stages() ? 64 : 0x55; } + +// The stage of a condition byte, 0 = none (the original's Add32 level). +inline int traffic_stage(int v) { return v <= 0 ? 0 : (v - 1) / traffic_step() + 1; } + +// The completed stages (MatchdaySetup's size step: the original's v / 0x55; 255 is stage 4). +inline int traffic_full_stages(int v) { + if (!four_traffic_stages()) return v / 0x55; + return v >= 255 ? 4 : v / 64; +} + +// Whether the building firm offers another stage. +inline bool traffic_buildable(int v) { return v < (four_traffic_stages() ? 3 * 64 + 1 : 0xab); } + +// The condition byte after a finished build: the next full stage. +inline uint8_t traffic_after_build(int v) { + const int step = traffic_step(); + return uint8_t(std::min(255, (v == 0 ? 1 : (v - 1) / step + 2) * step)); +} + +// The original's value of a stage boundary (the ageing message at each boundary). +inline bool traffic_stage_boundary(int v) { return v % traffic_step() == 0; } + +// A condition byte of the original's scale (start tables, older Modern saves) in this world's scale. +inline uint8_t traffic_from_original(int v) { + if (!four_traffic_stages() || v == 0) return uint8_t(v); + return uint8_t(std::min(255, ((v - 1) / 0x55 + 1) * 64)); +} + +} // namespace bmh::modern diff --git a/src/modern/game/weekly.cpp b/src/modern/game/weekly.cpp index d49f0ee..875e81e 100644 --- a/src/modern/game/weekly.cpp +++ b/src/modern/game/weekly.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "modern/game/traffic.hpp" #include "modern/game/modern_state.hpp" #include "modern/game/weekly.hpp" #include "modern/game/club_player_detail.hpp" @@ -171,7 +172,7 @@ int facility_rating(ModernState& g, int manager, int* second, WatcomRandom* rand const uint8_t v = rec.b(size_t(i)); if (v == 0) continue; int level; - if (i < 0xe || i == 0x10 || i == 0x11) level = i == 0 ? (v - 1) / 0x55 + 1 : 1; + if (i < 0xe || i == 0x10 || i == 0x11) level = i == 0 ? traffic_stage(v) : 1; else level = rec.b(size_t(i) + 0x2e) & 7; sum += (level & 0xFF) * kFacility[i * 5]; } @@ -365,7 +366,7 @@ void facility_ageing(ModernState& g, int manager, GameRandom& game, WatcomRandom if (weeks == 0 && rec.b(size_t(i)) != 0 && rec.b(0x1e + size_t(i)) == 0) { uint8_t& v = rec.b(size_t(i)); v--; - if ((i == 0 && v % 0x55 == 0) || rec.b(0x1e + size_t(i)) + v == 0) { + if ((i == 0 && traffic_stage_boundary(v)) || rec.b(0x1e + size_t(i)) + v == 0) { if (i < 0xe) { message = true; } else if (i < 0x16) { @@ -388,7 +389,7 @@ void facility_ageing(ModernState& g, int manager, GameRandom& game, WatcomRandom uint8_t& build = rec.b(0x1e + size_t(i)); if (build != 0 && --build == 0) { uint8_t& v = rec.b(size_t(i)); - if (i == 0) v = uint8_t((v == 0 ? 1 : (v - 1) / 0x55 + 2) * 0x55); + if (i == 0) v = traffic_after_build(v); else v = uint8_t(rand.range(kFacility[i * 5 + 2], kFacility[i * 5 + 3]) << 2); if (i > 0xd) { rec.b(0x2e + size_t(i)) = uint8_t((rec.b(0x2e + size_t(i)) >> 4) & 7); diff --git a/tests/modern_traffic_tests.cpp b/tests/modern_traffic_tests.cpp new file mode 100644 index 0000000..0e1f437 --- /dev/null +++ b/tests/modern_traffic_tests.cpp @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-3.0-only +// The traffic access stages (modern/game/traffic.hpp): the original's three in steps of 0x55, +// a Modern world's four in steps of 64, and the conversion of the original's scale. +#include + +#include "game/world_layout.hpp" +#include "modern/game/traffic.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; + } +} +} // namespace + +int main() { + // Classic: 0 -> 85 -> 170 -> 255, a build is offered below 0xab + set_world_layout(classic_world_layout()); + check(traffic_after_build(0) == 85 && traffic_after_build(85) == 170 && traffic_after_build(170) == 255, "classic builds"); + check(traffic_buildable(170) && !traffic_buildable(255), "classic offer limit"); + check(traffic_stage(85) == 1 && traffic_stage(170) == 2 && traffic_stage(255) == 3 && traffic_stage(84) == 1, "classic stages"); + check(traffic_full_stages(255) == 3 && traffic_full_stages(169) == 1, "classic size steps"); + check(traffic_from_original(170) == 170, "classic keeps its scale"); + + // a Modern world: 0 -> 64 -> 128 -> 192 -> 255, a build is offered below 193 + WorldLayout modern = classic_world_layout(); + modern.traffic_stages = 4; + set_world_layout(modern); + check(traffic_after_build(0) == 64 && traffic_after_build(64) == 128 && traffic_after_build(128) == 192 && + traffic_after_build(192) == 255, "four builds"); + check(traffic_buildable(192) && !traffic_buildable(255), "fourth stage offered, then no more"); + check(traffic_stage(64) == 1 && traffic_stage(128) == 2 && traffic_stage(192) == 3 && traffic_stage(255) == 4, "four stages"); + check(traffic_stage(63) == 1 && traffic_stage(191) == 3, "aged values keep their stage"); + check(traffic_full_stages(255) == 4 && traffic_full_stages(192) == 3 && traffic_full_stages(191) == 2, "size steps"); + check(traffic_stage_boundary(128) && !traffic_stage_boundary(127), "ageing message at a stage boundary"); + check(traffic_from_original(85) == 64 && traffic_from_original(170) == 128 && traffic_from_original(255) == 192 && + traffic_from_original(0) == 0 && traffic_from_original(150) == 128, "the original's stages in the new scale"); + + set_world_layout(classic_world_layout()); + if (failures == 0) std::printf("modern traffic tests passed\n"); + return failures == 0 ? 0 : 1; +}