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 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file TixyTaxyTorxy |
---|
31 | TixyTaxyTorxyField.cc |
---|
32 | @brief Implementation of the TixyTaxyTorxy |
---|
33 | TixyTaxyTorxyField class. |
---|
34 | */ |
---|
35 | |
---|
36 | #include "TixyTaxyTorxyField.h" |
---|
37 | #include "core/CoreIncludes.h" |
---|
38 | #include "core/XMLPort.h" |
---|
39 | #include "TixyTaxyTorxy.h" |
---|
40 | #include <iostream> |
---|
41 | |
---|
42 | using namespace std; |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | RegisterClass(TixyTaxyTorxyField); |
---|
47 | int counter=0; |
---|
48 | /** |
---|
49 | @brief |
---|
50 | Constructor. Registers and initializes the object and checks whether the gametype is actually TixyTaxyTorxy |
---|
51 | TixyTaxyTorxy. |
---|
52 | */ |
---|
53 | TixyTaxyTorxyField::TixyTaxyTorxyField(Context* context) : MovableEntity(context) |
---|
54 | { |
---|
55 | RegisterObject(TixyTaxyTorxyField); |
---|
56 | |
---|
57 | tower_ = nullptr; |
---|
58 | type_ = TixyTaxyTorxyFieldType::FREE; |
---|
59 | center_ = nullptr; |
---|
60 | upgrade_ = 0; |
---|
61 | setPosition(0,0,0); |
---|
62 | modelGround_ = new Model(getContext()); |
---|
63 | modelGround_->setScale(25); |
---|
64 | modelGround_->pitch(Degree(90)); |
---|
65 | attach(modelGround_); |
---|
66 | modelObject_ = new Model(getContext()); |
---|
67 | modelObject_->setScale(25); |
---|
68 | modelObject_->pitch(Degree(90)); |
---|
69 | attach(modelObject_); |
---|
70 | setAngle(0); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | @brief |
---|
75 | Method to create a TixyTaxyTorxy |
---|
76 | TixyTaxyTorxyField through XML. |
---|
77 | */ |
---|
78 | void TixyTaxyTorxyField::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
79 | { |
---|
80 | SUPER(TixyTaxyTorxyField, XMLPort, xmlelement, mode); |
---|
81 | |
---|
82 | //XMLPortParam(TixyTaxyTorxyField, "width", setWidth, getWidth, xmlelement, mode); |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | void TixyTaxyTorxyField::setCenterpoint(TixyTaxyTorxyCenterpoint* center) |
---|
87 | { |
---|
88 | center_ = center; |
---|
89 | } |
---|
90 | // void TixyTaxyTorxyField::upgrade() |
---|
91 | // { |
---|
92 | // if (canUpgrade() == true) |
---|
93 | // { |
---|
94 | // destroyTower(); |
---|
95 | // createTower(getUpgrade() + 1); |
---|
96 | // } |
---|
97 | // } |
---|
98 | |
---|
99 | // int TixyTaxyTorxyField::getUpgrade() |
---|
100 | // { |
---|
101 | // return upgrade_; |
---|
102 | // } |
---|
103 | |
---|
104 | // TixyTaxyTorxyFieldType TixyTaxyTorxyField::getType() |
---|
105 | // { |
---|
106 | // return type_; |
---|
107 | // } |
---|
108 | |
---|
109 | void TixyTaxyTorxyField::setUpgrade(int upgrade) |
---|
110 | { |
---|
111 | // upgrade_= counter%2; |
---|
112 | // if (upgrade < 0) |
---|
113 | // { |
---|
114 | // upgrade_ = 0; |
---|
115 | // } |
---|
116 | // else if (upgrade > 5) |
---|
117 | // { |
---|
118 | // upgrade = 5; |
---|
119 | // } |
---|
120 | // else |
---|
121 | // { |
---|
122 | // upgrade_ = upgrade; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | // } |
---|
127 | |
---|
128 | // bool TixyTaxyTorxyField::canUpgrade() |
---|
129 | // { |
---|
130 | // if (tower_ != nullptr && upgrade_ < 5) |
---|
131 | // { |
---|
132 | // return true; |
---|
133 | // } |
---|
134 | |
---|
135 | // return false; |
---|
136 | // } |
---|
137 | |
---|
138 | void TixyTaxyTorxyField::setAngle(int newAngle) |
---|
139 | { |
---|
140 | if (modelGround_ != nullptr) |
---|
141 | { |
---|
142 | switch (newAngle) |
---|
143 | { |
---|
144 | case 0: |
---|
145 | modelGround_->yaw(Degree(0)); |
---|
146 | angle_ = 0; |
---|
147 | break; |
---|
148 | case 1: |
---|
149 | modelGround_->yaw(Degree(90)); |
---|
150 | angle_ = 1; |
---|
151 | break; |
---|
152 | case 2: |
---|
153 | modelGround_->yaw(Degree(180)); |
---|
154 | angle_ = 2; |
---|
155 | break; |
---|
156 | case 3: |
---|
157 | modelGround_->yaw(Degree(270)); |
---|
158 | angle_ = 3; |
---|
159 | break; |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | if (modelObject_ != nullptr) |
---|
164 | { |
---|
165 | switch (newAngle) |
---|
166 | { |
---|
167 | case 0: |
---|
168 | modelObject_->yaw(Degree(0)); |
---|
169 | angle_ = 0; |
---|
170 | break; |
---|
171 | case 1: |
---|
172 | modelObject_->yaw(Degree(90)); |
---|
173 | angle_ = 1; |
---|
174 | break; |
---|
175 | case 2: |
---|
176 | modelObject_->yaw(Degree(180)); |
---|
177 | angle_ = 2; |
---|
178 | break; |
---|
179 | case 3: |
---|
180 | modelObject_->yaw(Degree(270)); |
---|
181 | angle_ = 3; |
---|
182 | break; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | int TixyTaxyTorxyField::getAngle() |
---|
190 | { |
---|
191 | return angle_; |
---|
192 | } |
---|
193 | |
---|
194 | void TixyTaxyTorxyField::createFree(int orientation) |
---|
195 | { |
---|
196 | modelGround_->setMeshSource("TD_F1.mesh"); |
---|
197 | tower_ = nullptr; |
---|
198 | type_ = TixyTaxyTorxyFieldType::FREE; |
---|
199 | setUpgrade(0); |
---|
200 | setAngle(orientation); |
---|
201 | } |
---|
202 | |
---|
203 | void TixyTaxyTorxyField::createStart(int orientation) |
---|
204 | { |
---|
205 | modelGround_->setMeshSource("TD_S5.mesh"); |
---|
206 | tower_ = nullptr; |
---|
207 | type_ = TixyTaxyTorxyFieldType::START; |
---|
208 | setUpgrade(0); |
---|
209 | setAngle(orientation); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | void TixyTaxyTorxyField::createEnd(int orientation) |
---|
214 | { |
---|
215 | modelGround_->setMeshSource("TD_S4.mesh"); |
---|
216 | tower_ = nullptr; |
---|
217 | type_ = TixyTaxyTorxyFieldType::END; |
---|
218 | setUpgrade(0); |
---|
219 | setAngle(orientation); |
---|
220 | } |
---|
221 | |
---|
222 | void TixyTaxyTorxyField::createStraight(int orientation) |
---|
223 | { |
---|
224 | modelGround_->setMeshSource("TD_S1.mesh"); |
---|
225 | tower_ = nullptr; |
---|
226 | type_ = TixyTaxyTorxyFieldType::STREET; |
---|
227 | setUpgrade(0); |
---|
228 | setAngle(orientation); |
---|
229 | } |
---|
230 | |
---|
231 | void TixyTaxyTorxyField::createRCurve(int orientation) |
---|
232 | { |
---|
233 | modelGround_->setMeshSource("TD_S2.mesh"); |
---|
234 | tower_ = nullptr; |
---|
235 | type_ = TixyTaxyTorxyFieldType::STREET; |
---|
236 | setUpgrade(0); |
---|
237 | setAngle(orientation); |
---|
238 | } |
---|
239 | |
---|
240 | void TixyTaxyTorxyField::createLCurve(int orientation) |
---|
241 | { |
---|
242 | modelGround_->setMeshSource("TD_S3.mesh"); |
---|
243 | tower_ = nullptr; |
---|
244 | type_ = TixyTaxyTorxyFieldType::STREET; |
---|
245 | setUpgrade(0); |
---|
246 | setAngle(orientation); |
---|
247 | } |
---|
248 | |
---|
249 | void TixyTaxyTorxyField::createObstacle(int orientation) |
---|
250 | { |
---|
251 | modelGround_->setMeshSource("TD_F1.mesh"); |
---|
252 | modelObject_->setMeshSource("TD_O1.mesh"); |
---|
253 | tower_ = nullptr; |
---|
254 | type_ = TixyTaxyTorxyFieldType::OBSTACLE; |
---|
255 | setUpgrade(0); |
---|
256 | setAngle(orientation); |
---|
257 | } |
---|
258 | |
---|
259 | void TixyTaxyTorxyField::createTower(int upgrade) |
---|
260 | { |
---|
261 | |
---|
262 | if (tower_ == nullptr) |
---|
263 | { |
---|
264 | counter++; |
---|
265 | if(counter%2==0){ |
---|
266 | modelGround_->setMeshSource("TD_T1.mesh"); |
---|
267 | tower_ = new TixyTaxyTorxyTower(center_->getContext()); |
---|
268 | attach(tower_); |
---|
269 | type_ = TixyTaxyTorxyFieldType::TOWER1; |
---|
270 | |
---|
271 | }else{ |
---|
272 | modelGround_->setMeshSource("TD_T2.mesh"); |
---|
273 | tower_ = new TixyTaxyTorxyTower(center_->getContext()); |
---|
274 | attach(tower_); |
---|
275 | type_ = TixyTaxyTorxyFieldType::TOWER2; |
---|
276 | } |
---|
277 | |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | void TixyTaxyTorxyField::destroyTower() |
---|
282 | { |
---|
283 | if (tower_ != nullptr) |
---|
284 | { |
---|
285 | tower_->destroy(); |
---|
286 | tower_ = nullptr; |
---|
287 | } |
---|
288 | } |
---|
289 | |
---|
290 | void TixyTaxyTorxyField::create(char object, char param) |
---|
291 | { |
---|
292 | int paramInt = atoi(¶m); |
---|
293 | switch (object) |
---|
294 | { |
---|
295 | case 'F': |
---|
296 | createFree(paramInt); |
---|
297 | break; |
---|
298 | case 'I': |
---|
299 | createStraight(paramInt); |
---|
300 | break; |
---|
301 | case 'R': |
---|
302 | createRCurve(paramInt); |
---|
303 | break; |
---|
304 | case 'L': |
---|
305 | createLCurve(paramInt); |
---|
306 | break; |
---|
307 | case 'X': |
---|
308 | createStart(paramInt); |
---|
309 | break; |
---|
310 | case 'O': |
---|
311 | createEnd(paramInt); |
---|
312 | break; |
---|
313 | case 'Y': |
---|
314 | createObstacle(paramInt); |
---|
315 | break; |
---|
316 | case 'T': |
---|
317 | createTower(paramInt); |
---|
318 | break; |
---|
319 | } |
---|
320 | } |
---|
321 | } |
---|