diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cbc574..e22c798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1242,6 +1242,9 @@ add_test(NAME modern_marketing_tests COMMAND modern_marketing_tests) add_executable(modern_shirt_number_tests tests/modern_shirt_number_tests.cpp) target_link_libraries(modern_shirt_number_tests PRIVATE bmh_season_modern) 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_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 769d98a..bb05607 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -52,6 +52,7 @@ describe deliberate changes; they are not a list of every known compatibility li - [src/modern/content/statistics.cpp](../src/modern/content/statistics.cpp): Modern chooses its own eleven of the day per league from the recorded facts of the matchday (goals, assists, cards, result, clean sheets) instead of the original's Sportschau rating, and words the ticker from several variants per event. - [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/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 4a839ec..4ecd8bf 100644 --- a/docs/new_engine/README.md +++ b/docs/new_engine/README.md @@ -15,6 +15,7 @@ Grundlage ist der [Engine-Split](../ENGINE_SPLIT.md); die Oberfläche ist in | [Namensrecht](namensrecht.md) | Stadionname, Angebote der Sponsoren, monatliche Zahlung | | [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 | | [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/immobilien.md b/docs/new_engine/immobilien.md new file mode 100644 index 0000000..e5a3674 --- /dev/null +++ b/docs/new_engine/immobilien.md @@ -0,0 +1,48 @@ +# Vier weitere Immobilien · Modern-Engine + +Stand: 17. November 2026. Eine Modern-Regel neben den sechs Immobilien des Originals (den +Fonds seiner Bank), die unverändert bleiben. + +## Regel + +| Nr. | Immobilie | Startpreis | +|---|---|---| +| 6 | Stadthaus | 450 000 € | +| 7 | Penthouse | 1 200 000 € | +| 8 | Siedlungshaus | 280 000 € | +| 9 | Altbau-Reihenhaus | 650 000 € | + +- Gekauft und verkauft wird zum Tagespreis, ohne Gebühr. Höchstens 20 Stück je Immobilie. + Der Kauf scheitert, wenn Konto und Kreditrahmen nicht reichen. +- **Preis:** Mit jedem Monatswechsel ändert sich jeder Preis um −2 bis +3 % (auf ganze + Tausender), nie unter die Hälfte und nie über das Dreifache des Startpreises. Der Zufall + dafür kommt aus einem eigenen Generator (Startwert aus Karriere, Monat und Immobilie) und + verbraucht keine Zahl des Spiels. +- **Miete:** Jedes Stück bringt im Monat 4 ‰ seines Preises, rund 4,8 % im Jahr. +- In die Vermögenswertung der [Jahreshauptversammlung](hauptversammlung.md) gehen sie zum + Tagespreis ein. Bei einem Vereinswechsel bleiben sie zurück. +- Dritter Schritt von `month_change` (`modern::estates_month`). + +## Speichern + +`state/modern.json`: `estates` (je Managerplatz vier Stückzahlen) und `estate_prices` (vier +Preise, 0 = Startpreis). + +## Anbindung + +Read `bank`: `funds` hat vier weitere Einträge `fund:6` bis `fund:9` mit `name`, `price`, +`owned`, `paid`, `maxToBuy`, dazu `monthlyRent` und `limit`. `bank.commit` mit `buy`/`sell` +und `assetId` `fund:6`–`fund:9` (Fehler `purchase_refused`, `sale_refused`, `unknown_asset`). + +## Prüfung + +`modern_estates_tests` (ohne Spieldaten): Startpreise, Miete, Kauf, Grenzen des Kaufs und +Verkaufs, Preisbewegung eines Monats, Mietzahlung, Verkauf zum Tagespreis, Höchstzahl, +Preisgrenzen über fünfzig Jahre. + +## Offen + +- Die Highscore-Wertung zählt die vier Immobilien nicht mit. +- `accounts.investments` des Reads `bank` nennt weiter nur die Anlagen des Originals. +- Miete und Kauf sind einfache Buchungen ohne eigenen Bilanzposten. +- Die Sätze sind ein erster Ansatz und nicht in einem Langlauf gemessen. diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index e4734f0..fb93003 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -44,7 +44,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht | `environment` | das Umfeld (Diamond 3.6): drei Jugendteams, Co-Trainer, Arzt, Physiotherapeut (`environment:`), je Stufe 0–6, Monatskosten, Kosten je Stufe; die Jugendteams mit Stärke, Platz, Liga; ob die Akademie läuft | | `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung | | `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) | -| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; `credit` verweist auf den Read `credit`, der Aktientipp zieht Zufall und kommt als `quote.request` | +| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; `credit` verweist auf den Read `credit`, der Aktientipp zieht Zufall und kommt als `quote.request`. Modern hängt vier [weitere Immobilien](immobilien.md) als `fund:6`–`fund:9` an (zusätzlich `monthlyRent`, `limit`); `bank.commit` handelt sie wie die übrigen | | `credit` | der Kreditdialog (`lenderId` `bank` oder die Manager-ID eines anderen Menschen): `saved` (Darlehen, Gesamtbetrag, Rate, Laufzeit, vergangene Monate, Zahlungen), `fields` (acht Felder mit `field`, `label`, `value`, `editable`, `min`, `max`; Werte in ganzen Euro bzw. Monaten), `fees`, `refund`, `principalPaid` (`Money`). Optional `edits` [{field, value}] als Vorschau, nichts wird gebucht; Fehler `unknown_lender`, `credit_unavailable`, `invalid_credit_edit` | | `assembly` | die [Jahreshauptversammlung](hauptversammlung.md) und die interessierten Vereine: `available` (false am Schreibtisch des Bundestrainers), `due` (am Schreibtisch „Saisonende“, solange in dieser Saison nicht abgestimmt ist), `dismissals`, `vote {sport, finance, supporters, yes, confirmed}` (Prozent), `club` und `offers[]` je mit `teamId`, `name`, `league`, `leagueIndex`, `leagueSize`, `strength` (Schnitt der Elf), `lines {goal, defence, midfield, attack}`, `positions[]` (Platz nach jedem Spieltag der Saison), `squad` (Spieler), `averageAge` (Altersschnitt des Kaders in Zehnteljahren), `results[]` (die letzten sechs Ligaspiele: `home`, `goalsFor`, `goalsAgainst`, `opponent`, `outcome` win/draw/loss), `stadiumCapacity` (Plätze des Stadions, das ein Manager dort erhält), `position`; Angebote zusätzlich `cash` (`Money`), dazu `cash` des Managers heute. Rein lesend, zieht keine Zufallszahl | | `postmatch` | das Nachspiel des letzten `session.advance` (auch am Bundestrainer-Schreibtisch): `steps` (`results`, `report`, `team_of_the_day`, `overview`, `table` je mit `available`), `matches` (alle Spiele des Anstoßes im Almanach-Format), `reportMatchIds` (Spiele menschlicher Manager), `teamOfTheDay` (die Sportschau-Elf der Engine je Wettbewerb mit Spieler, Verein, Wertung; nur mit der Sportschau-Option der EXE, sonst leer und `team_of_the_day` nicht verfügbar), `tables` (die aktuellen Tabellen der Ligen des Spieltags). Rückblick und Abspielen ändern nichts; weiter geht es mit `session.advance` | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 12bd914..b07ca50 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -15,6 +15,7 @@ #include "modern/game/naming_rights.hpp" #include "modern/game/marketing.hpp" #include "modern/game/shirt_numbers.hpp" +#include "modern/game/estates.hpp" #include "modern/game/balance_plan.hpp" #include "modern/game/bank_credit.hpp" #include "modern/game/career.hpp" @@ -9702,6 +9703,19 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co funds.push_back(O{{"id", "fund:" + std::to_string(i)}, {"name", property}, {"price", modern::ui_money(f.price)}, {"owned", int(f.owned)}, {"paid", modern::ui_money(f.paid)}, {"maxToBuy", f.max_to_buy}}); } + // the four further properties of Modern follow the six of the original as fund:6 to fund:9 + { + static constexpr const char* kEstateNames[modern::kEstates] = {"Stadthaus", "Penthouse", "Siedlungshaus", "Altbau-Reihenhaus"}; + const int64_t means = int64_t(b.balance) + int64_t(b.credit_line); + for (int k = 0; k < modern::kEstates; ++k) { + const int32_t price = modern::estate_price(g_, k); + const int held = modern::estates_held(g_, manager, k); + funds.push_back(O{{"id", "fund:" + std::to_string(6 + k)}, {"name", kEstateNames[k]}, {"price", modern::ui_money(int64_t(price))}, + {"owned", held}, {"paid", modern::ui_money(int64_t(held) * price)}, + {"maxToBuy", int(std::clamp(price > 0 ? means / price : 0, 0, modern::kEstateLimit - held))}, + {"monthlyRent", modern::ui_money(int64_t(modern::estate_rent(g_, k)))}, {"limit", modern::kEstateLimit}}); + } + } // the interest of a year in hundredths of a percent, read off the rule that books it // every day: what one day costs or earns on a sum of 36.5 million constexpr int32_t probe = 36500000; @@ -11349,6 +11363,19 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision if ((!stock && !fund) || !count || !count->integer()) return refuse("invalid_payload", "assetId und count nötig."); try { r.asset_index = std::stoi(asset.substr(stock ? 6 : 5)); } catch (const std::exception&) { return refuse("unknown_asset", asset); } r.count = int(*count->integer()); + if (fund && r.asset_index >= 6) { + // one of Modern's four further properties (immobilien.md): traded at today's price + const int k = r.asset_index - 6; + if (k >= modern::kEstates) return refuse("unknown_asset", asset); + if (!(action == "buy" ? modern::buy_estate(g_, manager, k, r.count) : modern::sell_estate(g_, manager, k, r.count))) + return refuse(action == "buy" ? "purchase_refused" : "sale_refused", + action == "buy" ? "Kauf nicht möglich: Konto, Anzahl oder die Grenze von 20 Stück." : "Verkauf nicht möglich: nicht so viele im Bestand."); + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"bank", "desktop"}, action == "buy" ? "Immobilie gekauft." : "Immobilie verkauft."); + ui_answers_[request_id] = {body, answer}; + ui_answer_order_.push_back(request_id); + return answer; + } r.kind = stock ? (action == "buy" ? ui::BankRequestKind::buy_shares : ui::BankRequestKind::sell_shares) : (action == "buy" ? ui::BankRequestKind::buy_fund : ui::BankRequestKind::sell_fund); } else if (action == "credit") { diff --git a/src/modern/content/world_save.cpp b/src/modern/content/world_save.cpp index bbd912b..799f99d 100644 --- a/src/modern/content/world_save.cpp +++ b/src/modern/content/world_save.cpp @@ -194,6 +194,12 @@ void save_world_career(const std::filesystem::path& path, const World& world, co return J(std::move(rows)); }()}, {"dismissals", state.dismissals}, + {"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]))}); + return J(std::move(rows)); + }()}, + {"estate_prices", A{J(int64_t(state.estate_prices[0])), J(int64_t(state.estate_prices[1])), J(int64_t(state.estate_prices[2])), J(int64_t(state.estate_prices[3]))}}, {"shirt_numbers", [&] { // only the players who have a number: [player, number] pairs A rows; @@ -288,6 +294,22 @@ 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); } + // the four further properties (since 17 November 2026) + if (o->count("estates") && o->count("estate_prices")) { + for (const J& row : arr(get(modern, "estates"))) { + const A& held = arr(row); + if (held.size() != 4) fail("invalid properties"); + std::array pieces{}; + for (size_t k = 0; k < 4; ++k) { + if (num(held[k]) < 0 || num(held[k]) > 20) fail("invalid properties"); + pieces[k] = uint16_t(num(held[k])); + } + out.state.estates.push_back(pieces); + } + const A& prices = arr(get(modern, "estate_prices")); + if (prices.size() != 4) fail("invalid property prices"); + for (size_t k = 0; k < 4; ++k) out.state.estate_prices[k] = uint32_t(num(prices[k])); + } // shirt numbers (since 17 November 2026) if (o->count("shirt_numbers")) for (const J& row : arr(get(modern, "shirt_numbers"))) { diff --git a/src/modern/game/assembly.cpp b/src/modern/game/assembly.cpp index 08cb595..90bc3d8 100644 --- a/src/modern/game/assembly.cpp +++ b/src/modern/game/assembly.cpp @@ -8,6 +8,7 @@ #include "formats/executable_layout.hpp" #include "game/random.hpp" #include "game/schedule.hpp" +#include "modern/game/estates.hpp" #include "modern/game/matchday.hpp" namespace bmh::modern { @@ -52,7 +53,7 @@ int64_t holdings(const ModernState& g, int m) { const uint32_t at = ::bmh::layout::Analytics_SourceAssetMaskE_RuntimeField + uint32_t(m) * 0x78 + k * 0x18; if (mem.has(at + 3)) sum -= int64_t(mem.u32(at)); } - return sum; + return sum + estates_value(g, m); } // What the club did in the cups of the running season: 2 a cup won, 1 a final lost, 0 otherwise. diff --git a/src/modern/game/career.cpp b/src/modern/game/career.cpp index c26aef2..def0460 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.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/estates.cpp b/src/modern/game/estates.cpp new file mode 100644 index 0000000..5103202 --- /dev/null +++ b/src/modern/game/estates.cpp @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/game/estates.hpp" + +#include + +#include "game/random.hpp" +#include "modern/game/matchday.hpp" + +namespace bmh::modern { +namespace { + +bool league_manager(const ModernState& g, int manager) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size() || g.manager_records.size() < size_t(manager + 1) * 0xb0c) return false; + const int team = g.manager_teams[size_t(manager)]; + return team >= 0 && team < league_clubs(); +} + +} // namespace + +int32_t estate_price(const ModernState& g, int k) { + if (k < 0 || k >= kEstates) return 0; + return g.estate_prices[size_t(k)] ? int32_t(g.estate_prices[size_t(k)]) : kEstateBasePrice[size_t(k)]; +} + +int estates_held(const ModernState& g, int manager, int k) { + return manager >= 0 && size_t(manager) < g.estates.size() && k >= 0 && k < kEstates ? g.estates[size_t(manager)][size_t(k)] : 0; +} + +int64_t estates_value(const ModernState& g, int manager) { + int64_t sum = 0; + for (int k = 0; k < kEstates; ++k) sum += int64_t(estates_held(g, manager, k)) * estate_price(g, k); + return sum; +} + +int32_t estate_rent(const ModernState& g, int k) { return estate_price(g, k) / 1000 * 4; } + +// OpenBMH deviates from the original: Modern adds four properties to the bank whose prices move monthly and which pay a monthly rent. +bool buy_estate(ModernState& g, int manager, int k, int count) { + if (!league_manager(g, manager) || k < 0 || k >= kEstates || count < 1 || estates_held(g, manager, k) + count > kEstateLimit) return false; + const int64_t cost = int64_t(estate_price(g, k)) * count; + if (cost > INT32_MAX || !modern::book_money(g, manager, int32_t(cost), false)) return false; + if (g.estates.size() <= size_t(manager)) g.estates.resize(size_t(manager) + 1); + g.estates[size_t(manager)][size_t(k)] = uint16_t(estates_held(g, manager, k) + count); + return true; +} + +bool sell_estate(ModernState& g, int manager, int k, int count) { + if (!league_manager(g, manager) || k < 0 || k >= kEstates || count < 1 || estates_held(g, manager, k) < count) return false; + modern::book_money(g, manager, -int32_t(int64_t(estate_price(g, k)) * count), true); + g.estates[size_t(manager)][size_t(k)] = uint16_t(estates_held(g, manager, k) - count); + return true; +} + +void estates_month(ModernState& g) { + uint32_t salt = 2166136261u; + for (const unsigned char c : g.career_id) salt = (salt ^ c) * 16777619u; + for (int k = 0; k < kEstates; ++k) { + GameRandom draw(int32_t((uint64_t(salt) + uint64_t(g.date / 30) * 4099u + uint64_t(k) * 7907u + 29u) % 4000000u)); + draw.range(0, 9); // (the first draw of a fresh seed is weak) + const int64_t base = kEstateBasePrice[size_t(k)]; + const int64_t moved = int64_t(estate_price(g, k)) * (100 + draw.range(-2, 3)) / 100 / 1000 * 1000; + g.estate_prices[size_t(k)] = uint32_t(std::clamp(moved, base / 2, base * 3)); + } + for (size_t m = 0; m < g.estates.size() && m < g.manager_teams.size(); ++m) { + if (!league_manager(g, int(m))) continue; + int64_t rent = 0; + for (int k = 0; k < kEstates; ++k) rent += int64_t(g.estates[m][size_t(k)]) * estate_rent(g, k); + if (rent > 0) modern::book_money(g, int(m), -int32_t(rent), true); + } +} + +} // namespace bmh::modern diff --git a/src/modern/game/estates.hpp b/src/modern/game/estates.hpp new file mode 100644 index 0000000..a708b52 --- /dev/null +++ b/src/modern/game/estates.hpp @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// Four further properties of the bank (docs/new_engine/immobilien.md). A Modern rule beside +// the six properties of the original (the funds of its bank). +// +// A manager buys and sells them at the day's price. Every month the price of each moves by +// minus two to plus three percent (a generator of its own, seeded from the career, the month +// and the property; never below half or above three times its starting price), and every +// property held pays a rent of four per mille of its price. Draws no number of the game. + +#include +#include + +#include "modern/game/modern_state.hpp" + +namespace bmh::modern { + +constexpr int kEstates = 4; +constexpr int kEstateLimit = 20; // pieces of one property a manager can hold +// Town house, penthouse, estate house, old terraced house: what they cost at the career's start. +constexpr std::array kEstateBasePrice{450000, 1200000, 280000, 650000}; + +// Today's price of property k (0-3). +int32_t estate_price(const ModernState& g, int k); +// How many of property k the manager holds. +int estates_held(const ModernState& g, int manager, int k); +// The value of all he holds at today's prices. +int64_t estates_value(const ModernState& g, int manager); +// The rent a piece of property k pays a month. +int32_t estate_rent(const ModernState& g, int k); + +// Buys or sells `count` pieces at today's price. False, with nothing changed, when the count, +// the limit, his holdings or his account (with the credit line) do not allow it. +bool buy_estate(ModernState& g, int manager, int k, int count); +bool sell_estate(ModernState& g, int manager, int k, int count); + +// The month change: the prices move and the rents are paid. +void estates_month(ModernState& g); + +} // namespace bmh::modern diff --git a/src/modern/game/modern_state.hpp b/src/modern/game/modern_state.hpp index 0dec88b..4763a9a 100644 --- a/src/modern/game/modern_state.hpp +++ b/src/modern/game/modern_state.hpp @@ -159,6 +159,10 @@ struct ModernState : GameState { std::vector marketing; // Shirt numbers (docs/new_engine/rueckennummern.md) by player: 1-99, 0 = none yet. std::vector shirt_numbers; + // Four further properties of the bank (docs/new_engine/immobilien.md): what each manager + // holds of them, and today's prices (0 = the starting price). + std::vector> estates; + std::array estate_prices{}; // 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 c3865b1..d659fd6 100644 --- a/src/modern/game/month.cpp +++ b/src/modern/game/month.cpp @@ -6,6 +6,7 @@ #include "modern/game/month.hpp" #include "modern/game/naming_rights.hpp" #include "modern/game/marketing.hpp" +#include "modern/game/estates.hpp" #include "modern/game/desk_actions.hpp" #include "game/trace.hpp" @@ -951,6 +952,7 @@ void search_profile_news(ModernState& g, int manager, uint32_t list, int player) void month_change(ModernState& g, WatcomRandom& rand, MinuteReport& report, GameRandom* 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) StaticMemory& mem = g.memory; std::vector& r = g.manager_records; const int managers = int(g.manager_teams.size()); diff --git a/src/modern/ui/bank_controls.inc b/src/modern/ui/bank_controls.inc index adcbcc8..dc8c513 100644 --- a/src/modern/ui/bank_controls.inc +++ b/src/modern/ui/bank_controls.inc @@ -8,7 +8,7 @@ bool App::bank_action(const std::string &action, Rml::Element *target) { if (action == "bank-property" && target) { // a house on the board is chosen: it is the one bought and sold const auto index = target->GetAttribute("data-id", -1); - if (bank_view_ != "properties" || index < 0 || index > 5) return true; + if (bank_view_ != "properties" || index < 0 || index > 9) return true; bank_property_ = bank_owned_ = index; focus_after_render_ = "bank-property-" + std::to_string(index); refresh(); diff --git a/src/modern/ui/bank_screens.inc b/src/modern/ui/bank_screens.inc index 9cf3509..5f44580 100644 --- a/src/modern/ui/bank_screens.inc +++ b/src/modern/ui/bank_screens.inc @@ -146,7 +146,7 @@ std::string App::render_bank() { const auto price = offer.at("price").get(); out += "
" + pg_kicker("Ausgewählt") + "

" + esc(calm_name(offer.at("name").get())) + "

" + esc(bank_money(price)) + "
" + - kv("Im Bestand", number(held) + " Stück") + kv("Wert heute", esc(bank_money(held * price))) + kv("Anteil am Konto", in_cash > 0 ? one(price * 100.0 / in_cash) + " %" : std::string("—")) + + kv("Im Bestand", number(held) + " Stück") + kv("Wert heute", esc(bank_money(held * price))) + (offer.contains("rent") ? kv("Miete je Stück", esc(bank_money(offer.at("rent").get())) + " / Monat") : std::string()) + kv("Anteil am Konto", in_cash > 0 ? one(price * 100.0 / in_cash) + " %" : std::string("—")) + (offer.contains("maxToBuy") ? kv("Bezahlbar", number(offer.at("maxToBuy").get()) + " Stück") : kv("Auf dem Konto", esc(bank_money(in_cash)))) + "
" + calc("Kaufen", "property-buy", "primary bk-wide") + calc("Verkaufen", "property-sell", "bk-wide", held > 0) + "Ein Haus am Brett anklicken, dann kaufen oder verkaufen.
"; } else if (bank_view_ == "stocks") { diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index 9c71a9c..b4e506a 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -378,12 +378,12 @@ Json engine_bank_projection(const Json &bundle) { const bool stock = std::string(key) == "stocks"; const auto dest = stock ? "stocks" : "properties"; const auto &rows = data.at(key); - require(rows.is_array() && !rows.empty() && rows.size() <= size_t(stock ? 12 : 6), "Ungültiger Bankkatalog."); + require(rows.is_array() && !rows.empty() && rows.size() <= size_t(stock ? 12 : 10), "Ungültiger Bankkatalog."); // six properties of the original, four of Modern std::set ids; for (const auto &row : rows) { const auto id = row.at("id").get(); bool known = false; - for (int i = 0; i < (stock ? 12 : 6); ++i) known |= id == std::string(stock ? "stock:" : "fund:") + std::to_string(i); + for (int i = 0; i < (stock ? 12 : 10); ++i) known |= id == std::string(stock ? "stock:" : "fund:") + std::to_string(i); require(known && ids.insert(id).second, "Unbekannte oder doppelte Bankanlage."); const auto price = engine_money_minor(row.at("price")); const int owned = whole_in_range(row.at("owned"), 0, 65535), max = whole_in_range(row.at("maxToBuy"), 0, 99999999); @@ -402,6 +402,7 @@ Json engine_bank_projection(const Json &bundle) { stocks += price * owned; } else { item["image"] = "bank.property." + id.substr(5); + if (row.contains("monthlyRent")) item["rent"] = engine_money_minor(row.at("monthlyRent")); properties += price * owned; } assets[dest].push_back(item); finance[dest].push_back(owned); diff --git a/src/modern/ui/tactics_page.inc b/src/modern/ui/tactics_page.inc index 67d79e1..f45819e 100644 --- a/src/modern/ui/tactics_page.inc +++ b/src/modern/ui/tactics_page.inc @@ -136,7 +136,7 @@ std::string App::render_tactics() { // --- the page --- std::string out = "
" + picture(renderer_.diagram("tactics-sketch-" + theme_, svg, 2088), sketch_w, sketch_h) + over + "
Meine Taktik
"; + scalar((1620 - sketch_h) / 2 - 62) + "dp;\">" + picture(renderer_.diagram("tactics-sketch-" + theme_, svg, 2088), sketch_w, sketch_h) + over + "
Meine Taktik
"; for (size_t i = 0; i < 7; ++i) { const bool toggle = i >= 5, on = values[i] > minima[i]; out += btn("tactic-cycle", pg_kicker(names[i], "width:122px;font-size:10px;") + "" + esc(toggle ? (on ? "an" : "aus") : text_of(i)) + "", "tk-row", diff --git a/tests/modern_estates_tests.cpp b/tests/modern_estates_tests.cpp new file mode 100644 index 0000000..875af15 --- /dev/null +++ b/tests/modern_estates_tests.cpp @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-3.0-only +// The four further properties of the bank (docs/new_engine/immobilien.md) on a synthetic +// manager: buying and selling at the day's price, the limit, the monthly price move and the rent. +#include + +#include "modern/game/estates.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); +} +ModernState world(int32_t euros) { + ModernState g; + g.career_id = "career:test"; + g.level = 2; + g.manager_teams = {0}; + g.manager_records.assign(5 * 0xb0c, 0); + 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(3000000); + check(estate_price(g, 0) == 450000 && estate_price(g, 1) == 1200000 && estate_price(g, 2) == 280000 && estate_price(g, 3) == 650000 && estate_price(g, 4) == 0, + "the starting prices"); + check(estate_rent(g, 1) == 4800, "the rent is four per mille of the price a month"); + check(buy_estate(g, 0, 1, 2) && estates_held(g, 0, 1) == 2 && cash(g) == 600000 && estates_value(g, 0) == 2400000, "two penthouses are bought"); + check(!buy_estate(g, 0, 1, 1) && !buy_estate(g, 0, 0, 0) && !buy_estate(g, 0, 4, 1) && !buy_estate(g, 1, 0, 1) && cash(g) == 600000, + "no purchase beyond the account, of nothing, of an unknown property or without a manager"); + check(!sell_estate(g, 0, 1, 3) && !sell_estate(g, 0, 0, 1), "nothing is sold that is not held"); + const int32_t before = cash(g); + estates_month(g); + bool moved_in_range = true; + for (int k = 0; k < kEstates; ++k) { + const int64_t base = kEstateBasePrice[size_t(k)], now = estate_price(g, k); + moved_in_range = moved_in_range && now >= base * 97 / 100 && now <= base * 103 / 100 + 1000 && now % 1000 == 0; + } + check(moved_in_range, "a month moves every price by minus two to plus three percent, in whole thousands"); + check(cash(g) == before + 2 * estate_rent(g, 1), "the rent of what he holds is paid at the new price"); + const int32_t price = estate_price(g, 1), held_cash = cash(g); + check(sell_estate(g, 0, 1, 1) && estates_held(g, 0, 1) == 1 && cash(g) == held_cash + price, "one is sold at the day's price"); + } + // the limit of twenty pieces, and prices that stay within half and three times the start + { + ModernState g = world(100000000); + check(buy_estate(g, 0, 2, kEstateLimit) && !buy_estate(g, 0, 2, 1), "twenty pieces of a property at most"); + bool bounded = true; + for (uint32_t month = 0; month < 600; ++month) { + g.date = month * 30; + estates_month(g); + for (int k = 0; k < kEstates; ++k) + bounded = bounded && estate_price(g, k) >= kEstateBasePrice[size_t(k)] / 2 && estate_price(g, k) <= kEstateBasePrice[size_t(k)] * 3; + } + check(bounded, "over fifty years the prices stay between half and three times their start"); + } + if (failures) return 1; + std::puts("modern_estates_tests: ok"); + return 0; +}