Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/Rocket.cc @ 11834

Last change on this file since 11834 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 10.6 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;
[11052]68        this->lifetime_ = 20.0f;
[6387]69
[6119]70        if (GameMode::isMaster())
71        {
[11071]72            this->setCollisionType(WorldEntity::CollisionType::Kinematic);
[6119]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");
[11052]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);
[11071]94            this->setCollisionType(CollisionType::Kinematic);
[6119]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            // Add sound
[9667]103            this->defSndWpnEngine_ = new WorldSound(this->getContext());
[6313]104            this->defSndWpnEngine_->setLooping(true);
105            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
[7848]106            this->defSndWpnEngine_->setVolume(1.0f);
[6313]107            this->attach(defSndWpnEngine_);
[6285]108
[9667]109            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
[6313]110            this->defSndWpnLaunch_->setLooping(false);
111            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
[7848]112            this->defSndWpnLaunch_->setVolume(1.0f);
[6313]113            this->attach(defSndWpnLaunch_);
[11052]114
115            this->setHudTemplate("rockethud");
[6313]116        }
117        else
118        {
[11071]119            this->defSndWpnEngine_ = nullptr;
120            this->defSndWpnLaunch_ = nullptr;
[6313]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
[11071]130        this->setRadarObjectShape(RadarViewable::Shape::Triangle);
[8738]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
[6119]189        if( this->hasLocalController() )
190        {
191            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
192            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
193            this->localAngularVelocity_ = 0;
[7163]194        }
[6387]195
[8855]196       this->destroyCheck();
[6119]197    }
[6387]198
[10216]199    bool Rocket::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
[6119]200    {
[10216]201        return this->processCollision(otherObject, contactPoint, cs);
[6119]202    }
[6387]203
[8855]204    /**
205    @brief
206        Destroys the Rocket and stops the sound,
207    */
208    void Rocket::destroyObject(void)
[6119]209    {
[8855]210        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
211            this->defSndWpnEngine_->stop();
212
213        this->BasicProjectile::destroyObject();
[6119]214    }
[6387]215
[8855]216    /**
217    @brief
218        Destroys the Rocket upon pressing "fire".
219    */
[6119]220    void Rocket::fired(unsigned int firemode)
221    {
[8855]222        this->destroyObject();
[7163]223    }
[7848]224
[8855]225    /**
226    @brief
227        The effects that are displayed, when the Rocket is destroyed.
228    */
[7163]229    void Rocket::destructionEffect()
230    {
[10622]231        ParticleSpawner *effect1, *effect2, *effect3, *effect4, *effect5;
[8855]232        if(this->getShooter())
[6119]233        {
[9667]234            effect1 = new ParticleSpawner(this->getShooter()->getContext());
235            effect2 = new ParticleSpawner(this->getShooter()->getContext());
[10622]236            effect3 = new ParticleSpawner(this->getShooter()->getContext());
237            effect4 = new ParticleSpawner(this->getShooter()->getContext());
238            effect5 = new ParticleSpawner(this->getShooter()->getContext());
[6119]239        }
[7163]240        else
241        {
[9667]242            effect1 = new ParticleSpawner(this->getContext());
243            effect2 = new ParticleSpawner(this->getContext());
[10622]244            effect3 = new ParticleSpawner(this->getContext());
245            effect4 = new ParticleSpawner(this->getContext());
246            effect5 = new ParticleSpawner(this->getContext());
[7163]247        }
[7848]248
[7163]249        effect1->setPosition(this->getPosition());
250        effect1->setOrientation(this->getOrientation());
251        effect1->setDestroyAfterLife(true);
[10622]252        effect1->setSource("orxonox/explosion_flash");
[7163]253        effect1->setLifetime(2.0f);
[7848]254
[7163]255        effect2->setPosition(this->getPosition());
256        effect2->setOrientation(this->getOrientation());
257        effect2->setDestroyAfterLife(true);
[10622]258        effect2->setSource("orxonox/explosion_flame");
[7163]259        effect2->setLifetime(3.0f);
[10622]260
261        effect3->setPosition(this->getPosition());
262        effect3->setOrientation(this->getOrientation());
263        effect3->setDestroyAfterLife(true);
264        effect3->setSource("orxonox/explosion_shockwave");
265        effect3->setLifetime(3.0f);
266
267        effect4->setPosition(this->getPosition());
268        effect4->setOrientation(this->getOrientation());
269        effect4->setDestroyAfterLife(true);
270        effect4->setSource("orxonox/explosion_sparks");
271        effect4->setLifetime(3.0f);
272
273        effect5->setPosition(this->getPosition());
274        effect5->setOrientation(this->getOrientation());
275        effect5->setDestroyAfterLife(true);
276        effect5->setSource("orxonox/explosion_streak1");
277        effect5->setLifetime(3.0f);
[6119]278    }
279
280    /**
281    @brief
282        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
283    @param value
284        The vector determining the amount of the angular movement.
285    */
286    void Rocket::rotateYaw(const Vector2& value)
287    {
288        ControllableEntity::rotateYaw(value);
[6387]289
[6119]290        if( !this->isInMouseLook() )
291            this->localAngularVelocity_.y += value.x;
292    }
293
294    /**
295    @brief
296        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
297    @param value
298        The vector determining the amount of the angular movement.
299    */
300    void Rocket::rotatePitch(const Vector2& value)
301    {
302        ControllableEntity::rotatePitch(value);
[6387]303
[6119]304        if( !this->isInMouseLook() )
305            this->localAngularVelocity_.x += value.x;
306    }
307
308    /**
309    @brief
310        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
311    @param value
312        The vector determining the amount of the angular movement.
313    */
314    void Rocket::rotateRoll(const Vector2& value)
315    {
316        ControllableEntity::rotateRoll(value);
[6387]317
[6119]318        if( !this->isInMouseLook() )
319            this->localAngularVelocity_.z += value.x;
320    }
[6387]321
[11052]322    float Rocket::getFuel() const
323    {
324        return this->destroyTimer_.getRemainingTime();
325    }
326
327    void Rocket::setMaxFuel(float fuel)
328    {
329        this->lifetime_ = fuel;
330        this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
331    }
[6119]332}
Note: See TracBrowser for help on using the repository browser.