diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index 9e8ef0f..771ed01 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -33,6 +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 | +| `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 | | `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`. @@ -61,6 +62,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `contract.offer` | `quoteId`, `years` 1–4, `monthlySalary` (`Money`) | das Angebot gegen die Forderung; `outcome` `applied` (verlängert) oder `offer_rejected`; das Angebot ist danach verbraucht (`stale_quote`). Versicherung und Prämien folgen | | `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` | | `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:`, `fund:`) 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` | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index a17fcba..fab330a 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -8824,7 +8824,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co const int manager = context.manager; if (manager < 0 || size_t(manager) >= g_.manager_teams.size() || (kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" && - kind != "advertising")) + kind != "advertising" && kind != "stadium")) return modern::ui_read(g_, context, request); if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager)) return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false); @@ -8854,6 +8854,47 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co {"rows", std::move(rows)}, {"positions", std::move(positions)}, {"depthMax", 19}, {"laneMax", 8}, {"manual", g_.manager_options.size() > size_t(manager) * 5 && g_.manager_options[size_t(manager) * 5] == 0}}); } + if (kind == "stadium") { + // the periphery (14 objects; the traffic access has three stages), the eight facilities with + // their level, the eight stand blocks (capacity in thousands, seats, roof) and the ticket price; + // building prices follow with the stadium quotes (they carry the day's construction percent) + ui::StadiumState st; + ui::StadiumDataProjection data; + try { + st = ui::stadium_from_game(g_, exe_, revision); + data = ui::stadium_data_from_game(g_, exe_, manager, 0x40); + } catch (const std::exception&) { + return modern::ui_error(request_id, "stadium_unavailable", "Das Stadion ist hier nicht verfügbar.", revision, false); + } + const auto text = [&](size_t id) { return g_.texts && id < g_.texts->strings.size() ? ui::original_to_utf8(g_.texts->strings[id]) : std::string{}; }; + A periphery, facilities, blocks; + for (size_t o = 0; o < 14; ++o) { + const int level = st.level[o]; + O row{{"id", "periphery:" + std::to_string(o)}, {"name", text(720 + o)}, {"constructionDays", int(st.days[o])}}; + if (o == 0) row["stage"] = level == 0 ? 0 : (level - 1) / 85 + 1, row["maxStage"] = 3; + else row["built"] = level != 0; + periphery.push_back(std::move(row)); + } + static constexpr const char* kFacilities[8] = {"floodlights", "scoreboard", "pitch_heating", "vip_lounge", "pitch", "comfort", "condition", "safety"}; + for (size_t i = 0; i < 8; ++i) { + const auto& f = st.investments[i]; + facilities.push_back(O{{"id", std::string("facility:") + kFacilities[i]}, {"name", text(734 + i)}, + {"level", int(f.current_level)}, {"maxLevel", i == 2 || i == 3 ? 2 : 4}, + {"constructionWeeks", int(f.construction_weeks)}, {"upgradeAvailable", f.available}}); + } + for (size_t b = 0; b < st.blocks.size(); ++b) { + const auto& k = st.blocks[b]; + blocks.push_back(O{{"id", "block:" + std::string(1, char('a' + b))}, {"name", text(742 + b)}, + {"places", int64_t(k.capacity_level) * 1000}, + {"maxPlaces", int64_t(exe_.u8(::bmh::layout::CareerSession_Invalid_RuntimeField + uint32_t(b))) * 1000}, + {"seats", (k.flags & 1) != 0}, {"roof", (k.flags & 2) != 0}, + {"constructionWeeks", int(k.construction_weeks)}, {"placesAfterConstruction", int64_t(k.capacity) * 1000}}); + } + return modern::ui_snapshot(g_, context, request_id, + O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"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)}}}}); + } if (kind == "advertising") { // the 14 boards, the shirt and the TV rights with their contract, the open offers per place, // the three budgets and the original's finance preview @@ -9347,6 +9388,19 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision revision = previous + 1; answer = modern::ui_command_result(request_id, previous, revision, {"advertising", "desktop", "bank"}, kind == "advertising.accept" ? "Werbevertrag abgeschlossen." : "Budget gesetzt."); + } else if (kind == "ticket.commit") { + // payload {price: Money}: the admission price, 8 to 25 euros + const cli::Json* price = ui_field(*payload, "price"); + int64_t cents = -1; + try { cents = price ? std::stoll(ui_text(*price, "minor")) : -1; } catch (const std::exception&) { cents = -1; } + if (cents < 800 || cents > 2500 || cents % 100) return refuse("invalid_amount", "Eintritt 8 bis 25 Euro in ganzen Euro."); + TicketPriceRequest r; + r.identity.manager_slot = manager, r.identity.runtime_club = g_.manager_teams[size_t(manager)], r.identity.revision = revision; + r.identity.stable_club_identity = int(g_.club_ids.at(size_t(r.identity.runtime_club))); + r.price = int(cents / 100); + if (!dispatch_ticket_price(r, revision, error)) { restore(); return refuse("ticket_refused", error); } + if (revision != previous) revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Eintrittspreis gesetzt."); } else if (kind == "bank.commit") { // payload {action: deposit|withdraw, amount: Money} or {action: buy|sell, assetId: stock:|fund:, count} const std::string action = ui_text(*payload, "action"); diff --git a/tests/modern_season_sim.cpp b/tests/modern_season_sim.cpp index dbee00c..aa78a45 100644 --- a/tests/modern_season_sim.cpp +++ b/tests/modern_season_sim.cpp @@ -743,7 +743,7 @@ int main(int argc, char** argv) { read({{"kind", "squad"}}); read({{"kind", "table"}, {"league", 42}}); // the interface contract (docs/new_engine/ui-anbindung.md) - for (const char* kind : {"session", "desktop", "squad", "camps", "nonsense"}) { + for (const char* kind : {"session", "desktop", "squad", "camps", "stadium", "nonsense"}) { const auto request = cli::Json::Object{{"kind", kind}, {"requestId", std::string("request:sim-") + kind}}; std::printf("ui_read %s\n -> %s\n", kind, cli::dump_json(session.ui_read(request, revision)).c_str()); } diff --git a/tests/modern_ui_contract_tests.cpp b/tests/modern_ui_contract_tests.cpp index ca23713..9ccfa3a 100644 --- a/tests/modern_ui_contract_tests.cpp +++ b/tests/modern_ui_contract_tests.cpp @@ -286,6 +286,25 @@ int main(int argc, char** argv) { "unknown_offer" && modern::save_stream(session.state()) == kept, "unknown offer refused"); std::printf("(advertising offer %s)\n", offer.empty() ? "none" : offer.c_str()); } + // stadium: periphery, facilities, blocks; the ticket price + { + const J stadium = session.ui_read(O{{"kind", "stadium"}}, rev); + const J& d = at(stadium, "data"); + if (s(at(stadium, "messageType")) != "snapshot") std::fprintf(stderr, "stadium: %s\n", cli::dump_json(stadium).c_str()); + check(at(d, "periphery").array() && at(d, "periphery").array()->size() == 14 && at(d, "blocks").array() && + at(d, "blocks").array()->size() == 8 && at(d, "facilities").array() && at(d, "facilities").array()->size() == 8, + "stadium read"); + if (const auto* p = at(d, "periphery").array(); p && !p->empty()) + check(!s(at((*p)[0], "name")).empty() && at((*p)[0], "stage").integer(), "traffic access with its stage"); + const uint64_t before = rev; + const J done = session.ui_command(cmd("request:e1", "ticket.commit", O{{"price", O{{"minor", "1200"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev); + if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "ticket: %s\n", cli::dump_json(done).c_str()); + const J after = session.ui_read(O{{"kind", "stadium"}}, rev); + check(s(at(done, "messageType")) == "command_result" && s(at(at(at(after, "data"), "ticketPrice"), "minor")) == "1200" && + 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"); + } // session.advance: three kickoffs, each one revision, the date moves on { const std::string date_before = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));