Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6699 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

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