Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc @ 9154

Last change on this file since 9154 was 9154, checked in by mentzerf, 13 years ago
  • Fixed size of oxw stuff.

+ Added tileScale to TowerDefenseCenterpoint to store the scale of the oxw

  • Removed WaypointController debug prints
File size: 8.9 KB
RevLine 
[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 *
68 * c) Im TowerDefense gamtype muss im Constructor noch das HUD-Template gesetzt werden.
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"
79
[9122]80#include "worldentities/SpawnPoint.h"
81#include "worldentities/pawns/Pawn.h"
[9129]82#include "worldentities/pawns/SpaceShip.h"
[9142]83#include "controllers/WaypointController.h"
84         
85#include "graphics/Model.h"
86#include "infos/PlayerInfo.h"
87         
[9138]88#include "chat/ChatManager.h"
89
[9136]90/* Part of a temporary hack to allow the player to add towers */
91#include "core/command/ConsoleCommand.h"
92
[9112]93namespace orxonox
94{
95    CreateUnloadableFactory(TowerDefense);
[9136]96       
97        TowerDefense::TowerDefense(BaseObject* creator) : Deathmatch(creator)
[9112]98    {
99        RegisterObject(TowerDefense);
[9136]100               
101                /* Temporary hack to allow the player to add towers */
102                this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
[9142]103       
104                // Quick hack to test waypoints
105                createConsoleCommand( "aw", createExecutor( createFunctor(&TowerDefense::addWaypointsAndFirstEnemy, this) ) );
[9112]106    }
[9136]107       
108    TowerDefense::~TowerDefense()
109    {
[9139]110                /* Part of a temporary hack to allow the player to add towers */
[9136]111        if (this->isInitialized())
112        {
113            if( this->dedicatedAddTower_ )
114                delete this->dedicatedAddTower_;
115        }
116    }
117       
118        void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint)
119        {
[9139]120                orxout() << "Centerpoint now set..." << endl;
[9136]121                this->center_ = centerpoint;
122        }
123       
[9112]124    void TowerDefense::start()
125    {
126        Deathmatch::start();
[9138]127               
[9139]128        orxout() << "Adding towers for debug..." << endl;
[9138]129               
[9139]130                // Mark corners
131                addTower(0,15); addTower(15,0);
[9138]132               
[9139]133                // Mark diagonal line
[9138]134                for (int i = 0 ; i <= 15; i++)
135                        addTower(i,i);
136               
[9139]137                orxout() << "Done" << endl;
[9138]138               
139                ChatManager::message("Use the console command addTower x y to add towers");
[9143]140
141                //TODO: let the player control his controllable entity && TODO: create a new ControllableEntity for the player
142
[9139]143        }
[9136]144       
[9139]145        void TowerDefense::end()
146        {
147                Deathmatch::end();
[9136]148         
[9139]149                ChatManager::message("Match is over");
150        }
[9136]151       
[9139]152       
[9136]153        void TowerDefense::addTower(int x, int y)
154        {
[9154]155                unsigned int width = this->center_->getWidth();
156                unsigned int height = this->center_->getHeight();
157                int tileScale = (int) this->center_->getTileScale();
158               
159                orxout() << "tile scale = " << tileScale << endl;
160               
161                if (x > 15 || y > 15 || x < 0 || y < 0)
[9136]162                {
[9154]163                        //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet)
[9138]164                        orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl;
[9136]165                        return;
166                }
167               
[9154]168                orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
[9136]169               
[9137]170                Tower* newTower = new Tower(this->center_);
171                newTower->addTemplate(this->center_->getTowerTemplate());
[9136]172               
[9137]173                this->center_->attach(newTower);
174               
[9154]175                newTower->setPosition((x-8) * tileScale, (y-8) * tileScale, 0);
[9137]176                newTower->setGame(this);
[9143]177                //TODO: Save the Tower in a Vector. I would suggest std::vector< std::vector<Tower*> > towers_ as a protected member variable;
[9137]178               
[9136]179                // TODO: create Tower mesh
180                // TODO: load Tower mesh
181        }
182       
[9123]183        void TowerDefense::tick(float dt)
184    {
185        SUPER(TowerDefense, tick, dt);
[9136]186               
[9142]187        static int test = 0;
188        if (++test == 10)
[9129]189        {
[9142]190                        orxout()<< "10th tick." <<endl;
191                        /*
192                        for (std::set<SpawnPoint*>::iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); it++)
193                        {
194                                orxout() << "checking spawnpoint with name " << (*it)->getSpawnClass()->getName() << endl;
195                        }
196                        */
197                       
198                        //addWaypointsAndFirstEnemy();
199                       
[9116]200        }
[9123]201    }
[9136]202       
[9142]203        // Function to test if we can add waypoints using code only. Doesn't work yet
204       
205        // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL???
206       
207        void TowerDefense::addWaypointsAndFirstEnemy()
208        {
209                SpaceShip *newShip = new SpaceShip(this->center_);
210                newShip->addTemplate("spaceshipassff");
211               
212                WaypointController *newController = new WaypointController(newShip);
213                newController->setAccuracy(3);
214               
215                Model *wayPoint1 = new Model(newController);
216                wayPoint1->setMeshSource("crate.mesh"); 
217                wayPoint1->setPosition(7,-7,5);
218                wayPoint1->setScale(0.2);
219                       
220                Model *wayPoint2 = new Model(newController);
221                wayPoint2->setMeshSource("crate.mesh");
222                wayPoint2->setPosition(7,7,5);
223                wayPoint2->setScale(0.2);
224                       
225                newController->addWaypoint(wayPoint1);
226                newController->addWaypoint(wayPoint2);
227                       
228                // The following line causes the game to crash
[9148]229
230                newShip->setController(newController);
[9142]231//              newController -> getPlayer() -> startControl(newShip);
232                newShip->setPosition(-7,-7,5);
233                newShip->setScale(0.1);
[9148]234                //newShip->addSpeed(1);
[9142]235               
236               
237               
238//              this->center_->attach(newShip);
239        }
240       
[9136]241        /*
242         void TowerDefense::playerEntered(PlayerInfo* player)
243         {
244         Deathmatch::playerEntered(player);
245         
246         const std::string& message = player->getName() + " entered the game";
247         ChatManager::message(message);
248         }
249         
250         bool TowerDefense::playerLeft(PlayerInfo* player)
251         {
252         bool valid_player = Deathmatch::playerLeft(player);
253         
254         if (valid_player)
255         {
256         const std::string& message = player->getName() + " left the game";
257         ChatManager::message(message);
258         }
259         
260         return valid_player;
261         }
262         
263         
264         void TowerDefense::pawnKilled(Pawn* victim, Pawn* killer)
265         {
266         if (victim && victim->getPlayer())
267         {
268         std::string message;
269         if (killer)
270         {
271         if (killer->getPlayer())
272         message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
273         else
274         message = victim->getPlayer()->getName() + " was killed";
275         }
276         else
277         message = victim->getPlayer()->getName() + " died";
278         
279         ChatManager::message(message);
280         }
281         
282         Deathmatch::pawnKilled(victim, killer);
283         }
284         
285         void TowerDefense::playerScored(PlayerInfo* player)
286         {
287         Gametype::playerScored(player);
288         
289         }*/
[9098]290}
Note: See TracBrowser for help on using the repository browser.