- Timestamp:
- Oct 28, 2008, 3:05:17 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r2020 r2024 48 48 RegisterObject(Gametype); 49 49 50 this->defaultPawn_ = Class(Spectator); 50 this->defaultControllableEntity_ = Class(Spectator); 51 51 52 this->bStarted_ = false; 52 53 this->bEnded_ = false; 53 54 this->bAutoStart_ = false; 55 this->bForceSpawn_ = false; 56 57 this->initialStartCountdown_ = 3; 58 this->startCountdown_ = 0; 59 this->bStartCountdownRunning_ = false; 54 60 55 61 COUT(0) << "created Gametype" << std::endl; … … 58 64 void Gametype::tick(float dt) 59 65 { 66 if (this->bStartCountdownRunning_ && !this->bStarted_) 67 this->startCountdown_ -= dt; 68 60 69 if (!this->bStarted_) 61 70 this->checkStart(); 62 71 63 72 this->assignDefaultPawnsIfNeeded(); 73 this->spawnDeadPlayersIfRequested(); 64 74 } 65 75 … … 69 79 this->bStarted_ = true; 70 80 71 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 72 this->spawnPlayer(*it); 81 this->spawnPlayersIfRequested(); 73 82 } 74 83 … … 122 131 } 123 132 124 void Gametype::playerSpawned(PlayerInfo* player) 125 { 126 } 127 128 void Gametype::playerDied(PlayerInfo* player) 133 void Gametype::pawnPreSpawn(Pawn* pawn) 134 { 135 } 136 137 void Gametype::pawnPostSpawn(Pawn* pawn) 138 { 139 } 140 141 void Gametype::pawnKilled(Pawn* victim, Pawn* killer) 129 142 { 130 143 } … … 164 177 { 165 178 // force spawn at spawnpoint with default pawn 166 ControllableEntity* newpawn = this->defaultPawn_.fabricate(spawn);167 spawn->spawn( newpawn);168 (*it)->startControl( newpawn);179 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 180 spawn->spawn(entity); 181 (*it)->startControl(entity); 169 182 } 170 183 else … … 181 194 if (!this->bStarted_) 182 195 { 183 if (this->players_.size() > 0) 196 if (this->bStartCountdownRunning_) 197 { 198 if (this->startCountdown_ <= 0) 199 { 200 this->bStartCountdownRunning_ = false; 201 this->startCountdown_ = 0; 202 this->start(); 203 } 204 } 205 else if (this->players_.size() > 0) 184 206 { 185 207 if (this->bAutoStart_) … … 196 218 } 197 219 if (allplayersready) 198 this->start(); 199 } 200 } 201 } 220 { 221 this->startCountdown_ = this->initialStartCountdown_; 222 this->bStartCountdownRunning_ = true; 223 } 224 } 225 } 226 } 227 } 228 229 void Gametype::spawnPlayersIfRequested() 230 { 231 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 232 if ((*it)->isReadyToSpawn() || this->bForceSpawn_) 233 this->spawnPlayer(*it); 234 } 235 236 void Gametype::spawnDeadPlayersIfRequested() 237 { 238 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 239 if (!(*it)->getControllableEntity()) 240 if ((*it)->isReadyToSpawn() || this->bForceSpawn_) 241 this->spawnPlayer(*it); 202 242 } 203 243 204 244 void Gametype::spawnPlayer(PlayerInfo* player) 205 245 { 206 if (player->isReadyToSpawn()) 207 { 208 SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); 209 if (spawnpoint) 210 { 211 player->startControl(spawnpoint->spawn()); 212 } 213 else 214 { 215 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 216 abort(); 217 } 246 SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); 247 if (spawnpoint) 248 { 249 player->startControl(spawnpoint->spawn()); 250 } 251 else 252 { 253 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 254 abort(); 218 255 } 219 256 }
Note: See TracChangeset
for help on using the changeset viewer.