// SPDX-License-Identifier: GPL-3.0-only namespace { // Where the fourteen boards stand around the pitch, in units of the page: five along the far // side, two at each end, five along the near side, numbered clockwise from the upper left. struct AdBoard { double x, y, w, h; int turn; }; // turn: 0 flat, 1 right end, -1 left end constexpr double ad_ground_w = 960, ad_ground_h = 668, ad_board_deep = 66; AdBoard ad_board(int index) { constexpr double first = ad_board_deep + 14, gap = 6, long_w = (ad_ground_w - 2 * first - 4 * gap) / 5, step = long_w + gap; constexpr double end_top = ad_board_deep + 26, end_gap = 20, tall = (ad_ground_h - 2 * end_top - end_gap) / 2; if (index < 5) return {first + index * step, 0, long_w, ad_board_deep, 0}; if (index < 7) return {ad_ground_w - ad_board_deep, end_top + (index - 5) * (tall + end_gap), ad_board_deep, tall, 1}; if (index < 12) return {first + (11 - index) * step, ad_ground_h - ad_board_deep, long_w, ad_board_deep, 0}; return {0, end_top + (13 - index) * (tall + end_gap), ad_board_deep, tall, -1}; } // The ground seen from above: the apron with its track, the mown pitch with all its lines, // goals, benches and corner flags, and around it the frames of the fourteen boards: lit where // a sponsor has signed, an empty frame where the place is free. std::string ad_ground_svg(const std::array &taken, int chosen) { const auto n = [](double v) { return scalar(std::round(v * 10) / 10); }; constexpr double W = ad_ground_w, H = ad_ground_h, D = ad_board_deep; const auto frame = [&](double inset, double radius, const std::string &more) { return ""; }; std::string svg = ""; // apron, running track with its lanes, the grass around the pitch svg += frame(0, 46, "fill=\"#d9c9a4\"") + frame(8, 40, "fill=\"#c98a5e\""); for (int lane = 0; lane < 4; ++lane) svg += frame(12.5 + lane * 4.6, 36 - lane * 3.4, "fill=\"none\" stroke=\"#f6e3d2\" stroke-opacity=\".55\" stroke-width=\".9\""); svg += frame(31, 22, "fill=\"#8fb271\""); // the pitch: thirteen mown stripes constexpr double px = D + 48, py = D + 46, pw = W - 2 * px, ph = H - 2 * py; constexpr int stripes = 13; for (int stripe = 0; stripe < stripes; ++stripe) svg += ""; // lengths on the pitch in metres: it is 105 long const double m = pw / 105, cx = px + pw / 2, cy = py + ph / 2; svg += ""; for (const int side : {-1, 1}) { const double edge = side < 0 ? px : px + pw; // penalty area, goal area, the arc at the area, the corner arcs svg += ""; svg += ""; svg += ""; } svg += ""; for (const int side : {-1, 1}) { const double edge = side < 0 ? px : px + pw, back = edge + side * 14, half = 3.66 * m + 4; // the goal with its net, and the flags in the corners svg += ""; for (int k = 1; k < 6; ++k) svg += ""; svg += ""; for (const double flag_y : {py, py + ph}) svg += ""; } // the two benches on the far side with their glass roofs, and the coaches' zones before them for (const double bench : {cx - 118, cx + 46}) { svg += ""; svg += ""; for (int seat = 0; seat < 8; ++seat) svg += ""; } // the players' tunnel between the benches svg += ""; // the boards: a shadow towards the pitch, two feet, the frame for (int i = 0; i < 14; ++i) { const auto b = ad_board(i); const bool on = taken[size_t(i)], here = i == chosen; const double fx = b.x + 4, fy = b.y + 4, fw = b.w - 8, fh = b.h - 8; svg += ""; if (b.turn == 0) for (const double foot : {fx + 16, fx + fw - 16}) svg += ""; else for (const double foot : {fy + 18, fy + fh - 18}) svg += " 0 ? fx - 5 : fx + fw - 2) + "\" y=\"" + n(foot - 2) + "\" width=\"7\" height=\"4\" fill=\"#6f6a60\"/>"; svg += ""; // a sponsor's board carries a stripe in the accent along its outer edge if (on) svg += b.turn == 0 ? "" : " 0 ? fx + fw - 6 : fx + 3) + "\" y=\"" + n(fy + 9) + "\" width=\"3\" height=\"" + n(fh - 18) + "\" rx=\"1.5\" fill=\"#c8733c\"/>"; } return svg + ""; } // A sponsor's mark where there is no logo: its initials on a rounded square of a colour of its own. std::string ad_mark(const std::string &name, double size) { static constexpr std::array colours{"#8c491a", "#56633f", "#2b6f8f", "#a8452f", "#6b5a48", "#3d6f5a"}; unsigned sum = 0; std::string initials; bool start = true; for (size_t i = 0; i < name.size(); ++i) { const auto c = static_cast(name[i]); sum += c; if (c == ' ' || c == '-' || c == '.') { start = true; continue; } if (start && initials.size() < 2 && c < 128 && std::isalnum(c)) initials += char(std::toupper(c)); start = false; } if (initials.empty()) initials = "·"; return "" + esc(initials) + ""; } } // namespace // Verein > Werbung: the ground with its fourteen boards on the left, the five pictures for // shirt, television and the three budgets on the right. The pointer on a picture shows what // stands there today; a click opens the offers as a note, or the number pad of a budget. std::string App::render_advertising() { const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap(); const auto view = engine_mode_ ? engine_advertising_projection(engine_data_) : demo_advertising_view(snapshot.state, *world_); const auto ad_cash = [&](int64_t value) { return engine_mode_ ? money(value, {{"code", "EUR"}, {"minor_units", 2}}) : cash(value); }; if (!view.value("ok", false)) return {}; const auto &slots = view.at("slots"); const auto taken_at = [&](int i) { return slots[size_t(i)].at("active") == true; }; std::array taken{}; int signed_boards = 0; for (int i = 0; i < 14; ++i) if ((taken[size_t(i)] = taken_at(i))) ++signed_boards; page_hint_ = std::to_string(signed_boards) + " von 14 Banden vergeben"; // what a contract says today const auto terms = [&](const Json &slot) { return std::to_string(slot.value("months", 0)) + (slot.value("months", 0) == 1 ? " Monat" : " Monate") + " · " + ad_cash(slot.value("amount", int64_t(0))) + " / Monat"; }; // The menu has two pages: the contracts with sponsors, and what the club invests itself. const bool investing = advertising_page_ == "investments"; page_title_ = investing ? "Investitionen" : "Werbung"; const auto forecast = [&] { std::string row = pg_kicker("Vereinsprognose / Monat") + "
"; for (const auto &[label, key] : std::array, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}}) { const auto value = view.at(key).get(); row += "
" + std::string(label) + "= 0 ? " ad-plus" : " ad-minus") : "") + "\">" + esc((std::string(key) == "balance" && value > 0 ? "+ " : "") + ad_cash(value)) + "
"; } return row + "
"; }; // A picture one can click: the pointer shows what stands there today. `shape` is "", "wide" // or "big"; `amount` stands beside the title where the picture is large enough for it. const auto tile = [&](const std::string &action, const std::string &id, const std::string &attrs, const std::string &art, const std::string &title, const std::string &kicker, const std::string &value, const std::string &detail, bool selected, const std::string &shape = std::string(), const std::string &amount = std::string()) { const double w = shape == "big" ? 921 : shape == "four" ? 612 : 520, h = shape == "big" ? 690 : 459; return btn(action, "" + img(art, w, h, false, true, shape.empty() ? 1100 : 1600) + "" + esc(pg_upper(kicker)) + "" + esc(value) + "" + esc(detail) + "" + esc(title) + "" + (amount.empty() ? std::string() : "" + esc(amount) + "") + "", std::string("ad-tile") + (shape.empty() ? "" : " " + shape) + (selected ? " selected" : ""), "id=\"" + id + "\" " + attrs + " aria-label=\"" + esc(title + ": " + value + (detail.empty() ? "" : ", " + detail)) + "\""); }; // what the game does not know yet is shown, and says so const std::string soon = "disabled=\"disabled\" aria-disabled=\"true\""; std::string delivery; if (const int weeks = view.at("spending")[0].value("delivery_weeks", 0); weeks > 0) delivery = "Fanartikel: Die Lieferung läuft noch " + std::to_string(weeks) + (weeks == 1 ? " Woche." : " Wochen."); std::string out = "
"; if (investing) { page_hint_ = "Wohin der Verein sein Geld steckt"; static constexpr std::array spending_art{"advertising.scene.merchandise", "advertising.scene.press", "advertising.scene.fans"}; std::string rows, use; int64_t largest = 0; for (const auto &row : view.at("spending")) largest = std::max(largest, row.at("amount").get()); out += "
"; for (int i = 0; i < 3; ++i) { const auto &row = view.at("spending")[size_t(i)]; const bool waiting = i == 0 && !delivery.empty(); const auto amount = ad_cash(row.at("amount").get()); out += tile("ad-spending", "ad-spending-" + std::to_string(i), "data-ad-spending=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"", spending_art[size_t(i)], row.at("name").get(), i == 0 ? "Bestellung" : "Monatsbudget", amount, waiting ? "Die Lieferung läuft noch" : "Anklicken zum Ändern", false, "big", amount); rows += "
" + esc(row.at("name").get()) + "" + esc(amount) + (i == 0 ? "" : " / Monat") + "
"; // how much of what the budget may hold is used; without a limit the largest budget is the measure const auto value = row.at("amount").get(), limit = row.value("max", int64_t(0)); const double share = limit > 0 ? double(value) * 100 / double(limit) : largest > 0 ? double(value) * 100 / double(largest) : 0; use += "
" + esc(row.at("name").get()) + "" + esc(limit > 0 ? std::to_string(int(std::lround(share))) + " % von " + ad_cash(limit) : amount) + "
" + pg_bar(share, i == 0 ? "soft" : i == 1 ? "accent" : "sage") + "
"; } out += tile("ad-soon", "ad-spending-international", soon, "investment.scene.international", "Internationale Vermarktung", "Neu", "Noch nicht im Spiel", "Diese Investition folgt", false, "big", "—") + "
" + pg_kicker("Investitionen") + rows + "
Internationale Vermarktungfolgt
" + (delivery.empty() ? std::string() : "" + esc(delivery) + "") + "
" + pg_kicker("Vereinsprognose / Monat") + "
Einnahmen" + esc(ad_cash(view.at("income").get())) + "
Ausgaben" + esc(ad_cash(view.at("expenses").get())) + "
Saldo() >= 0 ? "ad-plus" : "ad-minus") + "\">" + esc((view.at("balance").get() > 0 ? "+ " : "") + ad_cash(view.at("balance").get())) + "
"; // the note: only what the figures above say, in the manager's own hand const auto monthly = view.at("spending")[1].at("amount").get() + view.at("spending")[2].at("amount").get(); const auto expenses = view.at("expenses").get(), merchandise = view.at("spending")[0].at("amount").get(); std::vector lines; if (monthly > 0) { lines.push_back("Presse und Fans: " + ad_cash(monthly) + " im Monat."); if (expenses > 0) lines.push_back("Das sind " + std::to_string(std::max(1, std::llround(double(monthly) * 100 / double(expenses)))) + " % aller Monatsausgaben."); } else lines.push_back("Presse und Fans bekommen gerade nichts!"); lines.push_back(!delivery.empty() ? "Fanartikel sind unterwegs – abwarten." : merchandise > 0 ? "Fanartikel zuletzt bestellt für " + ad_cash(merchandise) + "." : "Fanshop leer. Nachbestellen?"); if (view.at("balance").get() < 0) lines.push_back("Achtung: Der Monat schließt im Minus."); lines.push_back("Ausland: kommt noch."); out += "
" + pg_kicker("Auslastung der Budgets") + use + "
Merkzettel"; for (const auto &line : lines) out += "" + esc(line) + ""; out += "
"; } else { out += "
" + picture(renderer_.diagram("advertising-ground", ad_ground_svg(taken, advertising_selected_ >= 0 && advertising_selected_ < 14 ? advertising_selected_ : -1), 3000), ad_ground_w * 2.25, ad_ground_h * 2.25); for (int i = 0; i < 14; ++i) { const auto &c = slots[size_t(i)]; const auto b = ad_board(i); const bool on = taken[size_t(i)]; const auto name = c.at("name").get(); // the boards at the ends are read from the pitch: their writing stands upright const std::string face = " 0 ? " right" : b.turn < 0 ? " left" : "") + "\" style=\"" + (b.turn ? "left:" + pg((b.w - b.h) / 2) + ";top:" + pg((b.h - b.w) / 2) + ";width:" + pg(b.h) + ";height:" + pg(b.w) + ";" : std::string()) + "\">BANDE " + std::to_string(i + 1) + "" + esc(on ? name : "Platz frei") + ""; out += btn("ad-contract", face, std::string("ad-board") + (on ? " on" : "") + (advertising_selected_ == i ? " selected" : ""), "id=\"ad-contract-" + std::to_string(i) + "\" data-ad-contract=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-pressed=\"" + (advertising_selected_ == i ? "true" : "false") + "\" aria-label=\"Bande " + std::to_string(i + 1) + ", " + esc(on ? name + ", " + terms(c) : std::string("Platz frei")) + "\" title=\"" + esc(on ? name + " · " + terms(c) : std::string("Platz frei · anklicken für Angebote")) + "\" style=\"left:" + pg(b.x) + ";top:" + pg(b.y) + ";width:" + pg(b.w) + ";height:" + pg(b.h) + ";\""); } out += "
" + pg_kicker("Vereinsprognose / Monat"); for (const auto &[label, key] : std::array, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}}) { const auto value = view.at(key).get(); out += "" + std::string(label) + "= 0 ? "ad-plus" : "ad-minus") : "") + "\">" + esc((std::string(key) == "balance" && value > 0 ? "+ " : "") + ad_cash(value)) + ""; } out += "
"; for (const auto &[slot, art, title] : std::array, 2>{{{14, "advertising.scene.shirt", "Trikotwerbung"}, {15, "advertising.scene.tv", "TV-Rechte"}}}) { const auto &c = slots[size_t(slot)]; const bool on = c.at("active") == true; out += tile("ad-contract", "ad-contract-" + std::to_string(slot), "data-ad-contract=\"" + std::to_string(slot) + "\" data-id=\"" + std::to_string(slot) + "\" aria-pressed=\"" + (advertising_selected_ == slot ? "true" : "false") + "\"", art, title, on ? (slot == 14 ? "Aktueller Sponsor" : "Aktueller Sender") : "Platz frei", on ? c.at("name").get() : std::string("Kein Vertrag"), on ? terms(c) : std::string("Anklicken für Angebote"), advertising_selected_ == slot, "four"); } out += tile("ad-soon", "ad-contract-naming", soon, "advertising.scene.arena", "Namensrecht Stadion", "Neu", "Noch nicht im Spiel", "Dieser Vertrag folgt", false, "four") + "
"; } out += "
"; if (advertising_selected_ < 0 || advertising_selected_ > 15) return out; // the offers for the chosen place, as a note const auto &choices = engine_mode_ ? slots[size_t(advertising_selected_)].at("choices") : Json::array(); if (engine_mode_) advertising_offer_ = std::clamp(advertising_offer_, 0, int(choices.size()) - 1); const auto quote = engine_mode_ ? engine_advertising_quote(engine_data_, advertising_selected_, advertising_offer_) : demo_advertising_quote(snapshot.state, advertising_selected_, advertising_offer_, *world_); const bool active = quote.at("active"); const bool cycle = engine_mode_ ? quote.at("can_cycle").get() : !active; const bool accept = engine_mode_ ? quote.at("can_accept").get() : !active; const auto place = quote.at("label").get(), sponsor = quote.at("name").get(); // which of the offers this is: a running contract stands before them const int running = engine_mode_ && !choices.empty() && choices[0].at("active") == true ? 1 : 0; const int count = engine_mode_ ? int(choices.size()) - running : 3; const bool none = engine_mode_ && !active && quote.value("offer_id", Json()).is_null(); const auto which = active ? std::string("Laufender Vertrag") : none ? std::string("Keine Angebote") : "Angebot " + std::to_string(advertising_offer_ - running + 1) + " von " + std::to_string(std::max(1, count)); const int boards = engine_mode_ ? quote.value("boards", 1) : 1; out += "

" + esc(place) + "

" + std::string(active ? "Der Vertrag läuft; mit den Pfeilen siehst du, was sonst geboten wird." : "Mit den Pfeilen durch die Angebote blättern.") + "
" + (none ? std::string() : ad_mark(sponsor, 171)) + "
" + pg_kicker(which) + "

" + esc(sponsor) + "

" + (none ? std::string("Für diesen Platz liegt derzeit nichts vor.") : (active ? "Noch " : "Dauer ") + std::to_string(quote.at("months").get()) + (quote.at("months").get() == 1 ? " Monat" : " Monate") + (boards > 1 ? " · " + std::to_string(boards) + " Banden" : std::string())) + "
" + (none ? std::string() : "
" + pg_kicker("je Monat") + "" + esc(ad_cash(quote.at("amount").get())) + "
") + "
"; return out; }