Files
Dreierpack-Manager/tests/modern_naming_tests.cpp
T
MichaelandClaude Fable 5.2 2639f37def The stadium has a name of its own, and the name can be sold
A manager renames his stadium on the stadium page. On the advertising page
three sponsors offer to buy the name for one to five years; the sponsor
pays with every month change, the stadium is called after him, and until
the contract ends it can be neither renamed nor sold again. The match
sheet shows the name.

Engine: naming_rights.hpp; read stadium (name, nameEditable, namingRights,
namingOffers), commands stadium.rename and stadium.namingRights, live read
stadiumName; saved in state/modern.json.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-17 15:09:01 +01:00

94 lines
4.9 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// The stadium's name and its naming rights (docs/new_engine/namensrecht.md) on a synthetic
// manager: renaming, the three offers, the sale, the monthly payment and the end of the contract.
#include <cstdio>
#include <set>
#include "modern/game/naming_rights.hpp"
using namespace bmh;
using namespace bmh::modern;
namespace {
int failures = 0;
void check(bool ok, const char* what) {
if (!ok) {
std::fprintf(stderr, "FAIL: %s\n", what);
++failures;
}
}
int32_t cash(const ModernState& g) {
return int32_t(uint32_t(g.manager_records[0x314]) | uint32_t(g.manager_records[0x315]) << 8 | uint32_t(g.manager_records[0x316]) << 16 |
uint32_t(g.manager_records[0x317]) << 24);
}
// Manager 0 runs club 0 of the first league with a stadium of 24 000 places.
ModernState world() {
ModernState g;
g.career_id = "career:test";
g.level = 2;
g.manager_teams = {0};
g.manager_records.assign(5 * 0xb0c, 0);
for (size_t block = 0; block < 8; ++block) g.manager_records[0x4c + block] = 3;
g.manager_records[0x211] = 50;
g.manager_records[0x314] = 0x40, g.manager_records[0x315] = 0x42, g.manager_records[0x316] = 0x0f; // 1 000 000
return g;
}
} // namespace
int main() {
{
ModernState g = world();
check(stadium_entry(g, 0) == nullptr && !naming_rights_sold(g, 0), "no entry before the manager names anything");
check(rename_stadium(g, 0, " Waldstadion ") && stadium_entry(g, 0)->name == "Waldstadion", "the name is trimmed and kept");
check(!rename_stadium(g, 0, " ") && !rename_stadium(g, 0, std::string(41, 'x')) && !rename_stadium(g, 0, "a\nb") &&
stadium_entry(g, 0)->name == "Waldstadion",
"an empty, too long or broken name is refused and changes nothing");
check(!rename_stadium(g, 1, "Nordpark"), "no stadium without a manager");
}
{
ModernState g = world();
const auto offers = naming_offers(g, 0);
std::set<int> sponsors;
bool sound = offers.size() == 3;
for (const NamingOffer& o : offers)
sound = sound && o.sponsor <= 9 && sponsors.insert(o.sponsor).second && o.months >= 12 && o.months <= 60 && o.months % 12 == 0 &&
o.monthly >= 1000 && o.monthly % 1000 == 0;
check(sound, "three offers of different sponsors for one to five years");
// 24 000 places at 36 euros a year: 72 000 a month before the factors (0.8-1.25 times prestige 1.0)
bool in_range = true;
for (const NamingOffer& o : offers) in_range = in_range && o.monthly >= 45000 && o.monthly <= 90000;
check(in_range, "the payment follows the places and the league");
const auto again = naming_offers(g, 0);
bool same = again.size() == offers.size();
for (size_t i = 0; same && i < offers.size(); ++i)
same = again[i].sponsor == offers[i].sponsor && again[i].monthly == offers[i].monthly && again[i].months == offers[i].months;
check(same, "reading the offers does not change them");
ModernState lower = world();
lower.manager_teams = {60};
check(naming_offers(lower, 0).front().monthly < offers.front().monthly / 2, "a lower league pays much less");
check(!sell_naming_rights(g, 0, 3) && !naming_rights_sold(g, 0), "an offer that does not exist is refused");
rename_stadium(g, 0, "Waldstadion");
const NamingOffer taken = offers[1];
check(sell_naming_rights(g, 0, 1) && naming_rights_sold(g, 0) && stadium_entry(g, 0)->sponsor == taken.sponsor &&
stadium_entry(g, 0)->monthly == taken.monthly && stadium_entry(g, 0)->months == taken.months,
"the sale notes sponsor, payment and term");
check(!rename_stadium(g, 0, "Nordpark") && stadium_entry(g, 0)->name == "Waldstadion", "a sold name cannot be changed");
check(naming_offers(g, 0).empty() && !sell_naming_rights(g, 0, 0), "no second sale while the contract runs");
const int32_t before = cash(g);
naming_rights_month(g);
check(cash(g) == before + int32_t(taken.monthly) && stadium_entry(g, 0)->months == taken.months - 1, "the sponsor pays with the month change");
for (int month = 1; month < taken.months; ++month) naming_rights_month(g);
check(cash(g) == before + int32_t(taken.monthly) * taken.months, "he pays every month of the term");
check(!naming_rights_sold(g, 0) && stadium_entry(g, 0)->name == "Waldstadion" && rename_stadium(g, 0, "Nordpark") && naming_offers(g, 0).size() == 3,
"after the last month the stadium has its own name again and can be renamed or sold");
naming_rights_month(g);
check(cash(g) == before + int32_t(taken.monthly) * taken.months, "nothing is paid without a contract");
}
if (failures) return 1;
std::puts("modern_naming_tests: ok");
return 0;
}