Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/SimpleRocket.cc @ 7338

Last change on this file since 7338 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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