Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/spawning_point.cc @ 8995

Last change on this file since 8995 was 8802, checked in by patrick, 18 years ago

merged the network branche back to trunk

File size: 3.7 KB
RevLine 
[6080]1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12### File Specific:
13   main-programmer: Patrick Boenzli
14   co-programmer:
15*/
16
17#include "spawning_point.h"
[6424]18
[7193]19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
[6424]21
[8068]22#include "world_entity.h"
23
[6093]24#include "compiler.h"
[6080]25
[8802]26#include "state.h"
27#include "game_rules.h"
[6424]28
[8068]29
[6080]30/**
[7357]31 *  constructor
[6080]32 */
[8068]33SpawningPoint::SpawningPoint (ClassID classid, const Vector& position)
[6084]34{
[7357]35  this->setAbsCoor(position);
[8068]36  this->classid = classid;
[7357]37  this->mode = SPT_ALL_AT_ONCE;
38  this->delay = 0;
[6088]39
40  this->init();
[6084]41}
[6080]42
43
44/**
[7357]45 *  standard constructor
[6081]46 */
[8068]47SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay)
[6081]48{
[7357]49  this->setAbsCoor(position);
[8068]50  this->classid = classid;
[7357]51  this->mode = mode;
52  this->delay = delay;
[6088]53
54  this->init();
55}
56
57
[7357]58
[6088]59void SpawningPoint::init()
60{
[7357]61  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
[8802]62 
63  this->teamId = -1;
[6081]64}
65
66
67/**
[6080]68 *  deconstructor
69 */
70SpawningPoint::~SpawningPoint ()
71{}
72
73
[6081]74/**
[6086]75 * loads the WorldEntity Specific Parameters.
76 * @param root: the XML-Element to load the Data From
77 */
78void SpawningPoint::loadParams(const TiXmlElement* root)
79{
[6087]80  /* let the world entity its stuff first */
[6512]81  WorldEntity::loadParams(root);
[6086]82
[6087]83  /* now load the frequency */
[7357]84  LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
85      .describe("sets the delay of the spawning point");
[8802]86     
87  /* load teamId */
88  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
89      .describe("sets teamId");
[6086]90
[6087]91
92  /* now load the seed */
[7357]93//   LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity)
94//       .describe("sets the spawning entity");
[6087]95
96  /* now load the seed */
[6093]97/*  LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)
[6088]98      .describe("sets the class id of the entity to spawn")
[7198]99      .defaultValues(CL_WORLD_ENTITY);*/
[6086]100}
101
102
[8068]103
[6086]104/**
[8068]105 * pushes a world entity to the spawning queue
106 *  @param entity WorldEntity to be added
107 */
108void SpawningPoint::pushEntity(WorldEntity* entity, float delay)
109{
[8802]110  QueueEntry qe;
111  qe.entity = entity;
112  qe.list = entity->getOMListNumber();
113  qe.respawnTime = this->localTimer + delay;
114 
115  queue.push_back( qe );
[8068]116}
117
118
119/**
[6081]120 *  spawn the entity
121 */
[8068]122void SpawningPoint::spawn(WorldEntity* entity)
[6083]123{
[8068]124  PRINTF(1)("Spawningpoint spawns new Entity (%s)\n", entity->getClassName());
[6424]125
[8068]126
[8802]127  entity->setAbsCoor( this->getAbsCoor() );
128  entity->setAbsDir( this->getAbsDir() );
129 
130  //TODO set camera (not smooth)
[6083]131}
[6080]132
133
134/**
135 *  this method is called every frame
136 * @param time: the time in seconds that has passed since the last tick
137 *
138 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
139 */
140void SpawningPoint::tick(float dt)
[6084]141{
[7357]142  this->localTimer += dt;
[8068]143
[8802]144  std::list<QueueEntry>::iterator it = this->queue.begin();
145  for( ; it != this->queue.end(); )
[6084]146  {
[8802]147   
148    if( it->respawnTime <= this->localTimer)
[8068]149    {
150      //spawn the player
[8802]151      this->spawn(it->entity);
152     
153      it->entity->toList( it->list );
154     
155      if ( State::getGameRules() )
156      {
157        (State::getGameRules())->registerSpawn( it->entity );
158      }
159     
160      std::list<QueueEntry>::iterator delit = it;
161      it++;
162     
163      queue.erase( delit );
164     
165      continue;
[8068]166    }
[8802]167   
168    it++;
[6084]169  }
[8068]170
[6084]171}
[6080]172
173
174/**
175 *  the entity is drawn onto the screen with this function
176 *
177 * This is a central function of an entity: call it to let the entity painted to the screen.
178 * Just override this function with whatever you want to be drawn.
179 */
180void SpawningPoint::draw()
[6087]181{}
Note: See TracBrowser for help on using the repository browser.