Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupSpawner.h @ 7548

Last change on this file since 7548 was 7547, checked in by dafrick, 14 years ago

Documenting and cleanup.

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