Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7357 in orxonox.OLD


Ignore:
Timestamp:
Apr 21, 2006, 11:45:52 AM (18 years ago)
Author:
patrick
Message:

spawning point reviewed

Location:
trunk/src/world_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/spawning_point.cc

    r7198 r7357  
    2424
    2525/**
    26  *  standard constructor
     26 *  constructor
    2727 */
    28 SpawningPoint::SpawningPoint (World* world, const Vector& absCoordinate)
     28SpawningPoint::SpawningPoint (ClassID classID, const Vector& position)
    2929{
    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;
    3334
    3435  this->init();
     
    3738
    3839/**
    39  *  constructor
     40 *  standard constructor
    4041 */
    41 SpawningPoint::SpawningPoint (const Vector& position, float frequency,
    42                               float seed, ClassID classID, World* world)
     42SpawningPoint::SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode mode, float delay)
    4343{
    44   this->frequency = frequency;
    45   this->seed = seed;
     44  this->setAbsCoor(position);
    4645  this->classID = classID;
    47   this->world = world;
     46  this->mode = mode;
     47  this->delay = delay;
    4848
    4949  this->init();
     
    5151
    5252
     53
    5354void SpawningPoint::init()
    5455{
    55   this->countDown = 0.0f;
     56  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
    5657}
    5758
     
    7475
    7576  /* 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");
    7979
    8080
    8181  /* 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");
    8584
    8685  /* now load the seed */
     
    9695void SpawningPoint::spawn()
    9796{
    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);
    101101
    102102//   if( likely(this->world != NULL))
     
    113113void SpawningPoint::tick(float dt)
    114114{
    115   this->countDown += dt;
    116   if( this->countDown > this->frequency)
     115  this->localTimer += dt;
     116  if( this->localTimer > this->delay)
    117117  {
    118118    this->spawn();
    119     this->countDown = 0.0f;
     119    this->localTimer = 0.0f;
    120120  }
    121121}
  • trunk/src/world_entities/spawning_point.h

    r6512 r7357  
    1313class TiXmlElement;
    1414
    15 //! The spawning point for world entities
     15
     16//!< used to indicate what type of objects are spawned by this spawning point
     17typedef 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 */
    1634class SpawningPoint : public WorldEntity {
    1735
    1836  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);
    2139    virtual ~SpawningPoint ();
    2240    void init();
     
    2745    void SpawningPoint::setSpawningEntity(ClassID classID) { this->classID = classID; }
    2846    /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */
    29     void SpawningPoint::setSpawningFrequency(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::setPositionSeed(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; }
    3250
    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
    3457
    3558    virtual void tick(float dt);
    3659    virtual void draw();
    3760
     61
    3862  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();
    4464
     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
    4574};
    4675
Note: See TracChangeset for help on using the changeset viewer.