/*! * @file spawning_point.h * Definition of a spawning point within the game, used for network game */ #ifndef _SPAWNING_POINT #define _SPAWNING_POINT #include "world_entity.h" class World; class TiXmlElement; //!< used to indicate what type of objects are spawned by this spawning point typedef enum SpawningPointMode { SPT_ALL_AT_ONCE = 0, //!< at this spawning points there will be players spawned (typicaly in MP games) SPT_ONE_AFTER_OTHER, //!< at this spawning points there will be NPS spawnded SPT_NUMBER }; /** * The spawning point for WorldEntities (and only WorldEntities) * * There are commonly two different spawning modes: * * 1) Just spawn whatever is in the queue with a given frequency (if delay = 0 => immediate spawn) * 2) Spawn everything in the queue together with the given frequency */ class SpawningPoint : public WorldEntity { public: SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0)); SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay); virtual ~SpawningPoint (); void init(); virtual void loadParams(const TiXmlElement* root); /** sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */ void SpawningPoint::setSpawningEntity(ClassID classID) { this->classID = classID; } /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */ void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; } /** sets the spawning point mode @param mode: the mode */ void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; } /** activates the spawning point */ void activate() { this->bSpawning = true; } /** deactivates the spawning point */ void deactivate() { this->bSpawning = false; } virtual void tick(float dt); virtual void draw(); private: void spawn(); private: float delay; //!< the timer that counts down until the next spawn float localTimer; //!< the local timer float seed; //!< the random seed of the position ClassID classID; //!< the classid of the entity to spawn SpawningPointMode mode; //!< the mode of the spawning point std::list queue; //!< queue of waiting WorldEntities to be spawned bool bSpawning; //!< flag to indicate if this spawning point is active or not }; #endif /* _SPAWNING_POINT */