Skip to content

Commit

Permalink
Battle: Halt the interpreter when a victory or lose condition is fulf…
Browse files Browse the repository at this point in the history
…illed.

Fixes EasyRPG#1129
  • Loading branch information
Ghabry committed Mar 22, 2017
1 parent 1fa3932 commit 08150d3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/game_battle.cpp
Expand Up @@ -132,6 +132,14 @@ void Game_Battle::Terminate() {
terminate = true;
}

bool Game_Battle::CheckWin() {
return !Main_Data::game_enemyparty->IsAnyActive();
}

bool Game_Battle::CheckLose() {
return !Main_Data::game_party->IsAnyActive();
}

Spriteset_Battle& Game_Battle::GetSpriteset() {
return *spriteset;
}
Expand Down Expand Up @@ -294,6 +302,10 @@ bool Game_Battle::AreConditionsMet(const RPG::TroopPageCondition& condition) {
}

bool Game_Battle::UpdateEvents() {
if (Game_Battle::CheckWin() || Game_Battle::CheckLose()) {
return true;
}

if (interpreter->IsRunning()) {
return false;
}
Expand Down
18 changes: 16 additions & 2 deletions src/game_battle.h
Expand Up @@ -43,6 +43,20 @@ namespace Game_Battle {

void Terminate();

/**
* Checks if a victory condition for the player party (enemy dead) is fulfilled.
*
* @return True on victory
*/
bool CheckWin();

/**
* Check if a lose condition for the player party (party dead) is fulfilled.
*
* @return True on lose
*/
bool CheckLose();

Spriteset_Battle& GetSpriteset();

/**
Expand Down Expand Up @@ -131,13 +145,13 @@ namespace Game_Battle {
void SetBattleMode(int battle_mode_);
int GetBattleMode();

/**
/**
* Sets the party index of the latest targeted enemy. Only used by battle branch "is target"
*
* @param target_enemy id of targeted enemy
*/
void SetEnemyTargetIndex(int target_enemy);

/**
* Gets the party index of the latest targeted enemy. Only used by battle branch "is target"
*
Expand Down
5 changes: 5 additions & 0 deletions src/game_interpreter_battle.cpp
Expand Up @@ -34,6 +34,11 @@ Game_Interpreter_Battle::Game_Interpreter_Battle(int depth, bool main_flag) :

// Execute Command.
bool Game_Interpreter_Battle::ExecuteCommand() {
if (Game_Battle::CheckWin() || Game_Battle::CheckLose()) {
// Interpreter is cancelled when a win/lose condition is fulfilled
return false;
}

if (index >= list.size()) {
return CommandEnd();
}
Expand Down
4 changes: 2 additions & 2 deletions src/scene_battle_rpg2k.cpp
Expand Up @@ -836,7 +836,7 @@ bool Scene_Battle_Rpg2k::DisplayMonstersInMessageWindow() {
}

bool Scene_Battle_Rpg2k::CheckWin() {
if (!Main_Data::game_enemyparty->IsAnyActive()) {
if (Game_Battle::CheckWin()) {
Game_Temp::battle_result = Game_Temp::BattleVictory;
SetState(State_Victory);

Expand Down Expand Up @@ -884,7 +884,7 @@ bool Scene_Battle_Rpg2k::CheckWin() {
}

bool Scene_Battle_Rpg2k::CheckLose() {
if (!Main_Data::game_party->IsAnyActive()) {
if (Game_Battle::CheckLose()) {
Game_Temp::battle_result = Game_Temp::BattleDefeat;
SetState(State_Defeat);

Expand Down
4 changes: 2 additions & 2 deletions src/scene_battle_rpg2k3.cpp
Expand Up @@ -952,7 +952,7 @@ void Scene_Battle_Rpg2k3::Escape() {
}

bool Scene_Battle_Rpg2k3::CheckWin() {
if (!Main_Data::game_enemyparty->IsAnyActive()) {
if (Game_Battle::CheckWin()) {
Game_Temp::battle_result = Game_Temp::BattleVictory;
SetState(State_Victory);

Expand Down Expand Up @@ -1023,7 +1023,7 @@ bool Scene_Battle_Rpg2k3::CheckWin() {
}

bool Scene_Battle_Rpg2k3::CheckLose() {
if (!Main_Data::game_party->IsAnyActive()) {
if (Game_Battle::CheckLose()) {
Game_Temp::battle_result = Game_Temp::BattleDefeat;
SetState(State_Defeat);

Expand Down

0 comments on commit 08150d3

Please sign in to comment.