Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8998 was 8802, checked in by patrick, 18 years ago

merged the network branche back to trunk

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