Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particles2/src/modules/weapons/projectiles/Rocket.cc @ 6372

Last change on this file since 6372 was 6101, checked in by scheusso, 15 years ago

rocket now steerable also on client
AIController shoots again now ;)
fire network function is now in CE instead of Pawn
some changes in PlayerInfo that allow controlling of temporary objects (such as Rocket)

File size: 8.4 KB
RevLine 
[6059]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:
[6066]23 *      Oliver Scheuss
[6059]24 *   Co-authors:
[6066]25 *      ...
[6059]26 *
27 */
28
29#include "Rocket.h"
30
31#include "core/XMLPort.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
[6065]33#include "worldentities/pawns/Pawn.h"
34#include "graphics/ParticleSpawner.h"
35#include "graphics/Model.h"
36#include "objects/collisionshapes/ConeCollisionShape.h"
[6079]37#include "infos/PlayerInfo.h"
38#include "controllers/Controller.h"
39#include "worldentities/CameraPosition.h"
[6059]40
41namespace orxonox
42{
[6086]43        CreateFactory(Rocket);   
[6059]44    // create the factory for the Rocket
45
46    /**
47    @brief
48        Constructor. Registers the object and initializes some default values.
49    */
50    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
51    {
52        RegisterObject(Rocket);// - register the Rocket class to the core
[6098]53
54                this->localAngularVelocity_ = 0;
[6059]55       
[6065]56        if (GameMode::isMaster())
57        {
[6087]58            this->setCollisionType(WorldEntity::Kinematic);
59            this->setVelocity(0,0,-100);
60            this->lifetime_ = 100;
61            this->bDestroy_ = false;
62       
63            this->model_ = new Model(this);
[6098]64            this->model_->setMeshSource("rocket.mesh");
65                        this->attach(this->model_);
66                        ParticleSpawner* fire = new ParticleSpawner(this);
67                        this->attach(fire);
68                        fire->setOrientation(this->getOrientation());
69            fire->setSource("Orxonox/rocketfire");
[6087]70       
[6065]71            this->enableCollisionCallback();
72            this->setCollisionResponse(false);
73            this->setCollisionType(Kinematic);
74
75            this->collisionShape_ = new ConeCollisionShape(this);
76            this->collisionShape_->setRadius(3);
77            this->collisionShape_->setHeight(500);
78            this->attachCollisionShape(this->collisionShape_);
79
80            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
[6098]81               
82                       
[6065]83        }
[6079]84       
85        this->camPosition_ = new CameraPosition(this);
[6082]86        this->camPosition_->setPosition(0,10,40);
[6087]87        this->camPosition_->setSyncMode(0x0);
[6079]88        this->attach( this->camPosition_ );
89        this->addCameraPosition( this->camPosition_ );
[6059]90    }
91
92    /**
93    @brief
94        Destructor. Destroys controller, if present.
95    */
96    Rocket::~Rocket()
97    {
[6065]98        if(this->isInitialized())
99        {
[6079]100           
[6087]101            if (GameMode::isMaster() && this->player_.get())
102            {
103                this->model_->destroy();
104                this->collisionShape_->destroy();
[6082]105                this->player_->stopTemporaryControl();
[6087]106            }
[6079]107            this->camPosition_->destroy();
[6065]108        }
[6059]109    }
110
111    /**
112    @brief
113        Method for creating a Rocket through XML.
114    */
115    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
116    {
117        // this calls the XMLPort function of the parent class
118        SUPER(Rocket, XMLPort, xmlelement, mode);
119    }
[6065]120   
121    void Rocket::setOwner(Pawn* owner)
122    {
123        this->owner_ = owner;
[6079]124        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
[6082]125        this->player_ = this->owner_->getPlayer();
126        this->owner_->getPlayer()->startTemporaryControl(this);
[6065]127    }
[6059]128
129    /**
130    @brief
131        Defines which actions the Rocket has to take in each tick.
132    @param dt
133        The length of the tick.
134    */
135    void Rocket::tick(float dt)
136    {
137        SUPER(Rocket, tick, dt);
138       
[6101]139        if( this->hasLocalController() )
[6087]140        {
141            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
142            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
143            this->localAngularVelocity_ = 0;
144           
145            if( this->bDestroy_ )
146                this->destroy();
147        }
[6059]148    }
149   
[6065]150    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
[6059]151    {
[6065]152        if (!this->bDestroy_ && GameMode::isMaster())
153        {
154            if (otherObject == this->owner_)
155                return false;
[6082]156           
[6065]157            this->bDestroy_ = true;
158
159            if (this->owner_)
160            {
161                {
162                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
163                    effect->setPosition(this->getPosition());
164                    effect->setOrientation(this->getOrientation());
165                    effect->setDestroyAfterLife(true);
[6098]166                    effect->setSource("Orxonox/explosion4");
[6065]167                    effect->setLifetime(2.0f);
168                }
[6098]169
[6065]170                {
171                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
172                    effect->setPosition(this->getPosition());
173                    effect->setOrientation(this->getOrientation());
174                    effect->setDestroyAfterLife(true);
175                    effect->setSource("Orxonox/smoke4");
176                    effect->setLifetime(3.0f);
177                }
178            }
179
180            float dmg = this->damage_;
181            if (this->owner_)
182                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
183
184            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
185            if (victim)
186                victim->damage(dmg, this->owner_);
[6082]187//             this->destroy();
[6065]188        }
189        return false;
[6059]190    }
[6065]191   
192    void Rocket::destroyObject()
[6059]193    {
[6065]194        if (GameMode::isMaster())
195            this->destroy();
[6059]196    }
[6087]197   
[6101]198    void Rocket::fired(unsigned int firemode)
[6087]199    {
200        if (this->owner_)
201        {
202            {
203                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
204                effect->setPosition(this->getPosition());
205                effect->setOrientation(this->getOrientation());
206                effect->setDestroyAfterLife(true);
[6098]207                effect->setSource("Orxonox/explosion4");
[6087]208                effect->setLifetime(2.0f);
209            }
[6098]210
[6087]211            {
212                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
213                effect->setPosition(this->getPosition());
214                effect->setOrientation(this->getOrientation());
215                effect->setDestroyAfterLife(true);
216                effect->setSource("Orxonox/smoke4");
217                effect->setLifetime(3.0f);
218            }
219            this->destroy();
220        }
221    }
[6059]222
223    /**
224    @brief
225        Rotates the Rocket 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 Rocket::rotateYaw(const Vector2& value)
230    {
[6082]231        this->localAngularVelocity_.y += value.x;
[6059]232    }
233
234    /**
235    @brief
236        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
237    @param value
238        The vector determining the amount of the angular movement.
239    */
240    void Rocket::rotatePitch(const Vector2& value)
241    {
[6082]242        this->localAngularVelocity_.x += value.x;
[6059]243    }
244
245    /**
246    @brief
247        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
248    @param value
249        The vector determining the amount of the angular movement.
250    */
251    void Rocket::rotateRoll(const Vector2& value)
252    {
[6082]253        this->localAngularVelocity_.z += value.x;
[6059]254    }
255   
256}
Note: See TracBrowser for help on using the repository browser.