Complete original edition rules, season safety and verified 1.0 releases (by Codex)

This commit is contained in:
Codex committed 2026-10-30 17:14:28 +01:00
1 parent e432f20ae7
commit f0ef79a119
21 files changed
+563 -30

No files matched your search

+2
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "game/career.hpp"
#include "game/lineup.hpp"
#include <algorithm>
@@ -38,6 +39,7 @@ void install_career_rules(const LeImage& exe) {
if (next[league][0] > next[league][1] || next[league][1] > 99)
throw FormatError("career: unsupported original league strength range");
}
install_lineup_rules(exe);
for (int league = 0; league < 9; ++league)
for (int bound = 0; bound < 2; ++bound) kLeagueStrength[league][bound] = next[league][bound];
}
+54 -2
View File
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "game/lineup.hpp"
#include "formats/le.hpp"
#include "game/match.hpp"
#include "game/weekly.hpp"
#include <cstdlib>
#include <stdexcept>
@@ -10,6 +13,7 @@
namespace bmh {
namespace {
bool original_foreign_limit_enabled = false;
// Position type by formation depth x (table at layout field).
constexpr int8_t kTypeByDepth[24] = {0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 0, 1, 2, 2};
@@ -317,6 +321,10 @@ bool save_pitch_formation_source(GameState& g, int manager_slot, int runtime_clu
}
}
void install_lineup_rules(const LeImage& exe) {
original_foreign_limit_enabled = exe.u8(layout::ForeignPlayerLimitEnabled) != 0;
}
static void auto_lineup_impl(GameState& g, int team, int mode, int manager) {
if (team >= 138 && team != kNoTeam) return; // teams without squads
if (g.lineups_frozen) return; // LineupRuntimeField (the season change)
@@ -574,8 +582,52 @@ static void auto_lineup_impl(GameState& g, int team, int mode, int manager) {
break;
}
}
// OpenBMH deviates from the original: disables the foreign-player limit in the supported rule profile.
// (foreign-player limit ForeignPlayerLimitEnabled is off in the supported rule profile)
if (original_foreign_limit_enabled) {
const int country = team_region(team) & 0xff;
const int allowed = 3 - int(country != 0);
std::vector<int> foreign_rows, foreign_roles;
for (int row = 0; row < 11; ++row) {
const int id = g.squad_slots.at(range.first + row) & 0x0fff;
if (id != 0x0fff && nationality(g, id) != country) {
foreign_rows.push_back(row);
foreign_roles.push_back(g.players.at(id).position());
}
}
int tolerance = 0;
for (int attempt = 0; foreign_rows.size() > size_t(allowed) && attempt < 200; ++attempt) {
++tolerance;
if (tolerance > 100) {
// No suitable domestic reserve: retain the original short-lineup
// outcome rather than fielding more foreign players than allowed.
g.squad_slots.at(range.first + foreign_rows.back()) &= 0x1fff;
foreign_rows.pop_back(); foreign_roles.pop_back();
continue;
}
for (int row = 11; row < players && value[row] != kUnavailable; ++row) {
const int id = g.squad_slots.at(range.first + row) & 0x0fff;
if (id == 0x0fff || nationality(g, id) != country) continue;
const int role = g.players.at(id).position();
const int replaced_role = foreign_roles.back();
if ((role == 0 && replaced_role != 0 && tolerance <= 7) ||
std::abs(role - replaced_role) >= tolerance) continue;
const int field = foreign_rows.back();
foreign_rows.pop_back(); foreign_roles.pop_back();
auto& incoming = g.squad_slots.at(range.first + row);
auto& outgoing = g.squad_slots.at(range.first + field);
incoming = uint16_t((incoming & 0x1fff) | 0x8000);
outgoing = uint16_t((outgoing & 0x1fff) | (row < 17 ? 0x4000 : 0));
std::swap(incoming, outgoing);
std::swap(value[row], value[field]);
if (manager >= 0) {
std::swap_ranges(board(row), board(row) + 0x58, board(field));
std::swap(board(row)[0x41], board(field)[0x41]);
std::swap(board(row)[0x42], board(field)[0x42]);
}
tolerance = 0;
if (foreign_rows.size() <= size_t(allowed)) break;
}
}
}
// After a full line-up every player in the eleven or on the bench notes his squad slot
// (relative to the squad start) in bits 0-4 of his card word (*PlayerCards).
if (!first_eleven_only && !g.player_cards.empty())
+7 -3
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// OpenBMH deviates from the original: disables the foreign-player limit and supports owner-bound designated set-piece selection.
// OpenBMH deviates from the original: supports owner-bound designated set-piece selection.
// Automatic line-up of computer teams, port of Int2.
//
// The squad of a team is a run of squad slots (squad_range). The first 11 slots are the
@@ -21,7 +21,7 @@
// The chosen player is swapped into slot p and flagged 0x8000 (slots 0-10) or 0x4000.
//
// Ported: assistant training-camp familiarity penalty and detailed position scoring at
// difficulty >= 6. The foreign-player limit (ForeignPlayerLimitEnabled) is off in supported rule profile.
// difficulty >= 6. The supplied edition controls the original foreign-player limit.
#include <cstdint>
#include <array>
@@ -30,6 +30,10 @@
#include "game/state.hpp"
namespace bmh {
class LeImage;
// Install the supplied edition's original automatic-lineup rule switch.
void install_lineup_rules(const LeImage& exe);
// Games: in-place quicksort (Hoare partition, middle element as pivot) of `keys`
// descending (ascending if `ascending`), comparing as unsigned 32-bit, moving `items`
@@ -93,7 +97,7 @@ bool save_pitch_formation_source(GameState& g, int manager_slot, int runtime_clu
int formation, uint8_t expected_weights,
const std::array<uint8_t, 22>& formation_positions);
// OpenBMH deviates from the original: disables the foreign-player limit and supports owner-bound designated set-piece selection.
// OpenBMH deviates from the original: supports owner-bound designated set-piece selection.
// supported rule profile NormalizePitchSetPieceSource/NormalizePitchSetPieceSource3/NormalizePitchSetPieceSource2/NormalizePitchSetPieceSource4: deterministic, owner-bound
// set-piece presentation state. Stored takers are player_id+1; zero is AUTO.
bool normalize_pitch_set_piece_source(GameState& g, int manager_slot, int runtime_club);
+17
View File
@@ -1167,10 +1167,16 @@ void season_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteRe
uint8_t count = 0xff; // local_20
int8_t owner = -1; // local_24: the club's human manager
size_t board_first = 0; // local_3c
std::vector<bool> processed(g.players.size(), false);
for (int s = 0; s < 0xc00 && !report.unsupported; s++) {
for (;;) {
const int player = g.squad_slots.at(size_t(s)) & 0xFFF;
if (player == 0xFFF) break;
// OpenBMH deviates from the original: age/retire each player
// once, even when a temporary offer row references his club
// slot or regeneration moves him to a later free-agent slot.
if (processed.at(size_t(player))) break;
processed.at(size_t(player)) = true;
const int team = slot_team(s);
if (team != int(last_team)) { // (-1 for the pool never equals 0xFFFF)
count = 0xff;
@@ -1643,6 +1649,16 @@ SeasonTransitionOutcome season_transition(GameState& g, GameRandom& game, Watcom
namespace bmh {
void initialize_european_qualification_seed(GameState& g) {
constexpr uint32_t entry = layout::CupTable + 14 * 0x28;
if (g.memory.u16(entry + 0x22) == 0 && g.memory.u16(entry + 0x24) == 0) {
// OpenBMH deviates from the original: initializes the empty EM qualifier
// seeds with national teams, preventing club zero from entering the EM.
g.memory.set16(entry + 0x22, 357);
g.memory.set16(entry + 0x24, 358);
}
}
bool career_season_setup(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport& report,
const std::function<void(const char*)>& pause,
const SeasonCupDrawHook& cup_draw) {
@@ -1662,6 +1678,7 @@ bool career_season_setup(GameState& g, GameRandom& game, WatcomRandom& rand, Min
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField5, uint16_t(first_small + 0x1f));
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField4, uint16_t(first_small + 0x13));
mem.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField3, uint16_t(foreign + 1));
initialize_european_qualification_seed(g);
mem.set16(::bmh::layout::Career_CompetitionPointersEnglish_ExecutableField28, 0);
mem.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField6, 0);
mem.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField5, 7);
+4
View File
@@ -187,6 +187,10 @@ void cup_group_overview_effects(GameState& g, int group_index);
// LeagueName: the name of a league below 5 (with its letter, e.g. for the third divisions).
std::string league_name(const GameState& g, int league);
// New careers: fill the original uninitialized EM qualification placeholders;
// preserve any nonzero seeds supplied by the installation.
void initialize_european_qualification_seed(GameState& g);
// Season boundary: reset manager boards, age/retire players and clear seasonal
// histories. Kept separate from cup draws, accounts and calendar advancement.
void season_players(GameState& g, GameRandom& game, WatcomRandom& rand, MinuteReport& report);