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_SCENE_BATTLE_RPG2K_H 19 #define EP_SCENE_BATTLE_RPG2K_H 20 21 // Headers 22 #include "scene_battle.h" 23 #include "game_enemy.h" 24 25 #include "window_command.h" 26 #include "window_battlemessage.h" 27 #include "game_battlealgorithm.h" 28 29 namespace Game_Message { 30 class PendingMessage; 31 }; 32 33 /** 34 * Scene_Battle class. 35 * Manages the battles. 36 */ 37 class Scene_Battle_Rpg2k : public Scene_Battle { 38 public: 39 /** The return value from a scene action state machine callback */ 40 enum class SceneActionReturn { 41 /** Return from Update() and wait until the next frame */ 42 eWaitTillNextFrame, 43 /** Continue processing this frame, unless CheckWait() etc.. requires us to block */ 44 eContinueThisFrame, 45 }; 46 47 /** The return value from a battle action state machine callback */ 48 enum class BattleActionReturn { 49 /** The battle action is not yet finished */ 50 eContinue, 51 /** The battle action is finished */ 52 eFinished, 53 }; 54 55 enum BattleActionState { 56 /** 57 * Called once 58 * Flashes enemy sprite and handles states. 59 */ 60 BattleActionState_Begin, 61 /** 62 * Called once 63 * Handles the start messages 64 */ 65 BattleActionState_Usage, 66 /** 67 * Called once 68 * Handles the animations 69 */ 70 BattleActionState_Animation, 71 /** 72 * Called once 73 * Handles the animations when skill is reflected (easyrpg extension) 74 */ 75 BattleActionState_AnimationReflect, 76 /** 77 * Called once per target. 78 * Used to execute the algorithm. 79 */ 80 BattleActionState_Execute, 81 /** 82 * Called once per target. 83 * Used to display critical hit message. 84 */ 85 BattleActionState_Critical, 86 /** 87 * Called once per target. 88 * Used to apply the new conditions, play an optional battle animation and sound, and print the second line of a technique. 89 */ 90 BattleActionState_Apply, 91 /** 92 * Called once per target. 93 * Used to handle action failure. 94 */ 95 BattleActionState_Failure, 96 /** 97 * Called once per target. 98 * Used to handle damage. 99 */ 100 BattleActionState_Damage, 101 /** 102 * Called repeatedly. 103 * Used for hp healing, sp, atk, def, api, agi, to push and pop each message. 104 */ 105 BattleActionState_Params, 106 /** 107 * Called repeatedly. 108 * Used for states. 109 */ 110 BattleActionState_States, 111 /** 112 * Called repeatedly. 113 * Used for attribute shifts. 114 */ 115 BattleActionState_Attributes, 116 /** 117 * Called once per target if killed by damage. 118 * Action treating whether the enemy died or not. 119 */ 120 BattleActionState_DeathDamage, 121 /** 122 * Called once per target if killed by a state.. 123 * Action treating whether the enemy died or not. 124 */ 125 BattleActionState_DeathState, 126 /** 127 * Called once per target. 128 * It finishes the action and checks whether to repeat it if there is another target to hit. 129 */ 130 BattleActionState_Finished 131 }; 132 133 public: 134 explicit Scene_Battle_Rpg2k(const BattleArgs& args); 135 ~Scene_Battle_Rpg2k() override; 136 137 void Start() override; 138 void Update() override; 139 140 protected: 141 bool UpdateBattleState(); 142 void SetState(State new_state) override; 143 144 void NextTurn(); 145 146 void CreateUi() override; 147 void CreateEnemySprites(); 148 149 void CreateBattleTargetWindow(); 150 void CreateBattleCommandWindow(); 151 void RefreshTargetWindow(); 152 153 bool CheckBattleEndConditions(); 154 bool RefreshEventsAndCheckBattleEnd(); 155 156 void ResetWindows(bool make_invisible); 157 void SetCommandWindows(int x); 158 void MoveCommandWindows(int x, int frames); 159 void RefreshCommandWindow(); 160 161 void ActionSelectedCallback(Game_Battler* for_battler) override; 162 163 /** 164 * Adds a message about the gold received into 165 * Game_Message::texts. 166 * 167 * @param money Number of gold to display. 168 */ 169 void PushGoldReceivedMessage(PendingMessage& pm, int money); 170 171 /** 172 * Adds a message about the experience received into 173 * Game_Message::texts. 174 * 175 * @param exp Number of experience to display. 176 */ 177 void PushExperienceGainedMessage(PendingMessage& pm, int exp); 178 179 /** 180 * Adds messages about the items obtained after the battle 181 * into Game_Message::texts. 182 * 183 * @param drops Vector of item IDs 184 */ 185 void PushItemRecievedMessages(PendingMessage& pm, std::vector<int> drops); 186 187 void OptionSelected(); 188 void CommandSelected(); 189 190 void SelectNextActor(bool auto_battle); 191 void SelectPreviousActor(); 192 193 void CreateExecutionOrder(); 194 void CreateEnemyActions(); 195 196 void SetSceneActionSubState(int substate); 197 198 // SceneAction State Machine Driver 199 SceneActionReturn ProcessSceneAction(); 200 201 // SceneAction State Machine Handlers 202 SceneActionReturn ProcessSceneActionStart(); 203 SceneActionReturn ProcessSceneActionFightAutoEscape(); 204 SceneActionReturn ProcessSceneActionActor(); 205 SceneActionReturn ProcessSceneActionAutoBattle(); 206 SceneActionReturn ProcessSceneActionCommand(); 207 SceneActionReturn ProcessSceneActionItem(); 208 SceneActionReturn ProcessSceneActionSkill(); 209 SceneActionReturn ProcessSceneActionEnemyTarget(); 210 SceneActionReturn ProcessSceneActionAllyTarget(); 211 SceneActionReturn ProcessSceneActionBattle(); 212 SceneActionReturn ProcessSceneActionVictory(); 213 SceneActionReturn ProcessSceneActionDefeat(); 214 SceneActionReturn ProcessSceneActionEscape(); 215 216 bool CheckBattleEndAndScheduleEvents(); 217 218 void SetBattleActionState(BattleActionState state); 219 void SetBattleActionSubState(int substate, bool reset_index = true); 220 221 // BattleAction State Machine Driver 222 BattleActionReturn ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase* action); 223 224 // BattleAction State Machine Handlers 225 BattleActionReturn ProcessBattleActionBegin(Game_BattleAlgorithm::AlgorithmBase* action); 226 BattleActionReturn ProcessBattleActionUsage(Game_BattleAlgorithm::AlgorithmBase* action); 227 BattleActionReturn ProcessBattleActionAnimation(Game_BattleAlgorithm::AlgorithmBase* action); 228 BattleActionReturn ProcessBattleActionAnimationReflect(Game_BattleAlgorithm::AlgorithmBase* action); 229 BattleActionReturn ProcessBattleActionAnimationImpl(Game_BattleAlgorithm::AlgorithmBase* action, bool reflect); 230 BattleActionReturn ProcessBattleActionExecute(Game_BattleAlgorithm::AlgorithmBase* action); 231 BattleActionReturn ProcessBattleActionCritical(Game_BattleAlgorithm::AlgorithmBase* action); 232 BattleActionReturn ProcessBattleActionApply(Game_BattleAlgorithm::AlgorithmBase* action); 233 BattleActionReturn ProcessBattleActionFailure(Game_BattleAlgorithm::AlgorithmBase* action); 234 BattleActionReturn ProcessBattleActionDamage(Game_BattleAlgorithm::AlgorithmBase* action); 235 BattleActionReturn ProcessBattleActionParamEffects(Game_BattleAlgorithm::AlgorithmBase* action); 236 BattleActionReturn ProcessBattleActionStateEffects(Game_BattleAlgorithm::AlgorithmBase* action); 237 BattleActionReturn ProcessBattleActionAttributeEffects(Game_BattleAlgorithm::AlgorithmBase* action); 238 BattleActionReturn ProcessBattleActionFinished(Game_BattleAlgorithm::AlgorithmBase* action); 239 240 void ProcessBattleActionDeath(Game_BattleAlgorithm::AlgorithmBase* action); 241 242 void SetWait(int min_wait, int max_wait); 243 void SetWaitForUsage(Game_BattleAlgorithm::Type type, int anim_frames); 244 bool CheckWait(); 245 246 std::unique_ptr<Window_BattleMessage> battle_message_window; 247 std::vector<std::string> battle_result_messages; 248 std::vector<std::string>::iterator battle_result_messages_it; 249 std::shared_ptr<Game_BattleAlgorithm::AlgorithmBase> pending_battle_action = {}; 250 int actor_index = 0; 251 int scene_action_substate = 0; 252 int battle_action_state = BattleActionState_Begin; 253 int battle_action_substate = 0; 254 int battle_action_start_index = 0; 255 int battle_action_results_index = 0; 256 int battle_action_dmg_index = 0; 257 std::string pending_message; 258 int battle_action_substate_index = 0; 259 260 int select_target_flash_count = 0; 261 262 int battle_action_wait = 0; 263 int battle_action_min_wait = 0; 264 265 bool message_box_got_visible = false; 266 bool resume_from_debug_scene = false; 267 }; 268 269 #endif 270