1 //////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2011 by The Allacrost Project 3 // Copyright (C) 2012-2016 by Bertram (Valyria Tear) 4 // All Rights Reserved 5 // 6 // This code is licensed under the GNU GPL version 2. It is free software and 7 // you may modify it and/or redistribute it under the terms of this license. 8 // See https://www.gnu.org/copyleft/gpl.html for details. 9 //////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef __BATTLE_COMMAND_SUPERVISOR_HEADER__ 12 #define __BATTLE_COMMAND_SUPERVISOR_HEADER__ 13 14 #include "command_settings.h" 15 16 #include "modes/battle/battle_item.h" 17 18 #include "item_command.h" 19 #include "skill_command.h" 20 21 namespace vt_battle 22 { 23 24 namespace private_battle 25 { 26 27 class BattleCharacter; 28 29 //! \brief Enums for the various states that the CommandSupervisor class may be in 30 enum COMMAND_STATE { 31 COMMAND_STATE_INVALID = -1, 32 //! Player is selecting the type of action to execute 33 COMMAND_STATE_CATEGORY = 0, 34 //! Player is selecting from a list of actions to execute 35 COMMAND_STATE_ACTION = 1, 36 //! Player is selecting the actor target to execute the action on 37 COMMAND_STATE_ACTOR = 2, 38 //! Player is selecting the point target to execute the action on 39 COMMAND_STATE_POINT = 3, 40 COMMAND_STATE_TOTAL = 4 41 }; 42 43 /** **************************************************************************** 44 *** \brief Manages input and display to allow the player to select commands for their characters 45 *** 46 *** This class is somewhat of an extension to the BattleMode class. It takes effect whenever a 47 *** character in the battle enters the command state, which in turn causes BattleMode to enter the 48 *** command state and initialize this class. The contents of the command supervisor are drawn to a 49 *** medium-size window in the lower right corner of the screen. The standard flow of this class 50 *** proceeds as follows. 51 *** 52 *** -# Class is initialized with a character that has entered the command state 53 *** -# The player selects an action category for the character 54 *** -# The player selects an action for the character, which may be to execute a skill or use an item 55 *** -# The player selects a target for the action, finalizing the command 56 *** 57 *** The player may backtrack through this flow of events and change their previous selections. 58 *** 59 *** This class also enables cursor memory on a per-character basis. It does this by retaining an instance 60 *** of CharacterCommandSettings for each character. These objects retain all the previous selections 61 *** for the characters, as well as containing the option boxes for the attack, defense, and support 62 *** skills of the characters. 63 *** 64 *** The ItemCommand and SkillCommand classes are assistants to this class, and this class creates an 65 *** instance of each type. Sometimes this class will receive notification messages to indicate when 66 *** certain events occur while the command supervisor is active. For example, if the character that 67 *** the player is selecting a command for is killed, this class will have to abort its operation. 68 *** Another example would be when another character has not used an item that they had intended to 69 *** (either due to that character's death or being unable to find a valid target). In this situation, 70 *** the item list needs to be updated to reflect the newly available item. Notifications are sent to 71 *** this class by BattleMode, and it may pass on some notifacations to the ItemCommand and SkillCommand 72 *** class where appropriate. 73 *** ***************************************************************************/ 74 class CommandSupervisor 75 { 76 public: 77 CommandSupervisor(); 78 79 ~CommandSupervisor(); 80 81 /** \brief Builds all of the varous command menus and prepares them for use 82 *** This should only be invoked once after the BattleMode class has initialized all of its 83 *** character actors. It will create a command menu for the list of usable items as well as 84 *** the various skill menus for each character in the party. 85 **/ 86 void ConstructMenus(); 87 88 /** \brief Resets the command supervisor state and members 89 *** \param character A pointer to the character that the player should select a command for 90 **/ 91 void Initialize(BattleCharacter *character); 92 93 //! \brief Returns a pointer to the character that the player is selecting a command for GetCommandCharacter()94 BattleCharacter *GetCommandCharacter() const { 95 if(_active_settings == nullptr) return nullptr; 96 else return _active_settings->GetCharacter(); 97 } 98 99 //! \brief Updates the state of the command selection 100 void Update(); 101 102 //! \brief Draws the command window and contents to the screen 103 void Draw(); 104 105 /** \brief Called whenever an actor dies while the command supervisor is active 106 *** \param actor A pointer to the actor who is now deceased 107 *** 108 *** If the actor who died is the active character that the player is selecting an action for, this 109 *** will cause the supervisor to return to the invalid state. If the actor who died is the selected 110 *** target, the next available valid target will be selected instead. 111 **/ 112 void NotifyActorDeath(private_battle::BattleActor *actor); 113 114 /** \brief Cancels the current command 115 *** 116 *** This function cancels the command without checking whether the battle 117 *** is in WAIT, SEMI-ACTIVE or ACTIVE mode. If this check is desired, it 118 *** must be done by the caller. 119 **/ 120 void CancelCurrentCommand(); 121 122 //! \name Class member accessor methods 123 //@{ GetState()124 COMMAND_STATE GetState() const { 125 return _state; 126 } 127 GetSelectedTarget()128 BattleTarget GetSelectedTarget() const { 129 return _selected_target; 130 } 131 132 /** \brief Apply battle items count on inventory items. 133 *** This will have to be called upon victory. 134 **/ CommitChangesToInventory()135 void CommitChangesToInventory() { 136 _item_command.CommitChangesToInventory(); 137 } 138 139 //! \brief Reset the item list content, used at battle restart ResetItemList()140 void ResetItemList() { 141 _item_command.ResetItemList(); 142 } 143 //@} 144 145 private: 146 //! \brief The state that the action window is in, which reflects the contents of the window 147 COMMAND_STATE _state; 148 149 //! \brief A pointer to the settings for the active character 150 CommandSettings* _active_settings; 151 152 //! \brief A pointer to the skill that is currently selected, if any 153 vt_global::GlobalSkill* _selected_skill; 154 155 //! \brief A pointer to the item that is currently selected, if any 156 std::shared_ptr<BattleItem> _selected_item; 157 158 //! \brief Retains the target that the player has selected 159 BattleTarget _selected_target; 160 161 //! \brief An instance for managing the character party's inventory 162 ItemCommand _item_command; 163 164 //! \brief An instance for managing the skills of the active character 165 SkillCommand _skill_command; 166 167 //! \brief A container of setting objects for each character in the battle 168 std::map<BattleCharacter *, CommandSettings> _character_settings; 169 170 // ---------- Graphics and GUI members 171 172 //! \brief Contains the icon images that represent each action category 173 std::vector<vt_video::StillImage> _category_icons; 174 175 //! \brief Contains the text that represent each action category 176 std::vector<vt_video::TextImage> _category_text; 177 178 //! \brief The window where all actions are drawn 179 vt_gui::MenuWindow _command_window; 180 181 //! \brief Header text 182 vt_video::TextImage _window_header; 183 184 //! \brief Rendered text that contains information about the currently selected target 185 vt_video::TextImage _selected_target_name; 186 187 //! \brief The current actor status effects. 188 std::vector<vt_video::StillImage*> _selected_target_status_effects; 189 190 //! \brief The status effects applied with a chance when aiming a body part. 191 std::vector<vt_video::StillImage*> _selected_attack_point_status_effects; 192 193 //! \brief The window where all information about the currently selected action is drawn 194 vt_gui::MenuWindow _info_window; 195 196 //! \brief Info text header 197 vt_video::TextImage _info_header; 198 199 //! \brief Info text text 200 vt_video::TextImage _info_text; 201 202 /** \brief The option box that lists the types of actions that a character may take in battle 203 *** Typically this list includes "attack", "defend", "support", and "item". More types may appear 204 *** under special circumstances and conditions. 205 **/ 206 vt_gui::OptionBox _category_options; 207 208 /** \brief Contains a list of the possible targets that a player may select from 209 *** 210 *** This option box is used for the selection of both actors and attack points. 211 **/ 212 vt_gui::OptionBox _target_options; 213 214 //! \brief Stores whether the information window should be shown 215 bool _show_information; 216 217 // ---------- Private methods 218 219 //! \brief Returns true if the selected action category is a skill action 220 bool _IsSkillCategorySelected() const; 221 222 //! \brief Returns true if the selected action category is an item action 223 bool _IsItemCategorySelected() const; 224 225 //! \brief Returns the type of target for the selected action 226 vt_global::GLOBAL_TARGET _ActionTargetType(); 227 228 //! \brief Returns true if the character parameter has already had a settings instance created for it _HasCharacterSettings(BattleCharacter * character)229 bool _HasCharacterSettings(BattleCharacter *character) const { 230 if(character == nullptr) return false; 231 else return (_character_settings.find(character) != _character_settings.end()); 232 } 233 234 /** \brief Creates and stores a CharacterCommandSettings instance for a given character 235 *** \param character A pointer to the character to create the command settings for 236 *** \note This function will not check whether or not an instance of CharacterCommandSettings has 237 *** already been created for this character. That check should be done externally to this function 238 *** call. 239 **/ _CreateCharacterSettings(BattleCharacter * character)240 void _CreateCharacterSettings(BattleCharacter *character) { 241 _character_settings.insert(std::make_pair(character, CommandSettings(character, _command_window))); 242 } 243 244 //! \brief Initializes the _selected_target member with an initial target for the currently selected action 245 bool _SetInitialTarget(); 246 247 /** \brief Changes the active command state and performs any necessary state transactions 248 *** \param new_state The state to change to 249 **/ 250 void _ChangeState(COMMAND_STATE new_state); 251 252 //! \brief Updates state when the player is selecting an action category 253 void _UpdateCategory(); 254 255 //! \brief Updates state when the player is selecting an action 256 void _UpdateAction(); 257 258 //! \brief Updates state when the player is selecting an actor target 259 void _UpdateActorTarget(); 260 261 //! \brief Updates state when the player is selecting an attack point target 262 void _UpdateAttackPointTarget(); 263 264 //! \brief Updates current skill/item information data 265 void _UpdateActionInformation(); 266 267 //! \brief Draws visible contents to the screen when the player is selecting an action category 268 void _DrawCategory(); 269 270 //! \brief Draws visible contents to the screen when the player is selecting an action 271 void _DrawAction(); 272 273 //! \brief Draws visible contents to the screen when the player is selecting an actor target 274 void _DrawActorTarget(); 275 276 //! \brief Draws visible contents to the screen when the player is selecting an attack point target 277 void _DrawAttackPointTarget(); 278 279 //! \brief Draws visible contents to the screen when the player is viewing information about an action 280 void _DrawActionInformation(); 281 282 //! \brief Updates the text for _window_header and _selected_target_name to represent information about the selected target 283 void _UpdateActorTargetText(); 284 285 //! \brief Sets the text for _window_header and _target_options to represent information about the selected target. 286 //! Should be called only when switching to displaying attack points. 287 void _CreateAttackPointTargetText(); 288 289 //! \brief Finalizes the player's command of the character by creating the appropriate action 290 void _FinalizeCommand(); 291 }; 292 293 } // namespace private_battle 294 295 } // namespace vt_battle 296 297 #endif // __BATTLE_COMMAND_SUPERVISOR_HEADER__ 298