diff --git a/docs/DIFFERENCES.md b/docs/DIFFERENCES.md index 4adc159..f8ec249 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -37,6 +37,7 @@ describe deliberate changes; they are not a list of every known compatibility li - [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): uses the supported transfer-fee arithmetic and designated set-piece fields. - [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): Modern training camps have grades up to six stars with a capped step, a higher limit and recovery extras. - [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): the Modern Toto takes up to six columns (one in the original), each at the stake plus a 10 % fee per extra column, 400,000 at most in all. +- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): 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. - [src/modern/game/desk_actions.hpp](../src/modern/game/desk_actions.hpp): supports designated set-piece records and the supported transfer-editor rules. - [src/modern/game/environment.hpp](../src/modern/game/environment.hpp): uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands. - [src/modern/game/highscore.cpp](../src/modern/game/highscore.cpp): reads the supported edition-specific high-score format from the loaded image. diff --git a/docs/new_engine/datenformat.md b/docs/new_engine/datenformat.md index c814ad4..bd67727 100644 --- a/docs/new_engine/datenformat.md +++ b/docs/new_engine/datenformat.md @@ -84,7 +84,8 @@ Die bestehende Regel `rule:training-camps` (Typ `training_camps`) bleibt und wir - Standardkarten und Resortbilder sind GUI-Ressourcen und werden anhand von Karten-/Lager-ID zugeordnet; sie sind keine Pflichtinhalte der Welt. `image` ist optional und nur für ein ausdrücklich in der Welt geliefertes Bild vorgesehen. Wenn gesetzt, muss der Asset-Schlüssel im normalen OBW-Asset-Index auflösbar sein. Siehe [GUI-/Welt-Trennung](../new_ui/assets.md). - Die IDs `resort:0` bis `resort:17` entsprechen den IDs 0–17 der Oberfläche und werden nicht umsortiert. - Fehlt die Regel in einer Modern-Welt, gilt die in die Engine eingebaute Vorgabe (`src/modern/game/training_camps.cpp`) mit den 18 fiktiven Lagern. -- **Editor:** Kartenliste und Lager bearbeiten: Karte (Pflicht), `x`/`y` (leer erlaubt, solange die Karte keine Maße hat), vier Qualitätswerte (0–6), Preis, Ort, Land und optionales datensatzspezifisches Bild. Prüfung auf eindeutige IDs, gültige Karte und Nation, Qualitäten im Bereich, auflösbare explizite Bildreferenzen und Koordinaten innerhalb der Kartenmaße, sobald diese gesetzt sind. Ein fehlendes `image` ist kein Fehler; feste GUI-Motive müssen nicht in den Datensatz kopiert werden. +- **Exklusiv-Sponsor (optional, neu 25.10.2026):** `sponsor_chance` (Prozent je Aufenthalt, 0–100; 0 = keiner), `sponsor_bonus` (Betrag in Prozent des besten regulären Angebots, 100–500, Standard 200), `sponsor_months` (Laufzeit 1–60, Standard 12). Fehlt `sponsor_chance`, gelten die eingebauten Werte des Lagers mit derselben ID (Doha 15, Abu Dhabi 30, Dubai 45), sonst keine Chance. Siehe [Trainingslager](trainingslager.md#exklusiv-sponsor). +- **Editor:** Kartenliste und Lager bearbeiten: Karte (Pflicht), `x`/`y` (leer erlaubt, solange die Karte keine Maße hat), vier Qualitätswerte (0–6), Preis, Ort, Land, optionales datensatzspezifisches Bild und die drei Sponsor-Felder. Prüfung auf eindeutige IDs, gültige Karte und Nation, Qualitäten im Bereich, auflösbare explizite Bildreferenzen und Koordinaten innerhalb der Kartenmaße, sobald diese gesetzt sind. Ein fehlendes `image` ist kein Fehler; feste GUI-Motive müssen nicht in den Datensatz kopiert werden. ## F5 · Namen diff --git a/docs/new_engine/trainingslager.md b/docs/new_engine/trainingslager.md index db67d48..bba487f 100644 --- a/docs/new_engine/trainingslager.md +++ b/docs/new_engine/trainingslager.md @@ -76,9 +76,22 @@ und 3 abgeschwächt. Das Ergebnis wird hier und in [DIFFERENCES](../DIFFERENCES. - Am Schreibtisch des Bundestrainers nennt der Managerdatensatz die Nationalmannschaft; dort ist kein Lager buchbar (`invalid_request`). - Offen: Messung der Saisonwirkung (M7) und die Projektion für die UI (M6). +## Exklusiv-Sponsor + +Die drei Lager im Nahen Osten haben dieselben Qualitäten, kosten aber 2,8 / 3,2 / 3,6 Mio. €. Damit das teurere Lager einen Grund hat, kann ein Aufenthalt einen Exklusiv-Sponsor bringen (abgestimmt am 25.10.2026): + +- **Chance je Aufenthalt:** Doha 15 %, Abu Dhabi 30 %, Dubai 45 % (`sponsor_chance`, [Datenformat F4](datenformat.md#f4--trainingslager)). Jedes Lager kann im Editor eine Chance bekommen. +- **Angebot:** Trikotwerbung (etwa jedes dritte Angebot) oder ein Paket aus vier Banden, zum doppelten besten regulären Angebot des Vereins (`sponsor_bonus` 200 %; reguläre Angebote: Banden bis 124 %, Trikot bis 116 % eines Grundwerts, je +25 %), Laufzeit 12 Monate (`sponsor_months`). Der Sponsorname ist einer der vorhandenen Werbepartner. Es kommt eine Post. +- **Antwort:** Ist die Fläche frei (Trikot ohne laufenden Vertrag, genug freie Banden), beginnt der Vertrag sofort. Sonst wird er als Anschlussvertrag vorgemerkt und startet beim Monatswechsel, sobald die Fläche frei ist (ein Vertrag mit offener Verlängerungsoption muss vorher entschieden sein). Ablehnen: Das Angebot verfällt. Pro Manager gibt es höchstens ein offenes Angebot oder einen vorgemerkten Vertrag. +- **Messung (Bundesliga-Spitzenverein):** ein Banden-Angebot bringt rund 100.000–111.000 € je Bande und Monat, also etwa 5 Mio. € im Jahr für vier Banden; das reguläre Bestangebot liegt bei etwa der Hälfte. +- **Umsetzung:** `roll_exclusive_sponsor`, `answer_exclusive_sponsor`, `start_queued_exclusive_sponsor` (`desk_actions.*`); das Angebot läuft über die reguläre Werbeannahme (`accept_advertising_offer`), damit Banden, Sortierung und Gruppen-IDs den Originalregeln folgen. Zustand `ModernState::exclusive_sponsors`, gespeichert in `state/modern.json`. Test: `modern_camp_tests`; Sim: `SIM_CAMP=16 SIM_SPONSOR=1`. +- **Offen: Assets.** Für die Exklusiv-Sponsoren gibt es noch keine Grafiken (Logo, Trikot- oder Bandenmotiv). Die Lese-Abfrage liefert `asset: null`; UI und Datensatz müssen die Motive noch festlegen. Ebenso gibt es für die Post noch keinen Textkatalog (der Text steht vorläufig in der Engine). + ## Für die Oberfläche Die Modern-Session liefert Katalog, Buchungsstand (Aufenthalte dieser Saison, Buchung diese Woche), aktuelle Schwerpunkte und den Preis für den eigenen Kader. Aktionen: Schwerpunkte setzen, Lager buchen. Einzelheiten in der [UI-Schnittstelle](ui-schnittstelle.md#trainingslager). + +Exklusiv-Sponsor: Lese-Abfrage `{kind: "sponsor"}` über `ModernSession::read` (`offer` und `queued` je `{kind: shirt|boards, boards, monthly, months, sponsor, asset, camp}` oder `null`), Antwort über `ModernSession::dispatch_exclusive_sponsor(manager, accept, …)` mit Ergebnis `started`, `queued` oder `declined`. diff --git a/docs/new_engine/ui-abfragen.md b/docs/new_engine/ui-abfragen.md index 835d795..42c7b68 100644 --- a/docs/new_engine/ui-abfragen.md +++ b/docs/new_engine/ui-abfragen.md @@ -24,6 +24,7 @@ Vereinbarter Ablauf: Die neue Oberfläche wird **je Menü** an die Modern-Engine | `{kind: "table", league}` | `league`, `played`, `rows: [{rank, club, played, won, drawn, lost, goals_for, goals_against, points}]` (aktueller Stand, mit Punktabzug) | | `{kind: "fixtures", league, matchday?}` | `league`, `matchday`, `matches: [{home, away, result: [h, a] \| null, status: open \| played \| postponed}]`; ohne `matchday` der nächste | | `{kind: "toto"}` | Tippschein des Spieltags und eigene Spalten, siehe [Toto](toto.md) | +| `{kind: "sponsor"}` | Exklusiv-Sponsor aus einem Trainingslager: offenes Angebot und vorgemerkter Vertrag, siehe [Trainingslager](trainingslager.md#exklusiv-sponsor) | | `{kind: "squad", club?}` | `club`, `players: [{slot, player, nation, position (gk/def/mid/fwd), age, technique, condition, form, strength, skills {teamplay, speed, shooting, passing, tackling, free_kick, corner}, lineup (start/bench/none), injured_weeks, banned_weeks}]`; ohne `club` der eigene Verein, sonst Welt-ID oder Laufzeitindex | | `competitions`, `winners`, `player_stats` | siehe [Spielstatistik](statistik.md) | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 3f4b7d2..03785d6 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -8614,6 +8614,22 @@ bool ModernSession::dispatch_toto(const ui::TotoRequest& request, uint64_t& revi return true; } +bool ModernSession::dispatch_exclusive_sponsor(int manager, bool accept, uint64_t& revision, std::string& result, + std::string& error) { + const int active = int(g_.memory.u8(::bmh::layout::ActiveManager)); + if (manager != active || manager < 0 || size_t(manager) >= g_.manager_teams.size()) { + error = "stale_manager_or_revision"; return false; + } + switch (modern::answer_exclusive_sponsor(g_, manager, accept)) { + case ExclusiveSponsorAnswer::started: result = "started"; break; + case ExclusiveSponsorAnswer::queued: result = "queued"; break; + case ExclusiveSponsorAnswer::declined: result = "declined"; break; + case ExclusiveSponsorAnswer::invalid: error = "no_sponsor_offer"; return false; + } + ++revision; + return true; +} + bool ModernSession::dispatch_pools_columns(int manager, uint32_t stake, const std::vector>& columns, uint64_t& revision, std::string& error) { const int active = int(g_.memory.u8(::bmh::layout::ActiveManager)); diff --git a/src/modern/app/modern_session.hpp b/src/modern/app/modern_session.hpp index 2e2f469..2677d75 100644 --- a/src/modern/app/modern_session.hpp +++ b/src/modern/app/modern_session.hpp @@ -610,6 +610,9 @@ public: // toto_coupon_requires_eleven_matches, invalid_toto_coupon, stale_manager_or_revision. bool dispatch_pools_columns(int manager, uint32_t stake, const std::vector>& columns, uint64_t& revision, std::string& error); + // The answer to an exclusive sponsor offer from a camp stay (docs/new_engine/trainingslager.md). + // `result` is "started" or "queued" when accepted, "declined" otherwise. Error: no_sponsor_offer. + bool dispatch_exclusive_sponsor(int manager, bool accept, uint64_t& revision, std::string& result, std::string& error); bool dispatch_tactics(const ui::TacticsRequest&, uint64_t& revision, std::string& error); bool dispatch_lineup(const ui::LineupRequest&, uint64_t& revision, std::string& error); // Source PitchScreen live-match path: apply one user-picked field/bench diff --git a/src/modern/content/projections.cpp b/src/modern/content/projections.cpp index 95b3964..132f87a 100644 --- a/src/modern/content/projections.cpp +++ b/src/modern/content/projections.cpp @@ -7,6 +7,7 @@ #include #include +#include "game/messages.hpp" #include "game/schedule.hpp" #include "game/table.hpp" #include "modern/content/statistics.hpp" @@ -203,6 +204,27 @@ J squad(const ModernState& g, int team) { return O{{"ok", true}, {"club", club_json(g, team)}, {"players", std::move(players)}}; } +// The manager's exclusive sponsor offer or queued contract (docs/new_engine/trainingslager.md). +// "asset" stays null: there is no artwork for these sponsors yet. +J sponsor(const ModernState& g, int manager) { + if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return error("invalid_manager"); + J offer = nullptr, queued = nullptr; + if (size_t(manager) < g.exclusive_sponsors.size()) { + const auto& s = g.exclusive_sponsors[size_t(manager)]; + if (s.offered || s.queued) { + std::string camp_name; + for (const auto& c : g.training_camps) + if (c.id == s.camp) camp_name = c.name; + J row = O{{"kind", s.kind == 1 ? "shirt" : "boards"}, {"boards", s.kind == 1 ? 0 : int(s.units)}, + {"monthly", int64_t(s.monthly)}, {"months", int(s.months)}, + {"sponsor", almanac_utf8(message_text(g, ::bmh::layout::Advertising_FormatError_ExecutableField3 + uint32_t(s.sponsor) * 4))}, + {"asset", nullptr}, {"camp", O{{"id", s.camp}, {"name", camp_name}}}}; + (s.offered ? offer : queued) = std::move(row); + } + } + return O{{"ok", true}, {"offer", std::move(offer)}, {"queued", std::move(queued)}}; +} + // The Toto coupon of the matchday and the manager's columns (docs/new_engine/toto.md). J toto(const ModernState& g, int manager) { if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return error("invalid_manager"); @@ -255,6 +277,7 @@ cli::Json query_projection(const ModernState& g, int manager, const cli::Json& r try { if (k == "status") return status(g, manager); if (k == "toto") return toto(g, manager); + if (k == "sponsor") return sponsor(g, manager); if (k == "leagues") return leagues(g); if (k == "table" || k == "fixtures") { const int league = league_of_request(g, field(request, "league")); diff --git a/src/modern/content/world.cpp b/src/modern/content/world.cpp index dffd9cb..1aa0890 100644 --- a/src/modern/content/world.cpp +++ b/src/modern/content/world.cpp @@ -138,6 +138,13 @@ World read_world(const obw::Documents& documents) { camp.quality[k] = uint8_t(grade); } if (camp.base_price < 0) fail("negative training camp price: " + camp.id); + // exclusive sponsor (optional; -1 = not given: the built-in values of the same camp id apply) + camp.sponsor_chance = integer(find(c, "sponsor_chance"), -1); + camp.sponsor_bonus = integer(find(c, "sponsor_bonus"), 200); + camp.sponsor_months = integer(find(c, "sponsor_months"), 12); + if (camp.sponsor_chance > 100 || camp.sponsor_bonus < 100 || camp.sponsor_bonus > 500 || + camp.sponsor_months < 1 || camp.sponsor_months > 60) + fail("training camp sponsor values out of range: " + camp.id); catalogue.camps.push_back(std::move(camp)); } w.camps = std::move(catalogue); diff --git a/src/modern/content/world_expand.cpp b/src/modern/content/world_expand.cpp index 371152b..d7f2079 100644 --- a/src/modern/content/world_expand.cpp +++ b/src/modern/content/world_expand.cpp @@ -462,6 +462,18 @@ void install_training_camps(ModernState& g, const World& world) { if (catalogue.camps.empty()) obw::detail::fail("the training camp catalogue is empty"); g.camp_maps = catalogue.maps; g.training_camps = catalogue.camps; + // A camp without sponsor values takes those of the built-in camp with the same id (the + // Middle East camps), else none. + for (TrainingCamp& camp : g.training_camps) { + if (camp.sponsor_chance >= 0) continue; + camp.sponsor_chance = 0; + for (const TrainingCamp& built_in : default_camp_catalogue().camps) + if (built_in.id == camp.id) { + camp.sponsor_chance = built_in.sponsor_chance; + camp.sponsor_bonus = built_in.sponsor_bonus; + camp.sponsor_months = built_in.sponsor_months; + } + } } } // namespace bmh::modern diff --git a/src/modern/content/world_save.cpp b/src/modern/content/world_save.cpp index 90cda8c..1740330 100644 --- a/src/modern/content/world_save.cpp +++ b/src/modern/content/world_save.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "content/digest.hpp" #include "content/package.hpp" @@ -44,6 +45,32 @@ std::vector strings(const J& value) { } std::string world_identity(const World& world) { return world.id + "@" + world.data_revision; } +// Exclusive sponsor offers and queued contracts per manager (docs/new_engine/trainingslager.md). +J sponsors_json(const std::vector& sponsors) { + A out; + for (const auto& s : sponsors) + out.push_back(O{{"offered", s.offered}, {"queued", s.queued}, {"kind", int(s.kind)}, {"units", int(s.units)}, + {"months", int(s.months)}, {"sponsor", int(s.sponsor)}, {"monthly", int64_t(s.monthly)}, {"score", int(s.score)}, {"camp", s.camp}}); + return out; +} +std::vector sponsors_json(const J& value) { + std::vector out; + for (const J& row : arr(value)) { + ModernState::ExclusiveSponsor s; + const J& offered = get(row, "offered"); + const J& queued = get(row, "queued"); + if (!std::holds_alternative(offered.value) || !std::holds_alternative(queued.value)) fail("invalid sponsor flags"); + s.offered = std::get(offered.value), s.queued = std::get(queued.value); + s.kind = uint8_t(num(get(row, "kind"))), s.units = uint8_t(num(get(row, "units"))); + s.months = uint8_t(num(get(row, "months"))), s.sponsor = uint8_t(num(get(row, "sponsor"))); + s.monthly = uint32_t(num(get(row, "monthly"))), s.camp = str(get(row, "camp")); + s.score = uint16_t(num(get(row, "score"))); + if (s.kind > 1 || s.units > 14 || s.sponsor > 9) fail("invalid exclusive sponsor"); + out.push_back(std::move(s)); + } + return out; +} + // The Toto columns 2-6 and the last settlement per manager (docs/new_engine/toto.md). J pools_json(const std::vector& pools) { A out; @@ -107,7 +134,8 @@ void save_world_career(const std::filesystem::path& path, const World& world, co {"league_ids", strings(state.world_league_id)}, {"league_names", strings(state.world_league_name)}, {"generated_players", int64_t(state.almanac.generated_players)}, - {"pools", pools_json(state.pools)}}); + {"pools", pools_json(state.pools)}, + {"exclusive_sponsors", sponsors_json(state.exclusive_sponsors)}}); // The almanac: finished seasons unchanged, the running one encoded now. for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes; if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current); @@ -156,6 +184,7 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl out.state.world_league_name = strings(get(modern, "league_names")); out.state.almanac.generated_players = uint32_t(num(get(modern, "generated_players"))); out.state.pools = pools_json(get(modern, "pools")); + out.state.exclusive_sponsors = sponsors_json(get(modern, "exclusive_sponsors")); for (const auto& [name, bytes] : docs) { if (!name.starts_with("history/season-")) continue; decode_almanac_season(bytes); // a damaged season fails here, not in the almanac screen diff --git a/src/modern/game/desk_actions.cpp b/src/modern/game/desk_actions.cpp index f049e1a..156b915 100644 --- a/src/modern/game/desk_actions.cpp +++ b/src/modern/game/desk_actions.cpp @@ -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 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; diff --git a/src/modern/game/desk_actions.hpp b/src/modern/game/desk_actions.hpp index 2407ec7..2de17f8 100644 --- a/src/modern/game/desk_actions.hpp +++ b/src/modern/game/desk_actions.hpp @@ -307,6 +307,18 @@ AdvertisingOfferList advertising_offers(const ModernState& g, int manager, int d AdvertisingOfferResult accept_advertising_offer(ModernState& g, const AdvertisingOfferRequest& request); +// Exclusive sponsor from a training camp stay (Modern; docs/new_engine/trainingslager.md). +// book_training_camp rolls the camp's sponsor_chance; a hit offers a shirt (about every third +// offer) or four boards at sponsor_bonus percent of the club's best regular offer for +// sponsor_months months, and posts a message. One offer or queued contract per manager. +void roll_exclusive_sponsor(ModernState& g, int manager, int resort, WatcomRandom& rand); +enum class ExclusiveSponsorAnswer { declined, started, queued, invalid }; +// The manager's answer. Accepted: the contract starts now when its place is free (the shirt +// without a running contract, enough free boards), else it waits for the place (queued). +ExclusiveSponsorAnswer answer_exclusive_sponsor(ModernState& g, int manager, bool accept); +// At the month change: a queued contract starts once its place is free. +void start_queued_exclusive_sponsor(ModernState& g, int manager); + // CheckAdvertisingRenewal: a click on a contract whose months ran out (sponsor set, months 0 - the // month change posted "kann verlängert werden", Month_MonthChange_TextPointer). The sponsor's demand (word // +8, the club attraction it wants) is scaled by W(95, 105) % (WatcomRandom); if it stays diff --git a/src/modern/game/modern_state.hpp b/src/modern/game/modern_state.hpp index 5952891..293dd55 100644 --- a/src/modern/game/modern_state.hpp +++ b/src/modern/game/modern_state.hpp @@ -63,6 +63,20 @@ struct ModernState : GameState { bool operator==(const PoolsColumns&) const = default; }; std::vector pools; + // Exclusive sponsor from a training camp stay (docs/new_engine/trainingslager.md), per manager. + struct ExclusiveSponsor { + bool offered = false; // an offer waits for the manager's answer + bool queued = false; // accepted while the place was taken: starts when it is free + uint8_t kind = 0; // 0 boards, 1 shirt + uint8_t units = 0; // boards of a board offer + uint8_t months = 0; // contract months + uint8_t sponsor = 0; // sponsor name index of the advertising list + uint32_t monthly = 0; // per board / for the shirt, per month + uint16_t score = 0; // the club's advertising score when offered (offer byte +8) + std::string camp; // the camp that brought it + bool operator==(const ExclusiveSponsor&) const = default; + }; + std::vector exclusive_sponsors; // Players whose age the data set gives (birth date); the others carry a placeholder the // career start replaces as in the original. Needed only while a career starts (not saved). std::vector world_age_known; diff --git a/src/modern/game/month.cpp b/src/modern/game/month.cpp index 44b01f5..4481ec3 100644 --- a/src/modern/game/month.cpp +++ b/src/modern/game/month.cpp @@ -3,6 +3,7 @@ #include "modern/game/modern_state.hpp" #include "modern/game/environment.hpp" #include "modern/game/month.hpp" +#include "modern/game/desk_actions.hpp" #include "game/trace.hpp" #include @@ -959,6 +960,8 @@ void month_change(ModernState& g, WatcomRandom& rand, MinuteReport& report, Game else turn_step = "month_change: advertising text", post_text(g, m, text_id(::bmh::layout::Month_MonthChange_TextPointer)); // the contract can be renewed } } + // Modern: a queued exclusive sponsor starts once its place is free (trainingslager.md) + for (int m = 0; m < managers; m++) modern::start_queued_exclusive_sponsor(g, m); // 2. new players on the transfer list turn_step = "month_change: new list entries"; new_list_entries(g, rand, report); diff --git a/src/modern/game/training_camps.cpp b/src/modern/game/training_camps.cpp index 571b131..aaad946 100644 --- a/src/modern/game/training_camps.cpp +++ b/src/modern/game/training_camps.cpp @@ -39,6 +39,11 @@ const CampCatalogue& default_camp_catalogue() { camp(15, "map:me", "Abu Dhabi Royal Training", "Abu Dhabi", "nation:ae", {6, 6, 6, 6}, 3200000); camp(16, "map:me", "Dubai Platinum Sports Camp", "Dubai", "nation:ae", {6, 6, 6, 6}, 3600000); camp(17, "map:eu", "Riviera Trainingscamp Belek", "Belek", "nation:tr", {5, 5, 5, 4}, 790000); + // The Middle East camps share their grades; a stay can bring an exclusive sponsor, the + // dearer the camp the likelier (15 / 30 / 45 %; trainingslager.md). + c.camps[14].sponsor_chance = 15; + c.camps[15].sponsor_chance = 30; + c.camps[16].sponsor_chance = 45; return c; }(); return catalogue; diff --git a/src/modern/game/training_camps.hpp b/src/modern/game/training_camps.hpp index 7f3b971..7f457dc 100644 --- a/src/modern/game/training_camps.hpp +++ b/src/modern/game/training_camps.hpp @@ -29,6 +29,9 @@ struct TrainingCamp { std::string name, place, country; int32_t base_price = 0; // the price is base_price + 5000 per squad player std::array quality{}; // pitch, fitness, catering, lodging (0-6) + // Exclusive sponsor (docs/new_engine/trainingslager.md): chance per stay in percent (0 = none), + // the offer's amount in percent of the best regular offer, its contract months. + int sponsor_chance = 0, sponsor_bonus = 200, sponsor_months = 12; }; struct CampCatalogue { diff --git a/src/modern/game/weekly.cpp b/src/modern/game/weekly.cpp index 09a5c68..d49f0ee 100644 --- a/src/modern/game/weekly.cpp +++ b/src/modern/game/weekly.cpp @@ -497,18 +497,8 @@ int club_attraction(const ModernState& g, int team) { return std::clamp(v, 0, 100); } -void advertising_offers(ModernState& g, int manager, WatcomRandom& rand, MinuteReport& report) { - (void)report; - if (g.memory.u8(::bmh::layout::CareerDuration) == 1) return; +AdvertisingBase advertising_base(ModernState& g, int manager) { Record rec = record(g, manager); - if (manager == 0) { - // "Es gibt neue Werbeangebote!" to every manager with a free advertising slot - uint32_t mask = 0x80000000u; - for (size_t m = 0; m < g.manager_teams.size(); m++) - for (int k = 0; k < 0x10; k++) - if (g.manager_records.at(m * kRecord + 0xa39 + size_t(k) * 0xc) == 0) mask |= 1u << m; - if (mask != 0x80000000u) post_text(g, int64_t(mask), text_id(::bmh::layout::Weekly_AdvertisingOffers_TextPointer)); - } int score = int16_t(int8_t(modern::club_attraction(g, int16_t(rec.u16(0x290))))); if (g.memory.u8(::bmh::layout::GameMode) == 3 && g.league_rounds.at(size_t(league_of(int16_t(rec.u16(0x290))))) > 0x11) { int t = rec.i32(0x320) / 100000; @@ -521,6 +511,23 @@ void advertising_offers(ModernState& g, int manager, WatcomRandom& rand, MinuteR score = int16_t(score) * 100 / 0x78; int base = (int16_t(score) * 60000 + 1000000) / 0xc; base = ((0xb4 - g.level * 5) * base) / 100; + return {score, base}; +} + +void advertising_offers(ModernState& g, int manager, WatcomRandom& rand, MinuteReport& report) { + (void)report; + if (g.memory.u8(::bmh::layout::CareerDuration) == 1) return; + Record rec = record(g, manager); + if (manager == 0) { + // "Es gibt neue Werbeangebote!" to every manager with a free advertising slot + uint32_t mask = 0x80000000u; + for (size_t m = 0; m < g.manager_teams.size(); m++) + for (int k = 0; k < 0x10; k++) + if (g.manager_records.at(m * kRecord + 0xa39 + size_t(k) * 0xc) == 0) mask |= 1u << m; + if (mask != 0x80000000u) post_text(g, int64_t(mask), text_id(::bmh::layout::Weekly_AdvertisingOffers_TextPointer)); + } + const AdvertisingBase value = modern::advertising_base(g, manager); + const int score = value.score, base = value.base; for (int kind = 0; kind < 3; kind++) for (int k = 0; k < 10; k++) { const size_t o = 0x8cc + size_t(kind) * 0x78 + size_t(k) * 0xc; diff --git a/src/modern/game/weekly.hpp b/src/modern/game/weekly.hpp index f22c53b..c1d9e9f 100644 --- a/src/modern/game/weekly.hpp +++ b/src/modern/game/weekly.hpp @@ -52,6 +52,11 @@ void season_ticket_compensation(ModernState& g, int manager); void season_ticket_compensation_source(ModernState& g, int manager, const SeasonTicketCompensationNoticeHook& notice = {}); void advertising_offers(ModernState& g, int manager, WatcomRandom& rand, MinuteReport& report); // TransferListCountdown2 +// The club's advertising score and the base of its offers (TransferListCountdown2, no draws): a +// board offer is about base / 16 per board and month, a shirt offer base / 4 (offer k: 70 + 6k +// resp. 80 + 4k percent of that, then +-25 %). +struct AdvertisingBase { int score = 0, base = 0; }; +AdvertisingBase advertising_base(ModernState& g, int manager); // TransferListCountdown(all): the days left of every listed player count down; at 0 the best bid wins // (with `all`, at the season end, every list is settled at once) void transfer_list_countdown(ModernState& g, GameRandom& game, WatcomRandom& rand, MinuteReport& report, bool all = false, diff --git a/tests/modern_camp_tests.cpp b/tests/modern_camp_tests.cpp index a2b8b07..6d4fb43 100644 --- a/tests/modern_camp_tests.cpp +++ b/tests/modern_camp_tests.cpp @@ -5,6 +5,7 @@ #include #include +#include "formats/executable_layout.hpp" #include "game/random.hpp" #include "modern/game/desk_actions.hpp" #include "modern/game/training_camps.hpp" @@ -117,6 +118,55 @@ int main() { check(training_camp_booking_block(g, 0) == TrainingCampBookingBlock::invalid_request, "no camp at the national coach's desk"); } + { + // Exclusive sponsor: a camp without a sponsor chance draws nothing; an accepted offer + // starts at once on a free place, waits for a taken one and starts when it is free. + ModernState g = squad(); + g.training_camps = {camp({6, 6, 6, 6})}; + g.memory.add_block(::bmh::layout::AdGroupId, 1); + WatcomRandom rand(5); + const uint64_t calls = rand.calls(); + roll_exclusive_sponsor(g, 0, 0, rand); + check(rand.calls() == calls && (g.exclusive_sponsors.empty() || !g.exclusive_sponsors[0].offered), + "no sponsor chance: no draw, no offer"); + check(answer_exclusive_sponsor(g, 0, true) == ExclusiveSponsorAnswer::invalid, "no offer to answer"); + + const auto row = [&](int slot) { return size_t(0xa34 + slot * 0xc); }; + const auto amount = [&](int slot) { + const size_t at = row(slot); + return uint32_t(g.manager_records[at]) | uint32_t(g.manager_records[at + 1]) << 8 | + uint32_t(g.manager_records[at + 2]) << 16 | uint32_t(g.manager_records[at + 3]) << 24; + }; + ModernState::ExclusiveSponsor shirt; + shirt.offered = true, shirt.kind = 1, shirt.units = 1, shirt.months = 12, shirt.sponsor = 3; + shirt.monthly = 300000, shirt.score = 50, shirt.camp = "resort:test"; + g.exclusive_sponsors = {shirt}; + check(answer_exclusive_sponsor(g, 0, true) == ExclusiveSponsorAnswer::started, "free shirt: starts at once"); + check(amount(14) == 300000 && g.manager_records[row(14) + 5] == 12 && !g.exclusive_sponsors[0].offered, + "shirt contract installed (amount, months)"); + + shirt.monthly = 350000; + g.exclusive_sponsors = {shirt}; + check(answer_exclusive_sponsor(g, 0, true) == ExclusiveSponsorAnswer::queued, "taken shirt: queued"); + check(amount(14) == 300000 && g.exclusive_sponsors[0].queued, "running shirt contract untouched"); + start_queued_exclusive_sponsor(g, 0); + check(g.exclusive_sponsors[0].queued, "still queued while the shirt is taken"); + for (size_t i = 0; i < 0xc; ++i) g.manager_records[row(14) + i] = 0; // the running contract ended + start_queued_exclusive_sponsor(g, 0); + check(amount(14) == 350000 && !g.exclusive_sponsors[0].queued, "queued shirt starts once free"); + + ModernState::ExclusiveSponsor boards = shirt; + boards.kind = 0, boards.units = 4, boards.monthly = 40000; + g.exclusive_sponsors = {boards}; + check(answer_exclusive_sponsor(g, 0, true) == ExclusiveSponsorAnswer::started, "four free boards: start at once"); + int taken = 0; + for (int slot = 0; slot < 14; ++slot) taken += amount(slot) == 40000; + check(taken == 4, "four boards installed"); + + g.exclusive_sponsors = {shirt}; + check(answer_exclusive_sponsor(g, 0, false) == ExclusiveSponsorAnswer::declined && !g.exclusive_sponsors[0].offered, + "declined offer is gone"); + } if (failures) return 1; std::puts("modern camp checks passed"); return 0; diff --git a/tests/modern_season_sim.cpp b/tests/modern_season_sim.cpp index 0cd3a3e..ade2c28 100644 --- a/tests/modern_season_sim.cpp +++ b/tests/modern_season_sim.cpp @@ -493,6 +493,7 @@ int main(int argc, char** argv) { bool listed_for_sale = false; int ad_contracts = 0; // SIM_ADVERTISING: contracts accepted int camp_stays = 0; // SIM_CAMP: training camp stays booked + int sponsor_offers = 0, sponsor_started = 0, sponsor_queued = 0; // SIM_SPONSOR for (; played < turns; played++) { // SIM_ADVERTISING=1: the manager keeps his advertising places filled, as every // player does (the largest income besides the gate): an expired contract is renewed @@ -506,6 +507,16 @@ int main(int argc, char** argv) { if (modern::training_camp_booking_block(g, 0) == TrainingCampBookingBlock::none && modern::book_training_camp(g, 0, resort, session.rand())) ++camp_stays; + // SIM_SPONSOR=1: an exclusive sponsor offer from the stay is accepted + if (std::getenv("SIM_SPONSOR") && !g.exclusive_sponsors.empty() && g.exclusive_sponsors[0].offered) { + ++sponsor_offers; + std::printf("exclusive sponsor offer at turn %d: %s, %u per month%s, %d months\n", played, + g.exclusive_sponsors[0].kind == 1 ? "shirt" : "4 boards", g.exclusive_sponsors[0].monthly, + g.exclusive_sponsors[0].kind == 1 ? "" : " per board", int(g.exclusive_sponsors[0].months)); + const auto answer = modern::answer_exclusive_sponsor(g, 0, true); + sponsor_started += answer == modern::ExclusiveSponsorAnswer::started; + sponsor_queued += answer == modern::ExclusiveSponsorAnswer::queued; + } } // SIM_TOTO=: the manager plays the Toto whenever a coupon is open, 400,000 in // all spread over the columns: the stronger side (team strength) wins, column k > 1 @@ -683,6 +694,9 @@ int main(int argc, char** argv) { } if (std::getenv("SIM_ADVERTISING")) std::printf("%d advertising contracts accepted (SIM_ADVERTISING=1)\n", ad_contracts); if (std::getenv("SIM_CAMP")) std::printf("%d training camp stays (SIM_CAMP=%s)\n", camp_stays, std::getenv("SIM_CAMP")); + if (std::getenv("SIM_SPONSOR")) + std::printf("exclusive sponsors: %d offers, %d started at once, %d queued (SIM_SPONSOR=1)\n", sponsor_offers, + sponsor_started, sponsor_queued); if (std::getenv("SIM_TOTO")) { int won_coupons = 0; std::printf("toto (SIM_TOTO=%s): %d coupons, paid %llu, won %llu, return %.1f %%; hits per column:", std::getenv("SIM_TOTO"),