Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/weapons/projectiles/SimpleRocket.cc @ 7021

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

documentation & formatting commit

File size: 8.2 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    @file
49    @brief
50        SimpleRocket, follows direction from a Rocketcontroller, has fuel for 80% of its lifetime, afterwords it's fire disappears.
51    @author
52       Gabriel Nadler (Original file: Oli Scheuss)
53    */
54    CreateFactory(SimpleRocket);
55
56
57    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator)
58    {
59        RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
60
61        this->localAngularVelocity_ = 0;
62        this->bDestroy_ = false;
63        this->lifetime_ = 120;
64
65        this->setMass(15);
66        COUT(4) << "simplerocket constructed\n";
67
68        if (GameMode::isMaster())
69        {
70            this->setCollisionType(WorldEntity::Kinematic);
71            this->fuel_=true;
72
73            Model* model = new Model(this);
74            model->setMeshSource("rocket.mesh");
75            model->scale(0.7f);
76            this->attach(model);
77
78            this->fire_ = new ParticleEmitter(this);
79            this->attach(this->fire_);
80           
81            this->fire_->setOrientation(this->getOrientation());
82            this->fire_->setSource("Orxonox/simplerocketfire");
83            this->enableCollisionCallback();
84            this->setCollisionResponse(false);
85            this->setCollisionType(Kinematic);
86
87            // TODO: fix the orientation and size of this collision shape to match the rocket
88            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
89            collisionShape->setOrientation(this->getOrientation());
90            collisionShape->setRadius(1.5f);
91            collisionShape->setHeight(5);
92            this->attachCollisionShape(collisionShape);
93            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
94        }
95
96    }
97
98
99   
100    /**
101    * @brief updates state of rocket, disables fire if no fuel
102    * @param dt tick-length
103    */
104    void SimpleRocket::tick(float dt)
105    {
106
107        SUPER(SimpleRocket, tick, dt);
108        if ( GameMode::isMaster() )
109        {
110
111
112            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
113            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
114            this->localAngularVelocity_ = 0;
115
116       
117            if (this->fuel_)
118            {
119                if (this->destroyTimer_.getRemainingTime()<  (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ ) 
120                    this->fuel_=false;
121            } else
122                this->disableFire();
123
124            if( this->bDestroy_ ) 
125                this->destroy();
126        }
127               
128    }
129
130    /**
131    * @brief Sets the Acceleration to 0 and detaches the fire
132    * @return void
133    */
134    void SimpleRocket::disableFire()
135    {
136        this->setAcceleration(0,0,0);       
137        this->fire_->detachFromParent();
138    }
139
140    /**s
141    @brief
142        Destructor. Destroys controller, if present and kills sounds, if playing.
143    */
144    SimpleRocket::~SimpleRocket()
145    {
146        if (this->isInitialized()) 
147        {
148            if( GameMode::isMaster() )
149            {
150                this->getController()->destroy();
151            }
152        }
153    }
154
155    /**
156    @brief
157        Method for creating a SimpleRocket through XML.
158    */
159    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
160    {
161        // this calls the XMLPort function of the parent class
162        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
163    }
164
165    void SimpleRocket::setOwner(Pawn* owner)
166    {
167        this->owner_ = owner;
168        this->player_ = this->owner_->getPlayer();
169    }
170
171
172
173
174    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
175    {
176        if (!this->bDestroy_ && GameMode::isMaster())
177        {
178            if (otherObject == this->owner_)
179                return false;
180
181            this->bDestroy_ = true;
182
183            if (this->owner_)
184            {
185                {
186                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
187                    effect->setPosition(this->getPosition());
188                    effect->setOrientation(this->getOrientation());
189                    effect->setDestroyAfterLife(true);
190                    effect->setSource("Orxonox/explosion4");
191                    effect->setLifetime(2.0f);
192                }
193
194                {
195                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
196                    effect->setPosition(this->getPosition());
197                    effect->setOrientation(this->getOrientation());
198                    effect->setDestroyAfterLife(true);
199                    effect->setSource("Orxonox/smoke4");
200                    effect->setLifetime(3.0f);
201                }
202            }
203
204            float dmg = this->damage_;
205//             if (this->owner_)
206//                 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
207
208            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
209            if (victim)
210                victim->hit(this->owner_, contactPoint, dmg);
211        }
212        return false;
213    }
214
215    void SimpleRocket::destroyObject()
216    {
217        if (GameMode::isMaster())
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.