Bind native balance planning and restore its saved runtime value (by Codex)
This commit is contained in:
1 parent
256d6d5211
commit
fd5c2b5330
24 files changed
+717
-28
No files matched your search
@@ -42,6 +42,7 @@
|
||||
#include "import/save.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
#include <system_error>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
@@ -7825,12 +7826,22 @@ void ModernSession::restore_native_session_context(const cli::Json &root) {
|
||||
if (!row.object() || !row.object()->contains("address") || !row.object()->contains("value"))
|
||||
throw FormatError("Invalid runtime byte");
|
||||
const auto at = uint32_t(integer(row.object()->at("address"), 0, UINT32_MAX));
|
||||
if (!club_modal_runtime_.contains(at) ||
|
||||
!runtime.emplace(at, uint8_t(integer(row.object()->at("value"), 0, 255))).second)
|
||||
const auto value = uint8_t(integer(row.object()->at("value"), 0, 255));
|
||||
const bool planned_ticket = at >= ::bmh::layout::PlanTicketPrice &&
|
||||
at < ::bmh::layout::PlanTicketPrice + 4 && !g_.memory.has(at);
|
||||
if ((!club_modal_runtime_.contains(at) && !planned_ticket) ||
|
||||
!runtime.emplace(at, value).second)
|
||||
throw FormatError("Unknown or duplicated runtime byte");
|
||||
if (planned_ticket && value > 25)
|
||||
throw FormatError("Invalid planned ticket price");
|
||||
}
|
||||
for (const auto &[address, value] : club_modal_runtime_) {
|
||||
(void)value;
|
||||
const bool planned_ticket = address >= ::bmh::layout::PlanTicketPrice &&
|
||||
address < ::bmh::layout::PlanTicketPrice + 4 && !g_.memory.has(address);
|
||||
if (!planned_ticket && !runtime.contains(address))
|
||||
throw FormatError("Incomplete native runtime bytes");
|
||||
}
|
||||
if (runtime.size() != club_modal_runtime_.size())
|
||||
throw FormatError("Incomplete native runtime bytes");
|
||||
std::vector<ui::DeskMatchCallargs> callargs;
|
||||
for (const auto &row : array(field("desk_callargs"), 4)) {
|
||||
const auto &fields = array(row, 2);
|
||||
@@ -8764,6 +8775,8 @@ std::string ui_text(const cli::Json& j, const char* key) {
|
||||
return v && v->string() ? *v->string() : std::string{};
|
||||
}
|
||||
|
||||
#include "modern/app/ui_balance.inc"
|
||||
|
||||
// The original mailbox of a manager, each message with an id that stays the same while the
|
||||
// mailbox shifts its entries (the entry index does not): "message:<day>-<text hash>", "-<n>"
|
||||
// for the n-th equal message of a day.
|
||||
@@ -9000,12 +9013,20 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
return answer;
|
||||
}
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "achievements" && kind != "statistics" && kind != "opening" && kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
(kind != "balance" && kind != "achievements" && kind != "statistics" && kind != "opening" && kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
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 == "balance") {
|
||||
try {
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
ui_balance_plan(g_, exe_, club_modal_runtime_, manager, request).data);
|
||||
} catch (const std::exception &e) {
|
||||
return modern::ui_error(request_id, "balance_unavailable", e.what(), revision, false);
|
||||
}
|
||||
}
|
||||
if(kind=="achievements") {
|
||||
const int team=g_.manager_teams[size_t(manager)];
|
||||
if(team<0||team>=league_clubs()||manager>3)return modern::ui_error(request_id,"no_club","Erfolge sind am Vereinsschreibtisch verfügbar.",revision,false);
|
||||
@@ -10585,6 +10606,33 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
if (!dispatch_ticket_price(r, revision, error)) { restore(); return refuse("ticket_refused", error); }
|
||||
if (revision != previous) revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Eintrittspreis gesetzt.");
|
||||
} else if (kind == "balance.commit") {
|
||||
if (balance_active() || transfer_offer_editor_ || contract_quote_ || stadium_.block_expansion)
|
||||
return refuse("decision_pending", "Bitte die offene Entscheidung zuerst abschließen.");
|
||||
if (ui_text(*payload, "view") != "future")
|
||||
return refuse("invalid_payload", "Eine Zukunftsplanung wird benötigt.");
|
||||
const auto *edits = ui_field(*payload, "edits");
|
||||
if (!edits || !edits->array() || edits->array()->empty())
|
||||
return refuse("invalid_payload", "Keine Planänderungen vorhanden.");
|
||||
try {
|
||||
auto plan = ui_balance_plan(g_, exe_, club_modal_runtime_, manager, *payload);
|
||||
const auto *accept = ui_field(*payload, "acceptWarning");
|
||||
if (plan.warning && (!accept || !std::holds_alternative<bool>(accept->value) ||
|
||||
!std::get<bool>(accept->value)))
|
||||
return refuse("confirmation_required", "Die Bilanzwarnung muss bestätigt werden.");
|
||||
const auto address = ::bmh::layout::PlanTicketPrice + uint32_t(manager);
|
||||
g_.manager_records = std::move(plan.records);
|
||||
if (g_.memory.has(address))
|
||||
g_.memory.set8(address, plan.ticket);
|
||||
else
|
||||
club_modal_runtime_[address] = plan.ticket;
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision,
|
||||
{"balance", "desktop"}, "Bilanzplanung übernommen.");
|
||||
} catch (const std::exception &e) {
|
||||
restore();
|
||||
return refuse("balance_refused", e.what());
|
||||
}
|
||||
} 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