Exclusive sponsor from training camp stays (Modern)

The Middle East camps share their grades but differ in price; a stay
can now bring an exclusive sponsor: 15 / 30 / 45 % per stay (Doha /
Abu Dhabi / Dubai), a shirt (about every third offer) or four boards at
twice the club's best regular offer for 12 months. Accepted on a free
place it starts at once, otherwise it is queued and starts at a month
change once the place is free. The offer goes through the regular
advertising acceptance.

Camp fields sponsor_chance / sponsor_bonus / sponsor_months (data
format F4, editable; built-in values for the Middle East camps), state
saved in state/modern.json, read query {kind: "sponsor"}, session action
dispatch_exclusive_sponsor, tests in modern_camp_tests, SIM_SPONSOR=1.
Sponsor artwork does not exist yet (asset: null, documented).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-25 09:15:38 +01:00
1 parent 44a7a77915
commit 77d1f93e8f
20 files changed
+333 -13

No files matched your search

+101
View File
@@ -1481,6 +1481,7 @@ bool book_training_camp(ModernState& g, int manager, int resort, WatcomRandom& r
uint8_t& stays = g.manager_records.at(rec + kStays);
stays = uint8_t((stays + 1) | 0x80);
modern::training_camp_effect(g, manager, resort, rand);
modern::roll_exclusive_sponsor(g, manager, resort, rand); // Modern: a chance of an exclusive sponsor
return true;
}
@@ -2159,6 +2160,106 @@ AdvertisingOfferResult accept_advertising_offer(ModernState& g,
return result;
}
// --- Exclusive sponsor (Modern) -------------------------------------------------------------
// OpenBMH deviates from the original: in Modern a training camp stay can bring an exclusive sponsor (shirt or four boards at twice the best regular offer), taken now or after the running contract.
namespace {
ModernState::ExclusiveSponsor& exclusive_sponsor(ModernState& g, int manager) {
if (g.exclusive_sponsors.size() < g.manager_teams.size()) g.exclusive_sponsors.resize(g.manager_teams.size());
return g.exclusive_sponsors.at(size_t(manager));
}
// The offer goes through the regular acceptance: it is written over the last offer of its pool
// and accepted there, so boards, sorting and group ids follow the original rules. Nothing
// changes (the pool offer is restored) when the place is taken.
bool install_exclusive_sponsor(ModernState& g, int manager, const ModernState::ExclusiveSponsor& s) {
if (!ad_manager_record_valid(g, manager)) return false;
const size_t rec = size_t(manager) * kAdRecord;
const int group = s.kind == 1 ? 1 : 0;
constexpr int kRaw = 9;
const size_t at = rec + kAdPool + size_t(group) * 0x78 + size_t(kRaw) * kAdContractBytes;
std::array<uint8_t, kAdContractBytes> saved{};
std::copy_n(g.manager_records.begin() + std::ptrdiff_t(at), kAdContractBytes, saved.begin());
auto& r = g.manager_records;
const uint16_t score = s.score;
for (size_t i = 0; i < 4; ++i) r.at(at + i) = uint8_t(s.monthly >> (8 * i));
r.at(at + 4) = s.kind == 1 ? 1 : s.units;
r.at(at + 5) = s.months;
r.at(at + 6) = 0;
r.at(at + 7) = s.sponsor;
r.at(at + 8) = uint8_t(score), r.at(at + 9) = uint8_t(score >> 8);
const int display = s.kind == 1 ? 14 : 13;
const AdvertisingOfferList view = modern::advertising_offers(g, manager, display);
bool accepted = false;
for (const AdvertisingOfferCandidate& c : view.offers)
if (c.raw_slot == kRaw && c.can_accept) {
AdvertisingOfferRequest request;
request.manager = manager;
request.display_slot = display;
request.contract_slot = view.contract_slot;
request.expected_contract = view.contract_bytes;
request.raw_slot = kRaw;
request.expected_offer = c.bytes;
accepted = modern::accept_advertising_offer(g, request).status == AdvertisingOfferStatus::accepted;
}
if (!accepted) std::copy(saved.begin(), saved.end(), r.begin() + std::ptrdiff_t(at));
return accepted;
}
} // namespace
void roll_exclusive_sponsor(ModernState& g, int manager, int resort, WatcomRandom& rand) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || resort < 0 || size_t(resort) >= g.training_camps.size())
return;
const TrainingCamp& camp = g.training_camps[size_t(resort)];
if (camp.sponsor_chance <= 0) return; // (no draw: camps without a sponsor keep the stream)
ModernState::ExclusiveSponsor& s = exclusive_sponsor(g, manager);
if (s.offered || s.queued) return; // one offer or contract at a time
if (rand.range(1, 100) > camp.sponsor_chance) return;
const AdvertisingBase value = modern::advertising_base(g, manager);
const bool shirt = rand.range(0, 2) == 0;
// the best regular offer: offer k = 9 at the top of its +-25 % (TransferListCountdown2)
int best = shirt ? (value.base >> 2) * (0x50 + 9 * 4) / 100 : ((value.base / 2) / 8) * (0x46 + 9 * 6) / 100;
best += best >> 2;
s = {};
s.offered = true;
s.kind = shirt ? 1 : 0;
s.units = shirt ? 1 : 4;
s.months = uint8_t(std::clamp(camp.sponsor_months, 1, 60));
s.sponsor = uint8_t(rand.range(0, 9));
s.monthly = uint32_t(std::max(0, int(int64_t(best) * camp.sponsor_bonus / 100)));
s.camp = camp.id;
s.score = uint16_t(value.score);
// (Modern has no text catalogue yet; the sponsor's name is one of the advertising firms)
const std::string sponsor = message_text(g, ::bmh::layout::Advertising_FormatError_ExecutableField3 + uint32_t(s.sponsor) * 4);
post_composed(g, manager, "Exklusiv-Sponsor: " + sponsor + " bietet Ihnen nach Ihrem Aufenthalt in " + camp.place +
(shirt ? " die Trikotwerbung" : " vier Banden") + " f}r " + format_amount(g, int32_t(s.monthly)) +
(shirt ? "" : " je Bande") + " monatlich an (" + std::to_string(s.months) + " Monate).");
}
ExclusiveSponsorAnswer answer_exclusive_sponsor(ModernState& g, int manager, bool accept) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return ExclusiveSponsorAnswer::invalid;
ModernState::ExclusiveSponsor& s = exclusive_sponsor(g, manager);
if (!s.offered) return ExclusiveSponsorAnswer::invalid;
if (!accept) {
s = {};
return ExclusiveSponsorAnswer::declined;
}
if (install_exclusive_sponsor(g, manager, s)) {
s = {};
return ExclusiveSponsorAnswer::started;
}
s.offered = false;
s.queued = true;
return ExclusiveSponsorAnswer::queued;
}
void start_queued_exclusive_sponsor(ModernState& g, int manager) {
if (manager < 0 || size_t(manager) >= g.exclusive_sponsors.size()) return;
ModernState::ExclusiveSponsor& s = g.exclusive_sponsors[size_t(manager)];
if (s.queued && install_exclusive_sponsor(g, manager, s)) s = {};
}
AdvertisingSpendingView advertising_spending(const ModernState& g, int manager, int target_slot) {
AdvertisingSpendingView view;
view.manager = manager;