Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/rocket2/src/modules/weapons/projectiles/SimpleRocket.cc @ 6966

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

now rocket slows and then finally stops after a given number of ticks (aka fuel).
rocket speeds up if distance is greater than x (right now 1000 but can be changed).
collisionShape not yet fixed.

File size: 9.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 *      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    CreateFactory(SimpleRocket);
48    // create the factory for the SimpleRocket
49
50    /**
51    @brief
52        Constructor. Registers the object and initializes some default values.
53    */
54    SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator)
55    {
56        RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
57
58        this->localAngularVelocity_ = 0;
59        this->bDestroy_ = false;
60        this->lifetime_ = 100;
61        this->setMass(15);
62        COUT(4) << "simplerocket constructed\n";
63        this->counter_=0;
64        this->slowing_=false;
65
66        if (GameMode::isMaster())
67       {
68            this->setCollisionType(WorldEntity::Kinematic);
69            this->fuel_=true;
70
71            Model* model = new Model(this);
72            model->setMeshSource("rocket.mesh");
73            model->scale(0.7f);
74            this->attach(model);
75
76            this->fire_ = new ParticleEmitter(this);
77            this->attach(this->fire_);
78           
79            this->fire_->setOrientation(this->getOrientation());
80            this->fire_->setSource("Orxonox/simplerocketfire");
81            this->enableCollisionCallback();
82            this->setCollisionResponse(false);
83            this->setCollisionType(Kinematic);
84
85            // TODO: fix the orientation and size of this collision shape to match the rocket
86            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
87            collisionShape->setOrientation(this->getOrientation());
88            collisionShape->setRadius(1.5f);
89            collisionShape->setHeight(200);
90            this->attachCollisionShape(collisionShape);
91           
92
93            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
94        }
95
96    }
97   
98    void SimpleRocket::disableFire(){
99        this->setAcceleration(0,0,0);
100        this->setVelocity(Vector3(0,0,0));
101       
102        this->fire_->detachFromParent();
103        //this->fire_->setVisible(false);
104
105    }
106
107
108    void SimpleRocket::tick(float dt)
109    {
110
111        SUPER(SimpleRocket, tick, dt);
112        counter_++;
113        if (this->getVelocity().squaredLength() >130000 && !slowing_) counter_++; //if Velocity bigger than about 360, uses a lot more "fuel" :)
114
115            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
116            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
117            this->localAngularVelocity_ = 0;
118
119           
120            if (this->fuel_) {
121                COUT(0)<<this->getVelocity().length()<<endl;
122                if (this->counter_>1000 && counter_%12==0) 
123                   
124                    if (!this->slowing_) {
125                        this->setAcceleration(this->getOrientation()*Vector3(10,10,10));
126                        this->slowing_=true;
127                    }
128
129                if (this->counter_ > 1800) 
130                    this->fuel_=false;
131            }
132            if( this->bDestroy_ )
133                this->destroy();
134            if (!this->fuel_) 
135                this->disableFire();
136       
137           
138           
139       
140    }
141
142    /**s
143    @brief
144        Destructor. Destroys controller, if present and kills sounds, if playing.
145    */
146    SimpleRocket::~SimpleRocket()
147    {
148        if (this->isInitialized()) 
149        {
150            this->getController()->destroy();
151            COUT(4)<< "simplerocket destroyed\n";
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->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
169        this->player_ = this->owner_->getPlayer();
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    void SimpleRocket::setDestroy()
224    {
225        this->bDestroy_=true;
226        CCOUT(4)<<"trying to destroy";
227    }
228
229    void SimpleRocket::fired(unsigned int firemode)
230    {
231        if (this->owner_)
232        {
233            {
234                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
235                effect->setPosition(this->getPosition());
236                effect->setOrientation(this->getOrientation());
237                effect->setDestroyAfterLife(true);
238                effect->setSource("Orxonox/explosion4");
239                effect->setLifetime(2.0f);
240            }
241
242            {
243                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
244                effect->setPosition(this->getPosition());
245                effect->setOrientation(this->getOrientation());
246                effect->setDestroyAfterLife(true);
247                effect->setSource("Orxonox/smoke4");
248                effect->setLifetime(3.0f);
249            }
250            this->destroy();
251        }
252    }
253
254    /**
255    @brief
256        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
257    @param value
258        The vector determining the amount of the angular movement.
259    */
260    void SimpleRocket::rotateYaw(const Vector2& value)
261    {
262        ControllableEntity::rotateYaw(value);
263
264        if( !this->isInMouseLook() )
265            this->localAngularVelocity_.y += value.x;
266    }
267
268    /**
269    @brief
270        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
271    @param value
272        The vector determining the amount of the angular movement.
273    */
274    void SimpleRocket::rotatePitch(const Vector2& value)
275    {
276        ControllableEntity::rotatePitch(value);
277
278        if( !this->isInMouseLook() )
279            this->localAngularVelocity_.x += value.x;
280    }
281
282    /**
283    @brief
284        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
285    @param value
286        The vector determining the amount of the angular movement.
287    */
288    void SimpleRocket::rotateRoll(const Vector2& value)
289    {
290        ControllableEntity::rotateRoll(value);
291
292        if( !this->isInMouseLook() )
293            this->localAngularVelocity_.z += value.x;
294    }
295
296}
Note: See TracBrowser for help on using the repository browser.