Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6245 was 6228, checked in by cdaniel, 16 years ago

Camera position is now closer to the Rocket (which is now a bit smaller (scale 0.8).

  • Property svn:eol-style set to native
File size: 8.2 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            Model* model = new Model(this);
64            model->setMeshSource("rocket.mesh");
65                        model->scale(0.7);
66            this->attach(model);
67            ParticleEmitter* fire = new ParticleEmitter(this);
68            this->attach(fire);
69            fire->setOrientation(this->getOrientation());
70            fire->setSource("Orxonox/rocketfire");
71       
72            this->enableCollisionCallback();
73            this->setCollisionResponse(false);
74            this->setCollisionType(Kinematic);
75
76            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
77            collisionShape->setRadius(3);
78            collisionShape->setHeight(500);
79            this->attachCollisionShape(collisionShape);
80
81            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
82        }
83       
84        CameraPosition* camPosition = new CameraPosition(this);
85        camPosition->setPosition(0,4,15);
86        camPosition->setAllowMouseLook(true);
87        this->addCameraPosition(camPosition);
88    }
89
90    /**
91    @brief
92        Destructor. Destroys controller, if present.
93    */
94    Rocket::~Rocket()
95    {
96        if(this->isInitialized())
97        {
98            if (GameMode::isMaster() && this->player_)
99                this->player_->stopTemporaryControl();
100        }
101    }
102
103    /**
104    @brief
105        Method for creating a Rocket through XML.
106    */
107    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
108    {
109        // this calls the XMLPort function of the parent class
110        SUPER(Rocket, XMLPort, xmlelement, mode);
111    }
112   
113    void Rocket::setOwner(Pawn* owner)
114    {
115        this->owner_ = owner;
116        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
117        this->player_ = this->owner_->getPlayer();
118        this->owner_->getPlayer()->startTemporaryControl(this);
119    }
120
121    /**
122    @brief
123        Defines which actions the Rocket has to take in each tick.
124    @param dt
125        The length of the tick.
126    */
127    void Rocket::tick(float dt)
128    {
129        SUPER(Rocket, tick, dt);
130       
131        if( this->hasLocalController() )
132        {
133            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
134            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
135            this->localAngularVelocity_ = 0;
136           
137            if( this->bDestroy_ )
138                this->destroy();
139        }
140    }
141   
142    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
143    {
144        if (!this->bDestroy_ && GameMode::isMaster())
145        {
146            if (otherObject == this->owner_)
147                return false;
148           
149            this->bDestroy_ = true;
150
151            if (this->owner_)
152            {
153                {
154                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
155                    effect->setPosition(this->getPosition());
156                    effect->setOrientation(this->getOrientation());
157                    effect->setDestroyAfterLife(true);
158                    effect->setSource("Orxonox/explosion4");
159                    effect->setLifetime(2.0f);
160                }
161
162                {
163                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
164                    effect->setPosition(this->getPosition());
165                    effect->setOrientation(this->getOrientation());
166                    effect->setDestroyAfterLife(true);
167                    effect->setSource("Orxonox/smoke4");
168                    effect->setLifetime(3.0f);
169                }
170            }
171
172            float dmg = this->damage_;
173            if (this->owner_)
174                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
175
176            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
177            if (victim)
178                victim->damage(dmg, this->owner_);
179//             this->destroy();
180        }
181        return false;
182    }
183   
184    void Rocket::destroyObject()
185    {
186        if (GameMode::isMaster())
187            this->destroy();
188    }
189   
190    void Rocket::fired(unsigned int firemode)
191    {
192        if (this->owner_)
193        {
194            {
195                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
196                effect->setPosition(this->getPosition());
197                effect->setOrientation(this->getOrientation());
198                effect->setDestroyAfterLife(true);
199                effect->setSource("Orxonox/explosion4");
200                effect->setLifetime(2.0f);
201            }
202
203            {
204                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
205                effect->setPosition(this->getPosition());
206                effect->setOrientation(this->getOrientation());
207                effect->setDestroyAfterLife(true);
208                effect->setSource("Orxonox/smoke4");
209                effect->setLifetime(3.0f);
210            }
211            this->destroy();
212        }
213    }
214
215    /**
216    @brief
217        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
218    @param value
219        The vector determining the amount of the angular movement.
220    */
221    void Rocket::rotateYaw(const Vector2& value)
222    {
223        ControllableEntity::rotateYaw(value);
224       
225        if( !this->isInMouseLook() )
226            this->localAngularVelocity_.y += value.x;
227    }
228
229    /**
230    @brief
231        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
232    @param value
233        The vector determining the amount of the angular movement.
234    */
235    void Rocket::rotatePitch(const Vector2& value)
236    {
237        ControllableEntity::rotatePitch(value);
238       
239        if( !this->isInMouseLook() )
240            this->localAngularVelocity_.x += value.x;
241    }
242
243    /**
244    @brief
245        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
246    @param value
247        The vector determining the amount of the angular movement.
248    */
249    void Rocket::rotateRoll(const Vector2& value)
250    {
251        ControllableEntity::rotateRoll(value);
252       
253        if( !this->isInMouseLook() )
254            this->localAngularVelocity_.z += value.x;
255    }
256   
257}
Note: See TracBrowser for help on using the repository browser.