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