From 388c551db3540bbe55c1f3ae5b7ed8b306c3c29b Mon Sep 17 00:00:00 2001 From: Mako Infused Date: Wed, 6 Nov 2024 21:39:52 -0500 Subject: [PATCH 1/4] Implemented Maniacs Command 3010: ControlATBGauge --- src/game_interpreter_battle.cpp | 96 ++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index 1f30d2b669..0841f0df2c 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -597,12 +597,104 @@ bool Game_Interpreter_Battle::CommandManiacControlBattle(lcf::rpg::EventCommand return true; } -bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventCommand const&) { +bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventCommand const& com) { if (!Player::IsPatchManiac()) { return true; } - Output::Warning("Maniac Patch: Command ControlAtbGauge not supported"); + // 0 actor + // 1 party member + // 2 entire party + // 3 troop member + // 4 entire troop + int targetFlags = com.parameters[0]; + // 0 constant + // 1 variable + // 2 variable id + int targetReferenceFlags = com.parameters[1]; + int targetReferenceIdentifier = com.parameters[2]; + // 0 set + // 1 add + // 2 sub + int operationFlags = com.parameters[3]; + // 0 value + // 1 percentage + int operandFlags = com.parameters[4]; + // 0 constant + // 1 variable + // 2 variable id + int valueReferenceFlags = com.parameters[5]; + int valueReferenceIdentifier = com.parameters[6]; + + auto getVariableOrValue = [](int flags, int identifier) { + switch (flags) { + case 0: + return identifier; + break; + case 1: + return Main_Data::game_variables->Get(identifier); + break; + case 2: + return Main_Data::game_variables->Get(Main_Data::game_variables->Get(identifier)); + break; + } + }; + + int targetId = getVariableOrValue(targetReferenceFlags, targetReferenceIdentifier); + + auto getAtbValue = [getVariableOrValue, valueReferenceFlags, valueReferenceIdentifier](int flags) { + int value = getVariableOrValue(valueReferenceFlags, valueReferenceIdentifier); + + switch (flags) { + case 0: + return value; + break; + case 1: + return (int) ((double)value / 100 * Game_Battler::GetMaxAtbGauge()); + break; + } + }; + + auto executeOperation = [getAtbValue, operandFlags](int flags, Game_Battler* battler) { + switch (flags) { + case 0: + battler->SetAtbGauge(getAtbValue(operandFlags)); + break; + case 1: + battler->IncrementAtbGauge(getAtbValue(operandFlags)); + break; + case 2: + battler->IncrementAtbGauge(-getAtbValue(operandFlags)); + break; + } + }; + + switch (targetFlags) { + case 0: + if (targetId > 0) { + executeOperation(operationFlags, Main_Data::game_actors->GetActor(targetId)); + } + break; + case 1: + executeOperation(operationFlags, Main_Data::game_party->GetActor(targetId)); + break; + case 2: + for each (Game_Battler* member in Main_Data::game_party->GetActors()) { + executeOperation(operationFlags, member); + } + break; + case 3: + if (targetId > 0) { + executeOperation(operationFlags, Main_Data::game_enemyparty->GetEnemy(targetId)); + } + break; + case 4: + for each (Game_Battler* member in Main_Data::game_enemyparty->GetEnemies()) { + executeOperation(operationFlags, member); + } + break; + } + return true; } From 4d3feae55d9453372e14dde9add1944a4d77b886 Mon Sep 17 00:00:00 2001 From: Mako Infused Date: Thu, 7 Nov 2024 07:31:03 -0500 Subject: [PATCH 2/4] fixed a compiler error on linux and implemented Ghabry's requested changes --- src/game_interpreter_battle.cpp | 88 +++++++++++++-------------------- 1 file changed, 34 insertions(+), 54 deletions(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index 0841f0df2c..ac1db11fd1 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -602,95 +602,75 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman return true; } - // 0 actor - // 1 party member - // 2 entire party - // 3 troop member - // 4 entire troop - int targetFlags = com.parameters[0]; - // 0 constant - // 1 variable - // 2 variable id - int targetReferenceFlags = com.parameters[1]; - int targetReferenceIdentifier = com.parameters[2]; - // 0 set - // 1 add - // 2 sub - int operationFlags = com.parameters[3]; - // 0 value - // 1 percentage - int operandFlags = com.parameters[4]; - // 0 constant - // 1 variable - // 2 variable id - int valueReferenceFlags = com.parameters[5]; - int valueReferenceIdentifier = com.parameters[6]; - - auto getVariableOrValue = [](int flags, int identifier) { - switch (flags) { - case 0: - return identifier; - break; - case 1: - return Main_Data::game_variables->Get(identifier); - break; - case 2: - return Main_Data::game_variables->Get(Main_Data::game_variables->Get(identifier)); - break; - } - }; + int target_flags = com.parameters[0]; + int target_reference_flags = com.parameters[1]; + int target_reference_identifier = com.parameters[2]; + int operation_flags = com.parameters[3]; + int operand_flags = com.parameters[4]; + int value_reference_flags = com.parameters[5]; + int value_reference_identifier = com.parameters[6]; - int targetId = getVariableOrValue(targetReferenceFlags, targetReferenceIdentifier); + int target_id = ValueOrVariable(target_reference_flags, target_reference_identifier); - auto getAtbValue = [getVariableOrValue, valueReferenceFlags, valueReferenceIdentifier](int flags) { - int value = getVariableOrValue(valueReferenceFlags, valueReferenceIdentifier); + auto getAtbValue = [this, value_reference_flags, value_reference_identifier](int flags) { + int value = ValueOrVariable(value_reference_flags, value_reference_identifier); switch (flags) { case 0: + // value return value; break; case 1: + // percentage return (int) ((double)value / 100 * Game_Battler::GetMaxAtbGauge()); break; } }; - auto executeOperation = [getAtbValue, operandFlags](int flags, Game_Battler* battler) { + auto executeOperation = [getAtbValue, operand_flags](int flags, Game_Battler* battler) { switch (flags) { case 0: - battler->SetAtbGauge(getAtbValue(operandFlags)); + // set + battler->SetAtbGauge(getAtbValue(operand_flags)); break; case 1: - battler->IncrementAtbGauge(getAtbValue(operandFlags)); + // add + battler->IncrementAtbGauge(getAtbValue(operand_flags)); break; case 2: - battler->IncrementAtbGauge(-getAtbValue(operandFlags)); + // sub + battler->IncrementAtbGauge(-getAtbValue(operand_flags)); break; } }; - switch (targetFlags) { + switch (target_flags) { case 0: - if (targetId > 0) { - executeOperation(operationFlags, Main_Data::game_actors->GetActor(targetId)); + // actor + if (target_id > 0) { + executeOperation(operation_flags, Main_Data::game_actors->GetActor(target_id)); } break; case 1: - executeOperation(operationFlags, Main_Data::game_party->GetActor(targetId)); + // party member + executeOperation(operation_flags, Main_Data::game_party->GetActor(target_id)); break; case 2: - for each (Game_Battler* member in Main_Data::game_party->GetActors()) { - executeOperation(operationFlags, member); + // entire party + for (Game_Battler* member : Main_Data::game_party->GetActors()) { + executeOperation(operation_flags, member); } break; case 3: - if (targetId > 0) { - executeOperation(operationFlags, Main_Data::game_enemyparty->GetEnemy(targetId)); + // troop member + if (target_id > 0) { + executeOperation(operation_flags, Main_Data::game_enemyparty->GetEnemy(target_id)); } break; case 4: - for each (Game_Battler* member in Main_Data::game_enemyparty->GetEnemies()) { - executeOperation(operationFlags, member); + // entire troop + for (Game_Battler* member : Main_Data::game_enemyparty->GetEnemies()) { + executeOperation(operation_flags, member); } break; } From 0ba00c479ab31054b0c7899ad3231c1d3fe89ed2 Mon Sep 17 00:00:00 2001 From: Dino Suvalic <82914521+MakoInfused@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:32:18 -0500 Subject: [PATCH 3/4] Fixed a null pointer exception, found by Ghabry --- src/game_interpreter_battle.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index ac1db11fd1..3330015d4f 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -37,6 +37,18 @@ enum BranchBattleSubcommand { eOptionBranchBattleElse = 1 }; +enum TargetType { + Actor, + Member, + Enemy, +}; + +static const char* target_text[] = { "actor", "party member", "enemy" }; + +static const void MissingTargetWarning(char* command_name, TargetType target_type, int target_id) { + Output::Warning("{}: Invalid {} ID: {}", command_name, target_text[target_type], target_id); +} + Game_Interpreter_Battle::Game_Interpreter_Battle(Span pages) : Game_Interpreter(true), pages(pages), executed(pages.size(), false) { @@ -624,10 +636,16 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman // percentage return (int) ((double)value / 100 * Game_Battler::GetMaxAtbGauge()); break; + default: return 0; } }; - auto executeOperation = [getAtbValue, operand_flags](int flags, Game_Battler* battler) { + auto executeOperation = [getAtbValue, operand_flags, target_id](int flags, Game_Battler* battler, TargetType battler_type) { + if (!battler) { + MissingTargetWarning("CommandManiacControlAtbGauge", battler_type, target_id); + return; + } + switch (flags) { case 0: // set @@ -648,29 +666,29 @@ bool Game_Interpreter_Battle::CommandManiacControlAtbGauge(lcf::rpg::EventComman case 0: // actor if (target_id > 0) { - executeOperation(operation_flags, Main_Data::game_actors->GetActor(target_id)); + executeOperation(operation_flags, Main_Data::game_actors->GetActor(target_id), Actor); } break; case 1: // party member - executeOperation(operation_flags, Main_Data::game_party->GetActor(target_id)); + executeOperation(operation_flags, Main_Data::game_party->GetActor(target_id), Member); break; case 2: // entire party for (Game_Battler* member : Main_Data::game_party->GetActors()) { - executeOperation(operation_flags, member); + executeOperation(operation_flags, member, Member); } break; case 3: // troop member if (target_id > 0) { - executeOperation(operation_flags, Main_Data::game_enemyparty->GetEnemy(target_id)); + executeOperation(operation_flags, Main_Data::game_enemyparty->GetEnemy(target_id), Enemy); } break; case 4: // entire troop for (Game_Battler* member : Main_Data::game_enemyparty->GetEnemies()) { - executeOperation(operation_flags, member); + executeOperation(operation_flags, member, Enemy); } break; } From 0e061b3f840c707a9a904082071b757ebbe0ec1c Mon Sep 17 00:00:00 2001 From: Dino Suvalic <82914521+MakoInfused@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:48:12 -0500 Subject: [PATCH 4/4] fixed linux compiler warning --- src/game_interpreter_battle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index 3330015d4f..e678e5e10f 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -45,7 +45,7 @@ enum TargetType { static const char* target_text[] = { "actor", "party member", "enemy" }; -static const void MissingTargetWarning(char* command_name, TargetType target_type, int target_id) { +static const void MissingTargetWarning(const char* command_name, TargetType target_type, int target_id) { Output::Warning("{}: Invalid {} ID: {}", command_name, target_text[target_type], target_id); }