Read the referee pool from the world (M5, data format F9)

Referees are staff rows with role referee. Imported ones keep their
original property byte; added ones (attributes strictness and the new
perception, 0-3 each) follow the 49 originals in table order, up to 255.
The matchday draw uses the pool size; a second match per day remains the
fallback when the pool runs out. The season sim gains
MODERN_EXTRA_REFEREES=N for testing before data revision 1.4 exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-23 23:28:43 +02:00
1 parent 28b59d9890
commit 57d75ab2f5
8 files changed
+100 -12

No files matched your search

+7 -1
View File
@@ -597,7 +597,10 @@ ModernSession::ModernSession(const std::filesystem::path& data, uint32_t watcom_
g_ = modern::startup_state(exe_, db_, read_file(data / "M3.MEN"), read_file(data / "M3.DAT"));
// A Modern world: give the Classic start the dimensions and data of the world (M3).
if (std::getenv("MODERN_DEBUG")) std::fprintf(stderr, "session: classic start built\n");
if (const World* world = current_world()) world_report_ = expand_to_world(g_, *world);
if (const World* world = current_world()) {
world_report_ = expand_to_world(g_, *world);
install_world_referees(db_.raw_referee_properties, *world);
}
if (std::getenv("MODERN_DEBUG")) std::fprintf(stderr, "session: world expanded\n");
if (const auto resource = content::find(data)) {
g_.display_start_year = resource->content->start_year;
@@ -648,6 +651,9 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
// A Modern career: the save names its world; the dimensions come from the world.
auto saved = load_world_career(save_path, *world);
install_world_dimensions(*world);
install_world_referees(db_.raw_referee_properties, *world);
if (saved.state.master_database_metadata.size() != db_.raw_referee_properties.size() * 2)
throw FormatError("the save and its world disagree on the referees");
g_ = std::move(saved.state);
rand_ = saved.random;
game_ = saved.game;
+21
View File
@@ -184,6 +184,27 @@ World read_world(const obw::Documents& documents) {
}
w.players.push_back(std::move(pl));
}
// Referees (data format F9): staff rows with role referee. Imported ones keep their
// Classic index and property byte; added ones follow the Classic ones in table order.
if (documents.contains("world/staff.json"))
for (const J& s : items(documents, "staff")) {
if (text(find(s, "role")) != "referee") continue;
WorldReferee r;
r.id = str(get(s, "id"));
r.name = text(find(s, "name"));
if (const J* a = find(s, "attributes")) {
r.strictness = integer(find(*a, "strictness"), 1);
r.perception = integer(find(*a, "perception"), 1);
}
if (r.strictness < 0 || r.strictness > 3 || r.perception < 0 || r.perception > 3)
fail("referee strictness or perception outside 0-3: " + r.id);
if (const J* legacy = find(s, "x-legacy")) {
r.legacy_index = integer(find(*legacy, "referee_index"), -1);
r.property = integer(find(*legacy, "property"), -1);
if (r.property > 0x7f) fail("referee property outside 0-127: " + r.id);
}
w.referees.push_back(std::move(r));
}
return w;
}
+14
View File
@@ -53,6 +53,19 @@ struct WorldPlayer {
uint32_t w35c = 0, w368 = 0, w364 = 0;
};
// A referee (staff row with role referee). The Classic property byte holds the perception
// (bits 0-1: offside calls, fouls let go) and the strictness (bits 3-4: cards).
struct WorldReferee {
std::string id, name;
int strictness = 1, perception = 1; // 0-3 each
int legacy_index = -1; // Classic referee 0-49, -1 for referees added by the data set
int property = -1; // the original property byte of an imported referee
uint8_t property_byte() const {
return property >= 0 ? uint8_t(property) : uint8_t(strictness << 3 | perception);
}
};
struct World {
std::string id, title, data_revision;
std::vector<std::string> requires_;
@@ -61,6 +74,7 @@ struct World {
std::vector<WorldLeague> leagues; // by league index 0-8
std::vector<WorldClub> clubs;
std::vector<WorldPlayer> players;
std::vector<WorldReferee> referees; // in table order (data format F9)
std::map<std::string, int> nationality; // nation id -> Classic nationality code (0 = Germany)
std::map<std::string, size_t> club_by_id; // club id -> index in clubs
// rule:training-camps with maps and camp details (data format F4); empty = built-in catalogue.
+16
View File
@@ -411,9 +411,25 @@ ExpandReport expand_to_world(ModernState& g, const World& world) {
g.player_last[i] = p->last;
g.player_nation[i] = p->nation;
}
// Referees the data set added (data format F9): their names go to the referee pool and
// their name offsets behind the Classic ones in MasterDatabaseMetadata (u16 per referee).
// install_world_referees adds the matching property bytes to the database.
for (const WorldReferee& r : world.referees) {
if (r.legacy_index >= 0) continue;
const uint16_t at = append_name(g.referee_names, legacy_encoding(r.name));
g.master_database_metadata.push_back(uint8_t(at));
g.master_database_metadata.push_back(uint8_t(at >> 8));
++report.added_referees;
}
if (g.master_database_metadata.size() / 2 > 0xff) fail("more than 255 referees");
return report;
}
void install_world_referees(std::vector<uint8_t>& properties, const World& world) {
for (const WorldReferee& r : world.referees)
if (r.legacy_index < 0) properties.push_back(r.property_byte());
}
} // namespace bmh::modern
namespace bmh::modern {
+6
View File
@@ -21,6 +21,7 @@ namespace bmh::modern {
struct ExpandReport {
int league_clubs = 0, added_clubs = 0, added_players = 0, free_agents = 0;
int fallback_nationalities = 0; // players whose nation has no Classic code
int added_referees = 0; // referees behind the 49 Classic ones (data format F9)
std::vector<std::string> notes; // moved league dates and similar remarks
};
@@ -37,6 +38,11 @@ void install_world_dimensions(const World& world);
// (docs/new_engine/trainingslager.md). Classic data keeps the eight original resorts.
void install_training_camps(ModernState& g, const World& world);
// Adds the property bytes of the referees the world added to the referee properties of the
// Classic database (indexed by referee; the turn driver draws from them). Needed for a new
// career after expand_to_world and for a loaded one; the names live in the game state.
void install_world_referees(std::vector<uint8_t>& properties, const World& world);
// The UTF-8 text of a name in the single-byte encoding of the engine texts (ISO 646-DE;
// letters outside it lose their accents, other characters become '?').
std::string legacy_encoding(const std::string& utf8);
+7 -5
View File
@@ -178,14 +178,16 @@ void match_weather(MatchGroup& grp, int m, const MatchdayContext& ctx, GameRando
// Range(1): a referee not yet chosen today
std::vector<uint8_t>& refs = *ctx.referees;
// OpenBMH deviates from the original: in Modern worlds a referee may take a second match on a day with more matches than referees.
// Modern: a day can have more matches than the 49 referees (larger international
// leagues on the dates of the German leagues). Once every referee has a match, one
// may referee a second match that day (DIFFERENCES.md); Classic draws until a free one.
// Modern: a day can have more matches than referees (larger international leagues on
// the dates of the German leagues). Once every referee has a match, one may referee a
// second match that day (DIFFERENCES.md); Classic draws until a free one.
// The pool is the world's (data format F9): referees 1..size-1, 49 with Classic data.
const int last = int(refs.size()) - 1;
bool free_referee = false;
for (int k = 1; k <= 0x31 && !free_referee; ++k) free_referee = !(refs.at(size_t(k)) & 0x80);
for (int k = 1; k <= last && !free_referee; ++k) free_referee = !(refs.at(size_t(k)) & 0x80);
int r;
do {
r = game.range(1, 0x31);
r = game.range(1, last);
} while (free_referee && (refs.at(size_t(r)) & 0x80));
refs.at(size_t(r)) |= 0x80;
grp.desc.at(0x10 + size_t(m)) = uint8_t(r);