[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> |
---|
[6475] | 41 | #include "interfaces/Pickupable.h" |
---|
[3196] | 42 | #include "tools/Timer.h" |
---|
[6475] | 43 | |
---|
[5693] | 44 | #include "tools/interfaces/Tickable.h" |
---|
[5735] | 45 | #include "worldentities/StaticEntity.h" |
---|
[2917] | 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | /** |
---|
[6475] | 50 | @brief |
---|
| 51 | The PickupSpawner class is responsible for spawning pickups of a specific type. |
---|
| 52 | Forthermore it can be specified how long the time interval between spawning two items is and how many pickups are spawned at maximum, amongst other things. |
---|
| 53 | @author |
---|
| 54 | Daniel 'Huty' Haggenmueller |
---|
| 55 | Damian 'Mozork' Frick |
---|
[2917] | 56 | */ |
---|
[6496] | 57 | class _PickupExport PickupSpawner : public StaticEntity, public Tickable |
---|
[2917] | 58 | { |
---|
[5947] | 59 | public: |
---|
[6475] | 60 | PickupSpawner(BaseObject* creator); //!< Default Constructor. |
---|
| 61 | PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor. |
---|
| 62 | virtual ~PickupSpawner(); //!< Destructor. |
---|
[2917] | 63 | |
---|
[5947] | 64 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML. |
---|
[6475] | 65 | virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty). |
---|
[5947] | 66 | virtual void tick(float dt); |
---|
[2917] | 67 | |
---|
[5947] | 68 | /** |
---|
[6475] | 69 | @brief Get the distance in which to trigger. |
---|
| 70 | @return Returns the distance in which this gets triggered. |
---|
[5947] | 71 | */ |
---|
| 72 | inline float getTriggerDistance() const |
---|
| 73 | { return this->triggerDistance_; } |
---|
| 74 | /** |
---|
[6475] | 75 | @brief Set the distance in which to trigger. |
---|
| 76 | @param value The new distance in which to trigger. |
---|
[5947] | 77 | */ |
---|
| 78 | inline void setTriggerDistance(float value) |
---|
| 79 | { this->triggerDistance_ = value; } |
---|
[2917] | 80 | |
---|
[5947] | 81 | /** |
---|
[6475] | 82 | @brief Get the time to respawn. |
---|
| 83 | @returns Returns the time after which this gets re-actived. |
---|
[5947] | 84 | */ |
---|
| 85 | inline float getRespawnTime() const |
---|
| 86 | { return this->respawnTime_; } |
---|
| 87 | /** |
---|
[6475] | 88 | @brief Set the time to respawn. |
---|
| 89 | @param time New time after which this gets re-actived. |
---|
[5947] | 90 | */ |
---|
| 91 | inline void setRespawnTime(float time) |
---|
| 92 | { this->respawnTime_ = time; } |
---|
[5953] | 93 | |
---|
[6421] | 94 | /** |
---|
[6475] | 95 | @brief Get the maximum number of items that will be spawned by this PickupSpawner. |
---|
| 96 | @return Returns the maximum number of items spawned by this PickupSpawner. |
---|
[6421] | 97 | */ |
---|
[5953] | 98 | inline int getMaxSpawnedItems(void) |
---|
| 99 | { return this->maxSpawnedItems_; } |
---|
[6475] | 100 | void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items. |
---|
[5953] | 101 | |
---|
| 102 | protected: |
---|
[6475] | 103 | void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns. |
---|
[7163] | 104 | |
---|
[6512] | 105 | void startRespawnTimer(void); |
---|
[7163] | 106 | |
---|
[6475] | 107 | virtual Pickupable* getPickup(void); //!< Creates a new Pickupable. |
---|
[7163] | 108 | |
---|
[6475] | 109 | void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn. |
---|
| 110 | const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner. |
---|
[7163] | 111 | |
---|
[6421] | 112 | Pickupable* pickup_; //!< The pickup to be spawned. |
---|
[5953] | 113 | |
---|
[5947] | 114 | private: |
---|
[5953] | 115 | void initialize(void); |
---|
[7163] | 116 | |
---|
[6475] | 117 | void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. |
---|
| 118 | void respawnTimerCallback(); //!< Method called when the timer runs out. |
---|
[5953] | 119 | |
---|
[6475] | 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. |
---|
[5953] | 122 | |
---|
[6475] | 123 | float triggerDistance_; //!< Distance in which this gets triggered. |
---|
[2917] | 124 | |
---|
[6475] | 125 | float respawnTime_; //!< Time after which this gets re-actived. |
---|
| 126 | Timer respawnTimer_; //!< Timer used for re-activating. |
---|
[3046] | 127 | |
---|
[7163] | 128 | bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing. |
---|
| 129 | |
---|
[6475] | 130 | static const int INF = -1; //!< Constant for infinity. |
---|
[2917] | 131 | }; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | #endif /* _PickupSpawner_H__ */ |
---|