Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ inline void Game_Interpreter::Push(Game_Event* ev, const lcf::rpg::EventPage* pa
template<InterpreterExecutionType type_ex>
inline void Game_Interpreter::Push(Game_CommonEvent* ev) {
static_assert(type_ex == InterpreterExecutionType::AutoStart || type_ex == InterpreterExecutionType::Parallel
|| type_ex == InterpreterExecutionType::BattleStart || type_ex == InterpreterExecutionType::BattleParallel
|| type_ex == InterpreterExecutionType::Call || type_ex == InterpreterExecutionType::DeathHandler
|| type_ex == InterpreterExecutionType::DebugCall || type_ex == InterpreterExecutionType::ManiacHook, "Unexpected ExecutionType for CommonEvent"
);
Expand Down
30 changes: 30 additions & 0 deletions src/scene_battle_rpg2k3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
#include "game_party.h"
#include "game_enemy.h"
#include "game_enemyparty.h"
#include "game_map.h"
#include "game_message.h"
#include "game_battle.h"
#include "game_interpreter_battle.h"
#include "game_battlealgorithm.h"
#include "game_screen.h"
#include "game_switches.h"
#include <lcf/reader_util.h>
#include "scene_gameover.h"
#include "utils.h"
Expand Down Expand Up @@ -972,6 +974,16 @@ void Scene_Battle_Rpg2k3::vUpdate() {
break;
}

if (state != State_Victory && state != State_Defeat) {
parallel_interpreter.Update();
if (!parallel_interpreter.IsRunning()) {
for (auto common_event : battle_parallel_events)
{
parallel_interpreter.Push<InterpreterExecutionType::BattleParallel>(common_event);
}
}
}

// this is checked separately because we want normal events to be processed
// just not sub-events called by maniacs battle hooks.
if (state != State_Victory && state != State_Defeat && Game_Battle::ManiacProcessSubEvents()) {
Expand Down Expand Up @@ -1114,6 +1126,23 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneAction()
return SceneActionReturn::eWaitTillNextFrame;
}

void Scene_Battle_Rpg2k3::CallBattleBeginCommonEvents() {
for (auto data_common_event : lcf::Data::commonevents) {
if ((!data_common_event.switch_flag || Main_Data::game_switches->Get(data_common_event.switch_id))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: condition could be inverted to reduce indenting:

Suggested change
if ((!data_common_event.switch_flag || Main_Data::game_switches->Get(data_common_event.switch_id))) {
if (data_common_event.switch_flag && !Main_Data::game_switches->Get(data_common_event.switch_id)) continue;

if (data_common_event.trigger == data_common_event.Trigger_maniac_battle_start) {
Game_CommonEvent* common_event = lcf::ReaderUtil::GetElement(Game_Map::GetCommonEvents(), data_common_event.ID);

Game_Battle::GetInterpreterBattle().Push<InterpreterExecutionType::BattleParallel>(common_event);
}
else if (data_common_event.trigger == data_common_event.Trigger_maniac_battle_parallel) {
Game_CommonEvent* common_event = lcf::ReaderUtil::GetElement(Game_Map::GetCommonEvents(), data_common_event.ID);

battle_parallel_events.push_back(common_event);
}
}
}
}

Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionStart() {
enum SubState {
eStartMessage,
Expand Down Expand Up @@ -1153,6 +1182,7 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionSt
EndNotification();
UpdateEnemiesDirection();
UpdateActorsDirection();
CallBattleBeginCommonEvents();
SetSceneActionSubState(eUpdateEvents);
return SceneActionReturn::eContinueThisFrame;
}
Expand Down
5 changes: 5 additions & 0 deletions src/scene_battle_rpg2k3.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle {
void SetSceneActionSubState(int substate);
void ReturnToMainBattleState();

void CallBattleBeginCommonEvents();

// SceneAction State Machine Driver
SceneActionReturn ProcessSceneAction();

Expand Down Expand Up @@ -260,6 +262,9 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle {
int GetNextReadyActor();

std::vector<int> atb_order;

std::vector<Game_CommonEvent*> battle_parallel_events;
Game_Interpreter_Battle parallel_interpreter;
};

#endif
Loading