Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gameimmersion/src/modules/weapons/projectiles/Rocket.cc @ 8740

Last change on this file since 8740 was 8542, checked in by simonmie, 14 years ago

comments added, unused parts removed, some spam messages removed

  • Property svn:eol-style set to native
File size: 8.3 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:
[8542]25 *      simonmie
[6119]26 *
27 */
28
29#include "Rocket.h"
30
[6378]31#include <BulletDynamics/Dynamics/btRigidBody.h>
32
33#include "core/CoreIncludes.h"
[6119]34#include "core/XMLPort.h"
[6378]35#include "worldentities/CameraPosition.h"
[6119]36#include "worldentities/pawns/Pawn.h"
37#include "graphics/ParticleSpawner.h"
38#include "graphics/Model.h"
39#include "objects/collisionshapes/ConeCollisionShape.h"
40#include "infos/PlayerInfo.h"
41#include "controllers/Controller.h"
[6247]42#include "sound/WorldSound.h"
[7163]43#include "Scene.h"
[6247]44
[6119]45namespace orxonox
46{
[6120]47    CreateFactory(Rocket);
[6119]48    // create the factory for the Rocket
49
50    /**
51    @brief
52        Constructor. Registers the object and initializes some default values.
53    */
[8533]54    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator), BasicProjectile()
[6119]55    {
56        RegisterObject(Rocket);// - register the Rocket class to the core
57
[6120]58        this->localAngularVelocity_ = 0;
[6315]59        this->lifetime_ = 100;
[6387]60
[6119]61        if (GameMode::isMaster())
62        {
63            this->setCollisionType(WorldEntity::Kinematic);
64            this->setVelocity(0,0,-100);
[6387]65
[6167]66            Model* model = new Model(this);
67            model->setMeshSource("rocket.mesh");
[6502]68            model->scale(0.7f);
[6167]69            this->attach(model);
70            ParticleEmitter* fire = new ParticleEmitter(this);
[6119]71            this->attach(fire);
72            fire->setOrientation(this->getOrientation());
73            fire->setSource("Orxonox/rocketfire");
[6387]74
[6119]75            this->enableCollisionCallback();
76            this->setCollisionResponse(false);
77            this->setCollisionType(Kinematic);
78
[6167]79            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
80            collisionShape->setRadius(3);
81            collisionShape->setHeight(500);
82            this->attachCollisionShape(collisionShape);
[6119]83
84            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
[6387]85
[6313]86            this->defSndWpnEngine_ = new WorldSound(this);
87            this->defSndWpnEngine_->setLooping(true);
88            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
[7848]89            this->defSndWpnEngine_->setVolume(1.0f);
[6313]90            this->attach(defSndWpnEngine_);
[6285]91
[6313]92            this->defSndWpnLaunch_ = new WorldSound(this);
93            this->defSndWpnLaunch_->setLooping(false);
94            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
[7848]95            this->defSndWpnLaunch_->setVolume(1.0f);
[6313]96            this->attach(defSndWpnLaunch_);
97        }
98        else
99        {
100            this->defSndWpnEngine_ = 0;
101            this->defSndWpnLaunch_ = 0;
102        }
[6387]103
[6315]104        CameraPosition* camPosition = new CameraPosition(this);
105        camPosition->setPosition(0,4,15);
106        camPosition->setAllowMouseLook(true);
107        this->addCameraPosition(camPosition);
[6119]108    }
109
110    /**
111    @brief
[6247]112        Destructor. Destroys controller, if present and kills sounds, if playing.
[6119]113    */
114    Rocket::~Rocket()
115    {
116        if(this->isInitialized())
117        {
[7163]118            if (GameMode::isMaster())
119            {
120                this->destructionEffect();
[6383]121
[7163]122                if (this->getPlayer() && this->getController())
123                    this->player_->stopTemporaryControl();
124            }
125
[6315]126            if ( this->defSndWpnEngine_ )
[6381]127                this->defSndWpnEngine_->destroy();
[6383]128
[6315]129            if ( this->defSndWpnLaunch_ )
[6381]130                this->defSndWpnLaunch_->destroy();
[6119]131        }
132    }
133
134    /**
135    @brief
136        Method for creating a Rocket through XML.
137    */
138    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
139    {
140        // this calls the XMLPort function of the parent class
141        SUPER(Rocket, XMLPort, xmlelement, mode);
142    }
[6387]143
[6119]144    void Rocket::setOwner(Pawn* owner)
145    {
146        this->owner_ = owner;
[8538]147        this->player_ = this->getOwner()->getPlayer();
148        this->getOwner()->getPlayer()->startTemporaryControl(this);
[6247]149
[6315]150        if( GameMode::isMaster() )
151        {
152            this->defSndWpnEngine_->play();
153            this->defSndWpnLaunch_->play();
154        }
[6119]155    }
156
157    /**
158    @brief
159        Defines which actions the Rocket has to take in each tick.
160    @param dt
161        The length of the tick.
162    */
163    void Rocket::tick(float dt)
164    {
165        SUPER(Rocket, tick, dt);
[6387]166
[6119]167        if( this->hasLocalController() )
168        {
169            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
170            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
171            this->localAngularVelocity_ = 0;
[7163]172        }
[6387]173
[7163]174        if( GameMode::isMaster() )
175        {
[8533]176            if( this->getBDestroy() )
[6119]177                this->destroy();
[7163]178
[6119]179        }
180    }
[6387]181
[8542]182    /* Calls the collidesAgainst function of BasicProjectile
183     */
[6119]184    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
185    {
[8538]186        return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);
[6119]187    }
[6387]188
[6119]189    void Rocket::destroyObject()
190    {
191        if (GameMode::isMaster())
[6247]192        {
193            if(this->defSndWpnEngine_->isPlaying())
194            {
195                this->defSndWpnEngine_->stop();
196            }
[6119]197            this->destroy();
[6247]198        }
[6119]199    }
[6387]200
[6119]201    void Rocket::fired(unsigned int firemode)
202    {
[8542]203        this->destroy();
[7163]204    }
[7848]205
[7163]206    void Rocket::destructionEffect()
207    {
208        ParticleSpawner *effect1, *effect2;
[8538]209        if( this->getOwner() )
[6119]210        {
[8538]211            effect1 = new ParticleSpawner(this->getOwner()->getCreator());
212            effect2 = new ParticleSpawner(this->getOwner()->getCreator());
[6119]213        }
[7163]214        else
215        {
216            effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
217            effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
218        }
[7848]219
[7163]220        effect1->setPosition(this->getPosition());
221        effect1->setOrientation(this->getOrientation());
222        effect1->setDestroyAfterLife(true);
223        effect1->setSource("Orxonox/explosion4");
224        effect1->setLifetime(2.0f);
[7848]225
[7163]226        effect2->setPosition(this->getPosition());
227        effect2->setOrientation(this->getOrientation());
228        effect2->setDestroyAfterLife(true);
229        effect2->setSource("Orxonox/smoke4");
230        effect2->setLifetime(3.0f);
[6119]231    }
232
233    /**
234    @brief
235        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
236    @param value
237        The vector determining the amount of the angular movement.
238    */
239    void Rocket::rotateYaw(const Vector2& value)
240    {
241        ControllableEntity::rotateYaw(value);
[6387]242
[6119]243        if( !this->isInMouseLook() )
244            this->localAngularVelocity_.y += value.x;
245    }
246
247    /**
248    @brief
249        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
250    @param value
251        The vector determining the amount of the angular movement.
252    */
253    void Rocket::rotatePitch(const Vector2& value)
254    {
255        ControllableEntity::rotatePitch(value);
[6387]256
[6119]257        if( !this->isInMouseLook() )
258            this->localAngularVelocity_.x += value.x;
259    }
260
261    /**
262    @brief
263        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
264    @param value
265        The vector determining the amount of the angular movement.
266    */
267    void Rocket::rotateRoll(const Vector2& value)
268    {
269        ControllableEntity::rotateRoll(value);
[6387]270
[6119]271        if( !this->isInMouseLook() )
272            this->localAngularVelocity_.z += value.x;
273    }
[6387]274
[6119]275}
Note: See TracBrowser for help on using the repository browser.