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:
ClaudeandClaude committed 2026-11-10 22:13:40 +01:00
1 parent 74d6cde914
commit cb6d3b6035
38 files changed
+232 -180

No files matched your search

+2 -2
View File
@@ -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});
+1 -1
View File
@@ -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};
+1 -1
View File
@@ -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
View File
@@ -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");
+2 -2
View File
@@ -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");
+6 -6
View File
@@ -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
View File
@@ -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;
+1 -1
View File
@@ -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;
+30 -1
View File
@@ -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());