1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
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 | * Ich habe die Klasse Deathmatch einfach per Copy&Paste&Rename als Vorlage für euren Deathmatch genommen. |
---|
29 | * Ein Deathmatch erbt vom Gametype. Der einzige Unterschied zum Gametype ist, dass hier ein bisschen |
---|
30 | * Textausgabe stattfindet. Sollte das Später nicht erwünscht sein, könnt ihr einfach die Gametype-Klasse |
---|
31 | * an die Stelle von Deathmatch setzten. |
---|
32 | * |
---|
33 | * Hier empfehle ich euch die gesamte Spielogik unter zu bringen. Viele Funktionen werden automatisch |
---|
34 | * bei gewissen Ereignissen aufgerufen bzw. lösen Ereignisse aus |
---|
35 | * |
---|
36 | *Z.B: |
---|
37 | * start() //wird aufgerufen, bevor das Spiel losgeht |
---|
38 | * end() //wenn man diese Funktion aufruft wird |
---|
39 | * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn ) |
---|
40 | * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben. |
---|
41 | * |
---|
42 | * |
---|
43 | * |
---|
44 | *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: |
---|
45 | * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter |
---|
46 | * tippt, werden die Vorschläge entsprechend gefiltert. |
---|
47 | * |
---|
48 | * |
---|
49 | *TIPP: schaut euch mal Tetris::createStone() an. Dort wird ein TetrisStone-Objekt (ControllableEntity) erzeugt, |
---|
50 | * ihm ein Template zugewiesen (welches vorher im Level definiert wurde und dem CenterPoint übergeben wurde) |
---|
51 | * Ähnlich könnt ihr vorgehen, um einen Turm zu erzeugen. (Zusätzlich braucht ein Turm noch einen Controller) |
---|
52 | * z.B: WaypointPatrolController. Wenn kein Team zugewiesen wurde bekämpft ein WaypointPatrolController alles, |
---|
53 | * was in seiner Reichweite liegt. |
---|
54 | * |
---|
55 | */ |
---|
56 | |
---|
57 | #include "TowerDefense.h" |
---|
58 | #include "Tower.h" |
---|
59 | #include "TowerDefenseCenterpoint.h" |
---|
60 | |
---|
61 | #include "worldentities/SpawnPoint.h" |
---|
62 | #include "worldentities/pawns/Pawn.h" |
---|
63 | #include "worldentities/pawns/SpaceShip.h" |
---|
64 | #include "controllers/WaypointController.h" |
---|
65 | |
---|
66 | #include "graphics/Model.h" |
---|
67 | #include "infos/PlayerInfo.h" |
---|
68 | |
---|
69 | #include "chat/ChatManager.h" |
---|
70 | |
---|
71 | /* Part of a temporary hack to allow the player to add towers */ |
---|
72 | #include "core/command/ConsoleCommand.h" |
---|
73 | |
---|
74 | namespace orxonox |
---|
75 | { |
---|
76 | CreateUnloadableFactory(TowerDefense); |
---|
77 | |
---|
78 | TowerDefense::TowerDefense(BaseObject* creator) : Deathmatch(creator) |
---|
79 | { |
---|
80 | RegisterObject(TowerDefense); |
---|
81 | |
---|
82 | /* Temporary hack to allow the player to add towers */ |
---|
83 | this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); |
---|
84 | |
---|
85 | // Quick hack to test waypoints |
---|
86 | createConsoleCommand( "aw", createExecutor( createFunctor(&TowerDefense::addWaypointsAndFirstEnemy, this) ) ); |
---|
87 | } |
---|
88 | |
---|
89 | TowerDefense::~TowerDefense() |
---|
90 | { |
---|
91 | /* Part of a temporary hack to allow the player to add towers */ |
---|
92 | if (this->isInitialized()) |
---|
93 | { |
---|
94 | if( this->dedicatedAddTower_ ) |
---|
95 | delete this->dedicatedAddTower_; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | void TowerDefense::setCenterpoint(TowerDefenseCenterpoint *centerpoint) |
---|
100 | { |
---|
101 | orxout() << "Centerpoint now set..." << endl; |
---|
102 | this->center_ = centerpoint; |
---|
103 | } |
---|
104 | |
---|
105 | void TowerDefense::start() |
---|
106 | { |
---|
107 | Deathmatch::start(); |
---|
108 | |
---|
109 | orxout() << "Adding towers for debug..." << endl; |
---|
110 | |
---|
111 | // Mark corners |
---|
112 | addTower(0,15); addTower(15,0); |
---|
113 | |
---|
114 | // Mark diagonal line |
---|
115 | for (int i = 0 ; i <= 15; i++) |
---|
116 | addTower(i,i); |
---|
117 | |
---|
118 | orxout() << "Done" << endl; |
---|
119 | |
---|
120 | ChatManager::message("Use the console command addTower x y to add towers"); |
---|
121 | } |
---|
122 | |
---|
123 | void TowerDefense::end() |
---|
124 | { |
---|
125 | Deathmatch::end(); |
---|
126 | |
---|
127 | ChatManager::message("Match is over"); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | void TowerDefense::addTower(int x, int y) |
---|
132 | { |
---|
133 | if (x > 15 || y > 15 || x < 0 || y < 0) |
---|
134 | { |
---|
135 | orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; |
---|
136 | return; |
---|
137 | } |
---|
138 | |
---|
139 | orxout()<< "Will add tower at (" << x << "," << y << ")" << endl; |
---|
140 | |
---|
141 | Tower* newTower = new Tower(this->center_); |
---|
142 | newTower->addTemplate(this->center_->getTowerTemplate()); |
---|
143 | |
---|
144 | this->center_->attach(newTower); |
---|
145 | |
---|
146 | newTower->setPosition(x-8,y-8,0); |
---|
147 | newTower->setGame(this); |
---|
148 | |
---|
149 | // TODO: create Tower mesh |
---|
150 | // TODO: load Tower mesh |
---|
151 | } |
---|
152 | |
---|
153 | void TowerDefense::tick(float dt) |
---|
154 | { |
---|
155 | SUPER(TowerDefense, tick, dt); |
---|
156 | |
---|
157 | static int test = 0; |
---|
158 | if (++test == 10) |
---|
159 | { |
---|
160 | orxout()<< "10th tick." <<endl; |
---|
161 | /* |
---|
162 | for (std::set<SpawnPoint*>::iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); it++) |
---|
163 | { |
---|
164 | orxout() << "checking spawnpoint with name " << (*it)->getSpawnClass()->getName() << endl; |
---|
165 | } |
---|
166 | */ |
---|
167 | |
---|
168 | //addWaypointsAndFirstEnemy(); |
---|
169 | |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | // Function to test if we can add waypoints using code only. Doesn't work yet |
---|
174 | |
---|
175 | // THE PROBLEM: WaypointController's getControllableEntity() returns null, so it won't track. How do we get the controlableEntity to NOT BE NULL??? |
---|
176 | |
---|
177 | void TowerDefense::addWaypointsAndFirstEnemy() |
---|
178 | { |
---|
179 | SpaceShip *newShip = new SpaceShip(this->center_); |
---|
180 | newShip->addTemplate("spaceshipassff"); |
---|
181 | |
---|
182 | WaypointController *newController = new WaypointController(newShip); |
---|
183 | newController->setAccuracy(3); |
---|
184 | |
---|
185 | Model *wayPoint1 = new Model(newController); |
---|
186 | wayPoint1->setMeshSource("crate.mesh"); |
---|
187 | wayPoint1->setPosition(7,-7,5); |
---|
188 | wayPoint1->setScale(0.2); |
---|
189 | |
---|
190 | Model *wayPoint2 = new Model(newController); |
---|
191 | wayPoint2->setMeshSource("crate.mesh"); |
---|
192 | wayPoint2->setPosition(7,7,5); |
---|
193 | wayPoint2->setScale(0.2); |
---|
194 | |
---|
195 | newController->addWaypoint(wayPoint1); |
---|
196 | newController->addWaypoint(wayPoint2); |
---|
197 | |
---|
198 | // The following line causes the game to crash |
---|
199 | // newController -> getPlayer() -> startControl(newShip); |
---|
200 | newShip->setController(newController); |
---|
201 | newShip->setPosition(-7,-7,5); |
---|
202 | newShip->setScale(0.1); |
---|
203 | newShip->addSpeed(1); |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | // this->center_->attach(newShip); |
---|
208 | } |
---|
209 | |
---|
210 | /* |
---|
211 | void TowerDefense::playerEntered(PlayerInfo* player) |
---|
212 | { |
---|
213 | Deathmatch::playerEntered(player); |
---|
214 | |
---|
215 | const std::string& message = player->getName() + " entered the game"; |
---|
216 | ChatManager::message(message); |
---|
217 | } |
---|
218 | |
---|
219 | bool TowerDefense::playerLeft(PlayerInfo* player) |
---|
220 | { |
---|
221 | bool valid_player = Deathmatch::playerLeft(player); |
---|
222 | |
---|
223 | if (valid_player) |
---|
224 | { |
---|
225 | const std::string& message = player->getName() + " left the game"; |
---|
226 | ChatManager::message(message); |
---|
227 | } |
---|
228 | |
---|
229 | return valid_player; |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | void TowerDefense::pawnKilled(Pawn* victim, Pawn* killer) |
---|
234 | { |
---|
235 | if (victim && victim->getPlayer()) |
---|
236 | { |
---|
237 | std::string message; |
---|
238 | if (killer) |
---|
239 | { |
---|
240 | if (killer->getPlayer()) |
---|
241 | message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName(); |
---|
242 | else |
---|
243 | message = victim->getPlayer()->getName() + " was killed"; |
---|
244 | } |
---|
245 | else |
---|
246 | message = victim->getPlayer()->getName() + " died"; |
---|
247 | |
---|
248 | ChatManager::message(message); |
---|
249 | } |
---|
250 | |
---|
251 | Deathmatch::pawnKilled(victim, killer); |
---|
252 | } |
---|
253 | |
---|
254 | void TowerDefense::playerScored(PlayerInfo* player) |
---|
255 | { |
---|
256 | Gametype::playerScored(player); |
---|
257 | |
---|
258 | }*/ |
---|
259 | } |
---|