Preserve human manager identity through national coach record swaps (by Codex)

This commit is contained in:
Codex committed 2026-10-29 01:56:31 +01:00
1 parent ce1535fe2d
commit 693744a961
16 files changed
+203 -21

No files matched your search

+24 -15
View File
@@ -109,27 +109,36 @@ J team_ref(const ModernState& g, int team, const std::string& as_of) {
{"crestAssetId", text_or_null(club ? &club->crest : nullptr)}, {"nameAsOf", as_of}};
}
std::string manager_id(const ModernState& g, int manager) {
const std::string& id = entry(g.manager_ids, size_t(manager));
return id.empty() ? "manager:slot-" + std::to_string(manager) : id;
std::string human_manager_id(const ModernState& g, int human) {
const std::string& id = entry(g.manager_ids, size_t(human));
return id.empty() ? "manager:slot-" + std::to_string(human) : id;
}
std::string manager_id(const ModernState& g, int runtime) {
return human_manager_id(g, g.human_manager_slot(runtime));
}
int human_team(const ModernState& g, int human) {
const int record = g.manager_record_slot(human);
if (record >= 0 && size_t(record) < g.manager_teams.size()) return g.manager_teams[size_t(record)];
const size_t at = size_t(record) * kRecord + 0x290;
return record >= 0 && at + 1 < g.manager_records.size() ? int(uint16_t(g.manager_records[at]) | uint16_t(g.manager_records[at + 1]) << 8) : -1;
}
// 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);
J manager_json(const ModernState& g, int human) {
const int manager = g.manager_record_slot(human);
const int team = human_team(g, human);
const size_t at = size_t(manager) * kRecord;
const int portrait = at + 0x221 < g.manager_records.size() ? g.manager_records[at + 0x221] : 0;
const auto* presentation = g.manager_presentation(manager);
const auto* presentation = g.manager_presentation_for_human(human);
const std::string style = presentation ? presentation->portrait_style : "photo";
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)},
return O{{"id", human_manager_id(g, human)}, {"slot", human}, {"runtimeSlot", manager}, {"name", manager_name(g, manager)},
{"control", ended ? "archived" : "human"}, {"status", status},
{"teamId", team >= 0 ? J(team_id(g, team)) : J(nullptr)},
{"portraitGuiKey", "gui:manager/" + style + "/" + std::to_string(portrait)}, {"portraitStyle", style},
{"strengthChoice", nullptr}, {"employments", manager_employments(g, manager, manager_id(g, manager))}};
{"strengthChoice", nullptr}, {"employments", manager_employments(g, human, human_manager_id(g, human))}};
}
// The commands the desk accepts now (the session refuses the others): none after the career's
@@ -192,15 +201,15 @@ J session_data(const ModernState& g, const UiContext& c) {
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);
const int team = human_team(g, m);
(team == no_team() ? national : club) = true;
if (ended) {
archived_ids.push_back(manager_id(g, m));
archived_ids.push_back(human_manager_id(g, m));
continue;
}
managers.push_back(manager_json(g, m, m == c.manager));
managers.push_back(manager_json(g, m));
if (team >= 0)
ownership.push_back(O{{"teamId", team_id(g, team)}, {"controller", "human"}, {"managerId", manager_id(g, m)},
ownership.push_back(O{{"teamId", team_id(g, team)}, {"controller", "human"}, {"managerId", human_manager_id(g, m)},
{"sinceRevision", "0"}});
}
const std::string reason = !g.career_end_reason.empty() ? g.career_end_reason : ended ? "career_completed" : "";
@@ -216,7 +225,7 @@ J session_data(const ModernState& g, const UiContext& c) {
J desktop_data(const ModernState& g, const UiContext& c, const std::string& today) {
const int team = team_of(g, c.manager);
const bool national = team == no_team();
O data{{"kind", "desktop"}, {"manager", manager_json(g, c.manager, true)}, {"team", team_ref(g, team, today)}};
O data{{"kind", "desktop"}, {"manager", manager_json(g, g.human_manager_slot(c.manager))}, {"team", team_ref(g, team, today)}};
// the account: the bank's savings and credit follow with the bank read
data["accounts"] = O{{"cash", ui_money(money_of(g, c.manager))}, {"savings", nullptr}, {"debt", nullptr},
{"netAssets", nullptr}};
@@ -465,7 +474,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); }
cli::Json ui_manager(const ModernState& g, int manager) { return manager_json(g, g.human_manager_slot(manager)); }
std::string ui_player_id(const ModernState& g, int player) {
std::string id = entry(g.world_player_id, size_t(player));
+1 -1
View File
@@ -63,7 +63,7 @@ AlmanacClub club_of(const ModernState& g, int team) {
AlmanacManager manager_of(const ModernState& g, int manager) {
AlmanacManager m;
m.index = manager;
m.index = g.human_manager_slot(manager);
if (const auto* p = g.manager_presentation(manager)) { m.name = p->name; return m; }
const size_t at = size_t(manager) * kManagerRecord + 0xa8; // the manager's name (30 bytes)
for (size_t i = 0; i < 30 && at + i < g.manager_records.size() && g.manager_records[at + i]; ++i)
+8 -1
View File
@@ -89,11 +89,18 @@ struct ModernState : GameState {
bool operator==(const ManagerPresentation&) const = default;
};
std::vector<ManagerPresentation> manager_presentations;
const ManagerPresentation* manager_presentation(int slot) const {
// Runtime slot zero temporarily contains the national coach. These read-only
// mappings recover the human identity and its original/backup record.
int human_manager_slot(int runtime_slot) const;
int manager_record_slot(int human_slot) const;
const ManagerPresentation* manager_presentation_for_human(int slot) const {
if (slot < 0 || size_t(slot) >= manager_ids.size()) return nullptr;
for (const auto& p : manager_presentations) if (p.id == manager_ids[size_t(slot)]) return &p;
return nullptr;
}
const ManagerPresentation* manager_presentation(int runtime_slot) const {
return manager_presentation_for_human(human_manager_slot(runtime_slot));
}
// The press journal (content/press_journal.hpp): business events the almanac cannot give
// (transfers, contracts, toto, seasons, managers), noted once when they happen and saved, so
// the interface's news keep their ids. `data` is the event's facts as JSON text.
+22
View File
@@ -221,6 +221,28 @@ void set_manager_count(ModernState& g, int managers) {
} // namespace
int ModernState::human_manager_slot(int runtime_slot) const {
if (runtime_slot < 0 || !memory.has(::bmh::layout::CoachActive) || memory.u8(::bmh::layout::CoachActive) == 0) return runtime_slot;
if (runtime_slot == 4) return 0;
if (runtime_slot != 0) return runtime_slot;
const int count = memory.u8(::bmh::layout::OriginalManagerCount);
if (count == 1 || memory.u32(::bmh::layout::CompetitionSelection) == 2) return 0;
// The source chose the first eligible original record. While coaching,
// record four preserves original human zero; the other records are frozen.
// Read those flags, rather than guessing from a possibly duplicated name.
for (int human = 0; human < count && human < 4; ++human) {
const size_t record = size_t(human == 0 ? 4 : human) * kManagerRecord;
if (record + 0x21c < manager_records.size() && manager_records[record + 0x21c] != 0) return human;
}
throw FormatError("national coach identity is unavailable");
}
int ModernState::manager_record_slot(int human_slot) const {
if (!memory.has(::bmh::layout::CoachActive) || memory.u8(::bmh::layout::CoachActive) == 0) return human_slot;
const int coach = human_manager_slot(0);
if (human_slot == coach) return 0;
return human_slot == 0 ? 4 : human_slot;
}
void national_coach_take_over(ModernState& g, int active_manager, uint16_t source_season_day) {
StaticMemory& mem = g.memory;
int managers = int(g.manager_teams.size());
+2 -1
View File
@@ -83,7 +83,8 @@ Json EngineBridge::save_copy(const fs::path &path) {
if (fs::weakly_canonical(path) == impl_->input || fs::exists(path))
throw editor::Error("Bitte eine neue Datei wählen. Der geladene Spielstand wird nicht überschrieben.");
const auto bundle = snapshot();
const auto slot = bundle.at("desktop").at("data").at("manager").at("slot").get<int>();
const auto &manager = bundle.at("desktop").at("data").at("manager");
const auto slot = manager.value("runtimeSlot", manager.at("slot").get<int>());
std::string error;
if (!impl_->session->save_game(path, slot, false, error)) throw editor::Error(error);
return {{"messageType", "saved"}, {"path", editor::utf8(path)}};