Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the network branche back to trunk

File size: 3.7 KB
Line 
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"
18
19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
21
22#include "world_entity.h"
23
24#include "compiler.h"
25
26#include "state.h"
27#include "game_rules.h"
28
29
30/**
31 *  constructor
32 */
33SpawningPoint::SpawningPoint (ClassID classid, const Vector& position)
34{
35  this->setAbsCoor(position);
36  this->classid = classid;
37  this->mode = SPT_ALL_AT_ONCE;
38  this->delay = 0;
39
40  this->init();
41}
42
43
44/**
45 *  standard constructor
46 */
47SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay)
48{
49  this->setAbsCoor(position);
50  this->classid = classid;
51  this->mode = mode;
52  this->delay = delay;
53
54  this->init();
55}
56
57
58
59void SpawningPoint::init()
60{
61  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
62 
63  this->teamId = -1;
64}
65
66
67/**
68 *  deconstructor
69 */
70SpawningPoint::~SpawningPoint ()
71{}
72
73
74/**
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{
80  /* let the world entity its stuff first */
81  WorldEntity::loadParams(root);
82
83  /* now load the frequency */
84  LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
85      .describe("sets the delay of the spawning point");
86     
87  /* load teamId */
88  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
89      .describe("sets teamId");
90
91
92  /* now load the seed */
93//   LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity)
94//       .describe("sets the spawning entity");
95
96  /* now load the seed */
97/*  LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)
98      .describe("sets the class id of the entity to spawn")
99      .defaultValues(CL_WORLD_ENTITY);*/
100}
101
102
103
104/**
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{
110  QueueEntry qe;
111  qe.entity = entity;
112  qe.list = entity->getOMListNumber();
113  qe.respawnTime = this->localTimer + delay;
114 
115  queue.push_back( qe );
116}
117
118
119/**
120 *  spawn the entity
121 */
122void SpawningPoint::spawn(WorldEntity* entity)
123{
124  PRINTF(1)("Spawningpoint spawns new Entity (%s)\n", entity->getClassName());
125
126
127  entity->setAbsCoor( this->getAbsCoor() );
128  entity->setAbsDir( this->getAbsDir() );
129 
130  //TODO set camera (not smooth)
131}
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)
141{
142  this->localTimer += dt;
143
144  std::list<QueueEntry>::iterator it = this->queue.begin();
145  for( ; it != this->queue.end(); )
146  {
147   
148    if( it->respawnTime <= this->localTimer)
149    {
150      //spawn the player
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;
166    }
167   
168    it++;
169  }
170
171}
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()
181{}
Note: See TracBrowser for help on using the repository browser.