[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 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Definition of the Pickupable class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #ifndef _Pickupable_H__ |
---|
| 35 | #define _Pickupable_H__ |
---|
| 36 | |
---|
| 37 | #include "OrxonoxPrereqs.h" |
---|
| 38 | |
---|
[6474] | 39 | #include <list> |
---|
[6405] | 40 | #include "core/Super.h" |
---|
| 41 | |
---|
[6474] | 42 | #include "core/OrxonoxClass.h" |
---|
| 43 | |
---|
[6405] | 44 | namespace orxonox |
---|
| 45 | { |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | @brief |
---|
[6474] | 49 | An Interface (or more precisely an abstract class) to model and represent different (all kinds of) pickups. |
---|
[6405] | 50 | @author |
---|
| 51 | Damian 'Mozork' Frick |
---|
| 52 | */ |
---|
| 53 | //TODO: Add stuff like weight/space ? |
---|
| 54 | class _OrxonoxExport Pickupable : virtual public OrxonoxClass |
---|
| 55 | { |
---|
[6466] | 56 | |
---|
[6405] | 57 | public: |
---|
| 58 | Pickupable(); //!< Default constructor. |
---|
[6474] | 59 | virtual ~Pickupable(); //!< Default destructor. |
---|
| 60 | |
---|
[6405] | 61 | /** |
---|
| 62 | @brief Get whether the pickup is currently in use or not. |
---|
| 63 | @return Returns true if the pickup is currently in use. |
---|
| 64 | */ |
---|
| 65 | inline bool isUsed(void) |
---|
| 66 | { return this->used_; } |
---|
[6474] | 67 | /** |
---|
| 68 | @brief Should be called when the pickup has transited from used to unused or the other way around. |
---|
| 69 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. |
---|
| 70 | */ |
---|
| 71 | virtual void changedUsed(void) {} |
---|
| 72 | bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input. |
---|
[6405] | 73 | |
---|
[6474] | 74 | /** |
---|
| 75 | @brief Returns whether the Pickupable is currently picked up. |
---|
| 76 | @return Returns true if the Pickupable is currently picked up, false if not. |
---|
| 77 | */ |
---|
[6466] | 78 | inline bool isPickedUp(void) |
---|
| 79 | { return this->pickedUp_; } |
---|
[6474] | 80 | //TODO: Better private, or protected? |
---|
| 81 | bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up. |
---|
| 82 | bool dropped(void); //!< Sets the Pickupable to not picked up or dropped. |
---|
[6466] | 83 | |
---|
[6475] | 84 | bool isTarget(const PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup. |
---|
[6490] | 85 | bool isTarget(Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this pickup. |
---|
[6474] | 86 | bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup. |
---|
[6490] | 87 | bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup. |
---|
[6466] | 88 | |
---|
[6405] | 89 | /** |
---|
[6474] | 90 | @brief Get the carrier of the pickup. |
---|
| 91 | @return Returns a pointer to the carrier of the pickup. |
---|
[6405] | 92 | */ |
---|
[6474] | 93 | inline PickupCarrier* getCarrier(void) |
---|
| 94 | { return this->carrier_; } |
---|
[6405] | 95 | /** |
---|
[6466] | 96 | @brief Should be called when the pickup has transited from picked up to dropped or the other way around. |
---|
| 97 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. |
---|
[6405] | 98 | */ |
---|
[6466] | 99 | virtual void changedCarrier(void) {} |
---|
[6474] | 100 | //TODO: Maybe private? |
---|
| 101 | bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup. |
---|
[6405] | 102 | |
---|
[6474] | 103 | Pickupable* clone(void); //!< Creates a duplicate of the Pickupable. |
---|
[6497] | 104 | virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. |
---|
[6466] | 105 | |
---|
[6474] | 106 | /** |
---|
| 107 | @brief Get the PickupIdentifier of this Pickupable. |
---|
| 108 | @return Returns a pointer to the PickupIdentifier of this Pickupable. |
---|
| 109 | */ |
---|
| 110 | virtual const PickupIdentifier* getPickupIdentifier(void) |
---|
[6475] | 111 | { return this->pickupIdentifier_; } |
---|
[6474] | 112 | |
---|
| 113 | virtual void destroy(void) |
---|
| 114 | { delete this; } |
---|
| 115 | |
---|
[6466] | 116 | protected: |
---|
[6474] | 117 | /** |
---|
| 118 | @brief Helper method to initialize the PickupIdentifier. |
---|
| 119 | */ |
---|
| 120 | //TODO: Really needed? |
---|
[6466] | 121 | void initializeIdentifier(void) {} |
---|
| 122 | |
---|
[6475] | 123 | /** |
---|
| 124 | @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. |
---|
| 125 | 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.: |
---|
| 126 | DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance); |
---|
| 127 | @param position The position at which the PickupSpawner should be placed. |
---|
| 128 | @return Returns true if a spawner was created, false if not. |
---|
| 129 | */ |
---|
| 130 | virtual bool createSpawner(const Vector3& position) = 0; |
---|
| 131 | |
---|
[6474] | 132 | //TODO: Move to private and create get method in protected. |
---|
[6475] | 133 | PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable. |
---|
[6466] | 134 | |
---|
[6405] | 135 | private: |
---|
[6474] | 136 | /** |
---|
| 137 | @brief Helper method to set the Pickupable to either picked up or not picked up. |
---|
| 138 | @param pickedUp The value this->pickedUp_ should be set to. |
---|
| 139 | */ |
---|
[6466] | 140 | inline void setPickedUp(bool pickedUp) |
---|
| 141 | { this->pickedUp_ = pickedUp; } |
---|
[6405] | 142 | |
---|
| 143 | bool used_; //!< Whether the pickup is currently in use or not. |
---|
[6466] | 144 | bool pickedUp_; //!< Whether the pickup is currently picked up or not. |
---|
[6405] | 145 | |
---|
[6474] | 146 | PickupCarrier* carrier_; //!< The carrier of the pickup. |
---|
[6405] | 147 | std::list<Identifier*> targets_; //!< The possible targets of this pickup. |
---|
| 148 | |
---|
| 149 | }; |
---|
| 150 | |
---|
[6466] | 151 | SUPER_FUNCTION(10, Pickupable, changedUsed, false); |
---|
| 152 | SUPER_FUNCTION(12, Pickupable, changedCarrier, false); |
---|
[6405] | 153 | } |
---|
| 154 | |
---|
| 155 | #endif /* _Pickupable_H__ */ |
---|