League system: the league tables of the loaded game as one structure
The mutable globals of schedule.hpp (league sizes, calendar groups, promotion ladder, European places, league suffixes, newcomers, English competitions) are members of LeagueSystem in world_layout.hpp, read through league_system() and written only by the installer of a game version. Values and uses are unchanged. The size check of set_league_sizes asks the world layout for the league teams. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
74d6cde914
commit
cb6d3b6035
38 files changed
+232
-180
No files matched your search
+12
-12
@@ -358,7 +358,7 @@ void initialize_saved_replay_group(MatchGroup& group, GameState& state, size_t i
|
||||
const int match = mem.u8(record + 4);
|
||||
if (league < 0 || league >= kLeagueCount || round < 0 ||
|
||||
round >= league_matchdays(league) ||
|
||||
match >= int(kLeagueSizes[league] / 2))
|
||||
match >= int(league_system().sizes[league] / 2))
|
||||
throw std::runtime_error("saved replay record is outside the league schedule");
|
||||
const std::vector<Fixture> fixtures = generate_fixtures(
|
||||
league_table_teams(league), round + 1, league_matchdays(league) / 2,
|
||||
@@ -585,20 +585,20 @@ static void install_league_sizes(const LeImage& exe) {
|
||||
for (int l = 0; l < kLeagueCount; ++l) sizes[l] = exe.u8(::bmh::layout::LeagueSizes + uint32_t(l));
|
||||
set_league_sizes(sizes);
|
||||
install_fixture_tables(exe);
|
||||
kEnglishCompetitions = sizes[0] == 20;
|
||||
installed_league_system().english_competitions = sizes[0] == 20;
|
||||
// the calendar groups (CalendarFirstLeague first league, CalendarLeagueCounts league count per bit)
|
||||
uint8_t first[8], count[8];
|
||||
for (uint32_t b = 0; b < 8; ++b) first[b] = exe.u8(::bmh::layout::CalendarFirstLeague + b), count[b] = exe.u8(::bmh::layout::CalendarLeagueCounts + b);
|
||||
set_league_groups(first, count);
|
||||
// the promotion ladder (schedule.hpp)
|
||||
for (uint32_t l = 0; l < uint32_t(kLeagueCount); ++l) {
|
||||
kLeagueRelegation[l] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField2 + l);
|
||||
kLeagueEurope[l] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField + l);
|
||||
kLeagueSuffix[l] = char(l < 5 ? exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField3 + l * 2) : 0);
|
||||
installed_league_system().relegation[l] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField2 + l);
|
||||
installed_league_system().europe[l] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField + l);
|
||||
installed_league_system().suffix[l] = char(l < 5 ? exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField3 + l * 2) : 0);
|
||||
}
|
||||
for (uint32_t g = 0; g < 8; ++g) kGroupBelow[g] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField5 + g), kGroupBelowCount[g] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField4 + g);
|
||||
kNewcomerFirst = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
kNewcomerCount = exe.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6);
|
||||
for (uint32_t g = 0; g < 8; ++g) installed_league_system().below_first[g] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField5 + g), installed_league_system().below_count[g] = exe.u8(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField4 + g);
|
||||
installed_league_system().newcomer_first = exe.u16(::bmh::layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
installed_league_system().newcomer_count = exe.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6);
|
||||
// EXE strings the engine posts (messages.hpp)
|
||||
install_message_texts(exe);
|
||||
install_career_rules(exe);
|
||||
@@ -1280,9 +1280,9 @@ std::string source_table_range_label(const TextDb& texts,int first,int end) {
|
||||
// DE50860 patches offsets 4/7 of its nine-byte TEXTD82 buffer. EN1e83f
|
||||
// patches 0/3 of the full " 0-34 only" string instead (the final y is live).
|
||||
const auto fixed=texts.raw(82,9);
|
||||
auto raw=kEnglishCompetitions ? texts[82] : std::string(fixed.begin(),fixed.end());
|
||||
const size_t start=kEnglishCompetitions ? 0 : 4;
|
||||
const size_t finish=kEnglishCompetitions ? 3 : 7;
|
||||
auto raw=league_system().english_competitions ? texts[82] : std::string(fixed.begin(),fixed.end());
|
||||
const size_t start=league_system().english_competitions ? 0 : 4;
|
||||
const size_t finish=league_system().english_competitions ? 3 : 7;
|
||||
if(raw.size()<finish+2)throw FormatError("league table: incomplete Source range label");
|
||||
auto patch_number=[&](size_t at,int value) {
|
||||
const int tens=value/10,ones=value%10;
|
||||
@@ -3051,7 +3051,7 @@ std::optional<ui::OpportunitiesState> CareerSession::open_opportunities(
|
||||
uint16_t mode=g_.memory.u16(choice_at);if(mode==0){mode=1;g_.memory.set16(choice_at,mode);}
|
||||
if(mode!=1&&mode!=2&&mode!=4&&mode!=8)throw FormatError("opportunities: invalid stored Source mode");
|
||||
ui::OpportunitiesState page;page.identity={manager,team,national_source_case?stable_identity:int(g_.club_ids[size_t(team)]),uint32_t(g_.date),revision+1,next_opportunities_scope_,0};
|
||||
page.mode=mode;page.league_size=kLeagueSizes[league];page.underlay=underlay;
|
||||
page.mode=mode;page.league_size=league_system().sizes[league];page.underlay=underlay;
|
||||
page.gradient_text=g_.memory.has(::bmh::layout::TextGradientDisabled)&&g_.memory.u8(::bmh::layout::TextGradientDisabled)==0&&g_.memory.has(::bmh::layout::TextGradientMode)&&g_.memory.u8(::bmh::layout::TextGradientMode)==2;
|
||||
page.current_rank=national_source_case?national_opportunities_rank(g_,team,page.ranks):table_prediction(g_,team,mode,page.ranks,nullptr);
|
||||
opportunities_owner_=OpportunitiesOwner{page,save_stream(g_),game_,rand_,national_source_case};++next_opportunities_scope_;
|
||||
|
||||
@@ -427,7 +427,7 @@ void Console::finish_kickoff(const ui::DeskState& before, const TurnAdvanceResul
|
||||
name = ui::league_table_from_game(session_->state(), active_slot(), *group.league_id).league_name;
|
||||
// (the indoor tournament, 0xb, has a runtime name: TEXTD only holds the placeholder
|
||||
// "...xxx"; the projection already carries the name frozen for these results)
|
||||
else if (group.cup_id && *group.cup_id >= 0 && *group.cup_id < 13 && (*group.cup_id != 0xb || bmh::kEnglishCompetitions))
|
||||
else if (group.cup_id && *group.cup_id >= 0 && *group.cup_id < 13 && (*group.cup_id != 0xb || bmh::league_system().english_competitions))
|
||||
name = text(kCompetitionNames + *group.cup_id);
|
||||
if (group.matches.empty()) continue;
|
||||
emit('i', name + ":");
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ 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 kLeagueSizes, schedule.hpp)
|
||||
// (the clubs per league are league_system().sizes, schedule.hpp)
|
||||
int kLeagueStrength[9][2] = {{71, 93}, {49, 71}, {28, 49}, {28, 49}, {10, 28},
|
||||
{85, 95}, {90, 95}, {75, 95}, {80, 95}};
|
||||
|
||||
@@ -89,7 +89,7 @@ void startup_players(GameState& g, GameRandom& game, WatcomRandom& rand) {
|
||||
const int league = team_league(team);
|
||||
index = league == previous ? index + 1 : 0;
|
||||
previous = league;
|
||||
const uint32_t count = uint32_t(kLeagueSizes[league]);
|
||||
const uint32_t count = uint32_t(league_system().sizes[league]);
|
||||
const uint32_t range = uint32_t(kLeagueStrength[league][1] - kLeagueStrength[league][0]);
|
||||
const int level = int16_t(int((count - uint32_t(index)) * range * 100) / int(count) / 100) + kLeagueStrength[league][0];
|
||||
const SquadRange r = squad_range(team);
|
||||
@@ -665,7 +665,7 @@ void english_competition_blocks(StaticMemory& mem) {
|
||||
}
|
||||
|
||||
void competition_pointers(StaticMemory& mem, const LeImage& exe) {
|
||||
if (kEnglishCompetitions) {
|
||||
if (league_system().english_competitions) {
|
||||
competition_pointers_english(mem, exe);
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ GameState startup_state(const LeImage& exe, const Database& db, const Bytes& m3_
|
||||
// the leagues, cups and tournaments.
|
||||
void competition_pointers(StaticMemory& mem, const LeImage& exe);
|
||||
|
||||
// The memory of the English-only competitions (Football Limited, kEnglishCompetitions):
|
||||
// The memory of the English-only competitions (Football Limited, league_system().english_competitions):
|
||||
// blocks at their English addresses, which no German address uses. FA Cup results (67
|
||||
// matches) and fields (68 clubs: the 20 Premier League clubs, the 48 of the qualifying
|
||||
// stage, the proper rounds), the League Cup (44 clubs, three entries) and entry 35.
|
||||
|
||||
+4
-4
@@ -352,7 +352,7 @@ void setup_cup_groups(GameState& g, int id, std::vector<MatchGroup>& groups, Min
|
||||
grp.desc.at(1) = flags;
|
||||
// competition 11 is the German indoor tournament; in the English game the same entry
|
||||
// is the League Cup ("Koka Kola Cup"), an ordinary cup on grass (EN Put32)
|
||||
if (type == 0xb && !kEnglishCompetitions) g.indoor = true;
|
||||
if (type == 0xb && !league_system().english_competitions) g.indoor = true;
|
||||
put32(grp.desc, 0xcc, e);
|
||||
// the first leg of a two-legged knockout tie is never decided on the day
|
||||
if ((flags & 5) == 5 && mem.u8(e + 0x1d) % 2 == 0) grp.desc.at(1) &= 0xF7;
|
||||
@@ -539,7 +539,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report,
|
||||
if (type == 9) return store_replays(g, g.season_day());
|
||||
// EndCompetition(type), re-added at the next preparation; the English Put32 keeps its
|
||||
// League Cup (type 0xb) running like the other cups
|
||||
if (type == 0xb && !kEnglishCompetitions) remove_competition(mem, type);
|
||||
if (type == 0xb && !league_system().english_competitions) remove_competition(mem, type);
|
||||
if (type == 10) {
|
||||
// the friendlies: off the running list, the day's calendar entry masked with 0xffe
|
||||
// (0x4001 becomes 0) and no teams left in today's entry (CupRuntimeField2)
|
||||
@@ -643,7 +643,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report,
|
||||
mem.set16(cup_entry_address(mem.u8(e + 0x17)) + 0x22, winners[1]);
|
||||
// (the indoor tournament only: the English League Cup has no Masters; its winner
|
||||
// would go to EN CupRuntimeField6 for Europe - not ported, see docs/fltd.md)
|
||||
if (type != 0xb || kEnglishCompetitions) return;
|
||||
if (type != 0xb || league_system().english_competitions) return;
|
||||
// the indoor tournament: the four places (CupRuntimeField7 picks them from the list
|
||||
// champion..fourth) earn points for the Masters (CupRuntimeField8 x strength class
|
||||
// Cup_AdvanceCup_RuntimeField3, clubs of the first two leagues only), then the next tournament is
|
||||
@@ -673,7 +673,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report,
|
||||
static constexpr uint8_t kPlacePoints[5] = {0, 6, 4, 2, 1}; // CupRuntimeField8
|
||||
for (int i = 0; i < 4 && size_t(kPlaceOrder[i]) < winners.size(); i++) { // Uint32T
|
||||
const int team = winners[kPlaceOrder[i]];
|
||||
if (team < kLeagueSizes[0] + kLeagueSizes[1]) {
|
||||
if (team < league_system().sizes[0] + league_system().sizes[1]) {
|
||||
const uint32_t at = ::bmh::layout::Cup_AdvanceCup_ExecutableField + uint32_t(team) * 2;
|
||||
mem.set16(at, uint16_t(mem.u16(at) + kPlacePoints[i + 1] * mem.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField3)));
|
||||
}
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ void enter_desk(GameState& g, int manager, GameRandom& game, WatcomRandom& rand,
|
||||
uint8_t v = uint8_t(g.memory.u8(at) & 0xf);
|
||||
// EN AlwaysHidesRecordIndoorTableIncluding always hides record 10 (IndoorTable), including
|
||||
// Modus III. DE HasNoEquivalentCondition has no equivalent condition.
|
||||
if ((kEnglishCompetitions && b == 10) ||
|
||||
if ((league_system().english_competitions && b == 10) ||
|
||||
(team == kNoTeam && kButtons[b] == 0) || (mode < 3 && kButtons[mode * 0x36 + b] == 0) ||
|
||||
(b == 0x16 && mode2 == 1 && g.date < 0x16e))
|
||||
v |= 0x10;
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ int team_region(int team) {
|
||||
if (team == kNoTeam) return 0;
|
||||
int t = team;
|
||||
for (int league = 0; league < kLeagueCount; league++) {
|
||||
t -= kLeagueSizes[league];
|
||||
t -= league_system().sizes[league];
|
||||
if (t < 0) return league >= kFirstRegionalLeague ? league - kFirstRegionalLeague + 1 : 0;
|
||||
}
|
||||
if (t - kCupTeams >= 0) return (t - kCupTeams) / 7 - kFirstRegionalLeague + 10;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace {
|
||||
constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 255,
|
||||
4, 255, 255, 255, 255, 255, 255, 1, 0, 0, 0, 0};
|
||||
// Clubs per league (LeagueSizes): five leagues of 18, four regional leagues of 12.
|
||||
// (the clubs per league are kLeagueSizes, schedule.hpp)
|
||||
// (the clubs per league are league_system().sizes, schedule.hpp)
|
||||
// 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};
|
||||
@@ -55,7 +55,7 @@ int league_of(int team) {
|
||||
if (team > 0x164) return 0;
|
||||
int end = 0;
|
||||
for (int l = 0; l < 9; l++) {
|
||||
end += kLeagueSizes[l];
|
||||
end += league_system().sizes[l];
|
||||
if (team < end) return l;
|
||||
}
|
||||
return 9;
|
||||
@@ -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 < kLeagueSizes[0] || (home >= 90 && home < 138);
|
||||
const bool league = home < league_system().sizes[0] || (home >= 90 && home < 138);
|
||||
const int win_points = kThreePoints[league_of(home)] ? 3 : 2;
|
||||
if (league) {
|
||||
add16(H + 0x20, hg);
|
||||
@@ -672,7 +672,7 @@ void manager_match_record(GameState& g, const MatchGroup& grp, int m, int home_g
|
||||
rating += int16_t(add);
|
||||
} else {
|
||||
int league = league_of(g.manager_teams[k]);
|
||||
int size = league < 9 ? kLeagueSizes[league] : 0;
|
||||
int size = league < 9 ? league_system().sizes[league] : 0;
|
||||
rating += (size - table_position(g, g.manager_teams[k])) * 4;
|
||||
}
|
||||
rating = std::clamp(int16_t(rating), int16_t(0), int16_t(200));
|
||||
@@ -710,15 +710,15 @@ static void store_strength_history(GameState& g, int manager) {
|
||||
}
|
||||
g.manager_records.at(rec + 0x222 + n) = uint8_t(team_average(g, team, 0xFF).value);
|
||||
int pos = table_position(g, team);
|
||||
if (pos == -1) pos = (kLeagueSizes[g.manager_records.at(rec + 0x210)] - 1) >> 1;
|
||||
if (pos == -1) pos = (league_system().sizes[g.manager_records.at(rec + 0x210)] - 1) >> 1;
|
||||
g.manager_records.at(rec + 0x248 + n) = uint8_t(pos);
|
||||
}
|
||||
|
||||
void advance_league_rounds(GameState& g, uint32_t competitions, WatcomRandom& rand, MinuteReport& report,
|
||||
const CompetitionWinnerHook& winner) {
|
||||
// CalendarFirstLeague / CalendarLeagueCounts: first league and league count of competition bits 0-7
|
||||
const uint8_t* kFirst = kGroupLeague; // (schedule.hpp: the groups of the loaded game)
|
||||
const uint8_t* kCount = kGroupLeagues;
|
||||
const uint8_t* kFirst = league_system().group_first; // (schedule.hpp: the groups of the loaded game)
|
||||
const uint8_t* kCount = league_system().group_count;
|
||||
for (int bit = 0; bit < 19; bit++) {
|
||||
if (!(competitions >> bit & 1)) continue;
|
||||
if (bit >= 5) {
|
||||
@@ -762,7 +762,7 @@ void advance_league_rounds(GameState& g, uint32_t competitions, WatcomRandom& ra
|
||||
if (c + 1 == end && g.league_rounds.at(2) == league_matchdays(2)) {
|
||||
uint32_t n = 0;
|
||||
for (int l = 2; l < 4; l++)
|
||||
for (int team = league_first_team(l); team < league_first_team(l) + kLeagueSizes[l]; team++) {
|
||||
for (int team = league_first_team(l); team < league_first_team(l) + league_system().sizes[l]; team++) {
|
||||
const uint8_t pos = uint8_t(table_position(g, team));
|
||||
if (pos != 0 && pos < 3) g.memory.set16(::bmh::layout::Teams + n++ * 2, uint16_t(team));
|
||||
}
|
||||
|
||||
+10
-10
@@ -37,7 +37,7 @@ constexpr uint8_t kCompetitionClass[24] = {0, 1, 2, 2, 2, 3, 3, 3, 3, 255, 0, 25
|
||||
4, 255, 255, 255, 255, 255, 255, 1, 0, 0, 0, 0};
|
||||
// League groups per competition bit 0-4 (CalendarFirstLeague first league, CalendarLeagueCounts count;
|
||||
// the arrays are indexed with the bit for bits 0-3 and with 4..7 for bit 4).
|
||||
// (kGroupLeague / kGroupLeagues: schedule.hpp, the calendar groups of the loaded game)
|
||||
// (league_system().group_first / league_system().group_count: schedule.hpp, the calendar groups of the loaded game)
|
||||
// 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).
|
||||
@@ -312,7 +312,7 @@ void winter_postponements(GameState& g, int day, int league, GameRandom& game, W
|
||||
if (count == 0) return;
|
||||
for (int slot = 0; slot < kPostponedEntries; slot++) {
|
||||
if (g.memory.u16(kPostponed + uint32_t(slot) * 6) != 0) continue;
|
||||
const int m = rand.range(0, kLeagueSizes[league] / 2 - 1);
|
||||
const int m = rand.range(0, league_system().sizes[league] / 2 - 1);
|
||||
if ((g.results.at(size_t(m) + size_t(round) * 10 + size_t(league) * 0x17C) & 0xcf) == 0xcc &&
|
||||
schedule_replay(g, day, league, m, slot, round, game)) {
|
||||
count--;
|
||||
@@ -385,7 +385,7 @@ void indoor_tournament_draw(GameState& g, GameRandom& game, WatcomRandom& rand)
|
||||
if (guest != 0) mem.set16(kTeams, uint16_t(rand.range(90, 137)));
|
||||
int count = guest != 0;
|
||||
int n = rand.range(5, 7);
|
||||
uint8_t lo = 0, hi = uint8_t(kLeagueSizes[0]);
|
||||
uint8_t lo = 0, hi = uint8_t(league_system().sizes[0]);
|
||||
uint32_t previous;
|
||||
do {
|
||||
for (int s = 0; s < n; s++) {
|
||||
@@ -415,8 +415,8 @@ void indoor_tournament_draw(GameState& g, GameRandom& game, WatcomRandom& rand)
|
||||
n = 8 - count;
|
||||
previous = hi;
|
||||
lo = hi;
|
||||
hi = uint8_t(hi + kLeagueSizes[1]);
|
||||
} while (previous < uint32_t(kLeagueSizes[0] + kLeagueSizes[1]));
|
||||
hi = uint8_t(hi + league_system().sizes[1]);
|
||||
} while (previous < uint32_t(league_system().sizes[0] + league_system().sizes[1]));
|
||||
std::string title;
|
||||
for (size_t i = 3; i < g.tournament_name.size() && g.tournament_name[i]; i++) title.push_back(char(g.tournament_name[i]));
|
||||
for (uint32_t k = 0; k < 8; k++) {
|
||||
@@ -438,7 +438,7 @@ void indoor_tournament_draw(GameState& g, GameRandom& game, WatcomRandom& rand)
|
||||
for (uint32_t k = 0; k < 8; k++) {
|
||||
const int t = mem.u16(kTeams + k * 2);
|
||||
const int league = t > 0x164 ? 0 : team_league(t); // TeamLeague2
|
||||
if (league < 2) sum += (0x26 - table_position(g, t)) - kLeagueSizes[0] * league;
|
||||
if (league < 2) sum += (0x26 - table_position(g, t)) - league_system().sizes[0] * league;
|
||||
else if (league < 5) sum += 1;
|
||||
else sum += 0x19;
|
||||
}
|
||||
@@ -450,14 +450,14 @@ uint32_t day_competitions(const GameState& g, uint16_t entry) {
|
||||
if (g.memory.u8(::bmh::layout::CalendarState_FormatError_RuntimeField2) != 0) v = entry & 0x7fef;
|
||||
// (German: the indoor option off removes the indoor days; the English CycleManagerOptions2 has no
|
||||
// such test - its 0x4002 days are the League Cup)
|
||||
if (!kEnglishCompetitions && g.memory.u8(::bmh::layout::CalendarState_FormatError_RuntimeField) != 0 && v == 0x4002) v = 0;
|
||||
if (!league_system().english_competitions && g.memory.u8(::bmh::layout::CalendarState_FormatError_RuntimeField) != 0 && v == 0x4002) v = 0;
|
||||
if ((v & 0x4001) == 0x4001) v = (v & 0xff0) | 0x8000;
|
||||
if (v == 0x4002) v = 0x10000;
|
||||
if (v == 0x4004) v = 0x40000;
|
||||
if (v == 0x4006) v = (g.memory.u8(::bmh::layout::CompetitionSelection) & 2) ? 0x800000 : 0;
|
||||
// the international tournament of the year (bits 9-12) turns with the season; the English
|
||||
// CycleManagerOptions2 counts from 1995 and adds 3 ((season + 3) % 4) to stay in step
|
||||
if (v & 0x1e00) v &= 1u << (0xc - (g.season + (kEnglishCompetitions ? 3 : 0)) % 4);
|
||||
if (v & 0x1e00) v &= 1u << (0xc - (g.season + (league_system().english_competitions ? 3 : 0)) % 4);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -568,11 +568,11 @@ std::vector<MatchGroup> setup_matchday(GameState& g, uint32_t competitions, cons
|
||||
const int from = bit, to = bit < 4 ? bit + 1 : 8;
|
||||
for (int k = from; k < to; k++) {
|
||||
// FixturesFromGenerateFixtures(k)
|
||||
for (int league = kGroupLeague[k]; league < kGroupLeague[k] + kGroupLeagues[k]; league++) {
|
||||
for (int league = league_system().group_first[k]; league < league_system().group_first[k] + league_system().group_count[k]; league++) {
|
||||
turn_step = "setup: winter postponements";
|
||||
winter_postponements(g, ctx.season_day, league, game, rand);
|
||||
const int round = g.league_rounds.at(size_t(league));
|
||||
const int size = kLeagueSizes[league];
|
||||
const int size = league_system().sizes[league];
|
||||
MatchGroup grp;
|
||||
grp.desc = group_descriptor(g, groups.size());
|
||||
for (const Fixture& f : generate_fixtures(league_table_teams(league), round + 1, league_matchdays(league) / 2, league_first_team(league))) {
|
||||
|
||||
@@ -191,12 +191,12 @@ std::string format_number_wide(const GameState& g, int64_t value, int flags) {
|
||||
std::string format_amount(const GameState& g, int32_t value) { return format_number(g, value, 0x101); }
|
||||
|
||||
void install_message_texts(const LeImage& exe) {
|
||||
kContractEndsSoonText = exe.cstring(kEnglishCompetitions ? ::bmh::layout::EnglishContractExpiryWarningText : ::bmh::layout::ContractExpiryWarningText);
|
||||
kMastersQualificationText = kEnglishCompetitions ? "Masters entry confirmed. Your participation bonus has been credited." : exe.cstring(::bmh::layout::MastersQualificationText);
|
||||
kMastersWinnerText = kEnglishCompetitions ? "Masters title won. Your prize money has been credited." : exe.cstring(::bmh::layout::MastersWinnerText);
|
||||
kIndoorInvitationText = kEnglishCompetitions ? "Indoor event entry bonus credited for " : exe.cstring(::bmh::layout::IndoorInvitationText);
|
||||
kChampionshipBonusText = kEnglishCompetitions ? "League title bonus credited." : exe.cstring(::bmh::layout::ChampionshipBonusText);
|
||||
kFriendlyPayerPrefixText = kEnglishCompetitions ? "Your share: " : exe.cstring(::bmh::layout::NationalFriendlyPayerPrefixText);
|
||||
kContractEndsSoonText = exe.cstring(league_system().english_competitions ? ::bmh::layout::EnglishContractExpiryWarningText : ::bmh::layout::ContractExpiryWarningText);
|
||||
kMastersQualificationText = league_system().english_competitions ? "Masters entry confirmed. Your participation bonus has been credited." : exe.cstring(::bmh::layout::MastersQualificationText);
|
||||
kMastersWinnerText = league_system().english_competitions ? "Masters title won. Your prize money has been credited." : exe.cstring(::bmh::layout::MastersWinnerText);
|
||||
kIndoorInvitationText = league_system().english_competitions ? "Indoor event entry bonus credited for " : exe.cstring(::bmh::layout::IndoorInvitationText);
|
||||
kChampionshipBonusText = league_system().english_competitions ? "League title bonus credited." : exe.cstring(::bmh::layout::ChampionshipBonusText);
|
||||
kFriendlyPayerPrefixText = league_system().english_competitions ? "Your share: " : exe.cstring(::bmh::layout::NationalFriendlyPayerPrefixText);
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
@@ -23,8 +23,8 @@ constexpr size_t kBoard = 0x840; // tactics board of a manager
|
||||
constexpr size_t kBoardSlot = 0x58; // one slot of the board
|
||||
|
||||
// Static league tables of V2.24 (not part of the savegame):
|
||||
// (European places per league, CareerSession_InstallLeagueSizes_RuntimeField, are kLeagueEurope of the loaded game; league 0 uses 4)
|
||||
// (the relegation places per league, CareerSession_InstallLeagueSizes_RuntimeField2, are kLeagueRelegation of the loaded game)
|
||||
// (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.
|
||||
@@ -41,11 +41,11 @@ int table_prediction(GameState& g, int team, int mode, std::array<uint8_t, 24>&
|
||||
// (Fill would refresh the desk warning flags PredictionRuntimeField.. here; they are
|
||||
// run-time only and not needed by the game logic.)
|
||||
const size_t rec = size_t(manager) * kRecord;
|
||||
const int size = kLeagueSizes[league]; // local_2c
|
||||
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;
|
||||
const int pos = team - league_first_team(league); // local_24
|
||||
const int target[3] = {0, league == 0 ? 4 : kLeagueEurope[league], size - kLeagueRelegation[league]};
|
||||
const int target[3] = {0, league == 0 ? 4 : league_system().europe[league], size - league_system().relegation[league]};
|
||||
|
||||
int from = 0; // local_10
|
||||
if (mode > 3) {
|
||||
@@ -147,7 +147,7 @@ static uint32_t season_bonus_impl(GameState& g, int manager, int team, int board
|
||||
if (league == 0 && rank == 0) amount = pay_bonus(g, manager, board_slot, 3, pay);
|
||||
if (amount == 0 && rank < 5) amount = pay_bonus(g, manager, board_slot, 4, pay);
|
||||
if (amount == 0 && rank < 10) amount = pay_bonus(g, manager, board_slot, 5, pay);
|
||||
if (amount == 0 && league < kLeagueCount && rank < kLeagueSizes[league] - kLeagueRelegation[league])
|
||||
if (amount == 0 && league < kLeagueCount && rank < league_system().sizes[league] - league_system().relegation[league])
|
||||
amount = pay_bonus(g, manager, board_slot, 6, pay);
|
||||
return amount;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ constexpr uint8_t kRescheduledMark = 0xce; // param_5 = -0x32
|
||||
constexpr size_t kRecordSize = 0xb0c;
|
||||
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 kGroupLeague in matchday_setup.cpp).
|
||||
// (kLeagueBit: schedule.hpp, set from the groups of the loaded game; 0xff = not played)
|
||||
// leagues of 12 clubs bit 4; compare league_system().group_first in matchday_setup.cpp).
|
||||
// (league_system().calendar_bit: schedule.hpp, set from the groups of the loaded game; 0xff = not played)
|
||||
|
||||
size_t result_at(int league, int round, int match) { return size_t(match) + size_t(round) * 10 + size_t(league) * 0x17c; }
|
||||
|
||||
@@ -122,14 +122,14 @@ std::vector<LeagueMatchRef> reschedulable_matches(const GameState& g, int manage
|
||||
// The screen only reacts to the calendar bit of the club's league for bits 0-3
|
||||
// (local_34 == bit); CalendarCell derives local_34 as league - (league > 2).
|
||||
const int screen_bit = league > 2 ? league - 1 : league;
|
||||
if (screen_bit > 3 || kLeagueBit[league] != screen_bit) return out;
|
||||
if (screen_bit > 3 || league_system().calendar_bit[league] != screen_bit) return out;
|
||||
// DaysIntoSeason, the day of the season; its saved copy in g.memory is only the load day
|
||||
const int today = g.season_day();
|
||||
const int matchdays = league_matchdays(league);
|
||||
int round = -1;
|
||||
for (int day = 0; day < kCalendarDays; day++) {
|
||||
const uint32_t comps = day_competitions(g, g.memory.u16(kCalendar + uint32_t(day) * 2));
|
||||
if (kLeagueBit[league] > 7 || !((comps >> kLeagueBit[league]) & 1)) continue;
|
||||
if (league_system().calendar_bit[league] > 7 || !((comps >> league_system().calendar_bit[league]) & 1)) continue;
|
||||
++round; // local_58 - 1: the league days up to this one
|
||||
if (day <= today || round == 0 || round + 2 >= matchdays) continue;
|
||||
const std::vector<Fixture> fixtures = round_fixtures(league, round);
|
||||
|
||||
@@ -96,14 +96,14 @@ void install_fixture_tables(const LeImage& exe) {
|
||||
|
||||
int league_first_team(int league) {
|
||||
int first = 0;
|
||||
for (int l = 0; l < league; l++) first += kLeagueSizes[l];
|
||||
for (int l = 0; l < league; l++) first += league_system().sizes[l];
|
||||
return first;
|
||||
}
|
||||
|
||||
int team_league(int team) {
|
||||
int end = 0;
|
||||
for (int l = 0; l < kLeagueCount; l++) {
|
||||
end += kLeagueSizes[l];
|
||||
end += league_system().sizes[l];
|
||||
if (team < end) return l;
|
||||
}
|
||||
return kLeagueCount;
|
||||
@@ -128,18 +128,18 @@ std::vector<Fixture> generate_fixtures(int teams, int matchday, int rounds, int
|
||||
return out;
|
||||
}
|
||||
|
||||
int league_table_teams(int league) { return league < 5 ? kLeagueSizes[0] : kLeagueSizes[5]; }
|
||||
int league_table_teams(int league) { return league < 5 ? league_system().sizes[0] : league_system().sizes[5]; }
|
||||
|
||||
void set_league_sizes(const uint8_t (&sizes)[kLeagueCount]) {
|
||||
int total = 0;
|
||||
for (int l = 0; l < kLeagueCount; l++) total += sizes[l];
|
||||
const auto has_table = [](int teams) { return teams == 20 || teams == 18 || teams == 16 || teams == 12; };
|
||||
if (total != 138 || !has_table(sizes[0]) || !has_table(sizes[5]))
|
||||
throw std::invalid_argument("league sizes do not describe 138 league teams with fixture tables");
|
||||
if (total != world_layout().league_teams || !has_table(sizes[0]) || !has_table(sizes[5]))
|
||||
throw std::invalid_argument("league sizes do not describe the league teams of the world with fixture tables");
|
||||
for (int l = 0; l < kLeagueCount; l++)
|
||||
if (sizes[l] < 2 || sizes[l] > (l < 5 ? sizes[0] : sizes[5]))
|
||||
throw std::invalid_argument("a league is larger than its fixture table");
|
||||
for (int l = 0; l < kLeagueCount; l++) kLeagueSizes[l] = sizes[l];
|
||||
for (int l = 0; l < kLeagueCount; l++) installed_league_system().sizes[l] = sizes[l];
|
||||
}
|
||||
|
||||
void set_league_groups(const uint8_t (&first)[8], const uint8_t (&count)[8]) {
|
||||
@@ -150,12 +150,12 @@ void set_league_groups(const uint8_t (&first)[8], const uint8_t (&count)[8]) {
|
||||
// (bits 4-7 are the four international leagues, all on calendar bit 4)
|
||||
for (int l = first[b]; l < first[b] + count[b]; l++) bit[l] = uint8_t(b < 4 ? b : 4);
|
||||
}
|
||||
for (int b = 0; b < 8; b++) kGroupLeague[b] = first[b], kGroupLeagues[b] = count[b];
|
||||
for (int l = 0; l < kLeagueCount; l++) kLeagueBit[l] = bit[l];
|
||||
for (int b = 0; b < 8; b++) installed_league_system().group_first[b] = first[b], installed_league_system().group_count[b] = count[b];
|
||||
for (int l = 0; l < kLeagueCount; l++) installed_league_system().calendar_bit[l] = bit[l];
|
||||
}
|
||||
|
||||
std::vector<Fixture> league_fixtures(int league, int matchday) {
|
||||
const int teams = kLeagueSizes[league];
|
||||
const int teams = league_system().sizes[league];
|
||||
return generate_fixtures(league_table_teams(league), matchday, teams - 1, league_first_team(league));
|
||||
}
|
||||
|
||||
|
||||
+10
-45
@@ -29,6 +29,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "game/world_layout.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
class LeImage;
|
||||
@@ -40,55 +42,18 @@ using FixtureTableCache = std::map<int, std::vector<std::string>>;
|
||||
void set_fixture_tables(FixtureTableCache tables);
|
||||
void install_fixture_tables(const LeImage& exe);
|
||||
|
||||
// Number of teams per league, LeagueSizes of the loaded game: the German versions have 5
|
||||
// leagues of 18 and 4 of 12; the English Football Limited 20 20 20 20 10 and the same four
|
||||
// international leagues of 12 (both 138 league teams, so the squad layout is the same).
|
||||
// The German sizes are the default; set_league_sizes() installs those of the loaded game
|
||||
// (app::CareerSession does it from the EXE table). One game per process.
|
||||
constexpr int kLeagueCount = 9;
|
||||
inline uint8_t kLeagueSizes[kLeagueCount] = {18, 18, 18, 18, 18, 12, 12, 12, 12};
|
||||
// The league structure of the loaded game (sizes, calendar groups, promotion ladder, cup structure)
|
||||
// is league_system() of world_layout.hpp. The German sizes are the default; app::CareerSession
|
||||
// installs those of the loaded game from the EXE tables. One game per process.
|
||||
//
|
||||
// Installs the league sizes of the loaded game; throws std::invalid_argument unless they
|
||||
// add up to 138 (the league teams of every version) and every league has a fixture table (20, 18, 16, 12 or 10 teams).
|
||||
// add up to the league teams of the world layout (138 in every version) and every league has a
|
||||
// fixture table (20, 18, 16, 12 or 10 teams).
|
||||
void set_league_sizes(const uint8_t (&sizes)[kLeagueCount]);
|
||||
|
||||
// The calendar groups of the loaded game: competition bits 0-7 play the leagues
|
||||
// kGroupLeague[bit] .. + kGroupLeagues[bit] - 1 (CalendarFirstLeague / CalendarLeagueCounts), and a league
|
||||
// plays on calendar bit kLeagueBit[league] (LeagueCalendarBits). German: 3. Liga A and B share
|
||||
// bit 2; English: every division has its own bit and the 10-team fifth league none (0xff
|
||||
// in kLeagueBit, not played). Set with the league sizes from the EXE tables.
|
||||
inline uint8_t kGroupLeague[8] = {0, 1, 2, 4, 5, 6, 7, 8};
|
||||
inline uint8_t kGroupLeagues[8] = {1, 1, 2, 1, 1, 1, 1, 1};
|
||||
inline uint8_t kLeagueBit[kLeagueCount] = {0, 1, 2, 2, 3, 4, 4, 4, 4};
|
||||
// Installs the calendar groups (first league and league count per competition bit) and derives
|
||||
// the calendar bit of every league from them.
|
||||
void set_league_groups(const uint8_t (&first)[8], const uint8_t (&count)[8]);
|
||||
|
||||
// The promotion ladder of the loaded game (Void / English ClubName), set with
|
||||
// the league sizes from the EXE tables:
|
||||
// - kLeagueRelegation[league]: relegation places (CareerSession_InstallLeagueSizes_RuntimeField2; German 3 4 2 2 3, English
|
||||
// 4 4 4 4 4),
|
||||
// - kGroupBelow[group] .. + kGroupBelowCount[group] - 1: the league(s) a promotion group
|
||||
// takes its promoted clubs from (CareerSession_InstallLeagueSizes_RuntimeField5 / CareerSession_InstallLeagueSizes_RuntimeField4; German 1 | 2 | 4 with the
|
||||
// two Regionalligen in one group, English 1 | 2 | 3),
|
||||
// - kLeagueSuffix[league]: the letter after a league's name (CareerSession_InstallLeagueSizes_RuntimeField3, two bytes per
|
||||
// league; German A/B for the Regionalligen, English none),
|
||||
// - kNewcomerFirst / kNewcomerCount: the clubs the lowest league is refilled from
|
||||
// (CareerSession_DispatchLineup_RuntimeField / CareerSession_InstallLeagueSizes_RuntimeField6; German the 30 amateur clubs 138-167; the English game
|
||||
// draws from its 12 further English clubs 138-149 - its later ids have no name - so the
|
||||
// session counts only named clubs).
|
||||
inline uint8_t kLeagueRelegation[kLeagueCount] = {3, 4, 2, 2, 3, 0, 0, 0, 0};
|
||||
// European places per league for the table prediction (CareerSession_InstallLeagueSizes_RuntimeField; German 0 3 2 2 4 - league
|
||||
// 0 uses 4 in the prediction -, English 0 4 4 4 4)
|
||||
inline uint8_t kLeagueEurope[kLeagueCount] = {0, 3, 2, 2, 4, 0, 0, 0, 0};
|
||||
inline uint8_t kGroupBelow[8] = {1, 2, 4, 5, 6, 7, 8, 0};
|
||||
inline uint8_t kGroupBelowCount[8] = {1, 2, 1, 1, 1, 1, 1, 0};
|
||||
inline char kLeagueSuffix[kLeagueCount] = {0, 0, 'A', 'B', 0, 0, 0, 0, 0};
|
||||
inline int kNewcomerFirst = 0x8a, kNewcomerCount = 0x1e;
|
||||
|
||||
// The English competition structure (Football Limited): an FA Cup of 68 clubs with a
|
||||
// qualifying stage (cup entries 0 and 28) and a League Cup (entries 25-27). Its cup memory
|
||||
// lies partly in blocks of its own (career.hpp, english_competition_blocks). Set with the
|
||||
// league sizes: a first league of 20 clubs is the English structure.
|
||||
inline bool kEnglishCompetitions = false;
|
||||
|
||||
// First team id of a league (sum of the sizes of all previous leagues).
|
||||
int league_first_team(int league);
|
||||
// League of a team id, or kLeagueCount for teams outside league play (TeamLeague2).
|
||||
|
||||
+28
-28
@@ -202,7 +202,7 @@ struct Entrants {
|
||||
|
||||
// OnTableJust(league, rank, ranks): the club with that final rank (0 if none)
|
||||
int club_at_rank(int league, int rank, const uint8_t* ranks) {
|
||||
for (int i = 0; i < kLeagueSizes[league]; i++)
|
||||
for (int i = 0; i < league_system().sizes[league]; i++)
|
||||
if (ranks[i] == rank) return league_first_team(league) + i;
|
||||
return 0;
|
||||
}
|
||||
@@ -370,12 +370,12 @@ void european_setup(GameState& g, GameRandom& game, WatcomRandom& rand, const Se
|
||||
if (u == 0) {
|
||||
// the national cup winner and finalist (+0x22/+0x24): entry 0, in the English
|
||||
// structure the FA Cup proper, entry 28 (U16: SeasonRuntimeField8/83c)
|
||||
const uint32_t cup = kEnglishCompetitions ? ::bmh::layout::CupTable + 28 * 0x28 : ::bmh::layout::CupTable;
|
||||
const uint32_t cup = league_system().english_competitions ? ::bmh::layout::CupTable + 28 * 0x28 : ::bmh::layout::CupTable;
|
||||
a = mem.u16(cup + 0x22), b = mem.u16(cup + 0x24);
|
||||
if (mem.has(::bmh::layout::Season_CareerSeasonSetup_RuntimeField7)) mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField7, uint16_t(a));
|
||||
} else {
|
||||
a = rand.range(0, kLeagueSizes[kLeague[u]] - 1);
|
||||
do b = rand.range(0, kLeagueSizes[kLeague[u]] - 1); while (b == a);
|
||||
a = rand.range(0, league_system().sizes[kLeague[u]] - 1);
|
||||
do b = rand.range(0, league_system().sizes[kLeague[u]] - 1); while (b == a);
|
||||
}
|
||||
const int first = kLeague[u] == 0 ? 0 : league_first_team(kLeague[u]);
|
||||
league_entrants(g, kLeague[u], uint8_t(a + first), uint8_t(b + first), kUefa[u]);
|
||||
@@ -818,7 +818,7 @@ void change_places(GameState& g, int a, int b) {
|
||||
replace(::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField19, 0x20);
|
||||
replace(::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField25, 0x40);
|
||||
// (the English national cup field: 68 clubs at layout field, InitializeNationalCup(0x44, ...))
|
||||
if (kEnglishCompetitions) {
|
||||
if (league_system().english_competitions) {
|
||||
if (mem.has(kEnglishFaField)) replace(kEnglishFaField, 0x44);
|
||||
} else {
|
||||
replace(::bmh::layout::Field, 0x40);
|
||||
@@ -850,7 +850,7 @@ void change_places(GameState& g, int a, int b) {
|
||||
void order_cup_ties(GameState& g, int teams, int offset) {
|
||||
StaticMemory& mem = g.memory;
|
||||
uint32_t list = mem.pointer(::bmh::layout::CupTable) + uint32_t(offset) * 2;
|
||||
if (kEnglishCompetitions) {
|
||||
if (league_system().english_competitions) {
|
||||
// the Football Limited CupField: the FA Cup stage decides the range - qualifying
|
||||
// round 1 (48 clubs from 0), round 2 (24 from 48), the proper rounds (entry 28);
|
||||
// with 0x80 the League Cup (entry 25)
|
||||
@@ -937,7 +937,7 @@ namespace {
|
||||
void shuffle_leagues(GameState& g, WatcomRandom& rand) {
|
||||
int first = 0;
|
||||
for (int l = 0; l < kLeagueCount; l++) {
|
||||
const int end = first + kLeagueSizes[l];
|
||||
const int end = first + league_system().sizes[l];
|
||||
for (int t = first; t < end; t++) {
|
||||
int r;
|
||||
do r = rand.range(first, end - 1); while (uint8_t(r) == uint8_t(t));
|
||||
@@ -994,7 +994,7 @@ void cup_fields_english(GameState& g, GameRandom& game, const uint8_t (&ranks)[4
|
||||
};
|
||||
uint32_t n = 0;
|
||||
for (int l = 0; l < 4; l++)
|
||||
for (int i = 0; i < kLeagueSizes[l]; i++) {
|
||||
for (int i = 0; i < league_system().sizes[l]; i++) {
|
||||
if (l >= 3 && i >= 8) continue;
|
||||
const int team = club_at_rank(l, i, ranks[l]);
|
||||
mem.set16(kEnglishFaField + n++ * 2, uint16_t(team));
|
||||
@@ -1012,7 +1012,7 @@ void cup_fields_english(GameState& g, GameRandom& game, const uint8_t (&ranks)[4
|
||||
}
|
||||
n = 0;
|
||||
for (int l = 0; l < 3; l++)
|
||||
for (int i = 0; i < kLeagueSizes[l]; i++) {
|
||||
for (int i = 0; i < league_system().sizes[l]; i++) {
|
||||
if (l >= 2 && i >= 4) continue;
|
||||
mem.set16(kEnglishLeagueCupField + n++ * 2, uint16_t(club_at_rank(l, i, ranks[l])));
|
||||
}
|
||||
@@ -1029,14 +1029,14 @@ void cup_field(GameState& g, GameRandom& game, const std::function<void(const ch
|
||||
const LeagueTable t = compute_league_table(g, l, 0, league_matchdays(l), 7, 1);
|
||||
for (int i = 0; i < t.size; i++) ranks[l][i] = uint8_t(t.rank(i));
|
||||
}
|
||||
if (kEnglishCompetitions) {
|
||||
if (league_system().english_competitions) {
|
||||
cup_fields_english(g, game, ranks, pause, cup_draw);
|
||||
return;
|
||||
}
|
||||
constexpr uint32_t kField = ::bmh::layout::Field;
|
||||
uint32_t n = 0;
|
||||
for (int l = 0; l < 4; l++)
|
||||
for (int i = 0; i < kLeagueSizes[l]; i++) {
|
||||
for (int i = 0; i < league_system().sizes[l]; i++) {
|
||||
if (l >= 2 && i >= 0xe) continue;
|
||||
const int team = club_at_rank(l, i, ranks[l]);
|
||||
mem.set16(kField + n++ * 2, uint16_t(team));
|
||||
@@ -1358,7 +1358,7 @@ void licence_withdrawals(GameState& g, int league, std::vector<uint16_t>& down,
|
||||
const int first = league_first_team(league);
|
||||
for (size_t m = 0; m < g.manager_teams.size(); m++) {
|
||||
const int team = g.manager_teams[m];
|
||||
if (team < first || team >= first + kLeagueSizes[league] || ranks[team - first] <= 5) continue;
|
||||
if (team < first || team >= first + league_system().sizes[league] || ranks[team - first] <= 5) continue;
|
||||
static const uint8_t kDownPlaces[kLeagueCount] = {3, 4, 2, 2, 3, 0, 0, 0, 0}; // CareerSession_InstallLeagueSizes_RuntimeField2
|
||||
if (kDownPlaces[league] == 0) continue;
|
||||
const uint8_t cut = rec8(g, int(m), 0x220);
|
||||
@@ -1375,7 +1375,7 @@ void licence_withdrawals(GameState& g, int league, std::vector<uint16_t>& down,
|
||||
int t = 0, r = 0;
|
||||
do {
|
||||
do {
|
||||
r = rand.range(0, kLeagueSizes[league] - 1);
|
||||
r = rand.range(0, league_system().sizes[league] - 1);
|
||||
t = first + r;
|
||||
} while (g.manager_of(t) >= 0);
|
||||
} while (ranks[r] < 10 || ranks[r] > 15);
|
||||
@@ -1407,22 +1407,22 @@ void promotion(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport&
|
||||
}
|
||||
// The league ladder is data of the loaded game (schedule.hpp, installed from the EXE):
|
||||
// Void reads the German tables, the English ClubName its own copies -
|
||||
// first league / number of leagues of each promotion group (kGroupLeague/s), relegation
|
||||
// places (kLeagueRelegation), the league(s) below (kGroupBelow/Count). German:
|
||||
// first league / number of leagues of each promotion group (league_system().group_first/s), relegation
|
||||
// places (league_system().relegation), the league(s) below (league_system().below_first/Count). German:
|
||||
// 0 | 1 | 2+3 (Regionalliga A/B) | 4; English: 0 | 1 | 2 | 3.
|
||||
const uint8_t* kFirst = kGroupLeague;
|
||||
const uint8_t* kCount = kGroupLeagues;
|
||||
const uint8_t* kDown = kLeagueRelegation;
|
||||
const uint8_t* kBelow = kGroupBelow;
|
||||
const uint8_t* kBelowCount = kGroupBelowCount;
|
||||
// The clubs that refill the lowest league: kNewcomerCount clubs from kNewcomerFirst
|
||||
const uint8_t* kFirst = league_system().group_first;
|
||||
const uint8_t* kCount = league_system().group_count;
|
||||
const uint8_t* kDown = league_system().relegation;
|
||||
const uint8_t* kBelow = league_system().below_first;
|
||||
const uint8_t* kBelowCount = league_system().below_count;
|
||||
// The clubs that refill the lowest league: league_system().newcomer_count clubs from league_system().newcomer_first
|
||||
// (German: the 30 amateur clubs 138-167). The English game draws from its 12 further
|
||||
// English clubs (ClubName: range(CareerSession_DispatchLineup_RuntimeField, CareerSession_DispatchLineup_RuntimeField + 11)); its later ids have no name.
|
||||
// The span ends at the last named club, which keeps the German draws unchanged.
|
||||
// (OpenBMH deviates from the English original here: its extra coin flip per draw is not
|
||||
// ported.)
|
||||
const int newcomer_first = kNewcomerFirst;
|
||||
int newcomer_count = kNewcomerCount;
|
||||
const int newcomer_first = league_system().newcomer_first;
|
||||
int newcomer_count = league_system().newcomer_count;
|
||||
while (newcomer_count > 1) {
|
||||
const std::string name = g.club_name(newcomer_first + newcomer_count - 1);
|
||||
if (club_has_name(name)) break;
|
||||
@@ -1433,7 +1433,7 @@ void promotion(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport&
|
||||
for (int l = kFirst[grp]; l < kFirst[grp] + kCount[grp]; l++) {
|
||||
int places = kDown[l];
|
||||
licence_withdrawals(g, l, down, places, ranks[l], game, rand);
|
||||
for (int rank = kLeagueSizes[l] - 1; places != 0; rank--) {
|
||||
for (int rank = league_system().sizes[l] - 1; places != 0; rank--) {
|
||||
const int team = club_at_rank(l, rank, ranks[l]);
|
||||
if (std::find(down.begin(), down.end(), uint16_t(team)) == down.end()) down.push_back(uint16_t(team)), places--;
|
||||
}
|
||||
@@ -1514,7 +1514,7 @@ void promotion(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport&
|
||||
std::string league_name(const GameState& g, int league) {
|
||||
// CareerSession_InstallLeagueSizes_RuntimeField3 of the loaded game (schedule.hpp: German A/B for the two Regionalligen,
|
||||
// English none - its four divisions are one ladder)
|
||||
const char* kSuffix = kLeagueSuffix;
|
||||
const char* kSuffix = league_system().suffix;
|
||||
int index = 0;
|
||||
for (int l = 0; l < league; l++)
|
||||
if (uint8_t(kSuffix[l + 1]) < 0x42) index++;
|
||||
@@ -1537,7 +1537,7 @@ int best_scorer_team(GameState& g, int league, int flags) {
|
||||
for (int i = 0; i < 40; i += 4) list[size_t(i)] = 0xfff, list[size_t(i) + 1] = 0xfff;
|
||||
int16_t best[10] = {};
|
||||
const int first = league_first_team(league);
|
||||
for (int team = first; team < first + kLeagueSizes[league]; team++) {
|
||||
for (int team = first; team < first + league_system().sizes[league]; team++) {
|
||||
if (g.manager_of(team) < 0 && (flags & 1)) continue;
|
||||
const SquadRange range = squad_range(team);
|
||||
for (size_t s = range.first; s < range.first + range.count; s++) {
|
||||
@@ -1570,7 +1570,7 @@ int best_scorer_team(GameState& g, int league, int flags) {
|
||||
// club's card counter DeskRecords_Teams_RuntimeField) and 1 per yellow, sorted ascending (Games).
|
||||
// Returns the club with the fewest points.
|
||||
int fair_play_team(const GameState& g, int league) {
|
||||
const int first = league_first_team(league), count = kLeagueSizes[league];
|
||||
const int first = league_first_team(league), count = league_system().sizes[league];
|
||||
std::vector<int16_t> teams(static_cast<size_t>(count));
|
||||
std::vector<uint32_t> points(static_cast<size_t>(count));
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -1683,7 +1683,7 @@ bool career_season_setup(GameState& g, GameRandom& game, WatcomRandom& rand, Min
|
||||
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);
|
||||
if (kEnglishCompetitions) mem.set16(::bmh::layout::CupTable + 28 * 0x28 + 0x22, 7); // (EN: the FA Cup proper, SeasonRuntimeField8)
|
||||
if (league_system().english_competitions) mem.set16(::bmh::layout::CupTable + 28 * 0x28 + 0x22, 7); // (EN: the FA Cup proper, SeasonRuntimeField8)
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField5, uint16_t(first_small + 0x1f));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField4, uint16_t(first_small + 0x13));
|
||||
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField3, uint16_t(foreign + 1));
|
||||
|
||||
+2
-2
@@ -77,12 +77,12 @@ void sort_table(LeagueTable& t, int parts) {
|
||||
}
|
||||
|
||||
|
||||
int league_matchdays(int league) { return kLeagueSizes[league] * 2 - 2; }
|
||||
int league_matchdays(int league) { return league_system().sizes[league] * 2 - 2; }
|
||||
|
||||
LeagueTable compute_league_table(const GameState& g, int league, int from, int to, int flags, int points_mode) {
|
||||
LeagueTable t;
|
||||
t.league = league;
|
||||
t.size = kLeagueSizes[league];
|
||||
t.size = league_system().sizes[league];
|
||||
int parts = 0;
|
||||
if (points_mode & 0xE) {
|
||||
parts = points_mode >> 1;
|
||||
|
||||
@@ -79,7 +79,7 @@ TopScorersProjection top_scorers_from_game(const GameState& g, int manager_slot,
|
||||
invalid("manager team is outside Source's nine domestic leagues");
|
||||
|
||||
const int first_team = league_first_team(league);
|
||||
const int team_count = kLeagueSizes[league];
|
||||
const int team_count = league_system().sizes[league];
|
||||
if (first_team < 0 || first_team + team_count > 138 ||
|
||||
g.club_ids.size() < size_t(first_team + team_count) || g.club_names.empty())
|
||||
invalid("incomplete domestic club table");
|
||||
|
||||
+1
-1
@@ -3026,7 +3026,7 @@ bool pre_match_offer(GameState& g, int manager, GameRandom& game, WatcomRandom&
|
||||
message_text(g, ::bmh::layout::Weekly_PreMatchOffer_TextPointer7) +
|
||||
// German: "<amount> KAUFEN" (with WeeklyRuntimeField11 " "); the English MessageText puts
|
||||
// the verb first: "BUY him for <amount>"
|
||||
(kEnglishCompetitions ? verb + amount : amount + " " + verb) + message_text(g, ::bmh::layout::Weekly_PreMatchOffer_TextPointer10);
|
||||
(league_system().english_competitions ? verb + amount : amount + " " + verb) + message_text(g, ::bmh::layout::Weekly_PreMatchOffer_TextPointer10);
|
||||
}
|
||||
// SystemIdentity shows it, PostMessage posts it
|
||||
post_composed(g, manager, text);
|
||||
|
||||
@@ -62,4 +62,62 @@ const WorldLayout& world_layout();
|
||||
// Installs a layout; throws std::invalid_argument when its ranges or its slot table are inconsistent.
|
||||
void set_world_layout(WorldLayout layout);
|
||||
|
||||
// The league structure of a game world: sizes, calendar groups, promotion ladder, cup structure.
|
||||
//
|
||||
// The German versions have 5 leagues of 18 and 4 of 12; the English Football Limited 20 20 20 20 10
|
||||
// and the same four international leagues of 12 (both 138 league teams, so the squad layout is the
|
||||
// same). Until 1.0.12 these tables were separate mutable globals of schedule.hpp (kLeagueSizes,
|
||||
// kGroupLeague, ...). The values and every use are unchanged; the German ones are the default.
|
||||
//
|
||||
// Still fixed (open for an edition with more leagues): the number of leagues (kLeagueCount, the size
|
||||
// of several tables of the save file), eight calendar groups, and the results block of schedule.hpp.
|
||||
constexpr int kLeagueCount = 9;
|
||||
|
||||
struct LeagueSystem {
|
||||
// Number of teams per league (LeagueSizes of the loaded game). Leagues are contiguous id ranges.
|
||||
uint8_t sizes[kLeagueCount] = {18, 18, 18, 18, 18, 12, 12, 12, 12};
|
||||
|
||||
// The calendar groups: competition bits 0-7 play the leagues group_first[bit] .. + group_count[bit] - 1
|
||||
// (CalendarFirstLeague / CalendarLeagueCounts), and a league plays on calendar bit calendar_bit[league]
|
||||
// (LeagueCalendarBits). German: 3. Liga A and B share bit 2; English: every division has its own
|
||||
// bit and the 10-team fifth league none (0xff in calendar_bit, not played).
|
||||
uint8_t group_first[8] = {0, 1, 2, 4, 5, 6, 7, 8};
|
||||
uint8_t group_count[8] = {1, 1, 2, 1, 1, 1, 1, 1};
|
||||
uint8_t calendar_bit[kLeagueCount] = {0, 1, 2, 2, 3, 4, 4, 4, 4};
|
||||
|
||||
// The promotion ladder (Void / English ClubName):
|
||||
// - relegation[league]: relegation places (CareerSession_InstallLeagueSizes_RuntimeField2; German 3 4 2 2 3,
|
||||
// English 4 4 4 4 4),
|
||||
// - below_first[group] .. + below_count[group] - 1: the league(s) a promotion group takes its promoted
|
||||
// clubs from (CareerSession_InstallLeagueSizes_RuntimeField5 / CareerSession_InstallLeagueSizes_RuntimeField4;
|
||||
// German 1 | 2 | 4 with the two Regionalligen in one group, English 1 | 2 | 3),
|
||||
// - suffix[league]: the letter after a league's name (CareerSession_InstallLeagueSizes_RuntimeField3, two
|
||||
// bytes per league; German A/B for the Regionalligen, English none),
|
||||
// - newcomer_first / newcomer_count: the clubs the lowest league is refilled from
|
||||
// (CareerSession_DispatchLineup_RuntimeField / CareerSession_InstallLeagueSizes_RuntimeField6; German the 30
|
||||
// amateur clubs 138-167; the English game draws from its 12 further English clubs 138-149 - its later
|
||||
// ids have no name - so the session counts only named clubs).
|
||||
uint8_t relegation[kLeagueCount] = {3, 4, 2, 2, 3, 0, 0, 0, 0};
|
||||
// European places per league for the table prediction (CareerSession_InstallLeagueSizes_RuntimeField;
|
||||
// German 0 3 2 2 4 - league 0 uses 4 in the prediction -, English 0 4 4 4 4)
|
||||
uint8_t europe[kLeagueCount] = {0, 3, 2, 2, 4, 0, 0, 0, 0};
|
||||
uint8_t below_first[8] = {1, 2, 4, 5, 6, 7, 8, 0};
|
||||
uint8_t below_count[8] = {1, 2, 1, 1, 1, 1, 1, 0};
|
||||
char suffix[kLeagueCount] = {0, 0, 'A', 'B', 0, 0, 0, 0, 0};
|
||||
int newcomer_first = 0x8a, newcomer_count = 0x1e;
|
||||
|
||||
// The English competition structure (Football Limited): an FA Cup of 68 clubs with a qualifying
|
||||
// stage (cup entries 0 and 28) and a League Cup (entries 25-27). Its cup memory lies partly in
|
||||
// blocks of its own (career.hpp, english_competition_blocks). A first league of 20 clubs is the
|
||||
// English structure.
|
||||
bool english_competitions = false;
|
||||
};
|
||||
|
||||
// The league structure of the running game. Read through league_system(); the installer of a game
|
||||
// version (app::CareerSession, set_league_sizes / set_league_groups of schedule.hpp) writes through
|
||||
// installed_league_system(). One game per process.
|
||||
inline LeagueSystem g_league_system;
|
||||
inline const LeagueSystem& league_system() { return g_league_system; }
|
||||
inline LeagueSystem& installed_league_system() { return g_league_system; }
|
||||
|
||||
} // namespace bmh
|
||||
+1
-1
@@ -49,7 +49,7 @@ CalendarScreen::CalendarScreen(const std::filesystem::path& data, CalendarState
|
||||
}
|
||||
// DE shares the third-tier bit between leagues 2/3; EN division 3
|
||||
// has its own bit. Use the loaded calendar topology for hit eligibility.
|
||||
active_calendar_class_ = league < kLeagueCount ? kLeagueBit[league] : -1;
|
||||
active_calendar_class_ = league < kLeagueCount ? league_system().calendar_bit[league] : -1;
|
||||
}
|
||||
(void)manager_name; // Source calendar's initial footer is empty, not a manager title.
|
||||
if (state_.season_start_counter > std::numeric_limits<uint32_t>::max() - 366 ||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ void source_frame(Image& out,int x,int y) {
|
||||
int region_for_team(int id) {
|
||||
if(id==kNoTeam)return 0;
|
||||
int t=id;
|
||||
for(int league=0;league<kLeagueCount;++league){t-=kLeagueSizes[league];if(t<0)return league>=5?league-5+1:0;}
|
||||
for(int league=0;league<kLeagueCount;++league){t-=league_system().sizes[league];if(t<0)return league>=5?league-5+1:0;}
|
||||
if(t-kCupOnlyTeams>=0)return (t-kCupOnlyTeams)/7-5+10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ uint8_t source_team_color(const GameState& g,int team) {
|
||||
|
||||
DeskRecordsState fair_play_state_from_game(const GameState& g, int league, const Image& underlay,int manager_slot) {
|
||||
if(league<0||league>=9) throw FormatError("fair play: invalid Source league");
|
||||
const int first=league_first_team(league), count=kLeagueSizes[league];
|
||||
const int first=league_first_team(league), count=league_system().sizes[league];
|
||||
if(first<0||count<=0||first+count>138||g.club_ids.size()<size_t(first+count))
|
||||
throw FormatError("fair play: incomplete Source league");
|
||||
std::vector<int16_t> teams(static_cast<size_t>(count)); std::vector<uint32_t> keys(static_cast<size_t>(count));
|
||||
@@ -75,7 +75,7 @@ DeskRecordsScreen::DeskRecordsScreen(const std::filesystem::path& data, DeskReco
|
||||
if(state_.kind==DeskRecordKind::fair_play) {
|
||||
kb56_=load_vga(asset_path(data/"KB","56.VGA"));
|
||||
const int bottom=int(state_.fair_play_rows.size())*9+38;
|
||||
if(state_.league<0||state_.league>=9||state_.fair_play_rows.size()!=size_t(kLeagueSizes[state_.league])||
|
||||
if(state_.league<0||state_.league>=9||state_.fair_play_rows.size()!=size_t(league_system().sizes[state_.league])||
|
||||
kb56_.width<296||kb56_.height<9+(bottom-28-1))
|
||||
throw FormatError("fair play: incomplete Original view");
|
||||
} else if(state_.highscore.ranked) {
|
||||
|
||||
@@ -61,7 +61,7 @@ FriendlyMatchState fixture(const std::filesystem::path& data) {
|
||||
table.league_id = league;
|
||||
table.league_name = "Liga";
|
||||
table.header_text = "Tabelle";
|
||||
for (int team = 0; team < bmh::kLeagueSizes[league]; ++team) {
|
||||
for (int team = 0; team < bmh::league_system().sizes[league]; ++team) {
|
||||
LeagueTableRow row;
|
||||
row.rank = team + 1;
|
||||
row.runtime_team_id = runtime++;
|
||||
@@ -273,7 +273,7 @@ int main(int argc, char** argv) {
|
||||
"only the authoritative success ACK completes the interaction");
|
||||
check(!screen.acknowledge_booking(accepted), "duplicate booking ACK is inert after completion");
|
||||
check(original.revision == 7 && original.planner_count == 4 &&
|
||||
original.leagues[0].rows.size() == size_t(bmh::kLeagueSizes[0]),
|
||||
original.leagues[0].rows.size() == size_t(bmh::league_system().sizes[0]),
|
||||
"screen interaction leaves its source projection unchanged");
|
||||
check(initial_json.find("friendly_match") != std::string::npos,
|
||||
"screen exposes machine-readable state for app routing");
|
||||
|
||||
@@ -78,7 +78,7 @@ void blit_table_region(Image& out, const Image& source, int source_y, int dest_y
|
||||
uint8_t original_rank_color(int league, int zero_based_rank) {
|
||||
uint8_t color = 0x37;
|
||||
if (zero_based_rank < kEuropeanPlaces[size_t(league)]) color = 0x51;
|
||||
else if (int(kLeagueSizes[league]) - zero_based_rank <= kRelegationPlaces[size_t(league)]) color = 0xf7;
|
||||
else if (int(league_system().sizes[league]) - zero_based_rank <= kRelegationPlaces[size_t(league)]) color = 0xf7;
|
||||
if (league == 0) {
|
||||
if (zero_based_rank == 0) color = 0x27;
|
||||
else if (zero_based_rank < 5) color = 0x7a;
|
||||
@@ -125,7 +125,7 @@ LeagueTableState project_league_table(const bmh::GameState& game, int manager_sl
|
||||
if (source_context && source_context->accepted_engine_table) {
|
||||
if (source_context->accepted_engine_league != league_id ||
|
||||
source_context->accepted_engine_table->league != league_id ||
|
||||
source_context->accepted_engine_table->size != bmh::kLeagueSizes[league_id])
|
||||
source_context->accepted_engine_table->size != bmh::league_system().sizes[league_id])
|
||||
throw FormatError("league table: accepted engine projection belongs to another league");
|
||||
engine_table = *source_context->accepted_engine_table;
|
||||
} else if (source_context) {
|
||||
@@ -168,7 +168,7 @@ LeagueTableState project_league_table(const bmh::GameState& game, int manager_sl
|
||||
state.retained_range_label_source_bytes = source_context->retained_range_label_source_bytes;
|
||||
state.forecast = source_context->forecast;
|
||||
}
|
||||
if (engine_table.size != bmh::kLeagueSizes[league_id])
|
||||
if (engine_table.size != bmh::league_system().sizes[league_id])
|
||||
throw FormatError("league table: incomplete engine projection for league " + std::to_string(league_id));
|
||||
|
||||
std::array<int, 20> order{};
|
||||
@@ -264,7 +264,7 @@ LeagueTableScreen::LeagueTableScreen(const std::filesystem::path& data,
|
||||
for (int league = 0; league < bmh::kLeagueCount; ++league) {
|
||||
const auto& table = tables_[size_t(league)];
|
||||
if (table.manager_slot != manager || table.league_id != league || table.header_text.empty() ||
|
||||
table.rows.size() != size_t(bmh::kLeagueSizes[league]) ||
|
||||
table.rows.size() != size_t(bmh::league_system().sizes[league]) ||
|
||||
table.original_table_panel != tables_[0].original_table_panel ||
|
||||
table.decorated_background != tables_[0].decorated_background ||
|
||||
table.secondary_leagues != tables_[0].secondary_leagues)
|
||||
@@ -457,8 +457,8 @@ Image LeagueTableScreen::render() const {
|
||||
int last_round = std::min<int>(table.rounds_played & 0x7f,
|
||||
league_matchdays(table.league_id));
|
||||
if (last_round < first_round) last_round = first_round;
|
||||
const size_t start=kEnglishCompetitions ? 0 : 4;
|
||||
const size_t finish=kEnglishCompetitions ? 3 : 7;
|
||||
const size_t start=league_system().english_competitions ? 0 : 4;
|
||||
const size_t finish=league_system().english_competitions ? 3 : 7;
|
||||
label[start] = char('0' + first_round / 10);
|
||||
label[start+1] = char('0' + first_round % 10);
|
||||
label[finish] = char('0' + last_round / 10);
|
||||
|
||||
@@ -95,7 +95,7 @@ int main(int argc, char** argv) {
|
||||
const auto& actual = tables[size_t(league)];
|
||||
const auto reference = compute_league_table(game, league, 0, league_matchdays(league), 7, 1);
|
||||
check(actual.manager_slot == manager && actual.league_id == league &&
|
||||
actual.rows.size() == size_t(kLeagueSizes[league]) && actual.points_mode == 1,
|
||||
actual.rows.size() == size_t(league_system().sizes[league]) && actual.points_mode == 1,
|
||||
"all leagues project an owned state with the engine's configured points rule");
|
||||
check(!actual.league_name.empty() && actual.league_name == original_league_title(game, exe, league),
|
||||
"league heading follows the independent EXE-suffix/TEXTD/Nation-ID oracle");
|
||||
|
||||
@@ -61,7 +61,7 @@ std::string competition_name(const MatchdayResultGroup& group,
|
||||
if (group.league_id) {
|
||||
const int league = *group.league_id;
|
||||
name = league < 5 ? league_name(game, league) : game.club_name(0x165 + league - 4);
|
||||
} else if (*group.cup_id == 0xb && !bmh::kEnglishCompetitions) { // (English: the League Cup, named below)
|
||||
} else if (*group.cup_id == 0xb && !bmh::league_system().english_competitions) { // (English: the League Cup, named below)
|
||||
// FinishEvent/BuildSideRecords: descriptor type 0x0c reads the runtime
|
||||
// TEXTD slot TournamentName, then appends edition TEXTD suffix MatchdayResults_CompetitionName_TextPointer.
|
||||
// The snapshot owns the name from before finish_event advances cups.
|
||||
|
||||
@@ -70,7 +70,7 @@ SeriesRecordsProjection series_records_from_game(const GameState& game, const Le
|
||||
out.league = league;
|
||||
out.league_row = team - league_first_team(league);
|
||||
out.rounds = game.league_rounds[size_t(league)];
|
||||
if (out.league_row < 0 || out.league_row >= kLeagueSizes[size_t(league)])
|
||||
if (out.league_row < 0 || out.league_row >= league_system().sizes[size_t(league)])
|
||||
throw FormatError("series records: manager club is outside the Source league");
|
||||
out.club_name = game.club_name(team);
|
||||
|
||||
@@ -110,7 +110,7 @@ SeriesRecordsScreen::SeriesRecordsScreen(const std::filesystem::path& data,
|
||||
projection_.runtime_team < 0 || projection_.runtime_team > 0x165 ||
|
||||
(projection_.source_available &&
|
||||
(projection_.league < 0 || projection_.league >= kLeagueCount ||
|
||||
projection_.league_row < 0 || projection_.league_row >= kLeagueSizes[size_t(projection_.league)])) ||
|
||||
projection_.league_row < 0 || projection_.league_row >= league_system().sizes[size_t(projection_.league)])) ||
|
||||
backdrop_.width != 320 || backdrop_.height != 240)
|
||||
throw FormatError("series records: incomplete Original projection");
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ uint8_t source_name_color(const GameState& game, int team) {
|
||||
std::vector<uint8_t> source_age_scratch(const GameState& game, int league, bool lineup_only) {
|
||||
const int first = league_first_team(league);
|
||||
std::vector<uint8_t> result;
|
||||
result.reserve(kLeagueSizes[league]);
|
||||
for (int team = first; team < first + kLeagueSizes[league]; ++team) {
|
||||
result.reserve(league_system().sizes[league]);
|
||||
for (int team = first; team < first + league_system().sizes[league]; ++team) {
|
||||
const SquadRange range = squad_range(team);
|
||||
if (range.first > game.squad_slots.size() ||
|
||||
range.count > game.squad_slots.size() - range.first)
|
||||
@@ -177,7 +177,7 @@ StrengthsProjection strengths_from_game(const GameState& game, int manager_slot,
|
||||
if (league < 5 && !game.texts) invalid("TEXTD data is unavailable for the league title");
|
||||
|
||||
const int first = league_first_team(league);
|
||||
const int size = kLeagueSizes[league];
|
||||
const int size = league_system().sizes[league];
|
||||
if (first < 0 || first + size > 138) 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");
|
||||
|
||||
@@ -100,7 +100,7 @@ TeamStatisticsProjection team_statistics_from_game(const GameState& game, int te
|
||||
if (out.league < 0 || out.league >= kLeagueCount)
|
||||
throw FormatError("team statistics: Source league index unavailable");
|
||||
out.league_row = team - league_first_team(out.league);
|
||||
if (out.league_row < 0 || out.league_row >= kLeagueSizes[out.league])
|
||||
if (out.league_row < 0 || out.league_row >= league_system().sizes[out.league])
|
||||
throw FormatError("team statistics: runtime team is not in a supported league table");
|
||||
out.source_flags = exe.u8(::bmh::layout::TableFlags + uint32_t(mode_number));
|
||||
out.points_mode = exe.u8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_RuntimeField + uint32_t(out.league));
|
||||
@@ -419,7 +419,7 @@ Image TeamStatisticsScreen::render() const {
|
||||
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) {
|
||||
const int clubs = kLeagueSizes[league];
|
||||
const int clubs = league_system().sizes[league];
|
||||
for (int round = 0; round < projection_.league_rounds && round < 39; ++round) {
|
||||
const size_t word_index = size_t(round / 3) * 2;
|
||||
const uint16_t packed = uint16_t(projection_.position_history[word_index] |
|
||||
|
||||
@@ -1096,13 +1096,13 @@ void check_strengths_semantic_and_controller(const std::filesystem::path& data)
|
||||
for(int n=0;n<9;++n) {
|
||||
const int league=(first_navigation+1+n)%9;
|
||||
page=action(StrengthsAction::select_league,StrengthsControl::condition,league);
|
||||
check(page&&page->page.projection.rows.size()==size_t(kLeagueSizes[league])&&
|
||||
check(page&&page->page.projection.rows.size()==size_t(league_system().sizes[league])&&
|
||||
page->page.projection.age_scratch.basis==StrengthsAgeBasis::entry_or_league_change_bit10&&
|
||||
!page->page.projection.age_scratch.lineup_only,"all nine ordinary leagues refresh age from current bit10");
|
||||
if(league>=5)check(page->page.projection.league_name==original_to_utf8(session->state().club_name(0x165+league-4)),
|
||||
"foreign ordinary leagues use actual country names without domestic suffix-table lookup");
|
||||
for(const auto& row:page->page.projection.rows)check(row.runtime_team>=league_first_team(league)&&
|
||||
row.runtime_team<league_first_team(league)+kLeagueSizes[league],"sorted rows retain authoritative runtime club identity");
|
||||
row.runtime_team<league_first_team(league)+league_system().sizes[league],"sorted rows retain authoritative runtime club identity");
|
||||
}
|
||||
neutral({id,StrengthsAction::team_info,StrengthsControl::condition,0});
|
||||
neutral({id,StrengthsAction::pairings});neutral({id,StrengthsAction::table});
|
||||
|
||||
@@ -3738,7 +3738,7 @@ int main(int argc, char** argv) {
|
||||
const int round = rebound.memory.u8(::bmh::layout::Postponed + uint32_t(postponed_slot) * 6 + 2);
|
||||
const int match = rebound.memory.u8(::bmh::layout::Postponed + uint32_t(postponed_slot) * 6 + 4);
|
||||
const size_t result_at = size_t(league) * 0x17c + size_t(round) * 10 + size_t(match);
|
||||
const auto scheduled = generate_fixtures(kLeagueSizes[league], round + 1,
|
||||
const auto scheduled = generate_fixtures(league_system().sizes[league], round + 1,
|
||||
league_matchdays(league) / 2, league_first_team(league));
|
||||
const std::vector<int> expected_replay{
|
||||
scheduled.at(size_t(match)).home, scheduled.at(size_t(match)).away};
|
||||
|
||||
@@ -189,7 +189,7 @@ int main(int argc, char** argv) {
|
||||
const auto& table_state = *standings.object()->at("state").object();
|
||||
check(*table_state.at("manager_slot").integer() == table_manager &&
|
||||
*table_state.at("league_id").integer() == table_league &&
|
||||
table_state.at("rows").array()->size() == size_t(kLeagueSizes[table_league]),
|
||||
table_state.at("rows").array()->size() == size_t(league_system().sizes[table_league]),
|
||||
"table query returns the explicitly selected league and its full roster");
|
||||
const auto expected_table = compute_league_table(reference.state(), table_league, 0,
|
||||
league_matchdays(table_league), 7, 1);
|
||||
|
||||
+1
-1
@@ -504,7 +504,7 @@ int run(int argc, char** argv) {
|
||||
}
|
||||
for (const auto& t : final_tables) {
|
||||
// (a league without calendar dates is not played: the English fifth league)
|
||||
if (t.league_id >= 0 && t.league_id < bmh::kLeagueCount && bmh::kLeagueBit[size_t(t.league_id)] > 7) continue;
|
||||
if (t.league_id >= 0 && t.league_id < bmh::kLeagueCount && bmh::league_system().calendar_bit[size_t(t.league_id)] > 7) continue;
|
||||
for (const auto& r : t.rows)
|
||||
if (r.games != 2 * (int(t.rows.size()) - 1))
|
||||
fail("season " + std::to_string(season) + ": " + t.league_name + " " + r.name + " ended with " + std::to_string(r.games) + " games");
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(int argc, char** argv) {
|
||||
const ui::DeskRequest origin{ui::DeskRequestKind::open_menu, 0, 0, 1, 0, revision};
|
||||
auto page = session.open_league_pairings(origin, revision, error);
|
||||
check(page.has_value(), error);
|
||||
const bool english = kLeagueSizes[0] == 20;
|
||||
const bool english = league_system().sizes[0] == 20;
|
||||
const int domestic_rows = english ? 10 : 9;
|
||||
check(page->rows.size() == size_t(domestic_rows) && stable(),
|
||||
"actual career opens all nine/ten pairings without changing live state or RNG");
|
||||
@@ -58,7 +58,7 @@ int main(int argc, char** argv) {
|
||||
// Four English divisions / five German divisions, then all four foreign
|
||||
// leagues. English league 4 has no calendar group and no selector button.
|
||||
for (int league = 0; league < 9; ++league) {
|
||||
if (kLeagueBit[league] == 0xff) continue;
|
||||
if (league_system().calendar_bit[league] == 0xff) continue;
|
||||
dispatch({LeaguePairingsAction::select_league, league});
|
||||
check(page->source.total_rounds == (league < 5 ? (english ? 38 : 34) : 22),
|
||||
"round count follows the loaded domestic/foreign league");
|
||||
|
||||
@@ -38,18 +38,18 @@ void tables(const std::filesystem::path& data) {
|
||||
check(bool(identity),error);
|
||||
const auto page=session.current_league_table_dispatch(error);
|
||||
check(bool(page),error);
|
||||
const bool english=kEnglishCompetitions;
|
||||
const bool english=league_system().english_competitions;
|
||||
const auto expected=english ? "01-01 only" : "Nur 01-01";
|
||||
check(page->page.retained_range_label_source_bytes==expected,
|
||||
std::string("range label follows the actual DE50860 / EN1e83f byte positions and keeps its suffix: ")+page->page.retained_range_label_source_bytes);
|
||||
const auto native=save_stream(session.state());const auto g=session.game();const auto w=session.rand();
|
||||
const auto all=ui::league_tables_from_game(session.state(),identity->manager);
|
||||
for(int league=0;league<kLeagueCount;++league) {
|
||||
if(kLeagueBit[league]==0xff)continue;
|
||||
if(league_system().calendar_bit[league]==0xff)continue;
|
||||
auto owner=*identity;owner.league=league;owner.league_group=league>=5;
|
||||
ui::LeagueTableScreen screen(data,all,league,ui::LeagueTableScreen::FamilyMode{owner});
|
||||
auto frame=screen.render();
|
||||
const int count=kLeagueSizes[league];
|
||||
const int count=league_system().sizes[league];
|
||||
check(all[size_t(league)].rows.size()==size_t(count),"table retains every loaded league row");
|
||||
check(frame.at(100,count*7+30)==0x40,"panel bottom follows eighteen/twenty/twelve rows");
|
||||
const int last_y=28+count*7-1;
|
||||
@@ -84,8 +84,8 @@ void statistics(const std::filesystem::path& data) {
|
||||
auto calendar=ui::calendar_from_game(session.state(),exe);
|
||||
const size_t target=size_t(calendar.current_day)+1;
|
||||
check(target<calendar.days.size(),"new career has a following calendar cell");
|
||||
const int own_bit=kEnglishCompetitions ? 3 : 2;
|
||||
const int other_bit=kEnglishCompetitions ? 2 : 3;
|
||||
const int own_bit=league_system().english_competitions ? 3 : 2;
|
||||
const int other_bit=league_system().english_competitions ? 2 : 3;
|
||||
const int fourth_division_team=league_first_team(3);
|
||||
auto accepts=[&](int bit) {
|
||||
auto projected=calendar;
|
||||
@@ -112,7 +112,7 @@ void statistics(const std::filesystem::path& data) {
|
||||
std::string error;
|
||||
auto opened=session.open_opportunities(owner,revision,menu.render_page(0),error);
|
||||
check(bool(opened),error);
|
||||
check(opened->league_size==kLeagueSizes[desk.league],"chances receives actual career league size");
|
||||
check(opened->league_size==league_system().sizes[desk.league],"chances receives actual career league size");
|
||||
ui::OpportunitiesScreen screen(data,*opened);
|
||||
check(screen.render().height==240,"actual DE/EN chances page renders, including rank-zero startup");
|
||||
// Unit-only nonzero ranks exercise the complete English ladder; no career
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
|
||||
const uint16_t lineup = LINEUP_ONLY | ALL_POSITIONS;
|
||||
std::printf("%-22s %3s %3s %3s %3s | %4s %4s %4s | %3s\n", "team", "K", "T", "F", "M", "KT", "KTF", "KTFM", "n");
|
||||
int first = league_first_team(league);
|
||||
for (int t = first; t < first + kLeagueSizes[league]; t++) {
|
||||
for (int t = first; t < first + league_system().sizes[league]; t++) {
|
||||
TeamAverage k = team_average(g, t, lineup | CONDITION);
|
||||
std::printf("%-22s %3d %3d %3d %3d | %4d %4d %4d | %3d\n", name(t).c_str(), k.value,
|
||||
team_average(g, t, lineup | TECHNIQUE).value, team_average(g, t, lineup | FORM).value,
|
||||
@@ -45,7 +45,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
std::printf("\nside ratings (legacy routine, computer teams): goal def mid att p4 p5, formation\n");
|
||||
for (int t = first; t < first + kLeagueSizes[league]; t++) {
|
||||
for (int t = first; t < first + league_system().sizes[league]; t++) {
|
||||
if (g.manager_of(t) >= 0) {
|
||||
std::printf("%-22s (human manager)\n", name(t).c_str());
|
||||
continue;
|
||||
|
||||
@@ -124,7 +124,7 @@ int g_league_goals = 0, g_league_matches = 0;
|
||||
void print_first_league_results(const GameState& g, const char* checkpoint) {
|
||||
int goals = 0, matches = 0;
|
||||
for (int round = 1; round <= league_matchdays(0); ++round)
|
||||
for (int match = 0; match < kLeagueSizes[0] / 2; ++match) {
|
||||
for (int match = 0; match < league_system().sizes[0] / 2; ++match) {
|
||||
const Result r = decode_result(g.results.at(result_index(0, round, match)));
|
||||
if (!r.played) continue;
|
||||
goals += r.home_goals + r.away_goals;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
|
||||
@@ -44,6 +45,34 @@ int main() {
|
||||
if (now.first != then.first || now.count != then.count)
|
||||
throw std::runtime_error("squad_range differs from the former table for team " + std::to_string(team));
|
||||
}
|
||||
// the league structure: the German tables are the default, exactly as the former globals
|
||||
{
|
||||
const LeagueSystem& s = league_system();
|
||||
const uint8_t sizes[9] = {18, 18, 18, 18, 18, 12, 12, 12, 12}, first[8] = {0, 1, 2, 4, 5, 6, 7, 8},
|
||||
count[8] = {1, 1, 2, 1, 1, 1, 1, 1}, bit[9] = {0, 1, 2, 2, 3, 4, 4, 4, 4},
|
||||
down[9] = {3, 4, 2, 2, 3, 0, 0, 0, 0}, europe[9] = {0, 3, 2, 2, 4, 0, 0, 0, 0},
|
||||
below[8] = {1, 2, 4, 5, 6, 7, 8, 0}, below_count[8] = {1, 2, 1, 1, 1, 1, 1, 0};
|
||||
const char suffix[9] = {0, 0, 'A', 'B', 0, 0, 0, 0, 0};
|
||||
int total = 0;
|
||||
for (int l = 0; l < kLeagueCount; ++l) {
|
||||
check(s.sizes[l] == sizes[l] && s.calendar_bit[l] == bit[l] && s.relegation[l] == down[l] &&
|
||||
s.europe[l] == europe[l] && s.suffix[l] == suffix[l], "a league table differs from the German default");
|
||||
total += s.sizes[l];
|
||||
}
|
||||
for (int b = 0; b < 8; ++b)
|
||||
check(s.group_first[b] == first[b] && s.group_count[b] == count[b] && s.below_first[b] == below[b] &&
|
||||
s.below_count[b] == below_count[b], "a group table differs from the German default");
|
||||
check(kLeagueCount == 9 && total == w.league_teams && s.newcomer_first == w.first_amateur() &&
|
||||
s.newcomer_count == w.amateur_teams && !s.english_competitions, "league totals differ");
|
||||
check(team_league(0) == 0 && team_league(17) == 0 && team_league(18) == 1 && team_league(89) == 4 &&
|
||||
team_league(90) == 5 && team_league(137) == 8 && team_league(138) == kLeagueCount &&
|
||||
league_first_team(5) == 90 && league_first_team(8) == 126, "team -> league differs");
|
||||
// league sizes that do not fill the league teams of the world are refused
|
||||
const uint8_t short_sizes[9] = {18, 18, 18, 18, 16, 12, 12, 12, 12};
|
||||
bool thrown = false;
|
||||
try { set_league_sizes(short_sizes); } catch (const std::invalid_argument&) { thrown = true; }
|
||||
check(thrown && league_system().sizes[4] == 18, "league sizes with 136 teams were accepted");
|
||||
}
|
||||
// inconsistent layouts are refused and leave the installed one alone
|
||||
const auto refused = [](WorldLayout layout) {
|
||||
try { set_world_layout(std::move(layout)); } catch (const std::invalid_argument&) { return true; }
|
||||
@@ -62,7 +91,7 @@ int main() {
|
||||
set_world_layout(classic_world_layout());
|
||||
check(squad_range(89).first == 89 * 24 && squad_range(90).first == 2160 && squad_range(0x165).first == 3072,
|
||||
"installing the Classic layout changed the squad table");
|
||||
std::printf("world layout: Classic numbers, squad table and validation passed\n");
|
||||
std::printf("world layout: Classic numbers, squad table, league structure and validation passed\n");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "%s\n", e.what());
|
||||
|
||||
Reference in new issue
Block a user