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
@@ -35,6 +35,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
| `advertising` | 14 Banden (`ad:board/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
|
||||
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
|
||||
| `transfer` | die Transferliste (`listing:<n>`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Jahr, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen |
|
||||
| `calendar` | der Saisonkalender des Teams am Schreibtisch, `from`/`until` (ISO, Vorgabe der laufende Monat): `days` (Datum, `seasonDay`, `today`, `eventKinds`: `league`, `cup:<n>`, `replay`, `indoor`, `special`, `national`, `friendly`; `fixtureIds`) und `fixtures` (die eigenen Ligaspiele: `fixture:league-<Liga>-<Runde>-<Nr.>`, Wettbewerb, Runde, `originalDate`, `scheduledDate`, Heim/Gast, `status` `scheduled`/`played`/`rescheduled`/`postponed`, `result`). Verlegte und im Winter ausgefallene Spiele stehen am Nachholtag. Pokalspiele nur als `eventKinds`; Fehler `invalid_range` |
|
||||
| `scheduling` | die verlegbaren eigenen Ligaspiele (`move:<Tag>-<Liga>-<Runde>-<Nr.>`, Datum, Runde, Heim/Gast, mögliche Zieldaten) und die verlegten, die sich zurücknehmen lassen |
|
||||
| `friendly` | mit `opponentId`, optional `home`: das Angebot für ein Freundschaftsspiel (Heim/Gast, Kosten, Zahler, ob der Gegner einen menschlichen Manager hat) und die freien Daten der Saison; kein Zufall |
|
||||
| `environment` | das Umfeld (Diamond 3.6): drei Jugendteams, Co-Trainer, Arzt, Physiotherapeut (`environment:<Bereich>`), je Stufe 0–6, Monatskosten, Kosten je Stufe; die Jugendteams mit Stärke, Platz, Liga; ob die Akademie läuft |
|
||||
|
||||
@@ -370,6 +370,50 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
|
||||
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
|
||||
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
|
||||
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
|
||||
if (kind == "calendar") {
|
||||
// the season calendar of the desk's team: days from `from` to `until` (ISO dates, default
|
||||
// the current month) with the day's competitions and the team's league matches (planned
|
||||
// day, or the replay day of a moved/postponed one with its original date). No draw.
|
||||
const int own = team_of(g, c.manager);
|
||||
const auto date_of = [&](int day) { return iso(almanac_date(g.season_start + uint32_t(day), g.display_start_year)); };
|
||||
const std::string from = text_field(request, "from").empty() ? today.substr(0, 8) + "01" : text_field(request, "from");
|
||||
const std::string until = text_field(request, "until").empty() ? today.substr(0, 8) + "31" : text_field(request, "until");
|
||||
if (from.size() != 10 || until.size() != 10 || until < from)
|
||||
return failure(request_id, "invalid_range", "from und until sind ISO-Daten, until nicht vor from.", c.state_revision);
|
||||
A days, fixtures;
|
||||
for (const ClubCalendarDay& d : club_calendar(g, own)) {
|
||||
const std::string date = date_of(d.day);
|
||||
if (date < from || date > until) continue;
|
||||
A kinds, ids;
|
||||
if (d.competitions & 0x1f) kinds.push_back("league");
|
||||
for (int bit = 5; bit < 15; ++bit)
|
||||
if (d.competitions >> bit & 1) kinds.push_back("cup:" + std::to_string(bit - 5));
|
||||
if (d.competitions & 0x8000) kinds.push_back("replay");
|
||||
if (d.competitions & 0x10000) kinds.push_back("indoor");
|
||||
if (d.competitions & 0x40000) kinds.push_back("special");
|
||||
if (d.competitions & 0x800000) kinds.push_back("national");
|
||||
if (d.friendly) kinds.push_back("friendly");
|
||||
for (const ClubCalendarMatch& cm : d.matches) {
|
||||
const std::string id = "fixture:league-" + std::to_string(cm.league) + "-" + std::to_string(cm.round + 1) + "-" + std::to_string(cm.match);
|
||||
ids.push_back(id);
|
||||
const bool open = (cm.result & 0xcc) == 0xcc;
|
||||
const bool past = d.day < g.season_day();
|
||||
const std::string league_id = cm.league < int(g.world_league_id.size()) && !g.world_league_id[size_t(cm.league)].empty()
|
||||
? g.world_league_id[size_t(cm.league)] : "league:" + std::to_string(cm.league);
|
||||
fixtures.push_back(O{{"id", id}, {"competition", O{{"id", league_id}, {"kind", "league"}}},
|
||||
{"round", cm.round + 1}, {"originalDate", cm.original_day >= 0 ? J(date_of(cm.original_day)) : J(date)},
|
||||
{"scheduledDate", date}, {"home", team_ref(g, cm.home, date)}, {"away", team_ref(g, cm.away, date)},
|
||||
{"status", !open ? "played" : cm.result == 0xcd && cm.original_day < 0 ? "postponed"
|
||||
: cm.original_day >= 0 ? "rescheduled" : past ? "void" : "scheduled"},
|
||||
{"result", open ? J(nullptr) : J(A{J(cm.result >> 4), J(cm.result & 0xf)})}});
|
||||
}
|
||||
if (kinds.empty() && ids.empty()) continue;
|
||||
days.push_back(O{{"date", date}, {"seasonDay", d.day}, {"today", d.day == g.season_day()},
|
||||
{"eventKinds", std::move(kinds)}, {"fixtureIds", std::move(ids)}});
|
||||
}
|
||||
return snapshot(request_id, std::move(m),
|
||||
O{{"kind", "calendar"}, {"from", from}, {"until", until}, {"days", std::move(days)}, {"fixtures", std::move(fixtures)}});
|
||||
}
|
||||
if (kind == "scheduling" || kind == "friendly") {
|
||||
const int own = team_of(g, c.manager);
|
||||
if (own < 0 || own >= league_clubs())
|
||||
|
||||
@@ -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
|
||||
@@ -4,6 +4,7 @@
|
||||
// (a Modern session on the Classic data).
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
@@ -415,6 +416,26 @@ int main(int argc, char** argv) {
|
||||
const J again = session.ui_read(O{{"kind", "scheduling"}}, rev);
|
||||
check(s(at(moved, "messageType")) == "command_result" && rev == before + 1 && at(at(again, "data"), "moved").array() &&
|
||||
!at(at(again, "data"), "moved").array()->empty(), "league match moved");
|
||||
// the calendar of the season: every league match once (two per opponent), the
|
||||
// moved one on its new date with the planned one as original date
|
||||
const J cal = session.ui_read(O{{"kind", "calendar"}, {"from", "1900-01-01"}, {"until", "2999-12-31"}}, rev);
|
||||
const auto* fixtures = at(at(cal, "data"), "fixtures").array();
|
||||
std::set<std::string> ids, opponents;
|
||||
std::string own = s(at(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "data"), "team"), "id"));
|
||||
bool moved_seen = false;
|
||||
if (fixtures)
|
||||
for (const auto& f : *fixtures) {
|
||||
ids.insert(s(at(f, "id")));
|
||||
const std::string h = s(at(at(f, "home"), "id")), a = s(at(at(f, "away"), "id"));
|
||||
opponents.insert(h == own ? a : h);
|
||||
if (s(at(f, "status")) == "rescheduled" && s(at(f, "scheduledDate")) == target && s(at(f, "originalDate")) != target)
|
||||
moved_seen = true;
|
||||
}
|
||||
std::printf("(calendar: %zu days, %zu league matches, %zu opponents)\n",
|
||||
at(at(cal, "data"), "days").array() ? at(at(cal, "data"), "days").array()->size() : 0, ids.size(), opponents.size());
|
||||
check(fixtures && ids.size() == fixtures->size() && !opponents.empty() && ids.size() == 2 * opponents.size(),
|
||||
"calendar: every league match once, two per opponent");
|
||||
check(moved_seen, "calendar: the moved match on its new date");
|
||||
const J undone = session.ui_command(cmd("request:f2", "fixture.reschedule", O{{"action", "undo"}, {"date", target}}), rev);
|
||||
check(s(at(undone, "messageType")) == "command_result", "move taken back");
|
||||
std::printf("(moved %s to %s and back)\n", match.c_str(), target.c_str());
|
||||
|
||||
Reference in new issue
Block a user