Play Modern worlds in the text console (openbmh_modern_cli)

The console and its desk/window actions are compiled a second time
against ModernSession (src/app/session.hpp, OPENBMH_MODERN_SESSION), so
a Modern world can be played before the new interface is connected:
new career, club picker, desk, live matchday, results, save and load.

- The CLI opens a Modern world like the season sim and keys its save
  folder by the SHA-256 of the world id.
- Rollbacks keep the whole session state (app::SessionState) instead
  of slicing it to GameState, which would drop Modern data.
- Club picker: clubs a world adds get unused master ids so the
  original picker's order stays unique; only German clubs can be
  confirmed in Modern.

Classic openbmh_cli is unchanged (same sources without the switch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-24 14:16:41 +02:00
1 parent a11311994d
commit ce79697b20
13 files changed
+163 -11

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@
#include <string_view>
#include <vector>
#include "app/career_session.hpp"
#include "app/session.hpp"
#include "game/balance_plan.hpp"
#include "game/bank_credit.hpp"
#include "game/desk_actions.hpp"
+5 -5
View File
@@ -86,7 +86,7 @@ struct Console::EngineRun {
bool loan_question = false;
// These capabilities refer to the month caller's staged transaction, never
// CareerSession's live state. They live only while its synchronous hook waits.
GameState* loan_state = nullptr;
app::SessionState* loan_state = nullptr;
GameRandom* loan_game = nullptr;
WatcomRandom* loan_random = nullptr;
app::ClubModalServices* loan_services = nullptr;
@@ -154,12 +154,12 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
run_->before = before;
EngineRun* run = run_.get();
if (options_.time == TimeMode::instant) run->quiet = run->to_end = true;
session_->set_loan_return_presenter([run](GameState&, WatcomRandom&, int manager, const std::string& question) {
session_->set_loan_return_presenter([run](app::SessionState&, WatcomRandom&, int manager, const std::string& question) {
run->loan_question = true;
struct Reset { bool& flag; ~Reset() { flag = false; } } reset{run->loan_question};
return run->ask(manager + 1, utf8(question), {"Yes", "No"}, "No") == "Yes" ? 1 : 0;
});
session_->set_loan_return_offer_presenter([run](GameState& state, GameRandom& game, WatcomRandom& random,
session_->set_loan_return_offer_presenter([run](app::SessionState& state, GameRandom& game, WatcomRandom& random,
app::ClubModalServices& services, int manager, int source_slot, int list_entry,
const HumanBuyerSaleHooks& hooks) -> int {
if (run->aborted || manager < 0 || size_t(manager) >= state.manager_teams.size() ||
@@ -204,7 +204,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
// that synchronous Source callback through the same engine-question pause
// used by the kickoff's transfer questions. Offers are the actual four
// Source demands; no guessed renewal term or salary is applied.
session_->set_contract_expiry_presenter([run](GameState& state, WatcomRandom& random, int manager, int row) {
session_->set_contract_expiry_presenter([run](app::SessionState& state, WatcomRandom& random, int manager, int row) {
if (manager < 0 || size_t(manager) >= state.manager_teams.size())
throw std::runtime_error("contract expiry: invalid manager owner");
const SquadRange squad = squad_range(state.manager_teams[size_t(manager)]);
@@ -217,7 +217,7 @@ void Console::start_matchday(const ui::DeskRequest& request, const ui::DeskState
if (player == 0x0fff || size_t(player) >= state.players.size())
throw std::runtime_error("contract expiry: missing player");
const std::string player_name = utf8(state.player_name(player));
const GameState before = state;
const app::SessionState before = state; // the whole state (Modern carries more)
const WatcomRandom before_random = random;
std::array<uint32_t, 4> demands{};
+18
View File
@@ -36,6 +36,10 @@
#include "launch/process.hpp"
#include "launch/mods.hpp"
#include "version.hpp"
#ifdef OPENBMH_MODERN_SESSION
#include "content/digest.hpp"
#include "modern/content/world_package.hpp"
#endif
namespace {
using namespace bmh::cli;
@@ -746,7 +750,17 @@ int main(int argc, char** argv) {
if (!args.data.empty()) {
if (std::filesystem::is_directory(args.data))
args.data /= "content.obw";
#ifdef OPENBMH_MODERN_SESSION
// A Modern world (docs/new_engine): read selectively (its artwork stays in the
// archive), mount its Classic payload and name the world for the session.
{
auto package = bmh::modern::open_world_package(args.data);
contents = package.classic;
bmh::modern::set_current_world(package.world);
}
#else
contents = bmh::content::open(args.data);
#endif
mount = std::make_unique<bmh::content::Mount>(args.data, contents);
args.data = mount->root();
if (args.saves.empty()) {
@@ -754,6 +768,10 @@ int main(int argc, char** argv) {
bmh::launch::executable_path(bmh::launch::path_from_utf8(argv[0])).parent_path());
bmh::launch::ModEntry mod;
mod.content_id = contents->content_id;
#ifdef OPENBMH_MODERN_SESSION
// a Modern world names itself "<id>@<revision>"; its save folder is keyed by the hash
mod.content_id = bmh::content::sha256(mod.content_id);
#endif
args.saves = library.user_directory(mod);
}
} else
+1 -1
View File
@@ -10,7 +10,7 @@
#include <sstream>
#include <string_view>
#include "app/career_session.hpp"
#include "app/session.hpp"
#include "formats/m3d.hpp"
#include "game/messages.hpp"
#include "game/schedule.hpp"
+4
View File
@@ -7,7 +7,11 @@
#include <memory>
#include <string>
#ifdef OPENBMH_MODERN_SESSION
#include "app/session.hpp" // CareerSession names the Modern session there
#else
namespace bmh::app { class CareerSession; }
#endif
namespace bmh::cli {
class Protocol {