Modern UI contract: advertising read, advertising.accept and budget.commit

The advertising read lists boards, shirt and TV rights with their contract and
open offers, the three budgets and the finance preview. advertising.accept
takes an offer by id, budget.commit sets a budget, both through the desk's
own checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:16:51 +01:00
1 parent f71f072774
commit 4372e6b78a
3 files changed
+109 -1

No files matched your search

+3
View File
@@ -32,6 +32,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `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 €) |
| `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 |
| `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`.
@@ -58,6 +59,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| `session.advance` | optional `contractExpiry {playerId: {action: "renew", years, monthlySalary} | {action: "release"}}` | 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. Läuft unterwegs ein Vertrag aus (das Original fragt in dem Moment), gilt die mitgeschickte Antwort; fehlt sie, wird der Lauf zurückgerollt und `decision_pending` nennt in `message.args` `{decision: "contract_expiry", playerId}` - die UI fragt und schickt den Anstoß mit der Antwort erneut. Sonst `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 |
| `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) |
| `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` |
+80 -1
View File
@@ -8823,7 +8823,8 @@ 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 != "contracts"))
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
kind != "advertising"))
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 +8854,45 @@ 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 == "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
ui::AdvertisingState a;
try { a = ui::advertising_from_game(g_, manager, revision); } catch (const std::exception&) {
return modern::ui_error(request_id, "advertising_unavailable", "Die Werbung ist hier nicht verfügbar.", revision, false);
}
const auto contract = [&](const ui::AdvertisingContract& c, const std::string& id, int display) {
A offers;
if (display >= 0 && display < 16)
for (const auto& o : a.offers[size_t(display)].offers) {
if (!o.present) continue;
const auto& names = display == 15 ? a.television_sponsor_names : a.board_sponsor_names;
offers.push_back(O{{"id", "offer:ad-" + std::to_string(display) + "-" + std::to_string(o.raw_slot)},
{"sponsor", o.sponsor_id < names.size() ? cli::Json(names[o.sponsor_id]) : cli::Json(nullptr)},
{"monthly", modern::ui_money(o.monthly_amount)}, {"boards", int(o.bundle_units)},
{"months", int(o.months)}, {"allowed", o.can_accept}});
}
return cli::Json(O{{"id", id}, {"active", c.active},
{"sponsor", c.active ? cli::Json(c.sponsor_name) : cli::Json(nullptr)},
{"monthly", modern::ui_money(c.monthly_amount)}, {"monthsRemaining", int(c.months_remaining)},
{"extensionMonths", int(c.extension_months)}, {"option", c.option_marker},
{"offers", std::move(offers)}});
};
A boards;
for (size_t i = 0; i < a.boards.size(); ++i) boards.push_back(contract(a.boards[i], "ad:board/" + std::to_string(i), int(i)));
A budgets;
static constexpr const char* kBudgets[3] = {"budget:merchandise", "budget:press", "budget:fans"};
for (size_t i = 0; i < 3; ++i)
budgets.push_back(O{{"id", kBudgets[i]}, {"label", a.spending_labels[i]}, {"current", modern::ui_money(a.spending[i].current_amount)},
{"maximum", modern::ui_money(a.spending[i].maximum_amount)}, {"deliveryWeeks", int(a.spending[i].delivery_weeks)},
{"available", a.spending[i].available}});
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "advertising"}, {"teamId", modern::ui_team_id(g_, team)}, {"boards", std::move(boards)},
{"shirt", contract(a.shirt, "ad:shirt", 14)}, {"television", contract(a.television, "ad:tv", 15)},
{"budgets", std::move(budgets)},
{"preview", O{{"income", modern::ui_money(a.finance_preview.income)}, {"expenses", modern::ui_money(a.finance_preview.expenses)},
{"balance", modern::ui_money(a.finance_preview.balance)}}}});
}
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
@@ -8985,10 +9025,12 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& 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 uint64_t saved_advertising_request = last_advertising_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;
last_advertising_request_id_ = saved_advertising_request;
};
cli::Json answer;
std::string error;
@@ -9268,6 +9310,43 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
: result.feedback);
if (!result.accepted) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
}
} else if (kind == "advertising.accept" || kind == "budget.commit") {
// advertising.accept {offerId: "offer:ad-<display>-<pool slot>"}: an offer of the advertising read;
// budget.commit {budgetId: "budget:merchandise|press|fans", amount: Money}
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 Werbung.");
const ui::AdvertisingState a = ui::advertising_from_game(g_, manager, revision);
ui::AdvertisingRequest r;
r.request_id = last_advertising_request_id_ + 1;
r.manager_slot = manager, r.runtime_club = team, r.revision = revision;
if (kind == "advertising.accept") {
const std::string id = ui_text(*payload, "offerId");
int display = -1, raw = -1;
if (std::sscanf(id.c_str(), "offer:ad-%d-%d", &display, &raw) != 2 || display < 0 || display >= 16)
return refuse("unknown_offer", "Unbekanntes Werbeangebot: " + id);
const auto& list = a.offers[size_t(display)];
const auto offer = std::find_if(list.offers.begin(), list.offers.end(), [&](const auto& o) { return o.present && o.raw_slot == raw; });
if (offer == list.offers.end() || !offer->can_accept) return refuse("unknown_offer", "Dieses Werbeangebot gibt es nicht (mehr).");
r.kind = ui::AdvertisingActionKind::accept_offer;
r.offer.manager = manager, r.offer.display_slot = display, r.offer.contract_slot = list.contract_slot;
r.offer.expected_contract = list.contract_bytes, r.offer.raw_slot = raw, r.offer.expected_offer = offer->bytes;
} else {
const std::string id = ui_text(*payload, "budgetId");
const int index = id == "budget:merchandise" ? 0 : id == "budget:press" ? 1 : id == "budget:fans" ? 2 : -1;
if (index < 0) return refuse("unknown_budget", "Unbekanntes Budget: " + id);
const cli::Json* amount = ui_field(*payload, "amount");
int64_t cents = -1;
try { cents = amount ? std::stoll(ui_text(*amount, "minor")) : -1; } catch (const std::exception&) { cents = -1; }
if (cents < 0 || cents % 100 || cents / 100 > UINT32_MAX) return refuse("invalid_amount", "amount in ganzen Euro (Money).");
const auto& view = a.spending[size_t(index)];
r.kind = ui::AdvertisingActionKind::set_spending;
r.spending.manager = manager, r.spending.target_slot = view.target_slot, r.spending.amount = uint32_t(cents / 100);
r.spending.expected_amount = view.current_amount, r.spending.expected_delivery_weeks = view.delivery_weeks;
}
if (!dispatch_advertising(r, revision, error)) { restore(); return refuse("advertising_refused", error); }
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 == "bank.commit") {
// payload {action: deposit|withdraw, amount: Money} or {action: buy|sell, assetId: stock:<n>|fund:<n>, count}
const std::string action = ui_text(*payload, "action");
+26
View File
@@ -260,6 +260,32 @@ int main(int argc, char** argv) {
"code")) == "stale_quote" && rev == before + 2, "a used quote is gone");
}
}
// advertising: the first acceptable offer, a budget
{
const J ads = session.ui_read(O{{"kind", "advertising"}}, rev);
check(s(at(ads, "messageType")) == "snapshot" && at(at(ads, "data"), "boards").array() &&
at(at(ads, "data"), "boards").array()->size() == 14, "advertising read");
std::string offer;
const auto pick = [&](const J& place) {
if (const auto* list = at(place, "offers").array())
for (const auto& o : *list)
if (offer.empty() && truth(at(o, "allowed"))) offer = s(at(o, "id"));
};
pick(at(at(ads, "data"), "shirt"));
pick(at(at(ads, "data"), "television"));
if (const auto* boards = at(at(ads, "data"), "boards").array())
for (const auto& b : *boards) pick(b);
const uint64_t before = rev;
if (!offer.empty()) {
const J done = session.ui_command(cmd("request:w1", "advertising.accept", O{{"offerId", offer}}), rev);
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "advertising: %s\n", cli::dump_json(done).c_str());
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "advertising offer accepted");
}
const auto kept = modern::save_stream(session.state());
check(s(at(session.ui_command(cmd("request:w2", "advertising.accept", O{{"offerId", "offer:ad-3-99"}}), rev), "code")) ==
"unknown_offer" && modern::save_stream(session.state()) == kept, "unknown offer refused");
std::printf("(advertising offer %s)\n", offer.empty() ? "none" : offer.c_str());
}
// 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"));