Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8895 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
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        this->bIsRocket_= true;
69
70        if (GameMode::isMaster())
71        {
72            this->setCollisionType(WorldEntity::Kinematic);
73            this->setVelocity(0,0,-100);
74
75            // Create rocket model
76            Model* model = new Model(this);
77            model->setMeshSource("rocket.mesh");
78            model->scale(0.7f);
79            this->attach(model);
80
81            // Add effects.
82            ParticleEmitter* fire = new ParticleEmitter(this);
83            this->attach(fire);
84            fire->setOrientation(this->getOrientation());
85            fire->setSource("Orxonox/rocketfire");
86
87            this->enableCollisionCallback();
88            this->setCollisionResponse(false);
89            this->setCollisionType(Kinematic);
90
91            // Add collision shape
92            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
93            collisionShape->setRadius(3);
94            collisionShape->setHeight(500);
95            this->attachCollisionShape(collisionShape);
96
97            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
98
99            // Add sound
100            this->defSndWpnEngine_ = new WorldSound(this);
101            this->defSndWpnEngine_->setLooping(true);
102            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
103            this->defSndWpnEngine_->setVolume(1.0f);
104            this->attach(defSndWpnEngine_);
105
106            this->defSndWpnLaunch_ = new WorldSound(this);
107            this->defSndWpnLaunch_->setLooping(false);
108            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
109            this->defSndWpnLaunch_->setVolume(1.0f);
110            this->attach(defSndWpnLaunch_);
111        }
112        else
113        {
114            this->defSndWpnEngine_ = 0;
115            this->defSndWpnLaunch_ = 0;
116        }
117
118        // Add camera
119        CameraPosition* camPosition = new CameraPosition(this);
120        camPosition->setPosition(0,4,15);
121        camPosition->setAllowMouseLook(true);
122        this->addCameraPosition(camPosition);
123
124        this->setRadarObjectColour(ColourValue(1.0, 0.5, 0.0)); // orange
125        this->setRadarObjectShape(RadarViewable::Triangle);
126        this->setRadarObjectScale(0.5f);
127    }
128
129    /**
130    @brief
131        Destructor. Destroys controller, if present and kills sounds, if playing.
132    */
133    Rocket::~Rocket()
134    {
135        if(this->isInitialized())
136        {
137            this->bIsRocket_= false;
138            if (GameMode::isMaster())
139            {
140                this->destructionEffect();
141
142                if (this->getPlayer() && this->getController())
143                    this->player_->stopTemporaryControl();
144            }
145
146            if ( this->defSndWpnEngine_ )
147                this->defSndWpnEngine_->destroy();
148
149            if ( this->defSndWpnLaunch_ )
150                this->defSndWpnLaunch_->destroy();
151        }
152    }
153
154    /**
155    @brief
156        Sets the entity that fired the Rocket.
157    @param shooter
158        A pointer to the Pawn that fired the Rocket.
159    */
160    void Rocket::setShooter(Pawn* shooter)
161    {
162        this->BasicProjectile::setShooter(shooter);
163       
164        this->player_ = this->getShooter()->getPlayer();
165        this->getShooter()->getPlayer()->startTemporaryControl(this);
166
167        if( GameMode::isMaster() )
168        {
169            this->defSndWpnEngine_->play();
170            this->defSndWpnLaunch_->play();
171        }
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);
183
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;
189        }
190
191       this->destroyCheck();
192    }
193
194    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
195    {
196        return this->processCollision(otherObject, contactPoint);
197    }
198
199    /**
200    @brief
201        Destroys the Rocket and stops the sound,
202    */
203    void Rocket::destroyObject(void)
204    {
205        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
206            this->defSndWpnEngine_->stop();
207
208        this->BasicProjectile::destroyObject();
209    }
210
211    /**
212    @brief
213        Destroys the Rocket upon pressing "fire".
214    */
215    void Rocket::fired(unsigned int firemode)
216    {
217        this->destroyObject();
218    }
219
220    /**
221    @brief
222        The effects that are displayed, when the Rocket is destroyed.
223    */
224    void Rocket::destructionEffect()
225    {
226        ParticleSpawner *effect1, *effect2;
227        if(this->getShooter())
228        {
229            effect1 = new ParticleSpawner(this->getShooter()->getCreator());
230            effect2 = new ParticleSpawner(this->getShooter()->getCreator());
231        }
232        else
233        {
234            effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
235            effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
236        }
237
238        effect1->setPosition(this->getPosition());
239        effect1->setOrientation(this->getOrientation());
240        effect1->setDestroyAfterLife(true);
241        effect1->setSource("Orxonox/explosion4");
242        effect1->setLifetime(2.0f);
243
244        effect2->setPosition(this->getPosition());
245        effect2->setOrientation(this->getOrientation());
246        effect2->setDestroyAfterLife(true);
247        effect2->setSource("Orxonox/smoke4");
248        effect2->setLifetime(3.0f);
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);
260
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);
274
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);
288
289        if( !this->isInMouseLook() )
290            this->localAngularVelocity_.z += value.x;
291    }
292
293}
Note: See TracBrowser for help on using the repository browser.