[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 | * |
---|
| 22 | * Author: |
---|
| 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 | * |
---|
| 40 | *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: |
---|
| 41 | * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter |
---|
| 42 | * tippt, werden die Vorschläge entsprechend gefiltert. |
---|
| 43 | * |
---|
| 44 | * |
---|
| 45 | *TIPP: schaut euch mal Tetris::createStone() an. Dort wird ein TetrisStone-Objekt (ControllableEntity) erzeugt, |
---|
| 46 | * ihm ein Template zugewiesen (welches vorher im Level definiert wurde und dem CenterPoint übergeben wurde) |
---|
| 47 | * Ähnlich könnt ihr vorgehen, um einen Turm zu erzeugen. (Zusätzlich braucht ein Turm noch einen Controller) |
---|
| 48 | * z.B: WaypointPatrolController. Wenn kein Team zugewiesen wurde bekämpft ein WaypointPatrolController alles, |
---|
| 49 | * was in seiner Reichweite liegt. |
---|
| 50 | * |
---|
[9143] | 51 | * |
---|
| 52 | *HUD: |
---|
| 53 | * Ein Gametype kann ein HUD (Head up Display haben.) Z.B: hat Pong eine Anzeige welcher Spieler wieviele Punkte hat. |
---|
| 54 | * Generell kann man a) Grafiken oder b) Zeichen in einer HUD anzeigen. |
---|
| 55 | * Fuer den ersten Schritt reicht reiner Text. |
---|
| 56 | * |
---|
| 57 | * a) |
---|
| 58 | * PongScore.cc uebernehmen und eigene Klasse draus machen. |
---|
| 59 | * Wenn ihr bloss anzeigen wollt wieviele Punkte der Spieler bereits erspielt hat (Punkte = Kapital fuer neue Tuerme) dann orientiert ihr euch an |
---|
| 60 | * TetrisScore.cc (im pCuts branch): http://www.orxonox.net/browser/code/branches/pCuts/src/modules/tetris/TetrisScore.cc |
---|
| 61 | * Ich habe TetrisScore lediglich dazu gebraucht, um eine Variable auf dem HUD auszugeben. Ein Objekt fuer statischen Text gibt es bereits. |
---|
| 62 | * |
---|
| 63 | * b) |
---|
| 64 | * Im naesten Schritt erstellt man die Vorlage fuer das HUD-Objekt: siehe /data/overlays/pongHUD |
---|
| 65 | * OverlayText ist eine Vorlage fuer statischen text zb: "Points Scored:". Aus mir nicht erklaerlichen Gruenden sollte man die OverlayText |
---|
| 66 | * Objekte immer erst nach dem PongScore anlegen. |
---|
| 67 | * |
---|
[9180] | 68 | * c) Im TowerDefense gamtype muss im Constructor noch das HUD-Template gesetzt werden. |
---|
[9143] | 69 | * |
---|
| 70 | * d) in CMakeLists.txt noch das Module includen das fuer die Overlays zustaendig ist. Siehe das gleiche File im Pong module. |
---|
| 71 | * |
---|
| 72 | * |
---|
| 73 | * |
---|
[9098] | 74 | */ |
---|
| 75 | |
---|
[9112] | 76 | #include "TowerDefense.h" |
---|
[9137] | 77 | #include "Tower.h" |
---|
| 78 | #include "TowerDefenseCenterpoint.h" |
---|
[9207] | 79 | #include "TowerDefensePlayerStats.h" |
---|
[9137] | 80 | |
---|
[9122] | 81 | #include "worldentities/SpawnPoint.h" |
---|
| 82 | #include "worldentities/pawns/Pawn.h" |
---|
[9129] | 83 | #include "worldentities/pawns/SpaceShip.h" |
---|
[9142] | 84 | #include "controllers/WaypointController.h" |
---|
| 85 | |
---|
| 86 | #include "graphics/Model.h" |
---|
| 87 | #include "infos/PlayerInfo.h" |
---|
| 88 | |
---|
[9138] | 89 | #include "chat/ChatManager.h" |
---|
| 90 | |
---|
[9136] | 91 | /* Part of a temporary hack to allow the player to add towers */ |
---|
| 92 | #include "core/command/ConsoleCommand.h" |
---|
| 93 | |
---|
[9112] | 94 | namespace orxonox |
---|
| 95 | { |
---|
| 96 | CreateUnloadableFactory(TowerDefense); |
---|
[9136] | 97 | |
---|
| 98 | TowerDefense::TowerDefense(BaseObject* creator) : Deathmatch(creator) |
---|
[9112] | 99 | { |
---|
| 100 | RegisterObject(TowerDefense); |
---|
[9136] | 101 | |
---|
[9180] | 102 | this->setHUDTemplate("TowerDefenseHUD"); |
---|
| 103 | |
---|
[9207] | 104 | this->stats_ = new TowerDefensePlayerStats(); |
---|
| 105 | |
---|
[9136] | 106 | /* Temporary hack to allow the player to add towers */ |
---|
| 107 | this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); |
---|
[9142] | 108 | |
---|
| 109 | // Quick hack to test waypoints |
---|
| 110 | createConsoleCommand( "aw", createExecutor( createFunctor(&TowerDefense::addWaypointsAndFirstEnemy, this) ) ); |
---|
[9112] | 111 | } |
---|
[9136] | 112 | |
---|
| 113 | TowerDefense::~TowerDefense() |
---|
| 114 | { |
---|
[9139] | 115 | /* Part of a temporary hack to allow the player to add towers */ |
---|
[9136] | 116 | if (this->isInitialized()) |
---|
| 117 | { |
---|
| 118 | if( this->dedicatedAddTower_ ) |
---|
| 119 | delete this->dedicatedAddTower_; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint) |
---|
| 124 | { |
---|
[9175] | 125 | orxout() << "Centerpoint now setting..." << endl; |
---|
| 126 | this->center_ = centerpoint; |
---|
[9139] | 127 | orxout() << "Centerpoint now set..." << endl; |
---|
[9136] | 128 | } |
---|
| 129 | |
---|
[9112] | 130 | void TowerDefense::start() |
---|
| 131 | { |
---|
| 132 | Deathmatch::start(); |
---|
[9138] | 133 | |
---|
[9139] | 134 | orxout() << "Adding towers for debug..." << endl; |
---|
[9138] | 135 | |
---|
[9139] | 136 | // Mark corners |
---|
| 137 | addTower(0,15); addTower(15,0); |
---|
[9138] | 138 | |
---|
[9139] | 139 | // Mark diagonal line |
---|
[9138] | 140 | for (int i = 0 ; i <= 15; i++) |
---|
| 141 | addTower(i,i); |
---|
| 142 | |
---|
[9139] | 143 | orxout() << "Done" << endl; |
---|
[9138] | 144 | |
---|
| 145 | ChatManager::message("Use the console command addTower x y to add towers"); |
---|
[9143] | 146 | |
---|
| 147 | //TODO: let the player control his controllable entity && TODO: create a new ControllableEntity for the player |
---|
| 148 | |
---|
[9139] | 149 | } |
---|
[9136] | 150 | |
---|
[9139] | 151 | void TowerDefense::end() |
---|
| 152 | { |
---|
| 153 | Deathmatch::end(); |
---|
[9136] | 154 | |
---|
[9139] | 155 | ChatManager::message("Match is over"); |
---|
| 156 | } |
---|
[9136] | 157 | |
---|
[9160] | 158 | bool TowerDefense::hasTower(int x, int y) |
---|
| 159 | { |
---|
| 160 | for(std::vector<coordinate>::iterator it = addedTowersCoordinates_.begin(); it != addedTowersCoordinates_.end(); ++it) |
---|
| 161 | { |
---|
| 162 | coordinate currentCoordinates = (coordinate) (*it); |
---|
| 163 | if (currentCoordinates.x == x && currentCoordinates.y == y) |
---|
| 164 | return true; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | return false; |
---|
| 168 | } |
---|
[9139] | 169 | |
---|
[9136] | 170 | void TowerDefense::addTower(int x, int y) |
---|
| 171 | { |
---|
[9160] | 172 | if (this->hasTower(x,y)) |
---|
| 173 | { |
---|
| 174 | orxout() << "tower exists!!" << endl; |
---|
| 175 | return; |
---|
| 176 | } |
---|
| 177 | |
---|
[9167] | 178 | coordinate newTowerCoordinates; |
---|
| 179 | newTowerCoordinates.x = x; newTowerCoordinates.y = y; |
---|
| 180 | addedTowersCoordinates_.push_back(newTowerCoordinates); |
---|
[9160] | 181 | |
---|
[9154] | 182 | unsigned int width = this->center_->getWidth(); |
---|
| 183 | unsigned int height = this->center_->getHeight(); |
---|
| 184 | int tileScale = (int) this->center_->getTileScale(); |
---|
| 185 | |
---|
| 186 | orxout() << "tile scale = " << tileScale << endl; |
---|
[9172] | 187 | |
---|
[9154] | 188 | if (x > 15 || y > 15 || x < 0 || y < 0) |
---|
[9136] | 189 | { |
---|
[9154] | 190 | //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet) |
---|
[9138] | 191 | orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; |
---|
[9136] | 192 | return; |
---|
| 193 | } |
---|
| 194 | |
---|
[9154] | 195 | orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; |
---|
[9136] | 196 | |
---|
[9137] | 197 | Tower* newTower = new Tower(this->center_); |
---|
| 198 | newTower->addTemplate(this->center_->getTowerTemplate()); |
---|
[9175] | 199 | |
---|
| 200 | //this->center_->attach(newTower); |
---|
| 201 | |
---|
[9160] | 202 | newTower->setPosition((x-8) * tileScale, (y-8) * tileScale, 100); |
---|
[9137] | 203 | newTower->setGame(this); |
---|
[9143] | 204 | //TODO: Save the Tower in a Vector. I would suggest std::vector< std::vector<Tower*> > towers_ as a protected member variable; |
---|
[9137] | 205 | |
---|
[9136] | 206 | // TODO: create Tower mesh |
---|
| 207 | // TODO: load Tower mesh |
---|
| 208 | } |
---|
| 209 | |
---|
[9123] | 210 | void TowerDefense::tick(float dt) |
---|
| 211 | { |
---|
| 212 | SUPER(TowerDefense, tick, dt); |
---|
[9136] | 213 | |
---|
[9142] | 214 | static int test = 0; |
---|
| 215 | if (++test == 10) |
---|
[9129] | 216 | { |
---|
[9142] | 217 | orxout()<< "10th tick." <<endl; |
---|
| 218 | /* |
---|
| 219 | for (std::set<SpawnPoint*>::iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); it++) |
---|
| 220 | { |
---|
| 221 | orxout() << "checking spawnpoint with name " << (*it)->getSpawnClass()->getName() << endl; |
---|
| 222 | } |
---|
| 223 | */ |
---|
| 224 | |
---|
| 225 | //addWaypointsAndFirstEnemy(); |
---|
| 226 | |
---|
[9116] | 227 | } |
---|
[9123] | 228 | } |
---|
[9136] | 229 | |
---|
[9142] | 230 | // Function to test if we can add waypoints using code only. Doesn't work yet |
---|
| 231 | |
---|
| 232 | // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL??? |
---|
| 233 | |
---|
| 234 | void TowerDefense::addWaypointsAndFirstEnemy() |
---|
| 235 | { |
---|
| 236 | SpaceShip *newShip = new SpaceShip(this->center_); |
---|
| 237 | newShip->addTemplate("spaceshipassff"); |
---|
| 238 | |
---|
| 239 | WaypointController *newController = new WaypointController(newShip); |
---|
| 240 | newController->setAccuracy(3); |
---|
| 241 | |
---|
| 242 | Model *wayPoint1 = new Model(newController); |
---|
| 243 | wayPoint1->setMeshSource("crate.mesh"); |
---|
| 244 | wayPoint1->setPosition(7,-7,5); |
---|
| 245 | wayPoint1->setScale(0.2); |
---|
| 246 | |
---|
| 247 | Model *wayPoint2 = new Model(newController); |
---|
| 248 | wayPoint2->setMeshSource("crate.mesh"); |
---|
| 249 | wayPoint2->setPosition(7,7,5); |
---|
| 250 | wayPoint2->setScale(0.2); |
---|
| 251 | |
---|
| 252 | newController->addWaypoint(wayPoint1); |
---|
| 253 | newController->addWaypoint(wayPoint2); |
---|
| 254 | |
---|
| 255 | // The following line causes the game to crash |
---|
[9148] | 256 | |
---|
| 257 | newShip->setController(newController); |
---|
[9142] | 258 | // newController -> getPlayer() -> startControl(newShip); |
---|
| 259 | newShip->setPosition(-7,-7,5); |
---|
| 260 | newShip->setScale(0.1); |
---|
[9148] | 261 | //newShip->addSpeed(1); |
---|
[9142] | 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | // this->center_->attach(newShip); |
---|
| 266 | } |
---|
| 267 | |
---|
[9136] | 268 | /* |
---|
| 269 | void TowerDefense::playerEntered(PlayerInfo* player) |
---|
| 270 | { |
---|
| 271 | Deathmatch::playerEntered(player); |
---|
| 272 | |
---|
| 273 | const std::string& message = player->getName() + " entered the game"; |
---|
| 274 | ChatManager::message(message); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | bool TowerDefense::playerLeft(PlayerInfo* player) |
---|
| 278 | { |
---|
| 279 | bool valid_player = Deathmatch::playerLeft(player); |
---|
| 280 | |
---|
| 281 | if (valid_player) |
---|
| 282 | { |
---|
| 283 | const std::string& message = player->getName() + " left the game"; |
---|
| 284 | ChatManager::message(message); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | return valid_player; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | void TowerDefense::pawnKilled(Pawn* victim, Pawn* killer) |
---|
| 292 | { |
---|
| 293 | if (victim && victim->getPlayer()) |
---|
| 294 | { |
---|
| 295 | std::string message; |
---|
| 296 | if (killer) |
---|
| 297 | { |
---|
| 298 | if (killer->getPlayer()) |
---|
| 299 | message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName(); |
---|
| 300 | else |
---|
| 301 | message = victim->getPlayer()->getName() + " was killed"; |
---|
| 302 | } |
---|
| 303 | else |
---|
| 304 | message = victim->getPlayer()->getName() + " died"; |
---|
| 305 | |
---|
| 306 | ChatManager::message(message); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | Deathmatch::pawnKilled(victim, killer); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | void TowerDefense::playerScored(PlayerInfo* player) |
---|
| 313 | { |
---|
| 314 | Gametype::playerScored(player); |
---|
| 315 | |
---|
| 316 | }*/ |
---|
[9098] | 317 | } |
---|