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 | * Benjamin de Capitani |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "BigExplosion.h" |
---|
30 | |
---|
31 | //#include <sstream> |
---|
32 | |
---|
33 | #include "util/Exception.h" |
---|
34 | #include "core/CoreIncludes.h" |
---|
35 | #include "core/CommandExecutor.h" |
---|
36 | #include "core/Executor.h" |
---|
37 | #include "core/GameMode.h" |
---|
38 | #include "tools/ParticleInterface.h" |
---|
39 | #include "Scene.h" |
---|
40 | #include "graphics/ParticleSpawner.h" |
---|
41 | #include "graphics/Model.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | CreateFactory(BigExplosion); |
---|
46 | |
---|
47 | BigExplosion::BigExplosion(BaseObject* creator) : MovableEntity(creator) |
---|
48 | { |
---|
49 | RegisterObject(BigExplosion); |
---|
50 | |
---|
51 | if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) ) |
---|
52 | ThrowException(AbortLoading, "Can't create BigExplosion, no scene or no scene manager given."); |
---|
53 | /* |
---|
54 | this->cps_ = 1; |
---|
55 | this->firstTick_ = true; |
---|
56 | */ |
---|
57 | this->bStop_ = false; |
---|
58 | this->LOD_ = LODParticle::Normal; |
---|
59 | |
---|
60 | /* this->stf_ = "setTimeFactor "; |
---|
61 | this->timeFactor_ = 1; |
---|
62 | std::ostringstream o; |
---|
63 | o << stf_ << this->timeFactor_; |
---|
64 | CommandExecutor::execute(o.str() ,false); |
---|
65 | this->timeFactor_ = 0.1; |
---|
66 | */ |
---|
67 | |
---|
68 | if ( GameMode::showsGraphics() ) |
---|
69 | { |
---|
70 | try |
---|
71 | { |
---|
72 | this->init(); |
---|
73 | } |
---|
74 | catch (...) |
---|
75 | { |
---|
76 | COUT(1) << "Error: Couln't load particle effect in BigExplosion." << std::endl; |
---|
77 | this->initZero(); |
---|
78 | } |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | this->initZero(); |
---|
83 | } |
---|
84 | |
---|
85 | if (GameMode::isMaster()) |
---|
86 | { |
---|
87 | Vector3 velocity(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)); |
---|
88 | velocity.normalise(); |
---|
89 | velocity *= rnd(20, 30); |
---|
90 | this->setVelocity(velocity); |
---|
91 | |
---|
92 | this->destroyTimer_.setTimer(rnd(2, 4), false, this, createExecutor(createFunctor(&BigExplosion::stop))); |
---|
93 | } |
---|
94 | this->registerVariables(); |
---|
95 | } |
---|
96 | |
---|
97 | void BigExplosion::init() |
---|
98 | { |
---|
99 | Identifier* idDE1 = Class(MovableEntity); |
---|
100 | BaseObject* oDE1 = idDE1->fabricate(this); |
---|
101 | this->debrisEntity1_ = orxonox_cast<MovableEntity*>(oDE1); |
---|
102 | |
---|
103 | Identifier* idDE2 = Class(MovableEntity); |
---|
104 | BaseObject* oDE2 = idDE2->fabricate(this); |
---|
105 | this->debrisEntity2_ = orxonox_cast<MovableEntity*>(oDE2); |
---|
106 | |
---|
107 | Identifier* idDE3 = Class(MovableEntity); |
---|
108 | BaseObject* oDE3 = idDE3 ->fabricate(this); |
---|
109 | this->debrisEntity3_ = orxonox_cast<MovableEntity*>(oDE3); |
---|
110 | |
---|
111 | Identifier* idDE4 = Class(MovableEntity); |
---|
112 | BaseObject* oDE4 = idDE4->fabricate(this); |
---|
113 | this->debrisEntity4_ = orxonox_cast<MovableEntity*>(oDE4); |
---|
114 | |
---|
115 | Identifier* idD1 = Class(Model); |
---|
116 | BaseObject* oD1 = idD1->fabricate(this); |
---|
117 | this->debris1_ = orxonox_cast<Model*>(oD1); |
---|
118 | |
---|
119 | Identifier* idD2 = Class(Model); |
---|
120 | BaseObject* oD2 = idD2->fabricate(this); |
---|
121 | this->debris2_ = orxonox_cast<Model*>(oD2); |
---|
122 | |
---|
123 | Identifier* idD3 = Class(Model); |
---|
124 | BaseObject* oD3 = idD3->fabricate(this); |
---|
125 | this->debris3_ = orxonox_cast<Model*>(oD3); |
---|
126 | |
---|
127 | Identifier* idD4 = Class(Model); |
---|
128 | BaseObject* oD4 = idD4->fabricate(this); |
---|
129 | this->debris4_ = orxonox_cast<Model*>(oD4); |
---|
130 | |
---|
131 | Identifier* id6 = Class(StaticEntity); |
---|
132 | BaseObject* object4 = id6->fabricate(this); |
---|
133 | this->explosion_ = orxonox_cast<StaticEntity*>(object4); |
---|
134 | |
---|
135 | this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
136 | this->debrisSmoke2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
137 | this->debrisSmoke3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
138 | this->debrisSmoke4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
139 | |
---|
140 | this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
141 | this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
142 | this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
143 | this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
144 | |
---|
145 | this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
146 | this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
147 | this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
148 | this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
149 | this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
150 | this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
151 | this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
152 | this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
153 | |
---|
154 | this->debris1_->setMeshSource("CockpitDebris.mesh"); |
---|
155 | this->debris2_->setMeshSource("WingDebris1.mesh"); |
---|
156 | this->debris3_->setMeshSource("BodyDebris1.mesh"); |
---|
157 | this->debris4_->setMeshSource("WingDebris2.mesh"); |
---|
158 | |
---|
159 | this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
160 | this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
161 | this->debrisEntity1_->setScale(4); |
---|
162 | |
---|
163 | this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
164 | this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
165 | this->debrisEntity2_->setScale(4); |
---|
166 | |
---|
167 | this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
168 | this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
169 | this->debrisEntity3_->setScale(4); |
---|
170 | |
---|
171 | this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
172 | this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
173 | this->debrisEntity4_->setScale(4); |
---|
174 | |
---|
175 | this->debrisEntity1_->attach(debris1_); |
---|
176 | this->debrisEntity2_->attach(debris2_); |
---|
177 | this->debrisEntity3_->attach(debris3_); |
---|
178 | this->debrisEntity4_->attach(debris4_); |
---|
179 | |
---|
180 | ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); |
---|
181 | effect->setDestroyAfterLife(true); |
---|
182 | effect->setSource("Orxonox/explosion2b"); |
---|
183 | effect->setLifetime(4.0f); |
---|
184 | |
---|
185 | ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator()); |
---|
186 | effect2->setDestroyAfterLife(true); |
---|
187 | effect2->setSource("Orxonox/smoke6"); |
---|
188 | effect2->setLifetime(4.0f); |
---|
189 | |
---|
190 | this->explosion_->attach(effect); |
---|
191 | this->explosion_->attach(effect2); |
---|
192 | |
---|
193 | this->attach(explosion_); |
---|
194 | this->attach(debrisEntity1_); |
---|
195 | this->attach(debrisEntity2_); |
---|
196 | this->attach(debrisEntity3_); |
---|
197 | this->attach(debrisEntity4_); |
---|
198 | |
---|
199 | |
---|
200 | for(int i=0;i<10;i++) |
---|
201 | { |
---|
202 | Identifier* idf1 = Class(Model); |
---|
203 | BaseObject* obj1 = idf1->fabricate(this); |
---|
204 | Model* part1 = orxonox_cast<Model*>(obj1); |
---|
205 | |
---|
206 | |
---|
207 | Identifier* idf2 = Class(Model); |
---|
208 | BaseObject* obj2 = idf2->fabricate(this); |
---|
209 | Model* part2 = orxonox_cast<Model*>(obj2); |
---|
210 | |
---|
211 | Identifier* idf3 = Class(MovableEntity); |
---|
212 | BaseObject* obj3 = idf3->fabricate(this); |
---|
213 | MovableEntity* partEntity1 = orxonox_cast<MovableEntity*>(obj3); |
---|
214 | |
---|
215 | Identifier* idf4 = Class(MovableEntity); |
---|
216 | BaseObject* obj4 = idf4->fabricate(this); |
---|
217 | MovableEntity* partEntity2 = orxonox_cast<MovableEntity*>(obj4); |
---|
218 | |
---|
219 | partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100)); |
---|
220 | partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
221 | partEntity1->setScale(rnd(1, 3)); |
---|
222 | |
---|
223 | partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100)); |
---|
224 | partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
225 | partEntity2->setScale(rnd(1, 3)); |
---|
226 | |
---|
227 | part1->setMeshSource("SmallPart1.mesh"); |
---|
228 | part2->setMeshSource("SmallPart2.mesh"); |
---|
229 | |
---|
230 | |
---|
231 | partEntity1->attach(part1); |
---|
232 | partEntity2->attach(part2); |
---|
233 | |
---|
234 | this->attach(partEntity1); |
---|
235 | this->attach(partEntity2); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | void BigExplosion::initZero() |
---|
240 | { |
---|
241 | this->debrisFire1_ = 0; |
---|
242 | this->debrisFire2_ = 0; |
---|
243 | this->debrisFire3_ = 0; |
---|
244 | this->debrisFire4_ = 0; |
---|
245 | |
---|
246 | this->debrisSmoke1_ = 0; |
---|
247 | this->debrisSmoke2_ = 0; |
---|
248 | this->debrisSmoke3_ = 0; |
---|
249 | this->debrisSmoke4_ = 0; |
---|
250 | |
---|
251 | this->explosionSmoke_=0; |
---|
252 | this->explosionFire_=0; |
---|
253 | } |
---|
254 | |
---|
255 | BigExplosion::~BigExplosion() |
---|
256 | { |
---|
257 | CommandExecutor::execute("setTimeFactor 1", false); |
---|
258 | |
---|
259 | if (this->isInitialized()) |
---|
260 | { |
---|
261 | if (this->debrisFire1_) |
---|
262 | { |
---|
263 | this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
264 | delete this->debrisFire1_; |
---|
265 | } |
---|
266 | if (this->debrisSmoke1_) |
---|
267 | { |
---|
268 | this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
269 | delete this->debrisSmoke1_; |
---|
270 | } |
---|
271 | |
---|
272 | if (this->debrisFire2_) |
---|
273 | { |
---|
274 | this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
275 | delete this->debrisFire2_; |
---|
276 | } |
---|
277 | if (this->debrisSmoke2_) |
---|
278 | { |
---|
279 | this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
280 | delete this->debrisSmoke2_; |
---|
281 | } |
---|
282 | |
---|
283 | if (this->debrisFire3_) |
---|
284 | { |
---|
285 | this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
286 | delete this->debrisFire3_; |
---|
287 | } |
---|
288 | if (this->debrisSmoke3_) |
---|
289 | { |
---|
290 | this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
291 | delete this->debrisSmoke3_; |
---|
292 | } |
---|
293 | |
---|
294 | if (this->debrisFire4_) |
---|
295 | { |
---|
296 | this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
297 | delete this->debrisFire4_; |
---|
298 | } |
---|
299 | if (this->debrisSmoke4_) |
---|
300 | { |
---|
301 | this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
302 | delete this->debrisSmoke4_; |
---|
303 | } |
---|
304 | } |
---|
305 | } |
---|
306 | |
---|
307 | void BigExplosion::registerVariables() |
---|
308 | { |
---|
309 | registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged)); |
---|
310 | registerVariable(this->bStop_, VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop)); |
---|
311 | } |
---|
312 | |
---|
313 | void BigExplosion::LODchanged() |
---|
314 | { |
---|
315 | if (this->debrisFire1_) |
---|
316 | this->debrisFire1_->setDetailLevel(this->LOD_); |
---|
317 | if (this->debrisSmoke1_) |
---|
318 | this->debrisSmoke1_->setDetailLevel(this->LOD_); |
---|
319 | |
---|
320 | if (this->debrisFire2_) |
---|
321 | this->debrisFire2_->setDetailLevel(this->LOD_); |
---|
322 | if (this->debrisSmoke2_) |
---|
323 | this->debrisSmoke2_->setDetailLevel(this->LOD_); |
---|
324 | |
---|
325 | if (this->debrisFire3_) |
---|
326 | this->debrisFire3_->setDetailLevel(this->LOD_); |
---|
327 | if (this->debrisSmoke3_) |
---|
328 | this->debrisSmoke3_->setDetailLevel(this->LOD_); |
---|
329 | |
---|
330 | if (this->debrisFire4_) |
---|
331 | this->debrisFire4_->setDetailLevel(this->LOD_); |
---|
332 | if (this->debrisSmoke4_) |
---|
333 | this->debrisSmoke4_->setDetailLevel(this->LOD_); |
---|
334 | } |
---|
335 | |
---|
336 | void BigExplosion::checkStop() |
---|
337 | { |
---|
338 | if (this->bStop_) |
---|
339 | this->stop(); |
---|
340 | } |
---|
341 | |
---|
342 | void BigExplosion::stop() |
---|
343 | { |
---|
344 | if (this->debrisFire1_) |
---|
345 | this->debrisFire1_->setEnabled(false); |
---|
346 | if (this->debrisSmoke1_) |
---|
347 | this->debrisSmoke1_->setEnabled(false); |
---|
348 | |
---|
349 | if (this->debrisFire2_) |
---|
350 | this->debrisFire2_->setEnabled(false); |
---|
351 | if (this->debrisSmoke2_) |
---|
352 | this->debrisSmoke2_->setEnabled(false); |
---|
353 | |
---|
354 | if (this->debrisFire3_) |
---|
355 | this->debrisFire3_->setEnabled(false); |
---|
356 | if (this->debrisSmoke3_) |
---|
357 | this->debrisSmoke3_->setEnabled(false); |
---|
358 | |
---|
359 | if (this->debrisFire4_) |
---|
360 | this->debrisFire4_->setEnabled(false); |
---|
361 | if (this->debrisSmoke4_) |
---|
362 | this->debrisSmoke4_->setEnabled(false); |
---|
363 | |
---|
364 | if (GameMode::isMaster()) |
---|
365 | { |
---|
366 | this->bStop_ = true; |
---|
367 | this->destroyTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&BigExplosion::destroy))); |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | void BigExplosion::destroy() |
---|
372 | { |
---|
373 | delete this; |
---|
374 | } |
---|
375 | |
---|
376 | /* TODO |
---|
377 | |
---|
378 | void BigExplosion::setDebrisMeshes() |
---|
379 | { |
---|
380 | |
---|
381 | } |
---|
382 | void BigExplosion::getDebrisMeshes() |
---|
383 | { |
---|
384 | |
---|
385 | } |
---|
386 | */ |
---|
387 | |
---|
388 | void BigExplosion::tick(float dt) |
---|
389 | { |
---|
390 | // static const unsigned int CHANGES_PER_SECOND = 10; |
---|
391 | |
---|
392 | |
---|
393 | /* if (GameMode::isMaster() && rnd() < dt*(this->cps_)) |
---|
394 | { |
---|
395 | |
---|
396 | if(this->timeFactor_ < 1 ) |
---|
397 | this->timeFactor_ += 0.05; |
---|
398 | |
---|
399 | if(this->firstTick_) |
---|
400 | this->cps_ = 256; |
---|
401 | |
---|
402 | std::ostringstream o; |
---|
403 | o << this->stf_ << this->timeFactor_; |
---|
404 | CommandExecutor::execute(o.str() ,false); |
---|
405 | if(this->cps_>50) |
---|
406 | this->cps_/=2; |
---|
407 | this->firstTick_ = false; |
---|
408 | COUT(0) << timeFactor_ << std::endl; |
---|
409 | } |
---|
410 | */ |
---|
411 | |
---|
412 | SUPER(BigExplosion, tick, dt); |
---|
413 | } |
---|
414 | } |
---|