Modern UI contract: scheduling, friendlies and rescheduling

The scheduling read lists the own league matches that can be moved with
their target dates and the moved ones; the friendly read quotes a friendly
against a club with its free dates. friendly.book books it (the payer
accepts the cost, a human opponent consents), fixture.reschedule moves a
league match or takes a move back. All without random draws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:51:35 +01:00
1 parent f2c895ffb0
commit 06445c24ef
4 files changed
+187 -35

No files matched your search

+45
View File
@@ -15,6 +15,7 @@
#include "modern/game/almanac.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/environment.hpp"
#include "modern/game/reschedule.hpp"
namespace bmh::modern {
@@ -369,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 == "scheduling" || kind == "friendly") {
const int own = team_of(g, c.manager);
if (own < 0 || own >= league_clubs())
return failure(request_id, "no_club", "Am Schreibtisch des Bundestrainers gibt es das nicht.", c.state_revision);
const auto date_of = [&](int day) { return iso(almanac_date(g.season_start + uint32_t(day), g.display_start_year)); };
if (kind == "scheduling") {
// league matches that can be moved (own home matches, rounds 1 .. matchdays - 3) with
// the dates they can go to, and moved ones that can be taken back (no random draw)
const auto ref_id = [](const LeagueMatchRef& r) {
return "move:" + std::to_string(r.day) + "-" + std::to_string(r.league) + "-" + std::to_string(r.round) + "-" + std::to_string(r.match);
};
A movable, moved;
for (const auto& r : reschedulable_matches(g, c.manager)) {
A targets;
for (int day : reschedule_target_days(g, c.manager, r)) targets.push_back(date_of(day));
movable.push_back(O{{"id", ref_id(r)}, {"date", date_of(r.day)}, {"round", r.round + 1},
{"home", team_ref(g, r.home, date_of(r.day))}, {"away", team_ref(g, r.away, date_of(r.day))},
{"targetDates", std::move(targets)}});
}
for (const auto& r : moved_matches(g, c.manager))
moved.push_back(O{{"date", date_of(r.day)}, {"round", r.round + 1}, {"home", team_ref(g, r.home, date_of(r.day))},
{"away", team_ref(g, r.away, date_of(r.day))}});
return snapshot(request_id, std::move(m), O{{"kind", "scheduling"}, {"movable", std::move(movable)}, {"moved", std::move(moved)}});
}
// friendly {opponentId, home?}: the price and venue quote and the free dates (no random draw)
const int opponent = requested_team(g, UiContext{c.state_revision, c.manager}, O{{"teamId", text_field(request, "opponentId")}});
const J* home_field = field(request, "home");
const bool home = !home_field || !std::holds_alternative<bool>(home_field->value) || std::get<bool>(home_field->value);
if (opponent < 0 || text_field(request, "opponentId").empty())
return failure(request_id, "unknown_team", "opponentId nennt keinen Verein.", c.state_revision);
const FriendlyBookingQuote q = quote_friendly_match(g, c.manager, opponent, home);
if (q.status != FriendlyQuoteStatus::quoted)
return failure(request_id, "friendly_unavailable", "Gegen diesen Verein ist kein Freundschaftsspiel möglich.", c.state_revision);
A dates;
for (int day = g.season_day() + 1; day <= 365; ++day) {
const FriendlyDateStatus st = friendly_match_date_status(g, q, uint16_t(day));
if (st == FriendlyDateStatus::available || st == FriendlyDateStatus::available_with_calendar_event)
dates.push_back(O{{"date", date_of(day)}, {"withCalendarEvent", st == FriendlyDateStatus::available_with_calendar_event}});
}
return snapshot(request_id, std::move(m),
O{{"kind", "friendly"}, {"home", team_ref(g, q.home_team, iso(almanac_date(g.date, g.display_start_year)))}, {"away", team_ref(g, q.away_team, iso(almanac_date(g.date, g.display_start_year)))},
{"cost", ui_money(q.cost)}, {"payerManagerId", q.payer_manager >= 0 ? J(manager_id(g, q.payer_manager)) : J(nullptr)},
{"opponentHuman", q.opponent_manager >= 0}, {"dates", std::move(dates)}});
}
if (kind == "environment") {
// the club's surroundings (Diamond 3.6): three youth teams, co-trainer, doctor, physio, each
// with a monthly budget level 0-6 and its cost; the youth teams' strength, place and league