Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/spawning_point.h @ 8798

Last change on this file since 8798 was 8798, checked in by rennerc, 18 years ago

network changes

File size: 3.2 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    inline int getTeamId(){ return this->teamId; }
54    inline void setTeamId( int teamId ){ this->teamId = teamId; }
55
56    void pushEntity(WorldEntity* entity, float delay = 0);
57
58    /** activates the spawning point */
59    inline void activate() { this->bSpawning = true; }
60    /** deactivates the spawning point */
61    inline void deactivate() { this->bSpawning = false; }
62    inline bool isActive() const { return this->bSpawning; }
63
64
65    virtual void tick(float dt);
66    virtual void draw();
67
68
69  private:
70    void spawn(WorldEntity* entity);
71
72
73  private:
74    float                           delay;                          //!< the timer that counts down until the next spawn
75    float                           localTimer;                     //!< the local timer
76    float                           seed;                           //!< the random seed of the position
77    int                             teamId;                         //!< only spawn players of this team
78    ClassID                         classid;                        //!< the classid of the entity to spawn
79    SpawningPointMode               mode;                           //!< the mode of the spawning point
80    std::map<WorldEntity*, float>   queue;                          //!< queue of waiting WorldEntities to be spawned
81    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
82};
83
84#endif /* _SPAWNING_POINT */
Note: See TracBrowser for help on using the repository browser.