Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/rocket/src/modules/weapons/projectiles/SimpleRocket.cc @ 6902

Last change on this file since 6902 was 6902, checked in by gnadler, 14 years ago

no rocket is controlled by controller. accidentally deleted tick function once :S

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 "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"
41#include "weapons/RocketController.h"
42#include "sound/WorldSound.h"
43#include "util/Debug.h"
44
45namespace orxonox
46{
47    CreateFactory(SimpleRocket);
48    // create the factory for the SimpleRocket
49
50    /**
51    @brief
52        Constructor. Registers the object and initializes some default values.
53    */
54    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator)
55    {
56        RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
57
58        this->localAngularVelocity_ = 0;
59        this->bDestroy_ = false;
60        this->lifetime_ = 100;
61                COUT(0)<< "simplerocket constructed\n";
62
63
64        if (GameMode::isMaster())
65       {
66           this->setCollisionType(WorldEntity::Kinematic);
67            this->setVelocity(0,0,100);
68
69            Model* model = new Model(this);
70            model->setMeshSource("rocket.mesh");
71            model->scale(0.7f);
72            this->attach(model);
73
74            ParticleEmitter* fire = new ParticleEmitter(this);
75            this->attach(fire);
76            fire->setOrientation(this->getOrientation());
77            fire->setSource("Orxonox/rocketfire2");
78
79            this->enableCollisionCallback();
80            this->setCollisionResponse(false);
81            this->setCollisionType(Kinematic);
82
83            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
84            collisionShape->setRadius(3);
85            collisionShape->setHeight(500);
86            this->attachCollisionShape(collisionShape);
87
88            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
89        }
90
91    }
92        void SimpleRocket::tick(float dt)
93    {
94        SUPER(SimpleRocket, tick, dt);
95
96            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
97            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
98
99            if( this->bDestroy_ )
100                this->destroy();
101       
102        }
103
104    /**s
105    @brief
106        Destructor. Destroys controller, if present and kills sounds, if playing.
107    */
108    SimpleRocket::~SimpleRocket()
109    {
110                if (this->isInitialized()) {
111                        this->getController()->destroy();
112                COUT(0)<< "simplerocket destroyed\n";
113                }
114        }
115
116    /**
117    @brief
118        Method for creating a SimpleRocket through XML.
119    */
120    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
121    {
122        // this calls the XMLPort function of the parent class
123        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
124    }
125
126    void SimpleRocket::setOwner(Pawn* owner)
127    {
128        this->owner_ = owner;
129        //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
130        this->player_ = this->owner_->getPlayer();
131    }
132
133
134    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
135    {
136        if (!this->bDestroy_ && GameMode::isMaster())
137        {
138            if (otherObject == this->owner_)
139                return false;
140
141            this->bDestroy_ = true;
142
143            if (this->owner_)
144            {
145                {
146                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
147                    effect->setPosition(this->getPosition());
148                    effect->setOrientation(this->getOrientation());
149                    effect->setDestroyAfterLife(true);
150                    effect->setSource("Orxonox/explosion4");
151                    effect->setLifetime(2.0f);
152                }
153
154                {
155                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
156                    effect->setPosition(this->getPosition());
157                    effect->setOrientation(this->getOrientation());
158                    effect->setDestroyAfterLife(true);
159                    effect->setSource("Orxonox/smoke4");
160                    effect->setLifetime(3.0f);
161                }
162            }
163
164            float dmg = this->damage_;
165            if (this->owner_)
166                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
167
168            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
169            if (victim)
170                victim->hit(this->owner_, contactPoint, dmg);
171        }
172        return false;
173    }
174
175    void SimpleRocket::destroyObject()
176    {
177        if (GameMode::isMaster())
178        {
179            this->destroy();
180        }
181    }
182
183    void SimpleRocket::fired(unsigned int firemode)
184    {
185        if (this->owner_)
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/explosion4");
193                effect->setLifetime(2.0f);
194            }
195
196            {
197                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
198                effect->setPosition(this->getPosition());
199                effect->setOrientation(this->getOrientation());
200                effect->setDestroyAfterLife(true);
201                effect->setSource("Orxonox/smoke4");
202                effect->setLifetime(3.0f);
203            }
204            this->destroy();
205        }
206    }
207
208    /**
209    @brief
210        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
211    @param value
212        The vector determining the amount of the angular movement.
213    */
214    void SimpleRocket::rotateYaw(const Vector2& value)
215    {
216        ControllableEntity::rotateYaw(value);
217
218        if( !this->isInMouseLook() )
219            this->localAngularVelocity_.y += value.x;
220    }
221
222    /**
223    @brief
224        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
225    @param value
226        The vector determining the amount of the angular movement.
227    */
228    void SimpleRocket::rotatePitch(const Vector2& value)
229    {
230        ControllableEntity::rotatePitch(value);
231
232        if( !this->isInMouseLook() )
233            this->localAngularVelocity_.x += value.x;
234    }
235
236    /**
237    @brief
238        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
239    @param value
240        The vector determining the amount of the angular movement.
241    */
242    void SimpleRocket::rotateRoll(const Vector2& value)
243    {
244        ControllableEntity::rotateRoll(value);
245
246        if( !this->isInMouseLook() )
247            this->localAngularVelocity_.z += value.x;
248    }
249
250}
Note: See TracBrowser for help on using the repository browser.