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

+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);