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>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-17 15:09:01 +01:00
1 parent 83bd96c1ff
commit 2639f37def
26 files changed
+507 -9

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/game/naming_rights.hpp"
#include <algorithm>
#include "game/random.hpp"
#include "game/schedule.hpp"
#include "modern/game/matchday.hpp"
namespace bmh::modern {
namespace {
constexpr size_t kRecord = 0xb0c;
int league_club(const ModernState& g, int manager) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || g.manager_records.size() < size_t(manager + 1) * kRecord) return -1;
const int team = g.manager_teams[size_t(manager)];
return team >= 0 && team < league_clubs() ? team : -1;
}
} // namespace
const ModernState::StadiumName* stadium_entry(const ModernState& g, int manager) {
return manager >= 0 && size_t(manager) < g.stadiums.size() ? &g.stadiums[size_t(manager)] : nullptr;
}
bool naming_rights_sold(const ModernState& g, int manager) {
const auto* entry = stadium_entry(g, manager);
return entry && entry->months > 0;
}
bool rename_stadium(ModernState& g, int manager, const std::string& name) {
if (league_club(g, manager) < 0 || naming_rights_sold(g, manager)) return false;
const size_t first = name.find_first_not_of(' '), last = name.find_last_not_of(' ');
if (first == std::string::npos) return false;
const std::string trimmed = name.substr(first, last - first + 1);
if (trimmed.size() > 40 || std::any_of(trimmed.begin(), trimmed.end(), [](unsigned char c) { return c < 0x20 || c == 0x7f; })) return false;
if (g.stadiums.size() <= size_t(manager)) g.stadiums.resize(size_t(manager) + 1);
g.stadiums[size_t(manager)].name = trimmed;
return true;
}
// OpenBMH deviates from the original: in Modern a manager names his stadium and can sell the name to a sponsor for one to five years; the sponsor pays monthly and the name is fixed until the contract ends.
std::vector<NamingOffer> naming_offers(const ModernState& g, int manager) {
const int team = league_club(g, manager);
if (team < 0 || naming_rights_sold(g, manager)) return {};
const size_t rec = size_t(manager) * kRecord;
int seats = 0;
for (size_t block = 0; block < 8; ++block) seats += int(g.manager_records[rec + 0x4c + block]) * 1000;
if (seats <= 0) return {};
// euros a seat and year, by league
static constexpr int kRate[5] = {36, 22, 12, 7, 7};
const int league = std::clamp(team_league(team), 0, 4);
const int prestige = g.manager_records[rec + 0x211];
const int64_t base = int64_t(seats) * kRate[league] / 12 * (80 + prestige * 2 / 5) / 100;
uint32_t salt = 2166136261u;
for (const unsigned char c : g.career_id) salt = (salt ^ c) * 16777619u;
GameRandom draw(int32_t((uint64_t(salt) + uint64_t(g.date / 28) * 6151u + uint64_t(manager) * 98317u + 17u) % 4000000u));
std::vector<NamingOffer> offers;
while (offers.size() < 3) {
NamingOffer offer;
offer.sponsor = uint8_t(draw.range(0, 9));
const int years = draw.range(1, 5);
// a longer contract pays a little less each month
const int percent = draw.range(80, 125) - (years - 1) * 3;
if (std::any_of(offers.begin(), offers.end(), [&](const NamingOffer& o) { return o.sponsor == offer.sponsor; })) continue;
offer.months = uint16_t(years * 12);
offer.monthly = uint32_t(std::max<int64_t>(base * percent / 100 / 1000 * 1000, 1000));
offers.push_back(offer);
}
return offers;
}
bool sell_naming_rights(ModernState& g, int manager, int index) {
const auto offers = naming_offers(g, manager);
if (index < 0 || size_t(index) >= offers.size()) return false;
if (g.stadiums.size() <= size_t(manager)) g.stadiums.resize(size_t(manager) + 1);
auto& entry = g.stadiums[size_t(manager)];
entry.sponsor = offers[size_t(index)].sponsor, entry.monthly = offers[size_t(index)].monthly, entry.months = offers[size_t(index)].months;
return true;
}
void naming_rights_month(ModernState& g) {
for (size_t m = 0; m < g.stadiums.size() && m < g.manager_teams.size(); ++m) {
auto& entry = g.stadiums[m];
if (entry.months == 0) continue;
if (league_club(g, int(m)) >= 0) modern::book_money(g, int(m), -int32_t(entry.monthly), true);
if (--entry.months == 0) entry.sponsor = 0xff, entry.monthly = 0;
}
}
} // namespace bmh::modern