Orxonox  0.0.5 Codename: Arcturus
PickupSpawner.h
Go to the documentation of this file.
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 
35 #ifndef _PickupSpawner_H__
36 #define _PickupSpawner_H__
37 
38 #include "PickupPrereqs.h"
39 
40 #include <map>
41 #include <string>
42 #include "tools/Timer.h"
43 
44 #include "interfaces/Pickupable.h"
45 
48 
49 namespace orxonox
50 {
77  {
78  public:
79  PickupSpawner(Context* context);
80  virtual ~PickupSpawner();
81 
82  static PickupSpawner* createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance = 10.0);
83 
84  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
85  virtual void tick(float dt) override;
86 
91  inline float getTriggerDistance() const
92  { return this->triggerDistance_; }
97  inline void setTriggerDistance(float value)
98  { this->triggerDistance_ = value; }
103  inline float getRespawnTime() const
104  { return this->respawnTime_; }
109  inline void setRespawnTime(float time)
110  { this->respawnTime_ = time; }
115  inline int getMaxSpawnedItems(void) const
116  { return this->maxSpawnedItems_; }
117  void setMaxSpawnedItems(int items);
118 
122  inline const std::string& getPickupTemplateName() const
123  { return this->pickupTemplateName_; }
127  inline Template* getPickupTemplate() const
128  {return this->pickupTemplate_; }
129 
130  void setPickupTemplateName(const std::string& name);
131  void setPickupTemplate(Template* temp);
132 
133  private:
134  void initialize(void);
135 
136  void trigger(PickupCarrier* carrier);
137  void respawnTimerCallback();
138 
139  void decrementSpawnsRemaining(void);
140  void startRespawnTimer(void);
141 
147  void block(PickupCarrier* carrier, unsigned int time = DEFAULT_BLOCKED_TIME)
148  { this->blocked_.insert(std::pair<PickupCarrier*, std::time_t>(carrier, std::time(0)+time)); }
149 
150  Pickupable* createPickup(void);
151  void setPickupable(Pickupable* pickup);
152 
157 
160 
162 
163  float respawnTime_;
165  std::map<PickupCarrier*, std::time_t> blocked_;
166 
168 
169  static const int INF = -1;
170  static const unsigned int DEFAULT_BLOCKED_TIME = 5;
171  };
172 }
173 
174 #endif /* _PickupSpawner_H__ */
#define _PickupExport
Definition: PickupPrereqs.h:60
StaticEntity * representation_
The active representation of the spawner.
Definition: PickupSpawner.h:154
The StaticEntity is the simplest derivative of the orxonox::WorldEntity class.
Definition: StaticEntity.h:50
Definition: Template.h:50
Declaration of the Tickable interface.
float getTriggerDistance() const
Get the distance in which to trigger.
Definition: PickupSpawner.h:91
An Interface (or more precisely an abstract class) to model and represent different (all kinds of) pi...
Definition: Pickupable.h:60
::std::string string
Definition: gtest-port.h:756
Template * getPickupTemplate() const
Returns the template which is used to create a pickup for this spawner.
Definition: PickupSpawner.h:127
float respawnTime_
Time after which this gets re-actived.
Definition: PickupSpawner.h:163
const std::string & getPickupTemplateName() const
Returns the name of the template which is used to create a pickup for this spawner.
Definition: PickupSpawner.h:122
int getMaxSpawnedItems(void) const
Get the maximum number of items that will be spawned by this PickupSpawner.
Definition: PickupSpawner.h:115
xmlelement
Definition: Super.h:519
Declaration of the Timer class, used to call functions after a given time-interval.
float triggerDistance_
Distance in which this gets triggered.
Definition: PickupSpawner.h:161
int spawnsRemaining_
Number of items that can be spawned by this PickupSpawner until it selfdestructs. ...
Definition: PickupSpawner.h:159
float getRespawnTime() const
Get the time to respawn.
Definition: PickupSpawner.h:103
std::string pickupTemplateName_
The name of the pickup template.
Definition: PickupSpawner.h:155
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Timer respawnTimer_
Timer used for re-activating.
Definition: PickupSpawner.h:164
Mode
Definition: CorePrereqs.h:102
bool selfDestruct_
True if the PickupSpawner is selfdestructing.
Definition: PickupSpawner.h:167
Definition: Context.h:45
void block(PickupCarrier *carrier, unsigned int time=DEFAULT_BLOCKED_TIME)
Helper method.
Definition: PickupSpawner.h:147
The PickupSpawner class is responsible for spawning @ref orxonox::Pickupable "Pickupables" of a speci...
Definition: PickupSpawner.h:76
Pickupable * pickup_
The pickup to be spawned.
Definition: PickupSpawner.h:153
The PickupCarrier interface provides the means, for any class implementing it, to possess Pickupables...
Definition: PickupCarrier.h:68
int maxSpawnedItems_
Maximum number of items spawned by this PickupSpawner.
Definition: PickupSpawner.h:158
Shared library macros, enums, constants and forward declarations for the questsystem module ...
std::map< PickupCarrier *, std::time_t > blocked_
Definition: PickupSpawner.h:165
The Tickable interface provides a tick(dt) function, that gets called every frame.
Definition: Tickable.h:52
void setRespawnTime(float time)
Set the time to respawn.
Definition: PickupSpawner.h:109
Timer is a helper class that executes a function after a given amount of seconds in game-time...
Definition: Timer.h:105
Template * pickupTemplate_
The template to be used to create a pickupable.
Definition: PickupSpawner.h:156
void setTriggerDistance(float value)
Set the distance in which to trigger.
Definition: PickupSpawner.h:97
Definition of the Pickupable class.