Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fabienHS15/src/modules/weapons/projectiles/Rocket.cc @ 10794

Last change on this file since 10794 was 10794, checked in by fvultier, 9 years ago

bug in the WeaponHUD fixed.

  • Property svn:eol-style set to native
File size: 10.4 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 *      Oliver Scheuss
24 *   Co-authors:
25 *      simonmie
26 *
27 */
28
29/**
30    @file Rocket.h
31    @brief Implementation of the Rocket class.
32*/
33
34#include "Rocket.h"
35
36#include <BulletDynamics/Dynamics/btRigidBody.h>
37
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40
41#include "Scene.h"
42#include "controllers/Controller.h"
43#include "graphics/Model.h"
44#include "graphics/ParticleSpawner.h"
45#include "infos/PlayerInfo.h"
46#include "objects/collisionshapes/ConeCollisionShape.h"
47#include "sound/WorldSound.h"
48#include "worldentities/CameraPosition.h"
49#include "worldentities/pawns/Pawn.h"
50//#include "particleuniverse/include/ParticleUniverseSystemManager.h"
51
52namespace orxonox
53{
54    RegisterClass(Rocket);
55
56    /**
57    @brief
58        Constructor. Registers the object and initializes some default values.
59    */
60    Rocket::Rocket(Context* context)
61        : ControllableEntity(context)
62        , BasicProjectile()
63        , RadarViewable(this, static_cast<WorldEntity*>(this))
64    {
65        RegisterObject(Rocket);// Register the Rocket class to the core
66
67        this->localAngularVelocity_ = 0;
68        this->lifetime_ = 100.0f;
69
70        if (GameMode::isMaster())
71        {
72            this->setCollisionType(WorldEntity::Kinematic);
73            this->setVelocity(0,0,-100);
74
75            // Create rocket model
76            Model* model = new Model(this->getContext());
77            model->setMeshSource("rocket.mesh");
78            model->scale(1.0f);
79            this->attach(model);
80
81            // Add effects.
82            ParticleEmitter* fire = new ParticleEmitter(this->getContext());
83            this->attach(fire);
84            fire->setOrientation(this->getOrientation());
85            fire->setSource("Orxonox/rocketfire");
86           
87            // Add Particle Universe Effects
88            //ParticleUniverse::ParticleSystemManager* pManager = ParticleUniverse::ParticleSystemManager::getSingletonPtr();
89            //ParticleUniverse::ParticleSystem* pSys1 = pManager->createParticleSystem("pSys1", "bubbles", this->getScene()->getSceneManager());
90            //this->attachOgreObject(pSys1);
91
92            this->enableCollisionCallback();
93            this->setCollisionResponse(false);
94            this->setCollisionType(Kinematic);
95
96            // Add collision shape
97            ConeCollisionShape* collisionShape = new ConeCollisionShape(this->getContext());
98            collisionShape->setRadius(3);
99            collisionShape->setHeight(500);
100            this->attachCollisionShape(collisionShape);
101
102            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
103
104            // Add sound
105            this->defSndWpnEngine_ = new WorldSound(this->getContext());
106            this->defSndWpnEngine_->setLooping(true);
107            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
108            this->defSndWpnEngine_->setVolume(1.0f);
109            this->attach(defSndWpnEngine_);
110
111            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
112            this->defSndWpnLaunch_->setLooping(false);
113            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
114            this->defSndWpnLaunch_->setVolume(1.0f);
115            this->attach(defSndWpnLaunch_);
116        }
117        else
118        {
119            this->defSndWpnEngine_ = 0;
120            this->defSndWpnLaunch_ = 0;
121        }
122
123        // Add camera
124        CameraPosition* camPosition = new CameraPosition(this->getContext());
125        camPosition->setPosition(0,4,15);
126        camPosition->setAllowMouseLook(true);
127        this->addCameraPosition(camPosition);
128
129        this->setRadarObjectColour(ColourValue(1.0, 0.5, 0.0)); // orange
130        this->setRadarObjectShape(RadarViewable::Triangle);
131        this->setRadarObjectScale(0.5f);
132    }
133
134    /**
135    @brief
136        Destructor. Destroys controller, if present and kills sounds, if playing.
137    */
138    Rocket::~Rocket()
139    {
140        if(this->isInitialized())
141        {
142            if (GameMode::isMaster())
143            {
144                this->destructionEffect();
145
146                if (this->getPlayer() && this->getController())
147                    this->player_->stopTemporaryControl();
148            }
149
150            if ( this->defSndWpnEngine_ )
151                this->defSndWpnEngine_->destroy();
152
153            if ( this->defSndWpnLaunch_ )
154                this->defSndWpnLaunch_->destroy();
155        }
156    }
157
158    /**
159    @brief
160        Sets the entity that fired the Rocket.
161    @param shooter
162        A pointer to the Pawn that fired the Rocket.
163    */
164    void Rocket::setShooter(Pawn* shooter)
165    {
166        this->BasicProjectile::setShooter(shooter);
167       
168        this->player_ = this->getShooter()->getPlayer();
169        if(this->player_)
170            this->player_->startTemporaryControl(this);
171
172        if( GameMode::isMaster() )
173        {
174            this->defSndWpnEngine_->play();
175            this->defSndWpnLaunch_->play();
176        }
177    }
178
179    /**
180    @brief
181        Defines which actions the Rocket has to take in each tick.
182    @param dt
183        The length of the tick.
184    */
185    void Rocket::tick(float dt)
186    {
187        SUPER(Rocket, tick, dt);
188
189        orxout() << "Rocket::tick" << getScale() << endl;
190
191        if( this->hasLocalController() )
192        {
193            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
194            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
195            this->localAngularVelocity_ = 0;
196        }
197
198       this->destroyCheck();
199    }
200
201    bool Rocket::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
202    {
203        return this->processCollision(otherObject, contactPoint, cs);
204    }
205
206    /**
207    @brief
208        Destroys the Rocket and stops the sound,
209    */
210    void Rocket::destroyObject(void)
211    {
212        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
213            this->defSndWpnEngine_->stop();
214
215        this->BasicProjectile::destroyObject();
216    }
217
218    /**
219    @brief
220        Destroys the Rocket upon pressing "fire".
221    */
222    void Rocket::fired(unsigned int firemode)
223    {
224        this->destroyObject();
225    }
226
227    /**
228    @brief
229        The effects that are displayed, when the Rocket is destroyed.
230    */
231    void Rocket::destructionEffect()
232    {
233        ParticleSpawner *effect1, *effect2, *effect3, *effect4, *effect5;
234        if(this->getShooter())
235        {
236            effect1 = new ParticleSpawner(this->getShooter()->getContext());
237            effect2 = new ParticleSpawner(this->getShooter()->getContext());
238            effect3 = new ParticleSpawner(this->getShooter()->getContext());
239            effect4 = new ParticleSpawner(this->getShooter()->getContext());
240            effect5 = new ParticleSpawner(this->getShooter()->getContext());
241        }
242        else
243        {
244            effect1 = new ParticleSpawner(this->getContext());
245            effect2 = new ParticleSpawner(this->getContext());
246            effect3 = new ParticleSpawner(this->getContext());
247            effect4 = new ParticleSpawner(this->getContext());
248            effect5 = new ParticleSpawner(this->getContext());
249        }
250
251        effect1->setPosition(this->getPosition());
252        effect1->setOrientation(this->getOrientation());
253        effect1->setDestroyAfterLife(true);
254        effect1->setSource("orxonox/explosion_flash");
255        effect1->setLifetime(2.0f);
256
257        effect2->setPosition(this->getPosition());
258        effect2->setOrientation(this->getOrientation());
259        effect2->setDestroyAfterLife(true);
260        effect2->setSource("orxonox/explosion_flame");
261        effect2->setLifetime(3.0f);
262
263        effect3->setPosition(this->getPosition());
264        effect3->setOrientation(this->getOrientation());
265        effect3->setDestroyAfterLife(true);
266        effect3->setSource("orxonox/explosion_shockwave");
267        effect3->setLifetime(3.0f);
268
269        effect4->setPosition(this->getPosition());
270        effect4->setOrientation(this->getOrientation());
271        effect4->setDestroyAfterLife(true);
272        effect4->setSource("orxonox/explosion_sparks");
273        effect4->setLifetime(3.0f);
274
275        effect5->setPosition(this->getPosition());
276        effect5->setOrientation(this->getOrientation());
277        effect5->setDestroyAfterLife(true);
278        effect5->setSource("orxonox/explosion_streak1");
279        effect5->setLifetime(3.0f);
280    }
281
282    /**
283    @brief
284        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
285    @param value
286        The vector determining the amount of the angular movement.
287    */
288    void Rocket::rotateYaw(const Vector2& value)
289    {
290        ControllableEntity::rotateYaw(value);
291
292        if( !this->isInMouseLook() )
293            this->localAngularVelocity_.y += value.x;
294    }
295
296    /**
297    @brief
298        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
299    @param value
300        The vector determining the amount of the angular movement.
301    */
302    void Rocket::rotatePitch(const Vector2& value)
303    {
304        ControllableEntity::rotatePitch(value);
305
306        if( !this->isInMouseLook() )
307            this->localAngularVelocity_.x += value.x;
308    }
309
310    /**
311    @brief
312        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
313    @param value
314        The vector determining the amount of the angular movement.
315    */
316    void Rocket::rotateRoll(const Vector2& value)
317    {
318        ControllableEntity::rotateRoll(value);
319
320        if( !this->isInMouseLook() )
321            this->localAngularVelocity_.z += value.x;
322    }
323
324}
Note: See TracBrowser for help on using the repository browser.