Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Launching sound of the Rocket plays normally now. Changed AL_MAX_DISTANCE to 10000.

  • Property svn:eol-style set to native
File size: 9.3 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        this->defSndWpnLaunch_ = new WorldSound(this);
97        this->defSndWpnLaunch_->setLooping(false);
98        this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
99        this->attach(defSndWpnLaunch_);
100    }
101
102    /**
103    @brief
104        Destructor. Destroys controller, if present and kills sounds, if playing.
105    */
106    Rocket::~Rocket()
107    {
108        if(this->isInitialized())
109        {
110            if (GameMode::isMaster() && this->player_)
111            {
112                this->player_->stopTemporaryControl();
113            }
114            if(this->defSndWpnEngine_->isPlaying())
115            {
116                this->defSndWpnEngine_->stop();
117            }
118            if(this->defSndWpnLaunch_->isPlaying())
119            {
120                this->defSndWpnLaunch_->stop();
121            }
122            delete this->defSndWpnEngine_;
123            delete this->defSndWpnLaunch_;
124        }
125    }
126
127    /**
128    @brief
129        Method for creating a Rocket through XML.
130    */
131    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
132    {
133        // this calls the XMLPort function of the parent class
134        SUPER(Rocket, XMLPort, xmlelement, mode);
135    }
136   
137    void Rocket::setOwner(Pawn* owner)
138    {
139        this->owner_ = owner;
140        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
141        this->player_ = this->owner_->getPlayer();
142        this->owner_->getPlayer()->startTemporaryControl(this);
143
144        this->defSndWpnEngine_->play();
145        this->defSndWpnLaunch_->play();
146    }
147
148    /**
149    @brief
150        Defines which actions the Rocket has to take in each tick.
151    @param dt
152        The length of the tick.
153    */
154    void Rocket::tick(float dt)
155    {
156        SUPER(Rocket, tick, dt);
157       
158        if( this->hasLocalController() )
159        {
160            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
161            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
162            this->localAngularVelocity_ = 0;
163           
164            if( this->bDestroy_ )
165                this->destroy();
166        }
167    }
168   
169    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
170    {
171        if (!this->bDestroy_ && GameMode::isMaster())
172        {
173            if (otherObject == this->owner_)
174                return false;
175           
176            this->bDestroy_ = true;
177
178            if (this->owner_)
179            {
180                {
181                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
182                    effect->setPosition(this->getPosition());
183                    effect->setOrientation(this->getOrientation());
184                    effect->setDestroyAfterLife(true);
185                    effect->setSource("Orxonox/explosion4");
186                    effect->setLifetime(2.0f);
187                }
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/smoke4");
195                    effect->setLifetime(3.0f);
196                }
197            }
198
199            float dmg = this->damage_;
200            if (this->owner_)
201                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
202
203            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
204            if (victim)
205                victim->damage(dmg, this->owner_);
206//             this->destroy();
207        }
208        return false;
209    }
210   
211    void Rocket::destroyObject()
212    {
213        if (GameMode::isMaster())
214        {
215            if(this->defSndWpnEngine_->isPlaying())
216            {
217                this->defSndWpnEngine_->stop();
218            }
219            this->destroy();
220        }
221    }
222   
223    void Rocket::fired(unsigned int firemode)
224    {
225        if (this->owner_)
226        {
227            {
228                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
229                effect->setPosition(this->getPosition());
230                effect->setOrientation(this->getOrientation());
231                effect->setDestroyAfterLife(true);
232                effect->setSource("Orxonox/explosion4");
233                effect->setLifetime(2.0f);
234            }
235
236            {
237                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
238                effect->setPosition(this->getPosition());
239                effect->setOrientation(this->getOrientation());
240                effect->setDestroyAfterLife(true);
241                effect->setSource("Orxonox/smoke4");
242                effect->setLifetime(3.0f);
243            }
244            this->destroy();
245        }
246    }
247
248    /**
249    @brief
250        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
251    @param value
252        The vector determining the amount of the angular movement.
253    */
254    void Rocket::rotateYaw(const Vector2& value)
255    {
256        ControllableEntity::rotateYaw(value);
257       
258        if( !this->isInMouseLook() )
259            this->localAngularVelocity_.y += value.x;
260    }
261
262    /**
263    @brief
264        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
265    @param value
266        The vector determining the amount of the angular movement.
267    */
268    void Rocket::rotatePitch(const Vector2& value)
269    {
270        ControllableEntity::rotatePitch(value);
271       
272        if( !this->isInMouseLook() )
273            this->localAngularVelocity_.x += value.x;
274    }
275
276    /**
277    @brief
278        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
279    @param value
280        The vector determining the amount of the angular movement.
281    */
282    void Rocket::rotateRoll(const Vector2& value)
283    {
284        ControllableEntity::rotateRoll(value);
285       
286        if( !this->isInMouseLook() )
287            this->localAngularVelocity_.z += value.x;
288    }
289   
290}
Note: See TracBrowser for help on using the repository browser.