Modern: national teams play with squads of their nationality (M9)

A Modern layout gives every national team after no_team 24 squad slots.
On each national team day, after the German nomination, the strongest fit
players of each nationality (quotas 3/5/7/5, the German strength measure)
fill its squad and get a computer line-up; a nation without a goalkeeper
or with fewer than 14 nominees keeps its drawn rating. The shared match
core asks fields_players() instead of 'league club or no_team', which is
the same set in Classic. National squads get no cards or injuries, their
players develop after the match like Germany's, and the almanac records
their line-ups.

Diamond data 1.5: 24 of 61 nations play with players. Classic regression
(game 1 and two-player) unchanged, Classic-data season identical, save
round trip identical, ctest passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-25 15:02:50 +01:00
1 parent 96e88c9579
commit 0f36b507d4
17 files changed
+154 -22

No files matched your search

+3
View File
@@ -651,6 +651,9 @@ ModernSession::ModernSession(const std::filesystem::path &data, uint32_t watcom_
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);
// saves from before the national squads end at the reserve: the national squads
// start empty (those teams play with their drawn rating until the next nomination)
if (g_.squad_slots.size() < world_layout().total_slots) g_.squad_slots.resize(world_layout().total_slots, 0x0fff);
rand_ = saved.random;
game_ = saved.game;
native.emplace();
+5 -1
View File
@@ -138,7 +138,11 @@ WorldLayout modern_layout(int league_clubs, int german_clubs) {
w.free_agents = w.transfer_list + 44;
w.foreign_offers = w.free_agents + 80;
w.pool_end = w.foreign_offers + 20;
w.total_slots = w.pool_end + w.no_team_slots + 54;
// behind the no-club squad and its 54 reserve slots: 24 slots for each national team after
// no_team, filled on the international days from the players of its nationality
w.national_start = w.pool_end + w.no_team_slots + 54;
w.national_slots = kSquadSlots;
w.total_slots = w.national_start + uint32_t(w.national_teams - 1) * w.national_slots;
return w;
}
+4 -6
View File
@@ -15,7 +15,6 @@
#include "modern/game/cup.hpp"
#include "modern/game/matchday.hpp"
#include "modern/game/modern_state.hpp"
#include "modern/game/national.hpp"
namespace bmh::modern {
@@ -539,10 +538,9 @@ AlmanacRecorder::AlmanacRecorder(ModernState& g, const std::vector<MatchGroup>&
if (const int ref = group.desc.at(0x10 + size_t(m)); ref > 0) rec.referee = season.referee(referee_name(g, ref));
for (int side = 0; side < 2; ++side) {
const int team = side ? away : home;
// only the league clubs and the German national team (no_team, squad nominated on the
// national team days, used only while a human is the national coach, as in the match engine) have
// squads; the other national and amateur teams play without players
if (team >= league_clubs() && (team != no_team() || !national_coach_active(g))) continue;
// the teams that play with their players (fields_players: the league clubs and the
// national teams with a nominated squad); the others play with a drawn rating
if (!fields_players(g, team)) continue;
const SquadRange range = squad_range(team);
for (size_t s = 0; s < range.count; ++s) {
const uint16_t e = g.squad_slots.at(range.first + s);
@@ -572,7 +570,7 @@ uint16_t AlmanacRecorder::player_ref(int player) {
// sent off or injured loses it; a substitute takes the slot of the player he replaces).
std::vector<uint16_t> AlmanacRecorder::on_pitch(int team) const {
std::vector<uint16_t> out;
if (team < 0 || (team >= league_clubs() && (team != no_team() || !national_coach_active(g_)))) return out;
if (team < 0 || !fields_players(g_, team)) return out;
const SquadRange range = squad_range(team);
for (size_t s = 0; s < std::min<size_t>(11, range.count); ++s) {
const uint16_t e = g_.squad_slots.at(range.first + s);
+3 -1
View File
@@ -406,7 +406,9 @@ void develop_players(ModernState& g, const MatchGroup& grp, int m, GameRandom& g
const int type = grp.desc.at(0);
for (int side = 0; side < 2; side++) {
const int team = grp.fixtures.at(m * 2 + side);
if (!(team < first_foreign_cup() || team == no_team())) continue;
// the clubs and every national team that plays with its players (Germany always, the
// other nations of a Modern world once nominated)
if (!(team < first_foreign_cup() || fields_players(g, team))) continue;
const uint8_t cls = (type == 0xb && team == no_team()) ? 3 : uint8_t(competition_class(type));
const int manager = g.manager_of(team);
const SquadRange range = squad_range(team);
+52
View File
@@ -4,7 +4,9 @@
#include "modern/game/national.hpp"
#include <algorithm>
#include <array>
#include <cstring>
#include <vector>
#include "game/lineup.hpp"
#include "game/match_engine.hpp"
@@ -21,6 +23,7 @@ constexpr size_t kBoardSlot = 0x58;
constexpr uint32_t kDesktops = ::bmh::layout::Desktops; // desktop layouts, 0x360 per manager slot
constexpr size_t kDesktop = 0x360;
constexpr uint8_t kNominated[4] = {3, 5, 7, 5}; // NationalRuntimeField: keepers, defence, midfield, attack
constexpr int kMinNationalSquad = 14; // Modern: fewer nominees keep a national team on its drawn rating
// the manager's team (record +0x290) as the port caches it
void refresh_manager_teams(ModernState& g) {
@@ -96,6 +99,54 @@ void new_board_entry(ModernState& g, int manager, int index, int slot, WatcomRan
std::memset(e + 0x12, 0, 7);
}
void nominate_national_squads(ModernState& g) {
const WorldLayout& w = world_layout();
if (w.national_slots == 0) return;
// the strongest fit players of each nationality per position, the quotas and the strength of
// the German nomination (without its bonus for clubs abroad: every nation plays abroad)
const int nations = w.national_teams;
struct Picks {
int16_t best[4][7] = {}, slot[4][7] = {}; // ascending per position, as for Germany
int found[4] = {}; // nominees per position (up to the quota)
};
std::vector<Picks> picks(static_cast<size_t>(nations));
for (size_t s = 0; s < transfer_list_slot(); s++) {
const int id = g.squad_slots.at(s) & 0xfff;
if (id == 0xfff) continue;
const int n = modern::nationality(g, id);
if (n < 1 || n >= nations) continue; // 0: Germany, nominated above
const Player& p = g.players.at(size_t(id));
const bool fit = (p.w35c >> 27) == 0 || ((p.w364 >> 16) & 0x1f) == 0;
if (!fit) continue;
const int pos = int(p.w364 & 3);
int16_t strength = int16_t(p.strength(false));
if (pos > 1) strength = int16_t(strength + ((p.w364 >> 2) & 0x3f) + (((p.w368 >> 18) & 0x3f) >> 1));
Picks& pick = picks[size_t(n)];
int16_t* row = pick.best[pos];
int16_t* at = pick.slot[pos];
int i = 0;
while (i < kNominated[pos] && strength > row[i]) i++;
if (i == 0) continue;
for (int k = 0; k < i - 1; k++) row[k] = row[k + 1], at[k] = at[k + 1];
row[i - 1] = strength;
at[i - 1] = int16_t(s);
pick.found[pos] = std::min<int>(pick.found[pos] + 1, kNominated[pos]);
}
for (int n = 1; n < nations; n++) {
const int team = no_team() + n;
const SquadRange range = squad_range(team);
for (size_t s = range.first; s < range.first + range.count; s++) g.squad_slots.at(s) = kEmptySlot;
// A nation needs a goalkeeper and 14 players; with fewer it keeps its drawn rating.
const int* f = picks[size_t(n)].found;
if (f[0] == 0 || f[0] + f[1] + f[2] + f[3] < kMinNationalSquad) continue;
size_t next = range.first;
for (int pos = 0; pos < 4; pos++)
for (int k = kNominated[pos] - f[pos]; k < kNominated[pos]; k++) // the found ones fill the top
g.squad_slots.at(next++) = uint16_t(g.squad_slots.at(size_t(picks[size_t(n)].slot[pos][k])) & 0x0fff);
auto_lineup(g, team, 100);
}
}
bool national_team_day(ModernState& g, WatcomRandom& rand, MinuteReport& report) {
StaticMemory& mem = g.memory;
const SquadRange national = squad_range(no_team());
@@ -146,6 +197,7 @@ bool national_team_day(ModernState& g, WatcomRandom& rand, MinuteReport& report)
} catch (const std::exception& ex) {
report.fail(std::string("national team line-up: ") + ex.what());
}
nominate_national_squads(g); // Modern: the other nations' squads (none in a Classic layout)
if (coach == 0) modern::swap_manager_slots(g, 4, 0);
g.manager_options.at(0) = option;
return coach != 0; // (with a Bundestrainer his desk follows: AdvanceTurn's local_28 = 4)
+7
View File
@@ -39,6 +39,13 @@ void new_board_entry(ModernState& g, int manager, int index, int slot, WatcomRan
// the national team (CoachActive) - then his desk follows (AdvanceTurn: local_28 = 4).
bool national_team_day(ModernState& g, WatcomRandom& rand, MinuteReport& report);
// Modern (a layout with national squads): on every national team day after the German
// nomination, each other national team (no_team() + nationality) gets the strongest fit players
// of its nationality from the league clubs (quotas 3/5/7/5, the German strength measure) and a
// computer line-up. A nation without a goalkeeper or with fewer than 14 nominees stays empty and
// plays with its drawn rating as in Classic. No generator is drawn.
void nominate_national_squads(ModernState& g);
// The Bundestrainer (national coach), see national.cpp. SwapManagerSlots2: notes the number of
// managers (OriginalManagerCount) and `active_manager` (ClubPlayerDetail_InvalidArgument_RuntimeField3 = ActiveManager); a manager
// flagged in his record (+0x21c), every manager in the world game without leagues