Skip to content

Commit 3ffe3cc

Browse files
committed
Maniac Patch Commands: Use the checked helper functions to get rid of Maniacs and range checks
1 parent 2b9f4a9 commit 3ffe3cc

File tree

1 file changed

+16
-57
lines changed

1 file changed

+16
-57
lines changed

src/game_interpreter.cpp

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,20 +2197,12 @@ bool Game_Interpreter::CommandChangeVehicleGraphic(lcf::rpg::EventCommand const&
21972197
bool Game_Interpreter::CommandChangeSystemBGM(lcf::rpg::EventCommand const& com) { //code 10660
21982198
lcf::rpg::Music music;
21992199
int context = com.parameters[0];
2200-
music.name = ToString(com.string);
2201-
music.fadein = com.parameters[1];
2202-
music.volume = com.parameters[2];
2203-
music.tempo = com.parameters[3];
2204-
music.balance = com.parameters[4];
22052200

2206-
if (Player::IsPatchManiac() && com.parameters.size() > 5) {
2207-
int opts = com.parameters[5];
2208-
music.name = ToString(Main_Data::game_strings->GetWithMode(music.name, (opts & 0xF), com.parameters[6], *Main_Data::game_variables));
2209-
music.fadein = ValueOrVariableBitfield(opts, 1, music.fadein);
2210-
music.volume = ValueOrVariableBitfield(opts, 2, music.volume);
2211-
music.tempo = ValueOrVariableBitfield(opts, 3, music.tempo);
2212-
music.balance = ValueOrVariableBitfield(opts, 4, music.balance);
2213-
}
2201+
music.name = ToString(CommandStringOrVariableBitfield(com, 5, 0, 6));
2202+
music.fadein = ValueOrVariableBitfield(com, 5, 1, 1);
2203+
music.volume = ValueOrVariableBitfield(com, 5, 2, 2);
2204+
music.tempo = ValueOrVariableBitfield(com, 5, 3, 3);
2205+
music.balance = ValueOrVariableBitfield(com, 5, 4, 4);
22142206

22152207
Main_Data::game_system->SetSystemBGM(context, std::move(music));
22162208
return true;
@@ -2219,29 +2211,17 @@ bool Game_Interpreter::CommandChangeSystemBGM(lcf::rpg::EventCommand const& com)
22192211
bool Game_Interpreter::CommandChangeSystemSFX(lcf::rpg::EventCommand const& com) { //code 10670
22202212
lcf::rpg::Sound sound;
22212213
int context = com.parameters[0];
2222-
sound.name = ToString(com.string);
2223-
sound.volume = com.parameters[1];
2224-
sound.tempo = com.parameters[2];
2225-
sound.balance = com.parameters[3];
2226-
2227-
if (Player::IsPatchManiac() && com.parameters.size() > 4) {
2228-
int opts = com.parameters[4];
2229-
sound.name = ToString(Main_Data::game_strings->GetWithMode(sound.name, (opts & 0xF), com.parameters[5], *Main_Data::game_variables));
2230-
sound.volume = ValueOrVariableBitfield(opts, 1, sound.volume);
2231-
sound.tempo = ValueOrVariableBitfield(opts, 2, sound.tempo);
2232-
sound.balance = ValueOrVariableBitfield(opts, 3, sound.balance);
2233-
}
2214+
sound.name = ToString(CommandStringOrVariableBitfield(com, 4, 0, 5));
2215+
sound.volume = ValueOrVariableBitfield(com, 4, 1, 1);
2216+
sound.tempo = ValueOrVariableBitfield(com, 4, 2, 2);
2217+
sound.balance = ValueOrVariableBitfield(com, 4, 3, 3);
22342218

22352219
Main_Data::game_system->SetSystemSE(context, std::move(sound));
22362220
return true;
22372221
}
22382222

22392223
bool Game_Interpreter::CommandChangeSystemGraphics(lcf::rpg::EventCommand const& com) { // code 10680
2240-
std::string name = ToString(com.string);
2241-
2242-
if (Player::IsPatchManiac() && com.parameters.size() > 2) {
2243-
name = ToString(CommandStringOrVariableBitfield(com, 2, 0, 3));
2244-
}
2224+
std::string name = ToString(CommandStringOrVariableBitfield(com, 2, 0, 3));
22452225

22462226
Main_Data::game_system->SetSystemGraphic(name,
22472227
static_cast<lcf::rpg::System::Stretch>(com.parameters[0]),
@@ -2354,13 +2334,8 @@ bool Game_Interpreter::CommandChangeEventLocation(lcf::rpg::EventCommand const&
23542334
}
23552335

23562336
bool Game_Interpreter::CommandTradeEventLocations(lcf::rpg::EventCommand const& com) { // Code 10870
2357-
int event1_id = com.parameters[0];
2358-
int event2_id = com.parameters[1];
2359-
2360-
if (Player::IsPatchManiac() && com.parameters.size() > 2) {
2361-
event1_id = ValueOrVariableBitfield(com.parameters[2], 0, event1_id);
2362-
event2_id = ValueOrVariableBitfield(com.parameters[2], 1, event2_id);
2363-
}
2337+
int event1_id = ValueOrVariableBitfield(2, 0, 0);
2338+
int event2_id = ValueOrVariableBitfield(2, 1, 1);
23642339

23652340
Game_Character *event1 = GetCharacter(event1_id, "TradeEventLocations");
23662341
Game_Character *event2 = GetCharacter(event2_id, "TradeEventLocations");
@@ -3402,11 +3377,7 @@ bool Game_Interpreter::CommandKeyInputProc(lcf::rpg::EventCommand const& com) {
34023377
}
34033378

34043379
bool Game_Interpreter::CommandChangeMapTileset(lcf::rpg::EventCommand const& com) { // code 11710
3405-
int chipset_id = com.parameters[0];
3406-
3407-
if (Player::IsPatchManiac() && com.parameters.size() > 1) {
3408-
chipset_id = ValueOrVariable(com.parameters[1], com.parameters[0]);
3409-
}
3380+
int chipset_id = chipset_id = ValueOrVariableBitfield(com, 1, 0, 0);
34103381

34113382
if (chipset_id == Game_Map::GetChipset()) {
34123383
return true;
@@ -3426,27 +3397,15 @@ bool Game_Interpreter::CommandChangeMapTileset(lcf::rpg::EventCommand const& com
34263397

34273398
bool Game_Interpreter::CommandChangePBG(lcf::rpg::EventCommand const& com) { // code 11720
34283399
Game_Map::Parallax::Params params;
3429-
params.name = ToString(com.string);
3430-
3431-
if (Player::IsPatchManiac() && com.parameters.size() > 7) {
3432-
params.name = ToString(CommandStringOrVariableBitfield(com, 6, 0, 7));
3433-
}
3400+
params.name = ToString(CommandStringOrVariableBitfield(com, 6, 0, 7));
34343401

34353402
params.scroll_horz = com.parameters[0] != 0;
34363403
params.scroll_vert = com.parameters[1] != 0;
34373404
params.scroll_horz_auto = com.parameters[2] != 0;
3438-
params.scroll_horz_speed = com.parameters[3];
3439-
3440-
if (Player::IsPatchManiac() && com.parameters.size() > 6) {
3441-
params.scroll_horz_speed = ValueOrVariableBitfield(com.parameters[6], 4, com.parameters[3]);
3442-
}
3405+
params.scroll_horz_speed = ValueOrVariableBitfield(com, 6, 4, 3);
34433406

34443407
params.scroll_vert_auto = com.parameters[4] != 0;
3445-
params.scroll_vert_speed = com.parameters[5];
3446-
3447-
if (Player::IsPatchManiac() && com.parameters.size() > 6) {
3448-
params.scroll_vert_speed = ValueOrVariableBitfield(com.parameters[6], 6, com.parameters[5]);
3449-
}
3408+
params.scroll_vert_speed = ValueOrVariableBitfield(com, 6, 6, 5);
34503409

34513410
Game_Map::Parallax::ChangeBG(params);
34523411

0 commit comments

Comments
 (0)