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