Skip to content

Commit

Permalink
Immediately start call command when called by an EventCommand.
Browse files Browse the repository at this point in the history
Fixes: EasyRPG#1559

Problem: In RPG_RT, when a call menu/shop/etc or battle is done by an eventcommand, it is called inmediately regardless of whether the player is still moving. In EasyRPG, it waits until it's over.

Solution: Add a Game_Temp::inmediate_call that is activated when an EventCommand is called. Then, put as a condition in Scene_Map to check the calls if it's active, and disable it in DisableCalls.
  • Loading branch information
Albeleon authored and fmatthew5876 committed Dec 14, 2018
1 parent 8a31e2d commit 02e02be
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
23 changes: 22 additions & 1 deletion src/game_interpreter_map.cpp
Expand Up @@ -49,9 +49,11 @@

Game_Interpreter_Map::Game_Interpreter_Map(int depth, bool main_flag) :
Game_Interpreter(depth, main_flag) {
ResetImmediateCalling();
}

bool Game_Interpreter_Map::SetupFromSave(const std::vector<RPG::SaveEventCommands>& save, int _index) {
ResetImmediateCalling();
if (_index < (int)save.size()) {
event_id = save[_index].event_id;
if (event_id != 0) {
Expand Down Expand Up @@ -706,7 +708,7 @@ bool Game_Interpreter_Map::CommandOpenSaveMenu(RPG::EventCommand const& /* com *
}

bool Game_Interpreter_Map::CommandOpenMainMenu(RPG::EventCommand const& /* com */) { // code 11950
Game_Temp::menu_calling = true;
Game_Temp::menu_calling_immediate = true;
SetContinuation(&Game_Interpreter::DefaultContinuation);
return false;
}
Expand All @@ -720,3 +722,22 @@ bool Game_Interpreter_Map::CommandToggleAtbMode(RPG::EventCommand const& /* com
Main_Data::game_data.system.atb_mode = !Main_Data::game_data.system.atb_mode;
return true;
}

void Game_Interpreter_Map::ResetImmediateCalling() {
Game_Temp::load_calling = false;
Game_Temp::save_calling = false;
Game_Temp::name_calling = false;
Game_Temp::shop_calling = false;
Game_Temp::battle_calling = false;
Game_Temp::menu_calling_immediate = false;
}


bool Game_Interpreter_Map::IsImmediateCall() const {
return Game_Temp::load_calling
|| Game_Temp::save_calling
|| Game_Temp::name_calling
|| Game_Temp::shop_calling
|| Game_Temp::battle_calling
|| Game_Temp::menu_calling_immediate;
};
10 changes: 10 additions & 0 deletions src/game_interpreter_map.h
Expand Up @@ -57,6 +57,16 @@ class Game_Interpreter_Map : public Game_Interpreter

bool ExecuteCommand() override;

/**
* @return true if an immediate call is requested
*/
bool IsImmediateCall() const;

/**
* Reset the immediate calling flags
*/
void ResetImmediateCalling();

private:
bool CommandRecallToLocation(RPG::EventCommand const& com);
bool CommandEnemyEncounter(RPG::EventCommand const& com);
Expand Down
2 changes: 1 addition & 1 deletion src/game_map.cpp
Expand Up @@ -359,7 +359,7 @@ void Game_Map::Refresh() {
refresh_type = Refresh_None;
}

Game_Interpreter& Game_Map::GetInterpreter() {
Game_Interpreter_Map& Game_Map::GetInterpreter() {
assert(interpreter);
return *interpreter;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_map.h
Expand Up @@ -446,7 +446,7 @@ namespace Game_Map {
*
* @return the game interpreter.
*/
Game_Interpreter& GetInterpreter();
Game_Interpreter_Map& GetInterpreter();

/**
* Destroy an interpreter after all events and common events have been updated.
Expand Down
2 changes: 2 additions & 0 deletions src/game_temp.cpp
Expand Up @@ -20,6 +20,7 @@
#include "transition.h"

bool Game_Temp::menu_calling;
bool Game_Temp::menu_calling_immediate;
bool Game_Temp::battle_calling;
bool Game_Temp::shop_calling;
bool Game_Temp::inn_calling;
Expand Down Expand Up @@ -55,6 +56,7 @@ bool Game_Temp::restart_title_cache;

void Game_Temp::Init() {
menu_calling = false;
menu_calling_immediate = false;
battle_calling = false;
shop_calling = false;
inn_calling = false;
Expand Down
1 change: 1 addition & 0 deletions src/game_temp.h
Expand Up @@ -34,6 +34,7 @@ class Game_Temp {
static void Init();

static bool menu_calling;
static bool menu_calling_immediate;

static bool battle_calling;
static bool shop_calling;
Expand Down
14 changes: 8 additions & 6 deletions src/scene_map.cpp
Expand Up @@ -189,34 +189,40 @@ void Scene_Map::Update() {
}
}

if (!Main_Data::game_player->IsMoving()) {
if (Game_Temp::menu_calling) {
if (!Main_Data::game_player->IsMoving() || Game_Map::GetInterpreter().IsImmediateCall()) {
if (Game_Temp::menu_calling || Game_Temp::menu_calling_immediate) {
CallMenu();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}

if (Game_Temp::name_calling) {
CallName();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}

if (Game_Temp::shop_calling) {
CallShop();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}

if (Game_Temp::save_calling) {
CallSave();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}

if (Game_Temp::load_calling) {
CallLoad();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}

if (Game_Temp::battle_calling) {
CallBattle();
Game_Map::GetInterpreter().ResetImmediateCalling();
return;
}
}
Expand Down Expand Up @@ -260,14 +266,12 @@ void Scene_Map::CallBattle() {
}

void Scene_Map::CallShop() {
Game_Temp::shop_calling = false;
Game_Temp::transition_menu = true;

Scene::Push(std::make_shared<Scene_Shop>());
}

void Scene_Map::CallName() {
Game_Temp::name_calling = false;
Game_Temp::transition_menu = true;

Scene::Push(std::make_shared<Scene_Name>());
Expand All @@ -291,14 +295,12 @@ void Scene_Map::CallMenu() {
}

void Scene_Map::CallSave() {
Game_Temp::save_calling = false;
Game_Temp::transition_menu = true;

Scene::Push(std::make_shared<Scene_Save>());
}

void Scene_Map::CallLoad() {
Game_Temp::load_calling = false;
Game_Temp::transition_menu = true;

Scene::Push(std::make_shared<Scene_Load>());
Expand Down

0 comments on commit 02e02be

Please sign in to comment.