Modern UI contract: the end of the game
Resigning as the only or last human ends the game as the end of the set duration does: the highscore hook updates and shows the table. The end's reason and date are saved; the session read follows the contract's Session schema (archived managers, termination reason, ownership, mode), managers become archived (resigned or retired) and their employments end with the career. The resign answer carries the ownership change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6570384642
commit
d6d31f939d
10 files changed
+99
-20
No files matched your search
@@ -24,7 +24,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
|
||||
| Read | Inhalt |
|
||||
|---|---|
|
||||
| `session` | `sessionState`, `activeManagerId`, alle menschlichen Manager (ID, Platz, Name, Team, Porträt, `active`/`waiting`) |
|
||||
| `session` | nach dem Schema `Session`: `sessionState` (`desktop`, nach dem Ende `ended`), `activeManagerId` (nach dem Ende `null`), `managers` (ID, Platz, Name, Team, Porträt, `control` human, `status` active, `employments`), `humanOwnership` (Team, Manager), `archivedManagerIds`/`archivedManagerCount`, `terminationReason` (`career_completed` wenn die festgelegte Dauer abläuft, `last_human_resigned` beim Aufgeben; `null` solange es läuft), `mode` (club/national/mixed), `canAdvance`, `blockingReason` (`session_ended`). Grund und Datum des Endes stehen im Spielstand |
|
||||
| `desktop` | Manager, Team (`TeamRef`), Kontostand (`accounts.cash`; Festgeld und Kredit im Read `bank` bzw. `credit`), nächstes Spiel, `menuAvailability` |
|
||||
| `squad` | ein Kader (`teamId`, sonst der eigene Verein; auch Nationalteams mit Kader): Spieler-ID, Name, Nation, Position, Rolle (`starter`/`bench`/`reserve`), Verfügbarkeit, Verletzung und Sperre in Wochen, Alter, Werte (Stärke, Kondition, Technik, Form), Fähigkeiten; für den eigenen Verein Monatsgehalt und Restlaufzeit in Monaten (fremde Vereine: `null`) |
|
||||
| `camps` | Karten und Lager (Qualität 0–6, Ort, Nation, Exklusiv-Sponsor-Chance), je Lager ein bindendes Angebot für den eigenen Kader (Grundpreis + Kaderzuschlag, ohne Zufall; `allowed`, `reasonCode` `booked_this_week`/`visit_limit`/`no_club`, `exceedsCash`), Schwerpunkte, Aufenthalte der Saison, Buchung dieser Woche |
|
||||
@@ -87,7 +87,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
|
||||
| `friendly.book` | `opponentId`, optional `home`, `date`, `acceptCost`, bei menschlichem Gegner `opponentConsent` | am Schreibtisch des Bundestrainers das Länderspiel (Rückmeldung mit Bonus, wenn das Original ihn gewährt); vereinbart das Freundschaftsspiel; Fehler `declined` (Kosten nicht bestätigt), `opponent_declined`, `insufficient_funds`, `date_unavailable`, `plan_full` u. a. |
|
||||
| `fixture.reschedule` | `matchId`, `date`; oder `action: undo`, `date` | verlegt eine eigene Ligapartie bzw. nimmt die Verlegung zurück; Fehler `invalid_day`, `day_full`, `team_clash`, `no_free_slot`, `no_moved_match` |
|
||||
| `environment.commit` | `itemId`, `level` 0–6 | setzt ein Monatsbudget des Umfelds (keine Sofortbuchung, kein Zufall); unverändert: `outcome: no_change`; Fehler `environment_refused` |
|
||||
| `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen): Der letzte menschliche Manager beendet die Karriere (`outcome: career_ended`, `session`-Read `sessionState: "ended"`, danach antwortet jeder Befehl `career_ended`). Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` |
|
||||
| `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen). Spielt nur ein Mensch (oder ist er der letzte), endet das Spiel wie mit dem Ablauf der festgelegten Dauer: die Highscore-Tabelle wird fortgeschrieben und angezeigt (der Hook der Saisonwende, erst Aktualisierung, dann Anzeige), `outcome: career_ended`, `ownershipChange` mit `archivedIdentity` (Manager `control: archived`, `status: resigned`, Amtszeiten mit `until` und `endReason: resigned`), `terminationReason: last_human_resigned`; danach antwortet jeder Befehl `career_ended`. Beim Ablauf der Dauer sind die Manager `retired`, die Amtszeiten enden mit `career_end`. Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` |
|
||||
| `toto.submit` | `stake` (`Money` je Spalte), `columns` (bis 6 Spalten mit 11 Tipps: 1 Heim, 0 Unentschieden, 2 Auswärts) | gibt den Tippschein ab; Fehler `toto_refused` (z. B. kein offener Schein, Einsatzgrenzen, doppelte Spalte) |
|
||||
| `sponsor.answer` | `accept` | Antwort auf das Exklusiv-Sponsor-Angebot: beginnt sofort, wird vorgemerkt oder abgelehnt |
|
||||
| `quote.request` (Stadion) | `kind: periphery`, `objectId`; oder `kind: facility`, `facilityId`, `increment` 1–3; oder `kind: block`, `blockId` (`block:a`–`block:h`), `places` (Ziel insgesamt), optional `seats`, `roof` | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen bzw. stellt den Tribünenausbau zusammen (Plätze, Sitzplätze, Dach; vorhandene Ausstattung bleibt; Angebot mit Aufschlüsselung Plätze/Sitze/Dach); `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) |
|
||||
|
||||
@@ -9353,6 +9353,7 @@ cli::Json ModernSession::finish_live(const std::string& request_id, uint64_t pre
|
||||
{"session", "desktop", "squad", "lineup", "tactics", "training", "camps", "bank", "statistics", "almanac", "live", "postmatch"},
|
||||
result.kind == TurnDeskKind::SeasonEndDesk ? "Saisonende." : result.kind == TurnDeskKind::CareerComplete
|
||||
? "Die Karriere ist zu Ende." : "Abpfiff. Weiter zum nächsten Termin.");
|
||||
if (result.kind == TurnDeskKind::CareerComplete) g_.career_end_reason = "career_completed", g_.career_end_date = g_.date;
|
||||
if (result.kind == TurnDeskKind::CareerComplete) std::get<cli::Json::Object>(answer.value)["outcome"] = "career_ended";
|
||||
return answer;
|
||||
}
|
||||
@@ -9858,6 +9859,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
answer = modern::ui_command_result(request_id, previous, revision,
|
||||
{"session", "desktop", "squad", "lineup", "tactics", "training", "camps", "bank",
|
||||
"statistics", "almanac"}, what);
|
||||
if (r.kind == TurnDeskKind::CareerComplete) g_.career_end_reason = "career_completed", g_.career_end_date = g_.date;
|
||||
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" ||
|
||||
@@ -10362,11 +10364,26 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
if (const int club = g_.manager_teams[size_t(manager)]; club >= 0)
|
||||
modern::note_press(g_, "career.manager_resigned", modern::ui_team_id(g_, club),
|
||||
cli::Json::Object{{"team", modern::press_team(g_, club)}, {"manager", modern::ui_manager_id(g_, manager)}});
|
||||
// the end is that of the set duration: the highscore table is brought up to date and shown
|
||||
// (season_end_steps: update, then the final display), the session ends
|
||||
if (turn_driver_.season_highscore) {
|
||||
turn_driver_.season_highscore(g_, false);
|
||||
turn_driver_.season_highscore(g_, true);
|
||||
}
|
||||
turn_driver_.stage = TurnDriver::Stage::CareerComplete;
|
||||
g_.career_end_reason = "last_human_resigned", g_.career_end_date = g_.date;
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"session", "desktop"},
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"session", "manager_menu", "desktop"},
|
||||
"Sie haben aufgegeben. Die Karriere ist beendet.");
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "career_ended";
|
||||
auto& o = std::get<cli::Json::Object>(answer.value);
|
||||
o["outcome"] = "career_ended";
|
||||
const int club = g_.manager_teams[size_t(manager)];
|
||||
o["ownershipChange"] = cli::Json::Object{
|
||||
{"kind", "ownership_change"}, {"managerId", modern::ui_manager_id(g_, manager)},
|
||||
{"archivedIdentity", modern::ui_manager(g_, manager)},
|
||||
{"teamId", club >= 0 ? cli::Json(modern::ui_team_id(g_, club)) : cli::Json(nullptr)}, {"aiHandover", false},
|
||||
{"activeManagerId", nullptr}, {"humanOwnership", cli::Json::Array{}}, {"sessionState", "ended"},
|
||||
{"terminationReason", "last_human_resigned"}};
|
||||
} else if (kind == "toto.submit") {
|
||||
// payload {stake: Money per column, columns: [[11 tips: 1 home, 0 draw, 2 away], ... up to 6]}
|
||||
const cli::Json* stake = ui_field(*payload, "stake");
|
||||
|
||||
@@ -914,7 +914,7 @@ public:
|
||||
GameRandom& game() { return game_; }
|
||||
WatcomRandom& rand() { return rand_; }
|
||||
uint64_t session_id() const { return session_id_; }
|
||||
bool career_complete() const { return turn_driver_.stage == TurnDriver::Stage::CareerComplete; }
|
||||
bool career_complete() const { return turn_driver_.stage == TurnDriver::Stage::CareerComplete || !g_.career_end_reason.empty(); }
|
||||
|
||||
// Portable host driver capabilities replace SOUND.CFG runtime latches; they
|
||||
// are never inferred from a saved switch or written into an FBM on entry.
|
||||
|
||||
@@ -1104,7 +1104,7 @@ cli::Json query_news(const ModernState& g, const std::string& team, const std::s
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
cli::Json manager_employments(const ModernState& g, int manager) {
|
||||
cli::Json manager_employments(const ModernState& g, int manager, const std::string& manager_id) {
|
||||
// the teams a human manager led, from the recorded matches: a new employment begins when
|
||||
// the team of his matches changes (a club and the national team run side by side)
|
||||
struct Stint { std::string team, name, kind; uint32_t from = 0, until = 0; int display_year = 0; };
|
||||
@@ -1127,14 +1127,22 @@ cli::Json manager_employments(const ModernState& g, int manager) {
|
||||
if (open && same(*open)) { open->until = m.date, open->team = c.id; continue; } // the id as last seen
|
||||
stints.push_back({c.id, c.name, kind, m.date, m.date, s.display_start_year});
|
||||
}
|
||||
// the last stint of each kind runs until the career's end (resigned, or the set duration
|
||||
// ran out); an earlier one ended with its last match (the reason is not recorded: null)
|
||||
const bool ended = !g.career_end_reason.empty();
|
||||
const char* end_reason = g.career_end_reason == "last_human_resigned" ? "resigned" : "career_end";
|
||||
const std::string end_date = ended ? iso_date(g.career_end_date, g.display_start_year) : std::string{};
|
||||
A out;
|
||||
for (size_t i = 0; i < stints.size(); ++i) {
|
||||
const Stint& st = stints[i];
|
||||
bool current = true; // the last stint of its kind is still running
|
||||
bool current = true; // the last stint of its kind
|
||||
for (size_t k = i + 1; k < stints.size(); ++k) current &= stints[k].kind != st.kind;
|
||||
out.push_back(O{{"teamId", st.team}, {"teamName", st.name}, {"role", st.kind},
|
||||
out.push_back(O{{"id", "employment:" + manager_id.substr(manager_id.find(':') + 1) + "-" + std::to_string(i + 1)},
|
||||
{"managerId", manager_id}, {"teamId", st.team},
|
||||
{"role", st.kind == "national" ? "national_coach" : "club_manager"},
|
||||
{"from", iso_date(st.from, st.display_year)},
|
||||
{"until", current ? J(nullptr) : J(iso_date(st.until, st.display_year))}});
|
||||
{"until", current ? (ended ? J(end_date) : J(nullptr)) : J(iso_date(st.until, st.display_year))},
|
||||
{"endReason", current && ended ? J(end_reason) : J(nullptr)}});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -53,9 +53,10 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
|
||||
// {for, against} from the team's side, venue, trailed, minute of the deciding goal).
|
||||
cli::Json query_news(const ModernState& g, const std::string& team, const std::string& from, const std::string& until);
|
||||
|
||||
// The teams a human manager (slot) led, from the almanac: [{teamId, teamName, role club or
|
||||
// national, from, until (null while running)}] in order. Before the first recorded match: empty.
|
||||
cli::Json manager_employments(const ModernState& g, int manager);
|
||||
// The teams a human manager (slot, contract id) led, from the almanac: Employment of the contract
|
||||
// [{id, managerId, teamId, role club_manager or national_coach, from, until (null while running),
|
||||
// endReason}] in order. Before the first recorded match: empty.
|
||||
cli::Json manager_employments(const ModernState& g, int manager, const std::string& manager_id);
|
||||
|
||||
// A game of a matchday under way: runtime teams and goals so far.
|
||||
struct LiveGame { int home = 0, away = 0, home_goals = 0, away_goals = 0; };
|
||||
|
||||
@@ -112,15 +112,20 @@ std::string manager_id(const ModernState& g, int manager) {
|
||||
return id.empty() ? "manager:slot-" + std::to_string(manager) : id;
|
||||
}
|
||||
|
||||
// A human manager (Manager of the contract). After the career's end he is archived: resigned
|
||||
// when he gave up, retired when the set duration ran out.
|
||||
J manager_json(const ModernState& g, int manager, bool at_desk) {
|
||||
(void)at_desk; // who is at the desk is the session's activeManagerId
|
||||
const int team = team_of(g, manager);
|
||||
const size_t at = size_t(manager) * kRecord;
|
||||
const int portrait = at + 0x221 < g.manager_records.size() ? g.manager_records[at + 0x221] : 0;
|
||||
const bool ended = !g.career_end_reason.empty();
|
||||
const char* status = !ended ? "active" : g.career_end_reason == "last_human_resigned" ? "resigned" : "retired";
|
||||
return O{{"id", manager_id(g, manager)}, {"slot", manager}, {"name", manager_name(g, manager)},
|
||||
{"control", "human"}, {"status", at_desk ? "active" : "waiting"},
|
||||
{"control", ended ? "archived" : "human"}, {"status", status},
|
||||
{"teamId", team >= 0 ? J(team_id(g, team)) : J(nullptr)},
|
||||
{"portraitGuiKey", "gui:manager/photo/" + std::to_string(portrait)}, {"portraitStyle", "photo"},
|
||||
{"strengthChoice", nullptr}, {"employments", manager_employments(g, manager)}};
|
||||
{"strengthChoice", nullptr}, {"employments", manager_employments(g, manager, manager_id(g, manager))}};
|
||||
}
|
||||
|
||||
// The commands the desk accepts now (the session refuses the others): none after the career's
|
||||
@@ -176,11 +181,32 @@ J failure(const std::string& request_id, const char* code, const std::string& me
|
||||
{"currentRevision", std::to_string(revision)}, {"retryable", false}, {"stateChanged", false}};
|
||||
}
|
||||
|
||||
// The session (Session of the contract): the human managers and their teams while it runs; after
|
||||
// its end no active manager, the managers archived (their ids) and why it ended.
|
||||
J session_data(const ModernState& g, const UiContext& c) {
|
||||
A managers;
|
||||
for (int m = 0; m < human_managers(g); ++m) managers.push_back(manager_json(g, m, m == c.manager));
|
||||
return O{{"kind", "session"}, {"sessionState", c.career_ended ? "ended" : "desktop"}, {"activeManagerId", manager_id(g, c.manager)},
|
||||
{"managers", std::move(managers)}};
|
||||
A managers, ownership, archived_ids;
|
||||
const bool ended = c.career_ended || !g.career_end_reason.empty();
|
||||
bool national = false, club = false;
|
||||
for (int m = 0; m < human_managers(g); ++m) {
|
||||
const int team = team_of(g, m);
|
||||
(team == no_team() ? national : club) = true;
|
||||
if (ended) {
|
||||
archived_ids.push_back(manager_id(g, m));
|
||||
continue;
|
||||
}
|
||||
managers.push_back(manager_json(g, m, m == c.manager));
|
||||
if (team >= 0)
|
||||
ownership.push_back(O{{"teamId", team_id(g, team)}, {"controller", "human"}, {"managerId", manager_id(g, m)},
|
||||
{"sinceRevision", "0"}});
|
||||
}
|
||||
const std::string reason = !g.career_end_reason.empty() ? g.career_end_reason : ended ? "career_completed" : "";
|
||||
return O{{"kind", "session"}, {"sessionState", ended ? "ended" : "desktop"},
|
||||
{"activeManagerId", ended ? J(nullptr) : J(manager_id(g, c.manager))},
|
||||
{"managers", std::move(managers)}, {"humanOwnership", std::move(ownership)},
|
||||
{"archivedManagerIds", std::move(archived_ids)}, {"archivedManagerCount", int64_t(ended ? human_managers(g) : 0)},
|
||||
{"terminationReason", reason.empty() ? J(nullptr) : J(reason)},
|
||||
{"mode", national && club ? "mixed" : national ? "national" : "club"},
|
||||
{"canAdvance", !ended}, {"blockingReason", ended ? J("session_ended") : J(nullptr)}};
|
||||
}
|
||||
|
||||
J desktop_data(const ModernState& g, const UiContext& c, const std::string& today) {
|
||||
@@ -380,6 +406,7 @@ cli::Json ui_snapshot(const ModernState& g, const UiContext& c, const std::strin
|
||||
}
|
||||
|
||||
std::string ui_team_id(const ModernState& g, int team) { return team_id(g, team); }
|
||||
cli::Json ui_manager(const ModernState& g, int manager) { return manager_json(g, manager, false); }
|
||||
|
||||
std::string ui_player_id(const ModernState& g, int player) {
|
||||
std::string id = entry(g.world_player_id, size_t(player));
|
||||
|
||||
@@ -59,5 +59,7 @@ std::string ui_manager_id(const ModernState& g, int manager);
|
||||
cli::Json ui_snapshot(const ModernState& g, const UiContext& context, const std::string& request_id, cli::Json data);
|
||||
std::string ui_team_id(const ModernState& g, int team);
|
||||
std::string ui_player_id(const ModernState& g, int player);
|
||||
// A human manager as the contract's Manager (archived after the career's end).
|
||||
cli::Json ui_manager(const ModernState& g, int manager);
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -155,7 +155,9 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
|
||||
{"manager_serial", int64_t(state.manager_serial)},
|
||||
{"traffic_scale", int64_t(state.traffic_scale)},
|
||||
{"press", press_json(state.press)},
|
||||
{"press_serial", int64_t(state.press_serial)}});
|
||||
{"press_serial", int64_t(state.press_serial)},
|
||||
{"career_end_reason", state.career_end_reason},
|
||||
{"career_end_date", int64_t(state.career_end_date)}});
|
||||
// The almanac: finished seasons unchanged, the running one encoded now.
|
||||
for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes;
|
||||
if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current);
|
||||
@@ -215,6 +217,10 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
|
||||
out.state.press = press_json(get(modern, "press"));
|
||||
out.state.press_serial = uint32_t(num(get(modern, "press_serial")));
|
||||
}
|
||||
if (o->count("career_end_reason")) {
|
||||
out.state.career_end_reason = str(get(modern, "career_end_reason"));
|
||||
out.state.career_end_date = uint32_t(num(get(modern, "career_end_date")));
|
||||
}
|
||||
}
|
||||
for (const auto& [name, bytes] : docs) {
|
||||
if (!name.starts_with("history/season-")) continue;
|
||||
|
||||
@@ -93,6 +93,11 @@ struct ModernState : GameState {
|
||||
};
|
||||
std::vector<PressEntry> press;
|
||||
uint32_t press_serial = 0;
|
||||
// How and when the career ended ("" while it runs; "career_completed" when the set duration ran
|
||||
// out, "last_human_resigned" when the only or last human manager gave up): the interface's
|
||||
// terminationReason and the end of the employments.
|
||||
std::string career_end_reason;
|
||||
uint32_t career_end_date = 0;
|
||||
// The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the
|
||||
// four stages of a Modern world. Older Modern saves are converted when loaded.
|
||||
uint8_t traffic_scale = 0;
|
||||
|
||||
@@ -827,7 +827,20 @@ int main(int argc, char** argv) {
|
||||
check(s(at(resign("request:r1", O{}), "code")) == "confirmation_required", "resigning needs the confirmation");
|
||||
const J done = resign("request:r2", O{{"confirmed", true}});
|
||||
check(s(at(done, "outcome")) == "career_ended", "the last human manager ends the career");
|
||||
check(s(at(at(session.ui_read(O{{"kind", "session"}}, rev), "data"), "sessionState")) == "ended", "session ended");
|
||||
const J ended = at(session.ui_read(O{{"kind", "session"}}, rev), "data");
|
||||
check(s(at(ended, "sessionState")) == "ended", "session ended");
|
||||
check(s(at(ended, "terminationReason")) == "last_human_resigned" && !truth(at(ended, "canAdvance")) &&
|
||||
std::holds_alternative<std::nullptr_t>(at(ended, "activeManagerId").value) &&
|
||||
at(ended, "archivedManagerIds").array() && at(ended, "archivedManagerIds").array()->size() == 1,
|
||||
"the ended session: reason, archived manager, no advance");
|
||||
const J& identity = at(at(done, "ownershipChange"), "archivedIdentity");
|
||||
const auto* jobs = at(identity, "employments").array();
|
||||
std::printf("(archived: %s)\n", cli::dump_json(identity).substr(0, 400).c_str());
|
||||
check(s(at(identity, "control")) == "archived" && s(at(identity, "status")) == "resigned", "the archived identity");
|
||||
bool resigned_job = false;
|
||||
if (jobs) for (const auto& j : *jobs) resigned_job |= s(at(j, "endReason")) == "resigned" && at(j, "until").string();
|
||||
check(resigned_job, "the employment ends with the resignation");
|
||||
check(!std::as_const(session).state().career_end_reason.empty(), "the end is kept in the state (saved)");
|
||||
check(s(at(resign("request:r3", O{{"confirmed", true}}), "code")) == "career_ended", "no command after the end");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
|
||||
Reference in new issue
Block a user