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

+36
View File
@@ -697,6 +697,42 @@ add_executable(openbmh_cli
src/cli/json.cpp
${BMH_APP_SESSION_SOURCE})
target_link_libraries(openbmh_cli PRIVATE bmh_launcher bmhui bmhlaunch)
# The same console on the Modern session (docs/new_engine): play a Modern world in the text
# console until the new interface is connected. The console and its desk/window actions are
# compiled a second time with OPENBMH_MODERN_SESSION (src/app/session.hpp).
add_executable(openbmh_modern_cli
src/cli/main.cpp
src/cli/protocol.cpp
src/cli/console/console.cpp
src/cli/console/parser.cpp
src/cli/console/windows_start.cpp
src/cli/console/windows_desk.cpp
src/cli/console/windows_tables.cpp
src/cli/console/windows_club.cpp
src/cli/console/windows_money.cpp
src/cli/console/windows_office.cpp
src/cli/console/windows_squad.cpp
src/cli/console/windows_transfer.cpp
src/cli/console/windows_info.cpp
src/cli/console/windows_match.cpp
src/cli/console/windows_friendly.cpp
src/cli/console/windows_reschedule.cpp
src/cli/console/windows_balance.cpp
src/cli/console/windows_environment.cpp
src/cli/console/windows_state.cpp
src/cli/seat_hub.cpp
src/cli/json.cpp
src/app/window_actions.cpp
src/app/desktop_actions.cpp)
target_compile_definitions(openbmh_modern_cli PRIVATE OPENBMH_MODERN_SESSION)
target_link_libraries(openbmh_modern_cli PRIVATE bmh_launcher bmhui bmhlaunch bmh_modern_session)
if(WIN32)
target_link_libraries(openbmh_modern_cli PRIVATE ws2_32)
endif()
if(MSVC)
target_compile_options(openbmh_modern_cli PRIVATE /utf-8 /bigobj)
endif()
if(WIN32)
target_link_libraries(openbmh_cli PRIVATE ws2_32) # --listen (Winsock)
endif()
+39
View File
@@ -0,0 +1,39 @@
# Modern in der Konsole spielen
Bis die neue Oberfläche angebunden ist, lässt sich die Modern-Engine mit einer Modern-Welt in der Textkonsole spielen: `openbmh_modern_cli`. Es ist dieselbe Konsole wie `openbmh_cli` (Befehle siehe [CLI-Konzept](../CLI_CONCEPT/README.md)), übersetzt gegen die Modern-Session.
```
openbmh_modern_cli --console --mod <Diamond_2026-27_Modern.obw> --saves <Ordner> --seed <n>
```
Beispiel (jeder Befehlsblock endet mit `go.`):
```text
NewGame(5, 3, 1, 3, true, true)
go.
SelectTeam("Name", club:3, Bundesliga, Middle, 2)
go.
Answer(1, Yes)
go.
Kickoff
go.
Run(End)
go.
Open(LeagueTable)
go.
```
Auch der JSON-Modus (`--json`, Befehle `new`, `kickoff`, `save`, `load`, …) und mehrere Sitze (`--serve`, `--seats`) funktionieren wie bei `openbmh_cli`.
## Grenzen
- Nur deutsche Vereine sind wählbar (0.3); die Zusatz-Reiter der Auswahl (Amateure) und Auslandsvereine werden abgelehnt.
- Die Konsole zeigt die Namen der Engine (Großbuchstaben, Einzelbyte-Zeichensatz); UTF-8-Namen, Vornamen, Almanach und Spielstatistik liefert die Engine über `ModernSession::read` für die neue Oberfläche.
- Spielstände sind Modern-Spielstände (`.obs`, nennen ihre Welt); sie laden nur mit derselben Welt.
## Technik
- `src/app/session.hpp`: Mit `OPENBMH_MODERN_SESSION` heißt `app::CareerSession` die Modern-Session, und deren Typen sind unter `bmh::app` sichtbar; ohne den Schalter bleibt alles beim Classic-Stand.
- Die Konsole und die Desk-/Fenster-Aktionen (`desktop_actions`, `window_actions`) werden für `openbmh_modern_cli` ein zweites Mal übersetzt. Zurückrollen nach einer gescheiterten Aktion sichert den ganzen Session-Zustand (`app::SessionState`), damit Modern-Daten (Namen, Almanach, Toto-Spalten) erhalten bleiben.
- `src/cli/main.cpp` öffnet im Modern-Build eine Welt wie der Sim (`open_world_package`, `set_current_world`); der Spielstandordner wird nach dem SHA-256 der Welt-ID benannt.
- Vereinsauswahl: Die Auswahl der Classic-Oberfläche arbeitet mit den Stamm-IDs der Original-Datenbank. Vereine, die eine Welt hinzufügt, bekommen dort freie IDs; bestätigen lassen sich nur deutsche Vereine.
+3 -2
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "app/career_session.hpp"
#include "app/session.hpp"
namespace bmh::app::detail {
@@ -30,7 +30,8 @@ bool apply_window(CareerSession& session, uint64_t& revision, Checkpoint before,
inline bool apply_native(CareerSession& session, uint64_t& revision, const std::function<bool()>& action) {
return apply_window(session, revision, session.state(),
[&](GameState before) { session.state() = std::move(before); }, action);
// the whole session state (the Modern one carries more than GameState)
[&](SessionState before) { session.state() = std::move(before); }, action);
}
} // namespace bmh::app::detail
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "app/career_session.hpp"
#include "app/session.hpp"
namespace bmh::app {
+22
View File
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The career session the console and its desk/window actions drive.
//
// Normally the Classic CareerSession. With OPENBMH_MODERN_SESSION (the openbmh_modern_cli
// target) the same console and action sources are compiled a second time against the Modern
// session (docs/new_engine): ModernSession is a fork of CareerSession with the same interface,
// so its types are made visible under bmh::app and CareerSession names the Modern session.
#ifdef OPENBMH_MODERN_SESSION
#include "modern/app/modern_session.hpp"
namespace bmh::app {
using namespace ::bmh::modern::app;
using CareerSession = ::bmh::modern::app::ModernSession;
using SessionState = ::bmh::modern::ModernState; // the state the session's hooks hand out
} // namespace bmh::app
#else
#include "app/career_session.hpp"
namespace bmh::app {
using SessionState = ::bmh::GameState;
} // namespace bmh::app
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "app/career_session.hpp"
#include "app/session.hpp"
namespace bmh::app {
+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 {
+28
View File
@@ -40,6 +40,7 @@
#include <stdexcept>
#include <system_error>
#include <algorithm>
#include <set>
#include <array>
#include <atomic>
#include <cctype>
@@ -798,6 +799,28 @@ ui::SelectionContext ModernSession::selection_context_for(const ModernState& sta
}
c.club_order.push_back(master);
}
// A Modern world has more clubs than the original's master ids, and the clubs it added have
// none. The human chooses German clubs only (docs/new_engine); those keep their master ids.
// The picker needs the order up to its extra-team tabs (the amateur clubs behind all league
// clubs). A club without a valid unique master id there (one the world added) gets an unused
// one, so the order stays unique; only German clubs can be confirmed (confirm_manager).
if (current_world()) {
const size_t needed = size_t(world_layout().league_teams) +
exe_.u16(::bmh::layout::CareerSession_InstallLeagueSizes_RuntimeField6);
const int masters = int(db_.club_names.size());
c.club_order.resize(std::min(c.club_order.size(), needed));
std::set<int> used;
std::vector<size_t> invalid;
for (size_t t = 0; t < c.club_order.size(); ++t)
if (c.club_order[t] < 0 || c.club_order[t] >= masters || !used.insert(c.club_order[t]).second) invalid.push_back(t);
int spare = 0;
for (size_t t : invalid) {
while (spare < masters && used.count(spare)) ++spare;
if (spare >= masters) throw FormatError("manager selection: not enough master ids for the world's clubs");
c.club_order[t] = spare;
used.insert(spare);
}
}
return c;
}
@@ -976,6 +999,11 @@ bool ModernSession::confirm_manager(const ui::SetupOptions& options, const ui::M
CareerManager c;
c.name = choice.name;
c.team = runtime_club(choice.master_club);
// Modern 0.3: a human manages a German club only (docs/new_engine)
if (current_world() && (c.team < 0 || c.team >= modern::german_clubs())) {
error = "only German clubs can be managed";
return false;
}
c.league = choice.start_league;
c.strength = choice.strength;
c.portrait = choice.portrait;
+4
View File
@@ -53,6 +53,8 @@
#include "ui/opportunities.hpp"
#include "ui/other_games_state.hpp"
namespace bmh::app { class TransferActions; }
namespace bmh::modern::app {
ui::OutgoingTransferEditorState loan_return_offer_editor_projection(
@@ -116,6 +118,8 @@ struct AutomationRequest {
class ModernSession {
friend class TransferActions;
// the console's transfer actions, compiled against this session (openbmh_modern_cli, app/session.hpp)
friend class ::bmh::app::TransferActions;
public:
struct LineupCheckpoint {
ModernState state;