Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/spawning_point.h @ 8776

Last change on this file since 8776 was 8068, checked in by patrick, 18 years ago

trunk: merged the network branche back to trunk

File size: 3.0 KB
Line 
1/*!
2 * @file spawning_point.h
3 *  Definition of a spawning point within the game, used for network game
4 */
5
6
7#ifndef _SPAWNING_POINT
8#define _SPAWNING_POINT
9
10#include "world_entity.h"
11
12#include <map>
13
14class World;
15class TiXmlElement;
16
17
18//!< used to indicate what type of objects are spawned by this spawning point
19typedef enum SpawningPointMode
20{
21  SPT_ALL_AT_ONCE = 0,                               //!< at this spawning points there will be players spawned (typicaly in MP games)
22  SPT_ONE_AFTER_OTHER,                               //!< at this spawning points there will be NPS spawnded
23
24  SPT_NUMBER
25};
26
27
28/**
29 * The spawning point for WorldEntities (and only WorldEntities)
30 *
31 * There are commonly two different spawning modes:
32 *
33 *  1) Just spawn whatever is in the queue with a given frequency (if delay = 0 => immediate spawn)
34 *  2) Spawn everything in the queue together with the given frequency
35 */
36class SpawningPoint : public WorldEntity {
37
38  public:
39    SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0));
40    SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay);
41    virtual ~SpawningPoint ();
42    void init();
43
44    virtual void loadParams(const TiXmlElement* root);
45
46    /**  sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */
47    void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }
48    /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
49    void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; }
50    /** sets the spawning point mode @param mode: the mode */
51    void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
52
53    void pushEntity(WorldEntity* entity, float delay = 0);
54
55    /** activates the spawning point */
56    inline void activate() { this->bSpawning = true; }
57    /** deactivates the spawning point */
58    inline void deactivate() { this->bSpawning = false; }
59    inline bool isActive() const { return this->bSpawning; }
60
61
62    virtual void tick(float dt);
63    virtual void draw();
64
65
66  private:
67    void spawn(WorldEntity* entity);
68
69
70  private:
71    float                           delay;                          //!< the timer that counts down until the next spawn
72    float                           localTimer;                     //!< the local timer
73    float                           seed;                           //!< the random seed of the position
74    ClassID                         classid;                        //!< the classid of the entity to spawn
75    SpawningPointMode               mode;                           //!< the mode of the spawning point
76    std::map<WorldEntity*, float>   queue;                          //!< queue of waiting WorldEntities to be spawned
77    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
78};
79
80#endif /* _SPAWNING_POINT */
Note: See TracBrowser for help on using the repository browser.