Team id comparisons ask the world layout

92 comparisons against the raw numbers 138, 168 and 357 in engine, UI and app
read world_layout().league_teams, first_foreign_cup() and no_team(); a team id
written as 0x165 is kNoTeam. Same values, same arithmetic.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude committed 2026-11-10 23:16:53 +01:00
1 parent cb6d3b6035
commit d552c59a77
29 files changed
+94 -93

No files matched your search

+1 -1
View File
@@ -269,7 +269,7 @@ bool human_club(const GameState& g, int team) {
const int managers = g.memory.u8(::bmh::layout::ManagerCount);
for (int m = 0; m < managers; m++)
if (team_of(g, m) == uint16_t(team)) return true;
return team_of(g, 0) == 0x165 && team_of(g, 4) == uint16_t(team);
return team_of(g, 0) == kNoTeam && team_of(g, 4) == uint16_t(team);
}
// OpenBMH deviates from the original: skips reserved calendar positions when assigning a joining manager to a club.
+1 -1
View File
@@ -8,7 +8,7 @@
#include <stdexcept>
namespace bmh {
ClubInfoEntry prepare_club_info_entry(GameState& g, int team) {
if (team < 0 || (team >= 138 && team != kNoTeam))
if (team < 0 || (team >= world_layout().league_teams && team != kNoTeam))
throw std::invalid_argument("club info: team has no squad");
const SquadRange range = squad_range(team);
if (range.first > g.squad_slots.size() || range.count > g.squad_slots.size() - range.first)
+1 -1
View File
@@ -78,7 +78,7 @@ ClubPlayerDetailContext club_player_detail_context(const GameState& g, const Clu
out.primary_club = -1;
} else {
if (s.rendered_row < 0 || s.rendered_row >= 24 || s.runtime_team < 0 ||
(s.runtime_team >= 138 && s.runtime_team != kNoTeam))
(s.runtime_team >= world_layout().league_teams && s.runtime_team != kNoTeam))
throw std::invalid_argument("player detail: invalid runtime club");
const auto range = squad_range(s.runtime_team);
if (range.first + range.count > g.squad_slots.size()) throw std::invalid_argument("player detail: truncated squad");
+8 -8
View File
@@ -75,7 +75,7 @@ FriendlyBookingQuote make_friendly_quote(const GameState& g, int manager, int op
return out;
}
const int own_team = g.manager_teams[size_t(manager)];
if (own_team < 0 || own_team >= 168 || opponent < 0 || opponent >= 168 || opponent == own_team) {
if (own_team < 0 || own_team >= world_layout().first_foreign_cup() || opponent < 0 || opponent >= world_layout().first_foreign_cup() || opponent == own_team) {
out.status = FriendlyQuoteStatus::invalid_opponent;
return out;
}
@@ -637,7 +637,7 @@ TransferActionResult submit_transfer_bid_impl(GameState& g, const TransferBidReq
const bool source_direct_candidate = source_hooks && seller_manager < 0 &&
fee_pct >= 110 && salary_pct >= g.memory.u8(entry + 0x55);
if (source_direct_candidate) {
if (request.list_entry >= 40 || seller < 0 || (seller >= 0x8a && seller != 0x0fff) || seller == buyer ||
if (request.list_entry >= 40 || seller < 0 || (seller >= world_layout().league_teams && seller != 0x0fff) || seller == buyer ||
request.manager < 0 || size_t(request.manager) >= g.manager_teams.size() ||
!g.memory.has(::bmh::layout::ActiveManager) || g.memory.u8(::bmh::layout::ActiveManager) != request.manager ||
source_hooks->direct_mode != HumanBuyerSaleDirectMode::ordinary_ai_purchase ||
@@ -803,7 +803,7 @@ TransferActionResult submit_transfer_bid_source_impl(GameState& g, const Transfe
// ordinary settlement already removes players using that actual range.
// Higher club IDs have no ordinary squad; do not invent their settlement
// or let ReleasePlayer reach its missing-player/internal-error21 boundary.
if (seller != 0x0fff && seller >= 138) {
if (seller != 0x0fff && seller >= world_layout().league_teams) {
report.fail(kOrdinarySellerBoundary);
out.status = TransferActionStatus::unsupported;
out.player = player; out.list_entry = request.list_entry;
@@ -1022,7 +1022,7 @@ TransferActionResult submit_transfer_bid_source_impl(GameState& g, const Transfe
std::optional<TransferMarketSnapshotPreview> transfer_market_snapshot_preview(
const GameState& g,int manager,int runtime_club,int index) {
if(manager<0||manager>=4||size_t(manager)>=g.manager_teams.size()||
g.manager_teams[size_t(manager)]!=runtime_club||runtime_club<0||runtime_club>=138||index<0||index>=12)
g.manager_teams[size_t(manager)]!=runtime_club||runtime_club<0||runtime_club>=world_layout().league_teams||index<0||index>=12)
return std::nullopt;
const auto owner=squad_range(runtime_club);
int count=0,ordinal=-1;
@@ -1049,7 +1049,7 @@ std::optional<TransferMarketSnapshotPreview> transfer_market_snapshot_preview(
// Require exactly one genuine ledger and its authenticated owner.
if(borrower!=-1||int(loan>>12&0x3ff)!=runtime_club)return std::nullopt;
borrower=int(loan>>22&0x3ff);
if(borrower<0||borrower>=138||borrower==runtime_club)return std::nullopt;
if(borrower<0||borrower>=world_layout().league_teams||borrower==runtime_club)return std::nullopt;
}
if(borrower<0)return std::nullopt;
const auto range=squad_range(borrower);
@@ -1104,7 +1104,7 @@ TransferMarketPreviewResult quote_transfer_market_preview_source(
// with the unchanged42307 formula; do not synthesize a Native slot.
} else {
if(request.snapshot_index!=-1)return unsupported("market preview: invalid snapshot index");
if(request.seller!=request.runtime_club||request.runtime_club>=138)
if(request.seller!=request.runtime_club||request.runtime_club>=world_layout().league_teams)
return unsupported("market preview: outgoing club is not an ordinary owned squad");
const auto range=squad_range(request.runtime_club);
if(range.count==0||range.first+range.count>g.squad_slots.size()||
@@ -1146,7 +1146,7 @@ int editor_slot(const GameState& g,const TransferOfferEditorRequest& r) {
std::string editor_identity(const GameState& g,const TransferOfferEditorRequest& r) {
if(r.manager<0||r.manager>=4||size_t(r.manager)>=g.manager_teams.size()||
!g.memory.has(::bmh::layout::ActiveManager)||g.memory.u8(::bmh::layout::ActiveManager)!=r.manager||
g.manager_teams[size_t(r.manager)]!=r.runtime_club||r.runtime_club<0||r.runtime_club>=138)
g.manager_teams[size_t(r.manager)]!=r.runtime_club||r.runtime_club<0||r.runtime_club>=world_layout().league_teams)
return "OpenTransferEditor: stale ordinary manager/team";
const size_t record=size_t(r.manager)*kRecordSize;
if(record+kRecordSize>g.manager_records.size()||
@@ -1172,7 +1172,7 @@ std::string editor_identity(const GameState& g,const TransferOfferEditorRequest&
const int seller=int(r.expected_seller_word&0x7fff);
if(r.expected_seller_word==0xffff||seller==r.runtime_club)
return "OpenTransferEditor: targeted/invalid seller is outside ordinary editor";
if(seller!=0x0fff&&seller>=138)return kOrdinarySellerBoundary;
if(seller!=0x0fff&&seller>=world_layout().league_teams)return kOrdinarySellerBoundary;
// OpenTransferEditor: the original refuses a loan from a free agent (seller 0x0fff) with the message
// DeskActionsRuntimeField6 (SDLFlushEvents3) - a rule of the game, not a gap: the code names it
if(r.loan&&r.expected_seller_word==0x0fff)return "free_agent_loan_refused";
+4 -4
View File
@@ -113,7 +113,7 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
require(o.supported&&!o.closed&&o.manager>=0&&o.manager<4&&
size_t(o.manager)<g.manager_teams.size()&&g.memory.has(::bmh::layout::ActiveManager)&&
g.memory.u8(::bmh::layout::ActiveManager)==o.manager&&g.manager_teams[size_t(o.manager)]==o.runtime_club&&
(national||(o.runtime_club>=0&&o.runtime_club<138))&&
(national||(o.runtime_club>=0&&o.runtime_club<world_layout().league_teams))&&
size_t(o.runtime_club)<g.club_ids.size()&&
g.club_ids[size_t(o.runtime_club)]==o.club_identity,
"pairings: stale or unsupported manager identity");
@@ -134,7 +134,7 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
"pairings: incomplete Native schedule");
const auto selection_valid=[&](int team,int identity) {
return team<0 ? team>=-2&&identity==-1 :
team<138&&team_league(team)==o.league&&g.club_ids.at(size_t(team))==identity;
team<world_layout().league_teams&&team_league(team)==o.league&&g.club_ids.at(size_t(team))==identity;
};
require(selection_valid(o.search_first,o.search_first_identity)&&
selection_valid(o.search_second,o.search_second_identity)&&
@@ -186,7 +186,7 @@ void validate(const GameState& g,const LeaguePairingsOwner& o) {
o.filter_offset>=0&&o.filter_offset%10==0&&o.filter_team>=-2,
"pairings: invalid Source club-filter mode");
if(o.filter_team>=0) {
require(o.filter_team<138&&team_league(o.filter_team)==o.league&&
require(o.filter_team<world_layout().league_teams&&team_league(o.filter_team)==o.league&&
g.club_ids.at(size_t(o.filter_team))==o.filter_identity&&
(o.filter_offset==0||o.filter_offset<filtered_fixture_count(o.league,o.filter_team)),
"pairings: stale or out-of-range filtered club");
@@ -320,7 +320,7 @@ LeaguePairingsOwner open_league_pairings_source(GameState& g,int manager,const L
require(manager>=0&&manager<4&&size_t(manager)<g.manager_teams.size(),"pairings: unsupported manager");
LeaguePairingsOwner out;out.manager=manager;out.runtime_club=g.manager_teams[size_t(manager)];
const bool national=out.runtime_club==kNoTeam;
require((national||(out.runtime_club>=0&&out.runtime_club<138))&&
require((national||(out.runtime_club>=0&&out.runtime_club<world_layout().league_teams))&&
size_t(out.runtime_club)<g.club_ids.size(),"pairings: unsupported or unowned manager");
out.club_identity=g.club_ids[size_t(out.runtime_club)];
// TeamLeague2 maps the Original national runtime team 0x165 to league 0.
+3 -3
View File
@@ -42,7 +42,7 @@ uint8_t formation_byte(const GameState& g, size_t index) {
}
bool pitch_context_valid(const GameState& g, int manager, int team) {
if (manager < 0 || manager > 3 || team < 0 || team >= 138 || g.lineups_frozen ||
if (manager < 0 || manager > 3 || team < 0 || team >= world_layout().league_teams || g.lineups_frozen ||
!g.memory.has(::bmh::layout::ActiveManager) || !g.memory.has(::bmh::layout::GameMode) ||
g.memory.u8(::bmh::layout::ActiveManager) != manager || g.memory.u8(::bmh::layout::GameMode) < 1 || g.memory.u8(::bmh::layout::GameMode) > 3 ||
size_t(manager) >= g.manager_teams.size() || g.manager_teams[size_t(manager)] != team ||
@@ -331,7 +331,7 @@ void install_lineup_rules(const LeImage& exe) {
}
static void auto_lineup_impl(GameState& g, int team, int mode, int manager) {
if (team >= 138 && team != kNoTeam) return; // teams without squads
if (team >= world_layout().league_teams && team != kNoTeam) return; // teams without squads
if (g.lineups_frozen) return; // LineupRuntimeField (the season change)
const bool improve_from_reserves = (mode & 0x80) != 0;
mode &= 0x7F;
@@ -687,7 +687,7 @@ void quicksort_by_key(int16_t* items, uint32_t* keys, int count, bool ascending)
}
bool substitute(GameState& g, int team, int off, int mode, WatcomRandom& rand) {
if (!(team < 138 || team == kNoTeam)) return false;
if (!(team < world_layout().league_teams || team == kNoTeam)) return false;
const int manager = g.manager_of(team);
int used = g.team_flags.at(team) >> 5 & 7; // substitutions so far
if (mode == 10) {
+6 -6
View File
@@ -84,7 +84,7 @@ MinuteReport MatchEngine::minute(int minute, int last_minute, int stoppage) {
// Human teams use the places on their tactics board, also for the player's value.
int MatchEngine::pick_player(int team, int mode, int exclude, MinuteReport& report, int preset) {
mode &= 0x7F; // 0x80 = reuse the squad of the previous call, same team here
if (team >= 138 && team != kNoTeam) return 0xFFF; // clubs without squad: nobody, no draws
if (team >= world_layout().league_teams && team != kNoTeam) return 0xFFF; // clubs without squad: nobody, no draws
SquadRange range = squad_range(team);
if (range.count == 0) return 0xFFF;
RatingContext ctx{state.chance_rain, state.chance_temperature};
@@ -534,7 +534,7 @@ ForcedMatchEvent MatchEngine::event_impl(MatchGroup& g, int m, int s, int minute
// national team (0x165, squad nominated on the national team days) only while manager
// slot 0 holds it (CupDraw_FormatError_RuntimeField2 == 0x165: a Bundestrainer's match).
if (!(team < 90 || rand.range(0, 1) == 0)) return result;
if (!(team < 138 || team == kNoTeam)) return result;
if (!(team < world_layout().league_teams || team == kNoTeam)) return result;
if (team == kNoTeam && (state.manager_teams.empty() || state.manager_teams[0] != kNoTeam)) return result;
const int manager = state.manager_of(team); // FindManagerForClub, local_6c
const bool human = manager >= 0;
@@ -955,7 +955,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
}
// Goalkeeper of the opponent: the player in squad slot 0 if the formation puts it in goal.
if (!reality_played && (opp_team < 168 || opp_team == kNoTeam)) {
if (!reality_played && (opp_team < world_layout().first_foreign_cup() || opp_team == kNoTeam)) {
int x = 0, y = 0;
state.formation_position(opp_team, 0, x, y);
if (x == 0 && y == 4) keeper = state.squad_slots.at(squad_range(opp_team).first) & 0x0FFF;
@@ -990,7 +990,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
deflected = game.range(0, 5) == 0;
}
if (kind == 0) {
if (team >= 168 && team != kNoTeam) {
if (team >= world_layout().first_foreign_cup() && team != kNoTeam) {
// clubs without squad: the attack rating (TeamRating, profile 3), drawn
RatingContext drawn;
drawn.rand = &rand;
@@ -1000,7 +1000,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
}
}
if (keeper == 0xFFF) {
if (opp_team >= 168 && opp_team != kNoTeam) {
if (opp_team >= world_layout().first_foreign_cup() && opp_team != kNoTeam) {
// clubs without squad: the goalkeeping rating (profile 0), drawn
RatingContext drawn;
drawn.rand = &rand;
@@ -1207,7 +1207,7 @@ void MatchEngine::penalty_shootout(MatchGroup& g, int m, MinuteReport& report) {
const int side = order[k];
const int team = pair[side];
int player = 0xFFF;
if (team < 138 || team == kNoTeam) {
if (team < world_layout().league_teams || team == kNoTeam) {
// a player who has not taken a penalty yet (after 100 tries the list restarts)
int tries = 0;
bool fresh;
+5 -5
View File
@@ -135,7 +135,7 @@ SportschauFixtureView sportschau_fixture_view(const GameState& state, const Matc
if (team >= 0 && size_t(team) * 2 + 1 < state.club_heap_78.size())
badge_word = uint16_t(state.club_heap_78[size_t(team) * 2] |
uint16_t(state.club_heap_78[size_t(team) * 2 + 1]) << 8);
if (team >= 0 && team < 0xa8) {
if (team >= 0 && team < world_layout().first_foreign_cup()) {
requires_font_fit = true;
if (state.memory.has(::bmh::layout::ClubShortNameOffsets + uint32_t(team))) {
const uint8_t source = state.memory.u8(::bmh::layout::ClubShortNameOffsets + uint32_t(team));
@@ -313,7 +313,7 @@ void update_club_table(GameState& g, int home, int away, int hg, int ag) {
auto add16 = [&](size_t o, int v) { wr16(g.club_table, o, uint16_t(rd16(g.club_table, o) + v)); };
// Only the first league and the regional leagues keep points in this table (the
// condition tests the home club only).
const bool league = home < league_system().sizes[0] || (home >= 90 && home < 138);
const bool league = home < league_system().sizes[0] || (home >= world_layout().domestic_teams && home < world_layout().league_teams);
const int win_points = kThreePoints[league_of(home)] ? 3 : 2;
if (league) {
add16(H + 0x20, hg);
@@ -415,7 +415,7 @@ void develop_players(GameState& g, const MatchGroup& grp, int m, GameRandom& gam
const int type = grp.desc.at(0);
for (int side = 0; side < 2; side++) {
const int team = grp.fixtures.at(m * 2 + side);
if (!(team < 168 || team == kNoTeam)) continue;
if (!(team < world_layout().first_foreign_cup() || team == kNoTeam)) continue;
const uint8_t cls = (type == 0xb && team == kNoTeam) ? 3 : uint8_t(competition_class(type));
const int manager = g.manager_of(team);
const SquadRange range = squad_range(team);
@@ -597,7 +597,7 @@ bool league_screen_shown(const std::vector<uint8_t>& buttons, int param_1, int p
int table_position(const GameState& g, int team) {
if (team >= 138) return 2;
if (team >= world_layout().league_teams) return 2;
int league = league_of(team);
int rounds = league < int(g.league_rounds.size()) ? g.league_rounds[league] : 0;
if (rounds == 0) return -1;
@@ -678,7 +678,7 @@ void manager_match_record(GameState& g, const MatchGroup& grp, int m, int home_g
rating = std::clamp(int16_t(rating), int16_t(0), int16_t(200));
rate_manager(g, int(k), rating, 0);
}
if (opp < 0xa8) {
if (opp < world_layout().first_foreign_cup()) {
size_t at = k * 0x690 + size_t(opp) * 10 + (side == 1 ? 5 : 0);
std::copy_backward(g.manager_results.begin() + at, g.manager_results.begin() + at + 4,
g.manager_results.begin() + at + 5);
+2 -2
View File
@@ -215,7 +215,7 @@ void list_club_player(GameState& g, int first, int last, WatcomRandom& rand, Min
n++;
}
}
int pick = 0x8a; // sVar11
int pick = world_layout().league_teams; // sVar11
int slot = -1; // unaff_EDI: the slot tried last
if (n != 0) {
quicksort_by_key(teams, keys, n);
@@ -237,7 +237,7 @@ void list_club_player(GameState& g, int first, int last, WatcomRandom& rand, Min
}
// (when no club had a fitting player the slot tried last is listed all the same)
}
if (pick < 0x8a) {
if (pick < world_layout().league_teams) {
list_player(g, slot, rand, report);
return;
}
+3 -3
View File
@@ -160,13 +160,13 @@ OtherGamesClubMetadata source_metadata(const GameState& game, int team) {
uint16_t(game.manager_records[kNationalOriginalClub + 1]) << 8));
manager_owned = original_club == team;
}
if (team >= 168 && !manager_owned) {
const size_t at = size_t(team - 168);
if (team >= world_layout().first_foreign_cup() && !manager_owned) {
const size_t at = size_t(team - world_layout().first_foreign_cup());
if (at >= game.foreign_strength.size()) invalid("missing Source foreign-strength byte");
out.foreign_strength = game.foreign_strength[at];
return out;
}
if (team >= 168 && team != kNoTeam)
if (team >= world_layout().first_foreign_cup() && team != kNoTeam)
invalid("manager-controlled foreign-club row needs live TeamRating W-generator context");
constexpr std::array<uint16_t, 5> kFlags{0x0f1, 0x0f2, 0x0f4, 0x0f8, 0x0ff};
for (size_t i = 0; i < kFlags.size(); ++i)
+2 -2
View File
@@ -126,7 +126,7 @@ int human_correction(GameState& g, RatingContext& ctx, int manager, int rank, in
} // namespace
int team_rating(GameState& g, int team, const RatingProfile& profile, RatingContext& ctx, int* keeper) {
if (team >= 168 && team != kNoTeam) {
if (team >= world_layout().first_foreign_cup() && team != kNoTeam) {
// Clubs without squad: per group a random value around the level of the club
// (ForeignClubStrength bits 5-7 -> RatingRuntimeField2), +2 if the group's strength bit is set
// (bit 3, 3, 2, 1 for goal, defence, midfield, attack: RatingRuntimeField3) and a style
@@ -135,7 +135,7 @@ int team_rating(GameState& g, int team, const RatingProfile& profile, RatingCont
static const uint8_t kStrongBit[4] = {3, 3, 2, 1};
static const int8_t kStyle[8] = {0, 6, 0, -6, 0, -6, 0, 6};
if (!ctx.rand) throw std::invalid_argument("team_rating: a team without squad needs the Watcom generator");
const uint8_t s = g.foreign_strength.at(size_t(team - 168));
const uint8_t s = g.foreign_strength.at(size_t(team - world_layout().first_foreign_cup()));
int16_t total = 0;
for (int i = 0; i < 4; i++) {
const int level = kLevel[s >> 5];
+1 -1
View File
@@ -155,7 +155,7 @@ Bytes save_header(const GameState& g) {
for (int m = 0; m < managers && m < 4; m++) {
const size_t rec = size_t(m) * 0xb0c;
const int team = int16_t(g.manager_records.at(rec + 0x290) | g.manager_records.at(rec + 0x291) << 8);
const bool national = team == 0x165;
const bool national = team == kNoTeam;
const size_t at = size_t(m) * 0x28;
list[at] = national ? 0x1e : g.manager_records.at(rec + 0x210); // (0x1e: high byte of the loop word)
list[at + 1] = national ? 1 : 0;
+9 -9
View File
@@ -284,9 +284,9 @@ void observe_initial_international_groups(GameState& g, WatcomRandom& rand, int
for(int position:{fixture.home,fixture.away}) {
const int team=mem.u16(teams+uint32_t(position)*2);
const bool manager_national=mem.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&mem.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&
mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==0x165&&mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==team;
mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==kNoTeam&&mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==team;
const bool human_owned=g.manager_of(team)>=0||manager_national;
if(team<168||team==kNoTeam||!human_owned)continue;
if(team<world_layout().first_foreign_cup()||team==kNoTeam||!human_owned)continue;
SeasonCupDrawEvent::GroupAverageSnapshot snapshot;
snapshot.runtime_id=uint16_t(team);
snapshot.values={team_average(g,team,0x0f1,&rand).value,
@@ -325,7 +325,7 @@ void european_setup(GameState& g, GameRandom& game, WatcomRandom& rand, const Se
constexpr uint32_t kField0 = ::bmh::layout::Field0;
if (!mem.has(kField0)) mem.add_block(kField0, 0x30);
const int s = g.season % 4;
const int base = 0xbd + 0x8a + 0x1e; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6
const int base = world_layout().no_team(); // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6
int n = 1;
std::vector<uint16_t> last;
if (s % 2 == 0) {
@@ -395,7 +395,7 @@ void european_setup(GameState& g, GameRandom& game, WatcomRandom& rand, const Se
void european_fields(GameState& g, GameRandom& game, WatcomRandom& rand) {
StaticMemory& mem = g.memory;
Entrants en{mem};
const int pool = 0x8a + 0x1e; // CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6: the first foreign club
const int pool = world_layout().first_foreign_cup(); // CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6: the first foreign club
auto pick = [&](int from) {
int t;
do t = rand.range(from, from + 6); while (en.find(t) != 0);
@@ -768,7 +768,7 @@ void season_accounts(GameState& g, int m, GameRandom& game, WatcomRandom& rand,
// swaps twice for them (no change), once otherwise.
void change_places(GameState& g, int a, int b) {
StaticMemory& mem = g.memory;
if (a >= 0x8a + 0x1e || b >= 0x8a + 0x1e) return;
if (a >= world_layout().first_foreign_cup() || b >= world_layout().first_foreign_cup()) return;
auto swap_bytes = [](std::vector<uint8_t>& v, size_t x, size_t y, size_t n) {
for (size_t i = 0; i < n; i++)
if (x + i < v.size() && y + i < v.size()) std::swap(v[x + i], v[y + i]);
@@ -785,7 +785,7 @@ void change_places(GameState& g, int a, int b) {
else if (v == uint16_t(b)) mem.set16(at + uint32_t(i) * 2, uint16_t(a));
}
};
const bool league_clubs = a < 0x8a && b < 0x8a;
const bool league_clubs = a < world_layout().league_teams && b < world_layout().league_teams;
if (league_clubs)
for (uint32_t k = 0; k < 200; k++) { // loans: seller and buyer
const uint32_t e = mem.u32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4);
@@ -795,7 +795,7 @@ void change_places(GameState& g, int a, int b) {
buyer = buyer == a ? b : buyer == b ? a : buyer;
mem.set32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4, (e & 0xfff) | uint32_t(seller) << 12 | uint32_t(buyer) << 22);
}
if (!g.club_table.empty() && a < 0xa8 && b < 0xa8) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
if (!g.club_table.empty() && a < world_layout().first_foreign_cup() && b < world_layout().first_foreign_cup()) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
swap_statistics_clubs(g, a, b);
std::swap(g.club_ids.at(size_t(a)), g.club_ids.at(size_t(b)));
swap_bytes(g.club_heap_bc, size_t(a) * 2, size_t(b) * 2, 2);
@@ -1673,13 +1673,13 @@ bool career_season_setup(GameState& g, GameRandom& game, WatcomRandom& rand, Min
const SeasonCupDrawHook& cup_draw) {
StaticMemory& mem = g.memory;
g.team_morale.at(0x165) |= 0x80;
for (int team = 0; team < 0x8a; team++) {
for (int team = 0; team < world_layout().league_teams; team++) {
club_balance(g, team, rand);
auto_lineup(g, team, g.manager_of(team) >= 0 ? 0xe4 : 100); // (byte 100 - 0x80 for humans)
}
// the title holders of the cup entries (+0x22): none yet, the placeholder clubs
const uint16_t first_small = 90; // TeamsWithSquads
const uint16_t foreign = 189 + 138 + 30; // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6 (0x165)
const uint16_t foreign = uint16_t(world_layout().no_team()); // ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField3 + CareerSession_DispatchLineup_RuntimeField + CareerSession_InstallLeagueSizes_RuntimeField6 (0x165)
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField2, foreign);
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField6, uint16_t(first_small + 7));
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField, 7);
+1
View File
@@ -14,6 +14,7 @@
#include "formats/m3d.hpp"
#include "formats/savestate.hpp"
#include "game/world_layout.hpp"
#include "formats/textd.hpp"
#include "game/memory.hpp"
#include "game/random.hpp"
+1 -1
View File
@@ -80,7 +80,7 @@ TopScorersProjection top_scorers_from_game(const GameState& g, int manager_slot,
const int first_team = league_first_team(league);
const int team_count = league_system().sizes[league];
if (first_team < 0 || first_team + team_count > 138 ||
if (first_team < 0 || first_team + team_count > world_layout().league_teams ||
g.club_ids.size() < size_t(first_team + team_count) || g.club_names.empty())
invalid("incomplete domestic club table");
+3 -3
View File
@@ -2532,7 +2532,7 @@ PendingOfferResult process_natural_pending_offers_after_desk(GameState& g,
};
if (record_team(0)!=kNoTeam) return false;
const int club=record_team(4*kRecord);
if (club<0 || club>=138) return false;
if (club<0 || club>=world_layout().league_teams) return false;
const auto squad=squad_range(club);
if (squad.first+squad.count>g.squad_slots.size()) return false;
for (size_t i=squad.first;i<squad.first+squad.count;++i)
@@ -2546,7 +2546,7 @@ PendingOfferResult process_natural_pending_offers_after_desk(GameState& g,
if(offer==0xffffffffu || int(offer&31)!=manager)continue;
const int team=native_team;
const bool national_owner = takeover && team == kNoTeam;
if (team<0 || (team>=138 && !national_owner))
if (team<0 || (team>=world_layout().league_teams && !national_owner))
return fail("AdvanceTurn: national or unknown owner is unsupported for normal-club offers");
// AdvanceTurn scans raw offer words until the first owned player resolves in
// an ordinary squad. A missing earlier player requires PresentLoanReturn's error
@@ -2710,7 +2710,7 @@ void transfer_list_countdown(GameState& g, GameRandom& game, WatcomRandom& rand,
// FindManagerForClub also recognizes the coach's temporarily saved
// club as owner 4 while manager 0 runs the national team.
return g.manager_of(club) >= 0 || (!g.manager_teams.empty() &&
g.manager_teams[0] == 0x165 && mem.has(::bmh::layout::DeskActions_NationalOpponentManager_RuntimeField) &&
g.manager_teams[0] == kNoTeam && mem.has(::bmh::layout::DeskActions_NationalOpponentManager_RuntimeField) &&
int(mem.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)) == club);
};
bool human_involved = human_participant(seller);