Modern UI contract: building in the stadium (periphery and facilities)
The original's stadium dialog in two commands: quote.request opens it and gets the building firm's offer (periphery) or selects a facility and levels; stadium.commit builds - facilities with or without the tip for faster building - or declines, and closes the dialog. The stadium read shows the open offer; a refused command also restores the dialog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6386c891b5
commit
e6bc72d3a0
3 files changed
+152
-7
No files matched your search
@@ -8890,8 +8890,20 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
{"seats", (k.flags & 1) != 0}, {"roof", (k.flags & 2) != 0},
|
||||
{"constructionWeeks", int(k.construction_weeks)}, {"placesAfterConstruction", int64_t(k.capacity) * 1000}});
|
||||
}
|
||||
// the open offer of the stadium dialog (quote.request), answered by stadium.commit
|
||||
cli::Json quote = nullptr;
|
||||
if (stadium_.opened && stadium_.manager == manager) {
|
||||
const std::string id = "quote:stadium-" + std::to_string(stadium_.scope);
|
||||
if (stadium_.periphery_quote)
|
||||
quote = O{{"id", id}, {"kind", "periphery"}, {"objectId", "periphery:" + std::to_string(stadium_.periphery_quote->first)},
|
||||
{"price", modern::ui_money(stadium_.periphery_quote->second)}};
|
||||
else if (stadium_.investment && stadium_.option)
|
||||
quote = O{{"id", id}, {"kind", "facility"}, {"facilityId", std::string("facility:") + kFacilities[size_t(*stadium_.investment)]},
|
||||
{"toLevel", int(stadium_.option->target_level)}, {"price", modern::ui_money(stadium_.option->base_price)},
|
||||
{"weeks", int(stadium_.option->base_weeks)}, {"tipPercent", O{{"min", 6}, {"max", 14}}}};
|
||||
}
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"periphery", std::move(periphery)},
|
||||
O{{"kind", "stadium"}, {"teamId", modern::ui_team_id(g_, team)}, {"quote", std::move(quote)}, {"periphery", std::move(periphery)},
|
||||
{"facilities", std::move(facilities)}, {"blocks", std::move(blocks)},
|
||||
{"ticketPrice", modern::ui_money(data.ticket_price)}, {"ticketPriceRange", O{{"min", modern::ui_money(8)}, {"max", modern::ui_money(25)}}}});
|
||||
}
|
||||
@@ -9067,11 +9079,14 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
const auto saved_quote = contract_quote_;
|
||||
const uint64_t saved_quote_id = next_contract_quote_id_, saved_contract_request = last_contract_request_id_;
|
||||
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 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;
|
||||
};
|
||||
cli::Json answer;
|
||||
std::string error;
|
||||
@@ -9296,6 +9311,95 @@ 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" && (ui_text(*payload, "kind") == "periphery" || ui_text(*payload, "kind") == "facility")) ||
|
||||
kind == "stadium.commit") {
|
||||
// The stadium dialog of the original in two commands; it stays open in between:
|
||||
// quote.request {kind: periphery, objectId} - opens the stadium, the building firm's offer
|
||||
// quote.request {kind: facility, facilityId, increment 1-3} - a facility and how many levels
|
||||
// stadium.commit {quoteId, accept, tip?} - builds (facilities: with or without the tip for
|
||||
// faster building, as the original asks) or declines, and closes the stadium
|
||||
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 kein Stadion.");
|
||||
bool ok = true;
|
||||
const auto step = [&](ui::StadiumRequestKind k, int object = -1, int option = -1, int32_t price = 0, bool tip = false) {
|
||||
if (!ok) return;
|
||||
ui::StadiumRequest r;
|
||||
r.kind = k, r.manager_slot = manager, r.runtime_club = team, r.revision = revision;
|
||||
r.stable_club_identity = int(g_.club_ids.at(size_t(team)));
|
||||
if (k != ui::StadiumRequestKind::open) r.scope = stadium_.scope, r.sequence = stadium_.sequence;
|
||||
r.object = object, r.option = option, r.price = price, r.accept_tip = tip;
|
||||
ok = dispatch_stadium(r, revision, error);
|
||||
};
|
||||
static constexpr const char* kFacilities[8] = {"floodlights", "scoreboard", "pitch_heating", "vip_lounge", "pitch", "comfort", "condition", "safety"};
|
||||
if (kind == "quote.request") {
|
||||
if (stadium_.opened && (stadium_.periphery_quote || stadium_.investment))
|
||||
return refuse("quote_open", "Ein Stadionangebot ist noch offen (stadium.commit).");
|
||||
if (!stadium_.opened) step(ui::StadiumRequestKind::open);
|
||||
if (ui_text(*payload, "kind") == "periphery") {
|
||||
int object = -1;
|
||||
if (std::sscanf(ui_text(*payload, "objectId").c_str(), "periphery:%d", &object) != 1 || object < 0 || object >= 14) {
|
||||
restore(); return refuse("unknown_object", "Unbekanntes Umfeldobjekt.");
|
||||
}
|
||||
step(ui::StadiumRequestKind::quote_periphery, object);
|
||||
} else {
|
||||
const std::string id = ui_text(*payload, "facilityId");
|
||||
int facility = -1;
|
||||
for (int i = 0; i < 8; ++i) if (id == std::string("facility:") + kFacilities[i]) facility = i;
|
||||
const cli::Json* inc = ui_field(*payload, "increment");
|
||||
if (facility < 0 || !inc || !inc->integer() || *inc->integer() < 1 || *inc->integer() > 3) {
|
||||
restore(); return refuse("invalid_payload", "facilityId und increment (1 bis 3) nötig.");
|
||||
}
|
||||
step(ui::StadiumRequestKind::select_investment, facility);
|
||||
if (ok) {
|
||||
StadiumInvestmentConstants constants;
|
||||
for (unsigned i = 0; i < 8; ++i) {
|
||||
constants.price[i] = exe_.u32(::bmh::layout::CareerSession_DispatchStadium_RuntimeField + i * 4);
|
||||
constants.weeks[i] = exe_.u8(::bmh::layout::CareerSession_DispatchStadium_RuntimeField2 + (14 + i) * 5);
|
||||
}
|
||||
const auto options = modern::stadium_investment_options_source(g_, manager, static_cast<StadiumInvestment>(facility),
|
||||
stadium_.price_percent, constants);
|
||||
const size_t option = size_t(*inc->integer() - 1);
|
||||
if (option >= options.size()) { restore(); return refuse("level_unavailable", "So viele Stufen sind nicht möglich."); }
|
||||
step(ui::StadiumRequestKind::select_investment_option, facility, int(option), int32_t(options[option].base_price));
|
||||
}
|
||||
}
|
||||
if (!ok) { restore(); return refuse("stadium_refused", error); }
|
||||
revision = previous + 1;
|
||||
stadium_.revision = revision; // the open dialog continues at the command's one revision
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Angebot liegt vor.");
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
|
||||
} else {
|
||||
const std::string quote = ui_text(*payload, "quoteId");
|
||||
const cli::Json* accept = ui_field(*payload, "accept");
|
||||
const cli::Json* tip = ui_field(*payload, "tip");
|
||||
const bool yes = accept && std::holds_alternative<bool>(accept->value) && std::get<bool>(accept->value);
|
||||
const bool with_tip = tip && std::holds_alternative<bool>(tip->value) && std::get<bool>(tip->value);
|
||||
if (!stadium_.opened || quote != "quote:stadium-" + std::to_string(stadium_.scope))
|
||||
return refuse("stale_quote", "Dieses Stadionangebot gilt nicht mehr.");
|
||||
if (stadium_.periphery_quote) {
|
||||
const auto [object, price] = *stadium_.periphery_quote;
|
||||
step(yes ? ui::StadiumRequestKind::build_periphery : ui::StadiumRequestKind::decline_periphery, object, -1, price);
|
||||
} else if (stadium_.investment && stadium_.option) {
|
||||
const int facility = int(*stadium_.investment), option = stadium_.option_index;
|
||||
const int32_t base = int32_t(stadium_.option->base_price);
|
||||
if (!yes) {
|
||||
step(ui::StadiumRequestKind::cancel_investment, facility);
|
||||
} else {
|
||||
step(ui::StadiumRequestKind::confirm_investment, facility, option, base);
|
||||
if (ok && stadium_.tip)
|
||||
step(ui::StadiumRequestKind::answer_construction_tip, facility, option,
|
||||
int32_t(with_tip ? stadium_.tip->offered_price : stadium_.tip->base_price), with_tip);
|
||||
}
|
||||
} else {
|
||||
return refuse("stale_quote", "Es liegt kein Stadionangebot vor.");
|
||||
}
|
||||
const std::string feedback = stadium_.feedback;
|
||||
step(ui::StadiumRequestKind::close);
|
||||
if (!ok) { restore(); return refuse("stadium_refused", error); }
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"stadium", "desktop", "bank"},
|
||||
!feedback.empty() ? feedback : yes ? "Der Bau beginnt." : "Abgelehnt.");
|
||||
}
|
||||
} 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,
|
||||
|
||||
Reference in new issue
Block a user