[2917] | 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: |
---|
[6475] | 25 | * Damian 'Mozork' Frick |
---|
[2917] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[6540] | 30 | @file PickupSpawner.h |
---|
| 31 | @brief Definition of the PickupSpawner class. |
---|
[7456] | 32 | @ingroup Pickup |
---|
[2917] | 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _PickupSpawner_H__ |
---|
| 36 | #define _PickupSpawner_H__ |
---|
| 37 | |
---|
[6466] | 38 | #include "PickupPrereqs.h" |
---|
[2917] | 39 | |
---|
[3196] | 40 | #include <string> |
---|
[7540] | 41 | |
---|
[3196] | 42 | #include "tools/Timer.h" |
---|
[6475] | 43 | |
---|
[7540] | 44 | #include "interfaces/Pickupable.h" |
---|
| 45 | |
---|
[5693] | 46 | #include "tools/interfaces/Tickable.h" |
---|
[5735] | 47 | #include "worldentities/StaticEntity.h" |
---|
[2917] | 48 | |
---|
| 49 | namespace orxonox |
---|
| 50 | { |
---|
| 51 | /** |
---|
[6475] | 52 | @brief |
---|
[7540] | 53 | The PickupSpawner class is responsible for spawning @ref orxonox::Pickupable "Pickupables" of a specific type. |
---|
| 54 | Furthermore it can be specified how long the time interval between spawning two items is and how many @ref orxonox::Pickupable "Pickupables" are spawned at maximum, amongst other things. The parameters that can be used to further specify the behaviour of the PickupSpawner are: |
---|
| 55 | - The <b>triggerDistance</b> can be used to specify how far away an entity has to be to still trigger the PickupSPawner (and thus receive a @ref orxonox::Pickupable "Pickupable" form it). The default is 10. |
---|
| 56 | - The <b>respawnTime</b> is the time in seconds that passes until the PickupSpawner is enabled again, after having spawned a @ref orxonox::Pickupable "Pickupable". The default is 0. |
---|
| 57 | - The <b>maxSpawnedItems</b> is the number of @ref orxonox::Pickupable "Pickupables" that are spawned by this PickupSpawner at the most. The default is -1, which denotes infinity. |
---|
[7494] | 58 | |
---|
[7540] | 59 | A PickupSpawner is created in XML, which can be done in the following fashion: |
---|
| 60 | @code |
---|
| 61 | <PickupSpawner position="-100,0,-100" respawnTime="30" maxSpawnedItems="10"> |
---|
| 62 | <pickup> |
---|
| 63 | <SomePickup > |
---|
| 64 | </pickup> |
---|
| 65 | </PickupSpawner> |
---|
| 66 | @endcode |
---|
| 67 | As we can see, since the PickupSpawner is a StaticEntity, it also has spatial coordinates. We can also see, that the type of @ref orxonox::Pickupable "Pickupable" which is spawned hast to be specified as well. |
---|
| 68 | |
---|
[6475] | 69 | @author |
---|
| 70 | Daniel 'Huty' Haggenmueller |
---|
[7494] | 71 | @author |
---|
[6475] | 72 | Damian 'Mozork' Frick |
---|
[7540] | 73 | |
---|
| 74 | @ingroup Pickup |
---|
[2917] | 75 | */ |
---|
[6496] | 76 | class _PickupExport PickupSpawner : public StaticEntity, public Tickable |
---|
[2917] | 77 | { |
---|
[5947] | 78 | public: |
---|
[6475] | 79 | PickupSpawner(BaseObject* creator); //!< Default Constructor. |
---|
| 80 | PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor. |
---|
| 81 | virtual ~PickupSpawner(); //!< Destructor. |
---|
[2917] | 82 | |
---|
[5947] | 83 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML. |
---|
[6475] | 84 | virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty). |
---|
[7540] | 85 | virtual void tick(float dt); //!< Tick, checks if any Pawn is close enough to trigger. |
---|
[2917] | 86 | |
---|
[5947] | 87 | /** |
---|
[6475] | 88 | @brief Get the distance in which to trigger. |
---|
| 89 | @return Returns the distance in which this gets triggered. |
---|
[5947] | 90 | */ |
---|
| 91 | inline float getTriggerDistance() const |
---|
| 92 | { return this->triggerDistance_; } |
---|
| 93 | /** |
---|
[6475] | 94 | @brief Set the distance in which to trigger. |
---|
| 95 | @param value The new distance in which to trigger. |
---|
[5947] | 96 | */ |
---|
| 97 | inline void setTriggerDistance(float value) |
---|
| 98 | { this->triggerDistance_ = value; } |
---|
[2917] | 99 | |
---|
[5947] | 100 | /** |
---|
[6475] | 101 | @brief Get the time to respawn. |
---|
| 102 | @returns Returns the time after which this gets re-actived. |
---|
[5947] | 103 | */ |
---|
| 104 | inline float getRespawnTime() const |
---|
| 105 | { return this->respawnTime_; } |
---|
| 106 | /** |
---|
[6475] | 107 | @brief Set the time to respawn. |
---|
| 108 | @param time New time after which this gets re-actived. |
---|
[5947] | 109 | */ |
---|
| 110 | inline void setRespawnTime(float time) |
---|
| 111 | { this->respawnTime_ = time; } |
---|
[5953] | 112 | |
---|
[6421] | 113 | /** |
---|
[6475] | 114 | @brief Get the maximum number of items that will be spawned by this PickupSpawner. |
---|
| 115 | @return Returns the maximum number of items spawned by this PickupSpawner. |
---|
[6421] | 116 | */ |
---|
[5953] | 117 | inline int getMaxSpawnedItems(void) |
---|
| 118 | { return this->maxSpawnedItems_; } |
---|
[6475] | 119 | void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items. |
---|
[5953] | 120 | |
---|
| 121 | protected: |
---|
[6475] | 122 | void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns. |
---|
[7163] | 123 | |
---|
[6512] | 124 | void startRespawnTimer(void); |
---|
[7163] | 125 | |
---|
[6475] | 126 | virtual Pickupable* getPickup(void); //!< Creates a new Pickupable. |
---|
[7163] | 127 | |
---|
[6475] | 128 | void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn. |
---|
| 129 | const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner. |
---|
[7163] | 130 | |
---|
[6421] | 131 | Pickupable* pickup_; //!< The pickup to be spawned. |
---|
[5953] | 132 | |
---|
[5947] | 133 | private: |
---|
[5953] | 134 | void initialize(void); |
---|
[7163] | 135 | |
---|
[6475] | 136 | void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. |
---|
| 137 | void respawnTimerCallback(); //!< Method called when the timer runs out. |
---|
[5953] | 138 | |
---|
[6475] | 139 | int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner. |
---|
| 140 | int spawnsRemaining_; //!< Number of items that can be spawned by this PickupSpawner until it selfdestructs. |
---|
[5953] | 141 | |
---|
[6475] | 142 | float triggerDistance_; //!< Distance in which this gets triggered. |
---|
[2917] | 143 | |
---|
[6475] | 144 | float respawnTime_; //!< Time after which this gets re-actived. |
---|
| 145 | Timer respawnTimer_; //!< Timer used for re-activating. |
---|
[3046] | 146 | |
---|
[7163] | 147 | bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing. |
---|
| 148 | |
---|
[6475] | 149 | static const int INF = -1; //!< Constant for infinity. |
---|
[2917] | 150 | }; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | #endif /* _PickupSpawner_H__ */ |
---|