Name the per-league stride of the results block; document the world layout

kLeagueResultsStride (records.hpp) replaces the literal 0x17C at 17 places, a
static_assert ties the block size to the league count. docs/architecture.md
describes WorldLayout, LeagueSystem and what is still fixed for a larger world.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude committed 2026-11-11 08:34:41 +01:00
1 parent 31ff36fb09
commit 81046f89f2
10 files changed
+40 -17

No files matched your search

+1 -1
View File
@@ -138,7 +138,7 @@ void store_replays(GameState& g, int day) {
if (mem.u16(at) != day) continue;
const uint16_t r = mem.u16(kReplayResults + uint32_t(k++) * 2);
const uint8_t result = uint8_t(((r >> 5) << 4) | (r & 0xf));
g.results.at(size_t(mem.u8(at + 4)) + size_t(mem.u8(at + 2)) * 10 + size_t(mem.u8(at + 3)) * 0x17C) = result;
g.results.at(size_t(mem.u8(at + 4)) + size_t(mem.u8(at + 2)) * 10 + size_t(mem.u8(at + 3)) * kLeagueResultsStride) = result;
mem.set16(at, 0);
}
remove_competition(mem, 9);
+7 -7
View File
@@ -287,7 +287,7 @@ bool schedule_replay(GameState& g, int day, int league, int m, int slot, int rou
g.memory.set8(at + 2, uint8_t(round));
g.memory.set8(at + 3, uint8_t(league));
g.memory.set8(at + 4, uint8_t(m));
g.results.at(size_t(m) + size_t(round) * 10 + size_t(league) * 0x17C) = kPostponedMark;
g.results.at(size_t(m) + size_t(round) * 10 + size_t(league) * kLeagueResultsStride) = kPostponedMark;
g.memory.set8(kCalendar + uint32_t(date) * 2 + 1, g.memory.u8(kCalendar + uint32_t(date) * 2 + 1) | 0x40);
return true;
}
@@ -312,7 +312,7 @@ void winter_postponements(GameState& g, int day, int league, GameRandom& game, W
for (int slot = 0; slot < kPostponedEntries; slot++) {
if (g.memory.u16(kPostponed + uint32_t(slot) * 6) != 0) continue;
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 &&
if ((g.results.at(size_t(m) + size_t(round) * 10 + size_t(league) * kLeagueResultsStride) & 0xcf) == 0xcc &&
schedule_replay(g, day, league, m, slot, round, game)) {
count--;
break;
@@ -510,7 +510,7 @@ bool matchday_needs_manager_desks(const GameState& g, uint16_t calendar_entry,
const uint32_t competition = rd32(group.desc, 0xcc);
for (size_t fixture = 0; fixture < size_t(group.matches()); ++fixture) {
if (competition < 0x14) {
const size_t result = size_t(competition) * 0x17c +
const size_t result = size_t(competition) * kLeagueResultsStride +
size_t(g.league_rounds.at(competition)) * 10 + fixture;
if (g.results.at(result) != 0xcc) continue;
} else if (int8_t(mem.u8(competition + 0x18) + 5) >= 0x1e) {
@@ -578,7 +578,7 @@ std::vector<MatchGroup> setup_matchday(GameState& g, uint32_t competitions, cons
grp.fixtures.push_back(f.home);
grp.fixtures.push_back(f.away);
}
const size_t at = size_t(league) * 0x17C + size_t(round) * 10;
const size_t at = size_t(league) * kLeagueResultsStride + size_t(round) * 10;
for (int m = 0; m < size / 2; m++) {
uint8_t& r = g.results.at(at + size_t(m));
if ((r & 0xCF) == 0xCE) r = 0xCD; // postponed -> to be replayed later
@@ -1006,7 +1006,7 @@ void kick_off(GameState& g, std::vector<MatchGroup>& groups, const MatchdayConte
grp.cup_results.assign(size_t(n), 0);
} else {
grp.results.assign(size_t(n), 0);
const size_t at = size_t(league) * 0x17C + size_t(g.league_rounds.at(size_t(league))) * 10;
const size_t at = size_t(league) * kLeagueResultsStride + size_t(g.league_rounds.at(size_t(league))) * 10;
for (int m = 0; m < n; m++) {
uint8_t& r = g.results.at(at + size_t(m));
if (r == 0xCC)
@@ -1053,7 +1053,7 @@ void kick_off(GameState& g, std::vector<MatchGroup>& groups, const MatchdayConte
const int home_goals = forfeit_side == 0 ? 0 : 2;
const int away_goals = forfeit_side == 0 ? 2 : 0;
if (grp.desc.at(0) == 0) {
const size_t at = size_t(league) * 0x17C +
const size_t at = size_t(league) * kLeagueResultsStride +
size_t(g.league_rounds.at(size_t(league))) * 10 + size_t(m);
const uint8_t score = uint8_t((home_goals << 4) | away_goals);
g.results.at(at) = score;
@@ -1149,7 +1149,7 @@ namespace {
void raw_score(const GameState& g, const MatchGroup& grp, int m, int& home, int& away) {
if (grp.desc.at(0) == 0) {
const int league = int(le32(grp.desc, 0xcc));
const uint8_t r = g.results.at(size_t(league) * 0x17C + size_t(g.league_rounds.at(size_t(league))) * 10 + size_t(m));
const uint8_t r = g.results.at(size_t(league) * kLeagueResultsStride + size_t(g.league_rounds.at(size_t(league))) * 10 + size_t(m));
home = r >> 4, away = r & 0xF;
} else {
const uint16_t r = grp.cup_results.at(size_t(m));
+3
View File
@@ -16,5 +16,8 @@ constexpr size_t kTacticsBoardSize = 0x840;
constexpr size_t kTacticsBoardSlotSize = 0x58;
// The league record of a club (*ClubSeasonRecords), one per club with league records.
constexpr size_t kClubRecordSize = 0x4a;
// One league's part of the results block (LeagueResults, schedule.hpp): 38 matchdays x 10 matches,
// whatever the size of the league.
constexpr size_t kLeagueResultsStride = 0x17C;
} // namespace bmh
+1 -1
View File
@@ -36,7 +36,7 @@ constexpr size_t kFloodlights = 0x0e; // manager record byte (RescheduleRuntime
// 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; }
size_t result_at(int league, int round, int match) { return size_t(match) + size_t(round) * 10 + size_t(league) * kLeagueResultsStride; }
bool memory_ok(const GameState& g) {
return g.memory.has(kCalendar + kCalendarDays * 2 - 1) &&
+4 -1
View File
@@ -29,6 +29,7 @@
#include <string>
#include <vector>
#include "game/records.hpp"
#include "game/world_layout.hpp"
namespace bmh {
@@ -81,7 +82,9 @@ std::vector<Fixture> league_fixtures(int league, int matchday);
std::vector<Fixture> generate_fixtures(int teams, int matchday, int rounds, int first_team);
constexpr uint8_t kNotPlayed = 0xCC;
// (one league's part of the block is kLeagueResultsStride bytes, records.hpp)
constexpr size_t kResultsSize = 0xD5C;
static_assert(kResultsSize == size_t(kLeagueCount) * kLeagueResultsStride, "the results block holds every league");
struct Result {
bool played = false;
@@ -97,7 +100,7 @@ inline Result decode_result(uint8_t v) {
// Index into the results block for a league match.
inline size_t result_index(int league, int matchday, int match) {
return size_t(league) * 0x17C + size_t(matchday - 1) * 10 + size_t(match);
return size_t(league) * kLeagueResultsStride + size_t(matchday - 1) * 10 + size_t(match);
}
} // namespace bmh
+1 -1
View File
@@ -111,7 +111,7 @@ LeagueTable compute_league_table(const GameState& g, int league, int from, int t
std::vector<Fixture> fx = generate_fixtures(league_table_teams(league), r + 1, matchdays / 2, first_team);
bool counted = false;
for (size_t i = 0; i < fx.size(); i++) {
uint8_t b = g.results.at(size_t(league) * 0x17C + size_t(r) * 10 + i);
uint8_t b = g.results.at(size_t(league) * kLeagueResultsStride + size_t(r) * 10 + i);
int club[2] = {fx[i].home - first_team, fx[i].away - first_team};
if ((b & 0xCC) == 0xCC) {
if (b == 0xCD)
+1 -1
View File
@@ -202,7 +202,7 @@ void finish_event(GameState& g, std::vector<MatchGroup>& groups, uint16_t calend
if (id < 0x15) {
if (league_screen_shown(buttons, 1, 90, int(id))) stir_random(game, rand);
const int round = g.league_rounds.at(id);
for (int m = 0; m < grp.matches(); m++) g.results.at(size_t(id) * 0x17C + size_t(round) * 10 + size_t(m)) = grp.results.at(size_t(m));
for (int m = 0; m < grp.matches(); m++) g.results.at(size_t(id) * kLeagueResultsStride + size_t(round) * 10 + size_t(m)) = grp.results.at(size_t(m));
} else {
store_cup_results(g, grp);
}