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:
1 parent
f2c895ffb0
commit
06445c24ef
4 files changed
+187
-35
No files matched your search
@@ -10094,6 +10094,75 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer", "squad", "desktop"}, feedback);
|
||||
if (bid_pending) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
|
||||
}
|
||||
} else if (kind == "friendly.book" || kind == "fixture.reschedule") {
|
||||
const int team = g_.manager_teams[size_t(manager)];
|
||||
if (team < 0 || team >= league_clubs()) return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es das nicht.");
|
||||
// a date of this season as its season day (0..365)
|
||||
const auto day_of = [&](const std::string& iso) -> int {
|
||||
for (int day = 0; day <= 365; ++day) {
|
||||
const AlmanacDate d = almanac_date(g_.season_start + uint32_t(day), g_.display_start_year);
|
||||
char text[16];
|
||||
std::snprintf(text, sizeof text, "%04d-%02d-%02d", d.year, d.month, d.day);
|
||||
if (iso == text) return day;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
const auto flag = [&](const char* key) {
|
||||
const cli::Json* v = ui_field(*payload, key);
|
||||
return v && std::holds_alternative<bool>(v->value) && std::get<bool>(v->value);
|
||||
};
|
||||
if (kind == "friendly.book") {
|
||||
// {opponentId, home?, date, acceptCost, opponentConsent?}: the quote of the friendly read
|
||||
// on a free date; the payer accepts the cost, a human opponent's manager consents
|
||||
const std::string opponent_id = ui_text(*payload, "opponentId");
|
||||
int opponent = -1;
|
||||
for (int t = 0; t < int(g_.world_club_id.size()); ++t) if (g_.world_club_id[size_t(t)] == opponent_id) opponent = t;
|
||||
if (opponent < 0 && opponent_id.starts_with("team:")) try { opponent = std::stoi(opponent_id.substr(5)); } catch (const std::exception&) {}
|
||||
const int day = day_of(ui_text(*payload, "date"));
|
||||
if (opponent < 0 || day < 0) return refuse("invalid_payload", "opponentId und date (dieser Saison) nötig.");
|
||||
const cli::Json* home = ui_field(*payload, "home");
|
||||
FriendlyBookingRequest r;
|
||||
r.quote = modern::quote_friendly_match(g_, manager, opponent, !home || !std::holds_alternative<bool>(home->value) || std::get<bool>(home->value));
|
||||
if (r.quote.status != FriendlyQuoteStatus::quoted) return refuse("friendly_unavailable", "Gegen diesen Verein ist kein Freundschaftsspiel möglich.");
|
||||
r.season_day = uint16_t(day);
|
||||
r.accept_opponent = r.quote.opponent_manager < 0 || flag("opponentConsent");
|
||||
r.consenting_manager = r.quote.opponent_manager;
|
||||
r.accept_cost = flag("acceptCost");
|
||||
r.approving_manager = r.quote.payer_manager;
|
||||
const FriendlyBookingResult result = modern::book_friendly_match(g_, r);
|
||||
if (result.status != FriendlyBookingStatus::booked) {
|
||||
static constexpr const char* kStatus[11] = {"booked", "declined", "opponent_declined", "insufficient_funds", "invalid_manager",
|
||||
"invalid_opponent", "invalid_date", "date_unavailable", "plan_full", "stale_quote", "invalid_request"};
|
||||
restore();
|
||||
return refuse(kStatus[size_t(result.status)], "Das Freundschaftsspiel kam nicht zustande.");
|
||||
}
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop", "bank"},
|
||||
"Freundschaftsspiel vereinbart.");
|
||||
} else {
|
||||
// {matchId: "move:...", date}: a league match to another day; {action: "undo", date}: a move taken back
|
||||
if (ui_text(*payload, "action") == "undo") {
|
||||
const int day = day_of(ui_text(*payload, "date"));
|
||||
if (day < 0 || !modern::undo_reschedule(g_, manager, day)) { restore(); return refuse("no_moved_match", "An diesem Tag gibt es keine verlegte Partie."); }
|
||||
} else {
|
||||
int day = -1, league = -1, round = -1, match = -1;
|
||||
if (std::sscanf(ui_text(*payload, "matchId").c_str(), "move:%d-%d-%d-%d", &day, &league, &round, &match) != 4)
|
||||
return refuse("invalid_payload", "matchId (move:...) und date nötig.");
|
||||
LeagueMatchRef ref;
|
||||
for (const auto& r : modern::reschedulable_matches(g_, manager))
|
||||
if (r.day == day && r.league == league && r.round == round && r.match == match) ref = r;
|
||||
const int target = day_of(ui_text(*payload, "date"));
|
||||
if (ref.day < 0 || target < 0) return refuse("unknown_match", "Diese Partie kann nicht verlegt werden.");
|
||||
const RescheduleStatus st = modern::reschedule_league_match(g_, manager, ref, target);
|
||||
if (st != RescheduleStatus::moved) {
|
||||
static constexpr const char* kStatus[7] = {"moved", "invalid_manager", "invalid_match", "invalid_day", "no_free_slot", "day_full", "team_clash"};
|
||||
restore();
|
||||
return refuse(kStatus[size_t(st)], "Die Partie lässt sich nicht auf diesen Tag verlegen.");
|
||||
}
|
||||
}
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop"}, "Spielplan geändert.");
|
||||
}
|
||||
} else if (kind == "environment.commit") {
|
||||
// payload {itemId: "environment:<item>", level 0-6}: a monthly budget of the surroundings
|
||||
// (no immediate booking, no random draw); the original's notice comes back as feedback
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user