Bug Summary

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

Annotated Source Code

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