Bug Summary

File:src/modules/towerdefense/TowerDefenseField.cc
Location:line 112, column 13
Description:Value stored to 'upgrade' is never read

Annotated Source Code

1
2/*
3 * ORXONOX - the hottest 3D action shooter ever to exist
4 * > www.orxonox.net <
5 *
6 *
7 * License notice:
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *
23 * Author:
24 * ...
25 * Co-authors:
26 * ...
27 *
28 */
29
30/**
31 @file TowerDefenseField.cc
32 @brief Implementation of the TowerDefenseField class.
33*/
34
35#include "TowerDefenseField.h"
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "TowerDefense.h"
39
40namespace orxonox
41{
42 RegisterClass(TowerDefenseField)orxonox::SI_I& _TowerDefenseFieldIdentifier = (*new orxonox
::SI_I(orxonox::registerClass<TowerDefenseField>("TowerDefenseField"
, new orxonox::ClassFactoryWithContext<TowerDefenseField>
(), true)))
;
43
44 /**
45 @brief
46 Constructor. Registers and initializes the object and checks whether the gametype is actually TowerDefense.
47 */
48 TowerDefenseField::TowerDefenseField(Context* context) : MovableEntity(context)
49 {
50 RegisterObject(TowerDefenseField)if (ClassIdentifier<TowerDefenseField>::getIdentifier()
->initializeObject(this)) return; else ((void)0)
;
51
52 tower_ = nullptr;
53 type_ = TowerDefenseFieldType::FREE;
54 center_ = nullptr;
55 upgrade_ = 0;
56 setPosition(0,0,0);
57 modelGround_ = new Model(getContext());
58 modelGround_->setScale(25);
59 modelGround_->pitch(Degree(90));
60 attach(modelGround_);
61 modelObject_ = new Model(getContext());
62 modelObject_->setScale(25);
63 modelObject_->pitch(Degree(90));
64 attach(modelObject_);
65 setAngle(0);
66 }
67
68 /**
69 @brief
70 Method to create a TowerDefenseField through XML.
71 */
72 void TowerDefenseField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73 {
74 SUPER(TowerDefenseField, XMLPort, xmlelement, mode)(*ClassIdentifier<TowerDefenseField>::getIdentifier()->
superFunctionCaller_XMLPort_)(this, xmlelement, mode)
;
75
76 //XMLPortParam(TowerDefenseField, "width", setWidth, getWidth, xmlelement, mode);
77
78 }
79
80 void TowerDefenseField::setCenterpoint(TowerDefenseCenterpoint* center)
81 {
82 center_ = center;
83 }
84
85 void TowerDefenseField::upgrade()
86 {
87 if (canUpgrade() == true)
88 {
89 destroyTower();
90 createTower(getUpgrade() + 1);
91 }
92 }
93
94 int TowerDefenseField::getUpgrade()
95 {
96 return upgrade_;
97 }
98
99 TowerDefenseFieldType TowerDefenseField::getType()
100 {
101 return type_;
102 }
103
104 void TowerDefenseField::setUpgrade(int upgrade)
105 {
106 if (upgrade < 0)
107 {
108 upgrade_ = 0;
109 }
110 else if (upgrade > 5)
111 {
112 upgrade = 5;
Value stored to 'upgrade' is never read
113 }
114 else
115 {
116 upgrade_ = upgrade;
117 }
118 }
119
120 bool TowerDefenseField::canUpgrade()
121 {
122 if (tower_ != nullptr && upgrade_ < 5)
123 {
124 return true;
125 }
126
127 return false;
128 }
129
130 void TowerDefenseField::setAngle(int newAngle)
131 {
132 if (modelGround_ != nullptr)
133 {
134 switch (newAngle)
135 {
136 case 0:
137 modelGround_->yaw(Degree(0));
138 angle_ = 0;
139 break;
140 case 1:
141 modelGround_->yaw(Degree(90));
142 angle_ = 1;
143 break;
144 case 2:
145 modelGround_->yaw(Degree(180));
146 angle_ = 2;
147 break;
148 case 3:
149 modelGround_->yaw(Degree(270));
150 angle_ = 3;
151 break;
152 }
153 }
154
155 if (modelObject_ != nullptr)
156 {
157 switch (newAngle)
158 {
159 case 0:
160 modelObject_->yaw(Degree(0));
161 angle_ = 0;
162 break;
163 case 1:
164 modelObject_->yaw(Degree(90));
165 angle_ = 1;
166 break;
167 case 2:
168 modelObject_->yaw(Degree(180));
169 angle_ = 2;
170 break;
171 case 3:
172 modelObject_->yaw(Degree(270));
173 angle_ = 3;
174 break;
175 }
176 }
177
178 }
179
180 int TowerDefenseField::getAngle()
181 {
182 return angle_;
183 }
184
185 void TowerDefenseField::createFree(int orientation)
186 {
187 modelGround_->setMeshSource("TD_F1.mesh");
188 tower_ = nullptr;
189 type_ = TowerDefenseFieldType::FREE;
190 setUpgrade(0);
191 setAngle(orientation);
192 }
193
194 void TowerDefenseField::createStart(int orientation)
195 {
196 modelGround_->setMeshSource("TD_S5.mesh");
197 tower_ = nullptr;
198 type_ = TowerDefenseFieldType::START;
199 setUpgrade(0);
200 setAngle(orientation);
201 }
202
203
204 void TowerDefenseField::createEnd(int orientation)
205 {
206 modelGround_->setMeshSource("TD_S4.mesh");
207 tower_ = nullptr;
208 type_ = TowerDefenseFieldType::END;
209 setUpgrade(0);
210 setAngle(orientation);
211 }
212
213 void TowerDefenseField::createStraight(int orientation)
214 {
215 modelGround_->setMeshSource("TD_S1.mesh");
216 tower_ = nullptr;
217 type_ = TowerDefenseFieldType::STREET;
218 setUpgrade(0);
219 setAngle(orientation);
220 }
221
222 void TowerDefenseField::createRCurve(int orientation)
223 {
224 modelGround_->setMeshSource("TD_S2.mesh");
225 tower_ = nullptr;
226 type_ = TowerDefenseFieldType::STREET;
227 setUpgrade(0);
228 setAngle(orientation);
229 }
230
231 void TowerDefenseField::createLCurve(int orientation)
232 {
233 modelGround_->setMeshSource("TD_S3.mesh");
234 tower_ = nullptr;
235 type_ = TowerDefenseFieldType::STREET;
236 setUpgrade(0);
237 setAngle(orientation);
238 }
239
240 void TowerDefenseField::createObstacle(int orientation)
241 {
242 modelGround_->setMeshSource("TD_F1.mesh");
243 modelObject_->setMeshSource("TD_O1.mesh");
244 tower_ = nullptr;
245 type_ = TowerDefenseFieldType::OBSTACLE;
246 setUpgrade(0);
247 setAngle(orientation);
248 }
249
250 void TowerDefenseField::createTower(int upgrade)
251 {
252 if (tower_ == nullptr)
253 {
254 modelGround_->setMeshSource("TD_F1.mesh");
255 tower_ = new TowerDefenseTower(center_->getContext());
256 attach(tower_);
257 type_ = TowerDefenseFieldType::TOWER;
258 setUpgrade(upgrade);
259 if (upgrade_ > 0 && modelObject_ != nullptr)
260 {
261 switch (upgrade_)
262 {
263 case 1:
264 modelObject_->setMeshSource("TD_T1.mesh");
265 tower_->addTemplate(center_->getTower1Template());
266 break;
267 case 2:
268 modelObject_->setMeshSource("TD_T2.mesh");
269 tower_->addTemplate(center_->getTower2Template());
270 break;
271 case 3:
272 modelObject_->setMeshSource("TD_T3.mesh");
273 tower_->addTemplate(center_->getTower3Template());
274 break;
275 case 4:
276 modelObject_->setMeshSource("TD_T4.mesh");
277 tower_->addTemplate(center_->getTower4Template());
278 break;
279 case 5:
280 modelObject_->setMeshSource("TD_T5.mesh");
281 tower_->addTemplate(center_->getTower5Template());
282 break;
283 }
284 }
285
286 }
287 }
288
289 void TowerDefenseField::destroyTower()
290 {
291 if (tower_ != nullptr)
292 {
293 tower_->destroy();
294 tower_ = nullptr;
295 }
296 }
297
298 void TowerDefenseField::create(char object, char param)
299 {
300 int paramInt = atoi(&param);
301 switch (object)
302 {
303 case 'F':
304 createFree(paramInt);
305 break;
306 case 'I':
307 createStraight(paramInt);
308 break;
309 case 'R':
310 createRCurve(paramInt);
311 break;
312 case 'L':
313 createLCurve(paramInt);
314 break;
315 case 'X':
316 createStart(paramInt);
317 break;
318 case 'O':
319 createEnd(paramInt);
320 break;
321 case 'Y':
322 createObstacle(paramInt);
323 break;
324 case 'T':
325 createTower(paramInt);
326 break;
327 }
328 }
329}