Modern UI contract: building in the stadium (periphery and facilities)

The original's stadium dialog in two commands: quote.request opens it and
gets the building firm's offer (periphery) or selects a facility and levels;
stadium.commit builds - facilities with or without the tip for faster
building - or declines, and closes the dialog. The stadium read shows the
open offer; a refused command also restores the dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:23:06 +01:00
1 parent 6386c891b5
commit e6bc72d3a0
3 files changed
+152 -7

No files matched your search

+3 -1
View File
@@ -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/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` 0–3, sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €). Baupreise folgen mit den Stadion-Angeboten |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` 0–3, sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; Kredite noch `unavailable` (folgen), der Aktientipp zieht Zufall und kommt als `quote.request` |
Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`.
@@ -63,6 +63,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| `advertising.accept` | `offerId` | nimmt ein Angebot an wie am Schreibtisch; Fehler `unknown_offer`, `advertising_refused` |
| `budget.commit` | `budgetId` (`budget:merchandise`, `budget:press`, `budget:fans`), `amount` (`Money`) | setzt ein Budget; Fehler `unknown_budget`, `invalid_amount`, `advertising_refused` (z. B. Lieferung läuft, zu wenig Geld) |
| `ticket.commit` | `price` (`Money`, 8–25 €) | der Eintrittspreis; Fehler `invalid_amount`, `ticket_refused` |
| `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` |
| `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:<n>`, `fund:<n>`) und `count` | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. |
| `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) |
| `tactics.commit` | `values`: die acht Werte | jede geänderte Einstellung über die Prüfung der Taktiktafel (eine gesetzte Grundausrichtung beendet die Steuerung durch den Assistenten); Fehler `invalid_tactic` |
+105 -1
View File
@@ -8890,8 +8890,20 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
{"seats", (k.flags & 1) != 0}, {"roof", (k.flags & 2) != 0},
{"constructionWeeks", int(k.construction_weeks)}, {"placesAfterConstruction", int64_t(k.capacity) * 1000}});
}
// the open offer of the stadium dialog (quote.request), answered by stadium.commit
cli::Json quote = nullptr;
if (stadium_.opened && stadium_.manager == manager) {
const std::string id = "quote:stadium-" + std::to_string(stadium_.scope);
if (stadium_.periphery_quote)
quote = O{{"id", id}, {"kind", "periphery"}, {"objectId", "periphery:" + std::to_string(stadium_.periphery_quote->first)},
{"price", modern::ui_money(stadium_.periphery_quote->second)}};
else if (stadium_.investment && stadium_.option)
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}}}};
}
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"periphery", std::move(periphery)},
O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"quote", std::move(quote)}, {"periphery", std::move(periphery)},
{"facilities", std::move(facilities)}, {"blocks", std::move(blocks)},
{"ticketPrice", modern::ui_money(data.ticket_price)}, {"ticketPriceRange", O{{"min", modern::ui_money(8)}, {"max", modern::ui_money(25)}}}});
}
@@ -9067,11 +9079,14 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
const auto saved_quote = contract_quote_;
const uint64_t saved_quote_id = next_contract_quote_id_, saved_contract_request = last_contract_request_id_;
const uint64_t saved_advertising_request = last_advertising_request_id_;
const StadiumRuntime saved_stadium = stadium_;
const uint64_t saved_stadium_scope = next_stadium_scope_;
const auto restore = [&] {
g_ = saved_state; rand_ = saved_rand; game_ = saved_game; revision = previous;
lineup_entry_manager_ = saved_entry_manager, lineup_entry_club_ = saved_entry_club; // the board stays as it was
contract_quote_ = saved_quote, next_contract_quote_id_ = saved_quote_id, last_contract_request_id_ = saved_contract_request;
last_advertising_request_id_ = saved_advertising_request;
stadium_ = saved_stadium, next_stadium_scope_ = saved_stadium_scope;
};
cli::Json answer;
std::string error;
@@ -9296,6 +9311,95 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
"statistics", "almanac"}, what);
if (r.kind == TurnDeskKind::CareerComplete)
std::get<cli::Json::Object>(answer.value)["outcome"] = "career_ended";
} else if ((kind == "quote.request" && (ui_text(*payload, "kind") == "periphery" || ui_text(*payload, "kind") == "facility")) ||
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
// quote.request {kind: facility, facilityId, increment 1-3} - a facility and how many levels
// stadium.commit {quoteId, accept, tip?} - builds (facilities: with or without the tip for
// faster building, as the original asks) or declines, and closes the stadium
const int team = g_.manager_teams[size_t(manager)];
if (team < 0 || team >= league_clubs()) return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es kein Stadion.");
bool ok = true;
const auto step = [&](ui::StadiumRequestKind k, int object = -1, int option = -1, int32_t price = 0, 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)));
if (k != ui::StadiumRequestKind::open) r.scope = stadium_.scope, r.sequence = stadium_.sequence;
r.object = object, r.option = option, r.price = price, r.accept_tip = tip;
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))
return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit).");
if (!stadium_.opened) step(ui::StadiumRequestKind::open);
if (ui_text(*payload, "kind") == "periphery") {
int object = -1;
if (std::sscanf(ui_text(*payload, "objectId").c_str(), "periphery:%d", &object) != 1 || object < 0 || object >= 14) {
restore(); return refuse("unknown_object", "Unbekanntes Umfeldobjekt.");
}
step(ui::StadiumRequestKind::quote_periphery, object);
} else {
const std::string id = ui_text(*payload, "facilityId");
int facility = -1;
for (int i = 0; i < 8; ++i) if (id == std::string("facility:") + kFacilities[i]) facility = i;
const cli::Json* inc = ui_field(*payload, "increment");
if (facility < 0 || !inc || !inc->integer() || *inc->integer() < 1 || *inc->integer() > 3) {
restore(); return refuse("invalid_payload", "facilityId und increment (1 bis 3) nötig.");
}
step(ui::StadiumRequestKind::select_investment, facility);
if (ok) {
StadiumInvestmentConstants constants;
for (unsigned i = 0; i < 8; ++i) {
constants.price[i] = exe_.u32(::bmh::layout::CareerSession_DispatchStadium_RuntimeField + i * 4);
constants.weeks[i] = exe_.u8(::bmh::layout::CareerSession_DispatchStadium_RuntimeField2 + (14 + i) * 5);
}
const auto options = modern::stadium_investment_options_source(g_, manager, static_cast<StadiumInvestment>(facility),
stadium_.price_percent, constants);
const size_t option = size_t(*inc->integer() - 1);
if (option >= options.size()) { restore(); return refuse("level_unavailable", "So viele Stufen sind nicht möglich."); }
step(ui::StadiumRequestKind::select_investment_option, facility, int(option), int32_t(options[option].base_price));
}
}
if (!ok) { restore(); return refuse("stadium_refused", error); }
revision = previous + 1;
stadium_.revision = revision; // the open dialog continues at the command's one revision
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Angebot liegt vor.");
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
} else {
const std::string quote = ui_text(*payload, "quoteId");
const cli::Json* accept = ui_field(*payload, "accept");
const cli::Json* tip = ui_field(*payload, "tip");
const bool yes = accept && std::holds_alternative<bool>(accept->value) && std::get<bool>(accept->value);
const bool with_tip = tip && std::holds_alternative<bool>(tip->value) && std::get<bool>(tip->value);
if (!stadium_.opened || quote != "quote:stadium-" + std::to_string(stadium_.scope))
return refuse("stale_quote", "Dieses Stadionangebot gilt nicht mehr.");
if (stadium_.periphery_quote) {
const auto [object, price] = *stadium_.periphery_quote;
step(yes ? ui::StadiumRequestKind::build_periphery : ui::StadiumRequestKind::decline_periphery, object, -1, price);
} else if (stadium_.investment && stadium_.option) {
const int facility = int(*stadium_.investment), option = stadium_.option_index;
const int32_t base = int32_t(stadium_.option->base_price);
if (!yes) {
step(ui::StadiumRequestKind::cancel_investment, facility);
} else {
step(ui::StadiumRequestKind::confirm_investment, facility, option, base);
if (ok && stadium_.tip)
step(ui::StadiumRequestKind::answer_construction_tip, facility, option,
int32_t(with_tip ? stadium_.tip->offered_price : stadium_.tip->base_price), with_tip);
}
} else {
return refuse("stale_quote", "Es liegt kein Stadionangebot vor.");
}
const std::string feedback = stadium_.feedback;
step(ui::StadiumRequestKind::close);
if (!ok) { restore(); return refuse("stadium_refused", error); }
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"stadium", "desktop", "bank"},
!feedback.empty() ? feedback : yes ? "Der Bau beginnt." : "Abgelehnt.");
}
} else if (kind == "quote.request" || kind == "contract.offer") {
// quote.request {kind: "contract", playerId}: the player's demands for one to four years
// (draws a random number, as at the desk); contract.offer {quoteId, years 1-4,
+44 -5
View File
@@ -304,6 +304,43 @@ int main(int argc, char** argv) {
rev <= before + 1, "ticket price set");
check(s(at(session.ui_command(cmd("request:e2", "ticket.commit", O{{"price", O{{"minor", "3000"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev),
"code")) == "invalid_amount", "ticket price above 25 refused");
// building: a periphery object not built yet, then a facility level without the tip
std::string object;
if (const auto* p = at(at(after, "data"), "periphery").array())
for (const auto& o : *p)
if (object.empty() && at(o, "built").value.index() == 1 && !truth(at(o, "built")) && *at(o, "constructionDays").integer() == 0)
object = s(at(o, "id"));
const auto quote_of = [&]() { const J st = session.ui_read(O{{"kind", "stadium"}}, rev); return J(at(at(st, "data"), "quote")); };
if (!object.empty()) {
const uint64_t b0 = rev;
const J q = session.ui_command(cmd("request:e3", "quote.request", O{{"kind", "periphery"}, {"objectId", object}}), rev);
if (s(at(q, "messageType")) != "command_result") std::fprintf(stderr, "periphery quote: %s\n", cli::dump_json(q).c_str());
const J quote = quote_of();
check(s(at(q, "outcome")) == "offer_pending" && s(at(quote, "objectId")) == object && rev == b0 + 1, "periphery quoted");
const J built = session.ui_command(cmd("request:e4", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}}), rev);
if (s(at(built, "messageType")) != "command_result") std::fprintf(stderr, "periphery build: %s\n", cli::dump_json(built).c_str());
check(s(at(built, "messageType")) == "command_result" && rev == b0 + 2 && std::holds_alternative<std::nullptr_t>(quote_of().value),
"periphery built, the stadium closed");
}
{
const uint64_t b0 = rev;
const J q = session.ui_command(cmd("request:e5", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:safety"}, {"increment", 1}}), rev);
const J quote = quote_of();
if (s(at(q, "messageType")) == "command_result") {
check(s(at(quote, "kind")) == "facility" && at(quote, "price").object(), "facility quoted");
const J done = session.ui_command(cmd("request:e6", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}, {"tip", false}}), rev);
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "facility build: %s\n", cli::dump_json(done).c_str());
check(s(at(done, "messageType")) == "command_result" && rev == b0 + 2, "facility ordered");
} else {
std::printf("(facility quote: %s)\n", s(at(q, "code")).c_str());
}
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);
check(s(at(declined, "messageType")) == "command_result" && std::holds_alternative<std::nullptr_t>(quote_of().value),
"facility offer declined, the stadium closed");
}
}
}
// session.advance: three kickoffs, each one revision, the date moves on
{
@@ -361,15 +398,17 @@ int main(int argc, char** argv) {
check(s(at(session.read_almanac(O{{"kind", "match"}, {"id", "match:0-0"}}), "error")) == "almanac_match_not_found",
"unknown match");
// the statistics screen: real data (fictional false), unrecorded views say so
// (the club views need a club desk: on an international day the manager sits at the national one)
const J minutes = session.read_statistics_screen(O{{"section", 8}});
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) && at(minutes, "rows").array() &&
at(minutes, "rows").array()->size() == 4, "minute statistics");
const J transfers = session.read_statistics_screen(O{{"section", 1}});
const bool club_desk = !std::holds_alternative<std::nullptr_t>(at(minutes, "club").value);
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) &&
(!club_desk || (at(minutes, "rows").array() && at(minutes, "rows").array()->size() == 4)), "minute statistics");
const J transfers = session.read_statistics_screen(O{{"section", 0}});
check(truth(at(transfers, "ok")) && !truth(at(transfers, "available")) && s(at(transfers, "reason")) == "not_recorded",
"transfer history not recorded");
"title chances not recorded");
check(s(at(session.read_statistics_screen(O{{"section", 9}}), "error")) == "invalid_statistics_filter", "bad section");
const J curves = session.read_statistics_screen(O{{"section", 2}});
check(at(curves, "series").array() && at(curves, "series").array()->size() == 6, "the six curves of the original");
check(!club_desk || (at(curves, "series").array() && at(curves, "series").array()->size() == 6), "the six curves of the original");
}
} catch (const std::exception& ex) {
std::fprintf(stderr, "FAIL: %s\n", ex.what());