Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particles2/src/modules/weapons/projectiles/Rocket.cc @ 6087

Last change on this file since 6087 was 6087, checked in by scheusso, 14 years ago

changes in PlayerInfo and Rocket (and scene)
not yet working in network though

File size: 8.1 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        if (GameMode::isMaster())
55        {
56            this->setCollisionType(WorldEntity::Kinematic);
57            this->setVelocity(0,0,-100);
58            this->lifetime_ = 100;
59            this->bDestroy_ = false;
60       
61            this->model_ = new Model(this);
62            this->model_->setMeshSource("rocket_test.mesh");
63            this->attach(this->model_);
64       
65            this->enableCollisionCallback();
66            this->setCollisionResponse(false);
67            this->setCollisionType(Kinematic);
68
69            this->collisionShape_ = new ConeCollisionShape(this);
70            this->collisionShape_->setRadius(3);
71            this->collisionShape_->setHeight(500);
72            this->attachCollisionShape(this->collisionShape_);
73
74            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
75        }
76       
77        this->camPosition_ = new CameraPosition(this);
78        this->camPosition_->setPosition(0,10,40);
79        this->camPosition_->setSyncMode(0x0);
80        this->attach( this->camPosition_ );
81        this->addCameraPosition( this->camPosition_ );
82    }
83
84    /**
85    @brief
86        Destructor. Destroys controller, if present.
87    */
88    Rocket::~Rocket()
89    {
90        if(this->isInitialized())
91        {
92           
93            if (GameMode::isMaster() && this->player_.get())
94            {
95                this->model_->destroy();
96                this->collisionShape_->destroy();
97                this->player_->stopTemporaryControl();
98            }
99            this->camPosition_->destroy();
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( GameMode::isMaster() )
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/explosion3");
159                    effect->setLifetime(2.0f);
160                }
161                {
162                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
163                    effect->setPosition(this->getPosition());
164                    effect->setOrientation(this->getOrientation());
165                    effect->setDestroyAfterLife(true);
166                    effect->setSource("Orxonox/smoke4");
167                    effect->setLifetime(3.0f);
168                }
169            }
170
171            float dmg = this->damage_;
172            if (this->owner_)
173                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
174
175            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
176            if (victim)
177                victim->damage(dmg, this->owner_);
178//             this->destroy();
179        }
180        return false;
181    }
182   
183    void Rocket::destroyObject()
184    {
185        if (GameMode::isMaster())
186            this->destroy();
187    }
188   
189    void Rocket::fire(unsigned int firemode)
190    {
191        if (this->owner_)
192        {
193            {
194                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
195                effect->setPosition(this->getPosition());
196                effect->setOrientation(this->getOrientation());
197                effect->setDestroyAfterLife(true);
198                effect->setSource("Orxonox/explosion3");
199                effect->setLifetime(2.0f);
200            }
201            {
202                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
203                effect->setPosition(this->getPosition());
204                effect->setOrientation(this->getOrientation());
205                effect->setDestroyAfterLife(true);
206                effect->setSource("Orxonox/smoke4");
207                effect->setLifetime(3.0f);
208            }
209            this->destroy();
210        }
211    }
212
213    /**
214    @brief
215        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
216    @param value
217        The vector determining the amount of the angular movement.
218    */
219    void Rocket::rotateYaw(const Vector2& value)
220    {
221        this->localAngularVelocity_.y += value.x;
222    }
223
224    /**
225    @brief
226        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
227    @param value
228        The vector determining the amount of the angular movement.
229    */
230    void Rocket::rotatePitch(const Vector2& value)
231    {
232        this->localAngularVelocity_.x += value.x;
233    }
234
235    /**
236    @brief
237        Rotates the Rocket around the z-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::rotateRoll(const Vector2& value)
242    {
243        this->localAngularVelocity_.z += value.x;
244    }
245   
246}
Note: See TracBrowser for help on using the repository browser.