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:
1 parent
cb6d3b6035
commit
d552c59a77
29 files changed
+94
-93
No files matched your search
@@ -92,7 +92,7 @@ int national_opportunities_rank(const GameState& game,int team,std::array<uint8_
|
||||
ranks.fill(1);
|
||||
const int rounds=game.league_rounds.empty()?0:int8_t(game.league_rounds.at(0));
|
||||
if(rounds<2||rounds>=league_matchdays(0))return 0;
|
||||
return team>=138?9:0;
|
||||
return team>=world_layout().league_teams?9:0;
|
||||
}
|
||||
|
||||
// Reads one byte of the executable's data at 'address': from the game's memory image when the
|
||||
@@ -1454,7 +1454,7 @@ std::optional<ui::StrengthsIdentity> CareerSession::begin_friendly_opponent_tabl
|
||||
uint64_t revision,std::string& error) {
|
||||
error.clear();
|
||||
const auto request=strengths_open_request(revision);
|
||||
if(!request||request->identity.runtime_club>=168||request->identity.source_param2||
|
||||
if(!request||request->identity.runtime_club>=world_layout().first_foreign_cup()||request->identity.source_param2||
|
||||
league_family_owner_||strengths_owner_||league_pairings_draft_) {
|
||||
error="friendly table: unavailable club entry";return {};
|
||||
}
|
||||
@@ -1505,7 +1505,7 @@ std::optional<int> CareerSession::resolve_friendly_table_opponent(
|
||||
if(visible.runtime_team_id!=request.runtime_team||visible.club_identity_key!=request.expected_club_identity||
|
||||
visible.runtime_team_id<0||size_t(visible.runtime_team_id)>=g_.club_ids.size()||
|
||||
visible.club_identity_key!=int(g_.club_ids[size_t(visible.runtime_team_id)])||
|
||||
normal.rank!=row+1||normal.runtime_team_id<0||normal.runtime_team_id>=168||
|
||||
normal.rank!=row+1||normal.runtime_team_id<0||normal.runtime_team_id>=world_layout().first_foreign_cup()||
|
||||
size_t(normal.runtime_team_id)>=g_.club_ids.size()||
|
||||
normal.club_identity_key!=int(g_.club_ids[size_t(normal.runtime_team_id)])) {
|
||||
error="friendly table: opponent row identity changed";return {};
|
||||
@@ -2860,7 +2860,7 @@ std::optional<ui::TopScorersState> CareerSession::open_top_scorers(
|
||||
throw FormatError("top scorers: unsupported national-coach owner");
|
||||
stable_team = int(uint16_t(g_.manager_records[backup] |
|
||||
uint16_t(g_.manager_records[backup + 1]) << 8));
|
||||
} else if (team < 0 || team >= 138) {
|
||||
} else if (team < 0 || team >= world_layout().league_teams) {
|
||||
throw FormatError("top scorers: manager team is outside Source league scope");
|
||||
}
|
||||
if (stable_team < 0 || stable_team >= 138 || size_t(stable_team) >= g_.club_ids.size())
|
||||
@@ -2932,7 +2932,7 @@ std::optional<CareerSession::TopScorersDispatch> CareerSession::dispatch_top_sco
|
||||
(backup + 2 <= g_.manager_records.size() ?
|
||||
int(uint16_t(g_.manager_records[backup] |
|
||||
uint16_t(g_.manager_records[backup + 1]) << 8)) : -1) : identity.runtime_team;
|
||||
if (identity_team < 0 || identity_team >= 138 ||
|
||||
if (identity_team < 0 || identity_team >= world_layout().league_teams ||
|
||||
size_t(identity_team) >= g_.club_ids.size() ||
|
||||
int(g_.club_ids[size_t(identity_team)]) != identity.club_identity)
|
||||
throw FormatError("top scorers: stable club identity changed");
|
||||
@@ -3041,7 +3041,7 @@ std::optional<ui::OpportunitiesState> CareerSession::open_opportunities(
|
||||
const int manager=request.manager_slot,team=g_.manager_teams[size_t(manager)];
|
||||
const int league=national_source_case?0:team_league(team);
|
||||
if(national_source_case) {
|
||||
if(team!=0x165||league!=0)throw FormatError("opportunities: invalid national menu-6 owner");
|
||||
if(team!=kNoTeam||league!=0)throw FormatError("opportunities: invalid national menu-6 owner");
|
||||
if(stable_identity<0)throw FormatError("opportunities: missing national Desk identity");
|
||||
} else if(team<0||team>=138||size_t(team)>=g_.club_ids.size()||league<0||league>=9)
|
||||
throw FormatError("opportunities: unsupported team/league");
|
||||
@@ -3082,7 +3082,7 @@ std::optional<CareerSession::OpportunitiesDispatch> CareerSession::dispatch_oppo
|
||||
uint32_t(g_.date)!=current.identity.day_counter||
|
||||
size_t(current.identity.runtime_team)>=g_.club_ids.size()||
|
||||
(!national_source_case&&int(g_.club_ids[size_t(current.identity.runtime_team)])!=current.identity.stable_club_identity)||
|
||||
(national_source_case&&(current.identity.runtime_team!=0x165||
|
||||
(national_source_case&&(current.identity.runtime_team!=kNoTeam||
|
||||
current.identity.stable_club_identity<0)))
|
||||
throw FormatError("opportunities: desk owner changed");
|
||||
OpportunitiesDispatch result;result.page=current;
|
||||
|
||||
@@ -191,12 +191,12 @@ void serve_friendly_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
const auto& national=*request.national_booking;
|
||||
const auto expected=FriendlyActions::national_owner(request);
|
||||
if(request.kind!=ui::FriendlyRequestKind::book||!request.quote_id||
|
||||
request.runtime_team!=0x165||request.opponent<0x166||request.opponent>0x1a2||
|
||||
request.runtime_team!=kNoTeam||request.opponent<0x166||request.opponent>0x1a2||
|
||||
request.season_day<0||request.season_day>365||request.planner_count<0||
|
||||
request.planner_count>253||request.revision!=revision||
|
||||
national.owner!=expected||national.quote.owner!=expected||
|
||||
national.season_day!=request.season_day||national.quote.terms.manager!=manager||
|
||||
national.quote.terms.manager_team!=0x165||national.quote.terms.opponent!=request.opponent||
|
||||
national.quote.terms.manager_team!=kNoTeam||national.quote.terms.opponent!=request.opponent||
|
||||
national.quote.terms.planner_count!=request.planner_count||
|
||||
national.quote.terms.home_team!=request.home_team||national.quote.terms.away_team!=request.away_team||
|
||||
national.quote.terms.payer_manager!=request.payer_manager||
|
||||
@@ -287,7 +287,7 @@ void serve_friendly_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
// mapped to a German notice if it was not applied.
|
||||
if (request.kind != ui::FriendlyRequestKind::book || request.quote_id == 0 ||
|
||||
request.season_day < 0 || request.season_day > 365 || request.opponent < 0 ||
|
||||
request.opponent >= 168 || request.cost < 0 || request.planner_count > 253) {
|
||||
request.opponent >= world_layout().first_foreign_cup() || request.cost < 0 || request.planner_count > 253) {
|
||||
flow.reject_friendly_action("Die Angaben zum Spieltermin sind ungültig.");
|
||||
return;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ bool valid_national_friendly_family(const ui::StartupFlow& flow,const GameState&
|
||||
const auto* origin=flow.national_friendly_desk_owner();
|
||||
const auto* menu=flow.statistics_menu();
|
||||
const auto* desk=flow.desktop();
|
||||
if(!owner||!origin||!menu||!desk||owner->desk_menu!=6||owner->runtime_team!=0x165||
|
||||
if(!owner||!origin||!menu||!desk||owner->desk_menu!=6||owner->runtime_team!=kNoTeam||
|
||||
owner->manager<0||owner->revision!=revision||origin->kind!=ui::DeskRequestKind::open_menu||
|
||||
origin->menu_kind!=6||origin->manager_slot!=owner->manager||origin->revision!=revision||
|
||||
desk->state().revision!=revision||desk->state().manager_slot!=owner->manager||
|
||||
@@ -342,7 +342,7 @@ void serve_national_friendly_selection(ui::StartupFlow& flow,CareerSession& sess
|
||||
const int manager=owner->manager;
|
||||
// Identity check: owner and desk request must be the national-coach friendly menu at the current
|
||||
// revision for the same manager, who must still be on team slot 0x165 and be the active manager.
|
||||
if(owner->desk_menu!=6||owner->runtime_team!=0x165||owner->revision!=revision||
|
||||
if(owner->desk_menu!=6||owner->runtime_team!=kNoTeam||owner->revision!=revision||
|
||||
desk_request->kind!=ui::DeskRequestKind::open_menu||desk_request->menu_kind!=6||
|
||||
desk_request->revision!=revision||desk_request->manager_slot!=manager||
|
||||
desk.revision!=revision||desk.manager_slot!=manager||manager<0||
|
||||
@@ -2639,7 +2639,7 @@ struct FlowRequestServer {
|
||||
// for club managers the friendly opponent table is started in the session.
|
||||
const int manager=request.manager_slot;
|
||||
if(manager>=0&&size_t(manager)<game.manager_teams.size()&&
|
||||
game.manager_teams[size_t(manager)]==0x165) {
|
||||
game.manager_teams[size_t(manager)]==kNoTeam) {
|
||||
const auto projection=ui::world_cup_statistics_from_game(game,
|
||||
load_le(ui::asset_path(data,"BMH.exe")),
|
||||
ui::WorldCupStatisticsOwner::friendly_match_nation_picker);
|
||||
|
||||
@@ -459,7 +459,7 @@ void Console::register_transfer_commands() {
|
||||
Arg a;
|
||||
a.text = number;
|
||||
const auto id = to_int(a);
|
||||
if (!id || *id < 0 || *id >= 138) fail("E_BAD_ARGUMENT", "club is club:<n> (ListPoachClubs)");
|
||||
if (!id || *id < 0 || *id >= world_layout().league_teams) fail("E_BAD_ARGUMENT", "club is club:<n> (ListPoachClubs)");
|
||||
return int(*id);
|
||||
};
|
||||
Param club = detail::text("club");
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -37,7 +37,7 @@ AllTimeTableState alltime_table_from_game(const GameState&g,const LeImage&exe,De
|
||||
for(int t=0;t<168;++t){size_t b=size_t(t)*0x4a+0x1e;auto u=[&](int o){return uint16_t(g.club_table[b+size_t(o)]|uint16_t(g.club_table[b+size_t(o+1)])<<8);};auto&r=s.records[size_t(t)];r.points=u(0);r.goals_for=u(2);r.goals_against=u(4);r.wins=u(6);r.draws=u(8);r.losses=u(10);if(t<int(g.club_ids.size()))s.club_names[size_t(t)]=g.club_name(t);s.club_name_colors[size_t(t)]=team_color(g,t);}
|
||||
for(int n=0;n<5;++n)if(0x165+n<int(g.club_ids.size()))s.nation_names[size_t(n)]=g.club_name(0x165+n);
|
||||
const uint32_t start=kFirst+uint32_t(nation)*8;const int league=exe.u8(kLeague+uint32_t(nation));const uint32_t full=uint32_t(league_matchdays(league));
|
||||
for(int part=0;part<2;++part){int first=exe.u16(start+uint32_t(part)*4),end=exe.u16(::bmh::layout::AlltimeTable_AlltimeTableFromGame_RuntimeField+uint32_t(nation)*8+uint32_t(part)*4);for(int team=first;team<end;++team){if(team<0||team>=168)continue;const auto&r=s.records[size_t(team)];int played=int(r.wins)+r.draws+r.losses;if(!played)continue;uint32_t p=r.points,gf=r.goals_for,ga=r.goals_against;if(relative){p=p*full*10U/uint32_t(played);gf=gf*full*10U/uint32_t(played);ga=ga*full*10U/uint32_t(played);}AllTimeRow row;row.team=team;row.played=played;row.points=p;row.goals_for=gf;row.goals_against=ga;row.points_key=p*0x10001U+0x7d000000U;row.goal_key=gf*0x10001U-ga*0x10000U+0x7d000000U;s.rows.push_back(row);}}
|
||||
for(int part=0;part<2;++part){int first=exe.u16(start+uint32_t(part)*4),end=exe.u16(::bmh::layout::AlltimeTable_AlltimeTableFromGame_RuntimeField+uint32_t(nation)*8+uint32_t(part)*4);for(int team=first;team<end;++team){if(team<0||team>=world_layout().first_foreign_cup())continue;const auto&r=s.records[size_t(team)];int played=int(r.wins)+r.draws+r.losses;if(!played)continue;uint32_t p=r.points,gf=r.goals_for,ga=r.goals_against;if(relative){p=p*full*10U/uint32_t(played);gf=gf*full*10U/uint32_t(played);ga=ga*full*10U/uint32_t(played);}AllTimeRow row;row.team=team;row.played=played;row.points=p;row.goals_for=gf;row.goals_against=ga;row.points_key=p*0x10001U+0x7d000000U;row.goal_key=gf*0x10001U-ga*0x10000U+0x7d000000U;s.rows.push_back(row);}}
|
||||
std::stable_sort(s.rows.begin(),s.rows.end(),[](const auto&a,const auto&b){if(a.points_key!=b.points_key)return a.points_key>b.points_key;return a.goal_key>b.goal_key;});if(s.rows.size()>24)s.rows.resize(24);return s;
|
||||
}
|
||||
AllTimeTableScreen::AllTimeTableScreen(const std::filesystem::path&data,AllTimeTableState s):state_(std::move(s)),data_(data),exe_(load_le(asset_path(data,"BMH.exe"))),font_(load_font(asset_path(data/"F","BMH3.FNT"))),header_(load_font(asset_path(data/"F","BMH2.FNT"))),sprite_(data),window_(load_vga(asset_path(data/"KB","56.VGA"))),buttons_(load_vga(asset_path(data/"KB","0.VGA"))),texts_(load_textd(asset_path(data,"TEXTD.BLK"))){if(state_.underlay.width!=320||state_.underlay.height!=240)throw FormatError("alltime: invalid parent frame");}
|
||||
|
||||
@@ -50,7 +50,7 @@ ClubPlayerDetailProjection club_player_detail_from_game(const GameState& g,
|
||||
for(int i=0;i<2;++i){
|
||||
const int id=i?c.secondary_club:c.primary_club;if(id<0||id==0xffff)continue;
|
||||
ClubPlayerDetailClub club;club.runtime_team=id;club.original_full_name=g.club_name(id);club.original_short_name=club.original_full_name;
|
||||
if(id<168){
|
||||
if(id<world_layout().first_foreign_cup()){
|
||||
const uint8_t raw=g.memory.u8(::bmh::layout::ClubShortNameOffsets+uint32_t(id));
|
||||
club.original_short_name=club.original_short_name.substr(raw>>4,(raw&15)+1);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ ClubPlayerDetailScreen::ClubPlayerDetailScreen(const std::filesystem::path& data
|
||||
}
|
||||
// TextWidth national/foreign names: longest word, then remove two
|
||||
// trailing characters until FNT3 fits57 pixels.
|
||||
if(id>=168 && small_.text_width(club.original_short_name)>57){
|
||||
if(id>=world_layout().first_foreign_cup() && small_.text_width(club.original_short_name)>57){
|
||||
std::string longest;size_t at=0;
|
||||
while(at<club.original_short_name.size()){
|
||||
const size_t end=club.original_short_name.find(' ',at);
|
||||
|
||||
+3
-3
@@ -144,8 +144,8 @@ CupDrawProjection cup_draw_from_game(const GameState& game,const SeasonCupDrawEv
|
||||
std::string context;
|
||||
if(event.group_stage&&event.phase==SeasonCupDrawPhase::overview) {
|
||||
const bool human_national=game.manager_of(id)>=0||
|
||||
(game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==0x165&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==id);
|
||||
if(id>=168&&!human_national) {
|
||||
(game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField2)&&game.memory.has(::bmh::layout::CupDraw_FormatError_RuntimeField3)&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField2)==kNoTeam&&game.memory.u16(::bmh::layout::CupDraw_FormatError_RuntimeField3)==id);
|
||||
if(id>=world_layout().first_foreign_cup()&&!human_national) {
|
||||
if(size_t(id-168)>=game.foreign_strength.size())throw FormatError("cup draw: missing Source foreign-strength byte");
|
||||
const uint8_t strength=game.foreign_strength[size_t(id-168)];
|
||||
const unsigned band=strength>>5;
|
||||
@@ -155,7 +155,7 @@ CupDrawProjection cup_draw_from_game(const GameState& game,const SeasonCupDrawEv
|
||||
context+=original_to_utf8(exe.cstring(::bmh::layout::CupDraw_FormatError_ExecutableField));
|
||||
} else {
|
||||
std::array<int,5> values{};
|
||||
if(id>=168&&id!=kNoTeam) {
|
||||
if(id>=world_layout().first_foreign_cup()&&id!=kNoTeam) {
|
||||
const auto snapshot=std::find_if(event.group_average_snapshots.begin(),event.group_average_snapshots.end(),
|
||||
[&](const auto& v){return v.runtime_id==id;});
|
||||
if(snapshot==event.group_average_snapshots.end())
|
||||
|
||||
@@ -45,7 +45,7 @@ std::string pool_name(const Bytes& names, const std::vector<uint16_t>& offsets,
|
||||
}
|
||||
|
||||
int executable_league(const LeImage& exe, int team) {
|
||||
if (team < 0 || team >= 138 || !exe.contains(::bmh::layout::LeagueSizes + 8)) return -1;
|
||||
if (team < 0 || team >= world_layout().league_teams || !exe.contains(::bmh::layout::LeagueSizes + 8)) return -1;
|
||||
int first = 0;
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
if (!exe.contains(::bmh::layout::LeagueSizes + uint32_t(league))) return -1;
|
||||
@@ -85,7 +85,7 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
auto rank_curve = [&](int team, DeskRankCurve& curve) {
|
||||
curve.runtime_team = team;
|
||||
curve.team_name = pool_name(club_names, club_ids, team);
|
||||
if (team == 0x165) {
|
||||
if (team == kNoTeam) {
|
||||
// TablePosition returns rank 2 for this special national row;
|
||||
// QuoteNationalFriendlyMatch uses its native no-team squad (no random rating).
|
||||
curve.current_position = 2;
|
||||
@@ -105,7 +105,7 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
curve.samples.push_back({round + 1, int((packed >> ((round % 3) * 5)) & 0x1f)});
|
||||
}
|
||||
if (!curve.samples.empty()) curve.current_position = curve.samples.back().source_rank;
|
||||
if (game && team < 138) curve.strength = team_average(*game, team, 0x1ff).value;
|
||||
if (game && team < world_layout().league_teams) curve.strength = team_average(*game, team, 0x1ff).value;
|
||||
};
|
||||
rank_curve(d.runtime_club < 0 ? 0x165 : d.runtime_club, d.rank_curves[0]);
|
||||
if (authenticated_rival && *authenticated_rival >= 0 && *authenticated_rival != d.runtime_club)
|
||||
@@ -113,7 +113,7 @@ void project_drawer_rows(DeskState& d, const LeImage& exe, const Bytes& managers
|
||||
|
||||
// SourceDrawerTeam reads only the prepared opponent's venue history. Other
|
||||
// teams' names need not be available to render this manager's current Desk.
|
||||
if (!authenticated_rival || *authenticated_rival < 0 || *authenticated_rival >= 168) return;
|
||||
if (!authenticated_rival || *authenticated_rival < 0 || *authenticated_rival >= world_layout().first_foreign_cup()) return;
|
||||
const size_t at = manager * 0x690 + size_t(*authenticated_rival) * 10;
|
||||
if (at + 10 > manager_results.size()) return;
|
||||
const bool present = std::any_of(manager_results.begin() + at,
|
||||
@@ -629,7 +629,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
// OpenBMH deviates from the original: the desk shows the opponent's badge whenever the data has one.
|
||||
// The original draws a computer icon for the clubs between its two gate values (the foreign league
|
||||
// clubs); only the cup-only teams and the empty selector keep the icon.
|
||||
const bool fallback = (opponent & 0xfff) == 0xfff || (opponent >= 168 && opponent < 357);
|
||||
const bool fallback = (opponent & 0xfff) == 0xfff || (opponent >= world_layout().first_foreign_cup() && opponent < 357);
|
||||
d.next_opponent_badge_fallback = fallback;
|
||||
if (!fallback) {
|
||||
const size_t badge_at = size_t(opponent) * 2;
|
||||
|
||||
@@ -83,7 +83,7 @@ FriendlyMatchScreen::FriendlyMatchScreen(const std::filesystem::path& data, Frie
|
||||
data_(data), next_request_id_(state_.first_request_id) {
|
||||
const bool valid_national_slot = state_.national_team && state_.runtime_team == bmh::kNoTeam;
|
||||
if (state_.manager_slot < 0 || state_.manager_slot > 3 || state_.runtime_team < 0 ||
|
||||
(state_.runtime_team >= 168 && !valid_national_slot) ||
|
||||
(state_.runtime_team >= world_layout().first_foreign_cup() && !valid_national_slot) ||
|
||||
state_.revision == UINT64_MAX || !state_.first_request_id || state_.planner_count < 0 ||
|
||||
state_.planner_count > std::numeric_limits<int>::max() - 2)
|
||||
throw FormatError("friendly screen: invalid manager/request identity");
|
||||
@@ -347,7 +347,7 @@ std::optional<FriendlyMatchRequest> FriendlyMatchScreen::click(int x, int y, boo
|
||||
const int row = (y-0x1d)/7;
|
||||
if (row < 0 || size_t(row) >= rows.size()) return std::nullopt;
|
||||
selected_opponent_ = rows[size_t(row)].runtime_team_id;
|
||||
if (selected_opponent_ == state_.runtime_team || selected_opponent_ < 0 || selected_opponent_ >= 168) {
|
||||
if (selected_opponent_ == state_.runtime_team || selected_opponent_ < 0 || selected_opponent_ >= world_layout().first_foreign_cup()) {
|
||||
selected_opponent_ = -1;
|
||||
feedback_ = "Bitte einen anderen Ligaverein waehlen.";
|
||||
return std::nullopt;
|
||||
|
||||
@@ -38,7 +38,7 @@ int pending_offer_owner_team(const GameState& game, int manager) {
|
||||
throw FormatError("pending offer UI: missing retained Source club");
|
||||
const int team = int(game.manager_records[base + 0x290]) |
|
||||
(int(game.manager_records[base + 0x291]) << 8);
|
||||
if (team >= 138) throw FormatError("pending offer UI: invalid retained Source club");
|
||||
if (team >= world_layout().league_teams) throw FormatError("pending offer UI: invalid retained Source club");
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int ex
|
||||
const uint32_t offer = ::bmh::layout::OfferSlots + uint32_t(raw_offer_slot) * 4;
|
||||
const uint32_t list = ::bmh::layout::EditorList + uint32_t(raw_offer_slot + 40) * 0x58;
|
||||
const size_t pool = 0xb70 + size_t(raw_offer_slot + 40);
|
||||
if (team_at(0) != kNoTeam || buyer >= 138 || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
if (team_at(0) != kNoTeam || buyer >= world_layout().league_teams || buyer != expected_team || !game.memory.has(offer + 3) ||
|
||||
!game.memory.has(list + 0x57) || pool >= game.squad_slots.size())
|
||||
return false;
|
||||
const uint32_t word = game.memory.u32(offer);
|
||||
@@ -72,7 +72,7 @@ bool pending_offer_spare_buyer(const GameState& game, int raw_offer_slot, int ex
|
||||
if (word == 0xffffffffu || int(word & 31) != owner ||
|
||||
player == 0xfff || size_t(player) >= game.players.size() ||
|
||||
(game.squad_slots[pool] & 0xfff) != player || game.memory.u16(list) != buyer ||
|
||||
seller >= 138 || seller == buyer || (owner > 0 && team_at(size_t(owner)) != seller))
|
||||
seller >= world_layout().league_teams || seller == buyer || (owner > 0 && team_at(size_t(owner)) != seller))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ void validate(const PlayerCardState& s) {
|
||||
const auto& p=s.lineup.players.at(size_t(s.row));
|
||||
if(p.player_id!=(p.slot&0xfff)||p.row!=s.row)throw FormatError("player card: inconsistent player identity");
|
||||
if(s.statistics && s.statistics->months>12)throw FormatError("player statistics: more than twelve monthly samples");
|
||||
if(s.loan&&(s.loan->owner<0||s.loan->owner>=168||s.loan->borrower!=s.lineup.runtime_club||
|
||||
s.loan->borrower>=168||s.loan->months<0||s.loan->months>255||
|
||||
if(s.loan&&(s.loan->owner<0||s.loan->owner>=world_layout().first_foreign_cup()||s.loan->borrower!=s.lineup.runtime_club||
|
||||
s.loan->borrower>=world_layout().first_foreign_cup()||s.loan->months<0||s.loan->months>255||
|
||||
std::any_of(s.loan->badges.begin(),s.loan->badges.end(),[](int badge){return badge<0||badge>511;})))
|
||||
throw FormatError("player card: inconsistent ordinary loan context");
|
||||
}
|
||||
@@ -73,7 +73,7 @@ void context(PlayerCardState& out,const StaticMemory& memory,const Bytes& club_h
|
||||
// the ordinary borrower row, not the lender's ClubInfo_FormatError_RuntimeField snapshot.
|
||||
PlayerCardLoan detail;
|
||||
detail.owner=int(loan>>12&0x3ff);detail.borrower=int(loan>>22&0x3ff);
|
||||
if(detail.borrower!=out.lineup.runtime_club||detail.owner>=168||detail.borrower>=168||out.loan||!memory.has(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i)){
|
||||
if(detail.borrower!=out.lineup.runtime_club||detail.owner>=world_layout().first_foreign_cup()||detail.borrower>=world_layout().first_foreign_cup()||out.loan||!memory.has(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i)){
|
||||
out.unsupported_record="loan_record";continue;
|
||||
}
|
||||
detail.months=memory.u8(::bmh::layout::ClubPlayerDetail_InvalidArgument_RuntimeField+i);
|
||||
|
||||
@@ -458,8 +458,8 @@ Image SportschauMatchReport::render_report(size_t visible_log_entries,
|
||||
text(out, heading_, 0, 54, home_name, 0x5f, 156);
|
||||
text(out, heading_, 156, 54, away_name, 0x5f, 312);
|
||||
|
||||
const bool home_domestic = fixture_.home_team < 168;
|
||||
const bool away_domestic = fixture_.away_team < 168;
|
||||
const bool home_domestic = fixture_.home_team < world_layout().first_foreign_cup();
|
||||
const bool away_domestic = fixture_.away_team < world_layout().first_foreign_cup();
|
||||
// Some Original club abbreviation bytes are unavailable because the
|
||||
// source-side temporary buffer was never initialized. Keep the known
|
||||
// header, badge, score and report visible, and omit only that abbreviation.
|
||||
|
||||
@@ -178,7 +178,7 @@ StrengthsProjection strengths_from_game(const GameState& game, int manager_slot,
|
||||
|
||||
const int first = league_first_team(league);
|
||||
const int size = league_system().sizes[league];
|
||||
if (first < 0 || first + size > 138) invalid("league bounds exceed domestic club table");
|
||||
if (first < 0 || first + size > world_layout().league_teams) invalid("league bounds exceed domestic club table");
|
||||
if (game.club_ids.size() < size_t(first + size)) invalid("club ID table is truncated");
|
||||
if (game.club_names.empty()) invalid("club name pool is empty");
|
||||
for (int team = first; team < first + size; ++team) {
|
||||
|
||||
@@ -73,14 +73,14 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
if (team < 0 || team > 0x165) throw FormatError("team statistics: runtime team outside LeagueCalculations range");
|
||||
const int mode_number = int(mode);
|
||||
if (mode_number < 0 || mode_number > 2) throw FormatError("team statistics: invalid mode");
|
||||
if (team >= 138 && team < 168)
|
||||
if (team >= world_layout().league_teams && team < world_layout().first_foreign_cup())
|
||||
throw FormatError("team statistics: simulated teams require Source draw-state ratings and are not exposed here");
|
||||
TeamStatisticsProjection out;
|
||||
out.runtime_team = team;
|
||||
out.mode = mode;
|
||||
out.source_badge_fallback = original_badge_fallback(team,&exe);
|
||||
out.badge_heap = game.club_heap_78;
|
||||
if (team != 0x165) {
|
||||
if (team != kNoTeam) {
|
||||
int region_team = team;
|
||||
const int league_gate = exe.u8(::bmh::layout::LeaguePairings_LeaguePairingsConstants_RuntimeField);
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
@@ -93,7 +93,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.flag_index = uint8_t((region_team - int(exe.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6))) / 7 - league_gate + 10);
|
||||
}
|
||||
}
|
||||
out.source_has_league_panel = team < 0xa8;
|
||||
out.source_has_league_panel = team < world_layout().first_foreign_cup();
|
||||
out.league = team > 0x164 ? 0 : team_league(team);
|
||||
if (size_t(team) < game.club_ids.size()) out.original_team_name = game.club_name(team);
|
||||
if (out.source_has_league_panel) {
|
||||
@@ -119,7 +119,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.position_history.size(), out.position_history.begin());
|
||||
out.source_has_position_history = true;
|
||||
}
|
||||
} else if (team == 0x165) {
|
||||
} else if (team == kNoTeam) {
|
||||
// Source 357 maps to league 0 for common labels, but the save does not
|
||||
// contain a position-history row for this national-team pseudo-club.
|
||||
out.source_has_position_history = false;
|
||||
@@ -127,7 +127,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.gradient_text = (!game.memory.has(::bmh::layout::TextGradientDisabled) || game.memory.u8(::bmh::layout::TextGradientDisabled) == 0) && exe.u8(::bmh::layout::TextGradientMode) == 2;
|
||||
out.decorated_background = !game.memory.has(::bmh::layout::PlainBackground) || game.memory.u8(::bmh::layout::PlainBackground) == 0;
|
||||
|
||||
if (team < 138) {
|
||||
if (team < world_layout().league_teams) {
|
||||
constexpr std::array<uint16_t, 5> average_flags{0x1f1, 0x1f2, 0x1f4, 0x1f8, 0x1ff};
|
||||
for (size_t i = 0; i < average_flags.size(); ++i)
|
||||
out.source_averages[i] = uint16_t(team_average(game, team, average_flags[i]).value);
|
||||
@@ -162,7 +162,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
out.active_manager_team = owned;
|
||||
if (owned >= 0 && size_t(owned) < game.club_ids.size())
|
||||
out.active_manager_team_name = game.club_name(owned);
|
||||
out.source_has_head_to_head = team != owned && team < 0xa8 && owned != 0x165;
|
||||
out.source_has_head_to_head = team != owned && team < world_layout().first_foreign_cup() && owned != kNoTeam;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,7 +415,7 @@ Image TeamStatisticsScreen::render() const {
|
||||
uint16_t(projection_.badge_heap[size_t(projection_.runtime_team) * 2 + 1]) << 8) & 0x1ff;
|
||||
copy(out, crest_, (selector & 7) * 38, 0, 271, 55, 38, 38);
|
||||
}
|
||||
if (projection_.source_has_league_panel || projection_.runtime_team == 0x165) {
|
||||
if (projection_.source_has_league_panel || projection_.runtime_team == kNoTeam) {
|
||||
const int league = projection_.league;
|
||||
rect(out, 225, 150, 1, 43, 0x6a); rect(out, 225, 192, 81, 1, 0x6a);
|
||||
if (projection_.source_has_position_history && projection_.source_has_league_panel) {
|
||||
|
||||
Reference in new issue
Block a user