Load Modern worlds and add Modern training camps (M3, M4)
M3 - Modern world loader: - modern/content/world: typed view of the world tables (leagues, clubs, players, nations, league dates, training camp catalogue). - modern/content/world_package: opens a Modern world (runtime:modern-v1, or editor:world-v1 until data revision 1.4), reads only the engine entries and decodes the Classic payload (import: load_classic_payload). - modern/content/world_expand: turns the Classic start into the world: club ids in the order of the world's leagues, per-club tables remapped (added clubs copy an original club of their league), added players from their attributes, 24 squad slots per league club, pools kept, layout, league sizes and league dates installed; UTF-8 names and OBW ids in ModernState. - Fixes found by playing the Modern data set: referee pool exhausted on days with German and larger international leagues (Modern deviation), card table per league club grown, slot-to-team lookup via WorldLayout, form history stride from the layout, remaining slot literals. - Classic UI projections used by the session read the layout instead of executable constants (Classic values unchanged). - modern_season_sim opens .obw worlds; MODERN_DEBUG / MODERN_WATCH tracing. M4 - training camps: - Catalogue in ModernState (built-in 18 fictional camps on three maps, or the world's extended catalogue); price, booking and effect use it. - Six-star grades: step index capped, limit +1 from pitch 5 and +1 with pitch and fitness 6, catering 6 one more point of condition, lodging 6 one week less injury. Classic data behaves as before. modern_camp_tests. Verified: 190 tests pass; Classic replay regression identical to the M0 baseline; season_sim and modern_season_sim identical with Classic data; the Modern data set plays full seasons (leagues 34/38/34 rounds). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13bdc56f04
commit
6f55622307
53 files changed
+1392
-87
No files matched your search
@@ -196,7 +196,7 @@ bool new_career_players(ModernState& g, GameRandom& game, WatcomRandom& rand, Mi
|
||||
p.w364 |= uint32_t(rand.range(4, 0x10)) << 21;
|
||||
p.w368 = (p.w368 & 0xffffc000u) + uint32_t(rand.range(0, 0x3fff));
|
||||
}
|
||||
for (int slot = 3096; slot < 3096 + 0x36; slot++)
|
||||
for (int slot = int(pool_end_slot() + 24); slot < int(pool_end_slot() + 24) + 0x36; slot++)
|
||||
if (!modern::release_player(g, slot, game, rand, report)) return false;
|
||||
return !report.unsupported;
|
||||
}
|
||||
@@ -412,7 +412,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
|
||||
choice.portrait < 0 || choice.portrait > 11 || choice.name.size() > 24 ||
|
||||
g.tactics.size() < size_t(m + 1) * 0x840 ||
|
||||
g.manager_ratings.size() < size_t(m + 1) * 0x3c ||
|
||||
g.manager_results.size() < g.manager_teams.size() * 0x690 ||
|
||||
g.manager_results.size() < g.manager_teams.size() * manager_history_stride() ||
|
||||
g.squad_slots.size() < total_squad_slots() || g.club_ids.size() < size_t(first_foreign_cup()) ||
|
||||
g.team_morale.size() < size_t(first_foreign_cup()) || g.team_flags.size() < size_t(first_foreign_cup()) ||
|
||||
g.club_heap_bc.size() < size_t(first_foreign_cup()) * 2 || g.club_heap_78.size() < size_t(first_foreign_cup()) * 2 ||
|
||||
@@ -530,7 +530,7 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
|
||||
modern::new_board_entry(g, m, int(i), int(slot), rand);
|
||||
g.tactics.at(size_t(m) * 0x840 + i * 0x58 + 0xd) = 100;
|
||||
}
|
||||
for (size_t i = 0; i < 0x690; i++) g.manager_results.at(size_t(m) * 0x690 + i) = 0xff;
|
||||
for (size_t i = 0; i < manager_history_stride(); i++) g.manager_results.at(size_t(m) * manager_history_stride() + i) = 0xff;
|
||||
const uint8_t level = mem.u8(::bmh::layout::Difficulty);
|
||||
const uint32_t money = level == 0 ? 50000000u : 4000000u - level * 200000u;
|
||||
put32(r, rec + 0x314, money);
|
||||
|
||||
@@ -32,10 +32,7 @@ int source_manager(const ModernState& g, int club) {
|
||||
|
||||
int club_of_slot(int slot) {
|
||||
if (slot < 0) return -1;
|
||||
if (slot < 90 * 24) return slot / 24;
|
||||
if (slot < 90 * 24 + 48 * 16) return (slot - 90 * 8) / 16;
|
||||
if (slot >= pool_end_slot() && slot < pool_end_slot() + 24) return no_team();
|
||||
return -1;
|
||||
return world_layout().team_of_slot(slot); // squads, no-club squad, else -1
|
||||
}
|
||||
|
||||
std::array<uint8_t, kBoardRow> board_copy(const ModernState& g, int manager, int row) {
|
||||
|
||||
@@ -507,13 +507,23 @@ void configure_training_camp_data(ModernState& g, const LeImage& exe) {
|
||||
}
|
||||
g.training_camp_base_prices = prices;
|
||||
g.training_camp_quality = quality;
|
||||
// The Modern catalogue starts as the eight original resorts; a Modern world replaces it.
|
||||
g.camp_maps.clear();
|
||||
g.training_camps.clear();
|
||||
for (size_t resort = 0; resort < prices.size(); ++resort) {
|
||||
TrainingCamp camp;
|
||||
camp.id = "resort:" + std::to_string(resort);
|
||||
camp.base_price = prices[resort];
|
||||
camp.quality = quality[resort];
|
||||
g.training_camps.push_back(std::move(camp));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t training_camp_price(const ModernState& g, int manager, int resort) {
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || resort < 0 || resort >= kTrainingCampResorts)
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || resort < 0 || size_t(resort) >= g.training_camps.size())
|
||||
throw FormatError("training camp: invalid manager or resort");
|
||||
const int team = int8_t(g.manager_records.at(size_t(manager) * kRecordSize + kTeam));
|
||||
return g.training_camp_base_prices[size_t(resort)] + team_average(g, team, 0xff).players * 5000;
|
||||
return g.training_camps[size_t(resort)].base_price + team_average(g, team, 0xff).players * 5000;
|
||||
}
|
||||
|
||||
bool set_training_camp_focus(ModernState& g, int manager, const std::array<uint8_t, 4>& focus) {
|
||||
@@ -1450,7 +1460,7 @@ TrainingCampBookingBlock training_camp_booking_block(const ModernState& g, int m
|
||||
}
|
||||
|
||||
bool book_training_camp(ModernState& g, int manager, int resort, WatcomRandom& rand) {
|
||||
if (resort < 0 || resort >= kTrainingCampResorts ||
|
||||
if (resort < 0 || size_t(resort) >= g.training_camps.size() ||
|
||||
modern::training_camp_booking_block(g, manager) != TrainingCampBookingBlock::none) return false;
|
||||
const int32_t cost = modern::training_camp_price(g, manager, resort);
|
||||
if (!modern::book_money(g, manager, cost, false)) return false;
|
||||
@@ -1465,7 +1475,7 @@ bool book_training_camp(ModernState& g, int manager, int resort, WatcomRandom& r
|
||||
void training_camp_effect(ModernState& g, int manager, int resort, WatcomRandom& rand) {
|
||||
const size_t rec = size_t(manager) * kRecordSize;
|
||||
const int team = int8_t(g.manager_records.at(rec + kTeam));
|
||||
const auto& grade = g.training_camp_quality[size_t(resort)];
|
||||
const auto& grade = g.training_camps.at(size_t(resort)).quality;
|
||||
|
||||
// Morale (bits 0-5) + 12 * grade * 20 %, clamped to 0..0x2f (ClampSignedWord with a word
|
||||
// sum of the sign extended byte); the flag bits 6-7 are kept.
|
||||
@@ -1496,15 +1506,26 @@ void training_camp_effect(ModernState& g, int manager, int resort, WatcomRandom&
|
||||
for (int i = 0; i < 5; i++) {
|
||||
const int lo = delta[i] < 0 ? 0 : 8;
|
||||
if (rand.range(0, 100) <= chance) {
|
||||
// values below 83..87 (88 in the better resorts 6 and 7) can still improve
|
||||
const int limit = rand.range(0x53, 0x57) + (resort >= 6 ? 1 : 0);
|
||||
// OpenBMH deviates from the original: Modern training camps have grades up to six stars with a capped step, a higher limit and recovery extras.
|
||||
// values below 83..87 can still improve. Classic raises the limit by 1 in its two best
|
||||
// resorts (6 and 7, the only ones with pitch grade 5); Modern ties it to the grades:
|
||||
// pitch 5 or more +1, pitch and fitness both 6 one more (docs/new_engine/trainingslager.md).
|
||||
const int limit = rand.range(0x53, 0x57) + (grade[0] >= 5 ? 1 : 0) + (grade[0] >= 6 && grade[1] >= 6 ? 1 : 0);
|
||||
if (v[i] < limit) {
|
||||
const int k = rand.range(lo, delta[i] + 8);
|
||||
// Grade 6 can draw beyond the step table; its top step (+5) is the maximum.
|
||||
const int k = std::min(rand.range(lo, delta[i] + 8), 23);
|
||||
v[i] = int8_t(v[i] + int8_t(kStep[k] * kDirection[i]));
|
||||
}
|
||||
}
|
||||
v[i] = std::clamp<int8_t>(v[i], 0, 0x63); // Int8T
|
||||
}
|
||||
// Six-star extras (Modern): catering 6 adds up to one point of condition, lodging 6 shortens
|
||||
// a running injury (w364 bits 16-20, weeks) by one week, never below one.
|
||||
if (grade[2] >= 6) v[0] = std::min<int8_t>(int8_t(v[0] + 1), 0x63);
|
||||
if (grade[3] >= 6) {
|
||||
const uint32_t weeks = p.w364 >> 16 & 0x1f;
|
||||
if (weeks > 1) p.w364 = (p.w364 & ~(0x1fu << 16)) | (weeks - 1) << 16;
|
||||
}
|
||||
p.w35c = (p.w35c & 0xffe00000u) | uint32_t(v[0]) << 14 | uint32_t(v[1]) << 7 | uint32_t(v[2]);
|
||||
board[0xf] = uint8_t(v[3]);
|
||||
board[0xe] = uint8_t((board[0xe] & 0xc0) | std::min<uint8_t>(uint8_t(v[4]), 0x3f));
|
||||
|
||||
@@ -670,7 +670,7 @@ void manager_match_record(ModernState& g, const MatchGroup& grp, int m, int home
|
||||
modern::rate_manager(g, int(k), rating, 0);
|
||||
}
|
||||
if (opp < first_foreign_cup()) {
|
||||
size_t at = k * 0x690 + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
size_t at = k * manager_history_stride() + size_t(opp) * 10 + (side == 1 ? 5 : 0);
|
||||
std::copy_backward(g.manager_results.begin() + at, g.manager_results.begin() + at + 4,
|
||||
g.manager_results.begin() + at + 5);
|
||||
g.manager_results.at(at) = uint8_t(own + (against << 4));
|
||||
|
||||
@@ -177,10 +177,16 @@ void match_weather(MatchGroup& grp, int m, const MatchdayContext& ctx, GameRando
|
||||
if (int16_t(home) < no_team() && uint16_t(away) < no_team() && !(grp.desc.at(1) & 0x80)) {
|
||||
// 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.
|
||||
bool free_referee = false;
|
||||
for (int k = 1; k <= 0x31 && !free_referee; ++k) free_referee = !(refs.at(size_t(k)) & 0x80);
|
||||
int r;
|
||||
do {
|
||||
r = game.range(1, 0x31);
|
||||
} while (refs.at(size_t(r)) & 0x80);
|
||||
} 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);
|
||||
}
|
||||
@@ -601,8 +607,11 @@ std::vector<MatchGroup> setup_matchday(ModernState& g, uint32_t competitions, co
|
||||
for (int i = 0; i < grp.matches() * 2; i++) {
|
||||
if (i < grp.matches()) modern::match_weather(grp, i, ctx, game, rand);
|
||||
const int team = grp.fixtures.at(size_t(i));
|
||||
turn_team = team;
|
||||
turn_step = "setup: prepare team";
|
||||
modern::prepare_team(g, team, cls, i);
|
||||
try {
|
||||
turn_step = "setup: line-up";
|
||||
auto_lineup(g, team, 100);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
report.fail(e.what());
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
// Modern-only data (world layout, UTF-8 names, ...) is added here, never to GameState.
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "game/state.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "modern/game/training_camps.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
@@ -31,7 +34,21 @@ inline size_t total_squad_slots() { return world_layout().total_slots; }
|
||||
// The callbacks the shared match core uses for season functions (SeasonHooks).
|
||||
const SeasonHooks& season_hooks();
|
||||
|
||||
// The form history per manager (manager_results) holds 10 bytes per club with a record
|
||||
// (Classic: 168 clubs, stride 0x690).
|
||||
inline size_t manager_history_stride() { return size_t(first_foreign_cup()) * 10; }
|
||||
|
||||
struct ModernState : GameState {
|
||||
// --- Modern world (docs/new_engine, M3); empty when the game runs on Classic data -------
|
||||
// UTF-8 names and OBW identities by runtime index. The single-byte name pools of
|
||||
// GameState stay for the engine texts; interfaces show these.
|
||||
std::vector<std::string> world_club_id, world_club_name, world_club_short; // per team
|
||||
std::vector<std::string> world_player_id, player_first, player_last; // per player
|
||||
std::vector<std::string> player_nation; // nation id per player
|
||||
// Training camps (M4): Classic data gives the eight original resorts, a Modern world its catalogue.
|
||||
std::vector<CampMap> camp_maps;
|
||||
std::vector<TrainingCamp> training_camps;
|
||||
|
||||
ModernState() { season_hooks = &modern::season_hooks(); }
|
||||
// Takes over a state built by shared code (save loading, career setup).
|
||||
ModernState(GameState&& g) : GameState(std::move(g)) { season_hooks = &modern::season_hooks(); }
|
||||
|
||||
@@ -830,7 +830,7 @@ void change_places(ModernState& g, int a, int b) {
|
||||
const uint16_t w = v == uint16_t(a) ? uint16_t(b) : v == uint16_t(b) ? uint16_t(a) : v;
|
||||
g.manager_records.at(at) = uint8_t(w), g.manager_records.at(at + 1) = uint8_t(w >> 8);
|
||||
}
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * 0x690, size_t(b) * 10 + m * 0x690, 10);
|
||||
swap_bytes(g.manager_results, size_t(a) * 10 + m * manager_history_stride(), size_t(b) * 10 + m * manager_history_stride(), 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/game/training_camps.hpp"
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
const CampCatalogue& default_camp_catalogue() {
|
||||
// Names, places, prices and grades are fictional interface data
|
||||
// (docs/new_ui/desktop/trainingcamp); the ids 0-17 are the interface's ids.
|
||||
static const CampCatalogue catalogue = [] {
|
||||
CampCatalogue c;
|
||||
c.maps = {{"map:de", "Deutschland", {}, {}}, {"map:eu", "Europa", {}, {}}, {"map:me", "Naher Osten", {}, {}}};
|
||||
const auto camp = [&](int id, const char* map, const char* name, const char* place, const char* country,
|
||||
std::array<uint8_t, 4> quality, int32_t price) {
|
||||
TrainingCamp t;
|
||||
t.id = "resort:" + std::to_string(id);
|
||||
t.map = map;
|
||||
t.name = name;
|
||||
t.place = place;
|
||||
t.country = country;
|
||||
t.quality = quality;
|
||||
t.base_price = price;
|
||||
c.camps.push_back(t);
|
||||
};
|
||||
camp(0, "map:eu", "Kraftmühle Łódź", "Łódź", "nation:pl", {4, 4, 4, 4}, 410000);
|
||||
camp(1, "map:eu", "Vitalpark Vinadio", "Vinadio", "nation:it", {4, 4, 4, 3}, 450000);
|
||||
camp(2, "map:eu", "Kraftwerk Stettin", "Stettin", "nation:pl", {4, 4, 3, 4}, 420000);
|
||||
camp(3, "map:de", "Wellness Resort Ulm", "Ulm", "nation:de", {2, 3, 2, 2}, 145000);
|
||||
camp(4, "map:eu", "Sportzentrum Groningen", "Groningen", "nation:nl", {4, 4, 4, 4}, 485000);
|
||||
camp(5, "map:de", "Ball-Arena Potsdam", "Potsdam", "nation:de", {3, 2, 3, 2}, 175000);
|
||||
camp(6, "map:eu", "Camp Royal Saint-Denis", "Saint-Denis", "nation:fr", {5, 4, 5, 4}, 650000);
|
||||
camp(7, "map:eu", "Elite-Fußballcamp Ancona", "Ancona", "nation:it", {5, 5, 5, 5}, 840000);
|
||||
camp(8, "map:de", "Sportpark Sauerland", "Schmallenberg", "nation:de", {1, 1, 1, 1}, 25000);
|
||||
camp(9, "map:de", "Trainingshof Harz", "Goslar", "nation:de", {2, 2, 2, 2}, 55000);
|
||||
camp(10, "map:de", "Alpencamp Allgäu", "Kempten", "nation:de", {3, 3, 2, 3}, 195000);
|
||||
camp(11, "map:de", "Leistungszentrum Schwarzwald", "Freiburg", "nation:de", {5, 5, 4, 5}, 490000);
|
||||
camp(12, "map:eu", "Algarve Performance Camp", "Faro", "nation:pt", {5, 4, 5, 5}, 920000);
|
||||
camp(13, "map:eu", "Costa del Sol Sport Resort", "Málaga", "nation:es", {5, 5, 5, 4}, 895000);
|
||||
camp(14, "map:me", "Doha Elite Football Resort", "Doha", "nation:qa", {6, 6, 6, 6}, 2800000);
|
||||
camp(15, "map:me", "Abu Dhabi Royal Training", "Abu Dhabi", "nation:ae", {6, 6, 6, 6}, 3200000);
|
||||
camp(16, "map:me", "Dubai Platinum Sports Camp", "Dubai", "nation:ae", {6, 6, 6, 6}, 3600000);
|
||||
camp(17, "map:eu", "Riviera Trainingscamp Belek", "Belek", "nation:tr", {5, 5, 5, 4}, 790000);
|
||||
return c;
|
||||
}();
|
||||
return catalogue;
|
||||
}
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// Training camp catalogue of the Modern season core (docs/new_engine/trainingslager.md, M4).
|
||||
//
|
||||
// Classic has eight resorts with four quality grades 1-5 read from the executable. Modern
|
||||
// worlds list their camps in rule:training-camps: map (Germany, Europe, Middle East, ...),
|
||||
// position on that map, place, country, base price and the four grades 0-6 (pitch, fitness,
|
||||
// catering, lodging). A world without such a catalogue gets the built-in, fictional
|
||||
// catalogue of 18 camps the Modern interface was designed with.
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bmh::modern {
|
||||
|
||||
struct CampMap {
|
||||
std::string id; // map:de, map:eu, map:me
|
||||
std::string name;
|
||||
std::optional<int> width, height; // coordinate system, once the interface defines it
|
||||
};
|
||||
|
||||
struct TrainingCamp {
|
||||
std::string id; // resort:<n>
|
||||
std::string map; // CampMap id
|
||||
std::optional<int> x, y; // position on the map, null until the interface sets it
|
||||
std::string name, place, country;
|
||||
int32_t base_price = 0; // the price is base_price + 5000 per squad player
|
||||
std::array<uint8_t, 4> quality{}; // pitch, fitness, catering, lodging (0-6)
|
||||
};
|
||||
|
||||
struct CampCatalogue {
|
||||
std::vector<CampMap> maps;
|
||||
std::vector<TrainingCamp> camps;
|
||||
};
|
||||
|
||||
// The built-in catalogue: 18 fictional camps on three maps (Germany 6, Europe 9, Middle East 3).
|
||||
const CampCatalogue& default_camp_catalogue();
|
||||
|
||||
} // namespace bmh::modern
|
||||
@@ -153,9 +153,8 @@ int squad_count(const ModernState& g, int team, int flags) {
|
||||
|
||||
// SlotTeam: club of an absolute squad slot (-1 for the pool).
|
||||
int slot_team(int slot) {
|
||||
if (slot < german_clubs() * 24) return slot / 24;
|
||||
if (slot < int(transfer_list_slot())) return (slot - german_clubs() * 24) / 16 + german_clubs();
|
||||
return -1;
|
||||
// WorldLayout: Classic gives 24 slots to the German clubs and 16 to the international ones.
|
||||
return slot >= 0 && uint32_t(slot) < transfer_list_slot() ? world_layout().team_of_slot(slot) : -1;
|
||||
}
|
||||
|
||||
// Add32 / FacilityRating2: the club's rating of its facilities.
|
||||
@@ -968,7 +967,7 @@ static bool remove_from_seller_impl(ModernState& g, int seller, int player, Minu
|
||||
report.fail("transfer: the player is not in the seller's squad (internal error 0x21)");
|
||||
return false;
|
||||
}
|
||||
for (size_t s = transfer_list_slot(); s < 2972; s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
for (size_t s = transfer_list_slot(); s < free_agent_slot(); s++) // CareerRuntimeField .. CareerRuntimeField2
|
||||
if ((g.squad_slots[s] & 0xFFF) == player) g.squad_slots[s] = 0xFFF;
|
||||
for (size_t s = at; s + 1 < range.first + range.count; s++) g.squad_slots[s] = g.squad_slots[s + 1];
|
||||
g.squad_slots[range.first + range.count - 1] = 0xFFF;
|
||||
|
||||
Reference in new issue
Block a user