Skip to content

Commit

Permalink
fixed 2 bugs: maniac battle control hooks not being reset between bat…
Browse files Browse the repository at this point in the history
…tles & dual attack not being represented. Also made stylistic changes requested by Ghabry.
  • Loading branch information
MakoInfused committed Nov 23, 2024
1 parent db5a253 commit 8c68f35
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/game_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Game_Battle::UpdateAtbGauges() {
}

ManiacBattleHook(
Game_Interpreter_Battle::AtbIncrement,
Game_Interpreter_Battle::ManiacBattleHookType::AtbIncrement,
bat->GetType() == Game_Battler::Type_Enemy,
bat->GetPartyIndex(),
bat->GetAtbGauge(),
Expand Down
78 changes: 61 additions & 17 deletions src/game_battlealgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ Game_BattleAlgorithm::AlgorithmBase::AlgorithmBase(Type ty, Game_Battler* source
}

int Game_BattleAlgorithm::AlgorithmBase::GetActionType() {
return 0;
return -1;
}

int Game_BattleAlgorithm::AlgorithmBase::GetActionId() {
return 0;
return -1;
}

void Game_BattleAlgorithm::AlgorithmBase::Reset() {
Expand Down Expand Up @@ -196,7 +196,7 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpEffect() {

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::StatChange,
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
Expand All @@ -222,7 +222,7 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAtkEffect() {

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::StatChange,
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
Expand All @@ -247,7 +247,7 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyDefEffect() {

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::StatChange,
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
Expand All @@ -272,7 +272,7 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpiEffect() {

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::StatChange,
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
Expand All @@ -297,7 +297,7 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAgiEffect() {

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::StatChange,
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
Expand Down Expand Up @@ -602,7 +602,23 @@ AlgorithmBase(Type::None, source, source) {
}

int Game_BattleAlgorithm::None::GetActionId() {
return 7;
return lcf::rpg::EnemyAction::Basic_nothing;
}

int Game_BattleAlgorithm::None::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::Normal::GetActionId() {
if (IsDualAttack()) {
return lcf::rpg::EnemyAction::Basic_dual_attack;
}

return lcf::rpg::EnemyAction::Basic_attack;
}

int Game_BattleAlgorithm::Normal::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

Game_BattleAlgorithm::Normal::Normal(Game_Battler* source, Game_Battler* target, int hits_multiplier, Style style) :
Expand Down Expand Up @@ -813,12 +829,16 @@ bool Game_BattleAlgorithm::Normal::vExecute() {
return SetIsSuccess();
}

bool Game_BattleAlgorithm::Normal::IsDualAttack() const {
return GetSource()->GetType() == Game_Battler::Type_Enemy && hits_multiplier == 2;
}

std::string Game_BattleAlgorithm::Normal::GetStartMessage(int line) const {
if (line == 0) {
if (Feature::HasRpg2kBattleSystem()) {
return BattleMessage::GetNormalAttackStartMessage2k(*GetSource());
}
if (GetSource()->GetType() == Game_Battler::Type_Enemy && hits_multiplier == 2) {
if (IsDualAttack()) {
return BattleMessage::GetDoubleAttackStartMessage2k3(*GetSource());
}
}
Expand Down Expand Up @@ -923,7 +943,7 @@ Game_BattleAlgorithm::Skill::Skill(Game_Battler* source, const lcf::rpg::Skill&
}

int Game_BattleAlgorithm::Skill::GetActionType() {
return 1;
return lcf::rpg::EnemyAction::Kind_skill;
}

int Game_BattleAlgorithm::Skill::GetActionId() {
Expand Down Expand Up @@ -1429,8 +1449,12 @@ Game_BattleAlgorithm::Defend::Defend(Game_Battler* source) :
source->SetIsDefending(true);
}

int Game_BattleAlgorithm::Defend::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::Defend::GetActionId() {
return 2;
return lcf::rpg::EnemyAction::Basic_defense;
}

std::string Game_BattleAlgorithm::Defend::GetStartMessage(int line) const {
Expand All @@ -1453,8 +1477,12 @@ AlgorithmBase(Type::Observe, source, source) {
// no-op
}

int Game_BattleAlgorithm::Observe::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::Observe::GetActionId() {
return 3;
return lcf::rpg::EnemyAction::Basic_observe;
}

std::string Game_BattleAlgorithm::Observe::GetStartMessage(int line) const {
Expand All @@ -1473,8 +1501,12 @@ AlgorithmBase(Type::Charge, source, source) {
// no-op
}

int Game_BattleAlgorithm::Charge::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::Charge::GetActionId() {
return 4;
return lcf::rpg::EnemyAction::Basic_charge;
}

std::string Game_BattleAlgorithm::Charge::GetStartMessage(int line) const {
Expand All @@ -1497,8 +1529,12 @@ AlgorithmBase(Type::SelfDestruct, source, target) {
// no-op
}

int Game_BattleAlgorithm::SelfDestruct::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::SelfDestruct::GetActionId() {
return 5;
return lcf::rpg::EnemyAction::Basic_autodestruction;
}

std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage(int line) const {
Expand Down Expand Up @@ -1555,8 +1591,12 @@ Game_BattleAlgorithm::Escape::Escape(Game_Battler* source) :
// no-op
}

int Game_BattleAlgorithm::Escape::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::Escape::GetActionId() {
return 6;
return lcf::rpg::EnemyAction::Basic_escape;
}

std::string Game_BattleAlgorithm::Escape::GetStartMessage(int line) const {
Expand Down Expand Up @@ -1597,7 +1637,7 @@ AlgorithmBase(Type::Transform, source, source), new_monster_id(new_monster_id) {
}

int Game_BattleAlgorithm::Transform::GetActionType() {
return 2;
return lcf::rpg::EnemyAction::Kind_transformation;
}

int Game_BattleAlgorithm::Transform::GetActionId() {
Expand Down Expand Up @@ -1626,7 +1666,11 @@ AlgorithmBase(Type::DoNothing, source, source) {
// no-op
}

int Game_BattleAlgorithm::DoNothing::GetActionType() {
return lcf::rpg::EnemyAction::Kind_basic;
}

int Game_BattleAlgorithm::DoNothing::GetActionId() {
return 7;
return lcf::rpg::EnemyAction::Basic_nothing;
}

28 changes: 28 additions & 0 deletions src/game_battlealgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ class None : public AlgorithmBase {
public:
None(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;
};
Expand All @@ -644,13 +647,20 @@ class Normal : public AlgorithmBase {
Style_MultiHit,
};

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

static Style GetDefaultStyle();

Normal(Game_Battler* source, Game_Battler* target, int hits_multiplier = 1, Style style = GetDefaultStyle());
Normal(Game_Battler* source, Game_Party_Base* target, int hits_multiplier = 1, Style style = GetDefaultStyle());

bool vExecute() override;
bool vStart() override;
bool IsDualAttack() const;

int GetAnimationId(int i) const override;
std::string GetStartMessage(int line) const override;
Expand Down Expand Up @@ -752,6 +762,9 @@ class Defend : public AlgorithmBase {
public:
Defend(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

Expand All @@ -763,6 +776,9 @@ class Observe : public AlgorithmBase {
public:
Observe(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

Expand All @@ -773,6 +789,9 @@ class Charge : public AlgorithmBase {
public:
Charge(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

Expand All @@ -784,6 +803,9 @@ class SelfDestruct : public AlgorithmBase {
public:
SelfDestruct(Game_Battler* source, Game_Party_Base* target);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

Expand All @@ -799,6 +821,9 @@ class Escape : public AlgorithmBase {
public:
Escape(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;

Expand Down Expand Up @@ -830,6 +855,9 @@ class DoNothing : public AlgorithmBase {
public:
DoNothing(Game_Battler* source);

/** @return the type associated with this action */
int GetActionType() override;

/** @return the id associated with this action */
int GetActionId() override;
};
Expand Down
2 changes: 1 addition & 1 deletion src/game_battler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool Game_Battler::AddState(int state_id, bool allow_battle_states) {
}

Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::SetState,
Game_Interpreter_Battle::ManiacBattleHookType::SetState,
GetType() == Game_Battler::Type_Enemy,
GetPartyIndex(),
state_id
Expand Down
22 changes: 14 additions & 8 deletions src/game_interpreter_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/

// Headers
// Headers
#include "game_actors.h"
#include "game_battle.h"
#include "game_enemyparty.h"
Expand Down Expand Up @@ -45,13 +45,19 @@ enum TargetType {

// Implemented as a static map, since maniac hooks can only have one common event callback at a time.
// Subsequent calls will simply override the previous common event callback.
std::map<Game_Interpreter_Battle::ManiacBattleHookType, std::tuple<int, int>> Game_Interpreter_Battle::maniac_hooks = {
{AtbIncrement, std::make_tuple(0, 0)},
{DamagePop, std::make_tuple(0, 0)},
{Targetting, std::make_tuple(0, 0)},
{SetState, std::make_tuple(0, 0)},
{StatChange, std::make_tuple(0, 0)}
};
std::map<Game_Interpreter_Battle::ManiacBattleHookType, std::tuple<int, int>> Game_Interpreter_Battle::maniac_hooks;

void Game_Interpreter_Battle::InitBattle() {
if (Player::IsPatchManiac()) {
Game_Interpreter_Battle::maniac_hooks = {
{Game_Interpreter_Battle::ManiacBattleHookType::AtbIncrement, std::make_tuple(0, 0)},
{Game_Interpreter_Battle::ManiacBattleHookType::DamagePop, std::make_tuple(0, 0)},
{Game_Interpreter_Battle::ManiacBattleHookType::Targetting, std::make_tuple(0, 0)},
{Game_Interpreter_Battle::ManiacBattleHookType::SetState, std::make_tuple(0, 0)},
{Game_Interpreter_Battle::ManiacBattleHookType::StatChange, std::make_tuple(0, 0)}
};
}
}

static const char* target_text[] = { "actor", "party member", "enemy" };

Expand Down
4 changes: 3 additions & 1 deletion src/game_interpreter_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ class Game_Interpreter_Battle : public Game_Interpreter

bool ExecuteCommand(lcf::rpg::EventCommand const& com) override;

static void InitBattle();

/**
* All possible hook type events that maniacs offers.
*/
enum ManiacBattleHookType {
enum class ManiacBattleHookType {
AtbIncrement,
DamagePop,
Targetting,
Expand Down
Loading

0 comments on commit 8c68f35

Please sign in to comment.