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:
1 parent
a11311994d
commit
ce79697b20
13 files changed
+163
-11
No files matched your search
@@ -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,7 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
|
||||
#include "app/career_session.hpp"
|
||||
#include "app/session.hpp"
|
||||
|
||||
namespace bmh::app {
|
||||
|
||||
|
||||
@@ -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,7 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
|
||||
#include "app/career_session.hpp"
|
||||
#include "app/session.hpp"
|
||||
|
||||
namespace bmh::app {
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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{};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user