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 Pickupable.h |
---|
31 | @brief Definition of the Pickupable class. |
---|
32 | @ingroup Pickup |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _Pickupable_H__ |
---|
36 | #define _Pickupable_H__ |
---|
37 | |
---|
38 | #include "OrxonoxPrereqs.h" |
---|
39 | |
---|
40 | #include <list> |
---|
41 | #include "core/Super.h" |
---|
42 | |
---|
43 | #include "core/OrxonoxClass.h" |
---|
44 | #include "Rewardable.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | |
---|
49 | /** |
---|
50 | @brief |
---|
51 | An Interface (or more precisely an abstract class) to model and represent different (all kinds of) pickups. |
---|
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 | |
---|
57 | @author |
---|
58 | Damian 'Mozork' Frick |
---|
59 | |
---|
60 | @ingroup Pickup |
---|
61 | */ |
---|
62 | class _OrxonoxExport Pickupable : virtual public OrxonoxClass, public Rewardable |
---|
63 | { |
---|
64 | protected: |
---|
65 | Pickupable(); //!< Default constructor. |
---|
66 | |
---|
67 | public: |
---|
68 | virtual ~Pickupable(); //!< Default destructor. |
---|
69 | |
---|
70 | /** |
---|
71 | @brief Get whether the Pickupable is currently in use or not. |
---|
72 | @return Returns true if the Pickupable is currently in use. |
---|
73 | */ |
---|
74 | inline bool isUsed(void) const |
---|
75 | { return this->used_; } |
---|
76 | /** |
---|
77 | @brief Should be called when the Pickupable has transited from used to unused or the other way around. |
---|
78 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. |
---|
79 | */ |
---|
80 | virtual void changedUsed(void) {} |
---|
81 | |
---|
82 | /** |
---|
83 | @brief Get the carrier of the Pickupable. |
---|
84 | @return Returns a pointer to the carrier of the Pickupable. |
---|
85 | */ |
---|
86 | inline PickupCarrier* getCarrier(void) |
---|
87 | { return this->carrier_; } |
---|
88 | /** |
---|
89 | @brief Should be called when the Pickupable has changed its PickupCarrier. |
---|
90 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. |
---|
91 | */ |
---|
92 | virtual void changedCarrier(void) {} |
---|
93 | |
---|
94 | /** |
---|
95 | @brief Returns whether the Pickupable is currently picked up. |
---|
96 | @return Returns true if the Pickupable is currently picked up, false if not. |
---|
97 | */ |
---|
98 | inline bool isPickedUp(void) const |
---|
99 | { return this->pickedUp_; } |
---|
100 | /** |
---|
101 | @brief Should be called when the Pickupable has transited from picked up to dropped or the other way around. |
---|
102 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. |
---|
103 | */ |
---|
104 | virtual void changedPickedUp(void) {} |
---|
105 | |
---|
106 | /** |
---|
107 | @brief Returns whether the Pickupable can be used. |
---|
108 | @return Returns true if it can be used. |
---|
109 | */ |
---|
110 | inline bool isUsable(void) const |
---|
111 | { return this->enabled_; } |
---|
112 | |
---|
113 | /** |
---|
114 | @brief Returns whether the Pickupable can be unused. |
---|
115 | @return Returns true if it can be unused. |
---|
116 | */ |
---|
117 | inline bool isUnusable(void) const |
---|
118 | { return this->enabled_; } |
---|
119 | |
---|
120 | /** |
---|
121 | @brief Returns whether the Pickupable is enabled. |
---|
122 | Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused. |
---|
123 | @return Returns true if the Pickupable is enabled. |
---|
124 | */ |
---|
125 | inline bool isEnabled(void) const |
---|
126 | { return this->enabled_; } |
---|
127 | |
---|
128 | bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable. |
---|
129 | bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. |
---|
130 | |
---|
131 | virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this Pickupable. |
---|
132 | bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable. |
---|
133 | bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this Pickupable. |
---|
134 | bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this Pickupable. |
---|
135 | |
---|
136 | Pickupable* clone(void); //!< Creates a duplicate of the Pickupable. |
---|
137 | virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. |
---|
138 | |
---|
139 | /** |
---|
140 | @brief Get the PickupIdentifier of this Pickupable. |
---|
141 | @return Returns a pointer to the PickupIdentifier of this Pickupable. |
---|
142 | */ |
---|
143 | virtual const PickupIdentifier* getPickupIdentifier(void) const |
---|
144 | { return this->pickupIdentifier_; } |
---|
145 | |
---|
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. |
---|
148 | //TODO: private? |
---|
149 | bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the Pickupable. |
---|
150 | |
---|
151 | //TODO: private? |
---|
152 | virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. |
---|
153 | |
---|
154 | void destroy(void); //!< Is called internally within the Pickupable module to destroy pickups. |
---|
155 | |
---|
156 | protected: |
---|
157 | /** |
---|
158 | @brief Helper method to initialize the PickupIdentifier. |
---|
159 | */ |
---|
160 | void initializeIdentifier(void) {} |
---|
161 | |
---|
162 | virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. |
---|
163 | virtual void destroyPickup(void); //!< Destroys a Pickupable. |
---|
164 | |
---|
165 | /** |
---|
166 | @brief Sets the Pickuapble to disabled. |
---|
167 | */ |
---|
168 | inline void setDisabled(void) |
---|
169 | { this->enabled_ = false; } |
---|
170 | |
---|
171 | /** |
---|
172 | @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. |
---|
173 | 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.: |
---|
174 | DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance); |
---|
175 | @return Returns true if a spawner was created, false if not. |
---|
176 | */ |
---|
177 | virtual bool createSpawner(void) = 0; |
---|
178 | |
---|
179 | PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable. |
---|
180 | |
---|
181 | private: |
---|
182 | |
---|
183 | bool used_; //!< Whether the Pickupable is currently in use or not. |
---|
184 | bool pickedUp_; //!< Whether the Pickupable is currently picked up or not. |
---|
185 | |
---|
186 | bool enabled_; //!< Whether the Pickupable is enabled or not. |
---|
187 | |
---|
188 | PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable. |
---|
189 | std::list<Identifier*> targets_; //!< The possible targets of this Pickupable. |
---|
190 | |
---|
191 | bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed. |
---|
192 | |
---|
193 | // For implementing the Rewardable interface: |
---|
194 | public: |
---|
195 | virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player. |
---|
196 | |
---|
197 | }; |
---|
198 | |
---|
199 | //! SUPER functions. |
---|
200 | SUPER_FUNCTION(10, Pickupable, changedUsed, false); |
---|
201 | SUPER_FUNCTION(12, Pickupable, changedCarrier, false); |
---|
202 | SUPER_FUNCTION(13, Pickupable, changedPickedUp, false); |
---|
203 | } |
---|
204 | |
---|
205 | #endif /* _Pickupable_H__ */ |
---|