Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8891 was 8891, checked in by jo, 13 years ago

Ai and tutorial improvements merged back to the trunk. AI features: all weapons are used, the ai-firestrength is configurable, bots are able to collect pickups . I've set the tutorial level as default level.

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