diff --git a/CMakeLists.txt b/CMakeLists.txt index cf75f7d..027d3f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/docs/new_engine/konsole.md b/docs/new_engine/konsole.md new file mode 100644 index 0000000..6c6672e --- /dev/null +++ b/docs/new_engine/konsole.md @@ -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 --saves --seed +``` + +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. diff --git a/src/app/action_transaction.hpp b/src/app/action_transaction.hpp index e1a8ba9..9d9dc0f 100644 --- a/src/app/action_transaction.hpp +++ b/src/app/action_transaction.hpp @@ -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& 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 diff --git a/src/app/desktop_actions.hpp b/src/app/desktop_actions.hpp index abc37ee..bbf579d 100644 --- a/src/app/desktop_actions.hpp +++ b/src/app/desktop_actions.hpp @@ -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 { diff --git a/src/app/session.hpp b/src/app/session.hpp new file mode 100644 index 0000000..65380c5 --- /dev/null +++ b/src/app/session.hpp @@ -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 diff --git a/src/app/window_actions.hpp b/src/app/window_actions.hpp index 830e11f..c98d8cb 100644 --- a/src/app/window_actions.hpp +++ b/src/app/window_actions.hpp @@ -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 { diff --git a/src/cli/console/console.hpp b/src/cli/console/console.hpp index 573ab40..db59817 100644 --- a/src/cli/console/console.hpp +++ b/src/cli/console/console.hpp @@ -28,7 +28,7 @@ #include #include -#include "app/career_session.hpp" +#include "app/session.hpp" #include "game/balance_plan.hpp" #include "game/bank_credit.hpp" #include "game/desk_actions.hpp" diff --git a/src/cli/console/windows_match.cpp b/src/cli/console/windows_match.cpp index cf427f1..b89bc89 100644 --- a/src/cli/console/windows_match.cpp +++ b/src/cli/console/windows_match.cpp @@ -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 demands{}; diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 9604d77..cd2e78e 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -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(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 "@"; 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 diff --git a/src/cli/protocol.cpp b/src/cli/protocol.cpp index a2fec6d..34f9e1d 100644 --- a/src/cli/protocol.cpp +++ b/src/cli/protocol.cpp @@ -10,7 +10,7 @@ #include #include -#include "app/career_session.hpp" +#include "app/session.hpp" #include "formats/m3d.hpp" #include "game/messages.hpp" #include "game/schedule.hpp" diff --git a/src/cli/protocol.hpp b/src/cli/protocol.hpp index d02b6d3..1b074d7 100644 --- a/src/cli/protocol.hpp +++ b/src/cli/protocol.hpp @@ -7,7 +7,11 @@ #include #include +#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 { diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index eb06eed..d7bb3b9 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -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 used; + std::vector 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; diff --git a/src/modern/app/modern_session.hpp b/src/modern/app/modern_session.hpp index 6c2e3f9..2e2f469 100644 --- a/src/modern/app/modern_session.hpp +++ b/src/modern/app/modern_session.hpp @@ -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;