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 Pickup.h |
---|
31 | @brief Declaration of the Pickup class. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _Pickup_H__ |
---|
35 | #define _Pickup_H__ |
---|
36 | |
---|
37 | #include "pickup/PickupPrereqs.h" |
---|
38 | |
---|
39 | #include "core/BaseObject.h" |
---|
40 | #include "core/XMLPort.h" |
---|
41 | |
---|
42 | #include "interfaces/Pickupable.h" |
---|
43 | |
---|
44 | #include "tools/Timer.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | |
---|
49 | //! Enum for the activation type. |
---|
50 | namespace pickupActivationType |
---|
51 | { |
---|
52 | enum Value |
---|
53 | { |
---|
54 | immediate, |
---|
55 | onUse, |
---|
56 | }; |
---|
57 | } |
---|
58 | |
---|
59 | //! Enum for the duration tyoe. |
---|
60 | namespace pickupDurationType |
---|
61 | { |
---|
62 | enum Value |
---|
63 | { |
---|
64 | once, |
---|
65 | continuous, |
---|
66 | }; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | @brief |
---|
71 | Pickup class. Offers base functionality for a wide range of pickups. |
---|
72 | Pickups ingeriting from this class cann choose an activation type and a duration type. |
---|
73 | @author |
---|
74 | Damian 'Mozork' Frick |
---|
75 | */ |
---|
76 | class _PickupExport Pickup : public Pickupable, public BaseObject |
---|
77 | { |
---|
78 | |
---|
79 | protected: |
---|
80 | Pickup(BaseObject* creator); //!< Constructor. |
---|
81 | |
---|
82 | public: |
---|
83 | virtual ~Pickup(); //!< Destructor. |
---|
84 | |
---|
85 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
86 | |
---|
87 | /** |
---|
88 | @brief Get the activation type of the pickup. |
---|
89 | @return Returns the activation type of the pickup. |
---|
90 | */ |
---|
91 | inline pickupActivationType::Value getActivationTypeDirect(void) |
---|
92 | { return this->activationType_; } |
---|
93 | /** |
---|
94 | @brief Get the duration type of the pickup. |
---|
95 | @return Returns the duration type of the pickup. |
---|
96 | */ |
---|
97 | inline pickupDurationType::Value getDurationTypeDirect(void) |
---|
98 | { return this->durationType_; } |
---|
99 | |
---|
100 | const std::string& getActivationType(void); //!< Get the activation type of the pickup. |
---|
101 | const std::string& getDurationType(void); //!< Get the duration type of the pickup. |
---|
102 | |
---|
103 | /** |
---|
104 | @brief Get whether the activation type is 'immediate'. |
---|
105 | @return Returns true if the activation type is 'immediate'. |
---|
106 | */ |
---|
107 | inline bool isImmediate(void) |
---|
108 | { return this->getActivationTypeDirect() == pickupActivationType::immediate; } |
---|
109 | /** |
---|
110 | @brief Get whether the activation type is 'onUse'. |
---|
111 | @return Returns true if the activation type is 'onUse'. |
---|
112 | */ |
---|
113 | inline bool isOnUse(void) |
---|
114 | { return this->getActivationTypeDirect() == pickupActivationType::onUse; } |
---|
115 | /** |
---|
116 | @brief Get whether the duration type is 'once'. |
---|
117 | @return Returns true if the duration type is 'once'. |
---|
118 | */ |
---|
119 | inline bool isOnce(void) |
---|
120 | { return this->getDurationTypeDirect() == pickupDurationType::once; } |
---|
121 | /** |
---|
122 | @brief Get whether the duration type is 'continuous'. |
---|
123 | @return Returns true if the duration type is 'continuous'. |
---|
124 | */ |
---|
125 | inline bool isContinuous(void) |
---|
126 | { return this->getDurationTypeDirect() == pickupDurationType::continuous; } |
---|
127 | |
---|
128 | virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around. |
---|
129 | |
---|
130 | virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup. |
---|
131 | |
---|
132 | protected: |
---|
133 | void initializeIdentifier(void); |
---|
134 | |
---|
135 | virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. |
---|
136 | |
---|
137 | bool startPickupTimer(float durationTime); //!< Starts the pickup duration timer. |
---|
138 | /** |
---|
139 | @brief Get your Timer. |
---|
140 | @return Returns a pointer to the Timer. |
---|
141 | */ |
---|
142 | inline Timer* getTimer(void) |
---|
143 | { return &this->durationTimer_; } |
---|
144 | |
---|
145 | /** |
---|
146 | @brief The callback method for the Timer. |
---|
147 | Can be overloaded to implement desired functionality. |
---|
148 | */ |
---|
149 | virtual void pickupTimerCallback(void) {} |
---|
150 | |
---|
151 | /** |
---|
152 | @brief Set the activation type of the pickup. |
---|
153 | @param type The activation type of the pickup. |
---|
154 | */ |
---|
155 | inline void setActivationTypeDirect(pickupActivationType::Value type) |
---|
156 | { this->activationType_ = type; } |
---|
157 | /** |
---|
158 | @brief Set the duration type of the pickup. |
---|
159 | @param type The duration type of the pickup. |
---|
160 | */ |
---|
161 | inline void setDurationTypeDirect(pickupDurationType::Value type) |
---|
162 | { this->durationType_ = type; } |
---|
163 | |
---|
164 | void setActivationType(const std::string& type); //!< Set the activation type of the pickup. |
---|
165 | void setDurationType(const std::string& type); //!< Set the duration type of the pickup |
---|
166 | |
---|
167 | private: |
---|
168 | void initialize(void); //!< Initializes the member variables. |
---|
169 | |
---|
170 | //TODO: Problems, when there are more Timers needed? Solutions? |
---|
171 | Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup. |
---|
172 | |
---|
173 | pickupActivationType::Value activationType_; //!< The activation type of the Pickup. |
---|
174 | pickupDurationType::Value durationType_; //!< The duration type of the pickup. |
---|
175 | |
---|
176 | //! Strings for the activation and duration types. |
---|
177 | static const std::string activationTypeImmediate_s; |
---|
178 | static const std::string activationTypeOnUse_s; |
---|
179 | static const std::string durationTypeOnce_s; |
---|
180 | static const std::string durationTypeContinuous_s; |
---|
181 | }; |
---|
182 | |
---|
183 | } |
---|
184 | #endif // _Pickup_H__ |
---|