Skip to content

Commit

Permalink
Merge pull request #3290 from MakoInfused/ManiacChangeBattleCommandEx
Browse files Browse the repository at this point in the history
Implemented Maniacs Command 3011: ChangeBattleCommandEx
  • Loading branch information
Ghabry authored Nov 8, 2024
2 parents 32ebfa5 + c8a851e commit edc1377
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
32 changes: 30 additions & 2 deletions src/game_interpreter_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "game_map.h"
#include "spriteset_battle.h"
#include <cassert>
#include "scene_battle.h"

enum BranchBattleSubcommand {
eOptionBranchBattleElse = 1
Expand Down Expand Up @@ -605,12 +606,39 @@ 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 actor_command_flags = com.parameters[0];

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 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 party_command_flag = party_command_flags & (1 << i);
bool flag_is_set = i > 2;

if (party_command_flag == flag_is_set) {
lcf::Data::system.easyrpg_battle_options.push_back(i);
}
}

auto* scene_battle = static_cast<Scene_Battle*>(Scene::instance.get());

if (scene_battle) {
scene_battle->CreateOptions();
}

return true;
}

Expand Down
20 changes: 16 additions & 4 deletions src/scene_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,18 @@ void Scene_Battle::DrawBackground(Bitmap& dst) {
dst.Clear();
}

void Scene_Battle::CreateUi() {
void Scene_Battle::CreateOptions() {
std::vector<std::string> 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;
Expand All @@ -208,13 +210,23 @@ 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;
}
}

options_window.reset(new Window_Command(commands, option_command_mov));
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);
Expand Down
6 changes: 5 additions & 1 deletion src/scene_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Scene_Battle : public Scene {

void Start() override;

void CreateOptions();

void UpdateScreen();
void UpdateBattlers();
void UpdateUi();
Expand Down Expand Up @@ -125,7 +127,9 @@ class Scene_Battle : public Scene {
enum BattleOptionType {
Battle,
AutoBattle,
Escape
Escape,
Win,
Lose
};

static void SelectionFlash(Game_Battler* battler);
Expand Down
19 changes: 16 additions & 3 deletions src/scene_battle_rpg2k3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,21 +1155,25 @@ 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);

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));
}
Expand Down Expand Up @@ -1217,6 +1221,15 @@ 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 (Game_Enemy* enemy : Main_Data::game_enemyparty->GetEnemies()) {
enemy->Kill();
}
SetState(State_Victory);
break;
case Lose: // Lose
SetState(State_Defeat);
break;
}
}
return SceneActionReturn::eWaitTillNextFrame;
Expand Down

0 comments on commit edc1377

Please sign in to comment.