Modern UI contract: national friendlies
At the national coach's desk the friendly read quotes a match against another nation on a copy of the Watcom generator (price, payer, ratings, free dates); friendly.book draws the same ratings and books it. The opponent bound of the national quote follows the world layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3d526c2e4
commit
d943494ef4
4 files changed
+107
-7
No files matched your search
@@ -37,7 +37,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
| `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 |
|
||||
| `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. Am Schreibtisch des Bundestrainers ein Länderspiel (`national: true`, Gegner ein anderes Nationalteam, dazu `ratings` beider Teams): das Original zieht für die Bewertung Zufall; der Read rechnet auf einer Kopie des Generators, die Buchung zieht dieselben Zahlen |
|
||||
| `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 |
|
||||
| `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung |
|
||||
| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) |
|
||||
@@ -83,7 +83,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
|
||||
| `budget.commit` | `budgetId` (`budget:merchandise`, `budget:press`, `budget:fans`), `amount` (`Money`) | setzt ein Budget; Fehler `unknown_budget`, `invalid_amount`, `advertising_refused` (z. B. Lieferung läuft, zu wenig Geld) |
|
||||
| `ticket.commit` | `price` (`Money`, 8–25 €) | der Eintrittspreis; Fehler `invalid_amount`, `ticket_refused` |
|
||||
| `transfer.submit` | `action: list`, `playerId`, optional `loan`; oder `action: bid`, `listingId`, `fee`, `monthlySalary` (`Money`), `years` 1–4, optional `loan` | setzt einen eigenen Spieler auf die Liste (bzw. bietet ihn zum Verleih an) oder gibt über den Angebotseditor des Originals ein Gebot ab (öffnen, Felder setzen, abschicken). `outcome`: `applied` (sofort angenommen), `offer_pending` (Antwort mit der nächsten Woche), `offer_rejected` (zu niedrig/abgelehnt). Fragt die Engine einen menschlichen Verkäufer (Abwerben), wird zurückgerollt: `decision_pending` (noch nicht unterstützt). Fehler `unknown_player`, `already_listed`, `unknown_listing`, `own_player`, `no_bid_slot`, `transfer_refused` |
|
||||
| `friendly.book` | `opponentId`, optional `home`, `date`, `acceptCost`, bei menschlichem Gegner `opponentConsent` | vereinbart das Freundschaftsspiel; Fehler `declined` (Kosten nicht bestätigt), `opponent_declined`, `insufficient_funds`, `date_unavailable`, `plan_full` u. a. |
|
||||
| `friendly.book` | `opponentId`, optional `home`, `date`, `acceptCost`, bei menschlichem Gegner `opponentConsent` | am Schreibtisch des Bundestrainers das Länderspiel (Rückmeldung mit Bonus, wenn das Original ihn gewährt); vereinbart das Freundschaftsspiel; Fehler `declined` (Kosten nicht bestätigt), `opponent_declined`, `insufficient_funds`, `date_unavailable`, `plan_full` u. a. |
|
||||
| `fixture.reschedule` | `matchId`, `date`; oder `action: undo`, `date` | verlegt eine eigene Ligapartie bzw. nimmt die Verlegung zurück; Fehler `invalid_day`, `day_full`, `team_clash`, `no_free_slot`, `no_moved_match` |
|
||||
| `environment.commit` | `itemId`, `level` 0–6 | setzt ein Monatsbudget des Umfelds (keine Sofortbuchung, kein Zufall); unverändert: `outcome: no_change`; Fehler `environment_refused` |
|
||||
| `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen): Der letzte menschliche Manager beendet die Karriere (`outcome: career_ended`, `session`-Read `sessionState: "ended"`, danach antwortet jeder Befehl `career_ended`). Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` |
|
||||
|
||||
@@ -8758,6 +8758,18 @@ std::string ui_text(const cli::Json& j, const char* key) {
|
||||
return v && v->string() ? *v->string() : std::string{};
|
||||
}
|
||||
|
||||
// The runtime team a contract team id names (a world id or "team:<n>"), or -1.
|
||||
int ui_team_index(const ModernState& g, const std::string& id) {
|
||||
if (id.empty()) return -1;
|
||||
for (int t = 0; t < int(g.world_club_id.size()); ++t)
|
||||
if (g.world_club_id[size_t(t)] == id) return t;
|
||||
if (id.starts_with("team:")) try {
|
||||
const int t = std::stoi(id.substr(5));
|
||||
if (t >= 0 && t < world_layout().total_teams()) return t;
|
||||
} catch (const std::exception&) {}
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
cli::Json ModernSession::read_live(const cli::Json& request) const {
|
||||
@@ -8929,10 +8941,42 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
const int manager = context.manager;
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit"))
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" &&
|
||||
!(kind == "friendly" && g_.manager_teams[size_t(manager)] == no_team())))
|
||||
return modern::ui_read(g_, context, request);
|
||||
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
|
||||
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
|
||||
if (kind == "friendly") {
|
||||
// the national coach's friendly (menu 6): the quote rates both teams with a draw of the
|
||||
// Watcom generator; the read quotes on a copy of it (the session's generator stays as it
|
||||
// is), the booking later draws the same numbers. Price, payer and the free dates.
|
||||
const int opponent = ui_team_index(g_, ui_text(request, "opponentId"));
|
||||
const cli::Json* home_field = ui_field(request, "home");
|
||||
const bool home = !home_field || !std::holds_alternative<bool>(home_field->value) || std::get<bool>(home_field->value);
|
||||
if (opponent < 0) return modern::ui_error(request_id, "unknown_team", "opponentId nennt kein Team.", revision, false);
|
||||
const NationalFriendlyOwner owner{1, revision, manager, no_team(), 6}; // request_id 1: the contract has its own ids
|
||||
WatcomRandom staged = rand_;
|
||||
const NationalFriendlyQuote q = modern::quote_national_friendly_match(g_, owner, opponent, home, staged);
|
||||
if (q.terms.status != FriendlyQuoteStatus::quoted)
|
||||
return modern::ui_error(request_id, "friendly_unavailable", "Gegen dieses Team ist kein Freundschaftsspiel möglich.", revision, false);
|
||||
A dates;
|
||||
for (int day = g_.season_day() + 1; day <= 365; ++day) {
|
||||
const FriendlyDateStatus st = modern::national_friendly_match_date_status(g_, q, owner, staged, uint16_t(day));
|
||||
if (st != FriendlyDateStatus::available && st != FriendlyDateStatus::available_with_calendar_event) continue;
|
||||
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);
|
||||
dates.push_back(O{{"date", text}, {"withCalendarEvent", st == FriendlyDateStatus::available_with_calendar_event}});
|
||||
}
|
||||
const auto team = [&](int t) {
|
||||
return cli::Json(O{{"id", modern::ui_team_id(g_, t)}, {"name", ui::original_to_utf8(g_.club_name(t))}});
|
||||
};
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "friendly"}, {"national", true}, {"home", team(q.terms.home_team)}, {"away", team(q.terms.away_team)},
|
||||
{"cost", modern::ui_money(q.terms.cost)},
|
||||
{"payerManagerId", q.terms.payer_manager >= 0 ? cli::Json(modern::ui_manager_id(g_, q.terms.payer_manager)) : cli::Json(nullptr)},
|
||||
{"opponentHuman", q.terms.opponent_manager >= 0}, {"ratings", A{q.own_rating, q.opponent_rating}}, {"dates", std::move(dates)}});
|
||||
}
|
||||
if (kind == "postmatch") {
|
||||
// the after-match steps of the interface for the last session.advance: results (every match
|
||||
// of the kickoff), report (the matches of human managers), the eleven of the day (the
|
||||
@@ -10162,7 +10206,8 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
}
|
||||
} 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.");
|
||||
const bool national = team == no_team() && kind == "friendly.book";
|
||||
if (!national && (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) {
|
||||
@@ -10177,7 +10222,38 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
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") {
|
||||
if (national) {
|
||||
// the national coach's friendly: the quote draws its ratings from the Watcom generator
|
||||
// (as the friendly read previewed), then the booking on the chosen date
|
||||
const int opponent = ui_team_index(g_, ui_text(*payload, "opponentId"));
|
||||
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");
|
||||
const NationalFriendlyOwner owner{1, revision, manager, no_team(), 6}; // request_id 1: the contract has its own ids
|
||||
NationalFriendlyBookingRequest r;
|
||||
r.owner = owner;
|
||||
r.quote = modern::quote_national_friendly_match(g_, owner, opponent,
|
||||
!home || !std::holds_alternative<bool>(home->value) || std::get<bool>(home->value), rand_);
|
||||
if (r.quote.terms.status != FriendlyQuoteStatus::quoted) {
|
||||
restore();
|
||||
return refuse("friendly_unavailable", "Gegen dieses Team ist kein Freundschaftsspiel möglich.");
|
||||
}
|
||||
r.season_day = uint16_t(day);
|
||||
r.accept_opponent = r.quote.terms.opponent_manager < 0 || flag("opponentConsent");
|
||||
r.consenting_manager = r.quote.terms.opponent_manager;
|
||||
r.accept_cost = flag("acceptCost");
|
||||
r.approving_manager = r.quote.terms.payer_manager;
|
||||
const NationalFriendlyBookingResult result = modern::book_national_friendly_match(g_, r, rand_, game_);
|
||||
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, {"calendar", "desktop"},
|
||||
result.national_bonus_awarded ? "Länderspiel vereinbart (Bonus)." : "Länderspiel vereinbart.");
|
||||
} else 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");
|
||||
|
||||
@@ -132,7 +132,7 @@ NationalFriendlyQuote make_national_friendly_quote(const ModernState& g,
|
||||
return out;
|
||||
}
|
||||
// Page 4 cannot return Germany (0); the engine boundary repeats that gate.
|
||||
if (opponent <= no_team() || opponent > 0x1a2 || opponent == no_team()) {
|
||||
if (opponent <= no_team() || opponent >= world_layout().total_teams()) {
|
||||
out.terms.status = FriendlyQuoteStatus::invalid_opponent;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -656,10 +656,34 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
O expiry;
|
||||
int decisions = 0, advances = 0;
|
||||
int national_friendly = -1; // -1 no national desk yet, 0 read, 1 booked
|
||||
for (int k = 0; k < 200 && advances < 120; ++k) {
|
||||
const uint64_t before = rev;
|
||||
const J done = session.ui_command(cmd("request:s" + std::to_string(k), "session.advance", O{{"contractExpiry", expiry}}), rev);
|
||||
if (s(at(done, "messageType")) == "command_result") { ++advances; continue; }
|
||||
if (s(at(done, "messageType")) == "command_result") {
|
||||
++advances;
|
||||
// at the national coach's desk: a friendly against another nation (the quote
|
||||
// draws ratings; the read previews them without moving the generator)
|
||||
if (national_friendly < 0) {
|
||||
const J nf = session.ui_read(O{{"kind", "friendly"}, {"opponentId", "team:384"}}, rev);
|
||||
if (!truth(at(at(nf, "data"), "national"))) continue;
|
||||
const J again = session.ui_read(O{{"kind", "friendly"}, {"opponentId", "team:384"}}, rev);
|
||||
const auto* dates = at(at(nf, "data"), "dates").array();
|
||||
check(cli::dump_json(at(nf, "data")) == cli::dump_json(at(again, "data")) && dates, "national friendly read is pure");
|
||||
std::printf("(national friendly: %s)\n", cli::dump_json(at(nf, "data")).substr(0, 300).c_str());
|
||||
national_friendly = 0;
|
||||
if (dates && !dates->empty()) {
|
||||
const J day = at(dates->back(), "date");
|
||||
const uint64_t was = rev;
|
||||
const J booked = session.ui_command(cmd("request:nf" + std::to_string(k), "friendly.book",
|
||||
O{{"opponentId", "team:384"}, {"date", day}, {"acceptCost", true}}), rev);
|
||||
std::printf("(national friendly booked: %s)\n", cli::dump_json(booked).substr(0, 200).c_str());
|
||||
check(s(at(booked, "messageType")) == "command_result" && rev == was + 1, "national friendly booked");
|
||||
national_friendly = 1;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const std::string code = s(at(done, "code"));
|
||||
const std::string player = s(at(at(at(done, "message"), "args"), "playerId"));
|
||||
check(code == "decision_pending" && !player.empty() && rev == before, "a pending contract names the player, nothing changed");
|
||||
|
||||
Reference in new issue
Block a user