Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7311 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 9.5 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"
[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    */
54    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
55    {
56        RegisterObject(Rocket);// - register the Rocket class to the core
57
[6120]58        this->localAngularVelocity_ = 0;
[6315]59        this->bDestroy_ = false;
60        this->lifetime_ = 100;
[6387]61
[6119]62        if (GameMode::isMaster())
63        {
64            this->setCollisionType(WorldEntity::Kinematic);
65            this->setVelocity(0,0,-100);
[6387]66
[6167]67            Model* model = new Model(this);
68            model->setMeshSource("rocket.mesh");
[6502]69            model->scale(0.7f);
[6167]70            this->attach(model);
71            ParticleEmitter* fire = new ParticleEmitter(this);
[6119]72            this->attach(fire);
73            fire->setOrientation(this->getOrientation());
74            fire->setSource("Orxonox/rocketfire");
[6387]75
[6119]76            this->enableCollisionCallback();
77            this->setCollisionResponse(false);
78            this->setCollisionType(Kinematic);
79
[6167]80            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
81            collisionShape->setRadius(3);
82            collisionShape->setHeight(500);
83            this->attachCollisionShape(collisionShape);
[6119]84
85            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
[6387]86
[6313]87            this->defSndWpnEngine_ = new WorldSound(this);
88            this->defSndWpnEngine_->setLooping(true);
89            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
[7163]90            this->defSndWpnEngine_->setVolume(100);
[6313]91            this->attach(defSndWpnEngine_);
[6285]92
[6313]93            this->defSndWpnLaunch_ = new WorldSound(this);
94            this->defSndWpnLaunch_->setLooping(false);
95            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
[7163]96            this->defSndWpnLaunch_->setVolume(100);
[6313]97            this->attach(defSndWpnLaunch_);
98        }
99        else
100        {
101            this->defSndWpnEngine_ = 0;
102            this->defSndWpnLaunch_ = 0;
103        }
[6387]104
[6315]105        CameraPosition* camPosition = new CameraPosition(this);
106        camPosition->setPosition(0,4,15);
107        camPosition->setAllowMouseLook(true);
108        this->addCameraPosition(camPosition);
[6119]109    }
110
111    /**
112    @brief
[6247]113        Destructor. Destroys controller, if present and kills sounds, if playing.
[6119]114    */
115    Rocket::~Rocket()
116    {
117        if(this->isInitialized())
118        {
[7163]119            if (GameMode::isMaster())
120            {
121                this->destructionEffect();
[6383]122
[7163]123                if (this->getPlayer() && this->getController())
124                    this->player_->stopTemporaryControl();
125            }
126
[6315]127            if ( this->defSndWpnEngine_ )
[6381]128                this->defSndWpnEngine_->destroy();
[6383]129
[6315]130            if ( this->defSndWpnLaunch_ )
[6381]131                this->defSndWpnLaunch_->destroy();
[6119]132        }
133    }
134
135    /**
136    @brief
137        Method for creating a Rocket through XML.
138    */
139    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
140    {
141        // this calls the XMLPort function of the parent class
142        SUPER(Rocket, XMLPort, xmlelement, mode);
143    }
[6387]144
[6119]145    void Rocket::setOwner(Pawn* owner)
146    {
147        this->owner_ = owner;
148        this->player_ = this->owner_->getPlayer();
149        this->owner_->getPlayer()->startTemporaryControl(this);
[6247]150
[6315]151        if( GameMode::isMaster() )
152        {
153            this->defSndWpnEngine_->play();
154            this->defSndWpnLaunch_->play();
155        }
[6119]156    }
157
158    /**
159    @brief
160        Defines which actions the Rocket has to take in each tick.
161    @param dt
162        The length of the tick.
163    */
164    void Rocket::tick(float dt)
165    {
166        SUPER(Rocket, tick, dt);
[6387]167
[6119]168        if( this->hasLocalController() )
169        {
170            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
171            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
172            this->localAngularVelocity_ = 0;
[7163]173        }
[6387]174
[7163]175        if( GameMode::isMaster() )
176        {
[6119]177            if( this->bDestroy_ )
178                this->destroy();
[7163]179
[6119]180        }
181    }
[6387]182
[6119]183    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
184    {
185        if (!this->bDestroy_ && GameMode::isMaster())
186        {
187            if (otherObject == this->owner_)
188                return false;
[6387]189
[6119]190            this->bDestroy_ = true;
191
192            if (this->owner_)
193            {
194                {
195                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
196                    effect->setPosition(this->getPosition());
197                    effect->setOrientation(this->getOrientation());
198                    effect->setDestroyAfterLife(true);
199                    effect->setSource("Orxonox/explosion4");
200                    effect->setLifetime(2.0f);
201                }
202
203                {
204                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
205                    effect->setPosition(this->getPosition());
206                    effect->setOrientation(this->getOrientation());
207                    effect->setDestroyAfterLife(true);
208                    effect->setSource("Orxonox/smoke4");
209                    effect->setLifetime(3.0f);
210                }
211            }
212
213            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
214            if (victim)
[6540]215                victim->hit(this->owner_, contactPoint, this->damage_);
[6119]216//             this->destroy();
217        }
218        return false;
219    }
[6387]220
[6119]221    void Rocket::destroyObject()
222    {
223        if (GameMode::isMaster())
[6247]224        {
225            if(this->defSndWpnEngine_->isPlaying())
226            {
227                this->defSndWpnEngine_->stop();
228            }
[6119]229            this->destroy();
[6247]230        }
[6119]231    }
[6387]232
[6119]233    void Rocket::fired(unsigned int firemode)
234    {
[7163]235//         if (this->owner_)
236//         {
237            this->destroy();
238//         }
239    }
240   
241    void Rocket::destructionEffect()
242    {
243        ParticleSpawner *effect1, *effect2;
244        if( this->owner_ )
[6119]245        {
[7163]246            effect1 = new ParticleSpawner(this->owner_->getCreator());
247            effect2 = new ParticleSpawner(this->owner_->getCreator());
[6119]248        }
[7163]249        else
250        {
251            effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
252            effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
253        }
254       
255        effect1->setPosition(this->getPosition());
256        effect1->setOrientation(this->getOrientation());
257        effect1->setDestroyAfterLife(true);
258        effect1->setSource("Orxonox/explosion4");
259        effect1->setLifetime(2.0f);
260       
261        effect2->setPosition(this->getPosition());
262        effect2->setOrientation(this->getOrientation());
263        effect2->setDestroyAfterLife(true);
264        effect2->setSource("Orxonox/smoke4");
265        effect2->setLifetime(3.0f);
[6119]266    }
267
268    /**
269    @brief
270        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
271    @param value
272        The vector determining the amount of the angular movement.
273    */
274    void Rocket::rotateYaw(const Vector2& value)
275    {
276        ControllableEntity::rotateYaw(value);
[6387]277
[6119]278        if( !this->isInMouseLook() )
279            this->localAngularVelocity_.y += value.x;
280    }
281
282    /**
283    @brief
284        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
285    @param value
286        The vector determining the amount of the angular movement.
287    */
288    void Rocket::rotatePitch(const Vector2& value)
289    {
290        ControllableEntity::rotatePitch(value);
[6387]291
[6119]292        if( !this->isInMouseLook() )
293            this->localAngularVelocity_.x += value.x;
294    }
295
296    /**
297    @brief
298        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
299    @param value
300        The vector determining the amount of the angular movement.
301    */
302    void Rocket::rotateRoll(const Vector2& value)
303    {
304        ControllableEntity::rotateRoll(value);
[6387]305
[6119]306        if( !this->isInMouseLook() )
307            this->localAngularVelocity_.z += value.x;
308    }
[6387]309
[6119]310}
Note: See TracBrowser for help on using the repository browser.