Modern UI contract: running-out contracts during session.advance

The original asks for a running-out contract in the middle of the calendar.
session.advance takes the answers in contractExpiry (renew with years and
salary, or release); a contract without an answer rolls the run back and
decision_pending names the player, the interface asks and sends the advance
again. The test plays two seasons of kickoffs answering every request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:15:04 +01:00
1 parent 2ca6b21a94
commit f71f072774
3 files changed
+74 -1

No files matched your search

+1 -1
View File
@@ -55,7 +55,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| Command | payload | Wirkung |
|---|---|---|
| `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` |
| `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 |
| `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. |
+52
View File
@@ -9141,13 +9141,65 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
} else if (kind == "session.advance") {
// payload {}: the kickoff of the desk - the calendar runs (matches without live view) to the
// next desk of a human manager, the season end desk or the end of the career
// contractExpiry {playerId: {action: "renew", years 1-4, monthlySalary: Money} | {action: "release"}}:
// the answers to contracts running out on the way (the original asks at that moment). A
// contract without an answer stops the run: it is rolled back and decision_pending names
// the player, the interface asks and sends the advance again with the answer.
struct Expiry { bool renew = false; int term = 0; uint32_t salary = 0; };
std::map<std::string, Expiry> answers;
if (const cli::Json* e = ui_field(*payload, "contractExpiry"); e && e->object())
for (const auto& [id, value] : *e->object()) {
Expiry x;
const std::string action = ui_text(value, "action");
if (action == "renew") {
const cli::Json* years = ui_field(value, "years");
const cli::Json* salary = ui_field(value, "monthlySalary");
int64_t cents = -1;
try { cents = salary ? std::stoll(ui_text(*salary, "minor")) : -1; } catch (const std::exception&) { cents = -1; }
if (!years || !years->integer() || *years->integer() < 1 || *years->integer() > 4 || cents < 0 || cents % 100)
return refuse("invalid_payload", "contractExpiry: renew braucht years 1-4 und monthlySalary.");
x.renew = true, x.term = int(*years->integer() - 1), x.salary = uint32_t(cents / 100);
} else if (action != "release") {
return refuse("invalid_payload", "contractExpiry: action ist renew oder release.");
}
answers[id] = x;
}
std::string pending_player;
auto previous_hook = g_.contract_screen;
const bool previous_installed = contract_expiry_presenter_installed_;
set_contract_expiry_presenter([&](modern::ModernState& state, WatcomRandom& random, int m, int row) -> int {
const int team = m >= 0 && size_t(m) < state.manager_teams.size() ? state.manager_teams[size_t(m)] : -1;
const SquadRange range = squad_range(team);
const int p = size_t(row) < range.count ? state.squad_slots[range.first + size_t(row)] & 0x0fff : 0x0fff;
const std::string id = p == 0x0fff ? std::string{} : modern::ui_player_id(state, p);
const auto it = answers.find(id);
if (it == answers.end()) { pending_player = id; return -2; } // ask the interface
if (!it->second.renew) return 0; // released
try {
const auto demands = modern::contract_demands(state, m, row, false, random);
const uint32_t demand = demands[size_t(it->second.term)];
if (demand == 0 || demand == UINT32_MAX) return 0;
return modern::contract_offer(state, m, row, it->second.term, it->second.salary, demand, false, true, random, nullptr) ? 1 : 0;
} catch (const std::exception&) {
return -2;
}
});
ui::DeskRequest kickoff;
kickoff.kind = ui::DeskRequestKind::advance_turn;
kickoff.manager_slot = manager;
kickoff.revision = revision;
const TurnAdvanceResult r = dispatch_kickoff(kickoff, revision, error);
g_.contract_screen = previous_hook; // the session's own presenter again
contract_expiry_presenter_installed_ = previous_installed;
if (r.kind == TurnDeskKind::Failed || r.kind == TurnDeskKind::WaitingAtDesk) {
restore();
g_.contract_screen = previous_hook;
if (!pending_player.empty()) {
cli::Json pending = refuse("decision_pending", "Ein Vertrag läuft aus: Verlängern oder freigeben?");
auto& message = std::get<cli::Json::Object>(std::get<cli::Json::Object>(pending.value)["message"].value);
message["args"] = cli::Json::Object{{"decision", "contract_expiry"}, {"playerId", pending_player}};
return pending;
}
const std::string reason = r.reason.empty() ? error : r.reason;
return refuse(r.kind == TurnDeskKind::WaitingAtDesk ? "decision_pending" : "advance_failed",
"Weiter nicht möglich: " + reason);
+21
View File
@@ -273,6 +273,27 @@ int main(int argc, char** argv) {
const std::string date_after = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));
check(date_after > date_before, "the date moved on");
}
// a season of kickoffs: running-out contracts stop the run with decision_pending and the
// player; the advance is sent again with the answer (here: release)
{
O expiry;
int decisions = 0, advances = 0;
for (int k = 0; k < 200 && advances < 120; ++k) {
const uint64_t before = rev;
const J done = session.ui_command(cmd("request:s" + std::to_string(k), "session.advance", O{{"contractExpiry", expiry}}), rev);
if (s(at(done, "messageType")) == "command_result") { ++advances; continue; }
const std::string code = s(at(done, "code"));
const std::string player = s(at(at(at(done, "message"), "args"), "playerId"));
check(code == "decision_pending" && !player.empty() && rev == before, "a pending contract names the player, nothing changed");
if (code != "decision_pending" || player.empty() || expiry.count(player)) break;
expiry[player] = O{{"action", "release"}};
++decisions;
}
check(advances == 120, "two seasons of kickoffs with answered contract decisions");
check(decisions > 0, "running-out contracts were asked for");
std::printf("(date now %s)\n", s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date")).c_str());
std::printf("(%d contract decisions answered)\n", decisions);
}
// almanac view after the kickoffs: index, calendar, day, match
{
const J index = session.read_almanac(O{{"kind", "index"}});