Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

updated ~SimpleRocket but still doesn't work

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