From 3132d803f31831d265fd3e85e81ecdb9a87d4f2e Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 30 Oct 2023 20:03:56 +0100 Subject: [PATCH] Maniac: Implement CallCommand --- src/game_interpreter.cpp | 30 +++++++++++++++++++++++++----- src/game_interpreter.h | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 0b61a590708..ce3f89b8571 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -100,7 +100,7 @@ bool Game_Interpreter::IsRunning() const { // Setup. void Game_Interpreter::Push( - const std::vector& _list, + std::vector _list, int event_id, bool started_by_decision_key ) { @@ -114,7 +114,7 @@ void Game_Interpreter::Push( lcf::rpg::SaveEventExecFrame frame; frame.ID = _state.stack.size() + 1; - frame.commands = _list; + frame.commands = std::move(_list); frame.current_command = 0; frame.triggered_by_decision_key = started_by_decision_key; frame.event_id = event_id; @@ -4975,13 +4975,33 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& } return true; } - -bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) { + +bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& com) { if (!Player::IsPatchManiac()) { return true; } - Output::Warning("Maniac Patch: Command CallCommand not supported"); + lcf::rpg::EventCommand cmd; + cmd.code = ValueOrVariableBitfield(com.parameters[0], 0, com.parameters[1]); + cmd.string = com.string; + + int arr_begin = ValueOrVariableBitfield(com.parameters[0], 1, com.parameters[2]); + int arr_length = ValueOrVariableBitfield(com.parameters[0], 2, com.parameters[3]); + + std::vector output_args; + if (arr_length > 0) { + output_args.reserve(arr_length); + for (int i = 0; i < arr_length; ++i) { + output_args.push_back(Main_Data::game_variables->Get(arr_begin + i)); + } + } + + cmd.parameters = lcf::DBArray(output_args.begin(), output_args.end()); + + // Our implementation pushes a new frame containing the command instead of invoking it directly. + // This is incompatible to Maniacs but has a better compatibility with our code. + Push({ cmd }, GetThisEventId(), false); + return true; } diff --git a/src/game_interpreter.h b/src/game_interpreter.h index a24c51e9dd8..8c0ccc38844 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -64,7 +64,7 @@ class Game_Interpreter void Update(bool reset_loop_count=true); void Push( - const std::vector& _list, + std::vector _list, int _event_id, bool started_by_decision_key = false );