Annual general meeting and change of club
At the end of a season three groups of members vote on a human manager. Below half of the votes he has to take over one of up to seven interested clubs; the same list lets a manager leave on his own from the manager page. The meeting is shown as a needle that swings between red and green and comes to rest on the result. Engine: assembly_vote, club_offers, change_club; read "assembly", command manager.clubChange, field assembly of session.advance; saved in state/modern.json. Dismissals are always on until the options offer them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
811edfa900
commit
a2b9770d81
24 files changed
+1016
-7
No files matched your search
@@ -11,6 +11,7 @@
|
||||
#include "ui/achievements.hpp"
|
||||
#include "ui/indoor_standings.hpp"
|
||||
#include "modern/content/world_save.hpp"
|
||||
#include "modern/game/assembly.hpp"
|
||||
#include "modern/game/balance_plan.hpp"
|
||||
#include "modern/game/bank_credit.hpp"
|
||||
#include "modern/game/career.hpp"
|
||||
@@ -8921,6 +8922,40 @@ cli::Json ModernSession::read_statistics_screen(const cli::Json& request) const
|
||||
|
||||
#include "modern/app/ui_managers.inc"
|
||||
|
||||
namespace {
|
||||
// The annual general meeting and the interested clubs for the interface (read "assembly", and the
|
||||
// args of the advance's question): the vote of the three groups, whether it is due at this desk,
|
||||
// and the clubs with the cash they offer and the strength of their eleven.
|
||||
cli::Json assembly_data(const modern::ModernState& g, int manager, bool season_end) {
|
||||
using O = cli::Json::Object;
|
||||
using A = cli::Json::Array;
|
||||
const int team = manager >= 0 && size_t(manager) < g.manager_teams.size() ? g.manager_teams[size_t(manager)] : -1;
|
||||
if (team < 0 || team >= league_clubs()) return O{{"kind", "assembly"}, {"available", false}};
|
||||
const auto vote = modern::assembly_vote(g, manager);
|
||||
const int voted = size_t(manager) < g.assembly.size() ? g.assembly[size_t(manager)].voted_season : -1;
|
||||
const uint16_t eleven = avg::CONDITION | avg::TECHNIQUE | avg::FORM | avg::MORALE | avg::ALL_POSITIONS | avg::LINEUP_ONLY;
|
||||
const auto club = [&](int t) {
|
||||
const int league = team_league(t);
|
||||
return O{{"teamId", modern::ui_team_id(g, t)},
|
||||
{"name", size_t(t) < g.world_club_name.size() ? g.world_club_name[size_t(t)] : std::string()},
|
||||
{"league", league >= 0 && size_t(league) < g.world_league_name.size() ? g.world_league_name[size_t(league)] : std::string()},
|
||||
{"leagueIndex", league}, {"strength", team_average(g, t, eleven).value},
|
||||
{"position", modern::table_position(g, t) < 0 ? cli::Json(nullptr) : cli::Json(modern::table_position(g, t) + 1)}};
|
||||
};
|
||||
A offers;
|
||||
for (const auto& offer : modern::club_offers(g, manager)) {
|
||||
O row = club(offer.team);
|
||||
row["cash"] = modern::ui_money(int64_t(offer.cash));
|
||||
offers.push_back(std::move(row));
|
||||
}
|
||||
return O{{"kind", "assembly"}, {"available", true}, {"due", season_end && voted != g.season},
|
||||
{"dismissals", g.dismissals}, {"season", g.season},
|
||||
{"vote", O{{"sport", vote.sport}, {"finance", vote.finance}, {"supporters", vote.supporters},
|
||||
{"yes", vote.yes}, {"confirmed", vote.confirmed}}},
|
||||
{"club", club(team)}, {"offers", std::move(offers)}};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) const {
|
||||
using O = cli::Json::Object;
|
||||
using A = cli::Json::Array;
|
||||
@@ -9055,7 +9090,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
}
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "balance" && kind != "achievements" && kind != "statistics" && kind != "analysis" && kind != "opening" && kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" && kind != "assembly" &&
|
||||
!(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))
|
||||
@@ -9480,6 +9515,15 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
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 == "assembly") {
|
||||
// the annual general meeting and the clubs that want the manager (hauptversammlung.md). Pure.
|
||||
try {
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
assembly_data(g_, manager, turn_driver_.stage == TurnDriver::Stage::SeasonEndDesk));
|
||||
} catch (const std::exception&) {
|
||||
return modern::ui_error(request_id, "assembly_unavailable", "Die Hauptversammlung ist hier nicht verfügbar.", revision, false);
|
||||
}
|
||||
}
|
||||
if (kind == "credit") {
|
||||
// the credit dialog (bank or another human manager as lender): the saved loan, the draft after
|
||||
// the request's edits [{field, value}] with labels, bounds per field, fees and refund. Pure:
|
||||
@@ -9818,6 +9862,64 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
};
|
||||
cli::Json answer;
|
||||
std::string error;
|
||||
// A manager takes over one of the clubs interested in him (manager.clubChange, and the advance
|
||||
// of a manager the annual general meeting voted out). False with `error`, and nothing changed,
|
||||
// when the club is not on his list.
|
||||
const auto move_manager = [&](const std::string& team_id) -> bool {
|
||||
std::vector<modern::ClubOffer> offers;
|
||||
try { offers = modern::club_offers(g_, manager); } catch (const std::exception&) { offers.clear(); }
|
||||
const auto offer = std::find_if(offers.begin(), offers.end(), [&](const modern::ClubOffer& o) { return modern::ui_team_id(g_, o.team) == team_id; });
|
||||
if (offer == offers.end()) { error = "Dieser Verein gehört nicht zu den interessierten Vereinen."; return false; }
|
||||
MinuteReport report;
|
||||
if (!modern::change_club(g_, exe_, manager, offer->team, offer->cash, rand_, report)) {
|
||||
error = report.reason.empty() ? "Vereinswechsel nicht möglich." : report.reason;
|
||||
return false;
|
||||
}
|
||||
modern::assembly_baseline(g_, manager);
|
||||
int master = -1;
|
||||
for (size_t m = 0; m * 2 + 1 < db_.raw_club_name_offsets.size() && master < 0; ++m)
|
||||
if (uint16_t(db_.raw_club_name_offsets[m * 2] | db_.raw_club_name_offsets[m * 2 + 1] << 8) == g_.club_ids.at(size_t(offer->team))) master = int(m);
|
||||
for (auto& entry : managers_)
|
||||
if (entry.slot == manager) entry.runtime_club = offer->team, entry.master_club = master >= 0 ? master : entry.master_club;
|
||||
return true;
|
||||
};
|
||||
// The annual general meeting (hauptversammlung.md). Whoever has no base yet gets it at his
|
||||
// first kickoff. At the season's last desk the members vote; only an interface that sends
|
||||
// `assembly` is asked: {} first, then {seen: true}, and for a manager who is voted out
|
||||
// {seen: true, teamId} with one of the interested clubs. Without the field the vote is held
|
||||
// unheard and nobody has to leave.
|
||||
const auto assembly_step = [&]() -> std::optional<cli::Json> {
|
||||
const auto managers_before = managers_;
|
||||
if (const int team = g_.manager_teams[size_t(manager)]; team >= 0 && team < league_clubs()) {
|
||||
if (size_t(manager) >= g_.assembly.size() || g_.assembly[size_t(manager)].place < 0) modern::assembly_baseline(g_, manager);
|
||||
if (turn_driver_.stage == TurnDriver::Stage::SeasonEndDesk && g_.assembly[size_t(manager)].voted_season != g_.season) {
|
||||
const auto vote = modern::assembly_vote(g_, manager);
|
||||
const bool must_leave = !vote.confirmed && g_.dismissals;
|
||||
const cli::Json* asked = ui_field(*payload, "assembly");
|
||||
const auto ask = [&](const char* text) {
|
||||
cli::Json data = assembly_data(g_, manager, true);
|
||||
restore(); managers_ = managers_before;
|
||||
cli::Json pending = refuse("decision_pending", text);
|
||||
auto& message = std::get<cli::Json::Object>(std::get<cli::Json::Object>(pending.value)["message"].value);
|
||||
auto args = std::get<cli::Json::Object>(data.value);
|
||||
args["decision"] = "assembly";
|
||||
message["args"] = std::move(args);
|
||||
return pending;
|
||||
};
|
||||
std::string new_club;
|
||||
if (asked && asked->object()) {
|
||||
const cli::Json* seen = ui_field(*asked, "seen");
|
||||
if (!seen || !std::holds_alternative<bool>(seen->value) || !std::get<bool>(seen->value))
|
||||
return ask("Die Jahreshauptversammlung stimmt über den Manager ab.");
|
||||
if (must_leave && (new_club = ui_text(*asked, "teamId")).empty())
|
||||
return ask("Die Mitglieder haben den Manager abgewählt: Er muss den Verein wechseln.");
|
||||
}
|
||||
modern::assembly_remember(g_, manager, vote);
|
||||
if (!new_club.empty() && !move_manager(new_club)) { restore(); managers_ = managers_before; return refuse("club_change_refused", error); }
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
if (kind == "camp.book") {
|
||||
// payload {campId, focus?: {condition, technique, play}}: focus first (recovery follows), then the booking
|
||||
const std::string camp = ui_text(*payload, "campId");
|
||||
@@ -9967,6 +10069,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
} else if (kind == "session.advance" && ui_field(*payload, "live") && std::holds_alternative<bool>(ui_field(*payload, "live")->value) &&
|
||||
std::get<bool>(ui_field(*payload, "live")->value)) {
|
||||
// the kickoff on its own thread, stopping after the first match minute of a human match
|
||||
if (auto stop = assembly_step()) return *stop;
|
||||
auto run = std::make_shared<LiveRun>();
|
||||
if (const cli::Json* e = ui_field(*payload, "contractExpiry"); e && e->object())
|
||||
for (const auto& [id, value] : *e->object()) {
|
||||
@@ -10126,6 +10229,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
restore();
|
||||
turn_driver_ = saved_driver, managers_ = saved_managers, source_desk_callargs_ = saved_desk_callargs;
|
||||
};
|
||||
if (auto stop = assembly_step()) return *stop;
|
||||
auto previous_hook = g_.contract_screen;
|
||||
const bool previous_installed = contract_expiry_presenter_installed_;
|
||||
set_contract_expiry_presenter([&](modern::ModernState& state, WatcomRandom& random, int m, int row) -> int {
|
||||
@@ -10872,6 +10976,26 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
} else if (kind == "manager.join.commit") {
|
||||
answer = ui_join_managers(*payload,request_id,revision);
|
||||
if (ui_text(answer,"messageType")=="error") return answer;
|
||||
} else if (kind == "manager.clubChange") {
|
||||
// payload {teamId, confirmed: true}. A Modern rule (hauptversammlung.md): the manager leaves
|
||||
// for one of the clubs of the read "assembly" and starts there with the cash it offers.
|
||||
const cli::Json* confirmed = ui_field(*payload, "confirmed");
|
||||
if (!confirmed || !std::holds_alternative<bool>(confirmed->value) || !std::get<bool>(confirmed->value))
|
||||
return refuse("confirmation_required", "Der Vereinswechsel muss bestätigt werden (confirmed: true).");
|
||||
if (career_complete()) return refuse("career_ended", "Die Karriere ist beendet.");
|
||||
if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ || top_scorers_owner_ ||
|
||||
top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ || other_games_dispatch_active_ || transfer_offer_editor_ ||
|
||||
(turn_driver_.stage != TurnDriver::Stage::Empty && turn_driver_.stage != TurnDriver::Stage::MatchdayDesks &&
|
||||
turn_driver_.stage != TurnDriver::Stage::SeasonEndDesk))
|
||||
return refuse("not_at_desk", "Der Verein lässt sich nur am Schreibtisch wechseln, wenn nichts anderes offen ist.");
|
||||
if (const int team = g_.manager_teams[size_t(manager)]; team < 0 || team >= league_clubs())
|
||||
return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es keinen Vereinswechsel.");
|
||||
if (!move_manager(ui_text(*payload, "teamId"))) { restore(); return refuse("club_change_refused", error); }
|
||||
modern::ensure_ui_identities(g_);
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision,
|
||||
{"session", "manager_menu", "desktop", "squad", "lineup", "tactics", "training", "camps", "bank",
|
||||
"stadium", "advertising", "contracts", "statistics"}, "Vereinswechsel vollzogen.");
|
||||
} 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
|
||||
|
||||
Reference in new issue
Block a user