Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamecontent/src/modules/weapons/projectiles/Rocket.cc @ 9215

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

Tutorial level enhancements (quest work, better texts are still needed), reverted old rocket hack, reworked configurable botlevel for the ai.

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