Skip to content

Commit

Permalink
Introduce CommandStringOrVariable API
Browse files Browse the repository at this point in the history
Makes implementing string variables for command simpler.
  • Loading branch information
Ghabry committed Nov 2, 2023
1 parent 9cc7db6 commit ed2ee73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,18 @@ int Game_Interpreter::ValueOrVariableBitfield(int mode, int shift, int val) {
return ValueOrVariable((mode & (0xF << shift * 4)) >> shift * 4, val);
}

StringView Game_Interpreter::CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx) {
if (!Player::IsPatchManiac()) {
return com.string;
}

if (com.parameters.size() >= std::max(mode_idx, val_idx) + 1) {
return Main_Data::game_strings->GetWithModeBitfield(com.string, com.parameters[mode_idx], shift, com.parameters[val_idx]);
}

return com.string;
}

bool Game_Interpreter::CommandChangeParameters(lcf::rpg::EventCommand const& com) { // Code 10430
int value = OperateValue(
com.parameters[2],
Expand Down Expand Up @@ -2043,7 +2055,7 @@ bool Game_Interpreter::CommandWait(lcf::rpg::EventCommand const& com) { // code

bool Game_Interpreter::CommandPlayBGM(lcf::rpg::EventCommand const& com) { // code 11510
lcf::rpg::Music music;
music.name = ToString(com.string);
music.name = ToString(CommandStringOrVariable(com, 4, 0, 5));

if (Player::IsPatchManiac() && com.parameters.size() >= 5) {
int mode = com.parameters[4];
Expand All @@ -2070,7 +2082,7 @@ bool Game_Interpreter::CommandFadeOutBGM(lcf::rpg::EventCommand const& com) { //

bool Game_Interpreter::CommandPlaySound(lcf::rpg::EventCommand const& com) { // code 11550
lcf::rpg::Sound sound;
sound.name = ToString(com.string);
sound.name = ToString(CommandStringOrVariable(com, 3, 0, 3));

if (Player::IsPatchManiac() && com.parameters.size() >= 4) {
int mode = com.parameters[3];
Expand Down Expand Up @@ -4984,11 +4996,7 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co
lcf::rpg::EventCommand cmd;
cmd.code = ValueOrVariableBitfield(com.parameters[0], 0, com.parameters[1]);

if (com.parameters.size() >= 5) {
cmd.string = Main_Data::game_strings->GetWithModeBitfield(com.string, com.parameters[0], 3, com.parameters[4]);
} else {
cmd.string = com.string;
}
cmd.string = lcf::DBString(CommandStringOrVariable(com, 0, 3, 4));

int arr_begin = ValueOrVariableBitfield(com.parameters[0], 1, com.parameters[2]);
int arr_length = ValueOrVariableBitfield(com.parameters[0], 2, com.parameters[3]);
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class Game_Interpreter
static std::vector<Game_Actor*> GetActors(int mode, int id);
static int ValueOrVariable(int mode, int val);
static int ValueOrVariableBitfield(int mode, int shift, int val);
StringView CommandStringOrVariable(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx);

/**
* When current frame finishes executing we pop the stack
Expand Down

0 comments on commit ed2ee73

Please sign in to comment.