| [6405] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  *                    > www.orxonox.net < | 
|---|
 | 4 |  * | 
|---|
 | 5 |  * | 
|---|
 | 6 |  *   License notice: | 
|---|
 | 7 |  * | 
|---|
 | 8 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 9 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 10 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 11 |  *   of the License, or (at your option) any later version. | 
|---|
 | 12 |  * | 
|---|
 | 13 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 14 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 15 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 16 |  *   GNU General Public License for more details. | 
|---|
 | 17 |  * | 
|---|
 | 18 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 19 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 20 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 21 |  * | 
|---|
 | 22 |  *   Author: | 
|---|
 | 23 |  *      Damian 'Mozork' Frick | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      ... | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | /** | 
|---|
| [6538] | 30 |     @file Pickupable.h | 
|---|
| [6405] | 31 |     @brief Definition of the Pickupable class. | 
|---|
| [7456] | 32 |     @ingroup Pickup | 
|---|
| [6405] | 33 | */ | 
|---|
 | 34 |  | 
|---|
 | 35 | #ifndef _Pickupable_H__ | 
|---|
 | 36 | #define _Pickupable_H__ | 
|---|
 | 37 |  | 
|---|
 | 38 | #include "OrxonoxPrereqs.h" | 
|---|
 | 39 |  | 
|---|
| [6474] | 40 | #include <list> | 
|---|
| [9667] | 41 | #include "core/class/Super.h" | 
|---|
| [6405] | 42 |  | 
|---|
| [9667] | 43 | #include "core/class/OrxonoxInterface.h" | 
|---|
| [7163] | 44 | #include "Rewardable.h" | 
|---|
| [6474] | 45 |  | 
|---|
| [7504] | 46 | namespace orxonox | 
|---|
 | 47 | { | 
|---|
| [7163] | 48 |  | 
|---|
| [6405] | 49 |     /** | 
|---|
 | 50 |     @brief | 
|---|
| [6474] | 51 |         An Interface (or more precisely an abstract class) to model and represent different (all kinds of) pickups. | 
|---|
| [7494] | 52 |  | 
|---|
| [7547] | 53 |         Pickups (@ref orxonox::Pickupable "Pickupables") are objects that (quite unsurprisingly) can be picked up. Additionally they can be used and unused (transition from used to not used), and also dropped. | 
|---|
| [7494] | 54 |  | 
|---|
| [6405] | 55 |     @author | 
|---|
 | 56 |         Damian 'Mozork' Frick | 
|---|
| [7547] | 57 |  | 
|---|
 | 58 |     @ingroup Pickup | 
|---|
| [6405] | 59 |     */ | 
|---|
| [9667] | 60 |     class _OrxonoxExport Pickupable : virtual public OrxonoxInterface, public Rewardable | 
|---|
| [7504] | 61 |     { | 
|---|
| [7552] | 62 |         friend class PickupCarrier; | 
|---|
 | 63 |  | 
|---|
| [6540] | 64 |         protected: | 
|---|
 | 65 |             Pickupable(); //!< Default constructor. | 
|---|
| [7163] | 66 |  | 
|---|
| [6405] | 67 |         public: | 
|---|
| [6474] | 68 |             virtual ~Pickupable(); //!< Default destructor. | 
|---|
| [7163] | 69 |  | 
|---|
| [9348] | 70 |             //! @brief Returns the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup. | 
|---|
 | 71 |             virtual const std::string& getRepresentationName() const = 0; | 
|---|
 | 72 |  | 
|---|
| [6405] | 73 |             /** | 
|---|
| [7494] | 74 |             @brief Get whether the Pickupable is currently in use or not. | 
|---|
 | 75 |             @return Returns true if the Pickupable is currently in use. | 
|---|
| [6405] | 76 |             */ | 
|---|
| [7547] | 77 |             inline bool isUsed(void) const | 
|---|
| [7504] | 78 |                 { return this->used_; } | 
|---|
| [6474] | 79 |             /** | 
|---|
| [7494] | 80 |             @brief  Should be called when the Pickupable has transited from used to unused or the other way around. | 
|---|
| [6474] | 81 |                     Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. | 
|---|
 | 82 |             */ | 
|---|
 | 83 |             virtual void changedUsed(void) {} | 
|---|
| [7163] | 84 |  | 
|---|
| [6474] | 85 |             /** | 
|---|
| [7494] | 86 |             @brief Get the carrier of the Pickupable. | 
|---|
 | 87 |             @return Returns a pointer to the carrier of the Pickupable. | 
|---|
| [6521] | 88 |             */ | 
|---|
 | 89 |             inline PickupCarrier* getCarrier(void) | 
|---|
 | 90 |                 { return this->carrier_; } | 
|---|
 | 91 |             /** | 
|---|
| [7494] | 92 |             @brief Should be called when the Pickupable has changed its PickupCarrier. | 
|---|
| [6521] | 93 |                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. | 
|---|
 | 94 |             */ | 
|---|
 | 95 |             virtual void changedCarrier(void) {} | 
|---|
| [7163] | 96 |  | 
|---|
| [6521] | 97 |             /** | 
|---|
| [11353] | 98 |             @brief Check whether the Pickupable is in the process of being destroyed. | 
|---|
 | 99 |             @return Returns true if so. | 
|---|
 | 100 |             */ | 
|---|
 | 101 |             inline bool isBeingDestroyed(void) | 
|---|
 | 102 |                 { return this->beingDestroyed_; } | 
|---|
 | 103 |                  | 
|---|
 | 104 |             /** | 
|---|
| [6474] | 105 |             @brief Returns whether the Pickupable is currently picked up. | 
|---|
 | 106 |             @return Returns true if the Pickupable is currently picked up, false if not. | 
|---|
 | 107 |             */ | 
|---|
| [7547] | 108 |             inline bool isPickedUp(void) const | 
|---|
| [7504] | 109 |                 { return this->pickedUp_; } | 
|---|
| [6521] | 110 |             /** | 
|---|
| [7494] | 111 |             @brief  Should be called when the Pickupable has transited from picked up to dropped or the other way around. | 
|---|
| [6521] | 112 |                     Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. | 
|---|
 | 113 |             */ | 
|---|
| [6523] | 114 |             virtual void changedPickedUp(void) {} | 
|---|
| [7163] | 115 |  | 
|---|
 | 116 |             /** | 
|---|
 | 117 |             @brief Returns whether the Pickupable can be used. | 
|---|
 | 118 |             @return Returns true if it can be used. | 
|---|
 | 119 |             */ | 
|---|
| [7547] | 120 |             inline bool isUsable(void) const | 
|---|
| [7504] | 121 |                 { return this->enabled_; } | 
|---|
 | 122 |  | 
|---|
| [7163] | 123 |             /** | 
|---|
 | 124 |             @brief Returns whether the Pickupable can be unused. | 
|---|
 | 125 |             @return Returns true if it can be unused. | 
|---|
 | 126 |             */ | 
|---|
| [7547] | 127 |             inline bool isUnusable(void) const | 
|---|
| [7504] | 128 |                 { return this->enabled_; } | 
|---|
| [7163] | 129 |  | 
|---|
 | 130 |             /** | 
|---|
 | 131 |             @brief Returns whether the Pickupable is enabled. | 
|---|
 | 132 |                    Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused. | 
|---|
 | 133 |             @return Returns true if the Pickupable is enabled. | 
|---|
 | 134 |             */ | 
|---|
| [7547] | 135 |             inline bool isEnabled(void) const | 
|---|
| [7163] | 136 |                 { return this->enabled_; } | 
|---|
 | 137 |  | 
|---|
 | 138 |             bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable. | 
|---|
 | 139 |             bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. | 
|---|
 | 140 |  | 
|---|
| [7547] | 141 |             virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this Pickupable. | 
|---|
| [6731] | 142 |             bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable. | 
|---|
| [7494] | 143 |             bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this Pickupable. | 
|---|
 | 144 |             bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this Pickupable. | 
|---|
| [7163] | 145 |  | 
|---|
| [6521] | 146 |             bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input. | 
|---|
 | 147 |             bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up. | 
|---|
| [7494] | 148 |             bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the Pickupable. | 
|---|
| [7163] | 149 |  | 
|---|
| [7494] | 150 |             void destroy(void); //!< Is called internally within the Pickupable module to destroy pickups. | 
|---|
| [7163] | 151 |  | 
|---|
| [6466] | 152 |         protected: | 
|---|
| [11071] | 153 |             virtual void preDestroy(void) override; //!< A method that is called by Destroyable::destroy() before the object is actually destroyed. | 
|---|
| [7163] | 154 |             virtual void destroyPickup(void); //!< Destroys a Pickupable. | 
|---|
| [7552] | 155 |             virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. | 
|---|
| [7163] | 156 |  | 
|---|
| [6475] | 157 |             /** | 
|---|
| [7163] | 158 |             @brief Sets the Pickuapble to disabled. | 
|---|
 | 159 |             */ | 
|---|
 | 160 |             inline void setDisabled(void) | 
|---|
 | 161 |                 { this->enabled_ = false; } | 
|---|
 | 162 |  | 
|---|
 | 163 |             /** | 
|---|
| [6475] | 164 |             @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. | 
|---|
| [9348] | 165 |                    This method must be implemented by any class directly inheriting from Pickupable. | 
|---|
| [6475] | 166 |             @return Returns true if a spawner was created, false if not. | 
|---|
 | 167 |             */ | 
|---|
| [6540] | 168 |             virtual bool createSpawner(void) = 0; | 
|---|
| [7163] | 169 |  | 
|---|
| [6405] | 170 |         private: | 
|---|
 | 171 |  | 
|---|
| [7163] | 172 |             bool used_; //!< Whether the Pickupable is currently in use or not. | 
|---|
 | 173 |             bool pickedUp_; //!< Whether the Pickupable is currently picked up or not. | 
|---|
 | 174 |  | 
|---|
 | 175 |             bool enabled_; //!< Whether the Pickupable is enabled or not. | 
|---|
 | 176 |  | 
|---|
 | 177 |             PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable. | 
|---|
 | 178 |             std::list<Identifier*> targets_; //!< The possible targets of this Pickupable. | 
|---|
 | 179 |  | 
|---|
 | 180 |             bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed. | 
|---|
 | 181 |  | 
|---|
 | 182 |         // For implementing the Rewardable interface: | 
|---|
 | 183 |         public: | 
|---|
| [11071] | 184 |             virtual bool reward(PlayerInfo* player) override; //!< Method to transcribe a Pickupable as a Rewardable to the player. | 
|---|
| [7163] | 185 |  | 
|---|
| [7504] | 186 |     }; | 
|---|
| [7163] | 187 |  | 
|---|
| [7494] | 188 |     //! SUPER functions. | 
|---|
| [10624] | 189 |     SUPER_FUNCTION(9, Pickupable, changedUsed, false); | 
|---|
 | 190 |     SUPER_FUNCTION(10, Pickupable, changedCarrier, false); | 
|---|
 | 191 |     SUPER_FUNCTION(11, Pickupable, changedPickedUp, false); | 
|---|
| [7504] | 192 | } | 
|---|
| [6405] | 193 |  | 
|---|
 | 194 | #endif /* _Pickupable_H__ */ | 
|---|