1 //////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2010 by The Allacrost Project 3 // All Rights Reserved 4 // 5 // This code is licensed under the GNU GPL version 2. It is free software and 6 // you may modify it and/or redistribute it under the terms of this license. 7 // See http://www.gnu.org/copyleft/gpl.html for details. 8 //////////////////////////////////////////////////////////////////////////////// 9 10 /** **************************************************************************** 11 *** \file battle_actions.h 12 *** \author Viljami Korhonen, mindflayer@allacrost.org 13 *** \author Andy Gardner, chopperdave@allacrost.org 14 *** \author Tyler Olsen, roots@allacrost.org 15 *** \brief Header file for actions that occur in battles. 16 *** 17 *** Actions are events that are carried out by actors and include the execution 18 *** of skills or the use of items. 19 *** ***************************************************************************/ 20 21 #ifndef __BATTLE_ACTIONS_HEADER__ 22 #define __BATTLE_ACTIONS_HEADER__ 23 24 #include "defs.h" 25 #include "utils.h" 26 27 #include "system.h" 28 #include "video.h" 29 30 #include "global.h" 31 32 namespace hoa_battle { 33 34 namespace private_battle { 35 36 /** **************************************************************************** 37 *** \brief Representation of a single action to be executed in battle 38 *** 39 *** This is an abstract base class for all action classes to inherit from. Actions are what 40 *** actors perform in battle whenever they move to attack an opponent, protect a comrade, use 41 *** an item, etc. There is no distinguishment between characters and enemies as far as the action 42 *** classes are concerned. All actions are implemented via Lua script functions that perform the 43 *** necessary synchronization of visual and audio media presented to the user as well as modifying 44 *** any change to the stats of the actor or target. Actions (and by proxy the actors executing them) 45 *** may be either processed individually one at a time, or multiple skills may be executed 46 *** simulatenously. 47 *** 48 *** Each action used determines the amount of time that the actor using the action 49 *** must wait in the warm up and cool down states. The warm up state is when the 50 *** actor has chosen to use the action but has not yet used it. The cool down state 51 *** occurs immediately after the actor finishes the action an 52 *** ***************************************************************************/ 53 class BattleAction { 54 public: 55 BattleAction(BattleActor* user, BattleTarget target); 56 ~BattleAction()57 virtual ~BattleAction() 58 {} 59 60 //! \brief Returns true if this action consumes an item 61 virtual bool IsItemAction() const = 0; 62 63 /** \brief Executes the action; This function may be called several times before execution is finished 64 *** \return True if the action is finished executing 65 **/ 66 virtual bool Execute() = 0; 67 68 //! \brief Returns the number of milliseconds that the owner actor must wait in the warm up state 69 virtual uint32 GetWarmUpTime() const = 0; 70 71 //! \brief Returns the number of milliseconds that the owner actor must wait in the cool down state 72 virtual uint32 GetCoolDownTime() const = 0; 73 74 //! \name Class member access functions 75 //@{ GetActor()76 BattleActor* GetActor() 77 { return _actor; } 78 GetTarget()79 BattleTarget& GetTarget() 80 { return _target; } 81 //@} 82 83 protected: 84 //! \brief The rendered text for the name of the action 85 // hoa_video::TextImage _action_name; 86 87 //! \brief The actor who will be executing the action 88 BattleActor* _actor; 89 90 //! \brief The target of the action which may be an attack point, actor, or entire party 91 BattleTarget _target; 92 93 /** \brief Makes sure that the target is valid and selects a new target if it is not 94 *** This method is necessary because there is a period of time between when the desired target 95 *** is selected and when the action actually gets executed by the owning actor. Within that time 96 *** period the target may have become invalid due death or some other reason. This method will 97 *** search for the next available target of the same type and modify the _target member so that 98 *** it points to a valid target. 99 *** 100 *** \note Certain skills may have different criteria for determining target validity. For example, 101 *** a revive skill or item would be useless if no allies were in the dead state. For this reason, 102 *** inheriting classes may wish to expand upon this function to check for these types of specific 103 *** conditions. 104 **/ 105 // virtual void _VerifyValidTarget(); 106 }; // class BattleAction 107 108 109 /** **************************************************************************** 110 *** \brief A battle action which involves the exectuion of an actor's skill 111 *** 112 *** This class invokes the execution of a GlobalSkill contained by the source 113 *** actor. When the action is finished, any SP required to use the skill is 114 *** subtracted from the source actor. 115 *** ***************************************************************************/ 116 class SkillAction : public BattleAction { 117 public: 118 SkillAction(BattleActor* actor, BattleTarget target, hoa_global::GlobalSkill* skill); 119 IsItemAction()120 bool IsItemAction() const 121 { return false; } 122 123 bool Execute(); 124 125 uint32 GetWarmUpTime() const; 126 127 uint32 GetCoolDownTime() const; 128 GetSkill()129 hoa_global::GlobalSkill* GetSkill() 130 { return _skill; } 131 132 private: 133 //! \brief Pointer to the skill attached to this script (for skill events only) 134 hoa_global::GlobalSkill* _skill; 135 }; // class SkillAction : public BattleAction 136 137 138 /** **************************************************************************** 139 *** \brief A battle action which involves the use of an item 140 *** 141 *** This class invokes the usage of a GlobalItem. The item's count is decremented 142 *** as soon as the action goes into the FIFO queue. After the action is executed, 143 *** the item is removed if its count has become zero. If the action is removed 144 *** from the queue before it is executed (because the source actor perished, or 145 *** the battle ended, or other circumstances), then the item's count is 146 *** incremented back to its original value since it was not used. 147 *** ***************************************************************************/ 148 class ItemAction : public BattleAction { 149 public: 150 ItemAction(BattleActor* source, BattleTarget target, BattleItem* item); 151 IsItemAction()152 bool IsItemAction() const 153 { return true; } 154 155 bool Execute(); 156 GetWarmUpTime()157 uint32 GetWarmUpTime() const 158 { return ITEM_WARM_UP_TIME; } 159 GetCoolDownTime()160 uint32 GetCoolDownTime() const 161 { return 0; } 162 GetItem()163 BattleItem* GetItem() 164 { return _item; } 165 166 private: 167 //! \brief Pointer to the item attached to this script 168 BattleItem* _item; 169 }; // class ItemAction : public BattleAction 170 171 } // namespace private_battle 172 173 } // namespace hoa_battle 174 175 #endif // __BATTLE_ACTIONS_HEADER__ 176