Modern UI contract: calendar read
club_calendar projects the season calendar of a club: the competitions of each day and the club's league matches on the day of their round, or on the replay day when moved or postponed. The calendar read lists a date range of it with fixtures, status and results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6e400d708c
commit
d3d526c2e4
5 files changed
+138
No files matched your search
@@ -241,4 +241,54 @@ bool undo_reschedule(ModernState& g, int manager, int day) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<ClubCalendarDay> club_calendar(const ModernState& g, int team) {
|
||||
std::vector<ClubCalendarDay> out;
|
||||
if (!memory_ok(g)) return out;
|
||||
const int league = team >= 0 && team != no_team() ? team_league(team) : kLeagueCount;
|
||||
// the club's replay entries: round, match, replay day
|
||||
struct Replay { int round, match, day; };
|
||||
std::vector<Replay> replays;
|
||||
if (league < kLeagueCount)
|
||||
for (int e = 0; e < kPostponedEntries; e++) {
|
||||
const uint32_t at = kPostponed + uint32_t(e) * 6;
|
||||
const int day = g.memory.u16(at), round = g.memory.u8(at + 2), match = g.memory.u8(at + 4);
|
||||
if (g.memory.u8(at + 3) != league || day == 0 || day >= kCalendarDays || round >= league_matchdays(league)) continue;
|
||||
const auto fx = round_fixtures(league, round);
|
||||
if (size_t(match) < fx.size() && (fx[size_t(match)].home == team || fx[size_t(match)].away == team))
|
||||
replays.push_back({round, match, day});
|
||||
}
|
||||
out.resize(kCalendarDays);
|
||||
std::vector<std::pair<int, ClubCalendarMatch>> moved; // replay day, match
|
||||
int ordinal = 0;
|
||||
for (int d = 0; d < kCalendarDays; d++) {
|
||||
ClubCalendarDay& day = out[size_t(d)];
|
||||
day.day = d;
|
||||
day.word = g.memory.u16(kCalendar + uint32_t(d) * 2);
|
||||
day.competitions = day_competitions(g, day.word);
|
||||
for (int i = 0; i < kFriendlyEntries && team >= 0; i++) {
|
||||
if (g.memory.u16(kFriendlyDays + uint32_t(i) * 2) != uint16_t(d)) continue;
|
||||
for (int side = 0; side < 2; side++)
|
||||
if (int16_t(g.memory.u16(kFriendlyTeams + uint32_t(i) * 4 + uint32_t(side) * 2)) == team) day.friendly = true;
|
||||
}
|
||||
if (league >= kLeagueCount || !(day.competitions >> kLeagueBit[league] & 1) || ordinal >= league_matchdays(league)) continue;
|
||||
const int round = ordinal++;
|
||||
const auto fx = round_fixtures(league, round);
|
||||
for (size_t m = 0; m < fx.size(); m++) {
|
||||
if (fx[m].home != team && fx[m].away != team) continue;
|
||||
ClubCalendarMatch match{league, round, int(m), fx[m].home, fx[m].away, -1, g.results.at(result_at(league, round, int(m)))};
|
||||
const auto replay = std::find_if(replays.begin(), replays.end(),
|
||||
[&](const Replay& r) { return r.round == round && r.match == int(m); });
|
||||
if (replay != replays.end() && replay->day != d) {
|
||||
match.original_day = d;
|
||||
moved.push_back({replay->day, match});
|
||||
} else {
|
||||
day.matches.push_back(match);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& [day, match] : moved) out[size_t(day)].matches.push_back(match);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -59,4 +59,26 @@ std::vector<LeagueMatchRef> moved_matches(const ModernState& g, int manager);
|
||||
// freed. Returns false if there is no such match.
|
||||
bool undo_reschedule(ModernState& g, int manager, int day);
|
||||
|
||||
|
||||
// The season calendar of a club for the interface (pure, no random draw): per calendar day
|
||||
// (0 = the season's first day, as CompetitionCalendar) the calendar word, the day's
|
||||
// competitions (day_competitions) and whether the club has a friendly, plus the club's league
|
||||
// matches. A league match sits on the day of its round (the rounds counted along the league's
|
||||
// calendar bit, as advance_league_rounds does); one with a replay entry (moved, 0xCE, or
|
||||
// postponed in winter, 0xCD) sits on the replay day with `original_day` set to its planned day.
|
||||
struct ClubCalendarMatch {
|
||||
int league = 0, round = 0, match = 0; // 0-based round, index in the round's fixture list
|
||||
int home = 0, away = 0;
|
||||
int original_day = -1; // the planned day of a replay, else -1
|
||||
uint8_t result = 0xcc; // result byte: home << 4 | away, 0xCC..0xCF open
|
||||
};
|
||||
struct ClubCalendarDay {
|
||||
int day = 0;
|
||||
uint16_t word = 0;
|
||||
uint32_t competitions = 0;
|
||||
bool friendly = false;
|
||||
std::vector<ClubCalendarMatch> matches;
|
||||
};
|
||||
std::vector<ClubCalendarDay> club_calendar(const ModernState& g, int team);
|
||||
|
||||
} // namespace bmh::modern
|
||||
Reference in new issue
Block a user