diff --git a/CMakeLists.txt b/CMakeLists.txt index e22c798..31eb59d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1245,6 +1245,9 @@ add_test(NAME modern_shirt_number_tests COMMAND modern_shirt_number_tests) add_executable(modern_estates_tests tests/modern_estates_tests.cpp) target_link_libraries(modern_estates_tests PRIVATE bmh_season_modern) add_test(NAME modern_estates_tests COMMAND modern_estates_tests) +add_executable(modern_expansion_tests tests/modern_expansion_tests.cpp) +target_link_libraries(modern_expansion_tests PRIVATE bmh_season_modern) +add_test(NAME modern_expansion_tests COMMAND modern_expansion_tests) add_executable(modern_almanac_tests tests/modern_almanac_tests.cpp) target_link_libraries(modern_almanac_tests PRIVATE bmh_modern_content) add_test(NAME modern_almanac_tests COMMAND modern_almanac_tests) diff --git a/docs/DIFFERENCES.md b/docs/DIFFERENCES.md index bb05607..932cbfa 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -53,6 +53,7 @@ describe deliberate changes; they are not a list of every known compatibility li - [src/modern/game/matchday_setup.cpp](../src/modern/game/matchday_setup.cpp): in Modern worlds a referee may take a second match on a day with more matches than referees. - [src/modern/game/month.cpp](../src/modern/game/month.cpp): in Modern every manager receives the monthly dividend of his own shares; the price product is kept in 64 bits until the division. - [src/modern/game/estates.cpp](../src/modern/game/estates.cpp): Modern adds four properties to the bank whose prices move monthly and which pay a monthly rent. +- [src/modern/game/expansions.cpp](../src/modern/game/expansions.cpp): in Modern the V.I.P. lounge, the shopping centre, the clubhouse, the car park and the restaurant can be extended in further stages, which cost money and time and bring a monthly income. - [src/modern/game/marketing.cpp](../src/modern/game/marketing.cpp): in Modern a monthly budget for international marketing builds up reach abroad, which brings monthly income by league and prestige. - [src/modern/game/naming_rights.cpp](../src/modern/game/naming_rights.cpp): in Modern a manager names his stadium and can sell the name to a sponsor for one to five years; the sponsor pays monthly and the name is fixed until the contract ends. - [src/modern/game/season.cpp](../src/modern/game/season.cpp): retains the enhanced academy player-generation strength bands with monthly youth budgets. diff --git a/docs/new_engine/README.md b/docs/new_engine/README.md index 4ecd8bf..b72e7b6 100644 --- a/docs/new_engine/README.md +++ b/docs/new_engine/README.md @@ -16,6 +16,7 @@ Grundlage ist der [Engine-Split](../ENGINE_SPLIT.md); die Oberfläche ist in | [Internationale Vermarktung](vermarktung.md) | Monatsbudget, Reichweite im Ausland, Einnahmen | | [Rückennummern](rueckennummern.md) | Nummern 1–99 je Spieler, eindeutig im Kader, änderbar | | [Immobilien](immobilien.md) | vier weitere Immobilien der Bank mit Preisgang und Miete | +| [Ausbaustufen](ausbaustufen.md) | weitere Stufen von V.I.P.-Lounge und vier Peripheriegebäuden | | [Datenformat](datenformat.md) | **Formatänderungen für Engine und Editor** (F1–F8) | | [Agentenregeln](AGENTS.md) | Arbeitsregeln für diesen Bereich | diff --git a/docs/new_engine/ausbaustufen.md b/docs/new_engine/ausbaustufen.md new file mode 100644 index 0000000..0cc9e82 --- /dev/null +++ b/docs/new_engine/ausbaustufen.md @@ -0,0 +1,54 @@ +# Ausbaustufen von Lounge und Peripherie · Modern-Engine + +Stand: 17. November 2026. Eine Modern-Regel über dem Original, das die V.I.P.-Lounge und diese +Gebäude nur als gebaut oder nicht gebaut kennt. Die Regeln des Originals für Bau, Zustand und +Einnahmen bleiben unverändert. + +## Regel + +| Gebäude | Stufen | Preis der 2. Stufe | Einnahme je weiterer Stufe und Monat (1. Liga) | +|---|---|---|---| +| V.I.P.-Lounge | 4 | 1 200 000 € | 45 000 € | +| Einkaufszentrum | 3 | 1 300 000 € | 40 000 € | +| Clubhaus | 3 | 600 000 € | 18 000 € | +| Parkplatz | 4 | 400 000 € | 12 000 € | +| Restaurant | 2 | 500 000 € | 16 000 € | + +- Stufe 1 ist das Gebäude, wie das Original es baut. Ausbauen lässt es sich nur, wenn es + steht und nicht selbst im Bau ist (Lounge: Ausstattung 3 auf Stufe 2; Peripherie: Objekte + 2 bis 5 des Stadions). +- Die dritte Stufe kostet das Doppelte, die vierte das Dreifache der zweiten. Die Bauzeit + beträgt 3, 4 und 5 Monate. Es wird je Gebäude nur eine Stufe zugleich gebaut. Bezahlt wird + beim Auftrag; reicht das Konto samt Kreditrahmen nicht, wird er abgelehnt. +- Jede fertige weitere Stufe bringt mit dem Monatswechsel Einnahmen: den Satz der ersten + Liga, in der zweiten 65 %, in der dritten 40 %, darunter 25 %. Steht das Gebäude nicht + mehr, ruhen die Einnahmen; die Stufen bleiben. +- Keine Zufallszahl. Vierter Schritt von `month_change` (`modern::expansions_month`). +- Bei einem [Vereinswechsel](hauptversammlung.md) bleiben die Stufen beim alten Stadion. + +## Speichern + +`state/modern.json` erhält das optionale Feld `expansions`: je Managerplatz `stage` (fünf +fertige weitere Stufen) und `months` (fünf Restbauzeiten). + +## Anbindung + +Read `stadium`: `expansions[]` mit `id` (`expansion:lounge`, `mall`, `clubhouse`, `parking`, +`restaurant`), `objectId`, `name`, `stage`, `maxStage`, `monthsLeft`, `monthlyIncome`, +`nextPrice`, `nextMonths`, `available`. Befehl `stadium.expand {expansionId, confirmed: true}` +(Fehler `confirmation_required`, `unknown_expansion`, `expansion_refused`). + +## Prüfung + +`modern_expansion_tests` (ohne Spieldaten): Stufe 1 nur für Gebautes, Preis und Bauzeit, +Ablehnung ohne Gebäude, während des Baus und ohne Geld, Bau über die Monate, Einnahme ab +Fertigstellung, letzte Stufe, Einnahme nach Liga, Lounge im Bau zählt nicht als gebaut. + +## Offen + +- Die Stufen sind auf der Stadionseite nur als Liste (Knopf „Ausbaustufen“) zu sehen, nicht + im Kartonmodell. +- Die Wirkung der Lounge auf Zuschauer und Preise bleibt die des Originals; die weiteren + Stufen bringen nur die monatliche Einnahme. +- Einnahmen und Baukosten sind einfache Buchungen ohne eigenen Bilanzposten. +- Sätze nicht in einem Langlauf gemessen. diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index fb93003..43d17d2 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. Dazu `internationalMarketing` (`budget`, `maxBudget`, `reach`, `targetReach`, `maxReach` in Promille, `income`, `incomeAtTarget`) | -| `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 %). Dazu der Name: `name` (wie das Stadion heißt), `worldName` (Name des Datensatzes), `nameEditable`, `namingRights` (`null` oder `{sponsor, monthly, monthsLeft}`) und `namingOffers[]` (`id`, `sponsor`, `name`, `monthly`, `months`, `total`) | +| `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 %). Dazu der Name: `name` (wie das Stadion heißt), `worldName` (Name des Datensatzes), `nameEditable`, `namingRights` (`null` oder `{sponsor, monthly, monthsLeft}`) und `namingOffers[]` (`id`, `sponsor`, `name`, `monthly`, `months`, `total`) sowie `expansions[]` (`id`, `objectId`, `name`, `stage`, `maxStage`, `monthsLeft`, `monthlyIncome`, `nextPrice`, `nextMonths`, `available`) | | `balance` | `view` current/real/future, optional `edits [{id: balance:<0–17>, amount: Money}]`; liefert ursprüngliche Posten/Labels/Grenzen, sechs Zusatzwerte, Abschreibung, Nettoergebnis und Bilanzwarnung. Prognose auf eigener Kopie, kein RNG/Live-Publish. | | `achievements` | Reine Manager-Saisonhistorie am Vereinsschreibtisch: `managerId`, aktuelles `teamId`, `currentSeasonYear`, `records` mit Jahr/Abschlussstatus, Liga-ID/Platz/Teilnehmerzahl und ursprünglichen Pokal-/Europapokalständen samt Text. Keine historische Vereinszuordnung erfinden. `available` bedeutet vorhandene Aufzeichnungen; `originalMenuAvailable` nennt zusätzlich die bisherige Ligaspiel-Sperre. Abgeschlossene Daten bleiben in der Modern UI auch zwischen Saisons lesbar; ungespielte neue Saisons werden nicht ergänzt. Kein RNG oder Schreibvorgang. | | `transfer` | die Transferliste (`listing:`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Monat, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen; `details` je Spieler mit vollständigem Namen, Nationalität, Foto, Kondition/Technik/Form und sieben Fähigkeiten; `activeStrengths`/`teamStrengths` enthalten vier Positionen und Gesamtschnitt. `ownBid.monthlySalary` ist das gespeicherte Monatsgehalt; `annualSalary` bleibt als früher irreführend benannter Alias erhalten. `salaryReferencePeriod: month`. `loanAvailable` sperrt vereinslose Anbieter; `offerTerms` liefert Kauf-/Leihgebühr, jeweilige maximale Gebühr und maximales Monatsgehalt aus den Original-Editorgrenzen. `ownBid.loan` bezeichnet die gespeicherte Leihart. `ownBid.bonuses` sind sieben gespeicherte Prämienstufen. Die Projektion und Gebotsprüfung verwenden den weltabhängigen Modern-Pool, nicht Classic `0xb70` (#24). | @@ -97,6 +97,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `manager.clubChange` | `teamId`, `confirmed: true` | der Manager wechselt zu einem der interessierten Vereine des Reads `assembly` und beginnt dort mit dessen Kasse ([Regeln](hauptversammlung.md)). Fehler: `confirmation_required`, `not_at_desk`, `no_club` (Bundestrainer), `club_change_refused` (Verein nicht auf der Liste) | | `lineup.setNumber` | `playerId`, `number` 1–99 | die [Rückennummer](rueckennummern.md) eines Spielers des eigenen Vereins; wer die Nummer trug, übernimmt die bisherige des Spielers. Fehler: `no_club`, `unknown_player`, `invalid_number` | | `marketing.commit` | `budget` (`Money`, 0–500 000 € in ganzen Tausendern) | das Monatsbudget der [internationalen Vermarktung](vermarktung.md). Fehler: `no_club`, `invalid_budget` | +| `stadium.expand` | `expansionId` (aus `expansions` des Reads `stadium`), `confirmed: true` | beginnt die nächste [Ausbaustufe](ausbaustufen.md) von Lounge oder Peripheriegebäude und bezahlt sie. Fehler: `confirmation_required`, `unknown_expansion`, `expansion_refused` | | `stadium.rename` | `name` | benennt das eigene Stadion ([Regeln](namensrecht.md)): 1–40 Zeichen. Fehler: `no_club`, `invalid_name`, `name_sold` (der Name ist verkauft) | | `stadium.namingRights` | `offerId` (`naming:` aus dem Read `stadium`), `confirmed: true` | verkauft den Stadionnamen an den Sponsor des Angebots; er zahlt mit jedem Monatswechsel. Fehler: `confirmation_required`, `name_sold`, `unknown_offer` | | `toto.submit` | `stake` (`Money` je Spalte), `columns` (bis 6 Spalten mit 11 Tipps: 1 Heim, 0 Unentschieden, 2 Auswärts) | gibt den Tippschein ab; Fehler `toto_refused` (z. B. kein offener Schein, Einsatzgrenzen, doppelte Spalte) | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index b07ca50..6350315 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -16,6 +16,7 @@ #include "modern/game/marketing.hpp" #include "modern/game/shirt_numbers.hpp" #include "modern/game/estates.hpp" +#include "modern/game/expansions.hpp" #include "modern/game/balance_plan.hpp" #include "modern/game/bank_credit.hpp" #include "modern/game/career.hpp" @@ -9497,6 +9498,25 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co A history,table; for(size_t curve=0;curve<6;++curve){A values,absolute,relative;for(const auto value:data.series[curve])values.push_back(int64_t(value));auto graph=data;bool absolute_ok=true,relative_ok=true;try{graph.flags=0x7f;for(const auto& [x,y]:ui::stadium_data_points(graph,exe_,int(curve)))absolute.push_back(A{cli::Json(x),cli::Json(y)});}catch(const std::exception&){absolute_ok=false;}try{graph.flags=0xbf;for(const auto& [x,y]:ui::stadium_data_points(graph,exe_,int(curve)))relative.push_back(A{cli::Json(x),cli::Json(y)});}catch(const std::exception&){relative_ok=false;}history.push_back(O{{"name",ui::original_to_utf8(exe_.cstring(exe_.u32(::bmh::layout::Analytics_FormatError_ExecutableField+(6+uint32_t(curve))*4)))},{"values",std::move(values)},{"absolute",std::move(absolute)},{"relative",std::move(relative)},{"absoluteAvailable",absolute_ok},{"relativeAvailable",relative_ok}});} for(size_t row=0;row(confirmed->value) || !std::get(confirmed->value)) + return refuse("confirmation_required", "Der Ausbau muss bestätigt werden (confirmed: true)."); + static constexpr const char* kExpansionId[modern::kExpansions] = {"lounge", "mall", "clubhouse", "parking", "restaurant"}; + int item = -1; + for (int k = 0; k < modern::kExpansions; ++k) + if (ui_text(*payload, "expansionId") == std::string("expansion:") + kExpansionId[k]) item = k; + if (item < 0) return refuse("unknown_expansion", "Diesen Ausbau gibt es nicht."); + if (!modern::start_expansion(g_, manager, modern::Expansion(item))) + return refuse("expansion_refused", "Ausbau nicht möglich: Das Gebäude steht nicht, wird gerade ausgebaut, ist fertig ausgebaut, oder das Konto reicht nicht."); + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"stadium", "desktop"}, "Der Ausbau hat begonnen."); } else if (kind == "lineup.setNumber") { // payload {playerId, number 1-99}: the shirt number of a player of the manager's club; the // player who wore the number takes the other's (rueckennummern.md) diff --git a/src/modern/content/ui_contract.cpp b/src/modern/content/ui_contract.cpp index 5a5e1dd..5b382e4 100644 --- a/src/modern/content/ui_contract.cpp +++ b/src/modern/content/ui_contract.cpp @@ -152,7 +152,7 @@ A allowed_commands(const ModernState& g, const UiContext& c) { const int team = team_of(g, c.manager); const bool national = team == no_team(); static constexpr const char* kAll[] = { - "session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "lineup.setFormation", "tactics.commit", "friendly.book", "manager.resign.commit", "manager.clubChange", "stadium.rename", "stadium.namingRights", "marketing.commit", "lineup.setNumber", + "session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "lineup.setFormation", "tactics.commit", "friendly.book", "manager.resign.commit", "manager.clubChange", "stadium.rename", "stadium.namingRights", "marketing.commit", "lineup.setNumber", "stadium.expand", "training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer", "stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit", "sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel", "news.update", "balance.commit", "settings.commit", "manager.join.commit"}; diff --git a/src/modern/content/world_save.cpp b/src/modern/content/world_save.cpp index 799f99d..7a16a6e 100644 --- a/src/modern/content/world_save.cpp +++ b/src/modern/content/world_save.cpp @@ -194,6 +194,15 @@ void save_world_career(const std::filesystem::path& path, const World& world, co return J(std::move(rows)); }()}, {"dismissals", state.dismissals}, + {"expansions", [&] { + A rows; + for (const auto& e : state.expansions) { + A stage, months; + for (size_t k = 0; k < 5; ++k) stage.push_back(int64_t(e.stage[k])), months.push_back(int64_t(e.months[k])); + rows.push_back(O{{"stage", std::move(stage)}, {"months", std::move(months)}}); + } + return J(std::move(rows)); + }()}, {"estates", [&] { A rows; for (const auto& held : state.estates) rows.push_back(A{J(int64_t(held[0])), J(int64_t(held[1])), J(int64_t(held[2])), J(int64_t(held[3]))}); @@ -294,6 +303,19 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl if (const auto it = o->find("dismissals"); it != o->end() && std::holds_alternative(it->second.value)) out.state.dismissals = std::get(it->second.value); } + // further stages of lounge and periphery (since 17 November 2026) + if (o->count("expansions")) + for (const J& row : arr(get(modern, "expansions"))) { + const A& stage = arr(get(row, "stage")); + const A& months = arr(get(row, "months")); + if (stage.size() != 5 || months.size() != 5) fail("invalid expansions"); + ModernState::Expansions e; + for (size_t k = 0; k < 5; ++k) { + if (num(stage[k]) < 0 || num(stage[k]) > 3 || num(months[k]) < 0 || num(months[k]) > 12) fail("invalid expansions"); + e.stage[k] = uint8_t(num(stage[k])), e.months[k] = uint8_t(num(months[k])); + } + out.state.expansions.push_back(e); + } // the four further properties (since 17 November 2026) if (o->count("estates") && o->count("estate_prices")) { for (const J& row : arr(get(modern, "estates"))) { diff --git a/src/modern/game/career.cpp b/src/modern/game/career.cpp index def0460..e030fa4 100644 --- a/src/modern/game/career.cpp +++ b/src/modern/game/career.cpp @@ -698,6 +698,7 @@ bool change_club(ModernState& g, const LeImage& exe, int m, int team, int32_t ca } if (size_t(m) < g.pools.size()) g.pools[size_t(m)] = {}; if (size_t(m) < g.exclusive_sponsors.size()) g.exclusive_sponsors[size_t(m)] = {}; + if (size_t(m) < g.expansions.size()) g.expansions[size_t(m)] = {}; // the further stages stand at the old ground if (size_t(m) < g.estates.size()) g.estates[size_t(m)] = {}; // his further properties stay behind as well if (size_t(m) < g.marketing.size()) g.marketing[size_t(m)] = {}; // the reach abroad was the old club's if (size_t(m) < g.stadiums.size()) g.stadiums[size_t(m)] = {}; // the name and its sponsor belong to the old ground diff --git a/src/modern/game/expansions.cpp b/src/modern/game/expansions.cpp new file mode 100644 index 0000000..90d486c --- /dev/null +++ b/src/modern/game/expansions.cpp @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/game/expansions.hpp" + +#include + +#include "game/schedule.hpp" +#include "modern/game/matchday.hpp" + +namespace bmh::modern { +namespace { + +constexpr size_t kRecord = 0xb0c; +// The periphery objects of the four buildings (record +object: its state, +0x1e +object: days +// under construction); the lounge is facility 3 (+0x3c + 3 its level, +0x2c + 3 its weeks). +constexpr std::array kObject{-1, 2, 3, 4, 5}; +// What a further stage costs (times its number) and brings a month in the first league. +constexpr std::array kStagePrice{1200000, 1300000, 600000, 400000, 500000}; +constexpr std::array kStageIncome{45000, 40000, 18000, 12000, 16000}; +constexpr int kLeaguePercent[5] = {100, 65, 40, 25, 25}; + +int league_club(const ModernState& g, int manager) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size() || g.manager_records.size() < size_t(manager + 1) * kRecord) return -1; + const int team = g.manager_teams[size_t(manager)]; + return team >= 0 && team < league_clubs() ? team : -1; +} +int extra(const ModernState& g, int manager, Expansion item) { + return manager >= 0 && size_t(manager) < g.expansions.size() ? g.expansions[size_t(manager)].stage[size_t(item)] : 0; +} + +} // namespace + +bool expansion_base_built(const ModernState& g, int manager, Expansion item) { + if (league_club(g, manager) < 0) return false; + const size_t rec = size_t(manager) * kRecord; + if (item == Expansion::lounge) return (g.manager_records[rec + 0x3c + 3] & 7) == 2 && g.manager_records[rec + 0x2c + 3] == 0; + const size_t object = size_t(kObject[size_t(item)]); + return g.manager_records[rec + object] != 0 && g.manager_records[rec + 0x1e + object] == 0; +} + +int expansion_stage(const ModernState& g, int manager, Expansion item) { + return expansion_base_built(g, manager, item) ? 1 + extra(g, manager, item) : 0; +} + +int expansion_months_left(const ModernState& g, int manager, Expansion item) { + return manager >= 0 && size_t(manager) < g.expansions.size() ? g.expansions[size_t(manager)].months[size_t(item)] : 0; +} + +int32_t expansion_price(const ModernState& g, int manager, Expansion item) { + const int next = extra(g, manager, item) + 1; + return next + 1 > kExpansionStages[size_t(item)] ? 0 : kStagePrice[size_t(item)] * next; +} + +int expansion_build_months(const ModernState& g, int manager, Expansion item) { + const int next = extra(g, manager, item) + 1; + return next + 1 > kExpansionStages[size_t(item)] ? 0 : 2 + next; +} + +int32_t expansion_income(const ModernState& g, int manager, Expansion item) { + const int team = league_club(g, manager); + if (team < 0 || !expansion_base_built(g, manager, item)) return 0; + return kStageIncome[size_t(item)] * extra(g, manager, item) * kLeaguePercent[std::clamp(team_league(team), 0, 4)] / 100; +} + +// OpenBMH deviates from the original: in Modern the V.I.P. lounge, the shopping centre, the clubhouse, the car park and the restaurant can be extended in further stages, which cost money and time and bring a monthly income. +bool start_expansion(ModernState& g, int manager, Expansion item) { + const int32_t price = expansion_price(g, manager, item); + if (!expansion_base_built(g, manager, item) || price == 0 || expansion_months_left(g, manager, item) != 0) return false; + const int months = expansion_build_months(g, manager, item); + if (!modern::book_money(g, manager, price, false)) return false; + if (g.expansions.size() <= size_t(manager)) g.expansions.resize(size_t(manager) + 1); + g.expansions[size_t(manager)].months[size_t(item)] = uint8_t(months); + return true; +} + +void expansions_month(ModernState& g) { + for (size_t m = 0; m < g.expansions.size() && m < g.manager_teams.size(); ++m) { + if (league_club(g, int(m)) < 0) continue; + auto& entry = g.expansions[m]; + int64_t income = 0; + for (int k = 0; k < kExpansions; ++k) { + if (entry.months[size_t(k)] > 0 && --entry.months[size_t(k)] == 0 && entry.stage[size_t(k)] + 1 < kExpansionStages[size_t(k)]) ++entry.stage[size_t(k)]; + income += expansion_income(g, int(m), Expansion(k)); + } + if (income > 0) modern::book_money(g, int(m), -int32_t(income), true); + } +} + +} // namespace bmh::modern diff --git a/src/modern/game/expansions.hpp b/src/modern/game/expansions.hpp new file mode 100644 index 0000000..9944f2c --- /dev/null +++ b/src/modern/game/expansions.hpp @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// Further stages of the V.I.P. lounge and of four buildings of the periphery +// (docs/new_engine/ausbaustufen.md). A Modern rule on top of the original, which knows the +// lounge and these buildings only as built or not. +// +// Once the building stands, the manager can extend it stage by stage: the lounge to four +// stages, the shopping centre and the clubhouse to three, the car park to four, the restaurant +// to two. A stage costs money and takes some months; every finished further stage brings a +// monthly income by league while the building stands. Draws no random number. + +#include +#include + +#include "modern/game/modern_state.hpp" + +namespace bmh::modern { + +enum class Expansion : uint8_t { lounge, mall, clubhouse, parking, restaurant }; +constexpr int kExpansions = 5; +constexpr std::array kExpansionStages{4, 3, 3, 4, 2}; + +// Whether the building of the original stands and is not under construction. +bool expansion_base_built(const ModernState& g, int manager, Expansion item); +// The stage it has: 0 not built, 1 as the original builds it, up to kExpansionStages. +int expansion_stage(const ModernState& g, int manager, Expansion item); +// Months until the stage under construction is finished (0 = none). +int expansion_months_left(const ModernState& g, int manager, Expansion item); +// Price and building time of the next stage; 0 when there is none. +int32_t expansion_price(const ModernState& g, int manager, Expansion item); +int expansion_build_months(const ModernState& g, int manager, Expansion item); +// What its further stages bring a month now. +int32_t expansion_income(const ModernState& g, int manager, Expansion item); + +// Starts the next stage and pays for it. False, with nothing changed, when the building does +// not stand, a stage is under construction, the last stage is reached or the account (with +// the credit line) cannot bear it. +bool start_expansion(ModernState& g, int manager, Expansion item); + +// The month change: stages under construction get a month nearer, finished stages pay. +void expansions_month(ModernState& g); + +} // namespace bmh::modern diff --git a/src/modern/game/modern_state.hpp b/src/modern/game/modern_state.hpp index 4763a9a..97ef02b 100644 --- a/src/modern/game/modern_state.hpp +++ b/src/modern/game/modern_state.hpp @@ -163,6 +163,15 @@ struct ModernState : GameState { // holds of them, and today's prices (0 = the starting price). std::vector> estates; std::array estate_prices{}; + // Further stages of the lounge and four buildings of the periphery + // (docs/new_engine/ausbaustufen.md), per manager slot and item (lounge, shopping centre, + // clubhouse, car park, restaurant): the further stages finished, and the months until the + // stage under construction is finished (0 = none). + struct Expansions { + std::array stage{}, months{}; + bool operator==(const Expansions&) const = default; + }; + std::vector expansions; // Whether a manager the meeting votes out has to leave his club. On until the options offer it. bool dismissals = true; // Players whose age the data set gives (birth date); the others carry a placeholder the diff --git a/src/modern/game/month.cpp b/src/modern/game/month.cpp index d659fd6..c0f32a3 100644 --- a/src/modern/game/month.cpp +++ b/src/modern/game/month.cpp @@ -7,6 +7,7 @@ #include "modern/game/naming_rights.hpp" #include "modern/game/marketing.hpp" #include "modern/game/estates.hpp" +#include "modern/game/expansions.hpp" #include "modern/game/desk_actions.hpp" #include "game/trace.hpp" @@ -953,6 +954,7 @@ void month_change(ModernState& g, WatcomRandom& rand, MinuteReport& report, Game modern::naming_rights_month(g); // Modern: the stadium sponsors pay (naming_rights.hpp) modern::marketing_month(g); // Modern: international marketing costs and pays (marketing.hpp) modern::estates_month(g); // Modern: the four further properties move and pay rent (estates.hpp) + modern::expansions_month(g); // Modern: further stages of lounge and periphery are built and pay (expansions.hpp) StaticMemory& mem = g.memory; std::vector& r = g.manager_records; const int managers = int(g.manager_teams.size()); diff --git a/src/modern/ui/engine_bridge.hpp b/src/modern/ui/engine_bridge.hpp index bb31daf..642afb4 100644 --- a/src/modern/ui/engine_bridge.hpp +++ b/src/modern/ui/engine_bridge.hpp @@ -32,6 +32,8 @@ Json engine_ticket_command(const Json &bundle, int euros, const std::string &req Json engine_environment_projection(const Json &bundle); Json engine_environment_command(const Json &bundle, const std::string &item, int level, const std::string &request_id); +// The next stage of the lounge or of a building of the periphery (read "stadium", expansions). +Json engine_expansion_command(const Json &bundle, const std::string &expansion, const std::string &request_id); // A player of the squad gets the shirt number 1-99. Json engine_shirt_number_command(const Json &bundle, const std::string &player, int number, const std::string &request_id); // The monthly budget for international marketing (read "advertising", internationalMarketing). diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 2d094f4..68593ec 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -481,6 +481,27 @@ void App::engine_event(Rml::Event &event) { const auto action = node->GetAttribute("data-action", ""), id = node->GetAttribute("data-id", ""); if (!popup_.empty()) { if(action=="balance-discard"){engine_balance_action(action,node);return;} + if (action == "expansion-start") { + const std::string expansion = id; + std::string name, terms; + try { + for (const auto &row : engine_data_.at("stadium").at("data").at("expansions")) + if (row.value("id", std::string()) == expansion && !row.at("nextPrice").is_null()) { + name = row.value("name", std::string()); + terms = engine_price(row.at("nextPrice")) + ", " + std::to_string(row.value("nextMonths", 0)) + " Monate Bauzeit"; + } + } catch (const std::exception &) {} + popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true; + if (name.empty()) return; + confirmation(name + " um eine Stufe ausbauen? (" + terms + ")", [this, expansion] { + try { + engine_finance_submit(engine_expansion_command(engine_data_, expansion, editor::new_id("request:ui-"))); + } catch (const std::exception &e) { message(e.what()); } + }); + popup_title_ = "Ausbau"; + popup_accept_ = "Ausbauen"; + return; + } if (action == "naming-accept") { const std::string offer = id; std::string name, terms; diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index b4e506a..a177dc5 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -514,6 +514,9 @@ Json engine_environment_projection(const Json &bundle) { } return {{"ok", true}, {"rows", rows}}; } +Json engine_expansion_command(const Json &bundle, const std::string &expansion, const std::string &request_id) { + return sports_command(bundle, "stadium.expand", {{"expansionId", expansion}, {"confirmed", true}}, request_id); +} Json engine_shirt_number_command(const Json &bundle, const std::string &player, int number, const std::string &request_id) { return sports_command(bundle, "lineup.setNumber", {{"playerId", player}, {"number", number}}, request_id); } diff --git a/src/modern/ui/engine_stadium.inc b/src/modern/ui/engine_stadium.inc index e4ec8a2..2dd95f7 100644 --- a/src/modern/ui/engine_stadium.inc +++ b/src/modern/ui/engine_stadium.inc @@ -217,6 +217,30 @@ bool App::engine_stadium_action(const std::string &action, Rml::Element *target) refresh(); return true; } + if (action == "stadium-expansions" && engine_fresh_ && !engine_busy_) { + // the further stages of the lounge and of four buildings: where each stands and what the next costs + Json rows; + try { rows = engine_data_.at("stadium").at("data").at("expansions"); } catch (const std::exception &) { return true; } + std::string body = "
"; + for (const auto &row : rows) { + const std::string id = row.value("id", std::string()); + const int stage = row.value("stage", 0), most = row.value("maxStage", 1), left = row.value("monthsLeft", 0); + std::string state = stage == 0 ? "noch nicht gebaut" : "Stufe " + std::to_string(stage) + " von " + std::to_string(most); + if (stage > 1) state += " · bringt " + engine_price(row.at("monthlyIncome")) + " im Monat"; + const std::string next = left > 0 ? "Die nächste Stufe ist in " + std::to_string(left) + (left == 1 ? " Monat fertig" : " Monaten fertig") + : stage == 0 ? std::string("Erst bauen, dann ausbauen") + : row.at("nextPrice").is_null() ? std::string("Fertig ausgebaut") + : "Nächste Stufe: " + engine_price(row.at("nextPrice")) + " · " + std::to_string(row.value("nextMonths", 0)) + " Monate Bauzeit"; + body += "
" + esc(row.value("name", std::string())) + "" + esc(state) + "" + esc(next) + "
" + + pg_button("expansion-start", "Ausbauen", "primary", "id=\"expansion-start-" + esc(id) + "\" data-id=\"" + esc(id) + "\" " + std::string(row.value("available", false) ? "" : "disabled=\"disabled\"")) + "
"; + } + body += "
"; + message("Die Lounge und vier Gebäude der Peripherie lassen sich in Stufen ausbauen. Jede weitere Stufe kostet Geld und Bauzeit und bringt danach jeden Monat Einnahmen."); + popup_title_ = "Ausbaustufen"; + popup_close_ = "Schließen"; + popup_body_ = body; + return true; + } if (action == "stadium-rename" && engine_fresh_ && !engine_busy_) { Json data; try { data = engine_data_.at("stadium").at("data"); } catch (const std::exception &) { return true; } diff --git a/src/modern/ui/stadium_screens.inc b/src/modern/ui/stadium_screens.inc index 767a48a..b6c413a 100644 --- a/src/modern/ui/stadium_screens.inc +++ b/src/modern/ui/stadium_screens.inc @@ -205,6 +205,7 @@ std::string App::render_stadium() { out+=btn("stadium-future",""+std::string(i?"Zukunft":"Aktuell")+"",std::string(i?"":"first ")+(on?"on":""),on?std::string("style=\"pointer-events:none;\" aria-pressed=\"true\""):std::string("id=\"stadium-future\" aria-pressed=\"false\"")); } out+=""+pg_button("stadium-data","Stadion-Daten","","id=\"stadium-data\""); + if(engine_mode_)out+=pg_button("stadium-expansions","Ausbaustufen","","id=\"stadium-expansions\""); // the name is the manager's to choose until he sells it to a sponsor if(engine_mode_)out+=pg_button("stadium-rename","Stadion umbenennen","","id=\"stadium-rename\" "+std::string(overview.value("name_editable",false)?"":"disabled=\"disabled\" title=\"Der Name ist an einen Sponsor verkauft\"")); } diff --git a/tests/modern_expansion_tests.cpp b/tests/modern_expansion_tests.cpp new file mode 100644 index 0000000..01591ce --- /dev/null +++ b/tests/modern_expansion_tests.cpp @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Further stages of lounge and periphery (docs/new_engine/ausbaustufen.md) on a synthetic +// manager: what can be extended, prices and building times, the months of building, the income. +#include + +#include "modern/game/expansions.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; + } +} +int32_t cash(const ModernState& g) { + return int32_t(uint32_t(g.manager_records[0x314]) | uint32_t(g.manager_records[0x315]) << 8 | uint32_t(g.manager_records[0x316]) << 16 | + uint32_t(g.manager_records[0x317]) << 24); +} +// Manager 0 runs club `team`; the lounge (facility 3) and the restaurant (object 5) stand. +ModernState world(int team, int32_t euros) { + ModernState g; + g.level = 2; + g.manager_teams = {int16_t(team)}; + g.manager_records.assign(5 * 0xb0c, 0); + g.manager_records[0x3c + 3] = 2; + g.manager_records[5] = 0x40; + for (int i = 0; i < 4; ++i) g.manager_records[0x314 + size_t(i)] = uint8_t(uint32_t(euros) >> (8 * i)); + return g; +} +} // namespace + +int main() { + { + ModernState g = world(0, 10000000); + check(expansion_stage(g, 0, Expansion::lounge) == 1 && expansion_stage(g, 0, Expansion::restaurant) == 1 && expansion_stage(g, 0, Expansion::mall) == 0, + "what the original built is stage one, the rest is not built"); + check(expansion_price(g, 0, Expansion::lounge) == 1200000 && expansion_build_months(g, 0, Expansion::lounge) == 3, "the second stage of the lounge"); + check(!start_expansion(g, 0, Expansion::mall) && cash(g) == 10000000, "a building that does not stand cannot be extended"); + check(start_expansion(g, 0, Expansion::lounge) && cash(g) == 8800000 && expansion_months_left(g, 0, Expansion::lounge) == 3, "the stage is paid and under construction"); + check(!start_expansion(g, 0, Expansion::lounge), "no second stage while one is built"); + expansions_month(g), expansions_month(g); + check(expansion_stage(g, 0, Expansion::lounge) == 1 && cash(g) == 8800000, "two months: still building, no income"); + expansions_month(g); + check(expansion_stage(g, 0, Expansion::lounge) == 2 && cash(g) == 8800000 + 45000, "the third month finishes the stage and it pays at once"); + check(expansion_price(g, 0, Expansion::lounge) == 2400000 && expansion_build_months(g, 0, Expansion::lounge) == 4, "the third stage costs twice as much and takes longer"); + // up to the last stage + while (expansion_price(g, 0, Expansion::lounge) != 0) { + check(start_expansion(g, 0, Expansion::lounge), "next stage started"); + while (expansion_months_left(g, 0, Expansion::lounge) != 0) expansions_month(g); + } + check(expansion_stage(g, 0, Expansion::lounge) == 4 && !start_expansion(g, 0, Expansion::lounge) && expansion_income(g, 0, Expansion::lounge) == 3 * 45000, + "four stages at most; three further stages pay three times"); + // the restaurant has two stages + check(start_expansion(g, 0, Expansion::restaurant), "the restaurant is extended"); + while (expansion_months_left(g, 0, Expansion::restaurant) != 0) expansions_month(g); + check(expansion_stage(g, 0, Expansion::restaurant) == 2 && expansion_price(g, 0, Expansion::restaurant) == 0, "the restaurant ends at stage two"); + // a building that is gone pays nothing + g.manager_records[5] = 0; + check(expansion_stage(g, 0, Expansion::restaurant) == 0 && expansion_income(g, 0, Expansion::restaurant) == 0, "no building, no income"); + } + { + ModernState low = world(60, 100000); + check(!start_expansion(low, 0, Expansion::lounge) && cash(low) == 100000, "an account that cannot bear the price refuses"); + low.expansions.resize(1); + low.expansions[0].stage[0] = 1; + check(expansion_income(low, 0, Expansion::lounge) == 45000 * 25 / 100, "a low league earns a quarter"); + low.manager_records[0x2c + 3] = 4; + check(!expansion_base_built(low, 0, Expansion::lounge), "a lounge under construction does not count as standing"); + } + if (failures) return 1; + std::puts("modern_expansion_tests: ok"); + return 0; +}