Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/rocket/src/modules/weapons/projectiles/SimpleRocket.cc @ 6818

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

latest try (see the forum thread for more info…)
now Orxonox starts, but rocket still invisible/not seen

File size: 8.8 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                COUT(0)<< "simplerocket constructed\n";
62                //this->camera_ = null;
63                //RocketController* myRController = new RocketController(this);
64                //this->setController(creator);
65                //myRController->setRocket(this, myRController);
66               
67                //this->getController()->setControllableEntity(this);
68                //myController->setControllableEntity(this);
69                //this->getController()->setControllableEntity(this);
70        //this->controllableEntity_->setController(this->controller_);
71
72        //if (GameMode::isMaster())
73        //{
74         /*   this->setCollisionType(WorldEntity::Kinematic);
75            this->setVelocity(0,0,-100);*/
76
77            Model* model = new Model(this);
78            model->setMeshSource("Rocket.mesh");
79            //model->scale(0.7f);
80            this->attach(model);
81           /* ParticleEmitter* fire = new ParticleEmitter(this);
82            this->attach(fire);
83            fire->setOrientation(this->getOrientation());
84            fire->setSource("Orxonox/Rocketfire");
85
86            this->enableCollisionCallback();
87            this->setCollisionResponse(false);
88            this->setCollisionType(Kinematic);
89
90            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
91            collisionShape->setRadius(3);
92            collisionShape->setHeight(500);
93            this->attachCollisionShape(collisionShape);*/
94
95            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
96       // }
97
98    }
99
100    /**s
101    @brief
102        Destructor. Destroys controller, if present and kills sounds, if playing.
103    */
104    SimpleRocket::~SimpleRocket()
105    {
106                if (this->isInitialized()) {
107                COUT(0)<< "simplerocket destroyed\n";
108                delete this->getController();
109                }
110        }
111
112    /**
113    @brief
114        Method for creating a SimpleRocket through XML.
115    */
116    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
117    {
118        // this calls the XMLPort function of the parent class
119        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
120    }
121
122    void SimpleRocket::setOwner(Pawn* owner)
123    {
124        this->owner_ = owner;
125        //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
126        this->player_ = this->owner_->getPlayer();
127    }
128
129    /**
130    @brief
131        Defines which actions the SimpleRocket has to take in each tick.
132    @param dt
133        The length of the tick.
134    */
135    void SimpleRocket::tick(float dt)
136    {
137        SUPER(SimpleRocket, 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 SimpleRocket::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->hit(this->owner_, contactPoint, dmg);
187//             this->destroy();
188        }
189        return false;
190    }
191
192    void SimpleRocket::destroyObject()
193    {
194        if (GameMode::isMaster())
195        {
196            this->destroy();
197        }
198    }
199
200    void SimpleRocket::fired(unsigned int firemode)
201    {
202        if (this->owner_)
203        {
204            {
205                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
206                effect->setPosition(this->getPosition());
207                effect->setOrientation(this->getOrientation());
208                effect->setDestroyAfterLife(true);
209                effect->setSource("Orxonox/explosion4");
210                effect->setLifetime(2.0f);
211            }
212
213            {
214                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
215                effect->setPosition(this->getPosition());
216                effect->setOrientation(this->getOrientation());
217                effect->setDestroyAfterLife(true);
218                effect->setSource("Orxonox/smoke4");
219                effect->setLifetime(3.0f);
220            }
221            this->destroy();
222        }
223    }
224
225    /**
226    @brief
227        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
228    @param value
229        The vector determining the amount of the angular movement.
230    */
231    void SimpleRocket::rotateYaw(const Vector2& value)
232    {
233        ControllableEntity::rotateYaw(value);
234
235        if( !this->isInMouseLook() )
236            this->localAngularVelocity_.y += value.x;
237    }
238
239    /**
240    @brief
241        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
242    @param value
243        The vector determining the amount of the angular movement.
244    */
245    void SimpleRocket::rotatePitch(const Vector2& value)
246    {
247        ControllableEntity::rotatePitch(value);
248
249        if( !this->isInMouseLook() )
250            this->localAngularVelocity_.x += value.x;
251    }
252
253    /**
254    @brief
255        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
256    @param value
257        The vector determining the amount of the angular movement.
258    */
259    void SimpleRocket::rotateRoll(const Vector2& value)
260    {
261        ControllableEntity::rotateRoll(value);
262
263        if( !this->isInMouseLook() )
264            this->localAngularVelocity_.z += value.x;
265    }
266
267}
Note: See TracBrowser for help on using the repository browser.