Skip to content

Commit

Permalink
Use enum values for subcommand idx values
Browse files Browse the repository at this point in the history
  • Loading branch information
mateofio committed Sep 3, 2019
1 parent eecb17b commit ce06c7d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
bool Game_Interpreter::to_title = false;
bool Game_Interpreter::exit_game = false;

enum BranchSubcommand {
eOptionBranchElse = 1
};

constexpr int Game_Interpreter::loop_limit;
constexpr int Game_Interpreter::call_stack_limit;
Expand Down Expand Up @@ -2981,7 +2984,7 @@ bool Game_Interpreter::CommandConditionalBranch(RPG::EventCommand const& com) {

int sub_idx = subcommand_sentinel;
if (!result) {
sub_idx = 1;
sub_idx = eOptionBranchElse;
SkipToNextConditional({Cmd::ElseBranch, Cmd::EndBranch}, com.indent);
}

Expand All @@ -2991,7 +2994,7 @@ bool Game_Interpreter::CommandConditionalBranch(RPG::EventCommand const& com) {


bool Game_Interpreter::CommandElseBranch(RPG::EventCommand const& com) { //code 22010
return CommandOptionGeneric(com, 1, {Cmd::EndBranch});
return CommandOptionGeneric(com, eOptionBranchElse, {Cmd::EndBranch});
}

bool Game_Interpreter::CommandEndBranch(RPG::EventCommand const& com) { //code 22011
Expand Down
8 changes: 6 additions & 2 deletions src/game_interpreter_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "spriteset_battle.h"
#include <cassert>

enum BranchBattleSubcommand {
eOptionBranchBattleElse = 1
};

Game_Interpreter_Battle::Game_Interpreter_Battle()
: Game_Interpreter(true) {}

Expand Down Expand Up @@ -397,7 +401,7 @@ bool Game_Interpreter_Battle::CommandConditionalBranchBattle(RPG::EventCommand c

int sub_idx = subcommand_sentinel;
if (!result) {
sub_idx = 1;
sub_idx = eOptionBranchBattleElse;
SkipToNextConditional({Cmd::ElseBranch_B, Cmd::EndBranch_B}, com.indent);
}

Expand All @@ -406,7 +410,7 @@ bool Game_Interpreter_Battle::CommandConditionalBranchBattle(RPG::EventCommand c
}

bool Game_Interpreter_Battle::CommandElseBranchBattle(RPG::EventCommand const& com) { //code 23310
return CommandOptionGeneric(com, 1, {Cmd::EndBranch_B});
return CommandOptionGeneric(com, eOptionBranchBattleElse, {Cmd::EndBranch_B});
}

bool Game_Interpreter_Battle::CommandEndBranchBattle(RPG::EventCommand const& com) { //code 23311
Expand Down
40 changes: 28 additions & 12 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
#include "game_interpreter_map.h"
#include "reader_lcf.h"

enum EnemyEncounterSubcommand {
eOptionEnemyEncounterVictory = 0,
eOptionEnemyEncounterEscape = 1,
eOptionEnemyEncounterDefeat = 2,
};

enum ShopSubcommand {
eOptionShopTransaction = 0,
eOptionShopNoTransaction = 1,
};

enum InnSubcommand {
eOptionInnStay = 0,
eOptionInnNoStay = 1,
};

void Game_Interpreter_Map::SetState(const RPG::SaveEventExecState& save) {
Clear();
_state = save;
Expand Down Expand Up @@ -230,19 +246,19 @@ bool Game_Interpreter_Map::ContinuationEnemyEncounter(RPG::EventCommand const& c
int sub_idx = subcommand_sentinel;

if (Game_Temp::battle_result == Game_Temp::BattleVictory) {
sub_idx = 0;
sub_idx = eOptionEnemyEncounterVictory;
}

if (Game_Temp::battle_result == Game_Temp::BattleEscape) {
sub_idx = 1;
sub_idx = eOptionEnemyEncounterEscape;
//FIXME: subidx set before this anyway??
if (Game_Temp::battle_escape_mode == 1) {
return CommandEndEventProcessing(com);
}
}

if (Game_Temp::battle_result == Game_Temp::BattleDefeat) {
sub_idx = 2;
sub_idx = eOptionEnemyEncounterDefeat;
//FIXME: subidx set before this anyway??
if (Game_Temp::battle_defeat_mode == 0) {
return CommandGameOver(com);
Expand All @@ -255,15 +271,15 @@ bool Game_Interpreter_Map::ContinuationEnemyEncounter(RPG::EventCommand const& c
}

bool Game_Interpreter_Map::CommandVictoryHandler(RPG::EventCommand const& com) { // code 20710
return CommandOptionGeneric(com, 0, {Cmd::EscapeHandler, Cmd::DefeatHandler, Cmd::EndBattle});
return CommandOptionGeneric(com, eOptionEnemyEncounterVictory, {Cmd::EscapeHandler, Cmd::DefeatHandler, Cmd::EndBattle});
}

bool Game_Interpreter_Map::CommandEscapeHandler(RPG::EventCommand const& com) { // code 20711
return CommandOptionGeneric(com, 1, {Cmd::DefeatHandler, Cmd::EndBattle});
return CommandOptionGeneric(com, eOptionEnemyEncounterEscape, {Cmd::DefeatHandler, Cmd::EndBattle});
}

bool Game_Interpreter_Map::CommandDefeatHandler(RPG::EventCommand const& com) { // code 20712
return CommandOptionGeneric(com, 2, {Cmd::EndBattle});
return CommandOptionGeneric(com, eOptionEnemyEncounterDefeat, {Cmd::EndBattle});
}

bool Game_Interpreter_Map::CommandEndBattle(RPG::EventCommand const& com) { // code 20713
Expand Down Expand Up @@ -323,19 +339,19 @@ bool Game_Interpreter_Map::ContinuationOpenShop(RPG::EventCommand const& com) {

continuation = nullptr;

int sub_idx = Game_Temp::shop_transaction ? 0 : 1;
int sub_idx = Game_Temp::shop_transaction ? eOptionShopTransaction : eOptionShopNoTransaction;

SetSubcommandIndex(com.indent, sub_idx);

return true;
}

bool Game_Interpreter_Map::CommandTransaction(RPG::EventCommand const& com) { // code 20720
return CommandOptionGeneric(com, 0, {Cmd::NoTransaction, Cmd::EndShop});
return CommandOptionGeneric(com, eOptionShopTransaction, {Cmd::NoTransaction, Cmd::EndShop});
}

bool Game_Interpreter_Map::CommandNoTransaction(RPG::EventCommand const& com) { // code 20721
return CommandOptionGeneric(com, 1, {Cmd::EndShop});
return CommandOptionGeneric(com, eOptionShopNoTransaction, {Cmd::EndShop});
}

bool Game_Interpreter_Map::CommandEndShop(RPG::EventCommand const& com) { // code 20722
Expand Down Expand Up @@ -463,7 +479,7 @@ bool Game_Interpreter_Map::ContinuationShowInnStart(RPG::EventCommand const& com

bool inn_stay = Game_Message::choice_result == 0;

SetSubcommandIndex(com.indent, inn_stay ? 0 : 1);
SetSubcommandIndex(com.indent, inn_stay ? eOptionInnStay : eOptionInnNoStay);

Game_Temp::inn_calling = false;

Expand Down Expand Up @@ -529,11 +545,11 @@ bool Game_Interpreter_Map::ContinuationShowInnFinish(RPG::EventCommand const& co
}

bool Game_Interpreter_Map::CommandStay(RPG::EventCommand const& com) { // code 20730
return CommandOptionGeneric(com, 0, {Cmd::NoStay, Cmd::EndInn});
return CommandOptionGeneric(com, eOptionInnStay, {Cmd::NoStay, Cmd::EndInn});
}

bool Game_Interpreter_Map::CommandNoStay(RPG::EventCommand const& com) { // code 20731
return CommandOptionGeneric(com, 1, {Cmd::EndInn});
return CommandOptionGeneric(com, eOptionInnNoStay, {Cmd::EndInn});
}

bool Game_Interpreter_Map::CommandEndInn(RPG::EventCommand const& com) { // code 20732
Expand Down

0 comments on commit ce06c7d

Please sign in to comment.