Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

made a mistake in previous update, but still not working…

File size: 8.8 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                //this->camera_ = null;
63                //RocketController* myRController = new RocketController(this);
64                //this->setController(creator);
65                //myRController->setRocket(this, myRController);
66               
67                //this->getController()->setControllableEntity(this);
68                //myController->setControllableEntity(this);
69                //this->getController()->setControllableEntity(this);
70        //this->controllableEntity_->setController(this->controller_);
71
72        //if (GameMode::isMaster())
73        //{
74         /*   this->setCollisionType(WorldEntity::Kinematic);
75            this->setVelocity(0,0,-100);*/
76
77            Model* model = new Model(this);
78            model->setMeshSource("Rocket.mesh");
79            //model->scale(0.7f);
80            this->attach(model);
81           /* ParticleEmitter* fire = new ParticleEmitter(this);
82            this->attach(fire);
83            fire->setOrientation(this->getOrientation());
84            fire->setSource("Orxonox/Rocketfire");
85
86            this->enableCollisionCallback();
87            this->setCollisionResponse(false);
88            this->setCollisionType(Kinematic);
89
90            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
91            collisionShape->setRadius(3);
92            collisionShape->setHeight(500);
93            this->attachCollisionShape(collisionShape);*/
94
95            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
96       // }
97
98    }
99
100    /**s
101    @brief
102        Destructor. Destroys controller, if present and kills sounds, if playing.
103    */
104    SimpleRocket::~SimpleRocket()
105    {
106                COUT(0)<< "simplerocket destroyed\n";
107                if (this->hasLocalController()) delete this->getController();
108        }
109
110    /**
111    @brief
112        Method for creating a SimpleRocket through XML.
113    */
114    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
115    {
116        // this calls the XMLPort function of the parent class
117        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
118    }
119
120    void SimpleRocket::setOwner(Pawn* owner)
121    {
122        this->owner_ = owner;
123        //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
124        this->player_ = this->owner_->getPlayer();
125    }
126
127    /**
128    @brief
129        Defines which actions the SimpleRocket has to take in each tick.
130    @param dt
131        The length of the tick.
132    */
133    void SimpleRocket::tick(float dt)
134    {
135        SUPER(SimpleRocket, 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 SimpleRocket::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->hit(this->owner_, contactPoint, dmg);
185//             this->destroy();
186        }
187        return false;
188    }
189
190    void SimpleRocket::destroyObject()
191    {
192        if (GameMode::isMaster())
193        {
194            this->destroy();
195        }
196    }
197
198    void SimpleRocket::fired(unsigned int firemode)
199    {
200        if (this->owner_)
201        {
202            {
203                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
204                effect->setPosition(this->getPosition());
205                effect->setOrientation(this->getOrientation());
206                effect->setDestroyAfterLife(true);
207                effect->setSource("Orxonox/explosion4");
208                effect->setLifetime(2.0f);
209            }
210
211            {
212                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
213                effect->setPosition(this->getPosition());
214                effect->setOrientation(this->getOrientation());
215                effect->setDestroyAfterLife(true);
216                effect->setSource("Orxonox/smoke4");
217                effect->setLifetime(3.0f);
218            }
219            this->destroy();
220        }
221    }
222
223    /**
224    @brief
225        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
226    @param value
227        The vector determining the amount of the angular movement.
228    */
229    void SimpleRocket::rotateYaw(const Vector2& value)
230    {
231        ControllableEntity::rotateYaw(value);
232
233        if( !this->isInMouseLook() )
234            this->localAngularVelocity_.y += value.x;
235    }
236
237    /**
238    @brief
239        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
240    @param value
241        The vector determining the amount of the angular movement.
242    */
243    void SimpleRocket::rotatePitch(const Vector2& value)
244    {
245        ControllableEntity::rotatePitch(value);
246
247        if( !this->isInMouseLook() )
248            this->localAngularVelocity_.x += value.x;
249    }
250
251    /**
252    @brief
253        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
254    @param value
255        The vector determining the amount of the angular movement.
256    */
257    void SimpleRocket::rotateRoll(const Vector2& value)
258    {
259        ControllableEntity::rotateRoll(value);
260
261        if( !this->isInMouseLook() )
262            this->localAngularVelocity_.z += value.x;
263    }
264
265}
Note: See TracBrowser for help on using the repository browser.