Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6287 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
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 "Rocket.h"
30
31#include "core/XMLPort.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33#include "worldentities/pawns/Pawn.h"
34#include "graphics/ParticleSpawner.h"
35#include "graphics/Model.h"
36#include "objects/collisionshapes/ConeCollisionShape.h"
37#include "infos/PlayerInfo.h"
38#include "controllers/Controller.h"
39#include "worldentities/CameraPosition.h"
40
41namespace orxonox
42{
43        CreateFactory(Rocket);   
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
53
54                this->localAngularVelocity_ = 0;
55       
56        if (GameMode::isMaster())
57        {
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);
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");
70       
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)));
81               
82                       
83        }
84       
85        this->camPosition_ = new CameraPosition(this);
86        this->camPosition_->setPosition(0,10,40);
87        this->camPosition_->setSyncMode(0x0);
88        this->attach( this->camPosition_ );
89        this->addCameraPosition( this->camPosition_ );
90    }
91
92    /**
93    @brief
94        Destructor. Destroys controller, if present.
95    */
96    Rocket::~Rocket()
97    {
98        if(this->isInitialized())
99        {
100           
101            if (GameMode::isMaster() && this->player_.get())
102            {
103                this->model_->destroy();
104                this->collisionShape_->destroy();
105                this->player_->stopTemporaryControl();
106            }
107            this->camPosition_->destroy();
108        }
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    }
120   
121    void Rocket::setOwner(Pawn* owner)
122    {
123        this->owner_ = owner;
124        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
125        this->player_ = this->owner_->getPlayer();
126        this->owner_->getPlayer()->startTemporaryControl(this);
127    }
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       
139        if( this->hasLocalController() )
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        }
148    }
149   
150    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
151    {
152        if (!this->bDestroy_ && GameMode::isMaster())
153        {
154            if (otherObject == this->owner_)
155                return false;
156           
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);
166                    effect->setSource("Orxonox/explosion4");
167                    effect->setLifetime(2.0f);
168                }
169
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_);
187//             this->destroy();
188        }
189        return false;
190    }
191   
192    void Rocket::destroyObject()
193    {
194        if (GameMode::isMaster())
195            this->destroy();
196    }
197   
198    void Rocket::fired(unsigned int firemode)
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);
207                effect->setSource("Orxonox/explosion4");
208                effect->setLifetime(2.0f);
209            }
210
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    }
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    {
231        this->localAngularVelocity_.y += value.x;
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    {
242        this->localAngularVelocity_.x += value.x;
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    {
253        this->localAngularVelocity_.z += value.x;
254    }
255   
256}
Note: See TracBrowser for help on using the repository browser.