Skip to content

Commit 3bd1298

Browse files
authored
Merge pull request #3295 from MakoInfused/ManiacControlBattle
Implement Maniacs Command 3009: ControlBattle
2 parents 6a45364 + ed6e15b commit 3bd1298

14 files changed

+513
-11
lines changed

src/game_battle.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,28 @@ void Game_Battle::UpdateAtbGauges() {
219219
const auto multiplier = std::max(1.0, static_cast<double>(275000 - cur_atb) / 55000.0);
220220
increment = Utils::RoundTo<int>(multiplier * increment);
221221
}
222+
223+
ManiacBattleHook(
224+
Game_Interpreter_Battle::ManiacBattleHookType::AtbIncrement,
225+
bat->GetType() == Game_Battler::Type_Enemy,
226+
bat->GetPartyIndex(),
227+
bat->GetAtbGauge(),
228+
increment
229+
);
230+
222231
bat->IncrementAtbGauge(increment);
223232
}
224233
}
225234
}
226235

236+
bool Game_Battle::ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4, int var5, int var6) {
237+
return interpreter->ManiacBattleHook(hook_type, var1, var2, var3, var4, var5, var6);
238+
}
239+
240+
bool Game_Battle::ManiacProcessSubEvents() {
241+
return interpreter->ProcessManiacSubEvents();
242+
}
243+
227244
void Game_Battle::ChangeBackground(const std::string& name) {
228245
background_name = name;
229246
}

src/game_battle.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <lcf/rpg/system.h>
2424
#include <lcf/rpg/troop.h>
2525
#include "teleport_target.h"
26+
#include "game_interpreter_battle.h"
2627
#include "utils.h"
2728
#include "point.h"
2829

@@ -109,6 +110,15 @@ namespace Game_Battle {
109110
*/
110111
void UpdateAtbGauges();
111112

113+
/**
114+
* Convenience function to call a maniacs battle hook, which processes sub-events at any time.
115+
*/
116+
bool ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4 = 0, int var5 = 0, int var6 = 0);
117+
/**
118+
* Convenience function to process all maniacs sub-events, and return whether they're currently running
119+
*/
120+
bool ManiacProcessSubEvents();
121+
112122
void ChangeBackground(const std::string& name);
113123

114124
const std::string& GetBackground();

src/game_battlealgorithm.cpp

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ Game_BattleAlgorithm::AlgorithmBase::AlgorithmBase(Type ty, Game_Battler* source
8888
party_target = target;
8989
}
9090

91+
int Game_BattleAlgorithm::AlgorithmBase::GetActionType() {
92+
return -1;
93+
}
94+
95+
int Game_BattleAlgorithm::AlgorithmBase::GetActionId() {
96+
return -1;
97+
}
98+
9199
void Game_BattleAlgorithm::AlgorithmBase::Reset() {
92100
hp = 0;
93101
sp = 0;
@@ -185,7 +193,20 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpEffect() {
185193
// Only absorb the sp that were left
186194
source->ChangeSp(-sp);
187195
}
196+
197+
if (Player::IsPatchManiac()) {
198+
Game_Battle::ManiacBattleHook(
199+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
200+
target->GetType() == Game_Battler::Type_Enemy,
201+
target->GetPartyIndex(),
202+
target->GetDisplayX(),
203+
target->GetDisplayY(),
204+
3,
205+
sp
206+
);
207+
}
188208
}
209+
189210
return sp;
190211
}
191212

@@ -198,6 +219,18 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAtkEffect() {
198219
if (IsAbsorbAtk()) {
199220
source->ChangeAtkModifier(-atk);
200221
}
222+
223+
if (Player::IsPatchManiac()) {
224+
Game_Battle::ManiacBattleHook(
225+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
226+
target->GetType() == Game_Battler::Type_Enemy,
227+
target->GetPartyIndex(),
228+
target->GetDisplayX(),
229+
target->GetDisplayY(),
230+
4,
231+
atk
232+
);
233+
}
201234
}
202235
return atk;
203236
}
@@ -211,6 +244,18 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyDefEffect() {
211244
if (IsAbsorbDef()) {
212245
source->ChangeDefModifier(-def);
213246
}
247+
248+
if (Player::IsPatchManiac()) {
249+
Game_Battle::ManiacBattleHook(
250+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
251+
target->GetType() == Game_Battler::Type_Enemy,
252+
target->GetPartyIndex(),
253+
target->GetDisplayX(),
254+
target->GetDisplayY(),
255+
5,
256+
def
257+
);
258+
}
214259
}
215260
return def;
216261
}
@@ -224,6 +269,18 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpiEffect() {
224269
if (IsAbsorbSpi()) {
225270
source->ChangeSpiModifier(-spi);
226271
}
272+
273+
if (Player::IsPatchManiac()) {
274+
Game_Battle::ManiacBattleHook(
275+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
276+
target->GetType() == Game_Battler::Type_Enemy,
277+
target->GetPartyIndex(),
278+
target->GetDisplayX(),
279+
target->GetDisplayY(),
280+
6,
281+
spi
282+
);
283+
}
227284
}
228285
return spi;
229286
}
@@ -237,6 +294,18 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAgiEffect() {
237294
if (IsAbsorbAgi()) {
238295
source->ChangeAgiModifier(-agi);
239296
}
297+
298+
if (Player::IsPatchManiac()) {
299+
Game_Battle::ManiacBattleHook(
300+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
301+
target->GetType() == Game_Battler::Type_Enemy,
302+
target->GetPartyIndex(),
303+
target->GetDisplayX(),
304+
target->GetDisplayY(),
305+
7,
306+
agi
307+
);
308+
}
240309
}
241310
return agi;
242311
}
@@ -532,6 +601,26 @@ AlgorithmBase(Type::None, source, source) {
532601
// no-op
533602
}
534603

604+
int Game_BattleAlgorithm::None::GetActionId() {
605+
return lcf::rpg::EnemyAction::Basic_nothing;
606+
}
607+
608+
int Game_BattleAlgorithm::None::GetActionType() {
609+
return lcf::rpg::EnemyAction::Kind_basic;
610+
}
611+
612+
int Game_BattleAlgorithm::Normal::GetActionId() {
613+
if (IsDualAttack()) {
614+
return lcf::rpg::EnemyAction::Basic_dual_attack;
615+
}
616+
617+
return lcf::rpg::EnemyAction::Basic_attack;
618+
}
619+
620+
int Game_BattleAlgorithm::Normal::GetActionType() {
621+
return lcf::rpg::EnemyAction::Kind_basic;
622+
}
623+
535624
Game_BattleAlgorithm::Normal::Normal(Game_Battler* source, Game_Battler* target, int hits_multiplier, Style style) :
536625
AlgorithmBase(Type::Normal, source, target), hits_multiplier(hits_multiplier)
537626
{
@@ -740,12 +829,16 @@ bool Game_BattleAlgorithm::Normal::vExecute() {
740829
return SetIsSuccess();
741830
}
742831

832+
bool Game_BattleAlgorithm::Normal::IsDualAttack() const {
833+
return GetSource()->GetType() == Game_Battler::Type_Enemy && hits_multiplier == 2;
834+
}
835+
743836
std::string Game_BattleAlgorithm::Normal::GetStartMessage(int line) const {
744837
if (line == 0) {
745838
if (Feature::HasRpg2kBattleSystem()) {
746839
return BattleMessage::GetNormalAttackStartMessage2k(*GetSource());
747840
}
748-
if (GetSource()->GetType() == Game_Battler::Type_Enemy && hits_multiplier == 2) {
841+
if (IsDualAttack()) {
749842
return BattleMessage::GetDoubleAttackStartMessage2k3(*GetSource());
750843
}
751844
}
@@ -849,6 +942,14 @@ Game_BattleAlgorithm::Skill::Skill(Game_Battler* source, const lcf::rpg::Skill&
849942
{
850943
}
851944

945+
int Game_BattleAlgorithm::Skill::GetActionType() {
946+
return lcf::rpg::EnemyAction::Kind_skill;
947+
}
948+
949+
int Game_BattleAlgorithm::Skill::GetActionId() {
950+
return skill.ID;
951+
}
952+
852953
void Game_BattleAlgorithm::Skill::Init() {
853954
}
854955

@@ -1236,6 +1337,14 @@ Game_BattleAlgorithm::Item::Item(Game_Battler* source, Game_Party_Base* target,
12361337
// no-op
12371338
}
12381339

1340+
int Game_BattleAlgorithm::Item::GetActionType() {
1341+
return 3;
1342+
}
1343+
1344+
int Game_BattleAlgorithm::Item::GetActionId() {
1345+
return item.ID;
1346+
}
1347+
12391348
bool Game_BattleAlgorithm::Item::vStart() {
12401349
Main_Data::game_party->ConsumeItemUse(item.ID);
12411350
return true;
@@ -1340,6 +1449,14 @@ Game_BattleAlgorithm::Defend::Defend(Game_Battler* source) :
13401449
source->SetIsDefending(true);
13411450
}
13421451

1452+
int Game_BattleAlgorithm::Defend::GetActionType() {
1453+
return lcf::rpg::EnemyAction::Kind_basic;
1454+
}
1455+
1456+
int Game_BattleAlgorithm::Defend::GetActionId() {
1457+
return lcf::rpg::EnemyAction::Basic_defense;
1458+
}
1459+
13431460
std::string Game_BattleAlgorithm::Defend::GetStartMessage(int line) const {
13441461
if (line == 0) {
13451462
if (Feature::HasRpg2kBattleSystem()) {
@@ -1360,6 +1477,14 @@ AlgorithmBase(Type::Observe, source, source) {
13601477
// no-op
13611478
}
13621479

1480+
int Game_BattleAlgorithm::Observe::GetActionType() {
1481+
return lcf::rpg::EnemyAction::Kind_basic;
1482+
}
1483+
1484+
int Game_BattleAlgorithm::Observe::GetActionId() {
1485+
return lcf::rpg::EnemyAction::Basic_observe;
1486+
}
1487+
13631488
std::string Game_BattleAlgorithm::Observe::GetStartMessage(int line) const {
13641489
if (line == 0) {
13651490
if (Feature::HasRpg2kBattleSystem()) {
@@ -1376,6 +1501,14 @@ AlgorithmBase(Type::Charge, source, source) {
13761501
// no-op
13771502
}
13781503

1504+
int Game_BattleAlgorithm::Charge::GetActionType() {
1505+
return lcf::rpg::EnemyAction::Kind_basic;
1506+
}
1507+
1508+
int Game_BattleAlgorithm::Charge::GetActionId() {
1509+
return lcf::rpg::EnemyAction::Basic_charge;
1510+
}
1511+
13791512
std::string Game_BattleAlgorithm::Charge::GetStartMessage(int line) const {
13801513
if (line == 0) {
13811514
if (Feature::HasRpg2kBattleSystem()) {
@@ -1396,6 +1529,14 @@ AlgorithmBase(Type::SelfDestruct, source, target) {
13961529
// no-op
13971530
}
13981531

1532+
int Game_BattleAlgorithm::SelfDestruct::GetActionType() {
1533+
return lcf::rpg::EnemyAction::Kind_basic;
1534+
}
1535+
1536+
int Game_BattleAlgorithm::SelfDestruct::GetActionId() {
1537+
return lcf::rpg::EnemyAction::Basic_autodestruction;
1538+
}
1539+
13991540
std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage(int line) const {
14001541
if (line == 0) {
14011542
if (Feature::HasRpg2kBattleSystem()) {
@@ -1450,6 +1591,14 @@ Game_BattleAlgorithm::Escape::Escape(Game_Battler* source) :
14501591
// no-op
14511592
}
14521593

1594+
int Game_BattleAlgorithm::Escape::GetActionType() {
1595+
return lcf::rpg::EnemyAction::Kind_basic;
1596+
}
1597+
1598+
int Game_BattleAlgorithm::Escape::GetActionId() {
1599+
return lcf::rpg::EnemyAction::Basic_escape;
1600+
}
1601+
14531602
std::string Game_BattleAlgorithm::Escape::GetStartMessage(int line) const {
14541603
if (line == 0) {
14551604
if (Feature::HasRpg2kBattleSystem()) {
@@ -1487,6 +1636,14 @@ AlgorithmBase(Type::Transform, source, source), new_monster_id(new_monster_id) {
14871636
// no-op
14881637
}
14891638

1639+
int Game_BattleAlgorithm::Transform::GetActionType() {
1640+
return lcf::rpg::EnemyAction::Kind_transformation;
1641+
}
1642+
1643+
int Game_BattleAlgorithm::Transform::GetActionId() {
1644+
return new_monster_id;
1645+
}
1646+
14901647
std::string Game_BattleAlgorithm::Transform::GetStartMessage(int line) const {
14911648
if (line == 0 && Feature::HasRpg2kBattleSystem()) {
14921649
auto* enemy = lcf::ReaderUtil::GetElement(lcf::Data::enemies, new_monster_id);
@@ -1509,3 +1666,11 @@ AlgorithmBase(Type::DoNothing, source, source) {
15091666
// no-op
15101667
}
15111668

1669+
int Game_BattleAlgorithm::DoNothing::GetActionType() {
1670+
return lcf::rpg::EnemyAction::Kind_basic;
1671+
}
1672+
1673+
int Game_BattleAlgorithm::DoNothing::GetActionId() {
1674+
return lcf::rpg::EnemyAction::Basic_nothing;
1675+
}
1676+

0 commit comments

Comments
 (0)