Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/modules/weapons/projectiles/Rocket.cc @ 8844

Last change on this file since 8844 was 8738, checked in by landauf, 13 years ago

added "scale" for radar viewables. scale is relative, 1.0 means "normal".
rocket and simple rocket are now visible on the radar as small triangles.
greatly reduced lifetime of simple rocket.
fixed another possible cause for flashing hud radar.

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