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:
MichaelandClaude Fable 5.2 committed 2026-11-17 12:58:36 +01:00
1 parent 811edfa900
commit a2b9770d81
24 files changed
+1016 -7

No files matched your search

+2 -2
View File
@@ -5,7 +5,7 @@ namespace {
struct CareerScene { const char *action, *title, *text; double left, top, width, height; };
constexpr std::array<CareerScene, 3> career_scenes{{
{"career-resign", "Aufhören", "Dein Amt abgeben. Der Verein wird danach vom Computer geführt.", 0, 0, 49.3, 52.3},
{"career-search", "Vereinssuche", "Bei einem anderen Verein anheuern – noch nicht verfügbar.", 50.1, 0, 49.9, 52.3},
{"career-search", "Vereinssuche", "Bei einem anderen Verein anheuern: Wer interessiert ist und was er bietet.", 50.1, 0, 49.9, 52.3},
{"career-add", "Neuer Spieler", "Einen weiteren menschlichen Mitspieler einrichten: Name, Land, Liga und Verein.", 0, 53.2, 100, 46.8}}};
std::string career_hint_markup(const std::string &action) {
for (const auto &scene : career_scenes)
@@ -22,7 +22,7 @@ std::string App::render_career() {
page_title_ = ended ? "Karriere beendet" : "Manager";
page_hint_ = m.value("name", "") + " · " + c.at("current_team").value("name", "") + " · " + (c.at("role") == "national" ? "Nationalmannschaft" : "Vereinsmanager");
const auto off = [&](const std::string &action) {
if (action == "career-search") return true;
if (action == "career-search") return ended || !engine_mode_ || c.at("role") == "national";
if (action == "career-resign") return ended || (engine_mode_ && engine_manager_value_.at("can_resign") != true);
return ended || (engine_mode_ && engine_manager_value_.at("can_join") != true);
};
+127
View File
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-3.0-only
// The annual general meeting and the clubs interested in a manager
// (docs/new_engine/hauptversammlung.md), as notes over the notebook.
namespace {
// One group of members: its name, a bar and its approval in percent.
std::string assembly_group(const char *name, int value) {
value = std::clamp(value, 0, 100);
return "<div class=\"as-row\"><span class=\"as-name\">" + esc(name) + "</span><div class=\"as-track\"><div class=\"as-fill" + std::string(value < 50 ? " low" : "") + "\" style=\"width:" + std::to_string(value) +
"%;\"></div></div><span class=\"as-value\">" + std::to_string(value) + " %</span></div>";
}
} // namespace
// The kickoff at the end of a season stopped for the meeting: first its result, then - for a
// manager who was voted out - the clubs he can go to.
void App::engine_assembly_ask(const Json &args) {
engine_assembly_ = args;
const Json vote = args.value("vote", Json::object());
const bool confirmed = vote.value("confirmed", true), leave = !confirmed && args.value("dismissals", true);
const Json sent = engine_advance_payload_.value("assembly", Json::object());
if (sent.is_object() && sent.value("seen", false)) {
if (leave) engine_assembly_clubs(true);
return;
}
const int yes = std::clamp(vote.value("yes", 0), 0, 100);
const std::string verdict = confirmed ? "Die Mitglieder bestätigen dich im Amt."
: leave ? "Die Mitglieder haben dich abgewählt. Du musst den Verein verlassen."
: "Die Mehrheit stimmt gegen dich. Diesmal bleibt das ohne Folgen.";
const std::string club = args.value("club", Json::object()).value("name", std::string());
confirmation("Zum Saisonende stimmen die Mitglieder" + (club.empty() ? std::string() : " von " + club) + " über ihren Manager ab.", [this, leave] {
engine_advance_payload_["assembly"]["seen"] = true;
if (leave) engine_assembly_clubs(true);
else engine_kickoff();
});
popup_title_ = "Jahreshauptversammlung";
popup_accept_ = leave ? "Interessierte Vereine" : "Weiter";
popup_close_ = "Zum Schreibtisch";
// the dial: red on the left, green on the right, the line of the vote in the middle
std::string dial = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 112'>";
constexpr int parts = 48;
for (int i = 0; i < parts; ++i) {
const double from = 3.14159265358979 * (1.0 - double(i) / parts), to = 3.14159265358979 * (1.0 - double(i + 1) / parts + 0.002);
const double at = (i + 0.5) / parts;
const std::array<int, 3> red{196, 62, 46}, amber{226, 170, 52}, green{84, 140, 66};
const auto &lo = at < 0.5 ? red : amber, &hi = at < 0.5 ? amber : green;
const double k = std::pow(at < 0.5 ? at * 2 : (at - 0.5) * 2, at < 0.5 ? 2.2 : 0.45); // the colour turns close to the middle
char colour[8];
std::snprintf(colour, sizeof colour, "#%02x%02x%02x", int(lo[0] + (hi[0] - lo[0]) * k), int(lo[1] + (hi[1] - lo[1]) * k), int(lo[2] + (hi[2] - lo[2]) * k));
dial += "<path d='M" + scalar(100 + 80 * std::cos(from)) + " " + scalar(100 - 80 * std::sin(from)) + " A80 80 0 0 1 " + scalar(100 + 80 * std::cos(to)) + " " + scalar(100 - 80 * std::sin(to)) +
"' fill='none' stroke='" + colour + "' stroke-width='22'/>";
}
const std::string ink = theme_ != "silver" && theme_ != "matchday" ? "#f0ece2" : "#2a211a";
dial += "<path d='M100 6v28' stroke='" + ink + "' stroke-width='2.4'/><circle cx='100' cy='100' r='9' fill='" + ink + "'/></svg>";
engine_assembly_target_ = yes;
engine_assembly_started_ = std::max<uint64_t>(SDL_GetTicks64(), 1);
popup_body_ = "<div class=\"as-vote\"><div class=\"as-gauge\">" + picture(renderer_.diagram("assembly-dial-" + theme_, dial, 1280), 640, 358) +
"<div id=\"assembly-needle\" class=\"as-needle\"></div></div><div class=\"as-ends\"><span>Abwahl</span><span>Bestätigung</span></div>" +
"<div id=\"assembly-result\" style=\"visibility:hidden;\">" + assembly_group("Sportliche Leitung", vote.value("sport", 0)) + assembly_group("Kassenprüfer", vote.value("finance", 0)) +
assembly_group("Fans", vote.value("supporters", 0)) + "<div class=\"as-result" + std::string(confirmed ? "" : " low") + "\"><strong>" + std::to_string(yes) + " % Ja</strong><span>" +
std::to_string(100 - yes) + " % Nein</span></div><p class=\"as-verdict\">" + esc(verdict) + "</p></div></div>";
}
// The needle swings while the votes are counted and comes to rest on the result. It moves from
// the middle towards the result within a second and a half; the swing around it starts at a
// good fifth of the dial and dies away, so a clear result never looks like its opposite.
void App::engine_assembly_tick() {
if (!engine_assembly_started_) return;
if (popup_.empty()) { engine_assembly_started_ = 0; return; }
auto *needle = element("assembly-needle");
if (!needle) return; // the note is drawn with this frame
constexpr double duration = 7.5;
const double t = double(SDL_GetTicks64() - engine_assembly_started_) / 1000.0;
const double target = std::clamp(engine_assembly_target_, 0, 100);
double shown = target;
if (t < duration) {
const double x = std::min(t / 1.5, 1.0), approach = x * x * (3 - 2 * x);
const double swing = 22.0 * std::pow(1.0 - t / duration, 1.4);
const double phase = double(engine_assembly_started_ % 6283) / 1000.0;
const double wave = 0.55 * std::sin(t * 4.3 + phase) + 0.3 * std::sin(t * 7.9 + phase * 2.1) + 0.25 * std::sin(t * 2.1 + phase * 0.7);
shown = std::clamp(50 + (target - 50) * approach + swing * wave, 0.0, 100.0);
}
needle->SetProperty("transform", "rotate(" + scalar((shown - 50) * 1.8) + "deg)");
if (t >= duration) {
if (auto *result = element("assembly-result")) result->SetProperty("visibility", "visible");
engine_assembly_started_ = 0;
}
}
// The clubs that want the manager: crest, league, the strength of their eleven beside his own,
// and the cash they give him to start with.
void App::engine_assembly_clubs(bool forced) {
engine_assembly_forced_ = forced;
const Json offers = engine_assembly_.value("offers", Json::array());
const Json own = engine_assembly_.value("club", Json::object());
std::string body = "<div class=\"po-offers\">";
for (const auto &offer : offers) {
const std::string id = offer.value("teamId", std::string());
const auto *club = world_->find("clubs", id);
const std::string name = club ? world_->name(*club) : offer.value("name", std::string("Ein Verein"));
body += "<div class=\"po-offer\"><span class=\"po-crest\">" + (club ? crest(club, 72) : std::string()) + "</span><div class=\"po-text\"><strong>" + esc(name) + "</strong><span>" + esc(offer.value("league", std::string())) +
(offer.contains("position") && offer.at("position").is_number_integer() ? " · Platz " + std::to_string(offer.at("position").get<int>()) : std::string()) + " · Stärke " + std::to_string(offer.value("strength", 0)) +
" · Startkapital " + esc(offer.contains("cash") ? engine_price(offer.at("cash")) : std::string("—")) + "</span></div>" +
pg_button("assembly-club", "Übernehmen", "primary", "id=\"assembly-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\"") + "</div>";
}
body += "</div>";
const std::string strength = own.contains("strength") ? " Deine Elf hat die Stärke " + std::to_string(own.value("strength", 0)) + "." : std::string();
message(offers.empty() ? "Zurzeit interessiert sich kein Verein für dich."
: forced ? "Diese Vereine wollen dich verpflichten. Einen davon musst du übernehmen, bevor die neue Saison beginnt." + strength
: "Diese Vereine wollen dich verpflichten. Die Liste wechselt alle zwei Wochen." + strength);
popup_title_ = "Interessierte Vereine";
popup_close_ = forced ? "Zum Schreibtisch" : "Abbrechen";
popup_body_ = body;
}
// A club of the list was chosen: asked once more, because nothing of the old club comes along.
void App::engine_assembly_choose(const std::string &team) {
const auto *club = world_->find("clubs", team);
const std::string name = club ? world_->name(*club) : std::string("diesem Verein");
const bool forced = engine_assembly_forced_;
confirmation("Wirklich zu " + name + " wechseln? Dein Konto, deine Aktien, Fonds und Kredite bleiben zurück; beim neuen Verein beginnst du mit dessen Startkapital und einem neuen Vertragswerk.", [this, team, forced] {
if (forced) {
engine_advance_payload_["assembly"] = {{"seen", true}, {"teamId", team}};
engine_kickoff();
return;
}
try {
engine_finance_submit(engine_club_change_command(engine_data_, team, editor::new_id("request:ui-")));
} catch (const std::exception &e) { message(e.what()); }
});
popup_title_ = "Vereinswechsel";
popup_accept_ = "Wechseln";
}
+2
View File
@@ -32,6 +32,8 @@ Json engine_ticket_command(const Json &bundle, int euros, const std::string &req
Json engine_environment_projection(const Json &bundle);
Json engine_environment_command(const Json &bundle, const std::string &item, int level, const std::string &request_id);
// The manager leaves for one of the clubs interested in him (read "assembly").
Json engine_club_change_command(const Json &bundle, const std::string &team, const std::string &request_id);
Json engine_advertising_projection(const Json &bundle);
Json engine_advertising_quote(const Json &bundle, int slot, int choice);
Json engine_advertising_command(const Json &bundle, const std::string &offer, const std::string &request_id);
+17
View File
@@ -14,6 +14,8 @@ void App::engine_kickoff() {
// kickoff, never after a match the manager has watched and steered.
// this interface answers the bids for listed players: the field says so even while it is empty
if (!engine_advance_payload_.contains("transferOffers")) engine_advance_payload_["transferOffers"] = Json::object();
// ... and shows the annual general meeting at the end of a season
if (!engine_advance_payload_.contains("assembly")) engine_advance_payload_["assembly"] = Json::object();
Json rehearsal = engine_advance_payload_, live = engine_advance_payload_;
rehearsal["dryRun"] = true; live["live"] = true;
const auto probe = engine_advance_command(engine_data_, editor::new_id("request:ui-"), rehearsal);
@@ -163,6 +165,8 @@ void App::engine_accept(EngineReply result) {
engine_expiry_ask(args);
else if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "transfer_offers")
engine_offers_ask(args);
else if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "assembly")
engine_assembly_ask(args);
}
if (engine_response_.contains("seasonOpening")) {
// a new season began: its draw is shown once the ticker is closed
@@ -213,6 +217,13 @@ void App::engine_poll() {
}
refresh(); return;
}
if (result.response.value("messageType", "") == "assembly_read") {
// the clubs interested in a manager who thinks of leaving
const auto &read = result.response.at("read");
if (read.value("messageType", "") == "error" || !read.contains("data") || !read.at("data").value("available", false)) engine_notice_ = "Hier gibt es keinen Vereinswechsel.";
else { engine_assembly_ = read.at("data"); engine_assembly_clubs(false); }
refresh(); return;
}
if (result.response.value("messageType", "") == "poach_squad") {
// the squad of the club a manager wants to poach from
const auto &read = result.response.at("read");
@@ -466,6 +477,12 @@ void App::engine_event(Rml::Event &event) {
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
if (!popup_.empty()) {
if(action=="balance-discard"){engine_balance_action(action,node);return;}
if (action == "assembly-club") {
const std::string team = id;
popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true;
engine_assembly_choose(team);
return;
}
if (action == "engine-offer-accept") {
const auto player = engine_offer_player_;
const int index = node->GetAttribute<int>("data-id", -1);
+3
View File
@@ -513,6 +513,9 @@ Json engine_environment_projection(const Json &bundle) {
}
return {{"ok", true}, {"rows", rows}};
}
Json engine_club_change_command(const Json &bundle, const std::string &team, const std::string &request_id) {
return sports_command(bundle, "manager.clubChange", {{"teamId", team}, {"confirmed", true}}, request_id);
}
Json engine_environment_command(const Json &bundle, const std::string &id, int level, const std::string &request_id) {
const auto view = engine_environment_projection(bundle);
const Json *item = nullptr;
+5
View File
@@ -50,6 +50,11 @@ void App::engine_manager_main() {
bool App::engine_manager_action(const std::string &action,Rml::Element *) {
if(engine_busy_)return true;
if(action=="career-game-end"){engine_manager_main();return true;}
if(action=="career-search"&&engine_fresh_&&!engine_busy_&&engine_link_) {
auto link=engine_link_;
engine_start("Interessierte Vereine …",[link]{auto response=link->read({{"kind","assembly"}});return EngineReply{link,link->snapshot(),{{"messageType","assembly_read"},{"read",response}},nullptr};});
return true;
}
if(action=="career-resign-cancel"){career_resign_open_=false;focus_after_render_="career-resign";refresh();return true;}
if(action=="career-resign"&&engine_fresh_&&engine_manager_value_.at("can_resign")==true){engine_manager_context_=engine_data_.at("desktop").at("meta");career_resign_open_=true;career_resign_portrait_=engine_manager_value_.at("active").at("portrait");focus_after_render_="career-resign-owner";refresh();return true;}
if(action=="career-resign-confirm") {
+11
View File
@@ -46,6 +46,17 @@
std::string engine_expiry_player_;
std::string engine_offer_player_; // the listed player whose bids are being decided
void engine_offers_ask(const Json &args);
// The annual general meeting: what the engine reported (vote, interested clubs) and whether
// the list of clubs is shown to a manager who was voted out.
Json engine_assembly_;
bool engine_assembly_forced_ = false;
void engine_assembly_ask(const Json &args);
void engine_assembly_clubs(bool forced);
void engine_assembly_choose(const std::string &team);
// The needle of the meeting: when it started to swing (0 = at rest) and where it comes to rest.
uint64_t engine_assembly_started_ = 0;
int engine_assembly_target_ = 50;
void engine_assembly_tick();
void engine_kickoff();
// A kickoff of the engine that is played minute by minute while the ticker is open.
bool engine_live_running_ = false, engine_live_busy_ = false, engine_live_at_end_ = false;
+7 -2
View File
@@ -565,6 +565,7 @@ class App final : public Rml::EventListener {
bool rendered_confirm_ = false;
std::string popup_input_, popup_extra_, popup_accept_ = "Bestätigen";
std::string popup_body_; // markup under the question, for a question that lists things
std::string popup_title_, popup_close_; // another heading and another word on the closing button
bool popup_has_input_ = false, quit_after_save_ = false;
std::function<void(const std::string &)> text_accept_;
bool context_open_ = false, context_dirty_ = false;
@@ -744,6 +745,8 @@ class App final : public Rml::EventListener {
popup_input_.clear();
popup_extra_.clear();
popup_body_.clear();
popup_title_.clear();
popup_close_.clear();
popup_accept_ = "Bestätigen";
text_accept_ = {};
rendered_popup_.clear();
@@ -1323,7 +1326,7 @@ class App final : public Rml::EventListener {
return;
element("popup")->SetInnerRML(
"<div class=\"fill popup-backdrop\"></div><div "
"class=\"popup-box\"><h2>" + std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis") + "</h2><p>" +
"class=\"popup-box\"><h2>" + (!popup_title_.empty() ? esc(popup_title_) : std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis")) + "</h2><p>" +
esc(popup_) + "</p>" + popup_body_ +
(popup_has_input_
? "<input id=\"popup-text\" value=\"" + esc(popup_input_) +
@@ -1331,7 +1334,7 @@ class App final : public Rml::EventListener {
: "") +
"<footer>" +
btn("popup-close",
confirm_ || text_accept_ ? "Abbrechen" : "Verstanden") +
!popup_close_.empty() ? popup_close_ : confirm_ || text_accept_ ? "Abbrechen" : "Verstanden") +
popup_extra_ +
((confirm_ || text_accept_)
? btn("popup-confirm", popup_accept_, "primary")
@@ -1373,6 +1376,7 @@ class App final : public Rml::EventListener {
engine_create_poll();
engine_files_poll();
stadium_flight_tick();
engine_assembly_tick();
if (engine_mode_) { engine_frame(); return; }
front_poll();
flush_selects();
@@ -1847,6 +1851,7 @@ public:
#include "modern/ui/engine_statistics.inc"
#include "modern/ui/engine_toto.inc"
#include "modern/ui/engine_stadium.inc"
#include "modern/ui/engine_assembly.inc"
#include "modern/ui/engine_transfer.inc"
#include "modern/ui/engine_achievements.inc"
#include "modern/ui/engine_news.inc"