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

+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());