// SPDX-License-Identifier: GPL-3.0-only #pragma once // The game state of the Modern season core. // // Modern started as a fork of the Classic season core (docs/new_engine). Its season // functions take ModernState instead of GameState: the shared parts (formats, match // core, line-ups, ratings) keep working on the GameState base, and overload resolution // always prefers the Modern season function over a Classic one of the same name. // Modern-only data (world layout, UTF-8 names, ...) is added here, never to GameState. #include #include #include #include #include #include #include #include "game/state.hpp" #include "game/world_layout.hpp" #include "modern/game/almanac.hpp" #include "modern/game/training_camps.hpp" namespace bmh::modern { // Dimensions of the running world (WorldLayout). Modern code uses these accessors where // the Classic sources have the fixed numbers (138 league clubs, 90 German clubs, 168, the // pool slots 0xb70/0xb9c/0xbec/0xc00, 3150 slots); no_team() replaces kNoTeam (0x165). inline int league_clubs() { return world_layout().league_teams; } inline int german_clubs() { return world_layout().german_teams; } inline int first_foreign_cup() { return world_layout().first_foreign_cup(); } inline size_t transfer_list_slot() { return world_layout().transfer_list; } inline size_t free_agent_slot() { return world_layout().free_agents; } inline size_t foreign_offer_slot() { return world_layout().foreign_offers; } inline size_t pool_end_slot() { return world_layout().pool_end; } inline size_t total_squad_slots() { return world_layout().total_slots; } // The callbacks the shared match core uses for season functions (SeasonHooks). const SeasonHooks& season_hooks(); // The form history per manager (manager_results) holds 10 bytes per club with a record // (Classic: 168 clubs, stride 0x690). inline size_t manager_history_stride() { return size_t(first_foreign_cup()) * 10; } struct ModernState : GameState { // --- Modern world (docs/new_engine, M3); empty when the game runs on Classic data ------- // UTF-8 names and OBW identities by runtime index. The single-byte name pools of // GameState stay for the engine texts; interfaces show these. std::vector world_club_id, world_club_name, world_club_short; // per team std::vector world_player_id, player_first, player_last; // per player std::vector player_nation; // nation id per player std::vector world_league_id, world_league_name; // per league index // Training camps (M4): Classic data gives the eight original resorts, a Modern world its catalogue. std::vector camp_maps; std::vector training_camps; // The football almanac (docs/new_engine/almanach.md): every match of the career. Almanac almanac; // Toto with up to six columns (docs/new_engine/toto.md), per manager. Column 1 is the // original coupon (Coupon + manager * 0x14); columns 2-6 and the last settlement live here. struct PoolsColumns { std::vector> extra; // columns 2-6, tips 1 home, 0 draw, 2 away std::vector hits; // hits per column of the last settlement uint32_t paid = 0, won = 0; // stakes and fee, winnings of the last settlement 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; // Identities of the interface contract (docs/new_engine/ui-anbindung.md): the career and the // human managers per manager slot ("manager:", never reused within a career). std::string career_id; std::vector manager_ids; uint32_t manager_serial = 0; // Optional Modern-only display metadata, keyed by stable manager identity. // Original records remain byte-compatible and are the fallback for older saves. struct ManagerPresentation { std::string id, name, portrait_style = "photo"; bool operator==(const ManagerPresentation&) const = default; }; std::vector manager_presentations; // Runtime slot zero temporarily contains the national coach. These read-only // mappings recover the human identity and its original/backup record. int human_manager_slot(int runtime_slot) const; int manager_record_slot(int human_slot) const; const ManagerPresentation* manager_presentation_for_human(int slot) const { if (slot < 0 || size_t(slot) >= manager_ids.size()) return nullptr; for (const auto& p : manager_presentations) if (p.id == manager_ids[size_t(slot)]) return &p; return nullptr; } const ManagerPresentation* manager_presentation(int runtime_slot) const { return manager_presentation_for_human(human_manager_slot(runtime_slot)); } // The press journal (content/press_journal.hpp): business events the almanac cannot give // (transfers, contracts, toto, seasons, managers), noted once when they happen and saved, so // the interface's news keep their ids. `data` is the event's facts as JSON text. struct PressEntry { std::string id, type, team; // team: the contract id of the scope team uint32_t date = 0; // day counter std::string data; bool operator==(const PressEntry&) const = default; }; std::vector press; uint32_t press_serial = 0; // The monthly result for the press: the month (year * 12 + month - 1, 0 = not yet started) and // each manager's cash at its start; the change over a month is finance.profit / finance.loss. uint32_t press_month = 0; std::vector press_month_cash; // The interface's mailbox marks per manager id and message id (news.update): bit 0 read, // bit 1 in the trash. Keeping a message is the original's own flag in the mailbox. std::map> news_marks; // How and when the career ended ("" while it runs; "career_completed" when the set duration ran // out, "last_human_resigned" when the only or last human manager gave up): the interface's // terminationReason and the end of the employments. std::string career_end_reason; uint32_t career_end_date = 0; // The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the // four stages of a Modern world. Older Modern saves are converted when loaded. uint8_t traffic_scale = 0; // The annual general meeting (docs/new_engine/hauptversammlung.md), per manager slot: what the // members compare the season with - his assets and his club's place over all leagues when // they last voted (or when he took the club) - and the season they last voted in. struct AssemblyMemory { int64_t assets = 0; int32_t place = -1; // -1: not yet set (an older save, a manager who has just joined) int32_t voted_season = -1; bool operator==(const AssemblyMemory&) const = default; }; std::vector assembly; // The stadium's name and its naming rights (docs/new_engine/namensrecht.md), per manager slot: // the name the manager gave it (empty: the default), and while the name is sold the sponsor // (name index of the advertising list), what he pays a month and the months left. struct StadiumName { std::string name; uint8_t sponsor = 0xff; uint32_t monthly = 0; uint16_t months = 0; bool operator==(const StadiumName&) const = default; }; std::vector stadiums; // International marketing (docs/new_engine/vermarktung.md), per manager slot: the monthly // budget in euros and the reach it has built up so far, in per mille. struct Marketing { int32_t budget = 0; uint16_t reach = 0; bool operator==(const Marketing&) const = default; }; std::vector marketing; // Shirt numbers (docs/new_engine/rueckennummern.md) by player: 1-99, 0 = none yet. std::vector shirt_numbers; // Whether a manager the meeting votes out has to leave his club. On until the options offer it. bool dismissals = true; // 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; ModernState() { season_hooks = &modern::season_hooks(); } // Takes over a state built by shared code (save loading, career setup). ModernState(GameState&& g) : GameState(std::move(g)) { season_hooks = &modern::season_hooks(); } ModernState(const GameState& g) : GameState(g) { season_hooks = &modern::season_hooks(); } }; // A player who came from the data set (not a new person the engine made of his index): his // values are the data set's (docs/new_engine/balance.md). Without a world: nobody. inline bool keeps_world_values(const ModernState& g, int player) { return player >= 0 && size_t(player) < g.world_player_id.size() && !g.world_player_id[size_t(player)].empty() && !g.world_player_id[size_t(player)].starts_with("player:gen-"); } // A player of the data set whose age it gives (balance.md). inline bool keeps_world_age(const ModernState& g, int player) { return keeps_world_values(g, player) && size_t(player) < g.world_age_known.size() && g.world_age_known[size_t(player)]; } } // namespace bmh::modern