From b71338c7b41cffa9ddf09af2c0e65b2e59efc802 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Wed, 1 Sep 2021 14:53:28 +0200 Subject: [PATCH] Maniac: Implement Erase Picture enhancements --- src/game_interpreter.cpp | 44 +++++++++++++++++++++++++++++++++------- src/game_pictures.cpp | 6 ++++++ src/game_pictures.h | 1 + 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 25617ded5c2..29576c0a19c 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -2754,15 +2754,45 @@ bool Game_Interpreter::CommandErasePicture(lcf::rpg::EventCommand const& com) { // Handling of RPG2k3 1.12 chunks int id_type = com.parameters[1]; - int max; - if (id_type < 2) { - pic_id = ValueOrVariable(id_type, pic_id); - max = pic_id; - } else { - max = com.parameters[2]; + int pic_id_max; + switch (id_type) { + case 1: + // Erase single picture referenced by variable + pic_id = ValueOrVariable(Lookup_Variable, pic_id); + pic_id_max = pic_id; + break; + case 2: + // Erase [Arg0, Arg2] + pic_id_max = com.parameters[2]; + break; + case 3: + // Erase [V[Arg0], V[Arg2]] + if (!Player::IsPatchManiac()) { + return true; + } + pic_id = ValueOrVariable(Lookup_Variable, pic_id); + pic_id_max = ValueOrVariable(Lookup_Variable, com.parameters[2]); + break; + case 4: + // Erase single picture referenced by variable indirect + if (!Player::IsPatchManiac()) { + return true; + } + pic_id = ValueOrVariable(Lookup_VariableIndirect, pic_id); + pic_id_max = pic_id; + break; + case 5: + // Erase all pictures + if (!Player::IsPatchManiac()) { + return true; + } + Main_Data::game_pictures->EraseAll(); + return true; + default: + return true; } - for (int i = pic_id; i <= max; ++i) { + for (int i = pic_id; i <= pic_id_max; ++i) { if (i <= 0) { Output::Error("ErasePicture: Requested invalid picture id ({})", i); } diff --git a/src/game_pictures.cpp b/src/game_pictures.cpp index 6809c950901..2876aa7e65f 100644 --- a/src/game_pictures.cpp +++ b/src/game_pictures.cpp @@ -310,6 +310,12 @@ void Game_Pictures::Erase(int id) { } } +void Game_Pictures::EraseAll() { + for (auto& pic: pictures) { + pic.Erase(); + } +} + void Game_Pictures::RequestPictureSprite(Picture& pic) { const auto& name = pic.data.name; if (name.empty()) { diff --git a/src/game_pictures.h b/src/game_pictures.h index 77832d998b4..eeb0a1b2218 100644 --- a/src/game_pictures.h +++ b/src/game_pictures.h @@ -82,6 +82,7 @@ class Game_Pictures { void Show(int id, const ShowParams& params); void Move(int id, const MoveParams& params); void Erase(int id); + void EraseAll(); void Update(bool is_battle);