[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> |
---|
[6405] | 41 | #include "core/Super.h" |
---|
| 42 | |
---|
[6474] | 43 | #include "core/OrxonoxClass.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 | |
---|
| 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. |
---|
| 54 | |
---|
| 55 | A class of Pickups can incorporate many different types of pickups (see @ref orxonox::PickupIdentifier "PickupIdentifier"), each type is uniquely defined by a @ref orxonox::PickupIdentifier "PickupIdentifier". Each pickup has such an identifier identiying its type. This means that two pickups of the same type have identifiers which are equal. |
---|
| 56 | |
---|
[6405] | 57 | @author |
---|
| 58 | Damian 'Mozork' Frick |
---|
| 59 | */ |
---|
[7504] | 60 | class _OrxonoxExport Pickupable : virtual public OrxonoxClass, public Rewardable |
---|
| 61 | { |
---|
[6540] | 62 | protected: |
---|
| 63 | Pickupable(); //!< Default constructor. |
---|
[7163] | 64 | |
---|
[6405] | 65 | public: |
---|
[6474] | 66 | virtual ~Pickupable(); //!< Default destructor. |
---|
[7163] | 67 | |
---|
[6405] | 68 | /** |
---|
[7494] | 69 | @brief Get whether the Pickupable is currently in use or not. |
---|
| 70 | @return Returns true if the Pickupable is currently in use. |
---|
[6405] | 71 | */ |
---|
[7504] | 72 | inline bool isUsed(void) |
---|
| 73 | { return this->used_; } |
---|
[6474] | 74 | /** |
---|
[7494] | 75 | @brief Should be called when the Pickupable has transited from used to unused or the other way around. |
---|
[6474] | 76 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. |
---|
| 77 | */ |
---|
| 78 | virtual void changedUsed(void) {} |
---|
[7163] | 79 | |
---|
[6474] | 80 | /** |
---|
[7494] | 81 | @brief Get the carrier of the Pickupable. |
---|
| 82 | @return Returns a pointer to the carrier of the Pickupable. |
---|
[6521] | 83 | */ |
---|
| 84 | inline PickupCarrier* getCarrier(void) |
---|
| 85 | { return this->carrier_; } |
---|
| 86 | /** |
---|
[7494] | 87 | @brief Should be called when the Pickupable has changed its PickupCarrier. |
---|
[6521] | 88 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. |
---|
| 89 | */ |
---|
| 90 | virtual void changedCarrier(void) {} |
---|
[7163] | 91 | |
---|
[6521] | 92 | /** |
---|
[6474] | 93 | @brief Returns whether the Pickupable is currently picked up. |
---|
| 94 | @return Returns true if the Pickupable is currently picked up, false if not. |
---|
| 95 | */ |
---|
[7504] | 96 | inline bool isPickedUp(void) |
---|
| 97 | { return this->pickedUp_; } |
---|
[6521] | 98 | /** |
---|
[7494] | 99 | @brief Should be called when the Pickupable has transited from picked up to dropped or the other way around. |
---|
[6521] | 100 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. |
---|
| 101 | */ |
---|
[6523] | 102 | virtual void changedPickedUp(void) {} |
---|
[7163] | 103 | |
---|
| 104 | /** |
---|
| 105 | @brief Returns whether the Pickupable can be used. |
---|
| 106 | @return Returns true if it can be used. |
---|
| 107 | */ |
---|
[7504] | 108 | inline bool isUsable(void) |
---|
| 109 | { return this->enabled_; } |
---|
| 110 | |
---|
[7163] | 111 | /** |
---|
| 112 | @brief Returns whether the Pickupable can be unused. |
---|
| 113 | @return Returns true if it can be unused. |
---|
| 114 | */ |
---|
[7504] | 115 | inline bool isUnusable(void) |
---|
| 116 | { return this->enabled_; } |
---|
[7163] | 117 | |
---|
| 118 | /** |
---|
| 119 | @brief Returns whether the Pickupable is enabled. |
---|
| 120 | Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused. |
---|
| 121 | @return Returns true if the Pickupable is enabled. |
---|
| 122 | */ |
---|
| 123 | inline bool isEnabled(void) |
---|
| 124 | { return this->enabled_; } |
---|
| 125 | |
---|
| 126 | bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable. |
---|
| 127 | bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. |
---|
| 128 | |
---|
[7494] | 129 | virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this Pickupable. |
---|
[6731] | 130 | bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable. |
---|
[7494] | 131 | bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this Pickupable. |
---|
| 132 | bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this Pickupable. |
---|
[7163] | 133 | |
---|
[6474] | 134 | Pickupable* clone(void); //!< Creates a duplicate of the Pickupable. |
---|
[6497] | 135 | virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. |
---|
[7163] | 136 | |
---|
[6474] | 137 | /** |
---|
| 138 | @brief Get the PickupIdentifier of this Pickupable. |
---|
| 139 | @return Returns a pointer to the PickupIdentifier of this Pickupable. |
---|
| 140 | */ |
---|
| 141 | virtual const PickupIdentifier* getPickupIdentifier(void) |
---|
[6475] | 142 | { return this->pickupIdentifier_; } |
---|
[7163] | 143 | |
---|
[6521] | 144 | bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input. |
---|
| 145 | bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up. |
---|
[7163] | 146 | //TODO: private? |
---|
[7494] | 147 | bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the Pickupable. |
---|
[7163] | 148 | |
---|
| 149 | //TODO: private? |
---|
| 150 | virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. |
---|
| 151 | |
---|
[7494] | 152 | void destroy(void); //!< Is called internally within the Pickupable module to destroy pickups. |
---|
[7163] | 153 | |
---|
[6466] | 154 | protected: |
---|
[6474] | 155 | /** |
---|
| 156 | @brief Helper method to initialize the PickupIdentifier. |
---|
| 157 | */ |
---|
[6466] | 158 | void initializeIdentifier(void) {} |
---|
[7163] | 159 | |
---|
| 160 | virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. |
---|
| 161 | virtual void destroyPickup(void); //!< Destroys a Pickupable. |
---|
| 162 | |
---|
[6475] | 163 | /** |
---|
[7163] | 164 | @brief Sets the Pickuapble to disabled. |
---|
| 165 | */ |
---|
| 166 | inline void setDisabled(void) |
---|
| 167 | { this->enabled_ = false; } |
---|
| 168 | |
---|
| 169 | /** |
---|
[6475] | 170 | @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. |
---|
| 171 | This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.: |
---|
[7401] | 172 | DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance); |
---|
[6475] | 173 | @return Returns true if a spawner was created, false if not. |
---|
| 174 | */ |
---|
[6540] | 175 | virtual bool createSpawner(void) = 0; |
---|
[7163] | 176 | |
---|
[6475] | 177 | PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable. |
---|
[7163] | 178 | |
---|
[6405] | 179 | private: |
---|
| 180 | |
---|
[7163] | 181 | bool used_; //!< Whether the Pickupable is currently in use or not. |
---|
| 182 | bool pickedUp_; //!< Whether the Pickupable is currently picked up or not. |
---|
| 183 | |
---|
| 184 | bool enabled_; //!< Whether the Pickupable is enabled or not. |
---|
| 185 | |
---|
| 186 | PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable. |
---|
| 187 | std::list<Identifier*> targets_; //!< The possible targets of this Pickupable. |
---|
| 188 | |
---|
| 189 | bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed. |
---|
| 190 | |
---|
| 191 | // For implementing the Rewardable interface: |
---|
| 192 | public: |
---|
| 193 | virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player. |
---|
| 194 | |
---|
[7504] | 195 | }; |
---|
[7163] | 196 | |
---|
[7494] | 197 | //! SUPER functions. |
---|
[6466] | 198 | SUPER_FUNCTION(10, Pickupable, changedUsed, false); |
---|
| 199 | SUPER_FUNCTION(12, Pickupable, changedCarrier, false); |
---|
[6521] | 200 | SUPER_FUNCTION(13, Pickupable, changedPickedUp, false); |
---|
[7504] | 201 | } |
---|
[6405] | 202 | |
---|
| 203 | #endif /* _Pickupable_H__ */ |
---|