[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 | |
---|
[6083] | 12 | class World; |
---|
[6086] | 13 | class TiXmlElement; |
---|
[6083] | 14 | |
---|
[7357] | 15 | |
---|
| 16 | //!< used to indicate what type of objects are spawned by this spawning point |
---|
| 17 | typedef enum SpawningPointMode |
---|
| 18 | { |
---|
| 19 | SPT_ALL_AT_ONCE = 0, //!< at this spawning points there will be players spawned (typicaly in MP games) |
---|
| 20 | SPT_ONE_AFTER_OTHER, //!< at this spawning points there will be NPS spawnded |
---|
| 21 | |
---|
| 22 | SPT_NUMBER |
---|
| 23 | }; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * The spawning point for WorldEntities (and only WorldEntities) |
---|
| 28 | * |
---|
| 29 | * There are commonly two different spawning modes: |
---|
| 30 | * |
---|
| 31 | * 1) Just spawn whatever is in the queue with a given frequency (if delay = 0 => immediate spawn) |
---|
| 32 | * 2) Spawn everything in the queue together with the given frequency |
---|
| 33 | */ |
---|
[6080] | 34 | class SpawningPoint : public WorldEntity { |
---|
| 35 | |
---|
| 36 | public: |
---|
[7357] | 37 | SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0)); |
---|
| 38 | SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay); |
---|
[6080] | 39 | virtual ~SpawningPoint (); |
---|
[6088] | 40 | void init(); |
---|
[6080] | 41 | |
---|
[6512] | 42 | virtual void loadParams(const TiXmlElement* root); |
---|
[6086] | 43 | |
---|
[6081] | 44 | /** sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */ |
---|
[6093] | 45 | void SpawningPoint::setSpawningEntity(ClassID classID) { this->classID = classID; } |
---|
[6081] | 46 | /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */ |
---|
[7357] | 47 | void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; } |
---|
| 48 | /** sets the spawning point mode @param mode: the mode */ |
---|
| 49 | void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; } |
---|
[6081] | 50 | |
---|
[6080] | 51 | |
---|
[7357] | 52 | /** activates the spawning point */ |
---|
| 53 | void activate() { this->bSpawning = true; } |
---|
| 54 | /** deactivates the spawning point */ |
---|
| 55 | void deactivate() { this->bSpawning = false; } |
---|
| 56 | |
---|
| 57 | |
---|
[6080] | 58 | virtual void tick(float dt); |
---|
| 59 | virtual void draw(); |
---|
| 60 | |
---|
[7357] | 61 | |
---|
[6080] | 62 | private: |
---|
[7357] | 63 | void spawn(); |
---|
[6080] | 64 | |
---|
[7357] | 65 | |
---|
| 66 | private: |
---|
| 67 | float delay; //!< the timer that counts down until the next spawn |
---|
| 68 | float localTimer; //!< the local timer |
---|
| 69 | float seed; //!< the random seed of the position |
---|
| 70 | ClassID classID; //!< the classid of the entity to spawn |
---|
| 71 | SpawningPointMode mode; //!< the mode of the spawning point |
---|
[7370] | 72 | ObjectManager::EntityList queue; //!< queue of waiting WorldEntities to be spawned |
---|
[7357] | 73 | bool bSpawning; //!< flag to indicate if this spawning point is active or not |
---|
[6080] | 74 | }; |
---|
| 75 | |
---|
| 76 | #endif /* _SPAWNING_POINT */ |
---|