Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/weapons/projectiles/Rocket.cc @ 7018

Last change on this file since 7018 was 7018, checked in by scheusso, 14 years ago

merged rocket2 branch back into presentation3 branch

  • Property svn:eol-style set to native
File size: 9.2 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:
25 *      ...
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"
43
[6119]44namespace orxonox
45{
[6120]46    CreateFactory(Rocket);
[6119]47    // create the factory for the Rocket
48
49    /**
50    @brief
51        Constructor. Registers the object and initializes some default values.
52    */
53    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
54    {
55        RegisterObject(Rocket);// - register the Rocket class to the core
56
[6120]57        this->localAngularVelocity_ = 0;
[6315]58        this->bDestroy_ = false;
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");
[7018]89            this->defSndWpnEngine_->setVolume(100);
[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");
[7018]95            this->defSndWpnLaunch_->setVolume(100);
[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        {
[6167]118            if (GameMode::isMaster() && this->player_)
[6119]119                this->player_->stopTemporaryControl();
[6383]120
[6315]121            if ( this->defSndWpnEngine_ )
[6381]122                this->defSndWpnEngine_->destroy();
[6383]123
[6315]124            if ( this->defSndWpnLaunch_ )
[6381]125                this->defSndWpnLaunch_->destroy();
[6119]126        }
127    }
128
129    /**
130    @brief
131        Method for creating a Rocket through XML.
132    */
133    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
134    {
135        // this calls the XMLPort function of the parent class
136        SUPER(Rocket, XMLPort, xmlelement, mode);
137    }
[6387]138
[6119]139    void Rocket::setOwner(Pawn* owner)
140    {
141        this->owner_ = owner;
142        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
143        this->player_ = this->owner_->getPlayer();
144        this->owner_->getPlayer()->startTemporaryControl(this);
[6247]145
[6315]146        if( GameMode::isMaster() )
147        {
148            this->defSndWpnEngine_->play();
149            this->defSndWpnLaunch_->play();
150        }
[6119]151    }
152
153    /**
154    @brief
155        Defines which actions the Rocket has to take in each tick.
156    @param dt
157        The length of the tick.
158    */
159    void Rocket::tick(float dt)
160    {
161        SUPER(Rocket, tick, dt);
[6387]162
[6119]163        if( this->hasLocalController() )
164        {
165            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
166            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
167            this->localAngularVelocity_ = 0;
[6964]168        }
169       
170        if( GameMode::isMaster() )
171        {
[6119]172            if( this->bDestroy_ )
173                this->destroy();
[6964]174           
[6119]175        }
176    }
[6387]177
[6119]178    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
179    {
180        if (!this->bDestroy_ && GameMode::isMaster())
181        {
182            if (otherObject == this->owner_)
183                return false;
[6387]184
[6119]185            this->bDestroy_ = true;
186
187            if (this->owner_)
188            {
189                {
190                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
191                    effect->setPosition(this->getPosition());
192                    effect->setOrientation(this->getOrientation());
193                    effect->setDestroyAfterLife(true);
194                    effect->setSource("Orxonox/explosion4");
195                    effect->setLifetime(2.0f);
196                }
197
198                {
199                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
200                    effect->setPosition(this->getPosition());
201                    effect->setOrientation(this->getOrientation());
202                    effect->setDestroyAfterLife(true);
203                    effect->setSource("Orxonox/smoke4");
204                    effect->setLifetime(3.0f);
205                }
206            }
207
208            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
209            if (victim)
[6540]210                victim->hit(this->owner_, contactPoint, this->damage_);
[6119]211//             this->destroy();
212        }
213        return false;
214    }
[6387]215
[6119]216    void Rocket::destroyObject()
217    {
218        if (GameMode::isMaster())
[6247]219        {
220            if(this->defSndWpnEngine_->isPlaying())
221            {
222                this->defSndWpnEngine_->stop();
223            }
[6119]224            this->destroy();
[6247]225        }
[6119]226    }
[6387]227
[6119]228    void Rocket::fired(unsigned int firemode)
229    {
230        if (this->owner_)
231        {
232            {
233                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
234                effect->setPosition(this->getPosition());
235                effect->setOrientation(this->getOrientation());
236                effect->setDestroyAfterLife(true);
237                effect->setSource("Orxonox/explosion4");
238                effect->setLifetime(2.0f);
239            }
240
241            {
242                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
243                effect->setPosition(this->getPosition());
244                effect->setOrientation(this->getOrientation());
245                effect->setDestroyAfterLife(true);
246                effect->setSource("Orxonox/smoke4");
247                effect->setLifetime(3.0f);
248            }
249            this->destroy();
250        }
251    }
252
253    /**
254    @brief
255        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
256    @param value
257        The vector determining the amount of the angular movement.
258    */
259    void Rocket::rotateYaw(const Vector2& value)
260    {
261        ControllableEntity::rotateYaw(value);
[6387]262
[6119]263        if( !this->isInMouseLook() )
264            this->localAngularVelocity_.y += value.x;
265    }
266
267    /**
268    @brief
269        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
270    @param value
271        The vector determining the amount of the angular movement.
272    */
273    void Rocket::rotatePitch(const Vector2& value)
274    {
275        ControllableEntity::rotatePitch(value);
[6387]276
[6119]277        if( !this->isInMouseLook() )
278            this->localAngularVelocity_.x += value.x;
279    }
280
281    /**
282    @brief
283        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
284    @param value
285        The vector determining the amount of the angular movement.
286    */
287    void Rocket::rotateRoll(const Vector2& value)
288    {
289        ControllableEntity::rotateRoll(value);
[6387]290
[6119]291        if( !this->isInMouseLook() )
292            this->localAngularVelocity_.z += value.x;
293    }
[6387]294
[6119]295}
Note: See TracBrowser for help on using the repository browser.