Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/RocketOld.cc @ 12273

Last change on this file since 12273 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: 9.3 KB
RevLine 
[10428]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 RocketOld.h
31    @brief Implementation of the RocketOld class.
32*/
33
34#include "RocketOld.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(RocketOld);
55
56    /**
57    @brief
58        Constructor. Registers the object and initializes some default values.
59    */
60    RocketOld::RocketOld(Context* context)
61        : ControllableEntity(context)
62        , BasicProjectile()
63        , RadarViewable(this, static_cast<WorldEntity*>(this))
64    {
65        RegisterObject(RocketOld);// Register the RocketOld class to the core
66
67        this->localAngularVelocity_ = 0;
68        this->lifetime_ = 100.0f;
69
70        if (GameMode::isMaster())
71        {
[11071]72            this->setCollisionType(WorldEntity::CollisionType::Kinematic);
[10428]73            this->setVelocity(0,0,-100);
74
75            // Create RocketOld model
76            Model* model = new Model(this->getContext());
77            model->setMeshSource("rocket.mesh");
78            model->scale(0.7f);
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
[10618]88            //ParticleUniverse::ParticleSystemManager* pManager = ParticleUniverse::ParticleSystemManager::getSingletonPtr();
89            //ParticleUniverse::ParticleSystem* pSys1 = pManager->createParticleSystem("pSys1", "bubbles", this->getScene()->getSceneManager());
90            //this->attachOgreObject(pSys1);
[10428]91
92            this->enableCollisionCallback();
93            this->setCollisionResponse(false);
[11071]94            this->setCollisionType(CollisionType::Kinematic);
[10428]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            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
103
104            // Add sound
105            this->defSndWpnEngine_ = new WorldSound(this->getContext());
106            this->defSndWpnEngine_->setLooping(true);
107            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
108            this->defSndWpnEngine_->setVolume(1.0f);
109            this->attach(defSndWpnEngine_);
110
111            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
112            this->defSndWpnLaunch_->setLooping(false);
113            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
114            this->defSndWpnLaunch_->setVolume(1.0f);
115            this->attach(defSndWpnLaunch_);
116        }
117        else
118        {
[11071]119            this->defSndWpnEngine_ = nullptr;
120            this->defSndWpnLaunch_ = nullptr;
[10428]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
[11071]130        this->setRadarObjectShape(RadarViewable::Shape::Triangle);
[10428]131        this->setRadarObjectScale(0.5f);
132    }
133
134    /**
135    @brief
136        Destructor. Destroys controller, if present and kills sounds, if playing.
137    */
138    RocketOld::~RocketOld()
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 RocketOld.
161    @param shooter
162        A pointer to the Pawn that fired the RocketOld.
163    */
164    void RocketOld::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 RocketOld has to take in each tick.
182    @param dt
183        The length of the tick.
184    */
185    void RocketOld::tick(float dt)
186    {
187        SUPER(RocketOld, 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 RocketOld::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
200    {
201        return this->processCollision(otherObject, contactPoint, cs);
202    }
203
204    /**
205    @brief
206        Destroys the RocketOld and stops the sound,
207    */
208    void RocketOld::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 RocketOld upon pressing "fire".
219    */
220    void RocketOld::fired(unsigned int firemode)
221    {
222        this->destroyObject();
223    }
224
225    /**
226    @brief
227        The effects that are displayed, when the RocketOld is destroyed.
228    */
229    void RocketOld::destructionEffect()
230    {
231        ParticleSpawner *effect1, *effect2;
232        if(this->getShooter())
233        {
234            effect1 = new ParticleSpawner(this->getShooter()->getContext());
235            effect2 = new ParticleSpawner(this->getShooter()->getContext());
236        }
237        else
238        {
239            effect1 = new ParticleSpawner(this->getContext());
240            effect2 = new ParticleSpawner(this->getContext());
241        }
242
243        effect1->setPosition(this->getPosition());
244        effect1->setOrientation(this->getOrientation());
245        effect1->setDestroyAfterLife(true);
246        effect1->setSource("Orxonox/explosion4");
247        effect1->setLifetime(2.0f);
248
249        effect2->setPosition(this->getPosition());
250        effect2->setOrientation(this->getOrientation());
251        effect2->setDestroyAfterLife(true);
252        effect2->setSource("Orxonox/smoke4");
253        effect2->setLifetime(3.0f);
254    }
255
256    /**
257    @brief
258        Rotates the RocketOld around the y-axis by the amount specified by the first component of the input 2-dim vector.
259    @param value
260        The vector determining the amount of the angular movement.
261    */
262    void RocketOld::rotateYaw(const Vector2& value)
263    {
264        ControllableEntity::rotateYaw(value);
265
266        if( !this->isInMouseLook() )
267            this->localAngularVelocity_.y += value.x;
268    }
269
270    /**
271    @brief
272        Rotates the RocketOld around the x-axis by the amount specified by the first component of the input 2-dim vector.
273    @param value
274        The vector determining the amount of the angular movement.
275    */
276    void RocketOld::rotatePitch(const Vector2& value)
277    {
278        ControllableEntity::rotatePitch(value);
279
280        if( !this->isInMouseLook() )
281            this->localAngularVelocity_.x += value.x;
282    }
283
284    /**
285    @brief
286        Rotates the RocketOld around the z-axis by the amount specified by the first component of the input 2-dim vector.
287    @param value
288        The vector determining the amount of the angular movement.
289    */
290    void RocketOld::rotateRoll(const Vector2& value)
291    {
292        ControllableEntity::rotateRoll(value);
293
294        if( !this->isInMouseLook() )
295            this->localAngularVelocity_.z += value.x;
296    }
297
298}
Note: See TracBrowser for help on using the repository browser.