From abbba65a813be2c1ee2ab66f22d9c70199931adb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 13:42:26 +0100 Subject: [PATCH] Modern UI contract: stand block expansion quote.request {kind: block, blockId, places, seats?, roof?} builds the stand block editor's draft (target places, then seats and roof one at a time) and stadium.commit confirms it with or without the tip, or cancels it. The stadium read shows the quote with its breakdown. Co-Authored-By: Claude Opus 5.5 --- docs/new_engine/ui-anbindung.md | 4 +- src/modern/app/modern_session.cpp | 73 ++++++++++++++++++++++++++++-- tests/modern_ui_contract_tests.cpp | 23 ++++++++++ 3 files changed, 95 insertions(+), 5 deletions(-) diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index 0c3bf87..6193573 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -81,8 +81,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen): Der letzte menschliche Manager beendet die Karriere (`outcome: career_ended`, `session`-Read `sessionState: "ended"`, danach antwortet jeder Befehl `career_ended`). Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` | | `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) | | `sponsor.answer` | `accept` | Antwort auf das Exklusiv-Sponsor-Angebot: beginnt sofort, wird vorgemerkt oder abgelehnt | -| `quote.request` (Stadion) | `kind: periphery`, `objectId` oder `kind: facility`, `facilityId`, `increment` 1–3 | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen; `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) | -| `stadium.commit` | `quoteId`, `accept`, bei Anlagen `tip` | baut (Anlagen mit oder ohne Trinkgeld für schnelleres Bauen, wie das Original fragt) oder lehnt ab und schließt den Dialog; Fehler `stale_quote`, `stadium_refused` | +| `quote.request` (Stadion) | `kind: periphery`, `objectId`; oder `kind: facility`, `facilityId`, `increment` 1–3; oder `kind: block`, `blockId` (`block:a`–`block:h`), `places` (Ziel insgesamt), optional `seats`, `roof` | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen bzw. stellt den Tribünenausbau zusammen (Plätze, Sitzplätze, Dach; vorhandene Ausstattung bleibt; Angebot mit Aufschlüsselung Plätze/Sitze/Dach); `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) | +| `stadium.commit` | `quoteId`, `accept`, bei Anlagen und Blöcken `tip` | baut (Anlagen und Blöcke mit oder ohne Trinkgeld für schnelleres Bauen, wie das Original fragt) oder lehnt ab und schließt den Dialog; Fehler `stale_quote`, `stadium_refused` | | `session.advance` mit `live: true` | wie oben, dazu `contractExpiry` | Live-Spieltag: hält in der ersten Minute eines Live-Spiels an (`changedReadKinds: ["live"]`); läuft kein Live-Spiel, endet er sofort wie ein normaler Anstoß | | `live.step` | `minutes` (1–150, sonst 1) | spielt so viele Spielminuten des Live-Spiels und hält wieder an; ist der Spieltag vorbei, kommt die Antwort des Anstoßes | | `live.substitute` | `outPlayerId`, `inPlayerId` | Wechsel wie im Spielfeld-Bildschirm des Originals (öffnen, tauschen, schließen; ab Minute 3); Fehler `substitution_refused` | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 2151945..09b8510 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9044,6 +9044,17 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co quote = O{{"id", id}, {"kind", "facility"}, {"facilityId", std::string("facility:") + kFacilities[size_t(*stadium_.investment)]}, {"toLevel", int(stadium_.option->target_level)}, {"price", modern::ui_money(stadium_.option->base_price)}, {"weeks", int(stadium_.option->base_weeks)}, {"tipPercent", O{{"min", 6}, {"max", 14}}}}; + else if (stadium_.block_expansion) { + const auto& q = stadium_.block_expansion->quote; + quote = O{{"id", id}, {"kind", "block"}, {"blockId", "block:" + std::string(1, char('a' + int(q.slot)))}, + {"places", int64_t(q.total_target_places)}, {"maxPlaces", int64_t(q.max_places)}, {"newPlaces", int64_t(q.new_places)}, + {"seats", (stadium_.block_expansion->desired_features & 1) != 0}, {"roof", (stadium_.block_expansion->desired_features & 2) != 0}, + {"price", modern::ui_money(q.base_price)}, + {"breakdown", A{O{{"code", "places"}, {"amount", modern::ui_money(q.new_places_cost)}}, + O{{"code", "seats"}, {"amount", modern::ui_money(q.seats_cost)}}, + O{{"code", "roof"}, {"amount", modern::ui_money(q.roof_cost)}}}}, + {"weeks", int(q.base_weeks)}, {"tipPercent", O{{"min", 6}, {"max", 14}}}}; + } } return modern::ui_snapshot(g_, context, request_id, O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"quote", std::move(quote)}, {"periphery", std::move(periphery)}, @@ -9736,7 +9747,8 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision "statistics", "almanac"}, what); if (r.kind == TurnDeskKind::CareerComplete) std::get(answer.value)["outcome"] = "career_ended"; - } else if ((kind == "quote.request" && (ui_text(*payload, "kind") == "periphery" || ui_text(*payload, "kind") == "facility")) || + } else if ((kind == "quote.request" && (ui_text(*payload, "kind") == "periphery" || ui_text(*payload, "kind") == "facility" || + ui_text(*payload, "kind") == "block")) || kind == "stadium.commit") { // The stadium dialog of the original in two commands; it stays open in between: // quote.request {kind: periphery, objectId} - opens the stadium, the building firm's offer @@ -9755,9 +9767,52 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision r.object = object, r.option = option, r.price = price, r.accept_tip = tip; ok = dispatch_stadium(r, revision, error); }; + // a step of the stand block editor: the slot, the target places and features, the quote it changes + const auto block_step = [&](ui::StadiumRequestKind k, int slot, uint32_t total, uint8_t features, bool tip = false) { + if (!ok) return; + ui::StadiumRequest r; + r.kind = k, r.manager_slot = manager, r.runtime_club = team, r.revision = revision; + r.stable_club_identity = int(g_.club_ids.at(size_t(team))); + r.scope = stadium_.scope, r.sequence = stadium_.sequence; + r.block_slot = slot, r.block_total_places = total, r.block_features = features, r.accept_tip = tip; + if (k != ui::StadiumRequestKind::expansion_select && stadium_.block_expansion) r.expected_block_quote = stadium_.block_expansion->quote; + ok = dispatch_stadium(r, revision, error); + }; static constexpr const char* kFacilities[8] = {"floodlights", "scoreboard", "pitch_heating", "vip_lounge", "pitch", "comfort", "condition", "safety"}; - if (kind == "quote.request") { - if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment)) + if (kind == "quote.request" && ui_text(*payload, "kind") == "block") { + // {blockId: "block:a".."block:h", places: target total, seats?, roof?} + if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment || stadium_.block_expansion)) + return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit)."); + const std::string id = ui_text(*payload, "blockId"); + const int slot = id.size() == 7 && id.starts_with("block:") && id[6] >= 'a' && id[6] <= 'h' ? id[6] - 'a' : -1; + const cli::Json* places = ui_field(*payload, "places"); + if (slot < 0 || !places || !places->integer() || *places->integer() < 0) return refuse("invalid_payload", "blockId und places nötig."); + const auto flag = [&](const char* key) { + const cli::Json* v = ui_field(*payload, key); + return v && std::holds_alternative(v->value) && std::get(v->value); + }; + if (!stadium_.opened) step(ui::StadiumRequestKind::open); + block_step(ui::StadiumRequestKind::expansion_select, slot, 0, 0); + if (ok) { + auto& d = *stadium_.block_expansion; + const uint32_t total = uint32_t(*places->integer()); + if (total != d.total_target_places) block_step(ui::StadiumRequestKind::expansion_set_total, slot, total, d.desired_features); + // a feature the block has stays; seats and roof are added one at a time + for (const uint8_t bit : {kBlockSeat, kBlockRoof}) { + if (!ok) break; + const auto& now = *stadium_.block_expansion; + const bool want = flag(bit == kBlockSeat ? "seats" : "roof") || (now.quote.current_raw_flags & bit); + if (want != bool(now.desired_features & bit)) + block_step(ui::StadiumRequestKind::expansion_toggle_feature, slot, now.total_target_places, uint8_t(now.desired_features ^ bit)); + } + } + if (!ok) { restore(); return refuse("stadium_refused", error); } + revision = previous + 1; + stadium_.revision = revision; + answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Angebot liegt vor."); + std::get(answer.value)["outcome"] = "offer_pending"; + } else if (kind == "quote.request") { + if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment || stadium_.block_expansion)) return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit)."); if (!stadium_.opened) step(ui::StadiumRequestKind::open); if (ui_text(*payload, "kind") == "periphery") { @@ -9815,6 +9870,18 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision step(ui::StadiumRequestKind::answer_construction_tip, facility, option, int32_t(with_tip ? stadium_.tip->offered_price : stadium_.tip->base_price), with_tip); } + } else if (stadium_.block_expansion) { + const int slot = int(stadium_.block_expansion->quote.slot); + const uint32_t total = stadium_.block_expansion->total_target_places; + const uint8_t features = stadium_.block_expansion->desired_features; + if (!yes) { + block_step(ui::StadiumRequestKind::expansion_cancel, slot, total, features); + } else { + // confirm draws the tip offer; a zero-cost draft closes without building + block_step(ui::StadiumRequestKind::expansion_confirm, slot, total, features); + if (ok && stadium_.block_expansion && stadium_.block_expansion->tip) + block_step(ui::StadiumRequestKind::expansion_answer_tip, slot, total, features, with_tip); + } } else { return refuse("stale_quote", "Es liegt kein Stadionangebot vor."); } diff --git a/tests/modern_ui_contract_tests.cpp b/tests/modern_ui_contract_tests.cpp index e6a1ff4..135f2a3 100644 --- a/tests/modern_ui_contract_tests.cpp +++ b/tests/modern_ui_contract_tests.cpp @@ -334,6 +334,29 @@ int main(int argc, char** argv) { } else { std::printf("(facility quote: %s)\n", s(at(q, "code")).c_str()); } + // a stand block: 1000 more places + std::string block; + int64_t places = 0; + if (const auto* blocks = at(at(after, "data"), "blocks").array()) + for (const auto& b : *blocks) + if (block.empty() && *at(b, "constructionWeeks").integer() == 0 && + *at(b, "places").integer() + 1000 <= *at(b, "maxPlaces").integer()) + block = s(at(b, "id")), places = *at(b, "places").integer() + 1000; + if (!block.empty()) { + const uint64_t b1 = rev; + const J bq = session.ui_command(cmd("request:eb1", "quote.request", O{{"kind", "block"}, {"blockId", block}, {"places", places}}), rev); + const J quote = quote_of(); + if (s(at(bq, "messageType")) != "command_result") std::fprintf(stderr, "block quote: %s\n", cli::dump_json(bq).c_str()); + check(s(at(quote, "kind")) == "block" && *at(quote, "places").integer() == places, "block quoted"); + const J built = session.ui_command(cmd("request:eb2", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}, {"tip", false}}), rev); + if (s(at(built, "messageType")) != "command_result") std::fprintf(stderr, "block build: %s\n", cli::dump_json(built).c_str()); + const J st = session.ui_read(O{{"kind", "stadium"}}, rev); + int weeks = -1; + for (const auto& b : *at(at(st, "data"), "blocks").array()) + if (s(at(b, "id")) == block) weeks = int(*at(b, "constructionWeeks").integer()); + check(s(at(built, "messageType")) == "command_result" && rev == b1 + 2 && weeks > 0, "block expansion under way"); + std::printf("(block %s to %lld places: %d weeks)\n", block.c_str(), (long long)places, weeks); + } const J q2 = session.ui_command(cmd("request:e7", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:comfort"}, {"increment", 1}}), rev); if (s(at(q2, "messageType")) == "command_result") { const J declined = session.ui_command(cmd("request:e8", "stadium.commit", O{{"quoteId", at(quote_of(), "id")}, {"accept", false}}), rev);