Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8495 was 8068, checked in by patrick, 19 years ago

trunk: merged the network branche back to trunk

File size: 3.0 KB
RevLine 
[6080]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
[8068]12#include <map>
13
[6083]14class World;
[6086]15class TiXmlElement;
[6083]16
[7357]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 */
[6080]36class SpawningPoint : public WorldEntity {
37
38  public:
[7357]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);
[6080]41    virtual ~SpawningPoint ();
[6088]42    void init();
[6080]43
[6512]44    virtual void loadParams(const TiXmlElement* root);
[6086]45
[6081]46    /**  sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */
[8068]47    void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }
[6081]48    /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
[7357]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; }
[6081]52
[8068]53    void pushEntity(WorldEntity* entity, float delay = 0);
[6080]54
[7357]55    /** activates the spawning point */
[8068]56    inline void activate() { this->bSpawning = true; }
[7357]57    /** deactivates the spawning point */
[8068]58    inline void deactivate() { this->bSpawning = false; }
59    inline bool isActive() const { return this->bSpawning; }
[7357]60
61
[6080]62    virtual void tick(float dt);
63    virtual void draw();
64
[7357]65
[6080]66  private:
[8068]67    void spawn(WorldEntity* entity);
[6080]68
[7357]69
70  private:
[8068]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
[6080]78};
79
80#endif /* _SPAWNING_POINT */
Note: See TracBrowser for help on using the repository browser.