Modern UI contract: environment read and environment.commit

The surroundings of Diamond 3.6: three youth teams, co-trainer, doctor and
physio with their monthly budget level and cost, the youth teams' strength,
place and league. environment.commit sets a level 0-6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:44:25 +01:00
1 parent abbba65a81
commit f2c895ffb0
4 files changed
+55

No files matched your search

+18
View File
@@ -10094,6 +10094,24 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
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 == "environment.commit") {
// payload {itemId: "environment:<item>", level 0-6}: a monthly budget of the surroundings
// (no immediate booking, no random draw); the original's notice comes back as feedback
static constexpr const char* kItems[6] = {"youth_youngest", "youth_academy", "youth_oldest", "co_trainer", "doctor", "physio"};
const std::string id = ui_text(*payload, "itemId");
int item = -1;
for (int i = 0; i < 6; ++i) if (id == std::string("environment:") + kItems[i]) item = i;
const cli::Json* level = ui_field(*payload, "level");
if (item < 0 || !level || !level->integer() || *level->integer() < 0 || *level->integer() > 6)
return refuse("invalid_payload", "itemId und level (0 bis 6) nötig.");
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 Umfeld.");
std::string message;
const EnvironmentResult result = modern::set_environment(g_, manager, item, int(*level->integer()), &message);
if (result == EnvironmentResult::invalid) { restore(); return refuse("environment_refused", message.empty() ? "Nicht möglich." : ui::original_to_utf8(message)); }
if (result == EnvironmentResult::changed) revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"environment", "desktop"},
message.empty() ? "Umfeld geändert." : ui::original_to_utf8(message));
} else if (kind == "manager.resign.commit") {
// payload {confirmed: true}. A Modern feature (the original has no resigning): when the last
// human manager resigns the career ends (outcome career_ended, sessionState "ended"). With
+18
View File
@@ -14,6 +14,7 @@
#include "modern/content/world_package.hpp"
#include "modern/game/almanac.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/environment.hpp"
namespace bmh::modern {
@@ -368,6 +369,23 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
if (kind == "environment") {
// the club's surroundings (Diamond 3.6): three youth teams, co-trainer, doctor, physio, each
// with a monthly budget level 0-6 and its cost; the youth teams' strength, place and league
static constexpr const char* kItems[6] = {"youth_youngest", "youth_academy", "youth_oldest", "co_trainer", "doctor", "physio"};
if (team_of(g, c.manager) < 0 || team_of(g, c.manager) >= league_clubs())
return failure(request_id, "no_club", "Am Schreibtisch des Bundestrainers gibt es kein Umfeld.", c.state_revision);
const EnvironmentState e = environment_state(g, c.manager);
A items, youth;
for (int i = 0; i < 6; ++i)
items.push_back(O{{"id", std::string("environment:") + kItems[i]}, {"level", e.level[size_t(i)]}, {"maxLevel", 6},
{"monthly", ui_money(e.monthly[size_t(i)])}, {"stepCost", ui_money(kEnvironmentStep[size_t(i)])}});
for (size_t t = 0; t < 3; ++t)
youth.push_back(O{{"id", std::string("youth:") + kItems[t]}, {"strength", int(e.youth_strength[t])},
{"place", int(e.youth_position[t])}, {"league", int(e.youth_league[t])}});
return snapshot(request_id, std::move(m), O{{"kind", "environment"}, {"items", std::move(items)}, {"youth", std::move(youth)},
{"academyActive", environment_academy_active(g, c.manager)}});
}
if (kind == "toto" || kind == "sponsor") {
// the existing projections (ui-abfragen.md), amounts as Money
J p = query_projection(g, c.manager, O{{"kind", kind}});