Skip to content

Commit

Permalink
Maniac: Implement CallCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Oct 30, 2023
1 parent 45bcf6f commit 3132d80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool Game_Interpreter::IsRunning() const {

// Setup.
void Game_Interpreter::Push(
const std::vector<lcf::rpg::EventCommand>& _list,
std::vector<lcf::rpg::EventCommand> _list,
int event_id,
bool started_by_decision_key
) {
Expand All @@ -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;
Expand Down Expand Up @@ -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<int32_t> 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<int32_t>(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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Game_Interpreter
void Update(bool reset_loop_count=true);

void Push(
const std::vector<lcf::rpg::EventCommand>& _list,
std::vector<lcf::rpg::EventCommand> _list,
int _event_id,
bool started_by_decision_key = false
);
Expand Down

0 comments on commit 3132d80

Please sign in to comment.