Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai2/src/modules/weapons/projectiles/SimpleRocket.cc @ 8721

Last change on this file since 8721 was 8706, checked in by dafrick, 13 years ago

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

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