Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc @ 6126

Last change on this file since 6126 was 6120, checked in by rgrieder, 15 years ago

Found some tabs

  • Property svn:eol-style set to native
File size: 8.5 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 *      ...
26 *
27 */
28
29#include "Rocket.h"
30
31#include "core/XMLPort.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33#include "worldentities/pawns/Pawn.h"
34#include "graphics/ParticleSpawner.h"
35#include "graphics/Model.h"
36#include "objects/collisionshapes/ConeCollisionShape.h"
37#include "infos/PlayerInfo.h"
38#include "controllers/Controller.h"
39#include "worldentities/CameraPosition.h"
40
41namespace orxonox
42{
43    CreateFactory(Rocket);
44    // create the factory for the Rocket
45
46    /**
47    @brief
48        Constructor. Registers the object and initializes some default values.
49    */
50    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
51    {
52        RegisterObject(Rocket);// - register the Rocket class to the core
53
54        this->localAngularVelocity_ = 0;
55       
56        if (GameMode::isMaster())
57        {
58            this->setCollisionType(WorldEntity::Kinematic);
59            this->setVelocity(0,0,-100);
60            this->lifetime_ = 100;
61            this->bDestroy_ = false;
62       
63            this->model_ = new Model(this);
64            this->model_->setMeshSource("rocket.mesh");
65            this->attach(this->model_);
66            ParticleSpawner* fire = new ParticleSpawner(this);
67            this->attach(fire);
68            fire->setOrientation(this->getOrientation());
69            fire->setSource("Orxonox/rocketfire");
70       
71            this->enableCollisionCallback();
72            this->setCollisionResponse(false);
73            this->setCollisionType(Kinematic);
74
75            this->collisionShape_ = new ConeCollisionShape(this);
76            this->collisionShape_->setRadius(3);
77            this->collisionShape_->setHeight(500);
78            this->attachCollisionShape(this->collisionShape_);
79
80            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
81        }
82       
83        this->camPosition_ = new CameraPosition(this);
84        this->camPosition_->setPosition(0,10,40);
85        this->camPosition_->setSyncMode(0x0);
86        this->camPosition_->setAllowMouseLook(true);
87        this->attach( this->camPosition_ );
88        this->addCameraPosition( this->camPosition_ );
89    }
90
91    /**
92    @brief
93        Destructor. Destroys controller, if present.
94    */
95    Rocket::~Rocket()
96    {
97        if(this->isInitialized())
98        {
99            if (GameMode::isMaster() && this->player_.get())
100            {
101                this->model_->destroy();
102                this->collisionShape_->destroy();
103                this->player_->stopTemporaryControl();
104            }
105            this->camPosition_->destroy();
106        }
107    }
108
109    /**
110    @brief
111        Method for creating a Rocket through XML.
112    */
113    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
114    {
115        // this calls the XMLPort function of the parent class
116        SUPER(Rocket, XMLPort, xmlelement, mode);
117    }
118   
119    void Rocket::setOwner(Pawn* owner)
120    {
121        this->owner_ = owner;
122        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
123        this->player_ = this->owner_->getPlayer();
124        this->owner_->getPlayer()->startTemporaryControl(this);
125    }
126
127    /**
128    @brief
129        Defines which actions the Rocket has to take in each tick.
130    @param dt
131        The length of the tick.
132    */
133    void Rocket::tick(float dt)
134    {
135        SUPER(Rocket, tick, dt);
136       
137        if( this->hasLocalController() )
138        {
139            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
140            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
141            this->localAngularVelocity_ = 0;
142           
143            if( this->bDestroy_ )
144                this->destroy();
145        }
146    }
147   
148    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
149    {
150        if (!this->bDestroy_ && GameMode::isMaster())
151        {
152            if (otherObject == this->owner_)
153                return false;
154           
155            this->bDestroy_ = true;
156
157            if (this->owner_)
158            {
159                {
160                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
161                    effect->setPosition(this->getPosition());
162                    effect->setOrientation(this->getOrientation());
163                    effect->setDestroyAfterLife(true);
164                    effect->setSource("Orxonox/explosion4");
165                    effect->setLifetime(2.0f);
166                }
167
168                {
169                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
170                    effect->setPosition(this->getPosition());
171                    effect->setOrientation(this->getOrientation());
172                    effect->setDestroyAfterLife(true);
173                    effect->setSource("Orxonox/smoke4");
174                    effect->setLifetime(3.0f);
175                }
176            }
177
178            float dmg = this->damage_;
179            if (this->owner_)
180                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
181
182            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
183            if (victim)
184                victim->damage(dmg, this->owner_);
185//             this->destroy();
186        }
187        return false;
188    }
189   
190    void Rocket::destroyObject()
191    {
192        if (GameMode::isMaster())
193            this->destroy();
194    }
195   
196    void Rocket::fired(unsigned int firemode)
197    {
198        if (this->owner_)
199        {
200            {
201                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
202                effect->setPosition(this->getPosition());
203                effect->setOrientation(this->getOrientation());
204                effect->setDestroyAfterLife(true);
205                effect->setSource("Orxonox/explosion4");
206                effect->setLifetime(2.0f);
207            }
208
209            {
210                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
211                effect->setPosition(this->getPosition());
212                effect->setOrientation(this->getOrientation());
213                effect->setDestroyAfterLife(true);
214                effect->setSource("Orxonox/smoke4");
215                effect->setLifetime(3.0f);
216            }
217            this->destroy();
218        }
219    }
220
221    /**
222    @brief
223        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
224    @param value
225        The vector determining the amount of the angular movement.
226    */
227    void Rocket::rotateYaw(const Vector2& value)
228    {
229        ControllableEntity::rotateYaw(value);
230       
231        if( !this->isInMouseLook() )
232            this->localAngularVelocity_.y += value.x;
233    }
234
235    /**
236    @brief
237        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
238    @param value
239        The vector determining the amount of the angular movement.
240    */
241    void Rocket::rotatePitch(const Vector2& value)
242    {
243        ControllableEntity::rotatePitch(value);
244       
245        if( !this->isInMouseLook() )
246            this->localAngularVelocity_.x += value.x;
247    }
248
249    /**
250    @brief
251        Rotates the Rocket around the z-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::rotateRoll(const Vector2& value)
256    {
257        ControllableEntity::rotateRoll(value);
258       
259        if( !this->isInMouseLook() )
260            this->localAngularVelocity_.z += value.x;
261    }
262   
263}
Note: See TracBrowser for help on using the repository browser.