Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/src/modules/pickup/PickupSpawner.h @ 8065

Last change on this file since 8065 was 7494, checked in by dafrick, 14 years ago

Some documenting and cleaning up/re-organization in pickups module.

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
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 *      Damian 'Mozork' Frick
26 *
27 */
28
29/**
30    @file PickupSpawner.h
31    @brief Definition of the PickupSpawner class.
32    @ingroup Pickup
33*/
34
35#ifndef _PickupSpawner_H__
36#define _PickupSpawner_H__
37
38#include "PickupPrereqs.h"
39
40#include <string>
41#include "interfaces/Pickupable.h"
42#include "tools/Timer.h"
43
44#include "tools/interfaces/Tickable.h"
45#include "worldentities/StaticEntity.h"
46
47namespace orxonox
48{
49    /**
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
54        @author
55            Daniel 'Huty' Haggenmueller
56        @author
57            Damian 'Mozork' Frick
58    */
59    class _PickupExport PickupSpawner : public StaticEntity, public Tickable
60    {
61        public:
62            PickupSpawner(BaseObject* creator); //!< Default Constructor.
63            PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor.
64            virtual ~PickupSpawner(); //!< Destructor.
65
66            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< Method for creating a PickupSpawner through XML.
67            virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
68            virtual void tick(float dt);
69
70            /**
71            @brief Get the distance in which to trigger.
72            @return Returns the distance in which this gets triggered.
73            */
74            inline float getTriggerDistance() const
75                { return this->triggerDistance_; }
76            /**
77            @brief Set the distance in which to trigger.
78            @param value The new distance in which to trigger.
79            */
80            inline void setTriggerDistance(float value)
81                { this->triggerDistance_ = value; }
82
83            /**
84            @brief Get the time to respawn.
85            @returns Returns the time after which this gets re-actived.
86            */
87            inline float getRespawnTime() const
88                { return this->respawnTime_; }
89            /**
90            @brief Set the time to respawn.
91            @param time New time after which this gets re-actived.
92            */
93            inline void setRespawnTime(float time)
94                { this->respawnTime_ = time; }
95
96            /**
97            @brief Get the maximum number of items that will be spawned by this PickupSpawner.
98            @return Returns the maximum number of items spawned by this PickupSpawner.
99            */
100            inline int getMaxSpawnedItems(void)
101                { return this->maxSpawnedItems_; }
102            void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
103
104        protected:
105            void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
106
107            void startRespawnTimer(void);
108
109            virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
110
111            void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn.
112            const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner.
113
114            Pickupable* pickup_; //!< The pickup to be spawned.
115
116        private:
117            void initialize(void);
118
119            void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
120            void respawnTimerCallback(); //!< Method called when the timer runs out.
121
122            int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner.
123            int spawnsRemaining_; //!< Number of items that can be spawned by this PickupSpawner until it selfdestructs.
124
125            float triggerDistance_; //!< Distance in which this gets triggered.
126
127            float respawnTime_; //!< Time after which this gets re-actived.
128            Timer respawnTimer_; //!< Timer used for re-activating.
129
130            bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing.
131
132            static const int INF = -1; //!< Constant for infinity.
133    };
134}
135
136#endif /* _PickupSpawner_H__ */
Note: See TracBrowser for help on using the repository browser.