Changeset 2485 for code/branches/presentation/src/orxonox/objects/gametypes
- Timestamp:
- Dec 16, 2008, 6:01:13 PM (15 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/objects/gametypes/Gametype.cc
r2171 r2485 34 34 35 35 #include "core/CoreIncludes.h" 36 #include "core/ConfigValueIncludes.h" 36 37 #include "objects/infos/PlayerInfo.h" 38 #include "objects/infos/Bot.h" 37 39 #include "objects/worldentities/pawns/Spectator.h" 38 40 #include "objects/worldentities/SpawnPoint.h" 41 #include "objects/worldentities/Camera.h" 39 42 40 43 #include "network/Host.h" … … 44 47 CreateUnloadableFactory(Gametype); 45 48 46 Gametype::Gametype(BaseObject* creator) : BaseObject(creator) 49 Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator) 47 50 { 48 51 RegisterObject(Gametype); 49 52 53 this->setGametype(this); 54 50 55 this->defaultControllableEntity_ = Class(Spectator); 51 56 52 this->bStarted_ = false;53 this->bEnded_ = false;54 57 this->bAutoStart_ = false; 55 58 this->bForceSpawn_ = false; 59 this->numberOfBots_ = 0; 56 60 57 61 this->initialStartCountdown_ = 3; 58 this->startCountdown_ = 0; 59 this->bStartCountdownRunning_ = false; 62 63 this->setConfigValues(); 64 65 this->addBots(this->numberOfBots_); 66 } 67 68 void Gametype::setConfigValues() 69 { 70 SetConfigValue(initialStartCountdown_, 3.0f); 71 SetConfigValue(bAutoStart_, false); 72 SetConfigValue(bForceSpawn_, false); 73 SetConfigValue(numberOfBots_, 0); 60 74 } 61 75 62 76 void Gametype::tick(float dt) 63 77 { 64 if (this->bStartCountdownRunning_ && !this->bStarted_) 65 this->startCountdown_ -= dt; 66 67 if (!this->bStarted_) 78 SUPER(Gametype, tick, dt); 79 80 if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_) 81 this->gtinfo_.startCountdown_ -= dt; 82 83 if (!this->gtinfo_.bStarted_) 68 84 this->checkStart(); 69 85 else … … 76 92 { 77 93 COUT(0) << "game started" << std::endl; 78 this-> bStarted_ = true;94 this->gtinfo_.bStarted_ = true; 79 95 80 96 this->spawnPlayersIfRequested(); … … 84 100 { 85 101 COUT(0) << "game ended" << std::endl; 86 this-> bEnded_ = true;102 this->gtinfo_.bEnded_ = true; 87 103 } 88 104 … … 140 156 void Gametype::pawnKilled(Pawn* victim, Pawn* killer) 141 157 { 158 if (victim && victim->getPlayer()) 159 { 160 std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(victim->getPlayer()); 161 if (it != this->players_.end()) 162 { 163 it->second = PlayerState::Dead; 164 165 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 166 if (victim->getCamera()) 167 { 168 entity->setPosition(victim->getCamera()->getWorldPosition()); 169 entity->setOrientation(victim->getCamera()->getWorldOrientation()); 170 } 171 else 172 { 173 entity->setPosition(victim->getWorldPosition()); 174 entity->setOrientation(victim->getWorldOrientation()); 175 } 176 it->first->startControl(entity); 177 } 178 else 179 COUT(2) << "Warning: Killed Pawn was not in the playerlist" << std::endl; 180 } 142 181 } 143 182 … … 150 189 if (this->spawnpoints_.size() > 0) 151 190 { 152 srand(time(0));153 rnd();154 155 191 unsigned int randomspawn = (unsigned int)rnd(this->spawnpoints_.size()); 156 192 unsigned int index = 0; … … 170 206 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 171 207 { 172 if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_)) 173 { 174 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); 175 if (spawn) 176 { 177 // force spawn at spawnpoint with default pawn 178 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 179 spawn->spawn(entity); 180 it->first->startControl(entity); 181 it->second = PlayerState::Dead; 208 if (!it->first->getControllableEntity()) 209 { 210 it->second = PlayerState::Dead; 211 212 if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_) 213 { 214 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); 215 if (spawn) 216 { 217 // force spawn at spawnpoint with default pawn 218 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 219 spawn->spawn(entity); 220 it->first->startControl(entity); 221 it->second = PlayerState::Dead; 222 } 223 else 224 { 225 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 226 abort(); 227 } 228 } 229 } 230 } 231 } 232 233 void Gametype::checkStart() 234 { 235 if (!this->gtinfo_.bStarted_) 236 { 237 if (this->gtinfo_.bStartCountdownRunning_) 238 { 239 if (this->gtinfo_.startCountdown_ <= 0) 240 { 241 this->gtinfo_.bStartCountdownRunning_ = false; 242 this->gtinfo_.startCountdown_ = 0; 243 this->start(); 244 } 245 } 246 else if (this->players_.size() > 0) 247 { 248 if (this->bAutoStart_) 249 { 250 this->start(); 182 251 } 183 252 else 184 253 { 185 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;186 abort();187 }188 }189 }190 }191 192 void Gametype::checkStart()193 {194 if (!this->bStarted_)195 {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)206 {207 if (this->bAutoStart_)208 {209 this->start();210 }211 else212 {213 254 bool allplayersready = true; 255 bool hashumanplayers = false; 214 256 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 215 257 { 216 258 if (!it->first->isReadyToSpawn()) 217 259 allplayersready = false; 260 if (it->first->isHumanPlayer()) 261 hashumanplayers = true; 218 262 } 219 if (allplayersready )263 if (allplayersready && hashumanplayers) 220 264 { 221 this-> startCountdown_ = this->initialStartCountdown_;222 this-> bStartCountdownRunning_ = true;265 this->gtinfo_.startCountdown_ = this->initialStartCountdown_; 266 this->gtinfo_.bStartCountdownRunning_ = true; 223 267 } 224 268 } … … 256 300 } 257 301 } 302 303 void Gametype::addBots(unsigned int amount) 304 { 305 for (unsigned int i = 0; i < amount; ++i) 306 new Bot(this); 307 } 308 309 void Gametype::killBots(unsigned int amount) 310 { 311 unsigned int i = 0; 312 for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); ) 313 { 314 if (it->getGametype() == this) 315 { 316 delete (*(it++)); 317 ++i; 318 } 319 } 320 } 258 321 } -
code/branches/presentation/src/orxonox/objects/gametypes/Gametype.h
r2171 r2485 38 38 #include "objects/worldentities/ControllableEntity.h" 39 39 #include "objects/Tickable.h" 40 #include "objects/infos/GametypeInfo.h" 40 41 41 42 namespace orxonox … … 60 61 virtual ~Gametype() {} 61 62 63 void setConfigValues(); 64 62 65 virtual void tick(float dt); 63 66 67 inline const GametypeInfo* getGametypeInfo() const 68 { return &this->gtinfo_; } 69 64 70 inline bool hasStarted() const 65 { return this-> bStarted_; }71 { return this->gtinfo_.bStarted_; } 66 72 inline bool hasEnded() const 67 { return this-> bEnded_; }73 { return this->gtinfo_.bEnded_; } 68 74 69 75 virtual void start(); … … 88 94 89 95 inline bool isStartCountdownRunning() const 90 { return this-> bStartCountdownRunning_; }96 { return this->gtinfo_.bStartCountdownRunning_; } 91 97 inline float getStartCountdown() const 92 { return this->startCountdown_; } 98 { return this->gtinfo_.startCountdown_; } 99 100 void addBots(unsigned int amount); 101 void killBots(unsigned int amount = 0); 93 102 94 103 private: … … 104 113 void spawnDeadPlayersIfRequested(); 105 114 106 bool bStarted_;107 bool bEnded_; 115 GametypeInfo gtinfo_; 116 108 117 bool bAutoStart_; 109 118 bool bForceSpawn_; 110 119 111 120 float initialStartCountdown_; 112 float startCountdown_; 113 bool bStartCountdownRunning_; 121 unsigned int numberOfBots_; 114 122 115 123 std::map<PlayerInfo*, PlayerState::Enum> players_;
Note: See TracChangeset
for help on using the changeset viewer.