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:
1 parent
96e88c9579
commit
0f36b507d4
17 files changed
+154
-22
No files matched your search
+2
-2
@@ -319,7 +319,7 @@ bool save_pitch_formation_source(GameState& g, int manager_slot, int runtime_clu
|
||||
}
|
||||
|
||||
static void auto_lineup_impl(GameState& g, int team, int mode, int manager) {
|
||||
if (team >= world_layout().league_teams && team != no_team()) return; // teams without squads
|
||||
if (!fields_players(g, team)) return; // teams without players
|
||||
if (g.lineups_frozen) return; // LineupRuntimeField (the season change)
|
||||
const bool improve_from_reserves = (mode & 0x80) != 0;
|
||||
mode &= 0x7F;
|
||||
@@ -631,7 +631,7 @@ void quicksort_by_key(int16_t* items, uint32_t* keys, int count, bool ascending)
|
||||
}
|
||||
|
||||
bool substitute(GameState& g, int team, int off, int mode, WatcomRandom& rand) {
|
||||
if (!(team < world_layout().league_teams || team == no_team())) return false;
|
||||
if (!fields_players(g, team)) return false;
|
||||
const int manager = g.manager_of(team);
|
||||
int used = g.team_flags.at(team) >> 5 & 7; // substitutions so far
|
||||
if (mode == 10) {
|
||||
|
||||
@@ -87,7 +87,7 @@ MinuteReport MatchEngine::minute(int minute, int last_minute, int stoppage) {
|
||||
// Human teams use the places on their tactics board, also for the player's value.
|
||||
int MatchEngine::pick_player(int team, int mode, int exclude, MinuteReport& report, int preset) {
|
||||
mode &= 0x7F; // 0x80 = reuse the squad of the previous call, same team here
|
||||
if (team >= world_layout().league_teams && team != no_team()) return 0xFFF; // clubs without squad: nobody, no draws
|
||||
if (!fields_players(state, team)) return 0xFFF; // teams without players: nobody, no draws
|
||||
SquadRange range = squad_range(team);
|
||||
if (range.count == 0) return 0xFFF;
|
||||
RatingContext ctx{state.chance_rain, state.chance_temperature};
|
||||
@@ -531,6 +531,7 @@ ForcedMatchEvent MatchEngine::event_impl(MatchGroup& g, int m, int s, int minute
|
||||
// Small-squad teams (id >= 90) only half of the time; teams without squads never. The
|
||||
// national team (0x165, squad nominated on the national team days) only while manager
|
||||
// slot 0 holds it (CupDraw_FormatError_RuntimeField2 == 0x165: a Bundestrainer's match).
|
||||
// The squads of the other national teams (Modern) get no cards or injuries either.
|
||||
if (!(team < 90 || rand.range(0, 1) == 0)) return result;
|
||||
if (!(team < world_layout().league_teams || team == no_team())) return result;
|
||||
if (team == no_team() && (state.manager_teams.empty() || state.manager_teams[0] != no_team())) return result;
|
||||
@@ -953,7 +954,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
}
|
||||
|
||||
// Goalkeeper of the opponent: the player in squad slot 0 if the formation puts it in goal.
|
||||
if (!reality_played && (opp_team < world_layout().first_foreign_cup() || opp_team == no_team())) {
|
||||
if (!reality_played && (opp_team < world_layout().first_foreign_cup() || fields_players(state, opp_team))) {
|
||||
int x = 0, y = 0;
|
||||
state.formation_position(opp_team, 0, x, y);
|
||||
if (x == 0 && y == 4) keeper = state.squad_slots.at(squad_range(opp_team).first) & 0x0FFF;
|
||||
@@ -988,7 +989,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
deflected = game.range(0, 5) == 0;
|
||||
}
|
||||
if (kind == 0) {
|
||||
if (team >= world_layout().first_foreign_cup() && team != no_team()) {
|
||||
if (team >= world_layout().first_foreign_cup() && !fields_players(state, team)) {
|
||||
// clubs without squad: the attack rating (TeamRating, profile 3), drawn
|
||||
RatingContext drawn;
|
||||
drawn.rand = &rand;
|
||||
@@ -998,7 +999,7 @@ void MatchEngine::side(MatchGroup& g, int m, int& s, int minute, int& own_att, i
|
||||
}
|
||||
}
|
||||
if (keeper == 0xFFF) {
|
||||
if (opp_team >= world_layout().first_foreign_cup() && opp_team != no_team()) {
|
||||
if (opp_team >= world_layout().first_foreign_cup() && !fields_players(state, opp_team)) {
|
||||
// clubs without squad: the goalkeeping rating (profile 0), drawn
|
||||
RatingContext drawn;
|
||||
drawn.rand = &rand;
|
||||
@@ -1205,7 +1206,7 @@ void MatchEngine::penalty_shootout(MatchGroup& g, int m, MinuteReport& report) {
|
||||
const int side = order[k];
|
||||
const int team = pair[side];
|
||||
int player = 0xFFF;
|
||||
if (team < world_layout().league_teams || team == no_team()) {
|
||||
if (fields_players(state, team)) {
|
||||
// a player who has not taken a penalty yet (after 100 tries the list restarts)
|
||||
int tries = 0;
|
||||
bool fresh;
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ int human_correction(GameState& g, RatingContext& ctx, int manager, int rank, in
|
||||
} // namespace
|
||||
|
||||
int team_rating(GameState& g, int team, const RatingProfile& profile, RatingContext& ctx, int* keeper) {
|
||||
if (team >= world_layout().first_foreign_cup() && team != no_team()) {
|
||||
if (team >= world_layout().first_foreign_cup() && !fields_players(g, team)) {
|
||||
// Clubs without squad: per group a random value around the level of the club
|
||||
// (ForeignClubStrength bits 5-7 -> RatingRuntimeField2), +2 if the group's strength bit is set
|
||||
// (bit 3, 3, 2, 1 for goal, defence, midfield, attack: RatingRuntimeField3) and a style
|
||||
|
||||
+10
-1
@@ -157,11 +157,20 @@ SquadRange squad_range(int team) {
|
||||
const WorldLayout& w = world_layout();
|
||||
if (team == w.no_team()) return {w.pool_end, w.no_team_slots};
|
||||
if (team >= 0 && team < w.league_teams) return {w.squad_start[size_t(team)], w.squad_size[size_t(team)]};
|
||||
if (w.national_squad(team)) return {w.national_start + uint32_t(team - w.no_team() - 1) * w.national_slots, w.national_slots};
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
bool fields_players(const GameState& g, int team) {
|
||||
const WorldLayout& w = world_layout();
|
||||
if ((team >= 0 && team < w.league_teams) || team == w.no_team()) return true;
|
||||
if (!w.national_squad(team)) return false;
|
||||
const SquadRange r = squad_range(team);
|
||||
return r.first < g.squad_slots.size() && (g.squad_slots[r.first] & 0x0FFF) != 0x0FFF;
|
||||
}
|
||||
|
||||
TeamAverage team_average(const GameState& g, int team, uint16_t flags, WatcomRandom* rand) {
|
||||
if (team >= world_layout().first_foreign_cup() && team != no_team()) {
|
||||
if (team >= world_layout().first_foreign_cup() && !fields_players(g, team)) {
|
||||
// TeamRating(team, profile 2 at layout field): a random value around the club's level
|
||||
if (!rand) throw std::invalid_argument("team_average: a team without squad needs the Watcom generator");
|
||||
RatingContext ctx;
|
||||
|
||||
@@ -255,6 +255,10 @@ struct SquadRange {
|
||||
size_t count = 0;
|
||||
};
|
||||
SquadRange squad_range(int team);
|
||||
// Whether the team plays with its players (squad, line-up, scorers) rather than with a drawn rating:
|
||||
// the league clubs and no_team always; in Modern a national team once players are nominated into
|
||||
// its squad (its first slot is taken). Classic: exactly the league clubs and no_team.
|
||||
bool fields_players(const GameState& g, int team);
|
||||
|
||||
// Selection and value flags of team_average (the "param_2" of QuoteNationalFriendlyMatch).
|
||||
namespace avg {
|
||||
|
||||
@@ -37,6 +37,9 @@ int WorldLayout::team_of_slot(int slot) const {
|
||||
return int(it - squad_start.begin()) - 1;
|
||||
}
|
||||
if (uint32_t(slot) >= pool_end && uint32_t(slot) < pool_end + no_team_slots) return no_team();
|
||||
if (national_slots != 0 && uint32_t(slot) >= national_start &&
|
||||
uint32_t(slot) < national_start + uint32_t(national_teams - 1) * national_slots)
|
||||
return no_team() + 1 + int((uint32_t(slot) - national_start) / national_slots);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -60,6 +63,10 @@ void set_world_layout(WorldLayout layout) {
|
||||
layout.foreign_offers != layout.free_agents + 80 || layout.pool_end != layout.foreign_offers + 20 ||
|
||||
layout.total_slots < layout.pool_end + layout.no_team_slots)
|
||||
throw std::invalid_argument("world layout: pools must follow the squads");
|
||||
if (layout.national_slots != 0 &&
|
||||
(layout.national_start < layout.pool_end + layout.no_team_slots || layout.national_teams < 1 ||
|
||||
layout.total_slots < layout.national_start + uint32_t(layout.national_teams - 1) * layout.national_slots))
|
||||
throw std::invalid_argument("world layout: national squads must follow the no-club squad");
|
||||
// Squad slot values hold 12-bit player ids; loans store 10-bit club ids.
|
||||
if (layout.total_teams() > 1023) throw std::invalid_argument("world layout: too many teams");
|
||||
current() = std::move(layout);
|
||||
|
||||
@@ -38,14 +38,22 @@ struct WorldLayout {
|
||||
uint32_t pool_end = 0xC00; // end of the pools = first slot of no_team
|
||||
uint32_t no_team_slots = 24; // the national team / no-club squad
|
||||
uint32_t total_slots = 3150; // including the reserve behind no_team
|
||||
// Modern: squads of the national teams after no_team (national_slots each, from slot
|
||||
// national_start: team no_team() + n at national_start + (n - 1) * national_slots). Classic: none,
|
||||
// the national teams play without players.
|
||||
uint32_t national_start = 0, national_slots = 0;
|
||||
|
||||
int first_amateur() const { return league_teams; }
|
||||
int first_foreign_cup() const { return league_teams + amateur_teams; }
|
||||
int no_team() const { return first_foreign_cup() + foreign_cup_teams; }
|
||||
int total_teams() const { return no_team() + national_teams; }
|
||||
bool has_squad(int team) const { return (team >= 0 && team < league_teams) || team == no_team(); }
|
||||
// The team whose squad holds `slot`: a league club, no_team() for the no-club squad, -1 for
|
||||
// the pools and the reserve.
|
||||
// A national team other than no_team with squad slots of its own (Modern).
|
||||
bool national_squad(int team) const { return national_slots != 0 && team > no_team() && team < total_teams(); }
|
||||
bool has_squad(int team) const {
|
||||
return (team >= 0 && team < league_teams) || team == no_team() || national_squad(team);
|
||||
}
|
||||
// The team whose squad holds `slot`: a league club, no_team() for the no-club squad, a
|
||||
// national team for its squad, -1 for the pools and the reserve.
|
||||
int team_of_slot(int slot) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user