Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc @ 6313

Last change on this file since 6313 was 6313, checked in by scheusso, 14 years ago

further network fixes
changed screenshot format from jpeg to tiff (lossless)

  • Property svn:eol-style set to native
File size: 9.5 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
41#include "sound/WorldSound.h"
42
43namespace orxonox
44{
45    CreateFactory(Rocket);
46    // create the factory for the Rocket
47
48    /**
49    @brief
50        Constructor. Registers the object and initializes some default values.
51    */
52    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
53    {
54        RegisterObject(Rocket);// - register the Rocket class to the core
55
56        this->localAngularVelocity_ = 0;
57       
58        if (GameMode::isMaster())
59        {
60            this->setCollisionType(WorldEntity::Kinematic);
61            this->setVelocity(0,0,-100);
62            this->lifetime_ = 100;
63            this->bDestroy_ = false;
64       
65            Model* model = new Model(this);
66            model->setMeshSource("rocket.mesh");
67                        model->scale(0.7);
68            this->attach(model);
69            ParticleEmitter* fire = new ParticleEmitter(this);
70            this->attach(fire);
71            fire->setOrientation(this->getOrientation());
72            fire->setSource("Orxonox/rocketfire");
73       
74            this->enableCollisionCallback();
75            this->setCollisionResponse(false);
76            this->setCollisionType(Kinematic);
77
78            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
79            collisionShape->setRadius(3);
80            collisionShape->setHeight(500);
81            this->attachCollisionShape(collisionShape);
82
83            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
84        }
85       
86        CameraPosition* camPosition = new CameraPosition(this);
87        camPosition->setPosition(0,4,15);
88        camPosition->setAllowMouseLook(true);
89        this->addCameraPosition(camPosition);
90
91        if( GameMode::isMaster() )
92        {
93            this->defSndWpnEngine_ = new WorldSound(this);
94            this->defSndWpnEngine_->setLooping(true);
95            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
96            this->attach(defSndWpnEngine_);
97
98            this->defSndWpnLaunch_ = new WorldSound(this);
99            this->defSndWpnLaunch_->setLooping(false);
100            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
101            this->attach(defSndWpnLaunch_);
102        }
103        else
104        {
105            this->defSndWpnEngine_ = 0;
106            this->defSndWpnLaunch_ = 0;
107        }
108    }
109
110    /**
111    @brief
112        Destructor. Destroys controller, if present and kills sounds, if playing.
113    */
114    Rocket::~Rocket()
115    {
116        if(this->isInitialized())
117        {
118            if (GameMode::isMaster() && this->player_)
119            {
120                this->player_->stopTemporaryControl();
121            }
122            if(this->defSndWpnEngine_->isPlaying())
123            {
124                this->defSndWpnEngine_->stop();
125            }
126            if(this->defSndWpnLaunch_->isPlaying())
127            {
128                this->defSndWpnLaunch_->stop();
129            }
130            delete this->defSndWpnEngine_;
131            delete this->defSndWpnLaunch_;
132        }
133    }
134
135    /**
136    @brief
137        Method for creating a Rocket through XML.
138    */
139    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
140    {
141        // this calls the XMLPort function of the parent class
142        SUPER(Rocket, XMLPort, xmlelement, mode);
143    }
144   
145    void Rocket::setOwner(Pawn* owner)
146    {
147        this->owner_ = owner;
148        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
149        this->player_ = this->owner_->getPlayer();
150        this->owner_->getPlayer()->startTemporaryControl(this);
151
152        this->defSndWpnEngine_->play();
153        this->defSndWpnLaunch_->play();
154    }
155
156    /**
157    @brief
158        Defines which actions the Rocket has to take in each tick.
159    @param dt
160        The length of the tick.
161    */
162    void Rocket::tick(float dt)
163    {
164        SUPER(Rocket, tick, dt);
165       
166        if( this->hasLocalController() )
167        {
168            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
169            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
170            this->localAngularVelocity_ = 0;
171           
172            if( this->bDestroy_ )
173                this->destroy();
174        }
175    }
176   
177    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
178    {
179        if (!this->bDestroy_ && GameMode::isMaster())
180        {
181            if (otherObject == this->owner_)
182                return false;
183           
184            this->bDestroy_ = true;
185
186            if (this->owner_)
187            {
188                {
189                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
190                    effect->setPosition(this->getPosition());
191                    effect->setOrientation(this->getOrientation());
192                    effect->setDestroyAfterLife(true);
193                    effect->setSource("Orxonox/explosion4");
194                    effect->setLifetime(2.0f);
195                }
196
197                {
198                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
199                    effect->setPosition(this->getPosition());
200                    effect->setOrientation(this->getOrientation());
201                    effect->setDestroyAfterLife(true);
202                    effect->setSource("Orxonox/smoke4");
203                    effect->setLifetime(3.0f);
204                }
205            }
206
207            float dmg = this->damage_;
208            if (this->owner_)
209                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
210
211            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
212            if (victim)
213                victim->hit(this->owner_, contactPoint, dmg);
214//             this->destroy();
215        }
216        return false;
217    }
218   
219    void Rocket::destroyObject()
220    {
221        if (GameMode::isMaster())
222        {
223            if(this->defSndWpnEngine_->isPlaying())
224            {
225                this->defSndWpnEngine_->stop();
226            }
227            this->destroy();
228        }
229    }
230   
231    void Rocket::fired(unsigned int firemode)
232    {
233        if (this->owner_)
234        {
235            {
236                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
237                effect->setPosition(this->getPosition());
238                effect->setOrientation(this->getOrientation());
239                effect->setDestroyAfterLife(true);
240                effect->setSource("Orxonox/explosion4");
241                effect->setLifetime(2.0f);
242            }
243
244            {
245                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
246                effect->setPosition(this->getPosition());
247                effect->setOrientation(this->getOrientation());
248                effect->setDestroyAfterLife(true);
249                effect->setSource("Orxonox/smoke4");
250                effect->setLifetime(3.0f);
251            }
252            this->destroy();
253        }
254    }
255
256    /**
257    @brief
258        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
259    @param value
260        The vector determining the amount of the angular movement.
261    */
262    void Rocket::rotateYaw(const Vector2& value)
263    {
264        ControllableEntity::rotateYaw(value);
265       
266        if( !this->isInMouseLook() )
267            this->localAngularVelocity_.y += value.x;
268    }
269
270    /**
271    @brief
272        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
273    @param value
274        The vector determining the amount of the angular movement.
275    */
276    void Rocket::rotatePitch(const Vector2& value)
277    {
278        ControllableEntity::rotatePitch(value);
279       
280        if( !this->isInMouseLook() )
281            this->localAngularVelocity_.x += value.x;
282    }
283
284    /**
285    @brief
286        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
287    @param value
288        The vector determining the amount of the angular movement.
289    */
290    void Rocket::rotateRoll(const Vector2& value)
291    {
292        ControllableEntity::rotateRoll(value);
293       
294        if( !this->isInMouseLook() )
295            this->localAngularVelocity_.z += value.x;
296    }
297   
298}
Note: See TracBrowser for help on using the repository browser.