Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fabienHS15/src/modules/weapons/projectiles/SimpleRocket.cc @ 10794

Last change on this file since 10794 was 10794, checked in by fvultier, 8 years ago

bug in the WeaponHUD fixed.

  • Property svn:eol-style set to native
File size: 6.6 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 *      Gabriel Nadler
24 *   Co-authors:
25 *      simonmie
26 *
27 */
28
29/**
30    @file SimpleRocket.h
31    @brief Implementation of the SimpleRocket class.
32*/
33
34
35#include "SimpleRocket.h"
36
37#include <BulletDynamics/Dynamics/btRigidBody.h>
38
39#include "core/CoreIncludes.h"
40#include "core/XMLPort.h"
41
42#include "controllers/Controller.h"
43#include "graphics/Model.h"
44#include "graphics/ParticleSpawner.h"
45#include "infos/PlayerInfo.h"
46#include "objects/collisionshapes/ConeCollisionShape.h"
47#include "worldentities/pawns/Pawn.h"
48#include "sound/WorldSound.h"
49
50#include "weapons/RocketController.h"
51
52namespace orxonox
53{
54    RegisterClass(SimpleRocket);
55
56    const float SimpleRocket::FUEL_PERCENTAGE = 0.8f;
57
58    SimpleRocket::SimpleRocket(Context* context)
59        : ControllableEntity(context)
60        , BasicProjectile()
61        , RadarViewable(this, static_cast<WorldEntity*>(this))
62    {
63        RegisterObject(SimpleRocket);// Register the SimpleRocket class to the core
64
65        this->localAngularVelocity_ = 0;
66        this->lifetime_ = 10.f;
67
68        this->setMass(15.0);
69
70        if (GameMode::isMaster())
71        {
72            this->setCollisionType(WorldEntity::Kinematic);
73            this->fuel_ = true;
74
75            // Create rocket model.
76            Model* model = new Model(this->getContext());
77            model->setMeshSource("rocket.mesh");
78            model->scale(1.0f);
79            this->attach(model);
80
81            // Add effects.
82            this->fire_ = new ParticleEmitter(this->getContext());
83            this->attach(this->fire_);
84
85            this->fire_->setOrientation(this->getOrientation());
86            this->fire_->setSource("Orxonox/simplerocketfire");
87            this->enableCollisionCallback();
88            this->setCollisionResponse(false);
89            this->setCollisionType(Kinematic);
90
91            // Add collision shape.
92            // TODO: fix the orientation and size of this collision shape to match the rocket
93            ConeCollisionShape* collisionShape = new ConeCollisionShape(this->getContext());
94            collisionShape->setOrientation(this->getOrientation());
95            collisionShape->setRadius(1.5f);
96            collisionShape->setHeight(5);
97            this->attachCollisionShape(collisionShape);
98
99            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
100        }
101
102        this->setRadarObjectColour(ColourValue(1.0, 1.0, 0.0)); // yellow
103        this->setRadarObjectShape(RadarViewable::Triangle);
104        this->setRadarObjectScale(0.5f);
105    }
106
107
108
109    /**
110    @brief
111        Updates state of rocket, disables fire if no fuel
112    @param dt
113        tick-length
114    */
115    void SimpleRocket::tick(float dt)
116    {
117        SUPER(SimpleRocket, tick, dt);
118
119        orxout() << "SimpleRocket::tick" << getScale() << endl;
120
121        if (GameMode::isMaster())
122        {
123            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
124            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
125            this->localAngularVelocity_ = 0;
126
127            if (this->fuel_)
128            {
129                if (this->destroyTimer_.getRemainingTime() < this->FUEL_PERCENTAGE*this->lifetime_ )
130                    this->fuel_ = false;
131            } else
132                this->disableFire();
133        }
134
135        this->destroyCheck();
136    }
137
138    /**
139    @brief
140        Sets the Acceleration to 0 and detaches the fire.
141    */
142    void SimpleRocket::disableFire()
143    {
144        this->setAcceleration(0,0,0);
145        this->fire_->detachFromParent();
146    }
147
148    /**
149    @brief
150        Destructor. Destroys controller, if present and kills sounds, if playing.
151    */
152    SimpleRocket::~SimpleRocket()
153    {
154        if (this->isInitialized())
155        {
156            if( GameMode::isMaster() )
157            {
158                if (this->getController())
159                    this->getController()->destroy();
160            }
161        }
162    }
163
164    /**
165    @brief
166        Set the entity that fired the SimpleRocket.
167    @param shooter
168        A pointer to the Pawn that fired the SimpleRocket.
169    */
170    void SimpleRocket::setShooter(Pawn* shooter)
171    {
172        BasicProjectile::setShooter(shooter);
173
174        this->player_ = this->getShooter()->getPlayer();
175    }
176
177    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
178    {
179        return this->processCollision(otherObject, contactPoint, cs);
180    }
181
182    /**
183    @brief
184        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
185    @param value
186        The vector determining the amount of the angular movement.
187    */
188    void SimpleRocket::rotateYaw(const Vector2& value)
189    {
190        ControllableEntity::rotateYaw(value);
191
192        if( !this->isInMouseLook() )
193            this->localAngularVelocity_.y += value.x;
194    }
195
196    /**
197    @brief
198        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
199    @param value
200        The vector determining the amount of the angular movement.
201    */
202    void SimpleRocket::rotatePitch(const Vector2& value)
203    {
204        ControllableEntity::rotatePitch(value);
205
206        if( !this->isInMouseLook() )
207            this->localAngularVelocity_.x += value.x;
208    }
209
210    /**
211    @brief
212        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
213    @param value
214        The vector determining the amount of the angular movement.
215    */
216    void SimpleRocket::rotateRoll(const Vector2& value)
217    {
218        ControllableEntity::rotateRoll(value);
219
220        if( !this->isInMouseLook() )
221            this->localAngularVelocity_.z += value.x;
222    }
223
224}
Note: See TracBrowser for help on using the repository browser.