Fix Almanac shoot-out recording and verified legacy views (by Codex)

This commit is contained in:
Codex committed 2026-10-28 20:42:40 +01:00
1 parent ddd4447563
commit f9e8719b2d
11 files changed
+309 -28

No files matched your search

+18 -3
View File
@@ -45,6 +45,10 @@ std::vector<AlmanacSeason> seasons_of(const ModernState& g) {
std::vector<AlmanacSeason> out;
for (const auto& [name, bytes] : g.almanac.finished) out.push_back(decode_almanac_season(bytes));
if (g.almanac.current.season >= 0) out.push_back(g.almanac.current);
// Work on query copies only: finished season bytes and the loaded career
// remain immutable, including older saves affected by double-counted kicks.
for (auto& season : out)
for (auto& match : season.matches) modern::normalize_legacy_shootout(match);
return out;
}
@@ -309,7 +313,18 @@ J almanac_match(const ModernState& g, const AlmanacSeason& s, size_t index) {
int regulation[2] = {0, 0};
for (const auto& e : m.events)
if (e.kind == AlmanacEventKind::Goal && e.minute <= 90 && e.side < 2) ++regulation[e.side];
const bool extra = m.decided >= 1, shootout = m.decided == 2;
const bool shootout = m.decided == 2;
const bool indoor = m.type == 12 || m.type == 13; // indoor cup / masters: 2 x 20, then penalties
const bool extra = m.decided >= 1 && !indoor;
int goals[2] = {};
bool ambiguous_stoppage = false;
for (const auto& e : m.events) if (e.kind == AlmanacEventKind::Goal && e.side < 2) {
++goals[e.side];
// Both regular stoppage time and the first extra-time minutes use
// 91..93. F10 has no phase tag; do not invent a 90-minute score there.
if (e.minute > 90 && e.minute <= 93) ambiguous_stoppage = true;
}
const bool split_known = goals[0] == m.home_goals && goals[1] == m.away_goals && !ambiguous_stoppage;
J lineups = O{};
for (int side = 0; side < 2; ++side) {
const auto& l = m.lineup[size_t(side)];
@@ -328,8 +343,8 @@ J almanac_match(const ModernState& g, const AlmanacSeason& s, size_t index) {
return O{{"id", match_id(s, index)}, {"date", iso_date(m.date, s.display_start_year)}, {"season", season_label(s.start_year)},
{"competition", O{{"id", c.id}, {"name", c.name}, {"type", type}}}, {"round", int(m.round)},
{"home", almanac_side(g, s, m.home, m.home_manager)}, {"away", almanac_side(g, s, m.away, m.away_manager)},
{"result", O{{"regulation", extra ? J(A{J(regulation[0]), J(regulation[1])}) : J(A{J(int(m.home_goals)), J(int(m.away_goals))})},
{"extra", extra ? J(A{J(int(m.home_goals) - regulation[0]), J(int(m.away_goals) - regulation[1])}) : J(nullptr)},
{"result", O{{"regulation", extra ? (split_known ? J(A{J(regulation[0]), J(regulation[1])}) : J(nullptr)) : J(A{J(int(m.home_goals)), J(int(m.away_goals))})},
{"extra", extra && split_known ? J(A{J(int(m.home_goals) - regulation[0]), J(int(m.away_goals) - regulation[1])}) : J(nullptr)},
{"penalties", shootout ? J(A{J(int(m.home_shootout)), J(int(m.away_shootout))}) : J(nullptr)},
{"final", A{J(int(m.home_goals)), J(int(m.away_goals))}}, {"extra_played", extra}, {"penalties_played", shootout}}},
{"referee", m.referee > 0 && m.referee < s.referees.size() ? J(s.referees[m.referee]) : J(nullptr)},