Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7163 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • 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        CommandExecutor::execute("setTimeFactor 1", false);
240
241        if (this->isInitialized())
242        {
243            if (this->debrisFire1_)
244            {
245                this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem());
246                this->debrisFire1_->destroy();
247            }
248            if (this->debrisSmoke1_)
249            {
250                this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
251                this->debrisSmoke1_->destroy();
252            }
253
254            if (this->debrisFire2_)
255            {
256                this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
257                this->debrisFire2_->destroy();
258            }
259            if (this->debrisSmoke2_)
260            {
261                this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
262                this->debrisSmoke2_->destroy();
263            }
264
265            if (this->debrisFire3_)
266            {
267                this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
268                this->debrisFire3_->destroy();
269            }
270            if (this->debrisSmoke3_)
271            {
272                this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
273                this->debrisSmoke3_->destroy();
274            }
275
276            if (this->debrisFire4_)
277            {
278                this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
279                this->debrisFire4_->destroy();
280            }
281            if (this->debrisSmoke4_)
282            {
283                this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
284                this->debrisSmoke4_->destroy();
285            }
286        }
287    }
288
289    void BigExplosion::registerVariables()
290    {
291        registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged));
292        registerVariable(this->bStop_,       VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop));
293    }
294
295    void BigExplosion::LODchanged()
296    {
297        if (this->debrisFire1_)
298            this->debrisFire1_->setDetailLevel(this->LOD_);
299        if (this->debrisSmoke1_)
300            this->debrisSmoke1_->setDetailLevel(this->LOD_);
301
302        if (this->debrisFire2_)
303            this->debrisFire2_->setDetailLevel(this->LOD_);
304        if (this->debrisSmoke2_)
305            this->debrisSmoke2_->setDetailLevel(this->LOD_);
306
307        if (this->debrisFire3_)
308            this->debrisFire3_->setDetailLevel(this->LOD_);
309        if (this->debrisSmoke3_)
310            this->debrisSmoke3_->setDetailLevel(this->LOD_);
311
312        if (this->debrisFire4_)
313            this->debrisFire4_->setDetailLevel(this->LOD_);
314        if (this->debrisSmoke4_)
315            this->debrisSmoke4_->setDetailLevel(this->LOD_);
316    }
317
318    void BigExplosion::checkStop()
319    {
320        if (this->bStop_)
321            this->stop();
322    }
323
324    void BigExplosion::stop()
325    {
326        if (this->debrisFire1_)
327            this->debrisFire1_->setEnabled(false);
328        if (this->debrisSmoke1_)
329            this->debrisSmoke1_->setEnabled(false);
330
331        if (this->debrisFire2_)
332            this->debrisFire2_->setEnabled(false);
333        if (this->debrisSmoke2_)
334            this->debrisSmoke2_->setEnabled(false);
335
336        if (this->debrisFire3_)
337            this->debrisFire3_->setEnabled(false);
338        if (this->debrisSmoke3_)
339            this->debrisSmoke3_->setEnabled(false);
340
341        if (this->debrisFire4_)
342            this->debrisFire4_->setEnabled(false);
343        if (this->debrisSmoke4_)
344            this->debrisSmoke4_->setEnabled(false);
345
346        if (GameMode::isMaster())
347        {
348            this->bStop_ = true;
349            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this)));
350        }
351    }
352
353/* TODO
354
355    void BigExplosion::setDebrisMeshes()
356    {
357
358    }
359    void BigExplosion::getDebrisMeshes()
360    {
361
362    }
363*/
364
365     void BigExplosion::tick(float dt)
366    {
367//        static const unsigned int CHANGES_PER_SECOND = 10;
368
369
370/*        if (GameMode::isMaster() && rnd() < dt*(this->cps_))
371        {
372
373            if(this->timeFactor_ < 1 )
374                this->timeFactor_ += 0.05;
375
376            if(this->firstTick_)
377                this->cps_ = 256;
378
379            std::ostringstream o;
380            o << this->stf_ << this->timeFactor_;
381            CommandExecutor::execute(o.str() ,false);
382            if(this->cps_>50)
383                this->cps_/=2;
384            this->firstTick_ = false;
385            COUT(0) << timeFactor_ << std::endl;
386        }
387*/
388
389        SUPER(BigExplosion, tick, dt);
390    }
391}
Note: See TracBrowser for help on using the repository browser.