From 31ff36fb09d5063aa9a659d6febd9d4816950177 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 00:15:40 +0100 Subject: [PATCH] Record sizes in one header; the engine's club count from the world layout game/records.hpp names the sizes of the manager record, the tactics board, a board slot and the club record; 58 local copies of these numbers refer to it. The six local club count constants of the engine (138) are gone, their uses read world_layout().league_teams. Co-Authored-By: Claude --- src/app/career_session.cpp | 2 +- src/game/balance_plan.cpp | 2 +- src/game/bank_credit.cpp | 2 +- src/game/career.cpp | 7 +++---- src/game/club_info.cpp | 2 +- src/game/club_player_detail.cpp | 2 +- src/game/desk.cpp | 2 +- src/game/desk_actions.cpp | 6 +++--- src/game/highscore.cpp | 2 +- src/game/lineup.cpp | 7 +++---- src/game/matchday.cpp | 6 +++--- src/game/matchday_setup.cpp | 10 ++++------ src/game/month.cpp | 9 ++++----- src/game/national.cpp | 6 +++--- src/game/other_games.cpp | 2 +- src/game/poach.cpp | 2 +- src/game/prediction.cpp | 11 +++++------ src/game/records.hpp | 20 +++++++++++++++++++ src/game/reschedule.cpp | 2 +- src/game/search_profile.cpp | 2 +- src/game/season.cpp | 4 ++-- src/game/stadium_blocks.cpp | 2 +- src/game/state.hpp | 1 + src/game/top_scorers.cpp | 1 - src/game/week.cpp | 2 +- src/game/weekly.cpp | 33 +++++++++++++++---------------- src/ui/advertising.cpp | 4 ++-- src/ui/analytics.cpp | 2 +- src/ui/club_info.cpp | 2 +- src/ui/contracts.cpp | 6 +++--- src/ui/finance_totals.cpp | 2 +- src/ui/incoming_transfer.cpp | 2 +- src/ui/minute_statistics.cpp | 2 +- src/ui/pending_offer.cpp | 2 +- src/ui/series_records.cpp | 4 ++-- src/ui/strengths_state.cpp | 1 - src/ui/training_camp.cpp | 2 +- src/ui/transfer_history.cpp | 2 +- src/ui/transfer_history_tests.cpp | 2 +- src/ui/transfer_market.cpp | 1 - 40 files changed, 96 insertions(+), 85 deletions(-) create mode 100644 src/game/records.hpp diff --git a/src/app/career_session.cpp b/src/app/career_session.cpp index ea3b959..d7d946a 100644 --- a/src/app/career_session.cpp +++ b/src/app/career_session.cpp @@ -1183,7 +1183,7 @@ bool other_games_source_manager_owned(const GameState& g,int team) { throw FormatError("other games: invalid Source manager count for club detail redraw"); for(size_t manager=0;manager=national_record+2) return int(uint16_t(g.manager_records[national_record]| diff --git a/src/game/balance_plan.cpp b/src/game/balance_plan.cpp index 5422579..b2e485b 100644 --- a/src/game/balance_plan.cpp +++ b/src/game/balance_plan.cpp @@ -21,7 +21,7 @@ namespace bmh { namespace { -constexpr size_t kRecordSize = 0xb0c; +constexpr size_t kRecordSize = kManagerRecordSize; constexpr uint32_t kPlanTicketPrice = ::bmh::layout::PlanTicketPrice; // one byte per manager // BalancePlanRuntimeField: months left in the business year by calendar month (July: 12, June: 1) constexpr int8_t kMonthsLeft[13] = {0, 6, 5, 4, 3, 2, 1, 12, 11, 10, 9, 8, 7}; diff --git a/src/game/bank_credit.cpp b/src/game/bank_credit.cpp index acb1d92..5b5891c 100644 --- a/src/game/bank_credit.cpp +++ b/src/game/bank_credit.cpp @@ -20,7 +20,7 @@ namespace bmh { namespace { constexpr uint32_t kLoans = ::bmh::layout::Loans; -constexpr size_t kRecord = 0xb0c; +constexpr size_t kRecord = kManagerRecordSize; int32_t signed_word(uint32_t v) { return std::bit_cast(v); } uint32_t word(int32_t v) { return std::bit_cast(v); } int32_t add(int32_t a, int32_t b) { return signed_word(word(a) + word(b)); } diff --git a/src/game/career.cpp b/src/game/career.cpp index e566167..a6dd8e8 100644 --- a/src/game/career.cpp +++ b/src/game/career.cpp @@ -24,7 +24,6 @@ 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 // LeagueSizes: clubs per league; LeagueStrengthRanges: (minimum, maximum) strength per league. // (the clubs per league are league_system().sizes, schedule.hpp) @@ -85,7 +84,7 @@ void startup_players(GameState& g, GameRandom& game, WatcomRandom& rand) { generate_player(g, int16_t(g.squad_slots.at(kExtraSlots + i)), int16_t(level), game, rand); } int previous = 0, index = -1; // local_18, local_1c - for (int team = 0; team < kLeagueTeams; team++) { + for (int team = 0; team < world_layout().league_teams; team++) { const int league = team_league(team); index = league == previous ? index + 1 : 0; previous = league; @@ -256,7 +255,7 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xb0c; +constexpr size_t kRecord = kManagerRecordSize; uint16_t team_of(const GameState& g, int m) { const size_t at = size_t(m) * kRecord + 0x290; @@ -351,7 +350,7 @@ void put32(std::vector& v, size_t o, uint32_t x) { // CareerAddManager2(team, mode): condition and technique of every player of a league club around // a level of its league (mode 0 random W(min, max), 1 min + 3, 2 the middle + 1, 3 max - 3). void set_club_strength(GameState& g, int team, int mode, WatcomRandom& rand) { - if (team >= kLeagueTeams) return; + if (team >= world_layout().league_teams) return; const int league = team_league(team); const int lo = kLeagueStrength[league][0], hi = kLeagueStrength[league][1]; int level = mode; diff --git a/src/game/club_info.cpp b/src/game/club_info.cpp index b3c4c16..8d38ecf 100644 --- a/src/game/club_info.cpp +++ b/src/game/club_info.cpp @@ -55,7 +55,7 @@ uint8_t set_club_info_category(GameState& g, int team, int requested) { if (manager_count > 4 || manager_count > g.manager_teams.size()) throw std::invalid_argument("club info: truncated manager teams"); const bool national = !g.manager_teams.empty() && g.manager_teams.front() == kNoTeam; - constexpr size_t national_club = 4 * 0xb0c + 0x290; + constexpr size_t national_club = 4 * kManagerRecordSize + 0x290; if (national && g.manager_records.size() < national_club + 2) throw std::invalid_argument("club info: truncated national manager record"); // FindManagerForClub matches the first ManagerCount teams, irrespective of manager name, diff --git a/src/game/club_player_detail.cpp b/src/game/club_player_detail.cpp index a29ca38..d461073 100644 --- a/src/game/club_player_detail.cpp +++ b/src/game/club_player_detail.cpp @@ -19,7 +19,7 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xb0c, kBoard = 0x840, kBoardRow = 0x58; +constexpr size_t kRecord = kManagerRecordSize, kBoard = kTacticsBoardSize, kBoardRow = kTacticsBoardSlotSize; uint16_t record_word(const GameState& g, size_t manager, size_t offset) { const size_t at = manager * kRecord + offset; diff --git a/src/game/desk.cpp b/src/game/desk.cpp index ed89902..ef76a2b 100644 --- a/src/game/desk.cpp +++ b/src/game/desk.cpp @@ -22,7 +22,7 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xB0C; +constexpr size_t kRecord = kManagerRecordSize; // DeskRuntimeField: which of the 0x36 desk buttons exist, for the pseudo club 0x165 and per // game mode (GameMode; the table for mode m starts at DeskRuntimeField + m * 0x36). diff --git a/src/game/desk_actions.cpp b/src/game/desk_actions.cpp index 9944d8f..87e5012 100644 --- a/src/game/desk_actions.cpp +++ b/src/game/desk_actions.cpp @@ -33,7 +33,7 @@ void wr32(std::vector& v, size_t o, int32_t x) { } // Manager record (ManagerRecords + manager * 0xb0c) offsets used here. -constexpr size_t kRecordSize = 0xb0c; +constexpr size_t kRecordSize = kManagerRecordSize; constexpr size_t kTeam = 0x290; // club of the manager (low byte used) constexpr size_t kFocus = 0xc1; // four training camp sliders 0..15 constexpr size_t kStays = 0x21f; // bits 0-6 stays, bit 7 "in a camp this week" @@ -1827,7 +1827,7 @@ namespace bmh { bool submit_pools_coupon(GameState& g, int manager, uint32_t stake, const std::array& tips) { - constexpr size_t kRecord = 0xb0c; + constexpr size_t kRecord = kManagerRecordSize; constexpr uint32_t kCoupon = ::bmh::layout::Coupon; constexpr uint32_t kCouponBytes = 5 * 0x14; if (manager < 0 || size_t(manager) >= g.manager_teams.size() || @@ -1849,7 +1849,7 @@ bool submit_pools_coupon(GameState& g, int manager, uint32_t stake, namespace bmh { namespace { -constexpr size_t kAdRecord = 0xb0c; +constexpr size_t kAdRecord = kManagerRecordSize; constexpr size_t kAdPool = 0x8cc; constexpr size_t kAdContracts = 0xa34; constexpr size_t kAdContractBytes = 0x0c; diff --git a/src/game/highscore.cpp b/src/game/highscore.cpp index 8cebd5e..26ca276 100644 --- a/src/game/highscore.cpp +++ b/src/game/highscore.cpp @@ -16,7 +16,7 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xb0c; +constexpr size_t kRecord = kManagerRecordSize; // OpenBMH deviates from the original: reads the supported edition-specific high-score format from the loaded image. // supported rule profile executable HighscoreRuntimeField..a5144, verified against the installed LE image. constexpr std::array kHistoryWeights{3, 5, 4, 30, 20, 10, 5, 40}; diff --git a/src/game/lineup.cpp b/src/game/lineup.cpp index 76328fa..ca379ac 100644 --- a/src/game/lineup.cpp +++ b/src/game/lineup.cpp @@ -27,9 +27,8 @@ constexpr int8_t kTypeBySlot[24] = {2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 0, 1, 2, 2, constexpr int16_t kUnavailable = -32000; // 0x8300 constexpr int kMismatchWeight = 0x40; // local_54 for computer teams -constexpr size_t kManagerRecordSize = 0xB0C; -constexpr size_t kManagerBoardSize = 0x840; -constexpr size_t kBoardRowSize = 0x58; +constexpr size_t kManagerBoardSize = kTacticsBoardSize; +constexpr size_t kBoardRowSize = kTacticsBoardSlotSize; constexpr size_t kFormationManagerSize = 0x160; constexpr size_t kNativeFormationBlockSize = 0x580; @@ -650,7 +649,7 @@ void auto_lineup(GameState& g, int team, int mode) { } void auto_lineup_parked_club_source(GameState& g, int team, int mode) { - constexpr size_t record = 4*0xb0c+0x290; + constexpr size_t record = 4 * kManagerRecordSize+0x290; if (team<0 || team>=138 || g.manager_teams.size()!=1 || g.manager_teams[0]!=kNoTeam || !g.memory.has(::bmh::layout::CoachActive) || g.memory.u8(::bmh::layout::CoachActive)==0 || !g.memory.has(::bmh::layout::ManagerCount) || g.memory.u8(::bmh::layout::ManagerCount)!=1 || diff --git a/src/game/matchday.cpp b/src/game/matchday.cpp index b245526..8c143e7 100644 --- a/src/game/matchday.cpp +++ b/src/game/matchday.cpp @@ -32,9 +32,9 @@ constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 25 // Three points for a win in every league (CareerSession_BeginFriendlyOpponentTable_RuntimeField, index 9 = "no league" reads the // following table byte 18, also non-zero). constexpr bool kThreePoints[10] = {true, true, true, true, true, true, true, true, true, true}; -constexpr size_t kClubRecord = 0x4a; -constexpr size_t kManagerRecord = 0xB0C; -constexpr size_t kBoard = 0x840, kBoardSlot = 0x58; +constexpr size_t kClubRecord = kClubRecordSize; +constexpr size_t kManagerRecord = kManagerRecordSize; +constexpr size_t kBoard = kTacticsBoardSize, kBoardSlot = kTacticsBoardSlotSize; uint32_t rd32(const std::vector& v, size_t o) { return uint32_t(v.at(o) | v.at(o + 1) << 8 | v.at(o + 2) << 16 | uint32_t(v.at(o + 3)) << 24); diff --git a/src/game/matchday_setup.cpp b/src/game/matchday_setup.cpp index cde95ca..6820add 100644 --- a/src/game/matchday_setup.cpp +++ b/src/game/matchday_setup.cpp @@ -30,7 +30,7 @@ namespace bmh { namespace { -constexpr size_t kManagerRecord = 0xB0C; +constexpr size_t kManagerRecord = kManagerRecordSize; constexpr size_t kDescriptorSize = 0xD0; // Competition class per descriptor type (MatchEngineRuntimeField9): which card counters apply. constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 255, @@ -41,7 +41,6 @@ constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 25 // Crowd interest per descriptor type (MatchdaySetupRuntimeField). constexpr uint8_t kTypeInterest[24] = {5, 5, 10, 15, 12, 10, 5, 10, 5, 10, 5, 31, 10, 10, 10, 0, 0, 1, 0, 0, 0, 12, 0, 0}; // Number of clubs taking part in league play (CareerSession_DispatchLineup_RuntimeField). -constexpr int kLeagueClubCount = 0x8a; // Squad slots checked by the driver (CareerRuntimeField). constexpr size_t kSquadSlotCount = 0xb70; @@ -613,7 +612,7 @@ std::vector setup_matchday(GameState& g, uint32_t competitions, cons } } } - for (int team = 0; team < kLeagueClubCount; team++) + for (int team = 0; team < world_layout().league_teams; team++) if (g.team_flags.at(size_t(team)) & 1) auto_lineup(g, team, 100); turn_step = "setup: options"; cycle_manager_options(g); @@ -892,8 +891,7 @@ bool select_live_match(GameState& g, int home, int away) { // record +0x8ac / 16 + 40. void man_marking(GameState& g, int own_manager, int own, int other_manager, int other, int chance, int rate, WatcomRandom& rand) { - constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField - if (g.indoor || own >= kLeagueTeams || other >= kLeagueTeams || (own_manager < 0 && other_manager < 0)) return; + if (g.indoor || own >= world_layout().league_teams || other >= world_layout().league_teams || (own_manager < 0 && other_manager < 0)) return; if (other_manager >= 0) for (size_t s = 0; s < 24; s++) { const size_t at = size_t(other_manager) * 0x840 + s * 0x58 + 0x46; @@ -1035,7 +1033,7 @@ void kick_off(GameState& g, std::vector& groups, const MatchdayConte man_marking(g, own_manager, t, other_manager, opponent, 0x32, rate, rand); } const TeamAverage fit = team_average(g, t, 0x1f1, &rand); - if ((t < kLeagueClubCount || t == kNoTeam) && (fit.players & 0xFF) < 8) { + if ((t < world_layout().league_teams || t == kNoTeam) && (fit.players & 0xFF) < 8) { // FinishEvent sets this fixture's local void bit and BuildSideRecords writes // the awarded 0:2/2:0 score before continuing to the next fixture. forfeit_side = side; diff --git a/src/game/month.cpp b/src/game/month.cpp index c639216..f3ea44c 100644 --- a/src/game/month.cpp +++ b/src/game/month.cpp @@ -33,9 +33,9 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xB0C; // manager record -constexpr size_t kBoard = 0x840; // tactics board of a manager -constexpr size_t kBoardSlot = 0x58; +constexpr size_t kRecord = kManagerRecordSize; // manager record +constexpr size_t kBoard = kTacticsBoardSize; // tactics board of a manager +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; constexpr uint32_t kTransferList = ::bmh::layout::EditorList; constexpr uint32_t kListEntry = 0x58; constexpr int kPoolFirst = 0xb70; // CareerRuntimeField: the transfer list (40 slots + 4) @@ -43,7 +43,6 @@ constexpr int kFreeAgents = 0xb9c; // CareerRuntimeField2: free agents (80 constexpr int kForeignAgents = 0xbec; // MonthRuntimeField: foreign free agents (20 slots) constexpr int kPoolEnd = 0xc00; // LargeSquadClubCount constexpr int kBigSquadClubs = 90; // TeamsWithSquads -constexpr int kLeagueClubs = 0x8a; // CareerSession_DispatchLineup_RuntimeField // MonthRuntimeField2: development steps by strength / 10; the ten bytes after it (PlayerCard_PlayerCardMarketValue_RuntimeField) // are the extra value above 500 points. @@ -303,7 +302,7 @@ void new_list_entries(GameState& g, WatcomRandom& rand, MinuteReport& report) { while (left-- != 0 && !report.unsupported) list_club_player(g, 0, kBigSquadClubs, rand, report); break; case 3: - while (left-- != 0 && !report.unsupported) list_club_player(g, kBigSquadClubs, kLeagueClubs, rand, report); + while (left-- != 0 && !report.unsupported) list_club_player(g, kBigSquadClubs, world_layout().league_teams, rand, report); break; } } diff --git a/src/game/national.cpp b/src/game/national.cpp index 721032c..07a3053 100644 --- a/src/game/national.cpp +++ b/src/game/national.cpp @@ -19,9 +19,9 @@ namespace bmh { namespace { -constexpr size_t kManagerRecord = 0xb0c; -constexpr size_t kBoard = 0x840; // one manager's tactics board (24 x 0x58) -constexpr size_t kBoardSlot = 0x58; +constexpr size_t kManagerRecord = kManagerRecordSize; +constexpr size_t kBoard = kTacticsBoardSize; // one manager's tactics board (24 x 0x58) +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; constexpr uint32_t kDesktops = ::bmh::layout::Desktops; // desktop layouts, 0x360 per manager slot constexpr size_t kDesktop = 0x360; constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField: the clubs' squads end here diff --git a/src/game/other_games.cpp b/src/game/other_games.cpp index 5598993..5fb092b 100644 --- a/src/game/other_games.cpp +++ b/src/game/other_games.cpp @@ -153,7 +153,7 @@ OtherGamesRow make_row(const GameState& game, int home, int away, uint16_t resul OtherGamesClubMetadata source_metadata(const GameState& game, int team) { OtherGamesClubMetadata out; bool manager_owned = game.manager_of(team) >= 0; - constexpr size_t kNationalOriginalClub = 4 * 0xb0c + 0x290; + constexpr size_t kNationalOriginalClub = 4 * kManagerRecordSize + 0x290; if (!manager_owned && !game.manager_teams.empty() && game.manager_teams[0] == kNoTeam && game.manager_records.size() >= kNationalOriginalClub + 2) { const int original_club = int(uint16_t(game.manager_records[kNationalOriginalClub] | diff --git a/src/game/poach.cpp b/src/game/poach.cpp index cb194b4..3b63d88 100644 --- a/src/game/poach.cpp +++ b/src/game/poach.cpp @@ -16,7 +16,7 @@ namespace bmh { namespace { -constexpr size_t kRecordSize = 0xb0c; +constexpr size_t kRecordSize = kManagerRecordSize; constexpr size_t kAttempts = 0x8b6; // five player ids, 0xffff free constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 rows of 0x58 bytes constexpr uint32_t kListRow = 0x58; diff --git a/src/game/prediction.cpp b/src/game/prediction.cpp index 09d082a..d7c16a1 100644 --- a/src/game/prediction.cpp +++ b/src/game/prediction.cpp @@ -18,14 +18,13 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xB0C; // manager record -constexpr size_t kBoard = 0x840; // tactics board of a manager -constexpr size_t kBoardSlot = 0x58; // one slot of the board +constexpr size_t kRecord = kManagerRecordSize; // manager record +constexpr size_t kBoard = kTacticsBoardSize; // tactics board of a manager +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; // one slot of the board // Static league tables of V2.24 (not part of the savegame): // (European places per league, CareerSession_InstallLeagueSizes_RuntimeField, are league_system().europe of the loaded game; league 0 uses 4) // (the relegation places per league, CareerSession_InstallLeagueSizes_RuntimeField2, are league_system().relegation of the loaded game) -constexpr int kLeagueTeams = 138; // CareerSession_DispatchLineup_RuntimeField: clubs in the league system // Text of a pointer variable of the text table TextPointerTable. } // namespace @@ -43,7 +42,7 @@ int table_prediction(GameState& g, int team, int mode, std::array& const size_t rec = size_t(manager) * kRecord; const int size = league_system().sizes[league]; // local_2c if (size_word) *size_word = size; // (stored as a word, see the header) - if (team >= kLeagueTeams) return 9; + if (team >= world_layout().league_teams) return 9; const int pos = team - league_first_team(league); // local_24 const int target[3] = {0, league == 0 ? 4 : league_system().europe[league], size - league_system().relegation[league]}; @@ -201,7 +200,7 @@ uint32_t expected_bonus_parked_club_source(GameState& g, int rank, int board_slo board_slot<0 || board_slot>=24 || g.tactics.size()<5*kBoard) throw std::invalid_argument("expected_bonus: invalid FindManagerForClub parked club context"); const int team=int(g.manager_records[team_at]) | int(g.manager_records[team_at+1])<<8; - if(team<0 || team>=kLeagueTeams) + if(team<0 || team>=world_layout().league_teams) throw std::invalid_argument("expected_bonus: parked record4 has no ordinary club"); return expected_bonus_impl(g,4,team,rank,board_slot,player,fitness); } diff --git a/src/game/records.hpp b/src/game/records.hpp new file mode 100644 index 0000000..638b82c --- /dev/null +++ b/src/game/records.hpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// Sizes of the fixed records of the original game state, in bytes. Until 1.0.12 every file that walks +// these records kept its own copy of the numbers; they are named here once. The values are those of +// the original (the save file is built from these records), so they are constants, not part of the +// world layout: a world with more managers or clubs has more records, not larger ones. + +#include + +namespace bmh { + +// One manager record (five of them: managers 0-3 and the spare record 4 the national coach swaps with). +constexpr size_t kManagerRecordSize = 0xB0C; +// The tactics board inside a manager record: 24 slots of kTacticsBoardSlotSize bytes. +constexpr size_t kTacticsBoardSize = 0x840; +constexpr size_t kTacticsBoardSlotSize = 0x58; +// The league record of a club (*ClubSeasonRecords), one per club with league records. +constexpr size_t kClubRecordSize = 0x4a; + +} // namespace bmh diff --git a/src/game/reschedule.cpp b/src/game/reschedule.cpp index 263e3fa..8a8c4e0 100644 --- a/src/game/reschedule.cpp +++ b/src/game/reschedule.cpp @@ -30,7 +30,7 @@ constexpr int kWinterBreakFirst = 0x96, kWinterBreakLast = 0xc8; // target inside 0x15 .. 0x11e. constexpr int kLastReplayDay = 0x11e, kFirstDayAfter = 0x15; constexpr uint8_t kRescheduledMark = 0xce; // param_5 = -0x32 -constexpr size_t kRecordSize = 0xb0c; +constexpr size_t kRecordSize = kManagerRecordSize; constexpr size_t kFloodlights = 0x0e; // manager record byte (RescheduleRuntimeField) // LeagueCalendarBits: calendar bit of a league (the two leagues 2 and 3 share bit 2, the four // leagues of 12 clubs bit 4; compare league_system().group_first in matchday_setup.cpp). diff --git a/src/game/search_profile.cpp b/src/game/search_profile.cpp index 0c23f40..05da4f1 100644 --- a/src/game/search_profile.cpp +++ b/src/game/search_profile.cpp @@ -13,7 +13,7 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xB0C; // manager record +constexpr size_t kRecord = kManagerRecordSize; // manager record constexpr uint32_t kTransferList = ::bmh::layout::EditorList; constexpr uint32_t kListEntry = 0x58; constexpr int kPoolFirst = 0xb70; // the transfer list lives in the first 40 pool slots diff --git a/src/game/season.cpp b/src/game/season.cpp index 4bb16ba..3c87cf0 100644 --- a/src/game/season.cpp +++ b/src/game/season.cpp @@ -35,8 +35,8 @@ constexpr uint32_t kTransferList = ::bmh::layout::EditorList; // 44 entries of constexpr uint32_t kListEntry = 0x58; constexpr size_t kPoolSlots = 0xb70; // CareerRuntimeField constexpr uint32_t kOffers = ::bmh::layout::OfferSlots; // OfferSlots: 4 offers, -1 = free -constexpr size_t kBoard = 0x840; // tactics board of a manager -constexpr size_t kBoardSlot = 0x58; +constexpr size_t kBoard = kTacticsBoardSize; // tactics board of a manager +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; uint32_t board32(const GameState& g, size_t at) { return uint32_t(g.tactics.at(at) | g.tactics.at(at + 1) << 8 | g.tactics.at(at + 2) << 16) | diff --git a/src/game/stadium_blocks.cpp b/src/game/stadium_blocks.cpp index 7f93996..f845ccd 100644 --- a/src/game/stadium_blocks.cpp +++ b/src/game/stadium_blocks.cpp @@ -14,7 +14,7 @@ namespace bmh { namespace { -constexpr size_t kRecordSize = 0xb0c; +constexpr size_t kRecordSize = kManagerRecordSize; constexpr size_t kManagerClub = 0x290; constexpr size_t kBuild = 0x34; constexpr size_t kFlags = 0x44; diff --git a/src/game/state.hpp b/src/game/state.hpp index e11c1ec..79622ec 100644 --- a/src/game/state.hpp +++ b/src/game/state.hpp @@ -14,6 +14,7 @@ #include "formats/m3d.hpp" #include "formats/savestate.hpp" +#include "game/records.hpp" #include "game/world_layout.hpp" #include "formats/textd.hpp" #include "game/memory.hpp" diff --git a/src/game/top_scorers.cpp b/src/game/top_scorers.cpp index 84deb70..7103844 100644 --- a/src/game/top_scorers.cpp +++ b/src/game/top_scorers.cpp @@ -14,7 +14,6 @@ namespace bmh::game { namespace { -constexpr size_t kManagerRecordSize = 0xb0c; constexpr size_t kNationalBackupManager = 4; constexpr size_t kManagerTeamOffset = 0x290; diff --git a/src/game/week.cpp b/src/game/week.cpp index f0018d5..a3db4a9 100644 --- a/src/game/week.cpp +++ b/src/game/week.cpp @@ -20,7 +20,7 @@ namespace bmh { namespace { -constexpr size_t kManagerRecord = 0xB0C; +constexpr size_t kManagerRecord = kManagerRecordSize; int32_t rd32(const std::vector& v, size_t o) { return int32_t(uint32_t(v.at(o)) | uint32_t(v.at(o + 1)) << 8 | uint32_t(v.at(o + 2)) << 16 | uint32_t(v.at(o + 3)) << 24); diff --git a/src/game/weekly.cpp b/src/game/weekly.cpp index e7298eb..49af7ce 100644 --- a/src/game/weekly.cpp +++ b/src/game/weekly.cpp @@ -34,13 +34,12 @@ namespace bmh { namespace { -constexpr size_t kRecord = 0xB0C; // manager record -constexpr size_t kBoard = 0x840; // tactics board of a manager -constexpr size_t kBoardSlot = 0x58; +constexpr size_t kRecord = kManagerRecordSize; // manager record +constexpr size_t kBoard = kTacticsBoardSize; // tactics board of a manager +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; 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 constexpr int kBigSquadClubs = 90; // TeamsWithSquads // Offers and incidents (Bool): 1 in WeeklyRuntimeField[kind] is only possible while the @@ -121,9 +120,9 @@ bool source_pending_owner_valid(const GameState& g,const SourcePendingOwner& own !mem.has(::bmh::layout::OfferSlots+uint32_t(entry-40)*4+3))return false; const auto team=[&](int manager){const size_t at=size_t(manager)*kRecord+0x290; return int(g.manager_records[at]) | int(g.manager_records[at+1])<<8;}; - if(team(0)!=kNoTeam || team(4)<0 || team(4)>=kLeagueClubs || + if(team(0)!=kNoTeam || team(4)<0 || team(4)>=world_layout().league_teams || team(owner.manager)!=owner.team || - (owner.manager==0 ? owner.team!=kNoTeam : owner.team<0 || owner.team>=kLeagueClubs))return false; + (owner.manager==0 ? owner.team!=kNoTeam : owner.team<0 || owner.team>=world_layout().league_teams))return false; const uint32_t list=kTransferList+uint32_t(entry)*kListEntry; if(!mem.has(list+kListEntry-1) || mem.u16(list+2)!=0xffff || mem.u16(list+4)!=0xffff || mem.u16(list+6)!=0xffff)return false; @@ -582,7 +581,7 @@ void transfer_bid(GameState& g, int slot, uint32_t list, bool high, int months, std::vector keys; std::vector needs; int region = 0; // local_20 (not reset between the clubs) - for (int team = 0; team < kLeagueClubs; team++) { + for (int team = 0; team < world_layout().league_teams; team++) { if (team == own || g.manager_of(team) >= 0) continue; if (team >= kBigSquadClubs) region = team_region(team) & 0xFF; if (own >= 0 && g.manager_of(own) >= 0 && list != 0 && (w35c >> 27) != 0 && game.range(0, 0xf) != 0) continue; @@ -867,7 +866,7 @@ TransferBidRating rate_transfer_bid_source(GameState& g, const TransferBidRating const int bidder = int(int16_t(g.memory.u16(list + uint32_t(request.bid_slot) * 2))); if (player == 0x0fff || size_t(player) >= g.players.size() || player != request.expected_player || bidder != request.expected_bidder || - bidder < 0 || bidder >= kLeagueClubs) + bidder < 0 || bidder >= world_layout().league_teams) return fail("source player/bidder identity mismatch"); uint32_t fee_base = 0, salary_base = 0; offer_bases(g.memory, list, request.bid_slot, fee_base, salary_base); @@ -955,7 +954,7 @@ TransferBidRating rate_transfer_bid_source(GameState& g, const TransferBidRating static void lineup_after_transfer_impl(GameState& g, int team, bool native_takeover) { if (pending_native_manager_of(g,team,native_takeover)==4) auto_lineup_parked_club_source(g,team,100); - else if (team < kLeagueClubs || team == kNoTeam) auto_lineup(g, team, 100); + else if (team < world_layout().league_teams || team == kNoTeam) auto_lineup(g, team, 100); } void lineup_after_transfer(GameState& g, int team) { lineup_after_transfer_impl(g,team,false); } @@ -1156,7 +1155,7 @@ bool preflight_human_owner_loan(const GameState& g, int seller, size_t pool_slot report.fail("transfer: Source free-agent loan return destination is not represented"); return false; } - if (buyer < 0 || buyer >= kLeagueClubs) { + if (buyer < 0 || buyer >= world_layout().league_teams) { report.fail("transfer: loan buyer has no squad"); return false; } @@ -1685,7 +1684,7 @@ static TransferOfferListView project_transfer_offer_list_impl(const GameState& g } // Only club IDs have a squad range in the source transfer path. Keep // malformed IDs visible for diagnosis but never use them as indexes. - const SquadRange range = buyer >= 0 && buyer < kLeagueClubs ? squad_range(buyer) : SquadRange{}; + const SquadRange range = buyer >= 0 && buyer < world_layout().league_teams ? squad_range(buyer) : SquadRange{}; offer.has_squad_room = range.count != 0 && squad_count(g, buyer, 3) < int(range.count) - 1; offer.passes_foreign_limit = range.count != 0; if (view.seller_manager < 0 && range.count != 0) { @@ -1872,7 +1871,7 @@ PendingSettleOutcome pending_settle(GameState& g, int raw, int player, int bid, const int movement_seller = pending_native_manager_of(g, seller, native_takeover); const int buyer = int16_t(mem.u16(list+uint32_t(bid)*2)); const int buyer_manager = pending_native_manager_of(g, buyer, native_takeover); - if (seller_manager < 0 || seller_manager >= 4 || buyer < 0 || buyer >= kLeagueClubs) { + if (seller_manager < 0 || seller_manager >= 4 || buyer < 0 || buyer >= world_layout().league_teams) { report.fail("DispatchClubPlayerPendingOffers: invalid seller/buyer for Void2"); return PendingSettleOutcome::unsupported; } const uint8_t term = mem.u8(list+0x34+uint32_t(bid)); @@ -1884,7 +1883,7 @@ PendingSettleOutcome pending_settle(GameState& g, int raw, int player, int bid, return PendingSettleOutcome::unsupported; } if (buyer_manager >= 0) { - const auto buyer_range = buyer >= 0 && buyer < kLeagueClubs ? squad_range(buyer) : SquadRange{}; + const auto buyer_range = buyer >= 0 && buyer < world_layout().league_teams ? squad_range(buyer) : SquadRange{}; if (buyer_range.count != 24) { report.fail("DispatchClubPlayerPendingOffers: human buyer uses unsupported non-24-slot squad layout"); return PendingSettleOutcome::unsupported; @@ -2112,8 +2111,8 @@ HumanBuyerSaleResult settle_human_buyer_sale(GameState& g, const HumanBuyerSaleR const bool free_agent = seller == 0x0fff; if (player == 0x0fff || size_t(player) >= g.players.size() || seller != request.expected_seller || buyer != request.expected_buyer || - (!free_agent && (seller < 0 || seller >= kLeagueClubs)) || - buyer < 0 || buyer >= kLeagueClubs || seller == buyer) + (!free_agent && (seller < 0 || seller >= world_layout().league_teams)) || + buyer < 0 || buyer >= world_layout().league_teams || seller == buyer) return fail("SettleHumanBuyerSale/Fail: source player/seller/buyer identity mismatch"); // SettleHumanBuyerSale uses param8 for the seller's accounts; Fail separately // resolves actual movement ownership through FindManagerForClub. @@ -2387,7 +2386,7 @@ PendingOfferResult process_pending_batch(GameState& g, int clicked_player, int c const int expected_seller=owner->team==kNoTeam ? int(g.manager_records.at(4*kRecord+0x290)) | (int(g.manager_records.at(4*kRecord+0x291))<<8) : owner->team; - if(seller<0 || seller>=kLeagueClubs || seller!=expected_seller || + if(seller<0 || seller>=world_layout().league_teams || seller!=expected_seller || (g.squad_slots.at(kPoolSlots+size_t(raw+40))&0x0fff)!=player) { report.fail("DispatchClubPlayerPendingOffers: invalid special offer seller/pool provenance (PreMatchOffer requires a club seller)"); return result; @@ -2512,7 +2511,7 @@ PendingOfferResult process_natural_pending_offers_after_desk(GameState& g, // Records1..3 survive the count-one national takeover. AdvanceTurn reads // these records directly even while their clubs have no current desk. if ((takeover && manager=kLeagueClubs)) || + (native_team!=kNoTeam && (native_team<0 || native_team>=world_layout().league_teams)) || (native_team==kNoTeam && (!takeover || manager!=0))) return fail("AdvanceTurn: invalid native ordered owner team"); const auto inactive_club_offer = [&](int raw, int player) { diff --git a/src/ui/advertising.cpp b/src/ui/advertising.cpp index 5cc971a..925577b 100644 --- a/src/ui/advertising.cpp +++ b/src/ui/advertising.cpp @@ -31,7 +31,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerRecord = 0xb0c; +constexpr size_t kManagerRecord = kManagerRecordSize; constexpr size_t kAdvertisingContracts = 0xa34; constexpr size_t kContractBytes = 0x0c; constexpr int kBoardCount = 14; @@ -201,7 +201,7 @@ AdvertisingFinancePreview original_finance_preview_impl(const GameState& game, i int32_t(game.manager_records.at(rec + 0x2e + size_t(i)) & 7) * kFacilityCost[size_t(i)]); expenses = wrap_add(expenses, signed32(u32(game.manager_records, rec + 0x854))); expenses = wrap_add(expenses, signed32(u32(game.manager_records, rec + 0x858))); - constexpr size_t kBoard = 0x840, kBoardSlot = 0x58; + constexpr size_t kBoard = kTacticsBoardSize, kBoardSlot = kTacticsBoardSlotSize; for (size_t slot = 0; slot < 24; ++slot) { const size_t board = size_t(manager) * kBoard + slot * kBoardSlot; if (game.tactics.at(board + 0x3d) == 0xff) continue; diff --git a/src/ui/analytics.cpp b/src/ui/analytics.cpp index 32f644a..2956f87 100644 --- a/src/ui/analytics.cpp +++ b/src/ui/analytics.cpp @@ -16,7 +16,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerRecord = 0xb0c; +constexpr size_t kManagerRecord = kManagerRecordSize; constexpr size_t kFlags = ::bmh::layout::Flags; constexpr int kSeriesCount = 6; constexpr int kSourcePointLimit = 52; // local_1d8[52] in CopyOpaqueSlice. diff --git a/src/ui/club_info.cpp b/src/ui/club_info.cpp index ccad57b..6fd5485 100644 --- a/src/ui/club_info.cpp +++ b/src/ui/club_info.cpp @@ -45,7 +45,7 @@ int sprite_width(const LeImage& exe, std::string_view value) { int source_manager_of(const GameState& game, int team) { const int manager = game.manager_of(team); if (manager >= 0) return manager; - constexpr size_t fifth_team_offset = size_t(4) * 0xb0c + 0x290; + constexpr size_t fifth_team_offset = size_t(4) * kManagerRecordSize + 0x290; if (!game.manager_teams.empty() && game.manager_teams.front() == kNoTeam && game.manager_records.size() >= fifth_team_offset + 2) { const uint16_t fifth_team = uint16_t(game.manager_records[fifth_team_offset] | diff --git a/src/ui/contracts.cpp b/src/ui/contracts.cpp index 57e34f9..6d28364 100644 --- a/src/ui/contracts.cpp +++ b/src/ui/contracts.cpp @@ -21,9 +21,9 @@ namespace bmh::ui { namespace { // Record sizes: one manager record, the per-manager block of player board entries (24 slots) // and one board entry (per-player data such as contract, insurance and premiums). -constexpr size_t kManagerRecord = 0xb0c; -constexpr size_t kBoard = 0x840; -constexpr size_t kBoardSlot = 0x58; +constexpr size_t kManagerRecord = kManagerRecordSize; +constexpr size_t kBoard = kTacticsBoardSize; +constexpr size_t kBoardSlot = kTacticsBoardSlotSize; // Copies a block from a widget/atlas image to the target; throws on out-of-range rectangles. // With `transparent` set, palette index 0 is skipped. diff --git a/src/ui/finance_totals.cpp b/src/ui/finance_totals.cpp index d71fdaf..c5fa5cd 100644 --- a/src/ui/finance_totals.cpp +++ b/src/ui/finance_totals.cpp @@ -14,7 +14,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerRecord = 0xb0c; +constexpr size_t kManagerRecord = kManagerRecordSize; uint32_t require_memory(const GameState& g, uint32_t address, size_t bytes) { if (bytes == 0 || !g.memory.has(address) || !g.memory.has(address + uint32_t(bytes - 1))) diff --git a/src/ui/incoming_transfer.cpp b/src/ui/incoming_transfer.cpp index 4925dbb..443075f 100644 --- a/src/ui/incoming_transfer.cpp +++ b/src/ui/incoming_transfer.cpp @@ -26,7 +26,7 @@ constexpr uint32_t kTitleText = ::bmh::layout::TitleText; constexpr uint32_t kPurchaseTitleText = ::bmh::layout::PurchaseTitleText; constexpr uint32_t kLoanTitleText = ::bmh::layout::LoanTitleText; constexpr uint32_t kTextBase = ::bmh::layout::TextPointerTable; -constexpr size_t kManagerRecord = 0xb0c; +constexpr size_t kManagerRecord = kManagerRecordSize; // Returns the TEXTD string for a text-table address; throws if the address is not a table entry. std::string_view text_at(const TextDb& texts, uint32_t address) { diff --git a/src/ui/minute_statistics.cpp b/src/ui/minute_statistics.cpp index ef1bd7f..59472d2 100644 --- a/src/ui/minute_statistics.cpp +++ b/src/ui/minute_statistics.cpp @@ -17,7 +17,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerStride = 0xb0c; +constexpr size_t kManagerStride = kManagerRecordSize; constexpr size_t kSeriesOffset = 0x1ae; constexpr size_t kSeriesBytes = 18; constexpr size_t kSeriesCount = 4; diff --git a/src/ui/pending_offer.cpp b/src/ui/pending_offer.cpp index a568d75..1b5c1bb 100644 --- a/src/ui/pending_offer.cpp +++ b/src/ui/pending_offer.cpp @@ -14,7 +14,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerRecord = 0xb0c; +constexpr size_t kManagerRecord = kManagerRecordSize; } // namespace diff --git a/src/ui/series_records.cpp b/src/ui/series_records.cpp index 678ddae..a201b36 100644 --- a/src/ui/series_records.cpp +++ b/src/ui/series_records.cpp @@ -16,8 +16,8 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerRecord = 0xb0c; -constexpr size_t kClubRecord = 0x4a; +constexpr size_t kManagerRecord = kManagerRecordSize; +constexpr size_t kClubRecord = kClubRecordSize; constexpr uint32_t kSeriesSelector = ::bmh::layout::SeriesSelector; constexpr uint32_t kTableFlags = ::bmh::layout::TableFlags; diff --git a/src/ui/strengths_state.cpp b/src/ui/strengths_state.cpp index ac16d9b..7bc6a1d 100644 --- a/src/ui/strengths_state.cpp +++ b/src/ui/strengths_state.cpp @@ -22,7 +22,6 @@ namespace bmh::ui { namespace { constexpr uint32_t kManagerSettings = ::bmh::layout::ManagerSettings; -constexpr size_t kManagerRecordSize = 0xb0c; constexpr std::array kCriterionFlags{0x001, 0x002, 0x004, 0x008}; [[noreturn]] void invalid(const std::string& reason) { diff --git a/src/ui/training_camp.cpp b/src/ui/training_camp.cpp index 2772581..9e6d1bc 100644 --- a/src/ui/training_camp.cpp +++ b/src/ui/training_camp.cpp @@ -20,7 +20,7 @@ namespace bmh::ui { namespace { -constexpr size_t kRecord = 0xb0c; +constexpr size_t kRecord = kManagerRecordSize; constexpr size_t kTeam = 0x290; constexpr size_t kFocus = 0xc1; constexpr size_t kStays = 0x21f; diff --git a/src/ui/transfer_history.cpp b/src/ui/transfer_history.cpp index af966e3..6d5fd03 100644 --- a/src/ui/transfer_history.cpp +++ b/src/ui/transfer_history.cpp @@ -14,7 +14,7 @@ namespace bmh::ui { namespace { -constexpr size_t kManagerStride = 0xb0c; +constexpr size_t kManagerStride = kManagerRecordSize; constexpr size_t kHistoryCount = 0x21d; constexpr size_t kEventWords = 0x760; constexpr size_t kNameWords = 0x7d8; diff --git a/src/ui/transfer_history_tests.cpp b/src/ui/transfer_history_tests.cpp index d7b156e..e3f60cc 100644 --- a/src/ui/transfer_history_tests.cpp +++ b/src/ui/transfer_history_tests.cpp @@ -22,7 +22,7 @@ int main() { game.manager_records.assign(4 * 0xb0c, 0); game.player_names = {'A','n','n','a',0,'M','a','x',0}; game.club_names = {'O','l','d',' ','F','C',0,'N','e','w',' ','F','C',0}; - constexpr size_t record = 0xb0c; + constexpr size_t record = kManagerRecordSize; game.manager_records[record + 0x21d] = 2; const uint32_t sell_event = (12u << 19) | (400u << 2) | 0u; const uint32_t buy_event = (3u << 19) | (401u << 2) | 1u; diff --git a/src/ui/transfer_market.cpp b/src/ui/transfer_market.cpp index 0244874..27b997f 100644 --- a/src/ui/transfer_market.cpp +++ b/src/ui/transfer_market.cpp @@ -24,7 +24,6 @@ constexpr size_t kPoolFirst = 0xb70; constexpr int kMarketEntries = 40; constexpr uint32_t kTransferTable = ::bmh::layout::EditorList; constexpr uint32_t kTransferEntrySize = 0x58; -constexpr size_t kManagerRecordSize = 0xb0c; // Fills a rectangle with one palette index, clipped to the image. void rect(Image& out,int x,int y,int w,int h,uint8_t color) {