From 2ca6b21a947762e38c88bdbd196e5af36e19da62 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 09:12:34 +0100 Subject: [PATCH] Modern UI contract: contracts read, quote.request and contract.offer The contracts read lists remaining months, salary, insurance and bonuses per player and the open quote. quote.request asks a player's demands for one to four years (a draw, as at the desk); contract.offer answers applied or offer_rejected. A refused command also restores the open quote. Co-Authored-By: Claude Opus 5.5 --- docs/new_engine/ui-anbindung.md | 3 + src/modern/app/modern_session.cpp | 92 +++++++++++++++++++++++++++++- tests/modern_ui_contract_tests.cpp | 25 ++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index 212a5dd..7337b0d 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -31,6 +31,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht | `lineup` | die Kaderzeilen in Reihenfolge (die ersten elf spielen) mit Rolle, die Plätze der Startelf auf der Taktiktafel (`depth` 0–19, `lane` 0–8; das JSON hat keine Kommazahlen), `manual` (Aufstellung von Hand) | | `tactics` | die acht Einstellungen (`tactic:0` Grundausrichtung bis `tactic:7` Einsatz) mit Wert und Maximum aus der EXE; die Bedeutung der Diagramm-Einstellungen 1–3, 5, 6 ist nicht belegt, daher neutrale Namen | | `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 €) | | `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`. @@ -55,6 +56,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt |---|---|---| | `camp.book` | `campId`, optional `focus {condition, technique, play}` (0–15; Erholung folgt) | setzt die Schwerpunkte und bucht das Lager wie der Schreibtisch; Fehler `unknown_camp`, `invalid_focus`, `booked_this_week`, `visit_limit`, `insufficient_funds` | | `session.advance` | `{}` | der Anstoß am Schreibtisch: der Kalender läuft bis zum nächsten Schreibtisch eines Menschen, zum Saisonende oder zum Karriereende (Spiele noch ohne Live-Ansicht); `outcome` `career_ended` am Ende; Fehler `decision_pending` (eine Entscheidung am Schreibtisch fehlt, z. B. ein auslaufender Vertrag), `advance_failed` | +| `quote.request` | `kind: contract`, `playerId` | fragt die Forderungen des Spielers ab (zieht Zufall wie am Schreibtisch); `outcome: offer_pending`, die Forderungen stehen danach im `contracts`-Read | +| `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 | | `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 be544bd..20b2c7d 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -8823,7 +8823,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId"); const int manager = context.manager; if (manager < 0 || size_t(manager) >= g_.manager_teams.size() || - (kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank")) + (kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts")) 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); @@ -8853,6 +8853,38 @@ 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 == "contracts") { + // per player: remaining months, monthly salary, insurance, the team bonuses; the open quote + // (quote.request) with the monthly demand for one to four years + ui::ContractsState c; + try { c = ui::contracts_from_game(g_, manager, revision); } catch (const std::exception&) { + return modern::ui_error(request_id, "contracts_unavailable", "Die Verträge sind hier nicht verfügbar.", revision, false); + } + static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"}; + A players; + for (const auto& p : c.players) { + A premiums; + for (uint8_t b : p.team_premiums) premiums.push_back(int(b)); + players.push_back(O{{"playerId", modern::ui_player_id(g_, p.player_id)}, {"name", p.name}, + {"age", p.age}, {"position", kPositions[p.position & 3]}, + {"contractRemaining", O{{"value", int(p.remaining_months)}, {"unit", "months"}}}, + {"salaryMonthly", modern::ui_money(p.current_monthly_salary)}, + {"insuranceMonths", int(p.insurance)}, {"insuranceAvailable", p.insurance_available}, + {"insuranceFee", modern::ui_money(p.insurance_fee)}, {"offerBlocked", p.offer_blocked}, + {"bonuses", std::move(premiums)}}); + } + cli::Json quote = nullptr; + if (contract_quote_ && contract_quote_->manager_slot == manager) { + A demands; + for (size_t y = 0; y < 4; ++y) + demands.push_back(O{{"years", int(y + 1)}, {"monthlyDemand", modern::ui_money(contract_quote_->demands[y])}}); + quote = O{{"id", "quote:contract-" + std::to_string(contract_quote_->quote_id)}, + {"playerId", modern::ui_player_id(g_, contract_quote_->player_id)}, {"demands", std::move(demands)}, + {"maxMonthlySalary", modern::ui_money(200000)}}; + } + return modern::ui_snapshot(g_, context, request_id, + O{{"kind", "contracts"}, {"teamId", modern::ui_team_id(g_, team)}, {"players", std::move(players)}, {"quote", std::move(quote)}}); + } if (kind == "bank") { // account, fixed deposit, credit line, the 12 stocks and 6 funds (prices in whole euros, // converted to Money); the stock tip draws a random number and is no read @@ -8951,9 +8983,12 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision const GameRandom saved_game = game_; const uint64_t previous = revision; const int saved_entry_manager = lineup_entry_manager_, saved_entry_club = lineup_entry_club_; + const auto saved_quote = contract_quote_; + const uint64_t saved_quote_id = next_contract_quote_id_, saved_contract_request = last_contract_request_id_; 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; }; cli::Json answer; std::string error; @@ -9126,6 +9161,61 @@ 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" || 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, + // monthlySalary: Money}: the offer against that quote, accepted or rejected by the player + 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 keine Verträge."); + const SquadRange range = squad_range(team); + ui::ContractRequest r; + r.request_id = last_contract_request_id_ + 1; + r.revision = revision; + r.manager_slot = manager; + r.runtime_club = team; + if (kind == "quote.request") { + if (ui_text(*payload, "kind") != "contract") return refuse("unknown_quote", "quote.request kennt bisher kind contract."); + const std::string id = ui_text(*payload, "playerId"); + for (size_t row = 0; row < range.count; ++row) { + const int p = g_.squad_slots[range.first + row] & 0x0fff; + if (p != 0x0fff && modern::ui_player_id(g_, p) == id) r.row = int(row), r.player_id = p; + } + if (r.row < 0) return refuse("unknown_player", "Spieler nicht im Kader: " + id); + r.kind = ui::ContractActionKind::request_demands; + ui::ContractActionResult result; + if (!dispatch_contract(r, revision, result, error)) { restore(); return refuse("quote_refused", error); } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"contracts"}, "Forderungen liegen vor."); + std::get(answer.value)["outcome"] = "offer_pending"; + } else { + const std::string quote = ui_text(*payload, "quoteId"); + const cli::Json* years = ui_field(*payload, "years"); + const cli::Json* salary = ui_field(*payload, "monthlySalary"); + if (!contract_quote_ || quote != "quote:contract-" + std::to_string(contract_quote_->quote_id)) + return refuse("stale_quote", "Dieses Angebot gilt nicht mehr; bitte die Forderungen neu abfragen."); + if (!years || !years->integer() || *years->integer() < 1 || *years->integer() > 4 || !salary) + return refuse("invalid_payload", "years (1 bis 4) und monthlySalary (Money) nötig."); + int64_t cents = -1; + try { cents = std::stoll(ui_text(*salary, "minor")); } catch (const std::exception&) { cents = -1; } + if (cents < 0 || cents % 100 != 0) return refuse("invalid_amount", "monthlySalary in ganzen Euro."); + r.kind = ui::ContractActionKind::submit_offer; + r.quote_id = contract_quote_->quote_id; + r.row = contract_quote_->row; + r.player_id = contract_quote_->player_id; + r.term_column = uint8_t(*years->integer() - 1); + r.demand = contract_quote_->demands[r.term_column]; + r.monthly_salary = uint32_t(cents / 100); + const size_t board = size_t(manager) * 0x840 + size_t(r.row) * 0x58; + for (size_t i = 0; i < r.proposed_bonuses.size() && board + 0x12 + i < g_.tactics.size(); ++i) + r.proposed_bonuses[i] = g_.tactics[board + 0x12 + i]; // the bonuses stay as they are + ui::ContractActionResult result; + if (!dispatch_contract(r, revision, result, error)) { restore(); return refuse("offer_refused", error); } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"contracts", "squad", "desktop"}, + result.feedback.empty() ? (result.accepted ? "Vertrag verlängert." : "Angebot abgelehnt.") + : result.feedback); + if (!result.accepted) std::get(answer.value)["outcome"] = "offer_rejected"; + } } 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_ui_contract_tests.cpp b/tests/modern_ui_contract_tests.cpp index 5d345f4..9dab75b 100644 --- a/tests/modern_ui_contract_tests.cpp +++ b/tests/modern_ui_contract_tests.cpp @@ -235,6 +235,31 @@ int main(int argc, char** argv) { check(s(at(refused, "messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_bank + 2, "withdrawal above the deposit refused without change"); } + // contracts: demands as a quote, an offer against it, a stale quote refused + { + const J contracts = session.ui_read(O{{"kind", "contracts"}}, rev); + const auto* players = at(at(contracts, "data"), "players").array(); + check(players && !players->empty(), "contracts read"); + const std::string player = players && !players->empty() ? s(at((*players)[0], "playerId")) : ""; + const uint64_t before = rev; + const J quoted = session.ui_command(cmd("request:k1", "quote.request", O{{"kind", "contract"}, {"playerId", player}}), rev); + check(s(at(quoted, "outcome")) == "offer_pending" && rev == before + 1, "demands quoted"); + const J with_quote = session.ui_read(O{{"kind", "contracts"}}, rev); + const J& quote = at(at(with_quote, "data"), "quote"); + const auto* demands = at(quote, "demands").array(); + check(s(at(quote, "playerId")) == player && demands && demands->size() == 4, "quote with four terms"); + if (demands && demands->size() == 4) { + const std::string id = s(at(quote, "id")); + const J offer = session.ui_command(cmd("request:k2", "contract.offer", + O{{"quoteId", id}, {"years", 2}, {"monthlySalary", O{{"minor", "100"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev); + const std::string outcome = s(at(offer, "outcome")); + check(s(at(offer, "messageType")) == "command_result" && (outcome == "applied" || outcome == "offer_rejected") && + rev == before + 2, "offer answered"); + check(s(at(session.ui_command(cmd("request:k3", "contract.offer", + O{{"quoteId", id}, {"years", 2}, {"monthlySalary", O{{"minor", "100"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev), + "code")) == "stale_quote" && rev == before + 2, "a used quote is gone"); + } + } // 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"));