Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/rocket/src/orxonox/worldentities/SimpleRocket.cc @ 6781

Last change on this file since 6781 was 6781, checked in by gnadler, 14 years ago
File size: 8.5 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 "controllers/RocketController.h"
42#include "sound/WorldSound.h"
43
44namespace orxonox
45{
46    CreateFactory(SimpleRocket);
47    // create the factory for the SimpleRocket
48
49    /**
50    @brief
51        Constructor. Registers the object and initializes some default values.
52    */
53    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator)
54    {
55        RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
56
57        this->localAngularVelocity_ = 0;
58        this->bDestroy_ = false;
59        this->lifetime_ = 100;
60                //this->camera_ = null;
61                RocketController* myController = new RocketController();
62                this->setController(myController));
63                myController->setControllableEntity(this);
64                //this->getController()->setControllableEntity(this);
65        //this->controllableEntity_->setController(this->controller_);
66
67        if (GameMode::isMaster())
68        {
69            this->setCollisionType(WorldEntity::Kinematic);
70            this->setVelocity(0,0,-100);
71
72            Model* model = new Model(this);
73            model->setMeshSource("Rocket.mesh");
74            model->scale(0.7f);
75            this->attach(model);
76            ParticleEmitter* fire = new ParticleEmitter(this);
77            this->attach(fire);
78            fire->setOrientation(this->getOrientation());
79            fire->setSource("Orxonox/Rocketfire");
80
81            this->enableCollisionCallback();
82            this->setCollisionResponse(false);
83            this->setCollisionType(Kinematic);
84
85            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
86            collisionShape->setRadius(3);
87            collisionShape->setHeight(500);
88            this->attachCollisionShape(collisionShape);
89
90            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
91        }
92                this->
93
94    }
95
96    /**
97    @brief
98        Destructor. Destroys controller, if present and kills sounds, if playing.
99    */
100    SimpleRocket::~SimpleRocket()
101    {
102    }
103
104    /**
105    @brief
106        Method for creating a SimpleRocket through XML.
107    */
108    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
109    {
110        // this calls the XMLPort function of the parent class
111        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
112    }
113
114    void SimpleRocket::setOwner(Pawn* owner)
115    {
116        this->owner_ = owner;
117        //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
118        this->player_ = this->owner_->getPlayer();
119    }
120
121    /**
122    @brief
123        Defines which actions the SimpleRocket has to take in each tick.
124    @param dt
125        The length of the tick.
126    */
127    void SimpleRocket::tick(float dt)
128    {
129        SUPER(SimpleRocket, tick, dt);
130
131        if( this->hasLocalController() )
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 SimpleRocket::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/explosion4");
159                    effect->setLifetime(2.0f);
160                }
161
162                {
163                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
164                    effect->setPosition(this->getPosition());
165                    effect->setOrientation(this->getOrientation());
166                    effect->setDestroyAfterLife(true);
167                    effect->setSource("Orxonox/smoke4");
168                    effect->setLifetime(3.0f);
169                }
170            }
171
172            float dmg = this->damage_;
173            if (this->owner_)
174                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
175
176            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
177            if (victim)
178                victim->hit(this->owner_, contactPoint, dmg);
179//             this->destroy();
180        }
181        return false;
182    }
183
184    void SimpleRocket::destroyObject()
185    {
186        if (GameMode::isMaster())
187        {
188            this->destroy();
189        }
190    }
191
192    void SimpleRocket::fired(unsigned int firemode)
193    {
194        if (this->owner_)
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/explosion4");
202                effect->setLifetime(2.0f);
203            }
204
205            {
206                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
207                effect->setPosition(this->getPosition());
208                effect->setOrientation(this->getOrientation());
209                effect->setDestroyAfterLife(true);
210                effect->setSource("Orxonox/smoke4");
211                effect->setLifetime(3.0f);
212            }
213            this->destroy();
214        }
215    }
216
217    /**
218    @brief
219        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
220    @param value
221        The vector determining the amount of the angular movement.
222    */
223    void SimpleRocket::rotateYaw(const Vector2& value)
224    {
225        ControllableEntity::rotateYaw(value);
226
227        if( !this->isInMouseLook() )
228            this->localAngularVelocity_.y += value.x;
229    }
230
231    /**
232    @brief
233        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
234    @param value
235        The vector determining the amount of the angular movement.
236    */
237    void SimpleRocket::rotatePitch(const Vector2& value)
238    {
239        ControllableEntity::rotatePitch(value);
240
241        if( !this->isInMouseLook() )
242            this->localAngularVelocity_.x += value.x;
243    }
244
245    /**
246    @brief
247        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
248    @param value
249        The vector determining the amount of the angular movement.
250    */
251    void SimpleRocket::rotateRoll(const Vector2& value)
252    {
253        ControllableEntity::rotateRoll(value);
254
255        if( !this->isInMouseLook() )
256            this->localAngularVelocity_.z += value.x;
257    }
258
259}
Note: See TracBrowser for help on using the repository browser.