diff --git a/CMakeLists.txt b/CMakeLists.txt index a0bd001..ccb3944 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,6 +220,7 @@ add_library(bmhcore STATIC src/game/league_pairings.cpp src/game/source_tip.cpp src/game/table_forecast.cpp + src/game/profile_runtime.cpp src/game/state.cpp src/game/rating.cpp src/game/match.cpp diff --git a/src/game/career.cpp b/src/game/career.cpp index 821368d..9e01685 100644 --- a/src/game/career.cpp +++ b/src/game/career.cpp @@ -12,12 +12,12 @@ namespace bmh { namespace { -constexpr size_t kPoolSlots = 2928; // CareerRuntimeField: the clubs' squads end here -constexpr size_t kTailFrom = 2928 + 40; -constexpr size_t kTailTo = 2972; // CareerRuntimeField2 -constexpr size_t kExtraSlots = 3096; // CareerSession_DataDirectory_RuntimeField4: 54 extra players from here -constexpr size_t kSquadSlots = 3096 + 54; -constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField +const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField: the clubs' squads end here +const int& kTailFrom = runtime_dimensions.market_special_first; +const int& kTailTo = runtime_dimensions.free_first; // CareerRuntimeField2 +const int& kExtraSlots = runtime_dimensions.extra_slots_first; // CareerSession_DataDirectory_RuntimeField4: 54 extra players from here +const int& kSquadSlots = runtime_dimensions.total_slots; +const int& kLeagueTeams = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField // LeagueSizes: clubs per league; LeagueStrengthRanges: (minimum, maximum) strength per league. // (the clubs per league are kLeagueSizes, schedule.hpp) diff --git a/src/game/profile_runtime.cpp b/src/game/profile_runtime.cpp new file mode 100644 index 0000000..afd14e7 --- /dev/null +++ b/src/game/profile_runtime.cpp @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "game/profile_runtime.hpp" +#include "formats/data_profile.hpp" +namespace bmh { +void install_runtime_profile(const DataProfile& profile) { + profile.validate(); + RuntimeDimensions next; + next.league_teams=int(profile.counts.league_teams); + next.cup_teams=int(profile.counts.cup_teams); + next.big_squad_teams=int(profile.big_squad_teams); + next.record_teams=int(profile.counts.n42); + next.national_first=int(profile.national_first); + next.pool_first=int(profile.pool_first()); + next.market_special_first=next.pool_first+40; + next.free_first=next.pool_first+44; + next.foreign_free_first=next.pool_first+124; + next.national_slots_first=int(profile.national_slots_first()); + next.extra_slots_first=int(profile.extra_slots_first()); + next.total_slots=int(profile.total_slots()); + next.expanded=profile.extended(); + runtime_dimensions=next; +} +} diff --git a/src/game/profile_runtime.hpp b/src/game/profile_runtime.hpp new file mode 100644 index 0000000..c338ac5 --- /dev/null +++ b/src/game/profile_runtime.hpp @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +namespace bmh { +struct DataProfile; +// Explicitly distinct concepts: German clubs, league clubs and large rosters. +// One installation is active per process, like the existing fixture/rule tables. +struct RuntimeDimensions { + int domestic_teams=90, league_teams=138, cup_teams=30, big_squad_teams=90; + int record_teams=168; + int national_first=357, pool_first=2928, market_special_first=2968; + int free_first=2972, foreign_free_first=3052, national_slots_first=3072; + int extra_slots_first=3096, total_slots=3150; + bool expanded=false; +}; +inline RuntimeDimensions runtime_dimensions{}; +void install_runtime_profile(const DataProfile& profile); +} diff --git a/src/game/schedule.cpp b/src/game/schedule.cpp index b56d090..f406f6b 100644 --- a/src/game/schedule.cpp +++ b/src/game/schedule.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "game/schedule.hpp" +#include "game/profile_runtime.hpp" #include "formats/executable_layout.hpp" #include "formats/le.hpp" @@ -123,16 +124,16 @@ std::vector generate_fixtures(int teams, int matchday, int rounds, int return out; } -int league_table_teams(int league) { return league < 5 ? kLeagueSizes[0] : kLeagueSizes[5]; } +int league_table_teams(int league) { return runtime_dimensions.expanded ? kLeagueSizes[league] : (league < 5 ? kLeagueSizes[0] : kLeagueSizes[5]); } void set_league_sizes(const uint8_t (&sizes)[kLeagueCount]) { int total = 0; for (int l = 0; l < kLeagueCount; l++) total += sizes[l]; const auto has_table = [](int teams) { return teams == 20 || teams == 18 || teams == 16 || teams == 12; }; - if (total != 138 || !has_table(sizes[0]) || !has_table(sizes[5])) - throw std::invalid_argument("league sizes do not describe 138 league teams with fixture tables"); + if (total != runtime_dimensions.league_teams || !has_table(sizes[0]) || !has_table(sizes[5])) + throw std::invalid_argument("league sizes do not match the installed profile and fixture tables"); for (int l = 0; l < kLeagueCount; l++) - if (sizes[l] < 2 || sizes[l] > (l < 5 ? sizes[0] : sizes[5])) + if (sizes[l] < 2 || (!runtime_dimensions.expanded && sizes[l] > (l < 5 ? sizes[0] : sizes[5])) || (runtime_dimensions.expanded && !has_table(sizes[l]))) throw std::invalid_argument("a league is larger than its fixture table"); for (int l = 0; l < kLeagueCount; l++) kLeagueSizes[l] = sizes[l]; } diff --git a/src/game/state.cpp b/src/game/state.cpp index c102de5..a10096c 100644 --- a/src/game/state.cpp +++ b/src/game/state.cpp @@ -11,9 +11,9 @@ namespace bmh { namespace { // Squad table layout constants of V2.24 (TeamsWithSquads, LargeSquadClubCount, NoTeamSquadStart). -constexpr int kBigSquadTeams = 90; -constexpr size_t kNoTeamSquadStart = 3072; -constexpr int kTeamsWithSquads = 168; +const int& kBigSquadTeams = runtime_dimensions.big_squad_teams; +const int& kNoTeamSquadStart = runtime_dimensions.national_slots_first; +const int& kTeamsWithSquads = runtime_dimensions.record_teams; // C-style signed division by 8 as compiled by Watcom (rounds toward zero). int div8(int x) { return x / 8; } @@ -158,7 +158,7 @@ void GameState::formation_position(int team, int slot, int& x, int& y) const { SquadRange squad_range(int team) { if (team == kNoTeam) return {kNoTeamSquadStart, 24}; if (team < kBigSquadTeams) return {size_t(team) * 24, 24}; - if (team < 138) return {size_t(team) * 16 + kBigSquadTeams * 8, 16}; + if (team < runtime_dimensions.league_teams) return {size_t(team) * 16 + kBigSquadTeams * 8, 16}; return {0, 0}; } diff --git a/src/game/state.hpp b/src/game/state.hpp index a5a3423..a54b8f1 100644 --- a/src/game/state.hpp +++ b/src/game/state.hpp @@ -16,6 +16,7 @@ #include "formats/savestate.hpp" #include "formats/textd.hpp" #include "game/memory.hpp" +#include "game/profile_runtime.hpp" #include "game/random.hpp" #include "game/reality_motion.hpp" @@ -26,7 +27,7 @@ struct TransferDecisionEvent; struct HumanBuyerSaleHooks; // Special team id used by the original for "no club" / the player pool (0x165). -constexpr int kNoTeam = 0x165; +inline const int& kNoTeam = runtime_dimensions.national_first; // Squad slot values (u16 in table *SquadSlots): // bits 0-11 player id, 0xFFF = empty slot diff --git a/src/game/weekly.cpp b/src/game/weekly.cpp index e4671fa..757514d 100644 --- a/src/game/weekly.cpp +++ b/src/game/weekly.cpp @@ -32,8 +32,8 @@ constexpr size_t kBoard = 0x840; // tactics board of a manager constexpr size_t kBoardSlot = 0x58; constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 entries of 0x58 bytes, one per pool slot constexpr uint32_t kListEntry = 0x58; -constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField: first squad slot of the transfer pool -constexpr int kLeagueClubs = 0x8a; // CareerSession_DispatchLineup_RuntimeField +const int& kPoolSlots = runtime_dimensions.pool_first; // CareerRuntimeField: first squad slot of the transfer pool +const int& kLeagueClubs = runtime_dimensions.league_teams; // CareerSession_DispatchLineup_RuntimeField constexpr int kBigSquadClubs = 90; // TeamsWithSquads // Offers and incidents (Bool): 1 in WeeklyRuntimeField[kind] is only possible while the @@ -154,8 +154,9 @@ int squad_count(const GameState& g, int team, int flags) { // SlotTeam: club of an absolute squad slot (-1 for the pool). int slot_team(int slot) { - if (slot < kBigSquadClubs * 24) return slot / 24; - if (slot < int(kPoolSlots)) return (slot - kBigSquadClubs * 24) / 16 + kBigSquadClubs; + const int large=runtime_dimensions.big_squad_teams; + if (slot < large * 24) return slot / 24; + if (slot < int(kPoolSlots)) return (slot - large * 24) / 16 + large; return -1; } @@ -605,7 +606,7 @@ void transfer_bid(GameState& g, int slot, uint32_t list, bool high, int months, const int r = rand.range(int16_t(need) + 3, int16_t(need) + 0xd); if (int16_t(diff) < r) score += int(int16_t(need + 0xe - diff)) * 16 + 100; else score -= int16_t(diff) * 8; - const int8_t* wanted = team < kBigSquadClubs ? kWantedBig : kWantedSmall; + const int8_t* wanted = team < runtime_dimensions.big_squad_teams ? kWantedBig : kWantedSmall; int16_t d = int16_t(wanted[position] - int8_t(count[position])); if (d < 0) { score += int(d) << 8; diff --git a/tests/data_profile_tests.cpp b/tests/data_profile_tests.cpp index c9b73be..17803a8 100644 --- a/tests/data_profile_tests.cpp +++ b/tests/data_profile_tests.cpp @@ -1,8 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/data_profile.hpp" #include "formats/savestate.hpp" +#include "game/profile_runtime.hpp" +#include "game/state.hpp" +#include "game/weekly.hpp" +#include "game/schedule.hpp" #include "formats/executable_layout.hpp" #include +#include #include #include #include @@ -26,6 +31,21 @@ int main()try { check(decoded.block(bmh::layout::PlayerConditionTechniqueForm).size == profile.counts.players * 4, "player block ignored configured profile counts"); } + bmh::install_runtime_profile(expanded); + check(bmh::squad_range(163).first==3912 && bmh::squad_range(163).count==24, + "last international club does not have a full-size squad"); + check(bmh::squad_range(bmh::kNoTeam).first==4080 && bmh::kNoTeam==383, + "national squad overlaps the expanded clubs/pool"); + check(bmh::slot_team(3935)==163 && bmh::slot_team(3936)==-1, + "absolute slot ownership was truncated or misclassified"); + uint8_t sizes[9];std::copy(expanded.leagues.begin(),expanded.leagues.end(),sizes); + bmh::set_league_sizes(sizes); + check(bmh::league_table_teams(6)==20 && bmh::league_table_teams(5)==18, + "England incorrectly shares the smaller foreign fixture table"); + bmh::install_runtime_profile(classic);std::copy(classic.leagues.begin(),classic.leagues.end(),sizes);bmh::set_league_sizes(sizes); + check(bmh::runtime_dimensions.record_teams==168,"Classic cup-only rating boundary changed"); + check(bmh::squad_range(90).first==2160 && bmh::squad_range(90).count==16 && bmh::kNoTeam==357, + "switching back did not restore original squad conventions"); auto invalid=expanded;invalid.counts.players=4095;bool rejected=false; try{invalid.validate();}catch(const bmh::FormatError&){rejected=true;} check(rejected,"Player-ID sentinel collision accepted");