From 76ab5292d93e083c517951a291b153507db06081 Mon Sep 17 00:00:00 2001 From: Mako Infused Date: Wed, 6 Nov 2024 08:18:51 -0500 Subject: [PATCH 1/3] Implemented Maniacs Command 3011: ChangeBattleCommandEx --- src/game_interpreter_battle.cpp | 35 +++++++++++++++++++++++++++++++-- src/scene_battle.cpp | 20 +++++++++++++++---- src/scene_battle.h | 6 +++++- src/scene_battle_rpg2k3.cpp | 13 ++++++++++-- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index 7fba49a61d..19b58145b4 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -31,6 +31,7 @@ #include "game_map.h" #include "spriteset_battle.h" #include +#include enum BranchBattleSubcommand { eOptionBranchBattleElse = 1 @@ -605,12 +606,42 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman return true; } -bool Game_Interpreter_Battle::CommandManiacChangeBattleCommandEx(lcf::rpg::EventCommand const&) { +bool Game_Interpreter_Battle::CommandManiacChangeBattleCommandEx(lcf::rpg::EventCommand const& com) { if (!Player::IsPatchManiac()) { return true; } - Output::Warning("Maniac Patch: Command ChangeBattleCommandEx not supported"); + // 1 row removed + bool actorCommandFlags = com.parameters[0]; + + lcf::Data::battlecommands.easyrpg_disable_row_feature = actorCommandFlags; + + // 10000 lose added + // 01000 win added + // 00100 escape removed + // 00010 auto removed + // 00001 fight removed + int partyCommandFlags = com.parameters[1]; + + lcf::Data::system.easyrpg_battle_options.clear(); + for (size_t i = 0; i < Scene_Battle::BattleOptionType::Lose + 1; i++) + { + bool partyCommandFlag = partyCommandFlags & (1 << i); + bool flagIsSet = i > 2; + + if (partyCommandFlag == flagIsSet) + { + lcf::Data::system.easyrpg_battle_options.push_back(i); + } + } + + auto& scene = Scene::instance; + Scene_Battle* sceneBattle = dynamic_cast(scene.get()); + + if (sceneBattle) { + sceneBattle->CreateOptions(); + } + return true; } diff --git a/src/scene_battle.cpp b/src/scene_battle.cpp index 149022488e..aaf6219f05 100644 --- a/src/scene_battle.cpp +++ b/src/scene_battle.cpp @@ -189,16 +189,18 @@ void Scene_Battle::DrawBackground(Bitmap& dst) { dst.Clear(); } -void Scene_Battle::CreateUi() { +void Scene_Battle::CreateOptions() { std::vector commands; - for (auto option: lcf::Data::system.easyrpg_battle_options) { + battle_options.clear(); + + for (auto option : lcf::Data::system.easyrpg_battle_options) { battle_options.push_back((BattleOptionType)option); } // Add all menu items - for (auto option: battle_options) { - switch(option) { + for (auto option : battle_options) { + switch (option) { case Battle: commands.push_back(ToString(lcf::Data::terms.battle_fight)); break; @@ -208,6 +210,12 @@ void Scene_Battle::CreateUi() { case Escape: commands.push_back(ToString(lcf::Data::terms.battle_escape)); break; + case Win: + commands.push_back("Win"); + break; + case Lose: + commands.push_back("Lose"); + break; } } @@ -215,6 +223,10 @@ void Scene_Battle::CreateUi() { options_window->SetHeight(80); options_window->SetX(Player::menu_offset_x); options_window->SetY(Player::menu_offset_y + MENU_HEIGHT - 80); +} + +void Scene_Battle::CreateUi() { + CreateOptions(); help_window.reset(new Window_Help(Player::menu_offset_x, Player::menu_offset_y, MENU_WIDTH, 32)); help_window->SetVisible(false); diff --git a/src/scene_battle.h b/src/scene_battle.h index 8c7e6ddb2e..bb88b9678a 100644 --- a/src/scene_battle.h +++ b/src/scene_battle.h @@ -80,6 +80,8 @@ class Scene_Battle : public Scene { void Start() override; + void CreateOptions(); + void UpdateScreen(); void UpdateBattlers(); void UpdateUi(); @@ -125,7 +127,9 @@ class Scene_Battle : public Scene { enum BattleOptionType { Battle, AutoBattle, - Escape + Escape, + Win, + Lose }; static void SelectionFlash(Game_Battler* battler); diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 7f42653e4c..285f5962ca 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -1163,13 +1163,12 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionFi options_window->SetActive(true); + auto it = std::find(battle_options.begin(), battle_options.end(), Escape); if (IsEscapeAllowedFromOptionWindow()) { - auto it = std::find(battle_options.begin(), battle_options.end(), Escape); if (it != battle_options.end()) { options_window->EnableItem(std::distance(battle_options.begin(), it)); } } else { - auto it = std::find(battle_options.begin(), battle_options.end(), Escape); if (it != battle_options.end()) { options_window->DisableItem(std::distance(battle_options.begin(), it)); } @@ -1217,6 +1216,16 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionFi Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer)); } break; + case Win: // Win + for each (Game_Enemy* enemy in Main_Data::game_enemyparty->GetEnemies()) + { + enemy->Kill(); + } + SetState(State_Victory); + break; + case Lose: // Lose + SetState(State_Defeat); + break; } } return SceneActionReturn::eWaitTillNextFrame; From 3846a55bcf13d4d2bde4a2570cecb6777449dd59 Mon Sep 17 00:00:00 2001 From: Mako Infused Date: Wed, 6 Nov 2024 12:47:18 -0500 Subject: [PATCH 2/3] Fixed case where autobattle is the only option and therefore is auto selected (just like Maniacs). Also fixed a case where the options for auto battle were not shown despite having other options available to use by the player: Win/Lose --- src/scene_battle_rpg2k3.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 285f5962ca..1d198763f8 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -1155,10 +1155,15 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionFi ResetWindows(true); target_window->SetIndex(-1); - if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_traditional || ((std::find(battle_options.begin(), battle_options.end(), AutoBattle) == battle_options.end()) && !IsEscapeAllowedFromOptionWindow())) { + if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_traditional + || ((std::find(battle_options.begin(), battle_options.end(), AutoBattle) == battle_options.end()) && (std::find(battle_options.begin(), battle_options.end(), Win) == battle_options.end()) && (std::find(battle_options.begin(), battle_options.end(), Lose) == battle_options.end()) && !IsEscapeAllowedFromOptionWindow())) { if (lcf::Data::battlecommands.battle_type != lcf::rpg::BattleCommands::BattleType_traditional) MoveCommandWindows(Player::menu_offset_x - options_window->GetWidth(), 1); SetState(State_SelectActor); return SceneActionReturn::eContinueThisFrame; + } else if (battle_options.size() == 1 && (std::find(battle_options.begin(), battle_options.end(), AutoBattle) != battle_options.end())) { + if (lcf::Data::battlecommands.battle_type != lcf::rpg::BattleCommands::BattleType_traditional) MoveCommandWindows(Player::menu_offset_x - options_window->GetWidth(), 1); + SetState(State_AutoBattle); + return SceneActionReturn::eContinueThisFrame; } options_window->SetActive(true); From c8a851e0aafe58335461ff8783e3828914d9fd3f Mon Sep 17 00:00:00 2001 From: Mako Infused Date: Thu, 7 Nov 2024 06:53:50 -0500 Subject: [PATCH 3/3] fixed a compiler error on non-windows machines and made some stylistic/readability improvements based on Ghabry's feedback. --- src/game_interpreter_battle.cpp | 25 +++++++++++-------------- src/scene_battle_rpg2k3.cpp | 3 +-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index 19b58145b4..1f30d2b669 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -31,7 +31,7 @@ #include "game_map.h" #include "spriteset_battle.h" #include -#include +#include "scene_battle.h" enum BranchBattleSubcommand { eOptionBranchBattleElse = 1 @@ -612,34 +612,31 @@ bool Game_Interpreter_Battle::CommandManiacChangeBattleCommandEx(lcf::rpg::Event } // 1 row removed - bool actorCommandFlags = com.parameters[0]; + bool actor_command_flags = com.parameters[0]; - lcf::Data::battlecommands.easyrpg_disable_row_feature = actorCommandFlags; + lcf::Data::battlecommands.easyrpg_disable_row_feature = actor_command_flags; // 10000 lose added // 01000 win added // 00100 escape removed // 00010 auto removed // 00001 fight removed - int partyCommandFlags = com.parameters[1]; + int party_command_flags = com.parameters[1]; lcf::Data::system.easyrpg_battle_options.clear(); - for (size_t i = 0; i < Scene_Battle::BattleOptionType::Lose + 1; i++) - { - bool partyCommandFlag = partyCommandFlags & (1 << i); - bool flagIsSet = i > 2; + for (size_t i = 0; i < Scene_Battle::BattleOptionType::Lose + 1; i++) { + bool party_command_flag = party_command_flags & (1 << i); + bool flag_is_set = i > 2; - if (partyCommandFlag == flagIsSet) - { + if (party_command_flag == flag_is_set) { lcf::Data::system.easyrpg_battle_options.push_back(i); } } - auto& scene = Scene::instance; - Scene_Battle* sceneBattle = dynamic_cast(scene.get()); + auto* scene_battle = static_cast(Scene::instance.get()); - if (sceneBattle) { - sceneBattle->CreateOptions(); + if (scene_battle) { + scene_battle->CreateOptions(); } return true; diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 1d198763f8..aeb3ea65a4 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -1222,8 +1222,7 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionFi } break; case Win: // Win - for each (Game_Enemy* enemy in Main_Data::game_enemyparty->GetEnemies()) - { + for (Game_Enemy* enemy : Main_Data::game_enemyparty->GetEnemies()) { enemy->Kill(); } SetState(State_Victory);