Implement calibrated Modern stadium periphery preview and staged upgrades (by Codex)
This commit is contained in:
1 parent
fff2cc2f0b
commit
bfcf9a07bf
12 files changed
+470
-37
No files matched your search
@@ -20,6 +20,18 @@ constexpr std::array<const char *, 8> facility_names{
|
||||
"Rasenzustand", "Stadionkomfort", "Stadionzustand", "Stadionsicherheit"};
|
||||
constexpr std::array<int, 8> facility_rates{250000,350000,850000,1200000,180000,200000,300000,400000};
|
||||
constexpr std::array<int, 8> facility_weeks{12,15,16,18,8,5,10,14};
|
||||
constexpr std::array<const char *, 14> periphery_names{
|
||||
"Verkehrsanbindung", "Arcade-Spielhalle", "Einkaufszentrum", "Clubhaus", "Parkplatz", "Restaurant",
|
||||
"1. Imbissbude", "2. Imbissbude", "3. Imbissbude", "4. Imbissbude",
|
||||
"1. Fan-Shop", "2. Fan-Shop", "3. Fan-Shop", "4. Fan-Shop"};
|
||||
constexpr std::array<int, 14> periphery_rates{700000,800000,1800000,650000,450000,550000,90000,90000,90000,90000,140000,140000,140000,140000};
|
||||
constexpr std::array<int, 14> periphery_weeks{12,14,28,16,9,12,4,4,4,4,6,6,6,6};
|
||||
int periphery_cap(size_t index) { return index == 0 ? 4 : index == 4 ? 3 : 1; }
|
||||
Json initial_periphery() {
|
||||
Json rows = Json::array();
|
||||
for (size_t i = 0; i < 14; ++i) rows.push_back({{"level", i == 0 || i == 4 || i == 5 ? 1 : 0}, {"job", nullptr}});
|
||||
return rows;
|
||||
}
|
||||
bool keys(const Json &value, std::initializer_list<const char *> expected) {
|
||||
return value.is_object() && value.size() == expected.size() &&
|
||||
std::all_of(expected.begin(), expected.end(), [&](auto *key) { return value.contains(key); });
|
||||
@@ -77,7 +89,7 @@ Json demo_stadium(const Catalog &world, const std::string &club) {
|
||||
facilities.push_back({{"level", initial_levels[i]}, {"job", nullptr}});
|
||||
}
|
||||
return {{"club", owner(world, nullptr, club)}, {"budget", budget_units * finance_currency_factor(world)},
|
||||
{"blocks", blocks}, {"facilities", facilities}};
|
||||
{"blocks", blocks}, {"facilities", facilities}, {"periphery", initial_periphery()}};
|
||||
}
|
||||
|
||||
bool valid_demo_stadium(const Json &state, const Catalog &world, const std::string &club) {
|
||||
@@ -85,11 +97,12 @@ bool valid_demo_stadium(const Json &state, const Catalog &world, const std::stri
|
||||
if (!state.is_object()) return false;
|
||||
const int64_t factor = finance_currency_factor(world), cap = budget_units * factor;
|
||||
const auto &stadium = state.at("stadium");
|
||||
if (!keys(stadium, {"club", "budget", "blocks", "facilities"}) ||
|
||||
if (!keys(stadium, {"club", "budget", "blocks", "facilities", "periphery"}) ||
|
||||
!stadium.at("club").is_string() || stadium.at("club") != owner(world, &state, club) ||
|
||||
!integer(stadium.at("budget"), 0, cap) ||
|
||||
!stadium.at("blocks").is_array() || stadium.at("blocks").size() != 8 ||
|
||||
!stadium.at("facilities").is_array() || stadium.at("facilities").size() != 8) return false;
|
||||
!stadium.at("facilities").is_array() || stadium.at("facilities").size() != 8 ||
|
||||
!stadium.at("periphery").is_array() || stadium.at("periphery").size() != 14) return false;
|
||||
int64_t pending = 0;
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
const auto &base = stadium.at("blocks")[i];
|
||||
@@ -120,6 +133,18 @@ bool valid_demo_stadium(const Json &state, const Catalog &world, const std::stri
|
||||
if (job.at("cost") != cost || cost > cap - pending) return false;
|
||||
pending += cost;
|
||||
}
|
||||
for (size_t i = 0; i < 14; ++i) {
|
||||
const auto &base = stadium.at("periphery")[i];
|
||||
if (!keys(base, {"level", "job"}) || !integer(base.at("level"), 0, periphery_cap(i))) return false;
|
||||
const auto &job = base.at("job");
|
||||
if (job.is_null()) continue;
|
||||
const int next = base.at("level").get<int>() + 1;
|
||||
const int64_t cost = periphery_rates[i] * factor;
|
||||
if (next > periphery_cap(i) || !keys(job, {"level", "weeks", "cost"}) ||
|
||||
!integer(job.at("level"), next, next) || !integer(job.at("weeks"), periphery_weeks[i], periphery_weeks[i]) ||
|
||||
job.at("cost") != cost || cost > cap - pending) return false;
|
||||
pending += cost;
|
||||
}
|
||||
return stadium.at("budget").get<int64_t>() == cap - pending;
|
||||
} catch (const std::exception &) { return false; }
|
||||
}
|
||||
@@ -127,7 +152,15 @@ bool valid_demo_stadium(const Json &state, const Catalog &world, const std::stri
|
||||
bool migrate_demo_stadium(Json &state, const Catalog &world, const std::string &club) {
|
||||
try {
|
||||
if (!state.is_object()) return false;
|
||||
if (state.contains("stadium")) return valid_demo_stadium(state, world, club);
|
||||
if (state.contains("stadium")) {
|
||||
if (valid_demo_stadium(state, world, club)) return true;
|
||||
if (!keys(state.at("stadium"), {"club", "budget", "blocks", "facilities"})) return false;
|
||||
auto next = state;
|
||||
next["stadium"]["periphery"] = initial_periphery();
|
||||
if (!valid_demo_stadium(next, world, club)) return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
}
|
||||
auto next = state;
|
||||
next["stadium"] = demo_stadium(world, owner(world, &state, club));
|
||||
if (!valid_demo_stadium(next, world, club)) return false;
|
||||
@@ -140,7 +173,7 @@ Json demo_stadium_quote(const Json &state, const Json &request, const Catalog &w
|
||||
if (!valid_demo_stadium(state, world, club)) return error("invalid_stadium_state");
|
||||
try {
|
||||
if (!request.is_object() || !request.contains("kind") || !request.at("kind").is_string() ||
|
||||
!request.contains("index") || !integer(request.at("index"), 0, 7)) return error("invalid_stadium_request");
|
||||
!request.contains("index") || !integer(request.at("index"), 0, request.value("kind", std::string()) == "periphery" ? 13 : 7)) return error("invalid_stadium_request");
|
||||
const auto kind = request.at("kind").get<std::string>();
|
||||
const auto index = request.at("index").get<size_t>();
|
||||
const auto &stadium = state.at("stadium");
|
||||
@@ -161,6 +194,14 @@ Json demo_stadium_quote(const Json &state, const Json &request, const Catalog &w
|
||||
quote = {{"cost", (request.at("level").get<int64_t>() - base.at("level").get<int64_t>()) * facility_rates[index] * factor},
|
||||
{"weeks", facility_weeks[index]}, {"placesCost", 0}, {"seatsCost", 0}, {"roofCost", 0}};
|
||||
pending = !base.at("job").is_null();
|
||||
} else if (kind == "periphery") {
|
||||
const auto &base = stadium.at("periphery")[index];
|
||||
const int next = base.at("level").get<int>() + 1;
|
||||
if (!keys(request, {"kind", "index", "level"}) || next > periphery_cap(index) ||
|
||||
!integer(request.at("level"), next, next)) return error("invalid_stadium_periphery_target");
|
||||
quote = {{"cost", periphery_rates[index] * factor}, {"weeks", periphery_weeks[index]},
|
||||
{"placesCost", 0}, {"seatsCost", 0}, {"roofCost", 0}};
|
||||
pending = !base.at("job").is_null();
|
||||
} else return error("unknown_stadium_request");
|
||||
const auto cost = quote.at("cost").get<int64_t>(), budget = stadium.at("budget").get<int64_t>();
|
||||
const auto reason = pending ? "stadium_pending" : !cost ? "stadium_no_change"
|
||||
@@ -187,7 +228,7 @@ std::string edit_demo_stadium(Json &state, const Json &action, const Catalog &wo
|
||||
next["stadium"]["blocks"][index]["job"] = job;
|
||||
} else {
|
||||
job["level"] = request.at("level");
|
||||
next["stadium"]["facilities"][index]["job"] = job;
|
||||
next["stadium"][quote.at("kind") == "periphery" ? "periphery" : "facilities"][index]["job"] = job;
|
||||
}
|
||||
next["stadium"]["budget"] = quote.at("remaining");
|
||||
if (!valid_demo_stadium(next, world, club)) return "invalid_stadium_state";
|
||||
@@ -208,7 +249,11 @@ Json demo_stadium_rules(const Catalog &world) {
|
||||
facilities.push_back({{"index", i}, {"name", facility_names[i]}, {"max_level", facility_cap(i)},
|
||||
{"rate", facility_rates[i] * factor}, {"weeks", facility_weeks[i]}, {"levels", levels}});
|
||||
}
|
||||
return {{"budget_cap", budget_units * factor}, {"blocks", blocks}, {"facilities", facilities}};
|
||||
Json periphery = Json::array();
|
||||
for (size_t i = 0; i < 14; ++i)
|
||||
periphery.push_back({{"index", i}, {"name", periphery_names[i]}, {"max_level", periphery_cap(i)},
|
||||
{"rate", periphery_rates[i] * factor}, {"weeks", periphery_weeks[i]}});
|
||||
return {{"budget_cap", budget_units * factor}, {"blocks", blocks}, {"facilities", facilities}, {"periphery", periphery}};
|
||||
}
|
||||
|
||||
Json demo_stadium_view(const Json &state, const Catalog &world, bool future, const std::string &club) {
|
||||
@@ -249,6 +294,17 @@ Json demo_stadium_view(const Json &state, const Catalog &world, bool future, con
|
||||
row["display_level"] = level; row["display_label"] = row.at("levels")[size_t(level)];
|
||||
if (building) pending += job.at("cost").get<int64_t>();
|
||||
}
|
||||
for (size_t i = 0; i < 14; ++i) {
|
||||
const auto &base = stadium.at("periphery")[i]; const auto &job = base.at("job");
|
||||
const bool building = !job.is_null(); auto &row = rules["periphery"][i];
|
||||
row["level"] = base.at("level"); row["job"] = job; row["building"] = building;
|
||||
row["display_level"] = (future && building ? job : base).at("level");
|
||||
if (building) pending += job.at("cost").get<int64_t>();
|
||||
}
|
||||
// Closed blocks still contribute their completed size to the physical stadium.
|
||||
int64_t physical = 0;
|
||||
for (const auto &block : stadium.at("blocks")) physical += block.at("places").get<int64_t>();
|
||||
rules["physical_capacity"] = future ? planned : physical;
|
||||
rules["ok"] = true; rules["club"] = id; rules["club_name"] = team ? world.name(*team) : "—";
|
||||
rules["stadium"] = record ? record->at("id") : Json();
|
||||
const auto name = record ? world.name(*record) : "";
|
||||
@@ -258,4 +314,55 @@ Json demo_stadium_view(const Json &state, const Catalog &world, bool future, con
|
||||
rules["capacity"] = future ? planned : available;
|
||||
return rules;
|
||||
}
|
||||
Json demo_stadium_scene(const Json &configuration, const Json &overview, bool future) {
|
||||
if (configuration.at("schemaVersion") != 1 || configuration.at("activeProfile") != "modern")
|
||||
throw editor::Error("invalid_stadium_scene");
|
||||
const auto &profile = configuration.at("profiles").at("modern");
|
||||
if (profile.at("referenceSize").at("width") != 1920 || profile.at("referenceSize").at("height") != 1080 ||
|
||||
profile.at("objects").size() != 14 || overview.at("periphery").size() != 14)
|
||||
throw editor::Error("invalid_stadium_scene");
|
||||
Json layers = Json::array(), areas = Json::array();
|
||||
const auto place = [&](const Json &binding, const Json &transform, const Json &owner, const char *role) {
|
||||
const auto asset = binding.at("asset").get<std::string>();
|
||||
const auto &meta = configuration.at("assets").at(asset);
|
||||
const double scale = transform.at("scale").get<double>();
|
||||
const double width = binding.at("width").get<double>() * binding.at("scale").get<double>() * scale;
|
||||
const double height = width * meta.at("height").get<double>() / meta.at("width").get<double>();
|
||||
layers.push_back({{"asset", asset}, {"owner", owner}, {"role", role}, {"z", transform.at("z")},
|
||||
{"x", transform.at("x").get<double>() + binding.at("offsetX").get<double>() * scale - binding.at("anchorX").get<double>() * width},
|
||||
{"y", transform.at("y").get<double>() + binding.at("offsetY").get<double>() * scale - binding.at("anchorY").get<double>() * height},
|
||||
{"width", width}, {"height", height}});
|
||||
};
|
||||
const auto &transport = overview.at("periphery")[0];
|
||||
const int traffic = (transport.at("building").get<bool>() ? transport.at("job") : transport).at("level").get<int>();
|
||||
const auto &background = profile.at("background");
|
||||
place(profile.at("backgroundOptions")[0].at("variants").at(size_t(traffic)),
|
||||
{{"x", background.at("offsetX")}, {"y", background.at("offsetY")}, {"scale", background.at("scale")}, {"z", 0}}, "background", "background");
|
||||
const auto capacity = overview.at("physical_capacity").get<int64_t>();
|
||||
size_t stadium_index = 0;
|
||||
for (const auto &threshold : profile.at("stadium").at("thresholds")) if (capacity >= threshold.get<int64_t>()) ++stadium_index;
|
||||
place(profile.at("stadium").at("variants").at(stadium_index), profile.at("stadium").at("transform"), "stadium", "stadium");
|
||||
for (size_t i = 0; i < 14; ++i) {
|
||||
const auto &object = profile.at("objects")[i], &row = overview.at("periphery")[i];
|
||||
if (object.at("id") != i) throw editor::Error("invalid_stadium_scene");
|
||||
const auto &transform = object.at("transform"), &area = object.at("hitArea"), &sprites = object.at("sprites");
|
||||
const bool pending = row.at("building").get<bool>(), building = pending && !future;
|
||||
const int level = (pending ? row.at("job") : row).at("level").get<int>();
|
||||
const double scale = transform.at("scale").get<double>();
|
||||
const double w = area.at("width").get<double>() * scale, h = area.at("height").get<double>() * scale;
|
||||
areas.push_back({{"index", i}, {"z", transform.at("z")},
|
||||
{"x", transform.at("x").get<double>() + area.at("offsetX").get<double>() * scale - w / 2},
|
||||
{"y", transform.at("y").get<double>() + area.at("offsetY").get<double>() * scale - h / 2}, {"width", w}, {"height", h}});
|
||||
if (i == 0 || (building && i >= 6)) {
|
||||
if (building) place(sprites.at("marker"), transform, i, "marker");
|
||||
} else if (level) {
|
||||
const size_t variant = i == 4 ? size_t(level - 1) : 0;
|
||||
place(sprites.at("variants").at(variant), transform, i, "building");
|
||||
if (building) place(sprites.at("overlays").at(variant), transform, i, "overlay");
|
||||
}
|
||||
}
|
||||
std::stable_sort(layers.begin(), layers.end(), [](const Json &a, const Json &b) { return a.at("z").get<double>() < b.at("z").get<double>(); });
|
||||
std::stable_sort(areas.begin(), areas.end(), [](const Json &a, const Json &b) { return a.at("z").get<double>() < b.at("z").get<double>(); });
|
||||
return {{"layers", layers}, {"areas", areas}, {"stadium_index", stadium_index}, {"traffic_level", traffic}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
Reference in new issue
Block a user