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

+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";
}