Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8907 was 8734, checked in by dafrick, 13 years ago

Fix for AI and rockets.

  • Property svn:eol-style set to native
File size: 6.4 KB
RevLine 
[7129]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:
[8706]25 *      simonmie
[7129]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
[8706]50    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator), BasicProjectile()
[7129]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);
[8706]58//        COUT(4) << "simplerocket constructed\n";
[7129]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            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
103            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
104            this->localAngularVelocity_ = 0;
105
106
107            if (this->fuel_)
108            {
109                if (this->destroyTimer_.getRemainingTime()<  (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ )
110                    this->fuel_=false;
111            } else
112                this->disableFire();
113
[8706]114            if( this->getBDestroy() )
[7129]115                this->destroy();
116        }
117
118    }
119
120    /**
121    * @brief Sets the Acceleration to 0 and detaches the fire
122    * @return void
123    */
124    void SimpleRocket::disableFire()
125    {
126        this->setAcceleration(0,0,0);
127        this->fire_->detachFromParent();
128    }
129
130    /**s
131    @brief
132        Destructor. Destroys controller, if present and kills sounds, if playing.
133    */
134    SimpleRocket::~SimpleRocket()
135    {
136        if (this->isInitialized())
137        {
138            if( GameMode::isMaster() )
139            {
140                this->getController()->destroy();
141            }
142        }
143    }
144
145    /**
146    @brief
147        Method for creating a SimpleRocket through XML.
148    */
149    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
150    {
151        // this calls the XMLPort function of the parent class
152        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
153    }
154
155    void SimpleRocket::setOwner(Pawn* owner)
156    {
157        this->owner_ = owner;
[8706]158        this->player_ = this->getOwner()->getPlayer();
[7129]159    }
160
161
[8706]162    /* Calls the collidesAgainst function of BasicProjectile
163     */
[7129]164    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
165    {
[8706]166        return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);
[7129]167    }
168
169    void SimpleRocket::destroyObject()
170    {
171        if (GameMode::isMaster())
172        {
173            this->destroy();
174        }
175    }
176
177    /**
178    @brief
179        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
180    @param value
181        The vector determining the amount of the angular movement.
182    */
183    void SimpleRocket::rotateYaw(const Vector2& value)
184    {
185        ControllableEntity::rotateYaw(value);
186
187        if( !this->isInMouseLook() )
188            this->localAngularVelocity_.y += value.x;
189    }
190
191    /**
192    @brief
193        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
194    @param value
195        The vector determining the amount of the angular movement.
196    */
197    void SimpleRocket::rotatePitch(const Vector2& value)
198    {
199        ControllableEntity::rotatePitch(value);
200
201        if( !this->isInMouseLook() )
202            this->localAngularVelocity_.x += value.x;
203    }
204
205    /**
206    @brief
207        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
208    @param value
209        The vector determining the amount of the angular movement.
210    */
211    void SimpleRocket::rotateRoll(const Vector2& value)
212    {
213        ControllableEntity::rotateRoll(value);
214
215        if( !this->isInMouseLook() )
216            this->localAngularVelocity_.z += value.x;
217    }
218
219}
Note: See TracBrowser for help on using the repository browser.