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
RevLine 
[6119]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:
[8706]25 *      simonmie
[6119]26 *
27 */
28
[8855]29/**
30    @file Rocket.h
31    @brief Implementation of the Rocket class.
32*/
33
[6119]34#include "Rocket.h"
35
[6378]36#include <BulletDynamics/Dynamics/btRigidBody.h>
37
38#include "core/CoreIncludes.h"
[6119]39#include "core/XMLPort.h"
[8855]40
41#include "Scene.h"
42#include "controllers/Controller.h"
43#include "graphics/Model.h"
[6119]44#include "graphics/ParticleSpawner.h"
[8855]45#include "infos/PlayerInfo.h"
[6119]46#include "objects/collisionshapes/ConeCollisionShape.h"
[6247]47#include "sound/WorldSound.h"
[8855]48#include "worldentities/CameraPosition.h"
49#include "worldentities/pawns/Pawn.h"
[10622]50//#include "particleuniverse/include/ParticleUniverseSystemManager.h"
[6247]51
[6119]52namespace orxonox
53{
[9667]54    RegisterClass(Rocket);
[6119]55
56    /**
57    @brief
58        Constructor. Registers the object and initializes some default values.
59    */
[9667]60    Rocket::Rocket(Context* context)
61        : ControllableEntity(context)
[8738]62        , BasicProjectile()
[9667]63        , RadarViewable(this, static_cast<WorldEntity*>(this))
[6119]64    {
[8855]65        RegisterObject(Rocket);// Register the Rocket class to the core
[6119]66
[6120]67        this->localAngularVelocity_ = 0;
[8855]68        this->lifetime_ = 100.0f;
[6387]69
[6119]70        if (GameMode::isMaster())
71        {
72            this->setCollisionType(WorldEntity::Kinematic);
73            this->setVelocity(0,0,-100);
[6387]74
[8855]75            // Create rocket model
[9667]76            Model* model = new Model(this->getContext());
[6167]77            model->setMeshSource("rocket.mesh");
[10794]78            model->scale(1.0f);
[6167]79            this->attach(model);
[8855]80
81            // Add effects.
[9667]82            ParticleEmitter* fire = new ParticleEmitter(this->getContext());
[6119]83            this->attach(fire);
84            fire->setOrientation(this->getOrientation());
85            fire->setSource("Orxonox/rocketfire");
[10622]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);
[6387]91
[6119]92            this->enableCollisionCallback();
93            this->setCollisionResponse(false);
94            this->setCollisionType(Kinematic);
95
[8855]96            // Add collision shape
[9667]97            ConeCollisionShape* collisionShape = new ConeCollisionShape(this->getContext());
[6167]98            collisionShape->setRadius(3);
99            collisionShape->setHeight(500);
100            this->attachCollisionShape(collisionShape);
[6119]101
[8855]102            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
[6387]103
[8855]104            // Add sound
[9667]105            this->defSndWpnEngine_ = new WorldSound(this->getContext());
[6313]106            this->defSndWpnEngine_->setLooping(true);
107            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
[7848]108            this->defSndWpnEngine_->setVolume(1.0f);
[6313]109            this->attach(defSndWpnEngine_);
[6285]110
[9667]111            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
[6313]112            this->defSndWpnLaunch_->setLooping(false);
113            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
[7848]114            this->defSndWpnLaunch_->setVolume(1.0f);
[6313]115            this->attach(defSndWpnLaunch_);
116        }
117        else
118        {
119            this->defSndWpnEngine_ = 0;
120            this->defSndWpnLaunch_ = 0;
121        }
[6387]122
[8855]123        // Add camera
[9667]124        CameraPosition* camPosition = new CameraPosition(this->getContext());
[6315]125        camPosition->setPosition(0,4,15);
126        camPosition->setAllowMouseLook(true);
127        this->addCameraPosition(camPosition);
[8738]128
129        this->setRadarObjectColour(ColourValue(1.0, 0.5, 0.0)); // orange
130        this->setRadarObjectShape(RadarViewable::Triangle);
131        this->setRadarObjectScale(0.5f);
[6119]132    }
133
134    /**
135    @brief
[6247]136        Destructor. Destroys controller, if present and kills sounds, if playing.
[6119]137    */
138    Rocket::~Rocket()
139    {
140        if(this->isInitialized())
141        {
[7163]142            if (GameMode::isMaster())
143            {
144                this->destructionEffect();
[6383]145
[7163]146                if (this->getPlayer() && this->getController())
147                    this->player_->stopTemporaryControl();
148            }
149
[6315]150            if ( this->defSndWpnEngine_ )
[6381]151                this->defSndWpnEngine_->destroy();
[6383]152
[6315]153            if ( this->defSndWpnLaunch_ )
[6381]154                this->defSndWpnLaunch_->destroy();
[6119]155        }
156    }
157
158    /**
159    @brief
[8855]160        Sets the entity that fired the Rocket.
161    @param shooter
162        A pointer to the Pawn that fired the Rocket.
[6119]163    */
[8855]164    void Rocket::setShooter(Pawn* shooter)
[6119]165    {
[8855]166        this->BasicProjectile::setShooter(shooter);
167       
168        this->player_ = this->getShooter()->getPlayer();
[9016]169        if(this->player_)
170            this->player_->startTemporaryControl(this);
[6387]171
[6315]172        if( GameMode::isMaster() )
173        {
174            this->defSndWpnEngine_->play();
175            this->defSndWpnLaunch_->play();
176        }
[6119]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);
[6387]188
[10794]189        orxout() << "Rocket::tick" << getScale() << endl;
190
[6119]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;
[7163]196        }
[6387]197
[8855]198       this->destroyCheck();
[6119]199    }
[6387]200
[10216]201    bool Rocket::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
[6119]202    {
[10216]203        return this->processCollision(otherObject, contactPoint, cs);
[6119]204    }
[6387]205
[8855]206    /**
207    @brief
208        Destroys the Rocket and stops the sound,
209    */
210    void Rocket::destroyObject(void)
[6119]211    {
[8855]212        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
213            this->defSndWpnEngine_->stop();
214
215        this->BasicProjectile::destroyObject();
[6119]216    }
[6387]217
[8855]218    /**
219    @brief
220        Destroys the Rocket upon pressing "fire".
221    */
[6119]222    void Rocket::fired(unsigned int firemode)
223    {
[8855]224        this->destroyObject();
[7163]225    }
[7848]226
[8855]227    /**
228    @brief
229        The effects that are displayed, when the Rocket is destroyed.
230    */
[7163]231    void Rocket::destructionEffect()
232    {
[10622]233        ParticleSpawner *effect1, *effect2, *effect3, *effect4, *effect5;
[8855]234        if(this->getShooter())
[6119]235        {
[9667]236            effect1 = new ParticleSpawner(this->getShooter()->getContext());
237            effect2 = new ParticleSpawner(this->getShooter()->getContext());
[10622]238            effect3 = new ParticleSpawner(this->getShooter()->getContext());
239            effect4 = new ParticleSpawner(this->getShooter()->getContext());
240            effect5 = new ParticleSpawner(this->getShooter()->getContext());
[6119]241        }
[7163]242        else
243        {
[9667]244            effect1 = new ParticleSpawner(this->getContext());
245            effect2 = new ParticleSpawner(this->getContext());
[10622]246            effect3 = new ParticleSpawner(this->getContext());
247            effect4 = new ParticleSpawner(this->getContext());
248            effect5 = new ParticleSpawner(this->getContext());
[7163]249        }
[7848]250
[7163]251        effect1->setPosition(this->getPosition());
252        effect1->setOrientation(this->getOrientation());
253        effect1->setDestroyAfterLife(true);
[10622]254        effect1->setSource("orxonox/explosion_flash");
[7163]255        effect1->setLifetime(2.0f);
[7848]256
[7163]257        effect2->setPosition(this->getPosition());
258        effect2->setOrientation(this->getOrientation());
259        effect2->setDestroyAfterLife(true);
[10622]260        effect2->setSource("orxonox/explosion_flame");
[7163]261        effect2->setLifetime(3.0f);
[10622]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);
[6119]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);
[6387]291
[6119]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);
[6387]305
[6119]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);
[6387]319
[6119]320        if( !this->isInMouseLook() )
321            this->localAngularVelocity_.z += value.x;
322    }
[6387]323
[6119]324}
Note: See TracBrowser for help on using the repository browser.