[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 | |
---|
[8802] | 10 | #include "playable.h" |
---|
[6080] | 11 | |
---|
[8802] | 12 | #include <list> |
---|
[8068] | 13 | |
---|
[6083] | 14 | class World; |
---|
[6086] | 15 | class TiXmlElement; |
---|
[6083] | 16 | |
---|
[8802] | 17 | struct QueueEntry |
---|
| 18 | { |
---|
| 19 | float respawnTime; |
---|
| 20 | WorldEntity * entity; |
---|
| 21 | OM_LIST list; |
---|
| 22 | }; |
---|
[7357] | 23 | |
---|
| 24 | //!< used to indicate what type of objects are spawned by this spawning point |
---|
| 25 | typedef 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 | */ |
---|
[6080] | 42 | class SpawningPoint : public WorldEntity { |
---|
| 43 | |
---|
| 44 | public: |
---|
[7357] | 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); |
---|
[6080] | 47 | virtual ~SpawningPoint (); |
---|
[6088] | 48 | void init(); |
---|
[6080] | 49 | |
---|
[6512] | 50 | virtual void loadParams(const TiXmlElement* root); |
---|
[6086] | 51 | |
---|
[6081] | 52 | /** sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */ |
---|
[8068] | 53 | void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; } |
---|
[6081] | 54 | /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */ |
---|
[7357] | 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; } |
---|
[8802] | 58 | |
---|
| 59 | inline int getTeamId(){ return this->teamId; } |
---|
| 60 | inline void setTeamId( int teamId ){ this->teamId = teamId; } |
---|
[6081] | 61 | |
---|
[8068] | 62 | void pushEntity(WorldEntity* entity, float delay = 0); |
---|
[6080] | 63 | |
---|
[7357] | 64 | /** activates the spawning point */ |
---|
[8068] | 65 | inline void activate() { this->bSpawning = true; } |
---|
[7357] | 66 | /** deactivates the spawning point */ |
---|
[8068] | 67 | inline void deactivate() { this->bSpawning = false; } |
---|
| 68 | inline bool isActive() const { return this->bSpawning; } |
---|
[7357] | 69 | |
---|
| 70 | |
---|
[6080] | 71 | virtual void tick(float dt); |
---|
| 72 | virtual void draw(); |
---|
| 73 | |
---|
[7357] | 74 | |
---|
[6080] | 75 | private: |
---|
[8068] | 76 | void spawn(WorldEntity* entity); |
---|
[6080] | 77 | |
---|
[7357] | 78 | |
---|
| 79 | private: |
---|
[8068] | 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 |
---|
[8802] | 83 | int teamId; //!< only spawn players of this team |
---|
[8068] | 84 | ClassID classid; //!< the classid of the entity to spawn |
---|
| 85 | SpawningPointMode mode; //!< the mode of the spawning point |
---|
[8802] | 86 | std::list<QueueEntry> queue; //!< queue of waiting WorldEntities to be spawned |
---|
[8068] | 87 | bool bSpawning; //!< flag to indicate if this spawning point is active or not |
---|
[6080] | 88 | }; |
---|
| 89 | |
---|
| 90 | #endif /* _SPAWNING_POINT */ |
---|