Modern UI contract: contracts read, quote.request and contract.offer
The contracts read lists remaining months, salary, insurance and bonuses per player and the open quote. quote.request asks a player's demands for one to four years (a draw, as at the desk); contract.offer answers applied or offer_rejected. A refused command also restores the open quote. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6054a44acf
commit
2ca6b21a94
3 files changed
+119
-1
No files matched your search
@@ -8823,7 +8823,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
|
||||
const int manager = context.manager;
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank"))
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts"))
|
||||
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);
|
||||
@@ -8853,6 +8853,38 @@ 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 == "contracts") {
|
||||
// per player: remaining months, monthly salary, insurance, the team bonuses; the open quote
|
||||
// (quote.request) with the monthly demand for one to four years
|
||||
ui::ContractsState c;
|
||||
try { c = ui::contracts_from_game(g_, manager, revision); } catch (const std::exception&) {
|
||||
return modern::ui_error(request_id, "contracts_unavailable", "Die Verträge sind hier nicht verfügbar.", revision, false);
|
||||
}
|
||||
static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"};
|
||||
A players;
|
||||
for (const auto& p : c.players) {
|
||||
A premiums;
|
||||
for (uint8_t b : p.team_premiums) premiums.push_back(int(b));
|
||||
players.push_back(O{{"playerId", modern::ui_player_id(g_, p.player_id)}, {"name", p.name},
|
||||
{"age", p.age}, {"position", kPositions[p.position & 3]},
|
||||
{"contractRemaining", O{{"value", int(p.remaining_months)}, {"unit", "months"}}},
|
||||
{"salaryMonthly", modern::ui_money(p.current_monthly_salary)},
|
||||
{"insuranceMonths", int(p.insurance)}, {"insuranceAvailable", p.insurance_available},
|
||||
{"insuranceFee", modern::ui_money(p.insurance_fee)}, {"offerBlocked", p.offer_blocked},
|
||||
{"bonuses", std::move(premiums)}});
|
||||
}
|
||||
cli::Json quote = nullptr;
|
||||
if (contract_quote_ && contract_quote_->manager_slot == manager) {
|
||||
A demands;
|
||||
for (size_t y = 0; y < 4; ++y)
|
||||
demands.push_back(O{{"years", int(y + 1)}, {"monthlyDemand", modern::ui_money(contract_quote_->demands[y])}});
|
||||
quote = O{{"id", "quote:contract-" + std::to_string(contract_quote_->quote_id)},
|
||||
{"playerId", modern::ui_player_id(g_, contract_quote_->player_id)}, {"demands", std::move(demands)},
|
||||
{"maxMonthlySalary", modern::ui_money(200000)}};
|
||||
}
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "contracts"}, {"teamId", modern::ui_team_id(g_, team)}, {"players", std::move(players)}, {"quote", std::move(quote)}});
|
||||
}
|
||||
if (kind == "bank") {
|
||||
// account, fixed deposit, credit line, the 12 stocks and 6 funds (prices in whole euros,
|
||||
// converted to Money); the stock tip draws a random number and is no read
|
||||
@@ -8951,9 +8983,12 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
const GameRandom saved_game = game_;
|
||||
const uint64_t previous = revision;
|
||||
const int saved_entry_manager = lineup_entry_manager_, saved_entry_club = lineup_entry_club_;
|
||||
const auto saved_quote = contract_quote_;
|
||||
const uint64_t saved_quote_id = next_contract_quote_id_, saved_contract_request = last_contract_request_id_;
|
||||
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;
|
||||
};
|
||||
cli::Json answer;
|
||||
std::string error;
|
||||
@@ -9126,6 +9161,61 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
"statistics", "almanac"}, what);
|
||||
if (r.kind == TurnDeskKind::CareerComplete)
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "career_ended";
|
||||
} else if (kind == "quote.request" || kind == "contract.offer") {
|
||||
// quote.request {kind: "contract", playerId}: the player's demands for one to four years
|
||||
// (draws a random number, as at the desk); contract.offer {quoteId, years 1-4,
|
||||
// monthlySalary: Money}: the offer against that quote, accepted or rejected by the player
|
||||
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 Verträge.");
|
||||
const SquadRange range = squad_range(team);
|
||||
ui::ContractRequest r;
|
||||
r.request_id = last_contract_request_id_ + 1;
|
||||
r.revision = revision;
|
||||
r.manager_slot = manager;
|
||||
r.runtime_club = team;
|
||||
if (kind == "quote.request") {
|
||||
if (ui_text(*payload, "kind") != "contract") return refuse("unknown_quote", "quote.request kennt bisher kind contract.");
|
||||
const std::string id = ui_text(*payload, "playerId");
|
||||
for (size_t row = 0; row < range.count; ++row) {
|
||||
const int p = g_.squad_slots[range.first + row] & 0x0fff;
|
||||
if (p != 0x0fff && modern::ui_player_id(g_, p) == id) r.row = int(row), r.player_id = p;
|
||||
}
|
||||
if (r.row < 0) return refuse("unknown_player", "Spieler nicht im Kader: " + id);
|
||||
r.kind = ui::ContractActionKind::request_demands;
|
||||
ui::ContractActionResult result;
|
||||
if (!dispatch_contract(r, revision, result, error)) { restore(); return refuse("quote_refused", error); }
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"contracts"}, "Forderungen liegen vor.");
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
|
||||
} else {
|
||||
const std::string quote = ui_text(*payload, "quoteId");
|
||||
const cli::Json* years = ui_field(*payload, "years");
|
||||
const cli::Json* salary = ui_field(*payload, "monthlySalary");
|
||||
if (!contract_quote_ || quote != "quote:contract-" + std::to_string(contract_quote_->quote_id))
|
||||
return refuse("stale_quote", "Dieses Angebot gilt nicht mehr; bitte die Forderungen neu abfragen.");
|
||||
if (!years || !years->integer() || *years->integer() < 1 || *years->integer() > 4 || !salary)
|
||||
return refuse("invalid_payload", "years (1 bis 4) und monthlySalary (Money) nötig.");
|
||||
int64_t cents = -1;
|
||||
try { cents = std::stoll(ui_text(*salary, "minor")); } catch (const std::exception&) { cents = -1; }
|
||||
if (cents < 0 || cents % 100 != 0) return refuse("invalid_amount", "monthlySalary in ganzen Euro.");
|
||||
r.kind = ui::ContractActionKind::submit_offer;
|
||||
r.quote_id = contract_quote_->quote_id;
|
||||
r.row = contract_quote_->row;
|
||||
r.player_id = contract_quote_->player_id;
|
||||
r.term_column = uint8_t(*years->integer() - 1);
|
||||
r.demand = contract_quote_->demands[r.term_column];
|
||||
r.monthly_salary = uint32_t(cents / 100);
|
||||
const size_t board = size_t(manager) * 0x840 + size_t(r.row) * 0x58;
|
||||
for (size_t i = 0; i < r.proposed_bonuses.size() && board + 0x12 + i < g_.tactics.size(); ++i)
|
||||
r.proposed_bonuses[i] = g_.tactics[board + 0x12 + i]; // the bonuses stay as they are
|
||||
ui::ContractActionResult result;
|
||||
if (!dispatch_contract(r, revision, result, error)) { restore(); return refuse("offer_refused", error); }
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"contracts", "squad", "desktop"},
|
||||
result.feedback.empty() ? (result.accepted ? "Vertrag verlängert." : "Angebot abgelehnt.")
|
||||
: result.feedback);
|
||||
if (!result.accepted) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
|
||||
}
|
||||
} else if (kind == "bank.commit") {
|
||||
// payload {action: deposit|withdraw, amount: Money} or {action: buy|sell, assetId: stock:<n>|fund:<n>, count}
|
||||
const std::string action = ui_text(*payload, "action");
|
||||
|
||||
Reference in new issue
Block a user