Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc @ 6247

Last change on this file since 6247 was 6247, checked in by youngk, 14 years ago

Implemented exhaust sound for rocket. Explosion sounds of any sort (either Rocket or Ship) do not work yet.
BUG Firing sound won't attach to HsW01 specifically. Other weapons work.

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