Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 13.1 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, this, createExecutor(createFunctor(&BigExplosion::stop)));
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->debris1_ = new Model(this);
105        this->debris2_ = new Model(this);
106        this->debris3_ = new Model(this);
107        this->debris4_ = new Model(this);
108
109        this->explosion_ = new StaticEntity(this);
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        {
178            Model* part1 = new Model(this);
179            Model* part2 = new Model(this);
180
181            MovableEntity* partEntity1 = new MovableEntity(this);
182            MovableEntity* partEntity2 = new MovableEntity(this);
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());
228                delete this->debrisFire1_;
229            }
230            if (this->debrisSmoke1_)
231            {
232                this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
233                delete this->debrisSmoke1_;
234            }
235
236            if (this->debrisFire2_)
237            {
238                this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
239                delete this->debrisFire2_;
240            }
241            if (this->debrisSmoke2_)
242            {
243                this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
244                delete this->debrisSmoke2_;
245            }
246
247            if (this->debrisFire3_)
248            {
249                this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
250                delete this->debrisFire3_;
251            }
252            if (this->debrisSmoke3_)
253            {
254                this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
255                delete this->debrisSmoke3_;
256            }
257
258            if (this->debrisFire4_)
259            {
260                this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
261                delete this->debrisFire4_;
262            }
263            if (this->debrisSmoke4_)
264            {
265                this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
266                delete this->debrisSmoke4_;
267            }
268        }
269    }
270
271    void BigExplosion::registerVariables()
272    {
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));
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;
331            this->destroyTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&BigExplosion::destroy)));
332        }
333    }
334
335    void BigExplosion::destroy()
336    {
337        delete this;
338    }
339
340/* TODO
341
342    void BigExplosion::setDebrisMeshes()
343    {
344
345    }
346    void BigExplosion::getDebrisMeshes()
347    {
348
349    }
350*/
351
352     void BigExplosion::tick(float dt)
353    {
354//        static const unsigned int CHANGES_PER_SECOND = 10;
355
356
357/*        if (GameMode::isMaster() && rnd() < dt*(this->cps_))
358        {
359
360            if(this->timeFactor_ < 1 )
361                this->timeFactor_ += 0.05;
362
363            if(this->firstTick_)
364                this->cps_ = 256;
365
366            std::ostringstream o;
367            o << this->stf_ << this->timeFactor_;
368            CommandExecutor::execute(o.str() ,false);
369            if(this->cps_>50)
370                this->cps_/=2;
371            this->firstTick_ = false;
372            COUT(0) << timeFactor_ << std::endl;
373        }
374*/
375
376        SUPER(BigExplosion, tick, dt);
377    }
378}
Note: See TracBrowser for help on using the repository browser.