Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/BigExplosion.cc @ 7171

Last change on this file since 7171 was 7171, checked in by landauf, 14 years ago

removed a strange line that changed the game speed with a console command in the destructor of BigExplosion

  • Property svn:eol-style set to native
File size: 13.7 KB
Line 
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
43namespace 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: " << Exception::handleMessage() << 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, createExecutor(createFunctor(&BigExplosion::stop, this)));
93        }
94        this->registerVariables();
95    }
96
97    void BigExplosion::init()
98    {
99        this->debrisEntity1_ = new MovableEntity(this);
100        this->debrisEntity2_ = new MovableEntity(this);
101        this->debrisEntity3_ = new MovableEntity(this);
102        this->debrisEntity4_ = new MovableEntity(this);
103       
104        this->debrisEntity1_->setSyncMode(0);
105        this->debrisEntity2_->setSyncMode(0);
106        this->debrisEntity3_->setSyncMode(0);
107        this->debrisEntity4_->setSyncMode(0);
108
109        this->debris1_ = new Model(this);
110        this->debris2_ = new Model(this);
111        this->debris3_ = new Model(this);
112        this->debris4_ = new Model(this);
113       
114        this->debris1_->setSyncMode(0);
115        this->debris2_->setSyncMode(0);
116        this->debris3_->setSyncMode(0);
117        this->debris4_->setSyncMode(0);
118
119        this->explosion_ = new StaticEntity(this);
120        this->explosion_->setSyncMode(0);
121
122        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
123        this->debrisSmoke2_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
124        this->debrisSmoke3_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
125        this->debrisSmoke4_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
126
127        this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
128        this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
129        this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
130        this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
131
132        this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem());
133        this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem());
134        this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem());
135        this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem());
136        this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem());
137        this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem());
138        this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem());
139        this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem());
140
141        this->debris1_->setMeshSource("CockpitDebris.mesh");
142        this->debris2_->setMeshSource("WingDebris1.mesh");
143        this->debris3_->setMeshSource("BodyDebris1.mesh");
144        this->debris4_->setMeshSource("WingDebris2.mesh");
145
146        this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
147        this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
148        this->debrisEntity1_->setScale(4);
149
150        this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
151        this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
152        this->debrisEntity2_->setScale(4);
153
154        this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
155        this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
156        this->debrisEntity3_->setScale(4);
157
158        this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
159        this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
160        this->debrisEntity4_->setScale(4);
161
162        this->debrisEntity1_->attach(debris1_);
163        this->debrisEntity2_->attach(debris2_);
164        this->debrisEntity3_->attach(debris3_);
165        this->debrisEntity4_->attach(debris4_);
166
167        ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
168        effect->setDestroyAfterLife(true);
169        effect->setSource("Orxonox/explosion2b");
170        effect->setLifetime(4.0f);
171        effect->setSyncMode(0);
172
173        ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator());
174        effect2->setDestroyAfterLife(true);
175        effect2->setSource("Orxonox/smoke6");
176        effect2->setLifetime(4.0f);
177        effect2->setSyncMode(0);
178
179        this->explosion_->attach(effect);
180        this->explosion_->attach(effect2);
181
182        this->attach(explosion_);
183        this->attach(debrisEntity1_);
184        this->attach(debrisEntity2_);
185        this->attach(debrisEntity3_);
186        this->attach(debrisEntity4_);
187
188
189        for(int i=0;i<10;i++)
190        {
191            Model* part1 = new Model(this);
192            Model* part2 = new Model(this);
193
194            MovableEntity* partEntity1 = new MovableEntity(this);
195            MovableEntity* partEntity2 = new MovableEntity(this);
196           
197            part1->setSyncMode(0);
198            part2->setSyncMode(0);
199            partEntity1->setSyncMode(0);
200            partEntity2->setSyncMode(0);
201
202            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
203            partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
204            partEntity1->setScale(rnd(1, 3));
205
206            partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100));
207            partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
208            partEntity2->setScale(rnd(1, 3));
209
210            part1->setMeshSource("SmallPart1.mesh");
211            part2->setMeshSource("SmallPart2.mesh");
212
213            partEntity1->attach(part1);
214            partEntity2->attach(part2);
215
216            this->attach(partEntity1);
217            this->attach(partEntity2);
218        }
219    }
220
221    void BigExplosion::initZero()
222    {
223        this->debrisFire1_ = 0;
224        this->debrisFire2_ = 0;
225        this->debrisFire3_ = 0;
226        this->debrisFire4_ = 0;
227
228        this->debrisSmoke1_ = 0;
229        this->debrisSmoke2_ = 0;
230        this->debrisSmoke3_ = 0;
231        this->debrisSmoke4_ = 0;
232
233        this->explosionSmoke_=0;
234        this->explosionFire_=0;
235    }
236
237    BigExplosion::~BigExplosion()
238    {
239        if (this->isInitialized())
240        {
241            if (this->debrisFire1_)
242            {
243                this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem());
244                this->debrisFire1_->destroy();
245            }
246            if (this->debrisSmoke1_)
247            {
248                this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
249                this->debrisSmoke1_->destroy();
250            }
251
252            if (this->debrisFire2_)
253            {
254                this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
255                this->debrisFire2_->destroy();
256            }
257            if (this->debrisSmoke2_)
258            {
259                this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
260                this->debrisSmoke2_->destroy();
261            }
262
263            if (this->debrisFire3_)
264            {
265                this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
266                this->debrisFire3_->destroy();
267            }
268            if (this->debrisSmoke3_)
269            {
270                this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
271                this->debrisSmoke3_->destroy();
272            }
273
274            if (this->debrisFire4_)
275            {
276                this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
277                this->debrisFire4_->destroy();
278            }
279            if (this->debrisSmoke4_)
280            {
281                this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
282                this->debrisSmoke4_->destroy();
283            }
284        }
285    }
286
287    void BigExplosion::registerVariables()
288    {
289        registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged));
290        registerVariable(this->bStop_,       VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop));
291    }
292
293    void BigExplosion::LODchanged()
294    {
295        if (this->debrisFire1_)
296            this->debrisFire1_->setDetailLevel(this->LOD_);
297        if (this->debrisSmoke1_)
298            this->debrisSmoke1_->setDetailLevel(this->LOD_);
299
300        if (this->debrisFire2_)
301            this->debrisFire2_->setDetailLevel(this->LOD_);
302        if (this->debrisSmoke2_)
303            this->debrisSmoke2_->setDetailLevel(this->LOD_);
304
305        if (this->debrisFire3_)
306            this->debrisFire3_->setDetailLevel(this->LOD_);
307        if (this->debrisSmoke3_)
308            this->debrisSmoke3_->setDetailLevel(this->LOD_);
309
310        if (this->debrisFire4_)
311            this->debrisFire4_->setDetailLevel(this->LOD_);
312        if (this->debrisSmoke4_)
313            this->debrisSmoke4_->setDetailLevel(this->LOD_);
314    }
315
316    void BigExplosion::checkStop()
317    {
318        if (this->bStop_)
319            this->stop();
320    }
321
322    void BigExplosion::stop()
323    {
324        if (this->debrisFire1_)
325            this->debrisFire1_->setEnabled(false);
326        if (this->debrisSmoke1_)
327            this->debrisSmoke1_->setEnabled(false);
328
329        if (this->debrisFire2_)
330            this->debrisFire2_->setEnabled(false);
331        if (this->debrisSmoke2_)
332            this->debrisSmoke2_->setEnabled(false);
333
334        if (this->debrisFire3_)
335            this->debrisFire3_->setEnabled(false);
336        if (this->debrisSmoke3_)
337            this->debrisSmoke3_->setEnabled(false);
338
339        if (this->debrisFire4_)
340            this->debrisFire4_->setEnabled(false);
341        if (this->debrisSmoke4_)
342            this->debrisSmoke4_->setEnabled(false);
343
344        if (GameMode::isMaster())
345        {
346            this->bStop_ = true;
347            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this)));
348        }
349    }
350
351/* TODO
352
353    void BigExplosion::setDebrisMeshes()
354    {
355
356    }
357    void BigExplosion::getDebrisMeshes()
358    {
359
360    }
361*/
362
363     void BigExplosion::tick(float dt)
364    {
365//        static const unsigned int CHANGES_PER_SECOND = 10;
366
367
368/*        if (GameMode::isMaster() && rnd() < dt*(this->cps_))
369        {
370
371            if(this->timeFactor_ < 1 )
372                this->timeFactor_ += 0.05;
373
374            if(this->firstTick_)
375                this->cps_ = 256;
376
377            std::ostringstream o;
378            o << this->stf_ << this->timeFactor_;
379            CommandExecutor::execute(o.str() ,false);
380            if(this->cps_>50)
381                this->cps_/=2;
382            this->firstTick_ = false;
383            COUT(0) << timeFactor_ << std::endl;
384        }
385*/
386
387        SUPER(BigExplosion, tick, dt);
388    }
389}
Note: See TracBrowser for help on using the repository browser.