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:
1 parent
31ff36fb09
commit
81046f89f2
10 files changed
+40
-17
No files matched your search
@@ -32,6 +32,23 @@ The current game model combines interpreted vectors with fixed-layout compatibil
|
||||
|
||||
Legacy saves serialize blocks in a fixed order and store name pools separately. Runtime UI owners, pending input and frontend capabilities are not additional save fields. See [FBM](formats/FBM.md), [state records](formats/STATE.md) and [RNG](RNG.md).
|
||||
|
||||
## World layout
|
||||
|
||||
The dimensions of the game world are described in one place, `src/game/world_layout.hpp`, instead of as numbers spread over the engine:
|
||||
|
||||
- `WorldLayout` holds the team id ranges (league clubs, amateur clubs, foreign cup clubs without squads, the pseudo team "no club", national teams) and the squad slot table with the player pools behind it.
|
||||
- `LeagueSystem` holds the league structure of the loaded game: league sizes, calendar groups, promotion ladder, European places and the cup structure. The session installs it from the tables of the game version, so the same engine runs the German and the English data.
|
||||
- `src/game/records.hpp` names the sizes of the fixed records (manager record, tactics board, club record).
|
||||
|
||||
OpenBMH Classic only ever uses `classic_world_layout()`, which returns the numbers of the original; a test compares them and the squad table with the former literals. Code asks `world_layout()` and `league_system()` rather than writing 138 or 168.
|
||||
|
||||
This is a parameterisation, not yet a larger world. Still fixed, and to be lifted for an edition with more leagues:
|
||||
|
||||
- the number of leagues (`kLeagueCount`) and of calendar groups (eight competition bits),
|
||||
- the results block (one fixed stride per league, `kLeagueResultsStride`) and the other save blocks sized for the Classic world; the save format is unchanged and a larger world needs a format of its own,
|
||||
- the id of "no club" as a compile-time constant (`kNoTeam`), five manager records, and some stack tables sized for the Classic club count,
|
||||
- the per-club tables of the loaded state, whose sizes are checked against the Classic numbers.
|
||||
|
||||
## Public interfaces and validation
|
||||
|
||||
The [console reference](CLI_CONCEPT/README.md) documents window commands. [protocol.md](protocol.md) describes structured requests, and [CONSOLE_CLIENTS.md](CONSOLE_CLIENTS.md) explains safe client ownership and batching. Prefer shared projections/actions when adding another frontend.
|
||||
|
||||
@@ -157,7 +157,7 @@ void initialize_saved_match_group(MatchGroup& group, const GameState& state, siz
|
||||
group.fixtures.push_back(fixture.home);
|
||||
group.fixtures.push_back(fixture.away);
|
||||
}
|
||||
const size_t result_at = size_t(league) * 0x17c + size_t(round) * 10;
|
||||
const size_t result_at = size_t(league) * kLeagueResultsStride + size_t(round) * 10;
|
||||
if (result_at + fixtures.size() > state.results.size())
|
||||
throw std::runtime_error("saved turn cursor: league result block is incomplete");
|
||||
group.results.assign(state.results.begin() + long(result_at),
|
||||
@@ -365,7 +365,7 @@ void initialize_saved_replay_group(MatchGroup& group, GameState& state, size_t i
|
||||
league_first_team(league));
|
||||
if (match >= int(fixtures.size()))
|
||||
throw std::runtime_error("saved replay record has no corresponding fixture");
|
||||
const size_t result = size_t(league) * 0x17c + size_t(round) * 10 + size_t(match);
|
||||
const size_t result = size_t(league) * kLeagueResultsStride + size_t(round) * 10 + size_t(match);
|
||||
if (result >= state.results.size() || state.results[result] != kPostponedMark)
|
||||
throw std::runtime_error("saved replay record has no postponed result marker");
|
||||
const uint32_t key = (uint32_t(league) << 16) | (uint32_t(round) << 8) | uint32_t(match);
|
||||
@@ -1828,7 +1828,7 @@ std::optional<CareerSession::LiveOverviewProjection> CareerSession::open_phase_r
|
||||
for (const auto& group : turn_driver_.groups) {
|
||||
const uint32_t id = le32(group.desc, 0xcc);
|
||||
if (id < 0x15) {
|
||||
const size_t at = size_t(id)*0x17c + size_t(entered.league_rounds.at(id))*10;
|
||||
const size_t at = size_t(id)*kLeagueResultsStride + size_t(entered.league_rounds.at(id))*10;
|
||||
for (size_t m = 0; m < group.results.size(); ++m)
|
||||
entered.results.at(at+m) = group.results[m];
|
||||
} else store_cup_results(entered, group);
|
||||
@@ -7747,7 +7747,7 @@ std::optional<int> CareerSession::prepared_lineup_opponent(int manager_slot, int
|
||||
raw_result = group.results[size_t(match)];
|
||||
} else if (league >= 0 && league < int(g_.league_rounds.size())) {
|
||||
const int round = int(g_.league_rounds[size_t(league)]);
|
||||
const size_t result_at = size_t(league) * 0x17c + size_t(round) * 10 + size_t(match);
|
||||
const size_t result_at = size_t(league) * kLeagueResultsStride + size_t(round) * 10 + size_t(match);
|
||||
if (round >= 0 && result_at < g_.results.size()) {
|
||||
has_result = true;
|
||||
raw_result = g_.results[result_at];
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
@@ -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) &&
|
||||
|
||||
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
@@ -593,7 +593,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
} else if (type == 0 && league >= 0 &&
|
||||
league < int(g.league_rounds.size())) {
|
||||
const int round = int(g.league_rounds[size_t(league)]);
|
||||
const size_t result_at = size_t(league) * 0x17c +
|
||||
const size_t result_at = size_t(league) * kLeagueResultsStride +
|
||||
size_t(round) * 10 + match;
|
||||
if (round >= 0 && result_at < g.results.size()) {
|
||||
has_result = true;
|
||||
|
||||
Reference in new issue
Block a user