Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/weapons/projectiles/SimpleRocket.cc @ 7127

Last change on this file since 7127 was 7127, checked in by rgrieder, 14 years ago

Removed excess white space at the end of lines.

File size: 7.9 KB
RevLine 
[6778]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 *      ...
26 *
27 */
28
29#include "SimpleRocket.h"
30
31#include <BulletDynamics/Dynamics/btRigidBody.h>
32
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35#include "worldentities/pawns/Pawn.h"
36#include "graphics/ParticleSpawner.h"
37#include "graphics/Model.h"
38#include "objects/collisionshapes/ConeCollisionShape.h"
39#include "infos/PlayerInfo.h"
40#include "controllers/Controller.h"
[6803]41#include "weapons/RocketController.h"
[6778]42#include "sound/WorldSound.h"
[6815]43#include "util/Debug.h"
[6778]44
45namespace orxonox
46{
[7025]47
[6778]48    CreateFactory(SimpleRocket);
49
50    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator)
51    {
52        RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
53
54        this->localAngularVelocity_ = 0;
55        this->bDestroy_ = false;
[7018]56        this->lifetime_ = 120;
[7021]57
[7018]58        this->setMass(15);
[6951]59        COUT(4) << "simplerocket constructed\n";
[6778]60
[6900]61        if (GameMode::isMaster())
[7019]62        {
[7018]63            this->setCollisionType(WorldEntity::Kinematic);
64            this->fuel_=true;
[6778]65
66            Model* model = new Model(this);
[6827]67            model->setMeshSource("rocket.mesh");
[6834]68            model->scale(0.7f);
[6778]69            this->attach(model);
[6834]70
[7018]71            this->fire_ = new ParticleEmitter(this);
72            this->attach(this->fire_);
[7127]73
[7018]74            this->fire_->setOrientation(this->getOrientation());
75            this->fire_->setSource("Orxonox/simplerocketfire");
[6778]76            this->enableCollisionCallback();
77            this->setCollisionResponse(false);
78            this->setCollisionType(Kinematic);
79
[6949]80            // TODO: fix the orientation and size of this collision shape to match the rocket
[6778]81            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
[7018]82            collisionShape->setOrientation(this->getOrientation());
83            collisionShape->setRadius(1.5f);
[6949]84            collisionShape->setHeight(5);
[6834]85            this->attachCollisionShape(collisionShape);
[6778]86            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
[6900]87        }
[6778]88
89    }
[7018]90
91
[7127]92
[7021]93    /**
94    * @brief updates state of rocket, disables fire if no fuel
95    * @param dt tick-length
96    */
[6951]97    void SimpleRocket::tick(float dt)
[6900]98    {
[7018]99
[6900]100        SUPER(SimpleRocket, tick, dt);
[7019]101        if ( GameMode::isMaster() )
102        {
[6902]103
[7021]104
[6902]105            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
106            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
[6949]107            this->localAngularVelocity_ = 0;
[6902]108
[7127]109
[7019]110            if (this->fuel_)
111            {
[7127]112                if (this->destroyTimer_.getRemainingTime()<  (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ )
[7018]113                    this->fuel_=false;
[7021]114            } else
[7019]115                this->disableFire();
[7018]116
[7127]117            if( this->bDestroy_ )
[6902]118                this->destroy();
[7019]119        }
[7127]120
[6951]121    }
[6778]122
[7021]123    /**
124    * @brief Sets the Acceleration to 0 and detaches the fire
125    * @return void
126    */
[7019]127    void SimpleRocket::disableFire()
128    {
[7127]129        this->setAcceleration(0,0,0);
[7021]130        this->fire_->detachFromParent();
[7018]131    }
132
[6810]133    /**s
[6778]134    @brief
135        Destructor. Destroys controller, if present and kills sounds, if playing.
136    */
137    SimpleRocket::~SimpleRocket()
138    {
[7127]139        if (this->isInitialized())
[6951]140        {
[7019]141            if( GameMode::isMaster() )
142            {
143                this->getController()->destroy();
144            }
[6951]145        }
146    }
[6778]147
148    /**
149    @brief
150        Method for creating a SimpleRocket through XML.
151    */
152    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
153    {
154        // this calls the XMLPort function of the parent class
155        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
156    }
157
158    void SimpleRocket::setOwner(Pawn* owner)
159    {
160        this->owner_ = owner;
161        this->player_ = this->owner_->getPlayer();
162    }
163
164
[7018]165
[7021]166
[6778]167    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
168    {
169        if (!this->bDestroy_ && GameMode::isMaster())
170        {
171            if (otherObject == this->owner_)
172                return false;
173
174            this->bDestroy_ = true;
175
176            if (this->owner_)
177            {
178                {
179                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
180                    effect->setPosition(this->getPosition());
181                    effect->setOrientation(this->getOrientation());
182                    effect->setDestroyAfterLife(true);
183                    effect->setSource("Orxonox/explosion4");
184                    effect->setLifetime(2.0f);
185                }
186
187                {
188                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
189                    effect->setPosition(this->getPosition());
190                    effect->setOrientation(this->getOrientation());
191                    effect->setDestroyAfterLife(true);
192                    effect->setSource("Orxonox/smoke4");
193                    effect->setLifetime(3.0f);
194                }
195            }
196
197            float dmg = this->damage_;
[6951]198//             if (this->owner_)
199//                 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
[6778]200
201            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
202            if (victim)
203                victim->hit(this->owner_, contactPoint, dmg);
204        }
205        return false;
206    }
207
208    void SimpleRocket::destroyObject()
209    {
210        if (GameMode::isMaster())
211        {
212            this->destroy();
213        }
214    }
215
216    /**
217    @brief
218        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
219    @param value
220        The vector determining the amount of the angular movement.
221    */
222    void SimpleRocket::rotateYaw(const Vector2& value)
223    {
224        ControllableEntity::rotateYaw(value);
225
226        if( !this->isInMouseLook() )
227            this->localAngularVelocity_.y += value.x;
228    }
229
230    /**
231    @brief
232        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
233    @param value
234        The vector determining the amount of the angular movement.
235    */
236    void SimpleRocket::rotatePitch(const Vector2& value)
237    {
238        ControllableEntity::rotatePitch(value);
239
240        if( !this->isInMouseLook() )
241            this->localAngularVelocity_.x += value.x;
242    }
243
244    /**
245    @brief
246        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
247    @param value
248        The vector determining the amount of the angular movement.
249    */
250    void SimpleRocket::rotateRoll(const Vector2& value)
251    {
252        ControllableEntity::rotateRoll(value);
253
254        if( !this->isInMouseLook() )
255            this->localAngularVelocity_.z += value.x;
256    }
257
258}
Note: See TracBrowser for help on using the repository browser.