Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/worldentities/BigExplosion.cc @ 3177

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

Removed old msvc specific support for precompiled header files.

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