Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/modules/weapons/projectiles/Rocket.cc @ 12362

Last change on this file since 12362 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 10.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/**
30    @file Rocket.h
31    @brief Implementation of the Rocket class.
32*/
33
34#include "Rocket.h"
35
36#include <BulletDynamics/Dynamics/btRigidBody.h>
37
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40
41#include "Scene.h"
42#include "controllers/Controller.h"
43#include "graphics/Model.h"
44#include "graphics/ParticleSpawner.h"
45#include "infos/PlayerInfo.h"
46#include "objects/collisionshapes/ConeCollisionShape.h"
47#include "sound/WorldSound.h"
48#include "worldentities/CameraPosition.h"
49#include "worldentities/pawns/Pawn.h"
50//#include "particleuniverse/include/ParticleUniverseSystemManager.h"
51
52namespace orxonox
53{
54    RegisterClass(Rocket);
55
56    /**
57    @brief
58        Constructor. Registers the object and initializes some default values.
59    */
60    Rocket::Rocket(Context* context)
61        : ControllableEntity(context)
62        , BasicProjectile()
63        , RadarViewable(this, static_cast<WorldEntity*>(this))
64    {
65        RegisterObject(Rocket);// Register the Rocket class to the core
66
67        this->localAngularVelocity_ = 0;
68        this->lifetime_ = 20.0f;
69
70        if (GameMode::isMaster())
71        {
72            this->setCollisionType(WorldEntity::CollisionType::Kinematic);
73            this->setVelocity(0,0,-100);
74
75            // Create rocket model
76            Model* model = new Model(this->getContext());
77            model->setMeshSource("rocket.mesh");
78            model->scale(1.0f);
79            this->attach(model);
80
81            // Add effects.
82            ParticleEmitter* fire = new ParticleEmitter(this->getContext());
83            this->attach(fire);
84            fire->setOrientation(this->getOrientation());
85            fire->setSource("Orxonox/rocketfire");
86           
87            // Add Particle Universe Effects
88            //ParticleUniverse::ParticleSystemManager* pManager = ParticleUniverse::ParticleSystemManager::getSingletonPtr();
89            //ParticleUniverse::ParticleSystem* pSys1 = pManager->createParticleSystem("pSys1", "bubbles", this->getScene()->getSceneManager());
90            //this->attachOgreObject(pSys1);
91
92            this->enableCollisionCallback();
93            this->setCollisionResponse(false);
94            this->setCollisionType(CollisionType::Kinematic);
95
96            // Add collision shape
97            ConeCollisionShape* collisionShape = new ConeCollisionShape(this->getContext());
98            collisionShape->setRadius(3);
99            collisionShape->setHeight(500);
100            this->attachCollisionShape(collisionShape);
101
102            // Add sound
103            this->defSndWpnEngine_ = new WorldSound(this->getContext());
104            this->defSndWpnEngine_->setLooping(true);
105            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
106            this->defSndWpnEngine_->setVolume(1.0f);
107            this->attach(defSndWpnEngine_);
108
109            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
110            this->defSndWpnLaunch_->setLooping(false);
111            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
112            this->defSndWpnLaunch_->setVolume(1.0f);
113            this->attach(defSndWpnLaunch_);
114
115            this->setHudTemplate("rockethud");
116        }
117        else
118        {
119            this->defSndWpnEngine_ = nullptr;
120            this->defSndWpnLaunch_ = nullptr;
121        }
122
123        // Add camera
124        CameraPosition* camPosition = new CameraPosition(this->getContext());
125        camPosition->setPosition(0,4,15);
126        camPosition->setAllowMouseLook(true);
127        this->addCameraPosition(camPosition);
128
129        this->setRadarObjectColour(ColourValue(1.0, 0.5, 0.0)); // orange
130        this->setRadarObjectShape(RadarViewable::Shape::Triangle);
131        this->setRadarObjectScale(0.5f);
132    }
133
134    /**
135    @brief
136        Destructor. Destroys controller, if present and kills sounds, if playing.
137    */
138    Rocket::~Rocket()
139    {
140        if(this->isInitialized())
141        {
142            if (GameMode::isMaster())
143            {
144                this->destructionEffect();
145
146                if (this->getPlayer() && this->getController())
147                    this->player_->stopTemporaryControl();
148            }
149
150            if ( this->defSndWpnEngine_ )
151                this->defSndWpnEngine_->destroy();
152
153            if ( this->defSndWpnLaunch_ )
154                this->defSndWpnLaunch_->destroy();
155        }
156    }
157
158    /**
159    @brief
160        Sets the entity that fired the Rocket.
161    @param shooter
162        A pointer to the Pawn that fired the Rocket.
163    */
164    void Rocket::setShooter(Pawn* shooter)
165    {
166        this->BasicProjectile::setShooter(shooter);
167       
168        this->player_ = this->getShooter()->getPlayer();
169        if(this->player_)
170            this->player_->startTemporaryControl(this);
171
172        if( GameMode::isMaster() )
173        {
174            this->defSndWpnEngine_->play();
175            this->defSndWpnLaunch_->play();
176        }
177    }
178
179    /**
180    @brief
181        Defines which actions the Rocket has to take in each tick.
182    @param dt
183        The length of the tick.
184    */
185    void Rocket::tick(float dt)
186    {
187        SUPER(Rocket, tick, dt);
188
189        if( this->hasLocalController() )
190        {
191            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
192            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
193            this->localAngularVelocity_ = 0;
194        }
195
196       this->destroyCheck();
197    }
198
199    bool Rocket::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
200    {
201        return this->processCollision(otherObject, contactPoint, cs);
202    }
203
204    /**
205    @brief
206        Destroys the Rocket and stops the sound,
207    */
208    void Rocket::destroyObject(void)
209    {
210        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
211            this->defSndWpnEngine_->stop();
212
213        this->BasicProjectile::destroyObject();
214    }
215
216    /**
217    @brief
218        Destroys the Rocket upon pressing "fire".
219    */
220    void Rocket::fired(unsigned int firemode)
221    {
222        this->destroyObject();
223    }
224
225    /**
226    @brief
227        The effects that are displayed, when the Rocket is destroyed.
228    */
229    void Rocket::destructionEffect()
230    {
231        ParticleSpawner *effect1, *effect2, *effect3, *effect4, *effect5;
232        if(this->getShooter())
233        {
234            effect1 = new ParticleSpawner(this->getShooter()->getContext());
235            effect2 = new ParticleSpawner(this->getShooter()->getContext());
236            effect3 = new ParticleSpawner(this->getShooter()->getContext());
237            effect4 = new ParticleSpawner(this->getShooter()->getContext());
238            effect5 = new ParticleSpawner(this->getShooter()->getContext());
239        }
240        else
241        {
242            effect1 = new ParticleSpawner(this->getContext());
243            effect2 = new ParticleSpawner(this->getContext());
244            effect3 = new ParticleSpawner(this->getContext());
245            effect4 = new ParticleSpawner(this->getContext());
246            effect5 = new ParticleSpawner(this->getContext());
247        }
248
249        effect1->setPosition(this->getPosition());
250        effect1->setOrientation(this->getOrientation());
251        effect1->setDestroyAfterLife(true);
252        effect1->setSource("orxonox/explosion_flash");
253        effect1->setLifetime(2.0f);
254
255        effect2->setPosition(this->getPosition());
256        effect2->setOrientation(this->getOrientation());
257        effect2->setDestroyAfterLife(true);
258        effect2->setSource("orxonox/explosion_flame");
259        effect2->setLifetime(3.0f);
260
261        effect3->setPosition(this->getPosition());
262        effect3->setOrientation(this->getOrientation());
263        effect3->setDestroyAfterLife(true);
264        effect3->setSource("orxonox/explosion_shockwave");
265        effect3->setLifetime(3.0f);
266
267        effect4->setPosition(this->getPosition());
268        effect4->setOrientation(this->getOrientation());
269        effect4->setDestroyAfterLife(true);
270        effect4->setSource("orxonox/explosion_sparks");
271        effect4->setLifetime(3.0f);
272
273        effect5->setPosition(this->getPosition());
274        effect5->setOrientation(this->getOrientation());
275        effect5->setDestroyAfterLife(true);
276        effect5->setSource("orxonox/explosion_streak1");
277        effect5->setLifetime(3.0f);
278    }
279
280    /**
281    @brief
282        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
283    @param value
284        The vector determining the amount of the angular movement.
285    */
286    void Rocket::rotateYaw(const Vector2& value)
287    {
288        ControllableEntity::rotateYaw(value);
289
290        if( !this->isInMouseLook() )
291            this->localAngularVelocity_.y += value.x;
292    }
293
294    /**
295    @brief
296        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
297    @param value
298        The vector determining the amount of the angular movement.
299    */
300    void Rocket::rotatePitch(const Vector2& value)
301    {
302        ControllableEntity::rotatePitch(value);
303
304        if( !this->isInMouseLook() )
305            this->localAngularVelocity_.x += value.x;
306    }
307
308    /**
309    @brief
310        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
311    @param value
312        The vector determining the amount of the angular movement.
313    */
314    void Rocket::rotateRoll(const Vector2& value)
315    {
316        ControllableEntity::rotateRoll(value);
317
318        if( !this->isInMouseLook() )
319            this->localAngularVelocity_.z += value.x;
320    }
321
322    float Rocket::getFuel() const
323    {
324        return this->destroyTimer_.getRemainingTime();
325    }
326
327    void Rocket::setMaxFuel(float fuel)
328    {
329        this->lifetime_ = fuel;
330        this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
331    }
332}
Note: See TracBrowser for help on using the repository browser.