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
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user