- Timestamp:
- Apr 21, 2006, 11:45:52 AM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/spawning_point.cc
r7198 r7357 24 24 25 25 /** 26 * standardconstructor26 * constructor 27 27 */ 28 SpawningPoint::SpawningPoint ( World* world, const Vector& absCoordinate)28 SpawningPoint::SpawningPoint (ClassID classID, const Vector& position) 29 29 { 30 this->world = world; 31 this->frequency = 0.5f; 32 this->seed = 0.0f; 30 this->setAbsCoor(position); 31 this->classID = classID; 32 this->mode = SPT_ALL_AT_ONCE; 33 this->delay = 0; 33 34 34 35 this->init(); … … 37 38 38 39 /** 39 * constructor40 * standard constructor 40 41 */ 41 SpawningPoint::SpawningPoint (const Vector& position, float frequency, 42 float seed, ClassID classID, World* world) 42 SpawningPoint::SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode mode, float delay) 43 43 { 44 this->frequency = frequency; 45 this->seed = seed; 44 this->setAbsCoor(position); 46 45 this->classID = classID; 47 this->world = world; 46 this->mode = mode; 47 this->delay = delay; 48 48 49 49 this->init(); … … 51 51 52 52 53 53 54 void SpawningPoint::init() 54 55 { 55 this-> countDown = 0.0f;56 this->setClassID(CL_SPAWNING_POINT, "SpawningPoint"); 56 57 } 57 58 … … 74 75 75 76 /* now load the frequency */ 76 LoadParam(root, "frequency", this, SpawningPoint, setSpawningFrequency) 77 .describe("sets the frequency of the spawning point") 78 .defaultValues(1.0f); 77 LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay) 78 .describe("sets the delay of the spawning point"); 79 79 80 80 81 81 /* now load the seed */ 82 LoadParam(root, "randomseed", this, SpawningPoint, setPositionSeed) 83 .describe("sets the random position seed (variance in the spawning location around the position)") 84 .defaultValues(0.0f); 82 // LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity) 83 // .describe("sets the spawning entity"); 85 84 86 85 /* now load the seed */ … … 96 95 void SpawningPoint::spawn() 97 96 { 98 PRINTF(5)("Spangingpoint creates a new Entity (id: %i, frequency: %f, seed: %f)\n", this->classID, 99 this->frequency, this->seed); 100 BaseObject* spawningEntity = Factory::fabricate(this->classID); 97 PRINTF(5)("Spangingpoint creates a new Entity (id: %i, delay: %f, mode: %f)\n", this->classID, 98 this->delay, this->mode); 99 100 //BaseObject* spawningEntity = Factory::fabricate(this->classID); 101 101 102 102 // if( likely(this->world != NULL)) … … 113 113 void SpawningPoint::tick(float dt) 114 114 { 115 this-> countDown+= dt;116 if( this-> countDown > this->frequency)115 this->localTimer += dt; 116 if( this->localTimer > this->delay) 117 117 { 118 118 this->spawn(); 119 this-> countDown= 0.0f;119 this->localTimer = 0.0f; 120 120 } 121 121 } -
trunk/src/world_entities/spawning_point.h
r6512 r7357 13 13 class TiXmlElement; 14 14 15 //! The spawning point for world entities 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 */ 16 34 class SpawningPoint : public WorldEntity { 17 35 18 36 public: 19 SpawningPoint ( World* world, const Vector& absCoordinate= Vector(0.0, 0.0, 0.0));20 SpawningPoint (const Vector& position, float frequency, float seed, ClassID classID, World* world);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); 21 39 virtual ~SpawningPoint (); 22 40 void init(); … … 27 45 void SpawningPoint::setSpawningEntity(ClassID classID) { this->classID = classID; } 28 46 /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */ 29 void SpawningPoint::setSpawning Frequency(float frequency) { this->frequency = frequency; }30 /** sets the seed of the position vector @param seed: the random seed around the given vector*/31 void SpawningPoint::set PositionSeed(float seed) { this->seed = seed; }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; } 32 50 33 void spawn(); 51 52 /** activates the spawning point */ 53 void activate() { this->bSpawning = true; } 54 /** deactivates the spawning point */ 55 void deactivate() { this->bSpawning = false; } 56 34 57 35 58 virtual void tick(float dt); 36 59 virtual void draw(); 37 60 61 38 62 private: 39 float frequency; //!< the frequency for entity spawning 40 float countDown; //!< the timer that counts down until the next spawn 41 float seed; //!< the random seed of the position 42 ClassID classID; //!< the classid of the entity to spawn 43 World* world; //!< reference to the world it belongs to (or in the future: the object manager) 63 void spawn(); 44 64 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 72 std::list<WorldEntity*> queue; //!< queue of waiting WorldEntities to be spawned 73 bool bSpawning; //!< flag to indicate if this spawning point is active or not 45 74 }; 46 75
Note: See TracChangeset
for help on using the changeset viewer.