1 /*
2  * This file is part of EasyRPG Player.
3  *
4  * EasyRPG Player is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * EasyRPG Player is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef EP_GAME_INTERPRETER_BATTLE_H
19 #define EP_GAME_INTERPRETER_BATTLE_H
20 
21 // Headers
22 #include <map>
23 #include <string>
24 #include <vector>
25 #include <cassert>
26 #include "game_character.h"
27 #include <lcf/rpg/eventcommand.h>
28 #include <lcf/rpg/trooppagecondition.h>
29 #include "system.h"
30 #include "game_interpreter.h"
31 
32 class Game_Event;
33 class Game_CommonEvent;
34 
35 /**
36  * Game_Interpreter_Battle class.
37  */
38 class Game_Interpreter_Battle : public Game_Interpreter
39 {
40 public:
41 	explicit Game_Interpreter_Battle(Span<const lcf::rpg::TroopPage> pages);
42 
43 	int GetNumPages() const;
44 
45 	bool IsValidPage(int page_id) const;
46 	bool HasPageExecuted(int page_id) const;
47 
48 	static bool AreConditionsMet(const lcf::rpg::TroopPageCondition& condition, Game_Battler* source);
49 
50 	int ScheduleNextPage(Game_Battler* source);
51 	int ScheduleNextPage(lcf::rpg::TroopPageCondition::Flags required_conditions, Game_Battler* source);
52 	void ResetPagesExecuted();
53 
54 	void SetCurrentEnemyTargetIndex(int idx);
55 	void SetCurrentActionTargetsSingleEnemy(bool value);
56 	void SetCurrentActingActorId(int id);
57 
58 	bool IsForceFleeEnabled() const;
59 
60 	bool ExecuteCommand() override;
61 private:
62 	bool CommandCallCommonEvent(lcf::rpg::EventCommand const& com);
63 	bool CommandForceFlee(lcf::rpg::EventCommand const& com);
64 	bool CommandEnableCombo(lcf::rpg::EventCommand const& com);
65 	bool CommandChangeMonsterHP(lcf::rpg::EventCommand const& com);
66 	bool CommandChangeMonsterMP(lcf::rpg::EventCommand const& com);
67 	bool CommandChangeMonsterCondition(lcf::rpg::EventCommand const& com);
68 	bool CommandShowHiddenMonster(lcf::rpg::EventCommand const& com);
69 	bool CommandChangeBattleBG(lcf::rpg::EventCommand const& com);
70 	bool CommandShowBattleAnimation(lcf::rpg::EventCommand const& com);
71 	bool CommandTerminateBattle(lcf::rpg::EventCommand const& com);
72 	bool CommandConditionalBranchBattle(lcf::rpg::EventCommand const& com);
73 	bool CommandElseBranchBattle(lcf::rpg::EventCommand const& com);
74 	bool CommandEndBranchBattle(lcf::rpg::EventCommand const& com);
75 
76 	bool CommandManiacControlBattle(lcf::rpg::EventCommand const& com);
77 	bool CommandManiacControlAtbGauge(lcf::rpg::EventCommand const& com);
78 	bool CommandManiacChangeBattleCommandEx(lcf::rpg::EventCommand const& com);
79 	bool CommandManiacGetBattleInfo(lcf::rpg::EventCommand const& com);
80 
81 private:
82 	Span<const lcf::rpg::TroopPage> pages;
83 	std::vector<bool> executed;
84 	int target_enemy_index = -1;
85 	int current_actor_id = 0;
86 	bool targets_single_enemy = false;
87 	bool force_flee_enabled = false;
88 };
89 
GetNumPages()90 inline int Game_Interpreter_Battle::GetNumPages() const {
91 	return static_cast<int>(pages.size());
92 }
93 
IsValidPage(int page_id)94 inline bool Game_Interpreter_Battle::IsValidPage(int page_id) const {
95 	return page_id >= 1 && page_id <= GetNumPages();
96 }
97 
HasPageExecuted(int page_id)98 inline bool Game_Interpreter_Battle::HasPageExecuted(int page_id) const {
99 	assert(IsValidPage(page_id));
100 	return executed[page_id - 1];
101 }
102 
ResetPagesExecuted()103 inline void Game_Interpreter_Battle::ResetPagesExecuted() {
104 	std::fill(executed.begin(), executed.end(), false);
105 }
106 
SetCurrentEnemyTargetIndex(int idx)107 inline void Game_Interpreter_Battle::SetCurrentEnemyTargetIndex(int idx) {
108 	target_enemy_index = idx;
109 }
110 
SetCurrentActionTargetsSingleEnemy(bool value)111 inline void Game_Interpreter_Battle::SetCurrentActionTargetsSingleEnemy(bool value) {
112 	targets_single_enemy = value;
113 }
114 
SetCurrentActingActorId(int id)115 inline void Game_Interpreter_Battle::SetCurrentActingActorId(int id) {
116 	current_actor_id = id;
117 }
118 
IsForceFleeEnabled()119 inline bool Game_Interpreter_Battle::IsForceFleeEnabled() const {
120 	return force_flee_enabled;
121 }
122 
123 #endif
124