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 | * Daniel 'Huty' Haggenmueller |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file |
---|
31 | @brief Definition of PickupSpawner. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _PickupSpawner_H__ |
---|
35 | #define _PickupSpawner_H__ |
---|
36 | |
---|
37 | #include "pickup/PickupPrereqs.h" |
---|
38 | |
---|
39 | #include <string> |
---|
40 | #include "tools/Timer.h" |
---|
41 | #include "tools/interfaces/Tickable.h" |
---|
42 | #include "worldentities/StaticEntity.h" |
---|
43 | #include "interfaces/Pickupable.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | /** |
---|
48 | @brief PickupSpawner. |
---|
49 | @author Daniel 'Huty' Haggenmueller |
---|
50 | */ |
---|
51 | class _OrxonoxExport PickupSpawner : public StaticEntity, public Tickable |
---|
52 | { |
---|
53 | public: |
---|
54 | //TODO: Add limit of items spawned here. |
---|
55 | PickupSpawner(BaseObject* creator); |
---|
56 | PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); |
---|
57 | virtual ~PickupSpawner(); |
---|
58 | |
---|
59 | //virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty). |
---|
60 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML. |
---|
61 | virtual void tick(float dt); |
---|
62 | |
---|
63 | /** |
---|
64 | @brief Get the distance in which to trigger. |
---|
65 | @return Returns the distance in which this gets triggered. |
---|
66 | */ |
---|
67 | inline float getTriggerDistance() const |
---|
68 | { return this->triggerDistance_; } |
---|
69 | /** |
---|
70 | @brief Set the distance in which to trigger. |
---|
71 | @param value The new distance in which to trigger. |
---|
72 | */ |
---|
73 | inline void setTriggerDistance(float value) |
---|
74 | { this->triggerDistance_ = value; } |
---|
75 | |
---|
76 | /** |
---|
77 | @brief Get the time to respawn. |
---|
78 | @returns Returns the time after which this gets re-actived. |
---|
79 | */ |
---|
80 | inline float getRespawnTime() const |
---|
81 | { return this->respawnTime_; } |
---|
82 | /** |
---|
83 | @brief Set the time to respawn. |
---|
84 | @param time New time after which this gets re-actived. |
---|
85 | */ |
---|
86 | inline void setRespawnTime(float time) |
---|
87 | { this->respawnTime_ = time; } |
---|
88 | |
---|
89 | /** |
---|
90 | @brief Get the maximum number of items that will be spawned by this PickupSpawner. |
---|
91 | @return Returns the maximum number of items spawned by this PickupSpawner. |
---|
92 | */ |
---|
93 | inline int getMaxSpawnedItems(void) |
---|
94 | { return this->maxSpawnedItems_; } |
---|
95 | void setMaxSpawnedItems(int items); |
---|
96 | |
---|
97 | protected: |
---|
98 | virtual Pickupable* getPickup(void); |
---|
99 | |
---|
100 | void setPickupable(Pickupable* pickup); |
---|
101 | const Pickupable* getPickupable(void); |
---|
102 | |
---|
103 | void decrementSpawnsRemaining(void); |
---|
104 | |
---|
105 | Pickupable* pickup_; //!< The pickup to be spawned. |
---|
106 | |
---|
107 | private: |
---|
108 | void initialize(void); |
---|
109 | |
---|
110 | void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. |
---|
111 | void respawnTimerCallback(); //!< Method called when the timer runs out. |
---|
112 | |
---|
113 | int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner. |
---|
114 | int spawnsRemaining_; //!< Number of items that can be spawned by this PickupSpawner until it selfdestructs. |
---|
115 | |
---|
116 | float triggerDistance_; //!< Distance in which this gets triggered. |
---|
117 | |
---|
118 | /* Pickup animation */ |
---|
119 | float tickSum_; //!< Adds up tick to use in sine movement |
---|
120 | static const float bounceSpeed_s; //!< Speed of pickup to bounce up and down |
---|
121 | static const float bounceDistance_s; //!< Distance the pickup bounces up and down |
---|
122 | static const float rotationSpeed_s; //!< Rotation speed of pickup |
---|
123 | |
---|
124 | float respawnTime_; //!< Time after which this gets re-actived. |
---|
125 | Timer respawnTimer_; //!< Timer used for re-activating. |
---|
126 | |
---|
127 | static const int INF = -1; //!< Constant for infinity. |
---|
128 | }; |
---|
129 | } |
---|
130 | |
---|
131 | #endif /* _PickupSpawner_H__ */ |
---|