Modern UI contract: transfer read and transfer.submit

The transfer read lists the transfer list with asking fee, salary reference,
offers and the own bid, and the own squad. transfer.submit lists an own
player (or offers him for loan) or bids through the original's offer editor
(open, set fee, salary and years, submit); the outcome tells accepted,
pending or rejected. The open editor is part of the rollback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:32:44 +01:00
1 parent 43317985e4
commit 1400848387
3 files changed
+179 -1

No files matched your search

+144 -1
View File
@@ -8824,7 +8824,7 @@ 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 != "advertising" && kind != "stadium" && kind != "transfer"))
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);
@@ -8854,6 +8854,36 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
{"rows", std::move(rows)}, {"positions", std::move(positions)}, {"depthMax", 19}, {"laneMax", 8},
{"manual", g_.manager_options.size() > size_t(manager) * 5 && g_.manager_options[size_t(manager) * 5] == 0}});
}
if (kind == "transfer") {
// the transfer list (listed players with seller, asking fee, salary reference, offers, the own
// bid), the own squad (listed or not), account and credit line
ui::TransferMarketState mk;
try { mk = ui::transfer_market_from_game(g_, revision); } catch (const std::exception&) {
return modern::ui_error(request_id, "transfer_unavailable", "Der Transfermarkt ist hier nicht verfügbar.", revision, false);
}
static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"};
A listings, squad;
for (const auto& it : mk.items) {
cli::Json bid = nullptr;
if (it.own_bid)
bid = O{{"fee", modern::ui_money(it.own_bid->fee)}, {"annualSalary", modern::ui_money(it.own_bid->annual_salary)},
{"years", int(it.own_bid->contract_years)}};
listings.push_back(O{{"id", "listing:" + std::to_string(it.list_entry)}, {"playerId", modern::ui_player_id(g_, it.player)},
{"name", ui::original_to_utf8(it.name)}, {"age", it.age}, {"position", kPositions[it.position & 3]},
{"strength", it.strength},
{"sellerId", it.seller >= 0 ? cli::Json(modern::ui_team_id(g_, it.seller)) : cli::Json(nullptr)},
{"seller", ui::original_to_utf8(it.seller_name)}, {"askingFee", modern::ui_money(it.asking_fee)},
{"salaryReference", modern::ui_money(it.salary_reference)},
{"salaryDemandPercent", int(it.salary_demand_percent)}, {"offers", it.offers},
{"ownListing", it.own_listing}, {"ownBidPending", it.own_bid_pending}, {"ownBid", std::move(bid)}});
}
for (const auto& s : mk.squad)
squad.push_back(O{{"playerId", modern::ui_player_id(g_, s.player)}, {"name", ui::original_to_utf8(s.name)}, {"age", s.age},
{"position", kPositions[s.position & 3]}, {"strength", s.strength}, {"listed", s.already_listed}});
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "transfer"}, {"teamId", modern::ui_team_id(g_, team)}, {"listings", std::move(listings)}, {"squad", std::move(squad)},
{"cash", modern::ui_money(mk.balance)}, {"creditLine", modern::ui_money(mk.credit_line)}});
}
if (kind == "stadium") {
// the periphery (14 objects; the traffic access has three stages), the eight facilities with
// their level, the eight stand blocks (capacity in thousands, seats, roof) and the ticket price;
@@ -9081,12 +9111,15 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
const uint64_t saved_advertising_request = last_advertising_request_id_;
const StadiumRuntime saved_stadium = stadium_;
const uint64_t saved_stadium_scope = next_stadium_scope_;
const auto saved_offer_editor = transfer_offer_editor_;
const uint64_t saved_offer_revision = transfer_offer_revision_;
const auto restore = [&] {
g_ = saved_state; rand_ = saved_rand; game_ = saved_game; revision = previous;
lineup_entry_manager_ = saved_entry_manager, lineup_entry_club_ = saved_entry_club; // the board stays as it was
contract_quote_ = saved_quote, next_contract_quote_id_ = saved_quote_id, last_contract_request_id_ = saved_contract_request;
last_advertising_request_id_ = saved_advertising_request;
stadium_ = saved_stadium, next_stadium_scope_ = saved_stadium_scope;
transfer_offer_editor_ = saved_offer_editor, transfer_offer_revision_ = saved_offer_revision;
};
cli::Json answer;
std::string error;
@@ -9492,6 +9525,116 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"advertising", "desktop", "bank"},
kind == "advertising.accept" ? "Werbevertrag abgeschlossen." : "Budget gesetzt.");
} else if (kind == "transfer.submit") {
// {action: "list", playerId, loan?}: an own player on the transfer list (or offered for loan)
// {action: "bid", listingId, fee, monthlySalary, years 1-4, loan?}: an offer on a listed player
// through the original's offer editor (open, set the fields, submit). A question to a human
// seller (poaching) is not supported yet and rolls back with decision_pending.
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 keine Transfers.");
const std::string action = ui_text(*payload, "action");
const cli::Json* loan_field = ui_field(*payload, "loan");
const bool loan = loan_field && std::holds_alternative<bool>(loan_field->value) && std::get<bool>(loan_field->value);
std::vector<std::string> notices;
bool question = false;
HumanBuyerSaleHooks hooks;
hooks.notice = [&](const GameState&, const HumanBuyerSaleNotice& n) { notices.push_back(ui::original_to_utf8(n.original_message)); };
hooks.confirm = [&](const GameState&, int, const std::string&) -> bool { question = true; throw std::runtime_error("question"); };
const ui::TransferMarketState m = ui::transfer_market_from_game(g_, revision);
std::string feedback;
bool bid_pending = false;
try {
if (action == "list") {
const std::string id = ui_text(*payload, "playerId");
const auto item = std::find_if(m.squad.begin(), m.squad.end(), [&](const auto& s) { return modern::ui_player_id(g_, s.player) == id; });
if (item == m.squad.end()) return refuse("unknown_player", "Spieler nicht im Kader: " + id);
if (item->already_listed) return refuse("already_listed", "Der Spieler steht schon auf der Liste.");
ui::TransferMarketRequest r;
r.kind = ui::TransferMarketRequestKind::list_player;
r.offer_is_loan = loan;
r.manager_slot = m.manager_slot, r.runtime_club = m.runtime_club, r.revision = m.revision;
r.squad_row = item->row, r.expected_player = item->player;
r.selected_players.push_back({-1, m.roster.squad_start_offset + item->row, item->player, m.runtime_club, item->row});
if (!dispatch_transfer_market(r, hooks, revision, error)) { restore(); return refuse("transfer_refused", error); }
feedback = loan ? "Der Spieler wird zum Verleih angeboten." : "Der Spieler steht auf der Transferliste.";
} else if (action == "bid") {
int entry = -1;
if (std::sscanf(ui_text(*payload, "listingId").c_str(), "listing:%d", &entry) != 1) return refuse("unknown_listing", "listingId fehlt.");
const auto item = std::find_if(m.items.begin(), m.items.end(), [&](const auto& it) { return it.list_entry == entry; });
if (item == m.items.end()) return refuse("unknown_listing", "Dieser Listenplatz ist nicht (mehr) belegt.");
if (item->own_listing) return refuse("own_player", "Das ist ein eigener Spieler.");
const auto money_of = [&](const char* key) -> int64_t {
const cli::Json* v = ui_field(*payload, key);
try { return v ? std::stoll(ui_text(*v, "minor")) : -1; } catch (const std::exception&) { return -1; }
};
const int64_t fee = money_of("fee"), salary = money_of("monthlySalary");
const cli::Json* years = ui_field(*payload, "years");
if (fee < 0 || fee % 100 || salary < 0 || salary % 100 || !years || !years->integer() || *years->integer() < 1 || *years->integer() > 4)
return refuse("invalid_payload", "fee, monthlySalary (Money, ganze Euro) und years 1-4 nötig.");
ui::TransferMarketRequest open;
open.kind = ui::TransferMarketRequestKind::open_offer;
open.offer_is_loan = loan;
open.manager_slot = m.manager_slot, open.runtime_club = m.runtime_club, open.revision = m.revision;
if (item->own_bid) open.bid = *item->own_bid;
open.bid.manager = m.manager_slot, open.bid.list_entry = item->list_entry, open.bid.player = item->player;
open.bid.source_slot = item->source_slot;
open.selected_players.push_back({item->list_entry, item->source_slot, item->player, item->seller, -1});
auto opened = open_transfer_offer(open, revision, error);
if (!opened) { restore(); return refuse("transfer_refused", error); }
ui::OutgoingTransferEditorState e = opened->editor;
if (!e.editable) { restore(); return refuse("no_bid_slot", "Für diesen Spieler ist kein Angebot möglich."); }
const auto edit = [&](ui::OutgoingTransferRequestKind k, ui::OutgoingTransferField field, uint32_t value)
-> std::optional<TransferOfferEditorDispatch> {
ui::OutgoingTransferRequest r;
r.kind = k;
r.identity = {e.manager_slot, e.runtime_club, e.revision, e.list_entry, e.source_slot, e.player, e.seller, e.bid_slot};
r.field = field, r.value = value, r.quote_loan = e.quote_loan;
r.fee = e.fee, r.monthly_salary = e.monthly_salary, r.duration_years = e.duration_years, r.bonuses = e.bonuses;
r.quoted_fee = e.panel.quoted_fee, r.quoted_monthly_salary = e.panel.quoted_monthly_salary, r.quoted_years = e.panel.quoted_years;
auto d = dispatch_transfer_offer(r, hooks, revision, error);
if (d) e = d->editor;
return d;
};
// the screen stores the edited value and asks for a fresh quote, one field at a time
bool ok = true;
if (ok && e.fee != uint32_t(fee / 100)) { e.fee = uint32_t(fee / 100); ok = bool(edit(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::fee, e.fee)); }
if (ok && e.monthly_salary != uint32_t(salary / 100)) {
e.monthly_salary = uint32_t(salary / 100);
ok = bool(edit(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::monthly_salary, e.monthly_salary));
}
if (ok && e.duration_years != uint8_t(*years->integer())) {
e.duration_years = uint8_t(*years->integer());
ok = bool(edit(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::duration_years, e.duration_years));
}
std::optional<TransferOfferEditorDispatch> sent;
if (ok) sent = edit(ui::OutgoingTransferRequestKind::submit, ui::OutgoingTransferField::fee, e.fee);
if (!sent) { restore(); return refuse("transfer_refused", error); }
const TransferActionStatus status = sent->action.status;
bid_pending = status == TransferActionStatus::pending;
if (!e.closed) edit(ui::OutgoingTransferRequestKind::cancel, ui::OutgoingTransferField::fee, e.fee); // a low offer keeps it open
feedback = status == TransferActionStatus::accepted ? "Angenommen: Der Spieler wechselt zu Ihrem Verein."
: status == TransferActionStatus::pending ? "Angebot abgegeben; die Antwort kommt mit der nächsten Woche."
: status == TransferActionStatus::offer_too_low ? "Das Angebot ist zu niedrig."
: "Das Angebot wurde abgelehnt.";
if (status != TransferActionStatus::accepted && status != TransferActionStatus::pending) {
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"transfer"}, feedback);
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
}
} else {
return refuse("invalid_payload", "action ist list oder bid.");
}
} catch (const std::exception& ex) {
restore();
if (question) return refuse("decision_pending", "Ein menschlicher Verkäufer müsste gefragt werden (noch nicht unterstützt).");
return refuse("transfer_refused", ex.what());
}
for (const auto& n : notices) feedback += (feedback.empty() ? "" : " ") + n;
if (std::holds_alternative<std::nullptr_t>(answer.value)) {
revision = previous + 1;
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 == "toto.submit") {
// payload {stake: Money per column, columns: [[11 tips: 1 home, 0 draw, 2 away], ... up to 6]}
const cli::Json* stake = ui_field(*payload, "stake");