[9098] | 1 | /* |
---|
[9112] | 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
[9098] | 4 | * |
---|
[9112] | 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
[10258] | 22 | * Author: |
---|
[9112] | 23 | * |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | *NACHRICHT: |
---|
| 28 | * |
---|
| 29 | * Hier empfehle ich euch die gesamte Spielogik unter zu bringen. Viele Funktionen werden automatisch |
---|
| 30 | * bei gewissen Ereignissen aufgerufen bzw. lösen Ereignisse aus |
---|
| 31 | * |
---|
| 32 | *Z.B: |
---|
| 33 | * start() //wird aufgerufen, bevor das Spiel losgeht |
---|
| 34 | * end() //wenn man diese Funktion aufruft wird |
---|
| 35 | * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn ) |
---|
| 36 | * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben. |
---|
| 37 | * |
---|
| 38 | * |
---|
| 39 | *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: |
---|
| 40 | * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter |
---|
| 41 | * tippt, werden die Vorschläge entsprechend gefiltert. |
---|
| 42 | * |
---|
| 43 | * |
---|
| 44 | *TIPP: schaut euch mal Tetris::createStone() an. Dort wird ein TetrisStone-Objekt (ControllableEntity) erzeugt, |
---|
| 45 | * ihm ein Template zugewiesen (welches vorher im Level definiert wurde und dem CenterPoint übergeben wurde) |
---|
| 46 | * Ähnlich könnt ihr vorgehen, um einen Turm zu erzeugen. (Zusätzlich braucht ein Turm noch einen Controller) |
---|
| 47 | * z.B: WaypointPatrolController. Wenn kein Team zugewiesen wurde bekämpft ein WaypointPatrolController alles, |
---|
| 48 | * was in seiner Reichweite liegt. |
---|
| 49 | * |
---|
[9143] | 50 | * |
---|
| 51 | *HUD: |
---|
| 52 | * Ein Gametype kann ein HUD (Head up Display haben.) Z.B: hat Pong eine Anzeige welcher Spieler wieviele Punkte hat. |
---|
| 53 | * Generell kann man a) Grafiken oder b) Zeichen in einer HUD anzeigen. |
---|
| 54 | * Fuer den ersten Schritt reicht reiner Text. |
---|
| 55 | * |
---|
| 56 | * a) |
---|
| 57 | * PongScore.cc uebernehmen und eigene Klasse draus machen. |
---|
| 58 | * Wenn ihr bloss anzeigen wollt wieviele Punkte der Spieler bereits erspielt hat (Punkte = Kapital fuer neue Tuerme) dann orientiert ihr euch an |
---|
| 59 | * TetrisScore.cc (im pCuts branch): http://www.orxonox.net/browser/code/branches/pCuts/src/modules/tetris/TetrisScore.cc |
---|
| 60 | * Ich habe TetrisScore lediglich dazu gebraucht, um eine Variable auf dem HUD auszugeben. Ein Objekt fuer statischen Text gibt es bereits. |
---|
| 61 | * |
---|
| 62 | * b) |
---|
| 63 | * Im naesten Schritt erstellt man die Vorlage fuer das HUD-Objekt: siehe /data/overlays/pongHUD |
---|
| 64 | * OverlayText ist eine Vorlage fuer statischen text zb: "Points Scored:". Aus mir nicht erklaerlichen Gruenden sollte man die OverlayText |
---|
| 65 | * Objekte immer erst nach dem PongScore anlegen. |
---|
| 66 | * |
---|
[9180] | 67 | * c) Im TowerDefense gamtype muss im Constructor noch das HUD-Template gesetzt werden. |
---|
[9143] | 68 | * |
---|
| 69 | * d) in CMakeLists.txt noch das Module includen das fuer die Overlays zustaendig ist. Siehe das gleiche File im Pong module. |
---|
| 70 | * |
---|
| 71 | * |
---|
| 72 | * |
---|
[9098] | 73 | */ |
---|
[9112] | 74 | #include "TowerDefense.h" |
---|
[10258] | 75 | #include "TowerDefenseTower.h" |
---|
[9137] | 76 | #include "TowerDefenseCenterpoint.h" |
---|
[9122] | 77 | #include "worldentities/SpawnPoint.h" |
---|
[12190] | 78 | #include "worldentities/StaticEntity.h" |
---|
| 79 | #include "TowerDefenseController.h" //muss ich noch in den richtigen Ordner verschieben |
---|
[9142] | 80 | #include "graphics/Model.h" |
---|
| 81 | #include "infos/PlayerInfo.h" |
---|
[9138] | 82 | #include "chat/ChatManager.h" |
---|
[9667] | 83 | #include "core/CoreIncludes.h" |
---|
[11356] | 84 | #include "Highscore.h" |
---|
[12190] | 85 | #include "util/Output.h" |
---|
| 86 | #include "TowerDefenseRangeViewer.h" |
---|
[9136] | 87 | |
---|
[12190] | 88 | |
---|
[9112] | 89 | namespace orxonox |
---|
| 90 | { |
---|
[9667] | 91 | RegisterUnloadableClass(TowerDefense); |
---|
[9272] | 92 | |
---|
[10622] | 93 | TowerDefense::TowerDefense(Context* context) : TeamDeathmatch(context) |
---|
[9112] | 94 | { |
---|
| 95 | RegisterObject(TowerDefense); |
---|
[9272] | 96 | |
---|
[11071] | 97 | selecter = nullptr; |
---|
[12190] | 98 | rangeViewer = nullptr; |
---|
[11071] | 99 | this->player_ = nullptr; |
---|
[9180] | 100 | this->setHUDTemplate("TowerDefenseHUD"); |
---|
[10629] | 101 | this->waveNumber_ = 0; |
---|
| 102 | this->timeSinceLastSpawn_ = 0.0; |
---|
| 103 | this->timeUntilNextWave_ = 0.0; |
---|
[10622] | 104 | this->credit_ = 0; |
---|
| 105 | this->lifes_ = 0; |
---|
[10629] | 106 | this->waveSize_ = 0; |
---|
| 107 | offset_ = Vector3(0,0,10); |
---|
[9112] | 108 | } |
---|
[9272] | 109 | |
---|
[9136] | 110 | TowerDefense::~TowerDefense() |
---|
| 111 | { |
---|
| 112 | if (this->isInitialized()) |
---|
| 113 | { |
---|
[10629] | 114 | |
---|
[9136] | 115 | } |
---|
| 116 | } |
---|
[9272] | 117 | |
---|
| 118 | void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint) |
---|
| 119 | { |
---|
| 120 | this->center_ = centerpoint; |
---|
| 121 | } |
---|
| 122 | |
---|
[9112] | 123 | void TowerDefense::start() |
---|
[10629] | 124 | { |
---|
[11071] | 125 | if (center_ != nullptr) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place. |
---|
[10622] | 126 | { |
---|
[11071] | 127 | if (selecter == nullptr) |
---|
[10622] | 128 | { |
---|
| 129 | selecter = new TowerDefenseSelecter(this->center_->getContext()); |
---|
| 130 | } |
---|
[12190] | 131 | if(rangeViewer == nullptr){ |
---|
| 132 | rangeViewer = new TowerDefenseRangeViewer(this->center_->getContext()); |
---|
| 133 | } |
---|
[10622] | 134 | selecter->addTemplate(center_->getSelecterTemplate()); |
---|
[12190] | 135 | rangeViewer->addTemplate("therangeviewer"); |
---|
| 136 | rangeViewer->setPosition(-10000,0,-500); |
---|
[10622] | 137 | center_->attach(selecter); |
---|
[12190] | 138 | center_->attach(rangeViewer); |
---|
[10622] | 139 | } |
---|
| 140 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 141 | { |
---|
| 142 | orxout(internal_error) << "Jump: No Centerpoint specified." << endl; |
---|
| 143 | return; |
---|
| 144 | } |
---|
[10258] | 145 | |
---|
[10629] | 146 | enemies_.clear(); |
---|
| 147 | |
---|
| 148 | createFields(); |
---|
[12190] | 149 | |
---|
[10622] | 150 | TeamDeathmatch::start(); |
---|
[9143] | 151 | |
---|
[10258] | 152 | //set initial credits, lifes and WaveNumber |
---|
[10629] | 153 | this->setCredit(1000); |
---|
| 154 | this->setLifes(100); |
---|
| 155 | this->timeSinceLastSpawn_ = 0.0; |
---|
| 156 | this->timeUntilNextWave_ = 5.0; |
---|
| 157 | this->waveSize_ = 0; |
---|
[10258] | 158 | this->setWaveNumber(0); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path. |
---|
[10629] | 162 | void TowerDefense::addTowerDefenseEnemy(int templatenr) |
---|
| 163 | { |
---|
[10258] | 164 | TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext()); |
---|
| 165 | |
---|
| 166 | switch(templatenr) |
---|
[9272] | 167 | { |
---|
[10258] | 168 | case 1 : |
---|
| 169 | en1->addTemplate("enemytowerdefense1"); |
---|
| 170 | en1->setScale(3); |
---|
[12190] | 171 | en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.5*(en1->getHealth())); |
---|
| 172 | en1->setShieldHealth(en1->getShieldHealth() + this->getWaveNumber()*1/3*0.5*(en1->getShieldHealth())); |
---|
[10258] | 173 | break; |
---|
| 174 | |
---|
| 175 | case 2 : |
---|
| 176 | en1->addTemplate("enemytowerdefense2"); |
---|
| 177 | en1->setScale(2); |
---|
[12190] | 178 | en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.3*(en1->getHealth())); |
---|
[10258] | 179 | break; |
---|
| 180 | |
---|
| 181 | case 3 : |
---|
| 182 | en1->addTemplate("enemytowerdefense3"); |
---|
| 183 | en1->setScale(1); |
---|
[12190] | 184 | en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.2*(en1->getHealth())); |
---|
| 185 | en1->setShieldHealth(en1->getShieldHealth() + this->getWaveNumber()*1/3*0.5*(en1->getShieldHealth())); |
---|
[10258] | 186 | break; |
---|
[10629] | 187 | } |
---|
[9272] | 188 | |
---|
[10622] | 189 | en1->setTeam(2); |
---|
[9272] | 190 | |
---|
[12190] | 191 | //Jedem Enemy wird ein eigener Controller uebergeben |
---|
| 192 | TowerDefenseController* controller = new TowerDefenseController(this->center_->getContext()); |
---|
| 193 | controller->setControllableEntity(en1); |
---|
| 194 | en1->setController(controller); |
---|
[10629] | 195 | |
---|
[12190] | 196 | if (waypoints_.size() > 1) |
---|
[10258] | 197 | { |
---|
[10629] | 198 | en1->setPosition(waypoints_.at(0)->getPosition() + offset_); |
---|
| 199 | en1->setOrientation(Vector3(0,0,10), Degree(0)); |
---|
| 200 | en1->setDirection(Vector3(0,1,0)); |
---|
| 201 | en1->lookAt(waypoints_.at(1)->getPosition() + offset_); |
---|
| 202 | |
---|
[11071] | 203 | for (TowerDefenseField* field : waypoints_) |
---|
[10629] | 204 | { |
---|
| 205 | orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext()); |
---|
[11071] | 206 | waypoint->setPosition(field->getPosition() + offset_); |
---|
[10629] | 207 | controller->addWaypoint(waypoint); |
---|
| 208 | } |
---|
[10258] | 209 | } |
---|
[10629] | 210 | |
---|
[12190] | 211 | auto pair = std::make_pair(orxonox::WeakPtr<TowerDefenseEnemy>(en1), controller); |
---|
| 212 | enemies_.push_back(pair); |
---|
[9272] | 213 | } |
---|
| 214 | |
---|
[10258] | 215 | |
---|
[9272] | 216 | void TowerDefense::end() |
---|
[9123] | 217 | { |
---|
[11716] | 218 | if (Highscore::exists()) |
---|
| 219 | { |
---|
| 220 | int score = this->getWaveNumber(); |
---|
| 221 | Highscore::getInstance().storeScore("Tower Defense", score, this->getPlayer()); |
---|
| 222 | } |
---|
[10622] | 223 | TeamDeathmatch::end(); |
---|
[10258] | 224 | ChatManager::message("Match is over! Gameover!"); |
---|
[9272] | 225 | |
---|
| 226 | } |
---|
| 227 | |
---|
[10622] | 228 | void TowerDefense::spawnPlayer(PlayerInfo* player) |
---|
| 229 | { |
---|
| 230 | assert(player); |
---|
[10629] | 231 | player_ = player; |
---|
[10622] | 232 | |
---|
[11071] | 233 | if (selecter->getPlayer() == nullptr) |
---|
[10622] | 234 | { |
---|
[10629] | 235 | player_->startControl(selecter); |
---|
[10622] | 236 | players_[player].state_ = PlayerState::Alive; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /** |
---|
| 241 | @brief |
---|
| 242 | Get the player. |
---|
| 243 | @return |
---|
[11071] | 244 | Returns a pointer to the player. If there is no player, nullptr is returned. |
---|
[10622] | 245 | */ |
---|
| 246 | PlayerInfo* TowerDefense::getPlayer(void) const |
---|
| 247 | { |
---|
| 248 | return this->player_; |
---|
| 249 | } |
---|
| 250 | |
---|
[10258] | 251 | //not working yet |
---|
[10629] | 252 | void TowerDefense::addTower(int x,int y) |
---|
[10622] | 253 | { |
---|
| 254 | TDCoordinate* coord = new TDCoordinate(x,y); |
---|
| 255 | x = coord->GetX(); |
---|
| 256 | y = coord->GetY(); |
---|
[10258] | 257 | |
---|
[10629] | 258 | int cost = center_->getTowerCost(1); |
---|
[10258] | 259 | |
---|
[10629] | 260 | if (fields_[x][y]->isFree() == true && getCredit() >= cost) |
---|
[10258] | 261 | { |
---|
[10629] | 262 | payCredit(cost); |
---|
| 263 | fields_[x][y]->createTower(1); |
---|
[10258] | 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") |
---|
| 268 | so towers have ability if the turrets |
---|
[10622] | 269 | */ |
---|
[10258] | 270 | |
---|
[10629] | 271 | void TowerDefense::upgradeTower(int x, int y) |
---|
| 272 | { |
---|
[10622] | 273 | TDCoordinate* coord = new TDCoordinate(x,y); |
---|
| 274 | x = coord->GetX(); |
---|
[10629] | 275 | y = coord->GetY(); |
---|
[9272] | 276 | |
---|
[10629] | 277 | int cost = center_->getTowerCost(fields_[x][y]->getUpgrade() + 1); |
---|
[10622] | 278 | |
---|
[10629] | 279 | if (fields_[x][y]->isFree() == false && fields_[x][y]->canUpgrade() == true && getCredit() >= cost) |
---|
[9272] | 280 | { |
---|
[10629] | 281 | payCredit(cost); |
---|
| 282 | fields_[x][y]->upgrade(); |
---|
[9272] | 283 | } |
---|
[10622] | 284 | } |
---|
| 285 | |
---|
[10258] | 286 | void TowerDefense::tick(float dt) |
---|
[9272] | 287 | { |
---|
[10258] | 288 | SUPER(TowerDefense, tick, dt); |
---|
| 289 | |
---|
[11071] | 290 | if (hasStarted() == false || player_ == nullptr) |
---|
[10622] | 291 | { |
---|
[10629] | 292 | return; |
---|
| 293 | } |
---|
| 294 | timeUntilNextWave_ -= dt; |
---|
| 295 | timeSinceLastSpawn_ += dt; |
---|
[10622] | 296 | |
---|
[12190] | 297 | if(selecter != nullptr && getField(selecter->selectedPos_)->canUpgrade() == true ){ |
---|
| 298 | rangeViewer->setPosition(((selecter->selectedPos_->GetX())-8)*100, ((selecter->selectedPos_->GetY())-8)*100, 200); |
---|
| 299 | } else { |
---|
| 300 | rangeViewer->setPosition(-10000,0,-500); |
---|
| 301 | } |
---|
| 302 | |
---|
[10629] | 303 | //build/upgrade tower at selecter position |
---|
[11071] | 304 | if (selecter != nullptr && selecter->buildTower_ == true) |
---|
[10629] | 305 | { |
---|
| 306 | selecter->buildTower_ = false; |
---|
[10622] | 307 | |
---|
[10629] | 308 | if (getField(selecter->selectedPos_)->canUpgrade() == true) |
---|
| 309 | { |
---|
| 310 | upgradeTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY()); |
---|
| 311 | } |
---|
| 312 | else |
---|
| 313 | { |
---|
| 314 | addTower(selecter->selectedPos_->GetX(), selecter->selectedPos_->GetY()); |
---|
| 315 | } |
---|
[10622] | 316 | } |
---|
[12190] | 317 | |
---|
[10629] | 318 | |
---|
[12190] | 319 | for (EnemyList::iterator it = enemies_.begin(); it != enemies_.end(); ) |
---|
[10258] | 320 | { |
---|
[12190] | 321 | WeakPtr<TowerDefenseEnemy> enemy = it->first; |
---|
| 322 | TowerDefenseController* ctrl = it->second; |
---|
| 323 | |
---|
| 324 | if (enemy == nullptr) |
---|
[10258] | 325 | { |
---|
[12190] | 326 | |
---|
| 327 | // the enemy was destroyed by a tower - remove it from the list AND destroy the corresponding controler |
---|
| 328 | ctrl->destroy(); |
---|
| 329 | it = enemies_.erase(it); |
---|
| 330 | |
---|
| 331 | int currentType = this->getWaveNumber() % 3 + 1; |
---|
| 332 | switch (currentType){ //Entscheidet, wie viele Credits vergeben werden sollen |
---|
| 333 | case 1: //currently boss wave |
---|
| 334 | addCredit(100); |
---|
| 335 | if (this->getLifes() <= 90) |
---|
| 336 | { |
---|
| 337 | this->setLifes(this->getLifes() + 10); |
---|
| 338 | } |
---|
| 339 | break; |
---|
| 340 | |
---|
| 341 | case 2: //currently mass wave |
---|
| 342 | addCredit(5); |
---|
| 343 | break; |
---|
| 344 | |
---|
| 345 | case 3: //currently moderate wave |
---|
| 346 | addCredit(10); |
---|
| 347 | break; |
---|
| 348 | } |
---|
[10629] | 349 | } |
---|
| 350 | else |
---|
| 351 | { |
---|
| 352 | //if ships are at the end they get destroyed |
---|
[12190] | 353 | Vector3 ship = enemy->getRVWorldPosition(); |
---|
[10629] | 354 | float distance = ship.distance(endpoint_); |
---|
| 355 | if(distance < 40) |
---|
| 356 | { |
---|
[12190] | 357 | enemy->getController()->destroy(); |
---|
| 358 | enemy->destroy(); |
---|
| 359 | |
---|
| 360 | it = enemies_.erase(it); |
---|
[10258] | 361 | this->reduceLifes(1); |
---|
[10629] | 362 | if (this->getLifes() == 0) |
---|
[10258] | 363 | { |
---|
| 364 | this->end(); |
---|
| 365 | } |
---|
| 366 | } |
---|
[10629] | 367 | else |
---|
| 368 | { |
---|
| 369 | ++ it; |
---|
| 370 | } |
---|
[10258] | 371 | } |
---|
[10629] | 372 | } |
---|
[10622] | 373 | |
---|
[10629] | 374 | // Add new enemy? |
---|
| 375 | if (timeSinceLastSpawn_ >= 1.0 && waveSize_ > 0) |
---|
[10258] | 376 | { |
---|
[10629] | 377 | // Add new enemy |
---|
| 378 | timeSinceLastSpawn_ -= 1.0; |
---|
| 379 | -- waveSize_; |
---|
[12190] | 380 | addTowerDefenseEnemy(this->getWaveNumber() % 3 + 1); //Gegnertyp rotiert durch die 3 moeglichen, er beginnt bei Typ 2!!! |
---|
[10258] | 381 | } |
---|
[10629] | 382 | else if (timeUntilNextWave_ <= 0.0 && waveSize_ <= 0) |
---|
| 383 | { |
---|
[12190] | 384 | int currentType = this->getWaveNumber() % 3 + 1; |
---|
[10629] | 385 | //New wave |
---|
| 386 | ++ waveNumber_; |
---|
| 387 | timeSinceLastSpawn_ = 0.0; |
---|
[10258] | 388 | |
---|
[10727] | 389 | timeUntilNextWave_ = waveNumber_+20.0f; |
---|
[12190] | 390 | // Entscheidung, wie gross die einzelnen waves sein sollen. |
---|
| 391 | switch (currentType){ |
---|
| 392 | case 1: //currently boss wave |
---|
| 393 | waveSize_ = waveNumber_+10; |
---|
| 394 | break; |
---|
| 395 | |
---|
| 396 | case 2: //currently mass wave |
---|
| 397 | waveSize_ = (waveNumber_+10)/2; |
---|
| 398 | break; |
---|
| 399 | |
---|
| 400 | case 3: //currently moderate wave |
---|
| 401 | waveSize_ = 1; |
---|
| 402 | break; |
---|
| 403 | } |
---|
[10629] | 404 | } |
---|
[10622] | 405 | |
---|
[10629] | 406 | } |
---|
| 407 | |
---|
| 408 | void TowerDefense::createFields() |
---|
| 409 | { |
---|
| 410 | assert(center_); |
---|
| 411 | TDCoordinate coord(0,0); |
---|
| 412 | TDCoordinate startCoord(0,0); |
---|
| 413 | std::string fields = center_->getFields(); |
---|
| 414 | int pos = 0; |
---|
[12190] | 415 | for (int j = 15; j >= 0; --j) //Vertical number of rows |
---|
[10258] | 416 | { |
---|
[12190] | 417 | for (int i = 0; i <= 15; ++i) //Horizontal number of rows |
---|
[10258] | 418 | { |
---|
[10629] | 419 | coord.Set(i,j); |
---|
| 420 | fields_[i][j] = new TowerDefenseField(center_->getContext()); |
---|
| 421 | fields_[i][j]->setCenterpoint(center_); |
---|
| 422 | center_->attach(fields_[i][j]); |
---|
| 423 | fields_[i][j]->setPosition(coord.get3dcoordinate()); |
---|
| 424 | fields_[i][j]->create(fields.at(pos), fields.at(pos+1)); |
---|
| 425 | pos += 2; |
---|
[11071] | 426 | if (fields_[i][j]->getType() == TowerDefenseFieldType::START) |
---|
[10629] | 427 | { |
---|
| 428 | startCoord.Set(i,j); |
---|
| 429 | waypoints_.push_back(fields_[i][j]); |
---|
| 430 | } |
---|
[10258] | 431 | } |
---|
| 432 | } |
---|
[10629] | 433 | //Place waypoints along the street for the waypoint controllers of the enemies |
---|
| 434 | TDCoordinate* thisCoord = &startCoord; |
---|
| 435 | TDCoordinate* nextCoord; |
---|
[11071] | 436 | while ((nextCoord = getNextStreetCoord(thisCoord)) != nullptr) |
---|
[10629] | 437 | { |
---|
| 438 | waypoints_.push_back(fields_[nextCoord->GetX()][nextCoord->GetY()]); |
---|
| 439 | thisCoord = nextCoord; |
---|
| 440 | endpoint_ = nextCoord->get3dcoordinate(); |
---|
| 441 | } |
---|
[10258] | 442 | |
---|
[9123] | 443 | } |
---|
[9148] | 444 | |
---|
[10629] | 445 | TDCoordinate* TowerDefense::getNextStreetCoord(TDCoordinate* thisCoord) |
---|
| 446 | { |
---|
| 447 | TowerDefenseField* thisField = fields_[thisCoord->GetX()][thisCoord->GetY()]; |
---|
[10622] | 448 | |
---|
[11071] | 449 | if (thisField->getType() != TowerDefenseFieldType::STREET && thisField->getType() != TowerDefenseFieldType::START) |
---|
[10629] | 450 | { |
---|
[11071] | 451 | return nullptr; |
---|
[10629] | 452 | } |
---|
[9272] | 453 | |
---|
[11083] | 454 | TDCoordinate* nextCoord = new TDCoordinate(0, 0); |
---|
| 455 | |
---|
[10629] | 456 | if (thisField->getAngle() == 0) |
---|
[9272] | 457 | { |
---|
[10629] | 458 | nextCoord->Set(thisCoord->GetX(), thisCoord->GetY() - 1); |
---|
[9272] | 459 | } |
---|
[10629] | 460 | else if (thisField->getAngle() == 1) |
---|
| 461 | { |
---|
| 462 | nextCoord->Set(thisCoord->GetX() + 1, thisCoord->GetY()); |
---|
| 463 | } |
---|
| 464 | else if (thisField->getAngle() == 2) |
---|
| 465 | { |
---|
| 466 | nextCoord->Set(thisCoord->GetX(), thisCoord->GetY() + 1); |
---|
| 467 | } |
---|
| 468 | else if (thisField->getAngle() == 3) |
---|
| 469 | { |
---|
| 470 | nextCoord->Set(thisCoord->GetX() - 1, thisCoord->GetY()); |
---|
| 471 | } |
---|
[9272] | 472 | |
---|
[10629] | 473 | if (thisCoord->GetX() != nextCoord->GetX() || thisCoord->GetY() != nextCoord->GetY()) |
---|
[9272] | 474 | { |
---|
[10629] | 475 | return nextCoord; |
---|
[9272] | 476 | } |
---|
| 477 | |
---|
[12190] | 478 | //Falls kein anliegender Weg gefunden wurde. |
---|
[11083] | 479 | delete nextCoord; |
---|
[11071] | 480 | return nullptr; |
---|
[9272] | 481 | } |
---|
[9098] | 482 | } |
---|