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_CHARACTER_HEADER__ 12 #define __BATTLE_CHARACTER_HEADER__ 13 14 #include "battle_actor.h" 15 16 namespace vt_global { 17 class GlobalCharacter; 18 } 19 20 namespace vt_battle 21 { 22 23 namespace private_battle 24 { 25 26 /** **************************************************************************** 27 *** \brief Represents a player-controlled character in the battle 28 *** 29 *** Character actors have a series of animated images that reflect their current 30 *** state and actions. Each character also has a custom set of progressive damage 31 *** battle portraits (5 in total) that are drawn when the character is selected. 32 *** ***************************************************************************/ 33 class BattleCharacter : public BattleActor 34 { 35 public: 36 BattleCharacter(vt_global::GlobalCharacter *character); 37 38 ~BattleCharacter(); 39 IsEnemy()40 bool IsEnemy() const { 41 return false; 42 } 43 44 void ChangeState(ACTOR_STATE new_state); 45 GetSpriteWidth()46 float GetSpriteWidth() const { 47 return _current_sprite_animation ? _current_sprite_animation->GetWidth() : 0.0f; 48 } 49 GetSpriteHeight()50 float GetSpriteHeight() const { 51 return _current_sprite_animation ? _current_sprite_animation->GetHeight() : 0.0f; 52 } 53 54 /** \brief Changes the battle character's current sprite animation image 55 *** \param alias The alias text used to identify the animation to change 56 *** 57 *** \note Not all forms of battle sprites have multiple animations or any animations at all. For 58 *** example, enemies typically only have a standard set of unanimated damage frames for their 59 *** sprites. The reason this method is defined for all actors is so that the same skills may be 60 *** reused for both characters and enemies, since some skill implementations will wish to call 61 *** this method on the actor performing the skill. 62 **/ 63 void ChangeSpriteAnimation(const std::string &alias); 64 65 //! \brief Changes the action and target selection text to reflect the character's current state 66 void ChangeActionText(); 67 68 //! \brief Returns true if the player may select a command for the character to execute CanSelectCommand()69 bool CanSelectCommand() const { 70 return (_state == ACTOR_STATE_IDLE) || (_state == ACTOR_STATE_COMMAND); 71 } 72 73 //! \brief Updates the state of the character. Must be called every frame loop. 74 void Update(); 75 76 //! \brief Draws the character's current sprite animation frame 77 void DrawSprite(); 78 79 //! \brief Draws the character's damage-blended face portrait 80 void DrawPortrait(); 81 82 /** \brief Draws the character's status in the bottom area of the screen 83 *** \param order The order position of the character [0-3] used to determine draw positions 84 *** \param character_command Tells which character the command menu is open for, if any. (can be nullptr) 85 **/ 86 void DrawStatus(uint32_t order, BattleCharacter* character_command); 87 GetGlobalCharacter()88 vt_global::GlobalCharacter *GetGlobalCharacter() { 89 return _global_character; 90 } 91 GetSpriteAnimationAlias()92 const std::string &GetSpriteAnimationAlias() const { 93 return _sprite_animation_alias; 94 } 95 96 protected: 97 //! \brief A pointer to the global character object which the battle character represents 98 vt_global::GlobalCharacter* _global_character; 99 100 //! \brief Retrains the last HP and SP values that were rendered to text 101 uint32_t _last_rendered_hp, _last_rendered_sp; 102 103 //! \brief Contains the identifier text of the current sprite animation 104 std::string _sprite_animation_alias; 105 106 //! \brief The animation name before being attacked, 107 //! used to return to it after the hurt or dodge animation. 108 std::string _before_attack_sprite_animation; 109 110 //! \brief The Animated image pointer from the global character 111 //! Used to avoid calling the global character std::map find calls on each loops 112 //! Don't delete it, it's just a reference to the global manager animated images 113 vt_video::AnimatedImage* _current_sprite_animation; 114 115 //! The current weapon animation loaded for the given weapon 116 vt_video::AnimatedImage _current_weapon_animation; 117 118 //! \brief Rendered text of the character's name 119 vt_video::TextImage _name_text; 120 121 //! \brief Rendered text of the character's current hit points 122 vt_video::TextImage _hit_points_text; 123 124 //! \brief Rendered text of the character's current skill points 125 vt_video::TextImage _skill_points_text; 126 127 //! \brief Rendered text of the character's currently selected action 128 vt_video::TextImage _action_selection_text; 129 130 //! \brief Rendered icon of the character's currently selected action 131 vt_video::StillImage _action_selection_icon; 132 }; 133 134 } // namespace private_battle 135 136 } // namespace vt_battle 137 138 #endif // __BATTLE_CHARACTER_HEADER__ 139