[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" |
---|
[10258] | 77 | //#include "TDCoordinate.h" |
---|
[9122] | 78 | #include "worldentities/SpawnPoint.h" |
---|
| 79 | #include "worldentities/pawns/Pawn.h" |
---|
[9129] | 80 | #include "worldentities/pawns/SpaceShip.h" |
---|
[9142] | 81 | #include "controllers/WaypointController.h" |
---|
| 82 | #include "graphics/Model.h" |
---|
| 83 | #include "infos/PlayerInfo.h" |
---|
[9138] | 84 | #include "chat/ChatManager.h" |
---|
[9667] | 85 | #include "core/CoreIncludes.h" |
---|
[9136] | 86 | /* Part of a temporary hack to allow the player to add towers */ |
---|
| 87 | #include "core/command/ConsoleCommand.h" |
---|
[10452] | 88 | #include <cmath> |
---|
[9136] | 89 | |
---|
[10452] | 90 | |
---|
[9112] | 91 | namespace orxonox |
---|
| 92 | { |
---|
[10452] | 93 | static const std::string __CC_addTower_name = "addTower"; |
---|
| 94 | static const std::string __CC_upgradeTower_name = "upgradeTower"; |
---|
| 95 | static const int upgradeCost = 20; |
---|
| 96 | static const int towerCost = 20; |
---|
| 97 | unsigned int maxspaceships = 30; |
---|
| 98 | int maxspaceshipsstandard = 30; |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | SetConsoleCommand("TowerDefense", __CC_addTower_name, &TowerDefense::addTower ).addShortcut().defaultValues(1); |
---|
| 103 | SetConsoleCommand("TowerDefense", __CC_upgradeTower_name, &TowerDefense::upgradeTower).addShortcut().defaultValues(0); |
---|
| 104 | |
---|
[9667] | 105 | RegisterUnloadableClass(TowerDefense); |
---|
[9272] | 106 | |
---|
[10452] | 107 | TowerDefense::TowerDefense(Context* context) : TeamDeathmatch(context) |
---|
[9112] | 108 | { |
---|
| 109 | RegisterObject(TowerDefense); |
---|
[10258] | 110 | /* |
---|
| 111 | for (int i=0; i < 16 ; i++){ |
---|
| 112 | for (int j = 0; j< 16 ; j++){ |
---|
| 113 | towermatrix[i][j] = NULL; |
---|
| 114 | } |
---|
| 115 | }*/ |
---|
[9272] | 116 | |
---|
[10452] | 117 | //Timer for the waves (10 seconds between the waves) |
---|
| 118 | selecter = NULL; |
---|
| 119 | this->player_ = NULL; |
---|
[9180] | 120 | this->setHUDTemplate("TowerDefenseHUD"); |
---|
[10452] | 121 | this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this))); |
---|
| 122 | this->nextwaveTimer_.stopTimer(); |
---|
| 123 | this->waves_ = 0; |
---|
| 124 | this->time = 0; |
---|
| 125 | this->credit_ = 0; |
---|
| 126 | this->lifes_ = 0; |
---|
| 127 | this->timeSetTower_ = 0; |
---|
| 128 | spaceships =15; |
---|
| 129 | eggs=3; |
---|
| 130 | ufos=7; |
---|
| 131 | randomships=5; |
---|
[9180] | 132 | |
---|
[9207] | 133 | |
---|
[10452] | 134 | ModifyConsoleCommand(__CC_addTower_name).setObject(this); |
---|
| 135 | ModifyConsoleCommand(__CC_upgradeTower_name).setObject(this); |
---|
[9112] | 136 | } |
---|
[9272] | 137 | |
---|
[9136] | 138 | TowerDefense::~TowerDefense() |
---|
| 139 | { |
---|
[9272] | 140 | /* Part of a temporary hack to allow the player to add towers */ |
---|
[9136] | 141 | if (this->isInitialized()) |
---|
| 142 | { |
---|
[10452] | 143 | ModifyConsoleCommand(__CC_addTower_name).setObject(NULL); |
---|
| 144 | ModifyConsoleCommand(__CC_upgradeTower_name).setObject(NULL); |
---|
[9136] | 145 | } |
---|
| 146 | } |
---|
[9272] | 147 | |
---|
| 148 | void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint) |
---|
| 149 | { |
---|
| 150 | orxout() << "Centerpoint now setting..." << endl; |
---|
| 151 | this->center_ = centerpoint; |
---|
| 152 | orxout() << "Centerpoint now set..." << endl; |
---|
| 153 | } |
---|
| 154 | |
---|
[9112] | 155 | void TowerDefense::start() |
---|
| 156 | { |
---|
[10452] | 157 | if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place. |
---|
| 158 | { |
---|
| 159 | if (selecter == NULL) |
---|
| 160 | { |
---|
| 161 | selecter = new TowerDefenseSelecter(this->center_->getContext()); |
---|
| 162 | } |
---|
| 163 | selecter->addTemplate(center_->getSelecterTemplate()); |
---|
| 164 | center_->attach(selecter); |
---|
| 165 | } |
---|
| 166 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 167 | { |
---|
| 168 | orxout(internal_error) << "Jump: No Centerpoint specified." << endl; |
---|
| 169 | return; |
---|
| 170 | } |
---|
[10258] | 171 | |
---|
[10452] | 172 | TeamDeathmatch::start(); |
---|
[9143] | 173 | |
---|
[10452] | 174 | // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path |
---|
| 175 | for (int i=0; i < 16 ; i++) |
---|
| 176 | { |
---|
| 177 | for (int j = 0; j< 16 ; j++) |
---|
| 178 | { |
---|
| 179 | towerModelMatrix[i][j] = NULL; |
---|
| 180 | towerTurretMatrix[i][j] = NULL; |
---|
[10258] | 181 | } |
---|
| 182 | } |
---|
[9175] | 183 | |
---|
[10452] | 184 | |
---|
| 185 | |
---|
| 186 | if (player_ != NULL) |
---|
| 187 | { |
---|
| 188 | //this->player_->startControl(selecter); |
---|
| 189 | } |
---|
| 190 | else |
---|
| 191 | { |
---|
| 192 | orxout() << "player=NULL" << endl; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | Model* dummyModel = new Model(this->center_->getContext()); |
---|
| 197 | |
---|
| 198 | //the path of the spacehips has to be blocked, so that no towers can be build there |
---|
[10258] | 199 | for (int k=0; k<3; k++) |
---|
[10452] | 200 | towerModelMatrix[1][k]=dummyModel; |
---|
[10258] | 201 | for (int l=1; l<11; l++) |
---|
[10452] | 202 | towerModelMatrix[l][3]=dummyModel; |
---|
[10258] | 203 | for (int m=3; m<12; m++) |
---|
[10452] | 204 | towerModelMatrix[10][m]=dummyModel; |
---|
[10258] | 205 | for (int n=10; n<14; n++) |
---|
[10452] | 206 | towerModelMatrix[n][11]=dummyModel; |
---|
[10258] | 207 | for (int o=13; o<16; o++) |
---|
[10452] | 208 | towerModelMatrix[13][o]=dummyModel; |
---|
[10258] | 209 | |
---|
[10452] | 210 | |
---|
[10258] | 211 | //set initial credits, lifes and WaveNumber |
---|
[10452] | 212 | this->setCredit(100); |
---|
| 213 | this->setLifes(100); |
---|
[10258] | 214 | this->setWaveNumber(0); |
---|
| 215 | time=0.0; |
---|
| 216 | |
---|
[10452] | 217 | /* |
---|
[10258] | 218 | //adds initial towers |
---|
| 219 | for (int i=0; i <7; i++){ |
---|
| 220 | addTower(i+3,4); |
---|
[10452] | 221 | } |
---|
| 222 | */ |
---|
[10258] | 223 | } |
---|
| 224 | |
---|
| 225 | // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path. |
---|
| 226 | void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){ |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext()); |
---|
| 230 | |
---|
| 231 | switch(templatenr) |
---|
[9272] | 232 | { |
---|
[10258] | 233 | case 1 : |
---|
| 234 | en1->addTemplate("enemytowerdefense1"); |
---|
| 235 | en1->setScale(3); |
---|
[10452] | 236 | en1->lookAt(Vector3(0,0,100000)); |
---|
| 237 | en1->setHealth(en1->getHealth() +50 + this->getWaveNumber()*4); |
---|
[10258] | 238 | break; |
---|
| 239 | |
---|
| 240 | case 2 : |
---|
| 241 | en1->addTemplate("enemytowerdefense2"); |
---|
| 242 | en1->setScale(2); |
---|
[10452] | 243 | en1->lookAt(Vector3(0,0,100000)); |
---|
| 244 | en1->roll(Degree(120)); |
---|
| 245 | en1->setHealth(en1->getHealth() -30 + this->getWaveNumber()*4); |
---|
[10258] | 246 | // en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2)) |
---|
| 247 | break; |
---|
| 248 | |
---|
| 249 | case 3 : |
---|
| 250 | en1->addTemplate("enemytowerdefense3"); |
---|
| 251 | en1->setScale(1); |
---|
[10452] | 252 | en1->lookAt(Vector3(0,0,100000)); |
---|
| 253 | en1->roll(Degree(120)); |
---|
| 254 | en1->setHealth(en1->getHealth() -10 + this->getWaveNumber()*4); |
---|
[10258] | 255 | break; |
---|
[9272] | 256 | } |
---|
| 257 | |
---|
[10452] | 258 | en1->setTeam(2); |
---|
[10258] | 259 | en1->getController(); |
---|
[10452] | 260 | en1->setPosition(path.at(0)->get3dcoordinate()); |
---|
[10258] | 261 | TowerDefenseEnemyvector.push_back(en1); |
---|
[9272] | 262 | |
---|
[10258] | 263 | for(unsigned int i = 0; i < path.size(); ++i) |
---|
| 264 | { |
---|
| 265 | en1->addWaypoint((path.at(i))); |
---|
| 266 | } |
---|
[9272] | 267 | } |
---|
| 268 | |
---|
[10258] | 269 | |
---|
[9272] | 270 | void TowerDefense::end() |
---|
[9123] | 271 | { |
---|
[10258] | 272 | |
---|
[10452] | 273 | TeamDeathmatch::end(); |
---|
[10258] | 274 | ChatManager::message("Match is over! Gameover!"); |
---|
[9272] | 275 | |
---|
| 276 | } |
---|
| 277 | |
---|
[10452] | 278 | void TowerDefense::spawnPlayer(PlayerInfo* player) |
---|
| 279 | { |
---|
| 280 | assert(player); |
---|
| 281 | this->player_ = player; |
---|
| 282 | |
---|
| 283 | if (selecter->getPlayer() == NULL) |
---|
| 284 | { |
---|
| 285 | this->player_ = player; |
---|
| 286 | player->startControl(selecter); |
---|
| 287 | players_[player].state_ = PlayerState::Alive; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | /** |
---|
| 292 | @brief |
---|
| 293 | Get the player. |
---|
| 294 | @return |
---|
| 295 | Returns a pointer to the player. If there is no player, NULL is returned. |
---|
| 296 | */ |
---|
| 297 | PlayerInfo* TowerDefense::getPlayer(void) const |
---|
| 298 | { |
---|
| 299 | return this->player_; |
---|
| 300 | } |
---|
| 301 | |
---|
[10258] | 302 | //not working yet |
---|
| 303 | void TowerDefense::upgradeTower(int x,int y) |
---|
[10452] | 304 | { |
---|
| 305 | TDCoordinate* coord = new TDCoordinate(x,y); |
---|
| 306 | x = coord->GetX(); |
---|
| 307 | y = coord->GetY(); |
---|
| 308 | |
---|
[10258] | 309 | |
---|
| 310 | if (!this->hasEnoughCreditForTower(upgradeCost)) |
---|
| 311 | { |
---|
| 312 | orxout() << "not enough credit: " << (this->getCredit()) << " available, " << upgradeCost << " needed."; |
---|
| 313 | return; |
---|
| 314 | } |
---|
| 315 | |
---|
[10452] | 316 | |
---|
| 317 | Model* dummyModel2 = new Model(this->center_->getContext()); |
---|
| 318 | |
---|
| 319 | if (towerModelMatrix [x][y] == NULL || (towerModelMatrix [x][y])->getMeshSource() == dummyModel2->getMeshSource()) |
---|
[10258] | 320 | { |
---|
| 321 | orxout() << "no tower on this position" << endl; |
---|
| 322 | return; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | else |
---|
| 326 | { |
---|
[10452] | 327 | (towerTurretMatrix [x][y])->upgradeTower(); |
---|
| 328 | switch(towerTurretMatrix[x][y]->upgrade) |
---|
| 329 | { |
---|
| 330 | case 1 : |
---|
| 331 | towerModelMatrix[x][y]->setMeshSource("TD_T2.mesh"); |
---|
| 332 | break; |
---|
| 333 | |
---|
| 334 | case 2 : |
---|
| 335 | towerModelMatrix[x][y]->setMeshSource("TD_T3.mesh"); |
---|
| 336 | break; |
---|
| 337 | case 3 : |
---|
| 338 | towerModelMatrix[x][y]->setMeshSource("TD_T4.mesh"); |
---|
| 339 | break; |
---|
| 340 | case 4 : |
---|
| 341 | towerModelMatrix[x][y]->setMeshSource("TD_T5.mesh"); |
---|
| 342 | break; |
---|
| 343 | |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | this->buyTower(upgradeCost); |
---|
| 347 | } |
---|
[10258] | 348 | } |
---|
| 349 | |
---|
| 350 | /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") |
---|
| 351 | so towers have ability if the turrets |
---|
[10452] | 352 | */ |
---|
[10258] | 353 | |
---|
[9272] | 354 | void TowerDefense::addTower(int x, int y) |
---|
[10452] | 355 | { |
---|
| 356 | TDCoordinate* coord = new TDCoordinate(x,y); |
---|
| 357 | x = coord->GetX(); |
---|
| 358 | y = coord->GetY(); |
---|
[9272] | 359 | |
---|
[10452] | 360 | |
---|
[9272] | 361 | if (!this->hasEnoughCreditForTower(towerCost)) |
---|
| 362 | { |
---|
[10258] | 363 | orxout() << "not enough credit: " << (this->getCredit()) << " available, " << towerCost << " needed."; |
---|
[9272] | 364 | return; |
---|
| 365 | } |
---|
| 366 | |
---|
[10452] | 367 | if (towerModelMatrix [x][y]!=NULL) |
---|
[9272] | 368 | { |
---|
[10258] | 369 | orxout() << "not possible to put tower here!!" << endl; |
---|
[9272] | 370 | return; |
---|
| 371 | } |
---|
| 372 | |
---|
[10258] | 373 | /* |
---|
[9272] | 374 | unsigned int width = this->center_->getWidth(); |
---|
| 375 | unsigned int height = this->center_->getHeight(); |
---|
[10258] | 376 | */ |
---|
[9272] | 377 | |
---|
| 378 | int tileScale = (int) this->center_->getTileScale(); |
---|
| 379 | |
---|
[10452] | 380 | /*if (x > 15 || y > 15 || x < 0 || y < 0) |
---|
[9272] | 381 | { |
---|
| 382 | //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet) |
---|
| 383 | orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; |
---|
| 384 | return; |
---|
[10452] | 385 | }*/ |
---|
[9272] | 386 | |
---|
[10452] | 387 | //orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; |
---|
| 388 | orxout() << "Will add tower at (" << x << "," << y << ")" << endl; |
---|
[9272] | 389 | |
---|
| 390 | |
---|
[10452] | 391 | //Create Model |
---|
| 392 | Model* newTowerModel = new Model(this->center_->getContext()); |
---|
| 393 | newTowerModel->setMeshSource("TD_T1.mesh"); |
---|
| 394 | newTowerModel->setScale(30); |
---|
| 395 | newTowerModel->pitch(Degree(90)); |
---|
| 396 | newTowerModel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 80); |
---|
| 397 | |
---|
[10258] | 398 | //Creates tower |
---|
| 399 | TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext()); |
---|
[10452] | 400 | towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 275); |
---|
[10258] | 401 | towernew->setGame(this); |
---|
[10452] | 402 | towernew->setTeam(1); |
---|
[9272] | 403 | |
---|
[10452] | 404 | //Reduce credit |
---|
| 405 | this->buyTower(towerCost); |
---|
| 406 | towerModelMatrix [x][y]= newTowerModel; |
---|
| 407 | towerTurretMatrix [x][y]= towernew; |
---|
| 408 | } |
---|
| 409 | |
---|
[10258] | 410 | bool TowerDefense::hasEnoughCreditForTower(int towerCost) |
---|
| 411 | { |
---|
| 412 | return ((this->getCredit()) >= towerCost); |
---|
[9272] | 413 | } |
---|
| 414 | |
---|
[10258] | 415 | |
---|
| 416 | bool TowerDefense::hasEnoughCreditForUpgrade() |
---|
[9272] | 417 | { |
---|
[10258] | 418 | return true; |
---|
[9272] | 419 | } |
---|
| 420 | |
---|
[10258] | 421 | |
---|
[10452] | 422 | void TowerDefense::nextwave() |
---|
| 423 | { |
---|
| 424 | |
---|
| 425 | orxout() << "newwave" << endl; |
---|
| 426 | TowerDefenseEnemyvector.clear(); |
---|
| 427 | waves_++; |
---|
| 428 | //maxspaceships = round(maxspaceshipsstandard + 0.25*(waves_)); |
---|
| 429 | time=0; |
---|
| 430 | |
---|
| 431 | int helpnumber = 40 -(waves_); |
---|
| 432 | if(helpnumber <= 0) {helpnumber =1;} |
---|
| 433 | float numSpaceships = std::abs((rand() % 100)*5*(helpnumber)); |
---|
| 434 | float numEggs = std::abs((rand() % 100)*1*(waves_)); |
---|
| 435 | float numUfos = std::abs((rand() % 100)*1.5*(0.5*(waves_))) ; |
---|
| 436 | |
---|
| 437 | float totalnumber = (numSpaceships + numEggs + numUfos)*1.3; |
---|
| 438 | |
---|
| 439 | int newspaceships = (int)(maxspaceships* numSpaceships / totalnumber); |
---|
| 440 | int neweggs = (int)(maxspaceships*numEggs / totalnumber); |
---|
| 441 | int newufos = (int)(maxspaceships*numUfos / totalnumber); |
---|
| 442 | int newrandomships = maxspaceships -newspaceships - neweggs - newufos; |
---|
| 443 | spaceships =newspaceships; |
---|
| 444 | eggs=neweggs; |
---|
| 445 | ufos=newufos; |
---|
| 446 | randomships=newrandomships; |
---|
| 447 | |
---|
| 448 | orxout() << spaceships << endl; |
---|
| 449 | orxout() << eggs << endl; |
---|
| 450 | orxout() << ufos << endl; |
---|
| 451 | orxout() << randomships << endl; |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | } |
---|
| 458 | |
---|
[10258] | 459 | void TowerDefense::tick(float dt) |
---|
[9272] | 460 | { |
---|
[10258] | 461 | SUPER(TowerDefense, tick, dt); |
---|
| 462 | time +=dt; |
---|
[10452] | 463 | timeSetTower_ +=dt; |
---|
[10258] | 464 | |
---|
[10452] | 465 | //Check if tower has to be set (because TowerDefenseSelecter asks for it) |
---|
| 466 | if(timeSetTower_ >= 0.25) |
---|
| 467 | { |
---|
| 468 | timeSetTower_ =0; |
---|
| 469 | if(selecter != NULL && selecter->firePressed_) |
---|
| 470 | { |
---|
| 471 | |
---|
| 472 | int x = selecter->selectedPos_->GetX(); |
---|
| 473 | int y = selecter->selectedPos_->GetY(); |
---|
| 474 | Model* dummyModel2 = new Model(this->center_->getContext()); |
---|
| 475 | |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | if(towerModelMatrix[x][y] == NULL) |
---|
| 479 | { |
---|
| 480 | addTower(x,y); |
---|
| 481 | } |
---|
| 482 | else |
---|
| 483 | { |
---|
| 484 | if(!((towerModelMatrix [x][y])->getMeshSource() == dummyModel2->getMeshSource())) |
---|
| 485 | { |
---|
| 486 | towerTurretMatrix[x][y]->upgradeTower(); |
---|
| 487 | if(towerTurretMatrix[x][y]->upgrade < towerTurretMatrix[x][y]->upgradeMax) |
---|
| 488 | { |
---|
| 489 | int specificupgradecost = (int)(upgradeCost*(std::pow(1.5,towerTurretMatrix[x][y]->upgrade))); |
---|
| 490 | if(this->credit_ >= specificupgradecost) |
---|
| 491 | { |
---|
| 492 | this->buyTower(specificupgradecost); |
---|
| 493 | switch(towerTurretMatrix[x][y]->upgrade) |
---|
| 494 | { |
---|
| 495 | case 1 : |
---|
| 496 | towerModelMatrix[x][y]->setMeshSource("TD_T2.mesh"); |
---|
| 497 | break; |
---|
| 498 | |
---|
| 499 | case 2 : |
---|
| 500 | towerModelMatrix[x][y]->setMeshSource("TD_T3.mesh"); |
---|
| 501 | break; |
---|
| 502 | case 3 : |
---|
| 503 | towerModelMatrix[x][y]->setMeshSource("TD_T4.mesh"); |
---|
| 504 | break; |
---|
| 505 | case 4 : |
---|
| 506 | towerModelMatrix[x][y]->setMeshSource("TD_T5.mesh"); |
---|
| 507 | break; |
---|
| 508 | |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | } |
---|
| 516 | selecter->firePressed_ = false; |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | |
---|
[10258] | 520 | TDCoordinate* coord1 = new TDCoordinate(1,1); |
---|
| 521 | std::vector<TDCoordinate*> path; |
---|
| 522 | path.push_back(coord1); |
---|
[9272] | 523 | |
---|
[10452] | 524 | |
---|
| 525 | |
---|
| 526 | |
---|
| 527 | |
---|
| 528 | if(time>=TowerDefenseEnemyvector.size() && TowerDefenseEnemyvector.size() < maxspaceships) |
---|
| 529 | { |
---|
| 530 | |
---|
| 531 | //adds different types of enemys depending on the WaveNumber progressively making the combination of enemys more difficult |
---|
| 532 | if(spaceships>0) |
---|
| 533 | { |
---|
| 534 | addTowerDefenseEnemy(path, 1); |
---|
| 535 | spaceships--; |
---|
| 536 | |
---|
| 537 | }else if(ufos>0) |
---|
| 538 | { |
---|
| 539 | addTowerDefenseEnemy(path, 3); |
---|
| 540 | ufos--; |
---|
| 541 | }else if(eggs>0) |
---|
| 542 | { |
---|
| 543 | addTowerDefenseEnemy(path, 2); |
---|
| 544 | eggs--; |
---|
| 545 | }else if(randomships>0) |
---|
| 546 | { |
---|
| 547 | addTowerDefenseEnemy(path, rand() % 3 +1); |
---|
| 548 | randomships--; |
---|
| 549 | |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | |
---|
[10258] | 555 | Vector3* endpoint = new Vector3(500, 700, 150); |
---|
| 556 | //if ships are at the end they get destroyed |
---|
| 557 | for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i) |
---|
| 558 | { |
---|
| 559 | if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive()) |
---|
| 560 | { |
---|
[10452] | 561 | //destroys enemys at the end of the path and reduces the life by 1. no credits gifted |
---|
[9272] | 562 | |
---|
[10258] | 563 | Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition(); |
---|
| 564 | float distance = ship.distance(*endpoint); |
---|
[9272] | 565 | |
---|
[10258] | 566 | if(distance <50){ |
---|
| 567 | TowerDefenseEnemyvector.at(i)->destroy(); |
---|
| 568 | this->reduceLifes(1); |
---|
| 569 | this->buyTower(1); |
---|
| 570 | if (this->getLifes()==0) |
---|
| 571 | { |
---|
| 572 | this->end(); |
---|
| 573 | } |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | } |
---|
[10452] | 577 | |
---|
[10258] | 578 | //goes thorugh vector to see if an enemy is still alive. if not next wave is launched |
---|
| 579 | int count= 0; |
---|
| 580 | for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i) |
---|
| 581 | { |
---|
| 582 | if(TowerDefenseEnemyvector.at(i)!= NULL) |
---|
| 583 | { |
---|
| 584 | ++count; |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | |
---|
[10452] | 588 | if (count == 0 && !this->nextwaveTimer_.isActive()) |
---|
| 589 | this->nextwaveTimer_.startTimer(); |
---|
| 590 | |
---|
| 591 | /* time2 +=dt; |
---|
[10258] | 592 | if(count== 0) |
---|
| 593 | { |
---|
| 594 | if(time2 > 10) |
---|
| 595 | { |
---|
| 596 | TowerDefenseEnemyvector.clear(); |
---|
| 597 | this->nextwave(); |
---|
| 598 | time=0; |
---|
| 599 | time2=0; |
---|
| 600 | } |
---|
| 601 | } |
---|
[10452] | 602 | */ |
---|
[10258] | 603 | |
---|
[9123] | 604 | } |
---|
[9148] | 605 | |
---|
[10452] | 606 | |
---|
[9272] | 607 | // Function to test if we can add waypoints using code only. Doesn't work yet |
---|
| 608 | |
---|
| 609 | // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL??? |
---|
| 610 | /* |
---|
| 611 | void TowerDefense::addWaypointsAndFirstEnemy() |
---|
| 612 | { |
---|
| 613 | SpaceShip *newShip = new SpaceShip(this->center_); |
---|
| 614 | newShip->addTemplate("spaceshipassff"); |
---|
| 615 | |
---|
| 616 | WaypointController *newController = new WaypointController(newShip); |
---|
| 617 | newController->setAccuracy(3); |
---|
| 618 | |
---|
| 619 | Model *wayPoint1 = new Model(newController); |
---|
| 620 | wayPoint1->setMeshSource("crate.mesh"); |
---|
| 621 | wayPoint1->setPosition(7,-7,5); |
---|
| 622 | wayPoint1->setScale(0.2); |
---|
| 623 | |
---|
| 624 | Model *wayPoint2 = new Model(newController); |
---|
| 625 | wayPoint2->setMeshSource("crate.mesh"); |
---|
| 626 | wayPoint2->setPosition(7,7,5); |
---|
| 627 | wayPoint2->setScale(0.2); |
---|
| 628 | |
---|
| 629 | newController->addWaypoint(wayPoint1); |
---|
| 630 | newController->addWaypoint(wayPoint2); |
---|
| 631 | |
---|
| 632 | // The following line causes the game to crash |
---|
| 633 | |
---|
| 634 | newShip->setController(newController); |
---|
| 635 | // newController -> getPlayer() -> startControl(newShip); |
---|
| 636 | newShip->setPosition(-7,-7,5); |
---|
| 637 | newShip->setScale(0.1); |
---|
| 638 | //newShip->addSpeed(1); |
---|
| 639 | |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | // this->center_->attach(newShip); |
---|
| 643 | } |
---|
| 644 | */ |
---|
| 645 | /* |
---|
| 646 | void TowerDefense::playerEntered(PlayerInfo* player) |
---|
| 647 | { |
---|
[10452] | 648 | TeamDeathmatch::playerEntered(player); |
---|
[9272] | 649 | |
---|
| 650 | const std::string& message = player->getName() + " entered the game"; |
---|
| 651 | ChatManager::message(message); |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | bool TowerDefense::playerLeft(PlayerInfo* player) |
---|
| 655 | { |
---|
[10452] | 656 | bool valid_player = TeamDeathmatch::playerLeft(player); |
---|
[9272] | 657 | |
---|
| 658 | if (valid_player) |
---|
| 659 | { |
---|
| 660 | const std::string& message = player->getName() + " left the game"; |
---|
| 661 | ChatManager::message(message); |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | return valid_player; |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | |
---|
| 668 | void TowerDefense::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 669 | { |
---|
| 670 | if (victim && victim->getPlayer()) |
---|
| 671 | { |
---|
| 672 | std::string message; |
---|
| 673 | if (killer) |
---|
| 674 | { |
---|
| 675 | if (killer->getPlayer()) |
---|
| 676 | message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName(); |
---|
| 677 | else |
---|
| 678 | message = victim->getPlayer()->getName() + " was killed"; |
---|
| 679 | } |
---|
| 680 | else |
---|
| 681 | message = victim->getPlayer()->getName() + " died"; |
---|
| 682 | |
---|
| 683 | ChatManager::message(message); |
---|
| 684 | } |
---|
| 685 | |
---|
[10452] | 686 | TeamDeathmatch::pawnKilled(victim, killer); |
---|
[9272] | 687 | } |
---|
| 688 | |
---|
[9347] | 689 | void TowerDefense::playerScored(PlayerInfo* player, int score) |
---|
[9272] | 690 | { |
---|
[9347] | 691 | Gametype::playerScored(player, score); |
---|
[9272] | 692 | }*/ |
---|
[9098] | 693 | } |
---|