Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6086 was 6086, checked in by cdaniel, 14 years ago
File size: 7.0 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->setCollisionType(WorldEntity::Kinematic);
55        this->setVelocity(0,0,-100);
56        this->model_ = new Model(this);
57        this->model_->setMeshSource("rocket_test.mesh");
58        this->attach(this->model_);
59        this->lifetime_ = 100;
60        this->bDestroy_ = false;
61       
62        if (GameMode::isMaster())
63        {
64            this->enableCollisionCallback();
65            this->setCollisionResponse(false);
66            this->setCollisionType(Kinematic);
67
68            this->collisionShape_ = new ConeCollisionShape(this);
69            this->collisionShape_->setRadius(3);
70            this->collisionShape_->setHeight(500);
71            this->attachCollisionShape(this->collisionShape_);
72
73            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
74        }
75       
76        this->camPosition_ = new CameraPosition(this);
77        this->camPosition_->setPosition(0,10,40);
78        this->attach( this->camPosition_ );
79        this->addCameraPosition( this->camPosition_ );
80    }
81
82    /**
83    @brief
84        Destructor. Destroys controller, if present.
85    */
86    Rocket::~Rocket()
87    {
88        if(this->isInitialized())
89        {
90            this->collisionShape_->destroy();
91            this->model_->destroy();
92           
93            if (GameMode::isMaster() && this->player_)
94                this->player_->stopTemporaryControl();
95            this->camPosition_->destroy();
96        }
97    }
98
99    /**
100    @brief
101        Method for creating a Rocket through XML.
102    */
103    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
104    {
105        // this calls the XMLPort function of the parent class
106        SUPER(Rocket, XMLPort, xmlelement, mode);
107    }
108   
109    void Rocket::setOwner(Pawn* owner)
110    {
111        this->owner_ = owner;
112       
113        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
114        this->player_ = this->owner_->getPlayer();
115        this->owner_->getPlayer()->startTemporaryControl(this);
116    }
117
118    /**
119    @brief
120        Defines which actions the Rocket has to take in each tick.
121    @param dt
122        The length of the tick.
123    */
124    void Rocket::tick(float dt)
125    {
126        SUPER(Rocket, tick, dt);
127       
128        this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
129        this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
130        this->localAngularVelocity_ = 0;
131       
132        if( this->bDestroy_ )
133            this->destroy();
134    }
135   
136    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
137    {
138        if (!this->bDestroy_ && GameMode::isMaster())
139        {
140            if (otherObject == this->owner_)
141                return false;
142           
143            this->bDestroy_ = true;
144
145            if (this->owner_)
146            {
147                {
148                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
149                    effect->setPosition(this->getPosition());
150                    effect->setOrientation(this->getOrientation());
151                    effect->setDestroyAfterLife(true);
152                    effect->setSource("Orxonox/explosion3");
153                    effect->setLifetime(2.0f);
154                }
155                {
156                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
157                    effect->setPosition(this->getPosition());
158                    effect->setOrientation(this->getOrientation());
159                    effect->setDestroyAfterLife(true);
160                    effect->setSource("Orxonox/smoke4");
161                    effect->setLifetime(3.0f);
162                }
163            }
164
165            float dmg = this->damage_;
166            if (this->owner_)
167                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
168
169            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
170            if (victim)
171                victim->damage(dmg, this->owner_);
172//             this->destroy();
173        }
174        return false;
175    }
176   
177    void Rocket::destroyObject()
178    {
179        if (GameMode::isMaster())
180            this->destroy();
181    }
182
183    /**
184    @brief
185        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
186    @param value
187        The vector determining the amount of the angular movement.
188    */
189    void Rocket::rotateYaw(const Vector2& value)
190    {
191        this->localAngularVelocity_.y += value.x;
192    }
193
194    /**
195    @brief
196        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
197    @param value
198        The vector determining the amount of the angular movement.
199    */
200    void Rocket::rotatePitch(const Vector2& value)
201    {
202        this->localAngularVelocity_.x += value.x;
203    }
204
205    /**
206    @brief
207        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
208    @param value
209        The vector determining the amount of the angular movement.
210    */
211    void Rocket::rotateRoll(const Vector2& value)
212    {
213        this->localAngularVelocity_.z += value.x;
214    }
215   
216}
Note: See TracBrowser for help on using the repository browser.