diff --git a/CMakeLists.txt b/CMakeLists.txt index dd0d55f..9b107ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-3.0-only cmake_minimum_required(VERSION 3.24) -project(OpenBMH VERSION 0.1.1 LANGUAGES CXX C) +project(OpenBMH VERSION 0.1.2 LANGUAGES CXX C) # the one place of the version: --version of both programs and the window title (src/version.hpp) add_compile_definitions(OPENBMH_VERSION="${PROJECT_VERSION}") @@ -39,7 +39,7 @@ function(bmh_add_data_test) set(T_DATA_DIR "${BMH_DATA}") endif() set(reason "") - set(external_text_tests season_transition_tests environment_tests cli_console_tests + set(external_text_tests season_transition_tests cli_console_tests ui_desktop_tests ui_lineup_tests format_tests app_controller_tests bank_app_tests cli_soak ui_cup_draw_tests league_pairings_tests ui_pending_offer_tests reality_reporter_layout_tests season_cup_draw_app_tests @@ -62,7 +62,7 @@ function(bmh_add_data_test) message(FATAL_ERROR "Invalid game data directory for ${T_NAME}: ${T_DATA_DIR}") endif() foreach(option IN LISTS T_REQUIRED_OPTIONS) - if(NOT "${${option}}" OR NOT EXISTS "${${option}}") + if("${${option}}" STREQUAL "" OR NOT EXISTS "${${option}}") set(reason "External test input not supplied: ${option}") endif() endforeach() @@ -365,9 +365,7 @@ bmh_add_data_test(NAME reschedule_tests REQUIRED_OPTIONS BMH_TEST_RESCHEDULE_TES add_executable(environment_tests tests/environment_tests.cpp) target_link_libraries(environment_tests PRIVATE bmhcore) -set(BMH_TEST_ENVIRONMENT_TESTS_INPUT_1 "" CACHE PATH "External input 1 for environment_tests; not distributed") -bmh_add_data_test(NAME environment_tests REQUIRED_OPTIONS BMH_TEST_ENVIRONMENT_TESTS_INPUT_1 COMMAND environment_tests "${BMH_DATA}" - "${BMH_TEST_ENVIRONMENT_TESTS_INPUT_1}") +add_test(NAME environment_tests COMMAND environment_tests) add_executable(youth_academy_tests tests/youth_academy_tests.cpp) target_link_libraries(youth_academy_tests PRIVATE bmhcore) @@ -482,6 +480,7 @@ if(MSVC) endif() bmh_add_data_test(NAME app_controller_tests COMMAND app_controller_tests "${BMH_DATA}") set(BMH_TEST_APP_DELAY_SETTINGS_TESTS_INPUT_1 "" CACHE PATH "External input 1 for app_delay_settings_tests; not distributed") +bmh_add_data_test(NAME app_environment_tests COMMAND app_controller_tests "${BMH_DATA}" --environment-only) bmh_add_data_test(NAME app_delay_settings_tests REQUIRED_OPTIONS BMH_TEST_APP_DELAY_SETTINGS_TESTS_INPUT_1 COMMAND app_controller_tests "${BMH_DATA}" --delay-settings-only "${BMH_TEST_APP_DELAY_SETTINGS_TESTS_INPUT_1}") diff --git a/README.md b/README.md index 4c2615a..8ef4baf 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Version 0.1 establishes the playable engine and development interfaces. Later mi ## Build from source -The following recipes target v0.1.1. They require Git, CMake 3.24 or newer and a C++20 compiler. The first configure fetches pinned open-source dependencies. Native build and package results are documented for each release; these instructions do not claim an untested platform result. +The following recipes target v0.1.2. They require Git, CMake 3.24 or newer and a C++20 compiler. The first configure fetches pinned open-source dependencies. Native build and package results are documented for each release; these instructions do not claim an untested platform result. Clone the public repository, then run the commands for your system: @@ -103,6 +103,6 @@ The implementation grew from study of file formats and behaviour of a legally ob OpenBMH's own code and documentation are licensed under **GNU GPL version 3 only**, SPDX **GPL-3.0-only**. [LICENSE](LICENSE) contains the unchanged GPLv3 text; the example wording in its appendix does not change this project's version choice. Game content has separate ownership and is not covered by this license. -Release source is identified by the matching version tag: [v0.1.1](https://github.com/Weyoune/openbmh/tree/v0.1.1) for this version. Binary releases must accompany or offer the corresponding source and build/relinking materials required by the applicable licenses. The tag identifies application source; it does not replace required materials for linked third-party components. +Release source is identified by the matching version tag: [v0.1.2](https://github.com/Weyoune/openbmh/tree/v0.1.2) for this version. Binary releases must accompany or offer the corresponding source and build/relinking materials required by the applicable licenses. The tag identifies application source; it does not replace required materials for linked third-party components. Bundled components retain their own licenses, including Nuked OPL3 under LGPL-2.1-or-later. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and [ACKNOWLEDGEMENTS.md](ACKNOWLEDGEMENTS.md). diff --git a/docs/CLI_CONCEPT/06-verein.md b/docs/CLI_CONCEPT/06-verein.md index 9d40675..453f455 100644 --- a/docs/CLI_CONCEPT/06-verein.md +++ b/docs/CLI_CONCEPT/06-verein.md @@ -308,9 +308,10 @@ This index includes registered and reserved names. `ListOptions` and `Help` from | Command | Parameters | Purpose | |---|---|---| -| `ShowEnvironment` | – | staff levels and the youth academy | +| `ShowEnvironment` | – | six monthly budgets and three youth tables | | `SetStaffLevel` | role:enum(AssistantCoach,Doctor,Physio), level:int(0..6) | click a staff tile: level 0..6, 5 000 a month each | -| `SetYouthAcademy` | state:enum(On,Off) | start (July/August) or stop the youth academy | +| `SetYouthLevel` | team:enum(Youngest,Academy,Oldest), level:int(0..6) | set a youth team’s monthly budget | +| `SetYouthAcademy` | state:enum(On,Off) | compatibility alias: middle youth budget at level 6 or 0 | ### `Balance` diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 77a71c2..80c30b3 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -11,3 +11,27 @@ OpenBMH aims to preserve the familiar game while handling malformed input and un Intentional changes in code should use the marker `OpenBMH deviates from the original:` and explain their purpose. Adding a new behaviour or balance change requires a concrete description and relevant tests; this page is not permission to substitute guessed rules. The [generated differences catalogue](DIFFERENCES.md) lists these markers with links to their source files. + +## Environment and presentation in 0.1.2 + +The desktop environment provides three youth teams and three staff +budgets, each set to zero through six stars. Youth budgets are monthly, can be +changed throughout the season, and contribute to the finance preview, balance +plan and booked expenses. Youth tables develop on first-division matchdays; +promotion, relegation and age-group handover occur at the season change. +The two previously hidden youth groups are available across data editions. +Staff prices and the shared academy player-generation strength bands stay in +effect. Recruitment needs an active middle youth budget and an oldest youth team +within 25 strength points of the senior squad (the full-build mode bypasses the +strength gate). This deliberately +combines the six-budget environment with OpenBMH's existing player-generation rules. + +Old saved academy lump sums remain payable once and retain their paid status. +They are not multiplied into twelve monthly payments. Editing that tile replaces +the old amount with the selected monthly budget. There is no new save field. + +Live match minutes use the loaded original delay setting (A9), including zero, +instead of an added fixed pause. A9 and the existing scene delays can be adjusted +in Settings; loaded saves and EIN files retain their chosen speeds. VGA retrace +animations use a 70-Hz reference instead of the host monitor's refresh rate. +`--live-frame-ms` and `BMH_LIVE_FRAME_MS` remain explicit diagnostic overrides. diff --git a/docs/DIFFERENCES.md b/docs/DIFFERENCES.md index e6ee49b..e97a0ac 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -6,32 +6,26 @@ See [Compatibility decisions](COMPATIBILITY.md) for the overall policy. These en describe deliberate changes; they are not a list of every known compatibility limit. - [src/app/career_session.cpp](../src/app/career_session.cpp): supports designated set-piece record initialization and validation. -- [src/cli/console/windows_environment.cpp](../src/cli/console/windows_environment.cpp): uses monthly staff levels in increments of five thousand and the supported youth-academy controls. - [src/formats/le.hpp](../src/formats/le.hpp): applies a shared supported rule profile when loading editions with different rule-table values. - [src/formats/rule_base.cpp](../src/formats/rule_base.cpp): normalizes live-scene defaults, league strength ranges, option defaults, stadium prices and capacities, betting limits, and the foreign-player limit across supported editions. - [src/formats/rule_base.hpp](../src/formats/rule_base.hpp): normalizes live-scene options, league strength ranges, option defaults, stadium prices and capacities, betting limits, and the foreign-player limit. -- [src/game/balance_plan.cpp](../src/game/balance_plan.cpp): omits the discontinued youth-group cost categories and uses league-specific youth-academy limits. -- [src/game/balance_plan.hpp](../src/game/balance_plan.hpp): uses the supported staff and youth-academy cost categories. - [src/game/career.cpp](../src/game/career.cpp): skips reserved calendar positions when assigning a joining manager to a club. - [src/game/career.hpp](../src/game/career.hpp): uses the supported player-generation ranges and excludes reserved calendar positions when assigning managers. - [src/game/desk_actions.cpp](../src/game/desk_actions.cpp): uses the supported transfer-fee arithmetic and designated set-piece fields. - [src/game/desk_actions.hpp](../src/game/desk_actions.hpp): supports designated set-piece records and the supported transfer-editor rules. -- [src/game/environment.hpp](../src/game/environment.hpp): enables the supported youth academy and represents staff levels in monthly increments of five thousand. +- [src/game/environment.hpp](../src/game/environment.hpp): uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands. - [src/game/highscore.cpp](../src/game/highscore.cpp): reads the supported edition-specific high-score format from the loaded image. - [src/game/lineup.cpp](../src/game/lineup.cpp): disables the foreign-player limit in the supported rule profile. - [src/game/lineup.hpp](../src/game/lineup.hpp): disables the foreign-player limit and supports owner-bound designated set-piece selection. - [src/game/match.hpp](../src/game/match.hpp): uses the enhanced injury selection and suspension rules. - [src/game/match_engine.cpp](../src/game/match_engine.cpp): supports designated set-piece takers, the enhanced injury tables, and the extended suspension fields. -- [src/game/month.cpp](../src/game/month.cpp): omits the two discontinued youth-group cost categories from monthly accounts. -- [src/game/season.cpp](../src/game/season.cpp): uses the enhanced youth-academy season settlement and player-generation rules. -- [src/game/season.hpp](../src/game/season.hpp): uses the enhanced youth-academy season settlement and player-generation rules. +- [src/game/season.cpp](../src/game/season.cpp): retains the enhanced academy player-generation strength bands with monthly youth budgets. +- [src/game/season.hpp](../src/game/season.hpp): retains the enhanced academy player-generation strength bands with monthly youth budgets. - [src/game/state.hpp](../src/game/state.hpp): retains designated set-piece selections in the supported manager-record extension. - [src/game/week.cpp](../src/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/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/ui/advertising.cpp](../src/ui/advertising.cpp): uses the supported youth-academy cap and its saved cost fields. -- [src/ui/environment.cpp](../src/ui/environment.cpp): omits the two discontinued youth groups from the environment screen. - [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. diff --git a/docs/formats/EXECUTABLE_LAYOUT.md b/docs/formats/EXECUTABLE_LAYOUT.md index d748b04..746a74f 100644 --- a/docs/formats/EXECUTABLE_LAYOUT.md +++ b/docs/formats/EXECUTABLE_LAYOUT.md @@ -1045,6 +1045,11 @@ declarations change. Game text, resort, image and audio fallbacks belong outside | `Environment_FormatError_RuntimeField` | `0xa50f0` | German-compatible image / runtime field | | `Environment_FormatError_RuntimeField2` | `0xa50f6` | German-compatible image / runtime field | | `Environment_Render_TextPointer` | `0xaeb74` | German-compatible image / runtime field | +| `EnvironmentYouthTeams` | `0xbd4bc` | German-compatible image / runtime field | +| `EnvironmentYouthPositionSuffix` | `0xa1698` | German-compatible image / runtime field | +| `EnvironmentCostSuffix` | `0xa169d` | German-compatible image / runtime field | +| `EnvironmentYouthLeagueTextPointer` | `0xaeb78` | German-compatible image / runtime field | +| `EnvironmentYouthColors` | `0xa50fc` | German-compatible image / runtime field | | `Environment_SetEnvironment_ExecutableField` | `0xaf394` | German-compatible image / runtime field | | `EuropeNameTable` | `0xae710` | German-compatible image / runtime field | | `EventPasses` | `0xa2ba1` | German-compatible image / runtime field | diff --git a/docs/release/0.1/RELEASE_NOTES.md b/docs/release/0.1/RELEASE_NOTES.md index 6217e07..0f236f5 100644 --- a/docs/release/0.1/RELEASE_NOTES.md +++ b/docs/release/0.1/RELEASE_NOTES.md @@ -1,7 +1,23 @@ -# OpenBMH v0.1.1 +# OpenBMH v0.1.2 OpenBMH reconstructs the Bundesliga Manager Hattrick engine in C++20. The graphical client uses SDL2; the console provides command batches and local manager-client transports over the same career session. This release needs a supported game installation supplied by the player. No original executable, artwork, music, text database, manual or saved game is included. +## Changes in 0.1.2 + +- The environment menu shows all six original artwork panels: three youth teams, + assistant coach, doctor and physio. Youth panels include their league and rank. +- All six monthly budgets can be set directly to zero through six stars. Youth + development, season promotion/relegation, finance previews and monthly accounts + share those values. Existing academy lump-sum saves retain their paid status. +- Match-minute pacing follows the loaded original delay setting; A9 in Settings + allows faster or slower progression. No fixed 250-ms pause is added. Retrace + animations use the original reference rate on different host monitors. +- External test fixtures are now recognised correctly by CMake instead of being + reported as unavailable despite configured paths. + +See [compatibility decisions](../../COMPATIBILITY.md) for youth recruitment and +legacy contract handling. The previous UI corrections remain included. + ## Changes in 0.1.1 - Live lineup navigation preserves the saved pitch view and allows repeated switches between the team list and pitch. Right-click can leave the dialog even when the pointer moves between press and release ([#1](https://github.com/Weyoune/openbmh/issues/1)). @@ -9,13 +25,16 @@ OpenBMH reconstructs the Bundesliga Manager Hattrick engine in C++20. The graphi - Right-click cancels load/save dialogs, including settings and desktop-layout files ([#3](https://github.com/Weyoune/openbmh/issues/3)). - Save filenames accept typing immediately, replace a selected existing name and support Ctrl+A/Cmd+A. This also applies to desktop layouts saved as MEN files ([#4](https://github.com/Weyoune/openbmh/issues/4)). -These corrections passed targeted UI/controller checks and Linux SDL input replays, including normal and Reality matches, substitutions, file writing and a fresh-process reload. Physical macOS window verification remains human QA. Use the new 0.1.1 packages to test these fixes; older 0.1.0 builds do not include them. +These corrections passed targeted UI/controller checks and Linux SDL input replays, including normal and Reality matches, substitutions, file writing and a fresh-process reload. Physical macOS window verification remains human QA. Use packages from 0.1.1 or later to test these fixes; older 0.1.0 builds do not include them. ## Scope The engine includes career management, leagues and cups, transfers and contracts, finances, training and camps, stadium management, live match interventions, audio playback and normal saves. Supported actions remain subject to mode, manager and phase restrictions; an unimplemented path reports an explicit error rather than an invented result. The project aims for recognisable behaviour and plausible results, not a promise that every original version produces identical events. -German game editions are the primary compatibility target. **Football Limited support is experimental.** English installation loading and edition-specific text/layout data are supported paths, while original V2.20 save import, English audio and remaining competition/interface differences have limitations. Check current issues before relying on a particular English workflow. +German game editions are the primary compatibility target. **Football Limited support is experimental.** English installation loading and edition-specific text/layout data are supported paths, while original V2.20 save import, English audio and remaining competition/interface differences have limitations. A known limitation can reject an English save made after the first calendar +advance: the saved turn cursor may no longer match the active calendar. Initial +save/reload works; a complete English career is not yet verified. Check current +issues before relying on a particular English workflow. ## Compatibility decisions @@ -34,7 +53,7 @@ Version 0.1 ships binary packages for Windows x64, macOS on Apple silicon (arm64 ## License -The matching application source tag is [v0.1.1](https://github.com/Weyoune/openbmh/tree/v0.1.1). Source/build and relinking materials for linked components must also accompany or be offered with binary releases under their licenses. +The matching application source tag is [v0.1.2](https://github.com/Weyoune/openbmh/tree/v0.1.2). Source/build and relinking materials for linked components must also accompany or be offered with binary releases under their licenses. OpenBMH-owned code and documentation use GPL-3.0-only. Third-party components retain their licenses; the full texts accompany the package. Read [LICENSE](../../../LICENSE) and [THIRD_PARTY_NOTICES](../../../THIRD_PARTY_NOTICES.md). These licenses do not grant rights to original game content. diff --git a/src/app/career_session.cpp b/src/app/career_session.cpp index 0edd23b..c3c62dd 100644 --- a/src/app/career_session.cpp +++ b/src/app/career_session.cpp @@ -4558,9 +4558,9 @@ bool CareerSession::dispatch_settings(const ui::SettingsWriteRequest& request, u const bool consumed = (request.column == 7 && ((request.row <= 6) || request.row == 7 || request.row == 9 || request.row == 10 || (scoped_settings && request.row == 8))) || - // B9:C9 chance result; D9:E9 bookings; F9:G9 rolling ball; + // A9 match minutes; B9:C9 chance result; D9:E9 bookings; F9:G9 rolling ball; // I9 cup draw; K9 Reality report; M9 preview/shootout; P9 shot. - (request.column == 8 && ((request.row >= 1 && request.row <= 6) || + (request.column == 8 && ((request.row >= 0 && request.row <= 6) || request.row == 7 || request.row == 8 || request.row == 10 || request.row == 12 || request.row == 15)); if (!consumed || old >= 200) { error = "Diese Einstellung ist noch nicht verfügbar."; diff --git a/src/app/main.cpp b/src/app/main.cpp index 9306216..ae6a067 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "ui/live_timing.hpp" // openbmh_play - the UI of src/ui connected to the engine: options, manager dialogs, a new // career initialised by the engine (app/career_session.hpp) and its desk. // @@ -97,7 +98,7 @@ int main(int argc, char** argv) { fs::path data, save_directory; uint32_t seed = uint32_t(std::chrono::system_clock::now().time_since_epoch().count()); bool muted = false, music_enabled = true; - int live_frame_ms = 10; + int live_frame_ms = 0; bool live_frame_ms_explicit = false; if (const char* configured = std::getenv("BMH_LIVE_FRAME_MS")) { live_frame_ms = std::clamp(std::atoi(configured), 0, 1000); @@ -478,14 +479,8 @@ int main(int argc, char** argv) { } }; auto wait_source_retraces = [&](unsigned count) { - // SDL has no VGA status-port equivalent. Approximate Source's - // retrace waits with the active display's reported refresh period; - // keep the previous frame visible and present the next frame once. - SDL_DisplayMode mode{}; - const int display = SDL_GetWindowDisplayIndex(window); - int refresh_hz = display >= 0 && SDL_GetCurrentDisplayMode(display, &mode) == 0 - ? mode.refresh_rate : 0; - if (refresh_hz <= 0) refresh_hz = 60; // explicit host fallback; not an Original VGA claim + // Keep the VGA cadence on 60/120/144-Hz host displays alike. + constexpr auto refresh_hz = ui::kOriginalRefreshHz; const Uint64 frequency = SDL_GetPerformanceFrequency(); const Uint64 ticks_per_wait = (frequency + Uint64(refresh_hz) - 1) / Uint64(refresh_hz); for (unsigned i = 0; running && i < count; ++i) { @@ -2158,7 +2153,8 @@ int main(int argc, char** argv) { live_frame_shown = true; } } - const int frame_delay = live_frame_ms_explicit ? live_frame_ms : std::max(live_frame_ms, 250); + const int frame_delay = live_frame_ms_explicit ? live_frame_ms : + int(ui::live_delay_milliseconds(state.memory.u8(::bmh::layout::Main_FormatError_ExecutableField))); if (live_frame_shown && !live_skipped && frame_delay > 0) SDL_Delay(Uint32(frame_delay)); }, diff --git a/src/cli/console/windows_environment.cpp b/src/cli/console/windows_environment.cpp index db064d6..1f269d1 100644 --- a/src/cli/console/windows_environment.cpp +++ b/src/cli/console/windows_environment.cpp @@ -1,11 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -// OpenBMH deviates from the original: uses monthly staff levels in increments of five thousand and the supported youth-academy controls. -// The club environment (menu 24, docs/CLI_CONCEPT/06-verein.md 10, H2 p. 93, supported rule profile p. 107, -// 111): co-trainer, doctor and physio in levels of 5 000 a month, and the supported rule profile youth -// academy that costs a season price of the league. -// -// The rules are the engine's (src/game/environment.hpp, a port of Image with the -// supported rule profile patch); a command is one click of the original screen. +// The console and desktop share all six monthly environment budgets. #include "app/desktop_actions.hpp" #include "cli/console/console.hpp" @@ -19,20 +13,21 @@ using namespace detail; void Console::register_environment_commands() { auto show = [this] { const EnvironmentState s = environment_state(session_->state(), active_slot()); - std::vector> rows = { - {"AssistantCoach", std::to_string(s.level[kCoTrainer]), money(s.monthly[kCoTrainer])}, - {"Doctor", std::to_string(s.level[kDoctor]), money(s.monthly[kDoctor])}, - {"Physio", std::to_string(s.level[kPhysio]), money(s.monthly[kPhysio])}, - {"YouthAcademy", s.monthly[kYouthAcademy] != 0 ? "on" : "off", money(s.youth_price) + " per season"}}; - emit_table({"Item", "Level", "Costs"}, rows); - emit('i', std::string("youth academy: ") + (s.youth_paid ? "paid this season" : s.youth_open ? "can be started (July/August)" - : "too late for this season")); + std::vector> rows; + constexpr const char* names[] = {"YouthYoungest", "YouthAcademy", "YouthOldest", "AssistantCoach", "Doctor", "Physio"}; + for (int i = 0; i < kEnvironmentItems; ++i) + rows.push_back({names[i], std::to_string(s.level[size_t(i)]), money(s.monthly[size_t(i)])}); + emit_table({"Item", "Level", "MonthlyCosts"}, rows); + rows.clear(); + for (size_t i = 0; i < 3; ++i) + rows.push_back({names[i], std::to_string(s.youth_position[i] + 1), std::to_string(s.youth_league[i] + 1)}); + emit_table({"YouthTeam", "Position", "Division"}, rows); }; openers_[24] = [this, show] { open_window("Environment"); show(); }; - add({"Environment", "ShowEnvironment", {}, "staff levels and the youth academy", false}, [show](const Values&) { show(); }); + add({"Environment", "ShowEnvironment", {}, "all six monthly budgets and youth tables", false}, [show](const Values&) { show(); }); auto apply = [this, show](int item, int level) { std::string error; const auto r=app::EnvironmentActions(*session_).set_console( @@ -44,11 +39,14 @@ void Console::register_environment_commands() { add({"Environment", "SetStaffLevel", {choice("role", {"AssistantCoach", "Doctor", "Physio"}), integer("level", 0, 6)}, "click a staff tile: level 0..6, 5 000 a month each", true}, [apply](const Values& v) { apply(kCoTrainer + v.choice("role"), int(v.integer("level"))); }); - add({"Environment", "SetYouthAcademy", {choice("state", {"On", "Off"})}, "start (July/August) or stop the youth academy", true}, + add({"Environment", "SetYouthLevel", {choice("team", {"Youngest", "Academy", "Oldest"}), integer("level", 0, 6)}, + "set one youth team's monthly budget, level 0..6", true}, + [apply](const Values& v) { apply(v.choice("team"), int(v.integer("level"))); }); + add({"Environment", "SetYouthAcademy", {choice("state", {"On", "Off"})}, "set the middle youth budget to level 6 or 0", true}, [this, apply](const Values& v) { const bool on = environment_state(session_->state(), active_slot()).monthly[kYouthAcademy] != 0; const bool want = v.choice("state") == 0; - // the original's click on an active academy switches it off: click only for a change + // Retain the old On/Off command as an alias for the middle youth budget. if (on == want) emit('+', std::string("youth academy already ") + (on ? "on" : "off")); else apply(kYouthAcademy, want ? 6 : 0); }); diff --git a/src/formats/executable_layout.hpp b/src/formats/executable_layout.hpp index 6fea83a..7d6b398 100644 --- a/src/formats/executable_layout.hpp +++ b/src/formats/executable_layout.hpp @@ -1026,6 +1026,11 @@ inline constexpr auto EnglishLeagueCupSemiFinalResults = 0x7d002; inline constexpr auto Environment_FormatError_RuntimeField = 0xa50f0; inline constexpr auto Environment_FormatError_RuntimeField2 = 0xa50f6; inline constexpr auto Environment_Render_TextPointer = 0xaeb74; +inline constexpr auto EnvironmentYouthTeams = 0xbd4bc; +inline constexpr auto EnvironmentYouthPositionSuffix = 0xa1698; +inline constexpr auto EnvironmentCostSuffix = 0xa169d; +inline constexpr auto EnvironmentYouthLeagueTextPointer = 0xaeb78; +inline constexpr auto EnvironmentYouthColors = 0xa50fc; inline constexpr auto Environment_SetEnvironment_ExecutableField = 0xaf394; inline constexpr auto EuropeNameTable = 0xae710; inline constexpr auto EventPasses = 0xa2ba1; diff --git a/src/game/balance_plan.cpp b/src/game/balance_plan.cpp index 4475179..e65d81d 100644 --- a/src/game/balance_plan.cpp +++ b/src/game/balance_plan.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "game/environment.hpp" #include "game/balance_plan.hpp" #include @@ -160,13 +161,6 @@ uint32_t catering_per_game(const GameState& g, int m, int32_t gate) { return sum; } -// OpenBMH deviates from the original: omits the discontinued youth-group cost categories and uses league-specific youth-academy limits. -// TeamLeague3 (supported rule profile patch): the youth academy limit of the league -int32_t youth_limit(const GameState& g, int m) { - const int league = team_league(g.manager_teams.at(size_t(m))); - return league == 0 ? 1500000 : league == 1 ? 1000000 : league <= 3 ? 580000 : 280000; -} - // The redraw of BalanceFromGame2 (with its continuation Redraw and the patch at // Redraw2): recomputes the items if `refresh` asks for it, then the spectator income // and the totals. @@ -228,12 +222,12 @@ void redraw(const GameState& source, BalancePlanDraft& d) { r[4] = wrap(int64_t(r[4]) + int64_t(facility_income(g, m)) * months); const uint32_t catering = catering_per_game(g, m, r[kBalanceAverageGate]); r[4] = wrap(int64_t(r[4]) + int64_t((catering * uint32_t(home)) / 12) * months); - // running costs Spending: the patch counts only the youth academy (index 1), - // with the whole league limit while +0x880 is below it const uint32_t costs = ::bmh::layout::Spending + uint32_t(m) * 0x24; - if (mem32(g, costs + 4) != 0 && int64_t(months) * mem32(g, costs + 4) != 0) { - const int32_t limit = youth_limit(g, m); - if (uint32_t(rec32(g, m, 0x880)) < uint32_t(limit)) r[9] = wrap(int64_t(r[9]) + limit); + for (int k = 0; k < 3; ++k) { + const auto value = environment_monthly_cost(g, m, k); + const auto raw = mem32(g, costs + uint32_t(k) * 4); + const int count = k == kYouthAcademy && raw > kEnvironmentStep[k] * 6 ? 1 : months; + r[9] = wrap(int64_t(r[9]) + int64_t(count) * value); } for (int k = 0; k < 3; k++) r[size_t(10 + k)] = wrap(int64_t(r[size_t(10 + k)]) + int64_t(months) * mem32(g, costs + 0xc + uint32_t(k) * 4)); for (int k = 0; k < 2; k++) r[size_t(14 + k)] = wrap(int64_t(r[size_t(14 + k)]) + int64_t(months) * rec32(g, m, 0x854 + size_t(k) * 4)); @@ -276,11 +270,7 @@ int32_t stadium_required_attendance(const GameState& source, int manager) { int32_t costs = wrap(int64_t(facility_costs(g, m)) + rec32(g, m, 0x854) + rec32(g, m, 0x858)); costs = wrap(int64_t(costs) + monthly_pay(g, m, 0xa)); for (int k = 0; k < 6; ++k) { - int32_t value = mem32(g, ::bmh::layout::Spending + uint32_t(m) * 0x24 + uint32_t(k) * 4); - if (k == 0 || k == 2) value = 0; // OpenBMH deviates from the original: omits the discontinued youth-group cost categories and uses league-specific youth-academy limits. -// supported rule profile MonthlyExpenses - if (k == 1 && value != 0) - value = uint32_t(rec32(g, m, 0x880)) < uint32_t(youth_limit(g, m)) ? youth_limit(g, m) : 0; + const int32_t value = environment_monthly_cost(g, m, k); costs = wrap(int64_t(costs) + value); } costs = wrap(int64_t(costs) - shares_and_loans(g, m, 2, 0) + int(rec8(g, m, 0x179)) * 1000); diff --git a/src/game/balance_plan.hpp b/src/game/balance_plan.hpp index bdb69b2..401b0c5 100644 --- a/src/game/balance_plan.hpp +++ b/src/game/balance_plan.hpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #pragma once -// OpenBMH deviates from the original: uses the supported staff and youth-academy cost categories. +// All three youth budgets and staff costs share the monthly environment model. // The balance plan ("Bilanz", desk menu 28, mode III; H2 p. 26-27; BMH.exe V2.24 + supported rule profile // patch): the screen BalanceFromGame2 projects the club's income and expenses for the business // year and lets the manager change every item. When he leaves the screen the resulting diff --git a/src/game/environment.cpp b/src/game/environment.cpp index 8a77cf9..8ef8f43 100644 --- a/src/game/environment.cpp +++ b/src/game/environment.cpp @@ -1,103 +1,113 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "game/environment.hpp" - #include - -#include "game/messages.hpp" -#include "game/schedule.hpp" -#include "game/week.hpp" +#include namespace bmh { - namespace { - -constexpr uint32_t kSpending = ::bmh::layout::Spending; // + manager * 0x24 + item * 4 -constexpr size_t kRecordSize = 0xb0c; -constexpr size_t kYouthPaid = 0x880; // youth expenses booked this season -// EnvironmentRuntimeField: the step of each item in thousands (items 3..5: 5 000 per level) -constexpr int kUnit[kEnvironmentItems] = {2, 4, 5, 5, 5, 5}; - -uint32_t spending_at(int manager, int item) { return kSpending + uint32_t(manager) * 0x24 + uint32_t(item) * 4; } - -// TeamLeague3: the academy's season price by the club's league -int32_t youth_price(const GameState& g, int manager) { - const int league = team_league(g.manager_teams.at(size_t(manager))); - return league == 0 ? 1500000 : league == 1 ? 1000000 : league <= 3 ? 580000 : 280000; +uint32_t youth_at(int manager) { return layout::EnvironmentYouthTeams + uint32_t(manager) * 0x24; } +uint32_t spending_at(int manager, int item) { + return layout::Spending + uint32_t(manager) * 0x24 + uint32_t(item) * 4; } - -// YouthOpen: July (unless the Bundesliga is past its 17th round) or August -bool youth_open(const GameState& g) { - const int month = month_code(g.date); - if (month == 7) return !(g.league_rounds.at(0) > 0x11); - return month == 8; +void validate_manager(const GameState& g, int manager) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size() || + !g.memory.has(youth_at(manager) + 8) || !g.memory.has(spending_at(manager, 5) + 3)) + throw FormatError("environment: invalid manager or truncated budgets"); } - -bool youth_paid(const GameState& g, int manager) { - const size_t at = size_t(manager) * kRecordSize + kYouthPaid; - const uint32_t paid = uint32_t(g.manager_records.at(at)) | uint32_t(g.manager_records.at(at + 1)) << 8 | - uint32_t(g.manager_records.at(at + 2)) << 16 | uint32_t(g.manager_records.at(at + 3)) << 24; - return paid >= uint32_t(youth_price(g, manager)); +int direction(int value) { return (value > 0) - (value < 0); } +int signed_clamp(int value, int low, int high) { + return std::clamp(int(int8_t(uint8_t(value))), low, high); +} +bool legacy_academy(const GameState& g, int manager) { + const auto value = g.memory.u32(spending_at(manager, kYouthAcademy)); + return value == 1500000 || value == 1000000 || value == 580000 || value == 280000; +} +uint32_t academy_paid(const GameState& g, int manager) { + const auto at = size_t(manager) * 0xb0c + 0x880; + return uint32_t(g.manager_records.at(at)) | uint32_t(g.manager_records.at(at + 1)) << 8 | + uint32_t(g.manager_records.at(at + 2)) << 16 | uint32_t(g.manager_records.at(at + 3)) << 24; +} +} +int32_t environment_monthly_cost(const GameState& g, int manager, int item) { + const auto value = g.memory.u32(spending_at(manager, item)); + if (item == kYouthAcademy && legacy_academy(g, manager) && academy_paid(g, manager) >= value) return 0; + return int32_t(value); +} +bool environment_academy_active(const GameState& g, int manager) { + const auto value = g.memory.u32(spending_at(manager, kYouthAcademy)); + return value != 0 && (!legacy_academy(g, manager) || academy_paid(g, manager) >= value); } - -} // namespace - EnvironmentState environment_state(const GameState& g, int manager) { - EnvironmentState s; - for (int i = 0; i < kEnvironmentItems; i++) { - s.monthly[size_t(i)] = int32_t(g.memory.u32(spending_at(manager, i))); - // the stars (SizeT7): staff value / step, the academy 6 when on, 0/2 none - if (i >= 3) s.level[size_t(i)] = std::clamp(s.monthly[size_t(i)] / (kUnit[i] * 1000), 0, 6); - else if (i == kYouthAcademy) s.level[size_t(i)] = s.monthly[size_t(i)] != 0 ? 6 : 0; + validate_manager(g, manager); + EnvironmentState result; + for (int i = 0; i < kEnvironmentItems; ++i) { + result.monthly[size_t(i)] = int32_t(g.memory.u32(spending_at(manager, i))); + result.level[size_t(i)] = std::clamp(result.monthly[size_t(i)] / kEnvironmentStep[size_t(i)], 0, 6); } - s.youth_price = youth_price(g, manager); - s.youth_paid = youth_paid(g, manager); - s.youth_open = youth_open(g); - return s; -} - -EnvironmentResult set_environment(GameState& g, int manager, int item, int level, std::string* message) { - if (manager < 0 || size_t(manager) >= g.manager_teams.size() || item < 0 || item >= kEnvironmentItems || level < 0 || - level > 6 || !g.memory.has(spending_at(manager, item) + 3)) - return EnvironmentResult::invalid; - const uint32_t at = spending_at(manager, item); - const int32_t before = int32_t(g.memory.u32(at)); - int32_t value = 0; - EnvironmentResult result = EnvironmentResult::changed; - if (item >= 3) { - value = level * kUnit[item] * 1000; - } else if (item == kYouthAcademy) { - // YouthPrice: a click on an active academy means "off" - int wanted = level; - if (before != 0 && wanted != 0) wanted = 0; - const int32_t price = youth_price(g, manager); - if (!youth_paid(g, manager)) { - if (wanted == 0) { - value = 0; - } else if (!youth_open(g)) { - value = 0; - result = EnvironmentResult::too_late; - if (message) *message = message_text(g, ::bmh::layout::Environment_SetEnvironment_ExecutableField); // "Zu spät für diese Saison..." - } else { - value = price; - } - } else { - // paid this season: stays on; a click meant as "off" brings the second string of - // the same text block (*Environment_SetEnvironment_ExecutableField + 0x42) - value = price; - if (wanted == 0) { - result = EnvironmentResult::contract_runs; - if (message) { - *message = message_text_following(g, ::bmh::layout::Environment_SetEnvironment_ExecutableField); - // OpenBMH-authored notice when an edition has no academy tail text. - if (message->empty()) *message = "This academy contract stays active until the season ends."; - } - } - } + for (uint32_t i = 0; i < 3; ++i) { + result.youth_strength[i] = g.memory.u8(youth_at(manager) + i); + result.youth_position[i] = g.memory.u8(youth_at(manager) + 3 + i); + result.youth_league[i] = g.memory.u8(youth_at(manager) + 6 + i); + if (result.youth_position[i] > 11 || result.youth_league[i] > 2) + throw FormatError("environment: invalid youth table"); } - g.memory.set32(at, uint32_t(value)); - if (result == EnvironmentResult::changed && value == before) result = EnvironmentResult::unchanged; return result; } - +EnvironmentResult set_environment(GameState& g, int manager, int item, int level, std::string* message) { + if (message) message->clear(); + if (manager < 0 || size_t(manager) >= g.manager_teams.size() || item < 0 || item >= kEnvironmentItems || + level < 0 || level > 6 || !g.memory.has(spending_at(manager, item) + 3)) + return EnvironmentResult::invalid; + const auto at = spending_at(manager, item); + const auto value = uint32_t(level * kEnvironmentStep[size_t(item)]); + if (g.memory.u32(at) == value) return EnvironmentResult::unchanged; + g.memory.set32(at, value); + return EnvironmentResult::changed; +} +void advance_youth_teams(GameState& g, int manager, WatcomRandom& rand) { + const auto observed = environment_state(g, manager); + std::array movement{}; + uint8_t step = 4; + for (auto& value : movement) { + value = step; + if (step != 0 && rand.range(0, 8) == 0) --step; + } + const auto round = g.league_rounds.at(0); + if (round >= movement.size()) throw FormatError("environment: youth round outside season"); + constexpr int division_strength[] = {85, 70, 57}; + for (size_t i = 0; i < 3; ++i) { + int strength = observed.youth_strength[i]; + int position = observed.youth_position[i]; + const int opponent = uint8_t(division_strength[observed.youth_league[i]] - position); + const int ratio = strength == 0 ? 100 : + int((((int64_t(observed.monthly[i]) * 100 / ((1 << i) * 10000)) >> 1) + 40) * 100 / strength); + int change = direction(ratio - 100); + if (rand.range(0, 4) == 0) change = rand.range(0, 2) - 1; + if (std::abs(ratio - 100) <= rand.range(0, 30)) change = 0; + if (rand.range(0, 2) == 0) strength = uint8_t(strength + change); + strength = signed_clamp(strength, 10, 85); + g.memory.set8(youth_at(manager) + uint32_t(i), uint8_t(strength)); + const int difference = strength - opponent; + change = direction(difference); + if (rand.range(0, 4) == 0) change = rand.range(0, 2) - 1; + if (rand.range(0, 3) != 0 && std::abs(difference) * 2 < rand.range(1, 18)) change = 0; + position = signed_clamp(uint8_t(position - change * rand.range(1, movement[round])), 0, 11); + g.memory.set8(youth_at(manager) + 3 + uint32_t(i), uint8_t(position)); + } +} +void finish_youth_season(GameState& g, int manager) { + const auto observed = environment_state(g, manager); + for (int i = 2; i >= 0; --i) { + auto division = observed.youth_league[size_t(i)]; + const int position = observed.youth_position[size_t(i)]; + int next_position = 5; + if (position < 2 && division != 0) { --division; next_position = position + 10; } + if (position > 10 && division < 2) { ++division; next_position = position - 10; } + if (i != 0) g.memory.set8(youth_at(manager) + uint32_t(i), + uint8_t((int(observed.youth_strength[size_t(i - 1)]) + observed.youth_strength[size_t(i)] * 2) / 3)); + g.memory.set8(youth_at(manager) + 3 + uint32_t(i), uint8_t(next_position)); + g.memory.set8(youth_at(manager) + 6 + uint32_t(i), division); + } +} } // namespace bmh diff --git a/src/game/environment.hpp b/src/game/environment.hpp index 0d6aa9b..326236e 100644 --- a/src/game/environment.hpp +++ b/src/game/environment.hpp @@ -1,47 +1,31 @@ // SPDX-License-Identifier: GPL-3.0-only #pragma once -// OpenBMH deviates from the original: enables the supported youth academy and represents staff levels in monthly increments of five thousand. -// The club environment ("Umfeld", desk menu 24, H2 p. 93; supported rule profile manual p. 107, 111): -// the screen Image with the supported rule profile patch (SizeT7 / EnvironmentOperation / -// YouthPrice / YouthOpen). Six monthly running costs per manager live at -// Spending + manager * 0x24 (u32 each); the month change books them -// (month.cpp monthly_expenses) and the staff values steer training, injuries and healing. -// -// item 0, 2 the original's two other youth age groups: the patch always sets 0 -// item 1 the youth academy (supported rule profile): on or off. On it is the league's season price -// (TeamLeague3: 1.5 M, 1 M, 580 000, 280 000), paid in full at the next month -// change while record +0x880 (youth expenses this season) is below it. It can -// be switched on in July and August only ("Zu spät für diese Saison...") and -// not switched off once paid ("Der Vertrag läuft bis zum Saisonende."). -// item 3..5 co-trainer, doctor, physio: level 0..6 times 5 000 a month (EnvironmentRuntimeField) -// -// A click on a tile sets the level from the mouse position (supported rule profile: one click per value). - #include #include #include - +#include "game/random.hpp" #include "game/state.hpp" namespace bmh { - constexpr int kEnvironmentItems = 6; -enum EnvironmentItem : int { kYouthAcademy = 1, kCoTrainer = 3, kDoctor = 4, kPhysio = 5 }; - +enum EnvironmentItem : int { kYouthYoungest = 0, kYouthAcademy = 1, kYouthOldest = 2, + kCoTrainer = 3, kDoctor = 4, kPhysio = 5 }; +// OpenBMH deviates from the original: uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands. +inline constexpr std::array kEnvironmentStep = {2000, 4000, 5000, 5000, 5000, 5000}; struct EnvironmentState { - std::array monthly{}; // Spending values - std::array level{}; // the stars the screen draws (0..6) - int32_t youth_price = 0; // the season price of the academy for the club's league - bool youth_paid = false; // record +0x880 reached the price: cannot be switched off - bool youth_open = false; // July/August: the academy can still be switched on + std::array monthly{}; + std::array level{}; + std::array youth_strength{}, youth_position{}, youth_league{}; }; - EnvironmentState environment_state(const GameState& g, int manager); - -enum class EnvironmentResult : uint8_t { changed, unchanged, too_late, contract_runs, invalid }; - -// A click on `item` at `level` (0..6; for the academy any level > 0 means "on" and a click on -// an active academy switches it off). `message` gets the original's message box text, if any. +// Preserve already saved lump-sum academy contracts until the user edits them. +int32_t environment_monthly_cost(const GameState& g, int manager, int item); +bool environment_academy_active(const GameState& g, int manager); +enum class EnvironmentResult : uint8_t { changed, unchanged, invalid }; +// Set a monthly budget to level 0..6, without an immediate debit or random draw. EnvironmentResult set_environment(GameState& g, int manager, int item, int level, std::string* message = nullptr); - +// Youth results advance with first-division matchdays. Promotion/relegation and +// the handover to the next age group happen before annual accounts. +void advance_youth_teams(GameState& g, int manager, WatcomRandom& rand); +void finish_youth_season(GameState& g, int manager); } // namespace bmh diff --git a/src/game/matchday.cpp b/src/game/matchday.cpp index 16ab195..7e60bbf 100644 --- a/src/game/matchday.cpp +++ b/src/game/matchday.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "game/environment.hpp" #include "game/matchday.hpp" #include @@ -676,30 +677,6 @@ void manager_match_record(GameState& g, const MatchGroup& grp, int m, int home_g } -// TicketPriceDraws: per human manager on a first league matchday. It once let the three -// ticket prices drift; in this version its stores were turned into comparisons (CMP -// instead of MOV), so only the random numbers remain. -void ticket_price_draws(const GameState& g, int manager, WatcomRandom& rand) { - uint8_t step[0x2c]; - int b = 4; - for (int i = 0; i < 0x2c; i++) { - step[i] = uint8_t(b); - if (b != 0 && rand.range(0, 8) == 0) b--; - } - (void)g; - (void)manager; - const int round = g.league_rounds.empty() ? 0 : g.league_rounds[0]; - for (int i = 0; i < 3; i++) { - // the direction terms depend on the prices, but only as values, not as draw counts - if (rand.range(0, 4) == 0) rand.range(0, 2); - rand.range(0, 30); - rand.range(0, 2); - if (rand.range(0, 4) == 0) rand.range(0, 2); - if (rand.range(0, 3) != 0) rand.range(1, 18); - rand.range(1, step[round < 0x2c ? round : 0x2b]); - } -} - // ManagerOf(manager, 0, value): the manager's position of this season. static void store_season_position(GameState& g, int manager, int value) { int season = std::min(g.season, 0x31); @@ -742,7 +719,7 @@ void advance_league_rounds(GameState& g, uint32_t competitions, WatcomRandom& ra for (int league = kFirst[c]; league < kFirst[c] + kCount[c]; league++) { if (league == 0) { for (size_t m = 0; m < g.manager_teams.size(); m++) { - ticket_price_draws(g, int(m), rand); + advance_youth_teams(g, int(m), rand); const size_t rec = m * kManagerRecord; if (g.league_rounds.at(0) == 0x10) wr32(g.manager_records, rec + 0x320, rd32(g.manager_records, rec + 0x308)); uint8_t& d = g.manager_records.at(rec + 0x220); // point deduction countdown diff --git a/src/game/month.cpp b/src/game/month.cpp index 718bdb7..ee02477 100644 --- a/src/game/month.cpp +++ b/src/game/month.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "game/environment.hpp" #include "game/month.hpp" #include "game/trace.hpp" @@ -482,11 +483,9 @@ void return_loans(GameState& g, WatcomRandom& rand, GameRandom* game, MinuteRepo } } -// OpenBMH deviates from the original: omits the two discontinued youth-group cost categories from monthly accounts. // OriginalFinancePreview(1): the month's expenses of a human manager: facility maintenance // (BMHExeXa), record +0x854/+0x858, the wages of the squad (MonthlyPay with flags -// 14), the six running costs of Spending (the youth work capped per league by the -// supported rule profile patch MonthlyExpenses, which also drops the youth groups 0 and 2) and the debt +// 14), all six monthly environment budgets and the debt // service (+0x179 x 1000); each booked in the statistics. int32_t monthly_expenses(GameState& g, int m) { std::vector& r = g.manager_records; @@ -514,18 +513,7 @@ int32_t monthly_expenses(GameState& g, int m) { } sum += wages; for (int k = 0; k < 6; k++) { - int32_t v = int32_t(g.memory.u32(::bmh::layout::Spending + uint32_t(m) * 0x24 + uint32_t(k) * 4)); - // OpenBMH deviates from the original: omits the two discontinued youth-group cost categories from monthly accounts. -// MonthlyExpenses (supported rule profile patch): the two other youth groups (items 0 and 2) cost - // nothing any more, whatever the saved value - if (k == 0 || k == 2) v = 0; - if (k == 1 && v != 0) { - // TeamLeague3: the limit of the league (1.5 M, 1 M, 580000, 280000); the full - // limit is paid while +0x880 is below it, nothing after - const int league = team_league(g.manager_teams.at(size_t(m))); - const uint32_t limit = league == 0 ? 1500000 : league == 1 ? 1000000 : league <= 3 ? 580000 : 280000; - v = rd32(r, rec + 0x880) < limit ? int32_t(limit) : 0; - } + const int32_t v = environment_monthly_cost(g, m, k); if (k >= 3 && k <= 5) add32(r, rec + 0x878 + size_t(k) * 4, v); else add32(r, rec + 0x880, v); sum += v; diff --git a/src/game/season.cpp b/src/game/season.cpp index 7bef5ec..a1915c9 100644 --- a/src/game/season.cpp +++ b/src/game/season.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "game/environment.hpp" #include "game/season.hpp" #include @@ -641,25 +642,21 @@ namespace { } // namespace -// OpenBMH deviates from the original: uses the enhanced youth-academy season settlement and player-generation rules. -// YouthAcademyPlayer(manager) with the supported rule profile patch (SeasonOperation2, SeasonOperation3, SeasonOperation4, -// SeasonOperation5): the youth academy's player at the season accounts. Only when the academy -// was paid in full this season (record +0x880 reached the league's price, TeamLeague3) and -// the squad has at most 22 players (SquadCount(team, 3)). A computer club's young player -// moves to the club: the slots 0x86f..0 of the big clubs are searched downwards (squads of -// human managers skipped) for a player not on loan whose age (years after 16) is at most -// G(t, t + 3), t starting at 15 and lowered by one for every pass that finds none. He leaves -// his club (ReleasePlayer), gets new values around a level of the club's league -// (GeneratePlayer with 0x3000: G(79, 95) first division, G(69, 85) second, G(49, 68) third, -// G(29, 48) below), a place in the squad with a fresh board entry (PendingOfferAnswer with the -// player id | 0xf000), mood 0x69 and an age of W(0, 4) (16..20). Returns whether a player -// came. The original's G(0, 0) before the search is kept. +// OpenBMH deviates from the original: retains the enhanced academy player-generation strength bands with monthly youth budgets. +// The middle youth budget enables the existing enhanced academy recruitment. +// Old lump-sum contracts remain eligible after their saved season payment. +// Player search, strength bands, age and board setup retain the shared rules. bool youth_academy_player(GameState& g, int m, GameRandom& game, WatcomRandom& rand, MinuteReport& report) { const int team = g.manager_teams.at(size_t(m)); const int league = club_league(team); - const uint32_t price = league == 0 ? 1500000 : league == 1 ? 1000000 : league <= 3 ? 580000 : 280000; - if (uint32_t(rec32(g, m, 0x880)) < price) return false; + if (!environment_academy_active(g, m)) return false; if (squad_count(g, team, 3) > 0x16) return false; + const auto budget = g.memory.u32(::bmh::layout::Spending + uint32_t(m) * 0x24 + kYouthAcademy * 4); + if (budget <= uint32_t(kEnvironmentStep[kYouthAcademy] * 6) && + g.memory.u8(::bmh::layout::CareerDuration) != 1 && + int(g.memory.u8(::bmh::layout::EnvironmentYouthTeams + uint32_t(m) * 0x24 + 2)) < + team_average(g, team, 0xf3).value - 25) + return false; const SquadRange own = squad_range(team); if (game.range(0, 0) != 0) return false; for (int t = 0xf;; --t) { @@ -708,6 +705,7 @@ namespace { void season_accounts(GameState& g, int m, GameRandom& game, WatcomRandom& rand, MinuteReport& report, const SeasonTaxHooks& tax_hooks, SeasonTaxState& tax_state) { for (size_t i = 0; i < 0xc; i++) rec8(g, m, 0x754 + i) = 0; + finish_youth_season(g, m); if (!g.memory.has(::bmh::layout::Season_SeasonAccounts_RuntimeField)) g.memory.add_block(::bmh::layout::Season_SeasonAccounts_RuntimeField, 4); // (runtime only, not saved) g.memory.set8(::bmh::layout::Season_SeasonAccounts_RuntimeField + uint32_t(m), 0); season_event(g, m, game, rand, report); @@ -720,8 +718,8 @@ void season_accounts(GameState& g, int m, GameRandom& game, WatcomRandom& rand, const SquadRange range = squad_range(team); for (size_t s = 0; s < 24; s++) if (g.squad_slots.at(range.first + s) != 0x0FFF) season_bonus(g, m, int(s), uint8_t(pos), true); - // OpenBMH deviates from the original: uses the enhanced youth-academy season settlement and player-generation rules. -// YouthAcademyPlayer: the youth academy's player (supported rule profile), posted as Season_SeasonAccounts_TextPointer + // OpenBMH deviates from the original: retains the enhanced academy player-generation strength bands with monthly youth budgets. + // Academy recruitment is posted after the youth season has settled. if (youth_academy_player(g, m, game, rand, report)) post_text(g, m, text_id(::bmh::layout::Season_SeasonAccounts_TextPointer)); if (report.unsupported) return; if (league == 0 && pos < 100) rec8(g, m, 0x21c) = 1; // the best human club of the first division diff --git a/src/game/season.hpp b/src/game/season.hpp index 42db130..1eaaf52 100644 --- a/src/game/season.hpp +++ b/src/game/season.hpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #pragma once -// OpenBMH deviates from the original: uses the enhanced youth-academy season settlement and player-generation rules. +// OpenBMH deviates from the original: retains the enhanced academy player-generation strength bands with monthly youth budgets. // From one season to the next (BMH.exe V2.24 + supported rule profile patch). // // On 1 July the "Weiter" loop (DailyInterest) ends the season: CareerSession_RuntimeError_RuntimeField4 = 1, the season @@ -94,10 +94,10 @@ void answer_offers(GameState& g, int manager, bool accept, WatcomRandom& rand, M // offer slots (transfer list entries 0x28..0x2b, OfferSlots) are freed. void free_offer_slots(GameState& g); -// OpenBMH deviates from the original: uses the enhanced youth-academy season settlement and player-generation rules. -// YouthAcademyPlayer (supported rule profile youth academy, season accounts): when manager `m` paid the academy in -// full this season (+0x880) and has room, a young player of a computer club joins his squad -// with values by the league (see season.cpp). Returns whether one came. +// OpenBMH deviates from the original: retains the enhanced academy player-generation strength bands with monthly youth budgets. +// Annual recruitment with an active middle youth budget (or a paid legacy +// academy contract), provided the squad has room. Shared player strength bands +// remain in effect; see season.cpp. bool youth_academy_player(GameState& g, int m, GameRandom& game, WatcomRandom& rand, MinuteReport& report); // ClubBalance(0): every club's mood (TeamMorale, W(20, 30)) and flags (*TeamFlags): a random diff --git a/src/ui/advertising.cpp b/src/ui/advertising.cpp index f35b930..e4c8424 100644 --- a/src/ui/advertising.cpp +++ b/src/ui/advertising.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "game/environment.hpp" #include "ui/advertising.hpp" #include "ui/game_end.hpp" @@ -182,10 +183,9 @@ AdvertisingFinancePreview original_finance_preview_impl(const GameState& game, i std::array{0,31,28,31,30,31,30,31,31,30,31,30,31}[size_t(month)]; income = wrap_add(income, wrap_neg(wrap_mul(original_finance_adjustment(game, manager), month_factor))); - // OpenBMH deviates from the original: uses the supported youth-academy cap and its saved cost fields. -// OriginalFinancePreview(0): pure amount of BMHExeXa, record +0x854/+0x858, + // OriginalFinancePreview(0): pure amount of BMHExeXa, record +0x854/+0x858, // MonthlyPay flags 0x0a (salary+bonus without statistic writes), and six - // saved supported rule profile cost words. The cap for index 1 comes from TeamLeague3. + // saved monthly environment budgets. int32_t expenses = 0; for (int i = 0; i < 14; ++i) expenses = wrap_add(expenses, kFacilityCost[size_t(i)]); for (int i = 14; i < 22; ++i) @@ -202,18 +202,8 @@ AdvertisingFinancePreview original_finance_preview_impl(const GameState& game, i expenses = wrap_add(expenses, signed32(u32(game.tactics, board + 0x50))); expenses = wrap_add(expenses, int32_t(bonus)); } - const int team = int(u32(game.manager_records, rec + 0x290) & 0xffff); - const int league = team > 0x164 ? 0 : team_league(team); // TeamLeague2 - const int32_t youth_cap = league == 0 ? 1500000 : league == 1 ? 1000000 : - league <= 3 ? 580000 : 280000; for (int k = 0; k < 6; ++k) { - int32_t item = mem_i32(game, ::bmh::layout::Spending + uint32_t(manager) * 0x24 + uint32_t(k) * 4); - if (k == 0 || k == 2) { - // MonthlyExpenses clears these indexes unconditionally (CMP AX,3 / CMP AX,1). - item = 0; - } else if (k == 1 && item != 0) { - item = u32(game.manager_records, rec + 0x880) < uint32_t(youth_cap) ? youth_cap : 0; - } + const int32_t item = environment_monthly_cost(game, manager, k); expenses = wrap_add(expenses, item); } expenses = wrap_add(expenses, wrap_neg(original_share_adjustment(game, manager, false))); diff --git a/src/ui/advertising_tests.cpp b/src/ui/advertising_tests.cpp index 6e2a5d1..6b3e566 100644 --- a/src/ui/advertising_tests.cpp +++ b/src/ui/advertising_tests.cpp @@ -167,17 +167,17 @@ int main(int argc, char** argv) { cap_fixture.memory.set32(::bmh::layout::Spending + 4, 99); cap_fixture.memory.set32(::bmh::layout::Spending, 111); cap_fixture.memory.set32(::bmh::layout::Spending + 8, 222); - check(advertising_from_game(cap_fixture, 0).finance_preview.expenses == 1543400, - "costs 0/2 stay zero while the youth-cost item uses the source league cap"); + check(advertising_from_game(cap_fixture, 0).finance_preview.expenses == 43832, + "all three youth budgets enter the monthly finance preview"); put32(cap_fixture.manager_records, 0x880, 1500000); const auto no_cap_preview = advertising_from_game(cap_fixture, 0).finance_preview; - check(no_cap_preview.expenses == 43400, - "the youth-cost item is suppressed once funds reach the strict source threshold"); + check(no_cap_preview.expenses == 43832, + "ordinary monthly youth budgets continue after the former academy threshold"); GameState ignored_cost_fixture = finance_fixture; ignored_cost_fixture.memory.set32(::bmh::layout::Spending, 111); ignored_cost_fixture.memory.set32(::bmh::layout::Spending + 8, 222); - check(advertising_from_game(ignored_cost_fixture, 0).finance_preview.expenses == 43400, - "legacy routine clears cost items zero and two regardless of their saved values"); + check(advertising_from_game(ignored_cost_fixture, 0).finance_preview.expenses == 43733, + "the youngest and oldest youth budgets both enter expenses"); GameState loan_fixture = finance_fixture; loan_fixture.memory.set32(::bmh::layout::Loans + 8, 100); const auto loan_preview = advertising_from_game(loan_fixture, 0).finance_preview; diff --git a/src/ui/environment.cpp b/src/ui/environment.cpp index 9ca40af..5d98946 100644 --- a/src/ui/environment.cpp +++ b/src/ui/environment.cpp @@ -72,6 +72,11 @@ EnvironmentView environment_from_game(const bmh::GameState& game, uint64_t revis view.values = bmh::environment_state(game, manager); for (int i = 0; i < kEnvironmentItems; ++i) view.cost_text[size_t(i)] = bmh::format_number(game, view.values.monthly[size_t(i)], 0x185); + for (size_t i = 0; i < 3; ++i) { + view.youth_position_text[i] = format_number(game, view.values.youth_position[i] + 1, 0x81); + view.youth_league_text[i] = format_number(game, view.values.youth_league[i] + 1, 2) + + message_text(game, ::bmh::layout::EnvironmentYouthLeagueTextPointer); + } view.decorated_background = !game.memory.has(::bmh::layout::PlainBackground) || game.memory.u8(::bmh::layout::PlainBackground) == 0; view.gradient_text = (!game.memory.has(::bmh::layout::TextGradientDisabled) || game.memory.u8(::bmh::layout::TextGradientDisabled) == 0); view.solid_panel_background = game.memory.has(::bmh::layout::SolidPanelBackground) && game.memory.u8(::bmh::layout::SolidPanelBackground) != 0; @@ -117,9 +122,14 @@ std::string environment_view_json(const EnvironmentView& s) { for (size_t i = 0; i < s.values.monthly.size(); ++i) { if (i) out << ','; out << s.values.monthly[i]; } out << "],\"level\":["; for (size_t i = 0; i < s.values.level.size(); ++i) { if (i) out << ','; out << s.values.level[i]; } - out << "],\"youth_price\":" << s.values.youth_price << ",\"youth_paid\":" - << (s.values.youth_paid ? "true" : "false") << ",\"youth_open\":" - << (s.values.youth_open ? "true" : "false") << '}'; + out << "],\"youth_teams\":["; + for (size_t i = 0; i < 3; ++i) { + if (i) out << ','; + out << "{\"strength\":" << int(s.values.youth_strength[i]) + << ",\"position\":" << int(s.values.youth_position[i]) + << ",\"league\":" << int(s.values.youth_league[i]) << '}'; + } + out << "]}"; return out.str(); } @@ -194,9 +204,6 @@ Image EnvironmentScreen::render() const { throw FormatError("environment: Original badge crop outside atlas"); crop(out, badge_atlas_, badge_x, 0, 0x8c, 0x61, 0x26, 0x26); for (int item = 0; item < kEnvironmentItems; ++item) { - // OpenBMH deviates from the original: omits the two discontinued youth groups from the environment screen. -// supported rule profile BypassesTwoDiscontinuedYouthGroups bypasses the two discontinued youth groups. - if (item < 3 && item != kYouthAcademy) continue; const int x = exe_.u8(::bmh::layout::Environment_FormatError_RuntimeField + item), y = exe_.u8(::bmh::layout::Environment_FormatError_RuntimeField2 + item); crop(out, tiles_, item * 0x33, 0x46, x, y, 0x33, 0x29); // CallsTwiceForUpperLowerCaptionStrips calls LoadGameEndTaxAnimationAssets twice for the upper and lower caption strips. @@ -215,25 +222,29 @@ Image EnvironmentScreen::render() const { for (int yy = top; yy <= bottom; ++yy) out.at(right, yy) = 0x40; }; panel(x - 4, y - 10, x + 0x36, y - 1); - panel(x - 4, y + 0x29, x + 0x36, y + 0x31); - const int unit = item == kYouthAcademy ? 1 : item >= 3 ? 5000 : 1; - const int count = item == kYouthAcademy ? (state_.values.monthly[size_t(item)] != 0 ? 6 : 0) - : std::clamp(state_.values.monthly[size_t(item)] / unit, 0, 6); + panel(x - 4, y + 0x29, x + 0x36, y + 0x31 + (item < 3 ? 6 : 0)); + const int count = state_.values.level[size_t(item)]; for (int star = 0; star < count; ++star) crop(out, tiles_, 0x1e, 0x1e, x + star * 9, y - 8, 7, 6, 0); // The tile artwork already contains its Source caption. CallsTwiceForUpperLowerCaptionStrips draws // the dynamic expense in the lower strip at baseline y+0x30; a second // invented TEXTD caption here overwrote the baked-in names and shifted // the cost down into the hit area. - const auto& cost = state_.cost_text[size_t(item)]; + const auto cost = state_.cost_text[size_t(item)] + exe_.cstring(::bmh::layout::EnvironmentCostSuffix); text(out, x + 0x32 / 2 - font_.text_width(cost) / 2, y + 0x30, cost, 0x6b); + if (item < 3) { + const auto caption = state_.youth_position_text[size_t(item)] + + exe_.cstring(::bmh::layout::EnvironmentYouthPositionSuffix) + state_.youth_league_text[size_t(item)]; + text(out, x + 0x32 / 2 - font_.text_width(caption) / 2, y + 0x36, + caption, exe_.u8(::bmh::layout::EnvironmentYouthColors + item)); + } } return out; } bool EnvironmentScreen::pointer_down(int x, int y, bool right) { + if (pending_) return false; press_seen_ = true; - pending_.reset(); pressed_item_ = pressed_level_ = -1; pressed_right_ = right; if (right) return true; @@ -241,7 +252,7 @@ bool EnvironmentScreen::pointer_down(int x, int y, bool right) { const int left = exe_.u8(::bmh::layout::Environment_FormatError_RuntimeField + item), top = exe_.u8(::bmh::layout::Environment_FormatError_RuntimeField2 + item); if (x >= left - 9 && x <= left + 0x36 && y >= top - 10 && y <= top + 0x29) { pressed_item_ = item; - pressed_level_ = std::clamp((x - left + 4) / 9, 0, 6); + pressed_level_ = std::clamp((x - left + 9) / 9, 0, 6); return true; } } diff --git a/src/ui/environment.hpp b/src/ui/environment.hpp index c2c3472..afbd3bd 100644 --- a/src/ui/environment.hpp +++ b/src/ui/environment.hpp @@ -26,6 +26,7 @@ struct EnvironmentView { std::string club_name; uint16_t badge_sprite = 0; std::array cost_text{}; + std::array youth_position_text{}, youth_league_text{}; bool decorated_background = true; bool gradient_text = true; bool solid_panel_background = false; diff --git a/src/ui/environment_tests.cpp b/src/ui/environment_tests.cpp index e803023..da5a7f2 100644 --- a/src/ui/environment_tests.cpp +++ b/src/ui/environment_tests.cpp @@ -33,9 +33,11 @@ void original_pixels(const std::filesystem::path& data, const LeImage& exe, const auto panel = load_vga(asset_path(data / "KB", "56.VGA")); const auto body = load_font(asset_path(data / "F", "BMH3.FNT")); SpriteFont sprite(data); - // All four visible groups exercise an empty and an occupied star rail. - state.values.monthly[1] = 0; - for (int item = 3; item < 6; ++item) state.values.monthly[size_t(item)] = 10000; + // All six visible groups exercise an empty and an occupied star rail. + for (int item = 0; item < 6; ++item) { + state.values.level[size_t(item)] = item < 3 ? 0 : 2; + state.values.monthly[size_t(item)] = state.values.level[size_t(item)] * kEnvironmentStep[size_t(item)]; + } for (int mode = 0; mode < 3; ++mode) { state.decorated_background = mode != 1; state.plain_background = mode == 2; @@ -56,9 +58,9 @@ void original_pixels(const std::filesystem::path& data, const LeImage& exe, sprite.draw(base, 5, 235, original_to_utf8(state.club_name), 5); for (int y = 0; y < 240; ++y) for (int x = 0; x < 320; ++x) { bool foreground = x >= 125 && x <= 195 && y >= 82 && y <= 151; - for (int item : {1, 3, 4, 5}) { + for (int item : {0, 1, 2, 3, 4, 5}) { const int tx = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField + item), ty = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField2 + item); - foreground |= x >= tx - 4 && x <= tx + 54 && y >= ty - 10 && y <= ty + 49; + foreground |= x >= tx - 4 && x <= tx + 54 && y >= ty - 10 && y <= ty + 49 + (item < 3 ? 6 : 0); } if (!foreground) check(pixel(actual, x, y) == pixel(base, x, y), "Source KB129/flat background, centered title and active club footer"); @@ -76,14 +78,14 @@ void original_pixels(const std::filesystem::path& data, const LeImage& exe, check(transparent_center > 0 && center_ink > 0, "central crop oracle covers transparent and ink pixels"); check(actual.at(139, 96) == 0x46 && actual.at(178, 96) == 0x40 && actual.at(139, 135) == 0x40, "Source badge frame and corner overwrite order"); - for (int item : {1, 3, 4, 5}) { + for (int item : {0, 1, 2, 3, 4, 5}) { const int tx = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField + item), ty = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField2 + item); for (int y = 0; y < 41; ++y) for (int x = 0; x < 51; ++x) check(pixel(actual, tx + x, ty + y) == pixel(art, item * 51 + x, 70 + y), "legacy routine tile is opaque, without a fabricated c0 comparekey"); // The Source upper panel is copied first; each nonzero star pixel // replaces it. A zero in the star bitmap exposes that panel. - const int stars = item == 1 ? 0 : 2; + const int stars = state.values.level[size_t(item)]; for (int y = ty - 9; y <= ty - 2; ++y) for (int x = tx - 3; x <= tx + 53; ++x) { uint8_t expected = state.solid_panel_background ? 0x42 : pixel(panel, x - 1, y - 20); for (int n = 0; n < stars; ++n) @@ -93,7 +95,7 @@ void original_pixels(const std::filesystem::path& data, const LeImage& exe, } check(pixel(actual, x, y) == expected, "Source star zero pixels expose the opaque KB56/flat rail"); } - const auto& cost = state.cost_text[size_t(item)]; + const auto cost = state.cost_text[size_t(item)] + exe.cstring(::bmh::layout::EnvironmentCostSuffix); const int width = body.text_width(cost), left = tx + 25 - width / 2; Image mask(width, body.height); body.draw(mask, 0, 0, cost, 1); @@ -171,7 +173,7 @@ int main(int argc, char** argv) { check(screen.key("ESC").kind == EnvironmentRequestKind::none && !screen.close_requested() && screen.state_json() == held, "back cannot steal a held staff control before its release"); const auto request = screen.release(x + 31, y + 5); - check(request.kind == EnvironmentRequestKind::set_item && request.item == 3 && request.level == 3 && + check(request.kind == EnvironmentRequestKind::set_item && request.item == 3 && request.level == 4 && request.manager_slot == state.manager_slot && request.runtime_club == state.runtime_club && request.revision == 17 && request.owner == owner, "tile release emits a typed, manager/revision-owned level request"); @@ -182,13 +184,13 @@ int main(int argc, char** argv) { auto updated = state; updated.revision = 18; - updated.values.level[3] = 3; - updated.values.monthly[3] = 15000; - updated.cost_text[3] = format_number(game, 15000, 0x185); + updated.values.level[3] = 4; + updated.values.monthly[3] = 20000; + updated.cost_text[3] = format_number(game, 20000, 0x185); updated.owner.revision = 18; screen.acknowledge(updated); check(!screen.pending() && screen.state().revision == 18 && - screen.state().values.monthly[3] == 15000, + screen.state().values.monthly[3] == 20000, "valid source mutation ACK refreshes the screen and clears the pending action"); const auto notice = environment_notice_dialog(game, state.manager_slot, diff --git a/src/ui/live_timing.hpp b/src/ui/live_timing.hpp new file mode 100644 index 0000000..13cfaf7 --- /dev/null +++ b/src/ui/live_timing.hpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include + +namespace bmh::ui { +// Saved column-nine delays are source timer units. Values below six use +// integer halving; zero genuinely disables the pause. +constexpr uint32_t live_delay_milliseconds(uint8_t saved) { + return uint32_t(saved < 6 ? saved / 2 : saved) * 20; +} +// VGA mode 13h timing is independent of the host monitor's refresh rate. +inline constexpr unsigned kOriginalRefreshHz = 70; +} // namespace bmh::ui diff --git a/tests/app_controller_tests.cpp b/tests/app_controller_tests.cpp index 36b22b9..166c33c 100644 --- a/tests/app_controller_tests.cpp +++ b/tests/app_controller_tests.cpp @@ -1670,6 +1670,26 @@ void check_environment_controller(const std::filesystem::path& data) { flow.environment()->state().values.level[3] == 6 && flow.environment()->state().values.monthly[3] == 30000, "valid environment transaction commits once and keeps the source screen open"); + for (int item : {0, 1, 2, 4, 5}) { + const int tx = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField + item) + 18; + const int ty = exe.u8(::bmh::layout::Environment_FormatError_RuntimeField2 + item) + 5; + const auto before = session->state(); + const auto old_revision = revision; + (void)flow.pointer_down(tx, ty); + const auto write = flow.click(tx, ty); + check(write.request == FlowRequest::environment_action && write.environment_action.item == item && + write.environment_action.level == 3 && serve(write).empty(), + "every youth and staff tile submits its own three-star budget"); + auto expected = before; + expected.memory.set32(::bmh::layout::Spending + uint32_t(item) * 4, uint32_t(kEnvironmentStep[size_t(item)] * 3)); + check(save_stream(session->state()) == save_stream(expected) && revision == old_revision + 1 && + session->rand().seed() == watcom_before.seed() && session->rand().calls() == watcom_before.calls() && + session->game().seed() == game_rng_before.seed() && session->game().calls() == game_rng_before.calls(), + "a tile edit changes only its saved budget and revision, without a turn or RNG draw"); + (void)flow.pointer_down(tx, ty); + check(serve(flow.click(tx, ty)).empty() && revision == old_revision + 1 && !flow.pending_environment(), + "clicking the same youth or staff level again ACKs without toggling or another revision"); + } (void)flow.pointer_down(10, 10, true); const auto close = flow.click(10, 10, true); check(close.request == FlowRequest::submenu_closed && !flow.in_environment() && flow.screen_name() == "desktop", @@ -3241,7 +3261,7 @@ void check_live_delay_settings_writer(const std::filesystem::path& data,const st app::CareerSession session(data,8128,save_path);auto& game=session.state(); const int manager=int(game.memory.u8(::bmh::layout::ActiveManager));uint64_t revision=1;std::string error; const auto exe=load_le(ui::asset_path(data,"BMH.exe"));const auto w=session.rand();const auto g=session.game(); - const std::array,13> cells{{{3,7},{4,7},{5,7},{6,7},{1,8},{2,8},{3,8},{4,8},{5,8},{6,8},{10,8},{12,8},{15,8}}}; + const std::array,14> cells{{{3,7},{4,7},{5,7},{6,7},{0,8},{1,8},{2,8},{3,8},{4,8},{5,8},{6,8},{10,8},{12,8},{15,8}}}; for(const auto [row,col]:cells) { auto state=settings_from_game(game,manager,revision,exe);const size_t index=size_t(row*9+col); const auto old=state.cells[index];check(old<200,"real WEEK196 exposes the consumed speed/delay cell"); @@ -6959,6 +6979,9 @@ int main(int argc, char** argv) { try { if (argc != 2 && argc != 3 && argc != 4) throw std::runtime_error("app_controller_tests requires data directory [optional Original save]"); const std::filesystem::path data = argv[1]; + if(argc==3 && std::string_view(argv[2])=="--environment-only") { + check_environment_controller(data);return 0; + } if(argc==4 && std::string_view(argv[2])=="--delay-settings-only") { check_live_delay_settings_writer(data,argv[3]);check_gameplay_switches_writer(data,argv[3]); check_settings_refusal_controller(data,argv[3]);return 0; diff --git a/tests/environment_tests.cpp b/tests/environment_tests.cpp index a804838..050706e 100644 --- a/tests/environment_tests.cpp +++ b/tests/environment_tests.cpp @@ -1,91 +1,81 @@ -#include "runtime_fixture_tables.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" -#include "test_inputs.hpp" -// The club environment (desk menu 24, src/game/environment.hpp) on a real savegame: staff -// levels, and the supported edition youth academy - only in July/August, the league's season price, -// no switching off once paid. - -#include +#include "game/environment.hpp" +#include "ui/live_timing.hpp" #include #include -#include - -#include "formats/fbm.hpp" -#include "formats/le.hpp" -#include "formats/savestate.hpp" -#include "formats/textd.hpp" -#include "game/career.hpp" -#include "game/environment.hpp" -#include "game/schedule.hpp" using namespace bmh; - namespace { - -void check(bool ok, const std::string& message) { - if (!ok) throw std::runtime_error(message); -} - -void set_rec32(GameState& g, size_t o, uint32_t v) { - for (int i = 0; i < 4; i++) g.manager_records.at(o + size_t(i)) = uint8_t(v >> (8 * i)); -} - -void environment_test(GameState g) { - // staff: level * 5 000 - check(set_environment(g, 0, kDoctor, 4) != EnvironmentResult::invalid, "doctor level"); - EnvironmentState s = environment_state(g, 0); - check(s.monthly[kDoctor] == 20000 && s.level[kDoctor] == 4, "doctor 4 x 5 000"); - check(set_environment(g, 0, kPhysio, 7) == EnvironmentResult::invalid, "level 7 is no level"); - // the other two youth groups are always 0 - set_environment(g, 0, 0, 6); - check(environment_state(g, 0).monthly[0] == 0, "item 0 stays 0"); - // the academy out of season (the savegame is in spring) - set_rec32(g, 0x880, 0); - std::string message; - check(set_environment(g, 0, kYouthAcademy, 6, &message) == EnvironmentResult::too_late, "too late in spring"); - check(message.find("Zu sp") == 0 && environment_state(g, 0).monthly[kYouthAcademy] == 0, "too late message, stays off"); - // July: on at the league's price, a second click switches it off again before it is paid - g.date = g.season_start + 5; - g.league_rounds.at(0) = 0; - s = environment_state(g, 0); - check(s.youth_open && !s.youth_paid, "July: the academy can be started"); - check(set_environment(g, 0, kYouthAcademy, 6) == EnvironmentResult::changed, "academy on"); - const int league = team_league(g.manager_teams.at(0)); - const int32_t price = league == 0 ? 1500000 : league == 1 ? 1000000 : league <= 3 ? 580000 : 280000; - check(environment_state(g, 0).monthly[kYouthAcademy] == price, "season price of the league"); - check(set_environment(g, 0, kYouthAcademy, 6) == EnvironmentResult::changed && - environment_state(g, 0).monthly[kYouthAcademy] == 0, "a click on the active academy switches it off"); - // paid this season: stays on - set_environment(g, 0, kYouthAcademy, 6); - set_rec32(g, 0x880, uint32_t(price)); - message.clear(); - check(set_environment(g, 0, kYouthAcademy, 0, &message) == EnvironmentResult::contract_runs, "paid: no switching off"); - check(message == bmh::test::expected_text("environment_tests.0") && environment_state(g, 0).monthly[kYouthAcademy] == price, - "paid: the contract runs"); -} - -} // namespace - -int main(int argc, char** argv) { - try { - check(argc == 3, "usage: environment_tests ORIGINAL_DATA SAVEGAME"); - if (!*argv[1]) { - std::cout << "environment tests: skipped (Original data directory not configured)\n"; - return 0; +void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +GameState fixture() { + GameState g; + g.manager_teams = {0, 1}; + g.manager_records.resize(2 * 0xb0c); + g.league_rounds.resize(1); + g.memory.add_block(layout::EnvironmentYouthTeams, 0x90); + for (uint32_t m = 0; m < 2; ++m) + for (uint32_t i = 0; i < 3; ++i) { + g.memory.set8(layout::EnvironmentYouthTeams + m * 0x24 + i, uint8_t(60 - i * 10)); + g.memory.set8(layout::EnvironmentYouthTeams + m * 0x24 + i + 3, 6); + g.memory.set8(layout::EnvironmentYouthTeams + m * 0x24 + i + 6, uint8_t(i)); } - const auto exe = bmh::test::load_executable(std::filesystem::path(argv[1]) / "BMH.exe"); - const auto file = load_savegame(argv[2]); - const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)}; - GameState g = GameState::from_save(SaveState(file.stream, counts), counts); - competition_pointers(g.memory, exe); - const auto texts = load_textd(std::filesystem::path(argv[1]) / "TEXTD.BLK"); - g.texts = &texts; - environment_test(g); - std::cout << "environment tests: ok\n"; - return 0; - } catch (const std::exception& error) { - std::cerr << "environment tests: " << error.what() << "\n"; - return 1; - } + return g; +} +void budgets() { + auto g = fixture(); + for (int i = 0; i < 6; ++i) check(set_environment(g, 0, i, 6) == EnvironmentResult::changed, "all six budgets accept maximum"); + const auto s = environment_state(g, 0); + check(s.monthly == std::array{12000,24000,30000,30000,30000,30000}, "six monthly costs match the supported price units"); + check(environment_state(g, 1).monthly == std::array{}, "other manager's budgets are isolated"); + check(set_environment(g, 0, kYouthAcademy, 6) == EnvironmentResult::unchanged, "repeating a level does not toggle the youth budget"); + for (int i = 0; i < 6; ++i) check(environment_monthly_cost(g, 0, i) == s.monthly[size_t(i)], "all six selected budgets reach monthly accounting"); + check(set_environment(g, 0, kYouthAcademy, 0) == EnvironmentResult::changed && !environment_academy_active(g, 0), "youth budget can be stopped"); + check(set_environment(g, 0, 6, 2) == EnvironmentResult::invalid && + set_environment(g, -1, 0, 1) == EnvironmentResult::invalid && + set_environment(g, 0, 0, 7) == EnvironmentResult::invalid, "invalid requests rejected"); + g.memory.set32(layout::Spending + 4, 1500000); + check(environment_monthly_cost(g, 0, 1) == 1500000 && !environment_academy_active(g, 0), "unpaid legacy contract retains one season payment"); + for (int i = 0; i < 4; ++i) g.manager_records[0x880 + size_t(i)] = uint8_t(1500000u >> (i * 8)); + check(environment_monthly_cost(g, 0, 1) == 0 && environment_academy_active(g, 0), "paid legacy contract is never debited again"); + set_environment(g, 0, 1, 2); + check(environment_monthly_cost(g, 0, 1) == 8000 && environment_academy_active(g, 0), "an explicit edit replaces the legacy contract with a monthly budget"); +} +void progression() { + auto funded = fixture(), unfunded = fixture(); + for (int i = 0; i < 3; ++i) set_environment(funded, 0, i, 6); + WatcomRandom rich(4711), poor(4711); + for (int round = 0; round < 100; ++round) { + funded.league_rounds[0] = unfunded.league_rounds[0] = uint8_t(round % 34); + advance_youth_teams(funded, 0, rich); + advance_youth_teams(unfunded, 0, poor); + } + const auto a = environment_state(funded, 0), b = environment_state(unfunded, 0); + check(a.youth_strength[0] > b.youth_strength[0] && a.youth_strength[1] > b.youth_strength[1] && + a.youth_strength[2] > b.youth_strength[2], "investment changes development in every youth group"); + check(rich.seed() == poor.seed() && rich.calls() == poor.calls(), "budgets do not change the youth algorithm's RNG call sequence"); + check(environment_state(funded, 1).youth_position == std::array{6,6,6}, "youth results remain manager-local"); + auto g = fixture(); + for (uint32_t i = 0; i < 3; ++i) g.memory.set8(layout::EnvironmentYouthTeams + i, uint8_t(30 + 20 * i)); + g.memory.set8(layout::EnvironmentYouthTeams + 3, 0); + g.memory.set8(layout::EnvironmentYouthTeams + 6, 1); + g.memory.set8(layout::EnvironmentYouthTeams + 4, 11); + g.memory.set8(layout::EnvironmentYouthTeams + 7, 0); + g.memory.set8(layout::EnvironmentYouthTeams + 5, 11); + finish_youth_season(g, 0); + const auto s = environment_state(g, 0); + check(s.youth_league == std::array{0,1,2} && s.youth_position == std::array{10,1,5}, "season transition handles promotion, relegation and bottom division"); + check(s.youth_strength == std::array{30,43,63}, "age-group handover uses previous strengths without cascading"); +} +void timing() { + using bmh::ui::live_delay_milliseconds; + check(live_delay_milliseconds(0) == 0 && live_delay_milliseconds(1) == 0 && + live_delay_milliseconds(2) == 20 && live_delay_milliseconds(5) == 40 && + live_delay_milliseconds(6) == 120 && live_delay_milliseconds(30) == 600 && + live_delay_milliseconds(198) == 3960, "original integer delay scale includes zero and manual speed range"); +} +} +int main() { + try { budgets(); progression(); timing(); std::cout << "environment and live timing: ok\n"; return 0; } + catch (const std::exception& e) { std::cerr << e.what() << '\n'; return 1; } } diff --git a/tests/youth_academy_tests.cpp b/tests/youth_academy_tests.cpp index 6cd9eb5..c7ec3e9 100644 --- a/tests/youth_academy_tests.cpp +++ b/tests/youth_academy_tests.cpp @@ -39,7 +39,20 @@ void youth_test(GameState g) { GameRandom game(4711); WatcomRandom rand(815); MinuteReport report; + auto monthly = g; + monthly.memory.set32(::bmh::layout::Spending + 4, 8000); + monthly.memory.set8(::bmh::layout::CareerDuration, 0); + monthly.memory.set8(::bmh::layout::EnvironmentYouthTeams + 2, 10); + check(team_average(monthly, team, 0xf3).value > 35, "fixture has a stronger senior squad"); + check(!youth_academy_player(monthly, 0, game, rand, report) && game.calls() == 0 && rand.calls() == 0, + "monthly recruitment requires the oldest youth team's strength without consuming RNG on refusal"); + monthly.memory.set8(::bmh::layout::EnvironmentYouthTeams + 2, 85); + GameRandom monthly_game(4711); + WatcomRandom monthly_rand(815); + check(youth_academy_player(monthly, 0, monthly_game, monthly_rand, report) && !report.unsupported, + "an active monthly budget and sufficiently strong youth team recruit without a season lump sum"); // unpaid: nothing happens, nothing is drawn + g.memory.set32(::bmh::layout::Spending + 4, price); set_rec32(g, 0x880, price - 1); check(!youth_academy_player(g, 0, game, rand, report) && game.calls() == 0 && rand.calls() == 0, "unpaid academy"); // paid diff --git a/tools/public_release/check_public_tree.py b/tools/public_release/check_public_tree.py index ca7d31c..b029b04 100644 --- a/tools/public_release/check_public_tree.py +++ b/tools/public_release/check_public_tree.py @@ -65,6 +65,8 @@ SECRET_PATTERNS = ( re.compile(r"(?m)^(?:export\s+)?[A-Z_]*(?:TOKEN|PASSWORD|SECRET|API_KEY)\s*=\s*[A-Za-z0-9_./+-]{20,}(?:\s|$)"), ) EMAIL = re.compile(r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", re.IGNORECASE) +# Resolution-qualified artwork names are filenames, including in older commits. +SIZED_ASSET_NAME = re.compile(r"[A-Z0-9._+-]+@[1-9][0-9]{0,4}\.(?:png|jpe?g|webp|svg|gif|avif)", re.IGNORECASE) # Project bot identities and the co-author trailer address are not personal data. BOT_EMAILS = {"codex@openbmh.invalid", "claude@openbmh.invalid", "noreply@anthropic.com"} HEX_NUMBER = re.compile(r"\b0x(?P[0-9a-f]{5,8})(?:u(?:ll?|z)?|ll?u?|z)?\b", re.IGNORECASE) @@ -187,7 +189,7 @@ def scan_blob(name: str, blob: bytes) -> list[Finding]: for match in pattern.finditer(text): result.append(Finding(name, line_at(text, match.start()), rule)) for match in EMAIL.finditer(text): - if match.group().lower() not in BOT_EMAILS: + if match.group().lower() not in BOT_EMAILS and not SIZED_ASSET_NAME.fullmatch(match.group()): result.append(Finding(name, line_at(text, match.start()), "personal-email")) if PurePosixPath(name).suffix.lower() in SOURCE_SUFFIXES: result.extend(layout_findings(name, text)) diff --git a/tools/public_release/test_public_tree.py b/tools/public_release/test_public_tree.py index 737f001..cf589cb 100644 --- a/tools/public_release/test_public_tree.py +++ b/tools/public_release/test_public_tree.py @@ -20,6 +20,12 @@ class BlobChecks(unittest.TestCase): def rules(self, name, text): return {finding.rule for finding in guard.scan_blob(name, text.encode())} + def test_resolution_asset_names_are_not_personal_emails(self): + for filename in ["crest@128.png", "icon@64.svg", "photo@1024.webp"]: + self.assertNotIn("personal-email", self.rules("docs/formats/EXAMPLE.md", filename)) + for address in ["person@" + "128.example.org", "person@" + "abc.png", "person@" + "example.org"]: + self.assertIn("personal-email", self.rules("README.md", address)) + def test_legacy_names_without_english_word_false_positives(self): self.assertIn("legacy-address-symbol", self.rules("src/a.cpp", "FUN" + "_00012345();")) self.assertIn("legacy-address-symbol", self.rules("src/a.cpp", "raw_" + "ba384"))