Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Success:
Now rocket spawns somewhere around the ship and the orientation is more or less correct. The controller does nothing but change some pitch/roll (to be sure it does something).
I modified the rocketfire particle to produce rocketfire2.particle which is slightly smaller and matches the smaller rocket.

File size: 7.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
63
64        //if (GameMode::isMaster())
65        //{
66           this->setCollisionType(WorldEntity::Kinematic);
67            this->setVelocity(0,0,100);
68
69            Model* model = new Model(this);
70            model->setMeshSource("rocket.mesh");
71            model->scale(0.7f);
72            this->attach(model);
73
74            ParticleEmitter* fire = new ParticleEmitter(this);
75            this->attach(fire);
76            fire->setOrientation(this->getOrientation());
77            fire->setSource("Orxonox/rocketfire2");
78
79            this->enableCollisionCallback();
80            this->setCollisionResponse(false);
81            this->setCollisionType(Kinematic);
82
83            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
84            collisionShape->setRadius(3);
85            collisionShape->setHeight(500);
86            this->attachCollisionShape(collisionShape);
87
88            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
89       // }
90
91    }
92
93    /**s
94    @brief
95        Destructor. Destroys controller, if present and kills sounds, if playing.
96    */
97    SimpleRocket::~SimpleRocket()
98    {
99                if (this->isInitialized()) {
100                COUT(0)<< "simplerocket destroyed\n";
101                delete this->getController();
102                }
103        }
104
105    /**
106    @brief
107        Method for creating a SimpleRocket through XML.
108    */
109    void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
110    {
111        // this calls the XMLPort function of the parent class
112        SUPER(SimpleRocket, XMLPort, xmlelement, mode);
113    }
114
115    void SimpleRocket::setOwner(Pawn* owner)
116    {
117        this->owner_ = owner;
118        //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
119        this->player_ = this->owner_->getPlayer();
120    }
121
122
123    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
124    {
125        if (!this->bDestroy_ && GameMode::isMaster())
126        {
127            if (otherObject == this->owner_)
128                return false;
129
130            this->bDestroy_ = true;
131
132            if (this->owner_)
133            {
134                {
135                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
136                    effect->setPosition(this->getPosition());
137                    effect->setOrientation(this->getOrientation());
138                    effect->setDestroyAfterLife(true);
139                    effect->setSource("Orxonox/explosion4");
140                    effect->setLifetime(2.0f);
141                }
142
143                {
144                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
145                    effect->setPosition(this->getPosition());
146                    effect->setOrientation(this->getOrientation());
147                    effect->setDestroyAfterLife(true);
148                    effect->setSource("Orxonox/smoke4");
149                    effect->setLifetime(3.0f);
150                }
151            }
152
153            float dmg = this->damage_;
154            if (this->owner_)
155                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
156
157            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
158            if (victim)
159                victim->hit(this->owner_, contactPoint, dmg);
160//             this->destroy();
161        }
162        return false;
163    }
164
165    void SimpleRocket::destroyObject()
166    {
167        if (GameMode::isMaster())
168        {
169            this->destroy();
170        }
171    }
172
173    void SimpleRocket::fired(unsigned int firemode)
174    {
175        if (this->owner_)
176        {
177            {
178                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
179                effect->setPosition(this->getPosition());
180                effect->setOrientation(this->getOrientation());
181                effect->setDestroyAfterLife(true);
182                effect->setSource("Orxonox/explosion4");
183                effect->setLifetime(2.0f);
184            }
185
186            {
187                ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
188                effect->setPosition(this->getPosition());
189                effect->setOrientation(this->getOrientation());
190                effect->setDestroyAfterLife(true);
191                effect->setSource("Orxonox/smoke4");
192                effect->setLifetime(3.0f);
193            }
194            this->destroy();
195        }
196    }
197
198    /**
199    @brief
200        Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
201    @param value
202        The vector determining the amount of the angular movement.
203    */
204    void SimpleRocket::rotateYaw(const Vector2& value)
205    {
206        ControllableEntity::rotateYaw(value);
207
208        if( !this->isInMouseLook() )
209            this->localAngularVelocity_.y += value.x;
210    }
211
212    /**
213    @brief
214        Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
215    @param value
216        The vector determining the amount of the angular movement.
217    */
218    void SimpleRocket::rotatePitch(const Vector2& value)
219    {
220        ControllableEntity::rotatePitch(value);
221
222        if( !this->isInMouseLook() )
223            this->localAngularVelocity_.x += value.x;
224    }
225
226    /**
227    @brief
228        Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
229    @param value
230        The vector determining the amount of the angular movement.
231    */
232    void SimpleRocket::rotateRoll(const Vector2& value)
233    {
234        ControllableEntity::rotateRoll(value);
235
236        if( !this->isInMouseLook() )
237            this->localAngularVelocity_.z += value.x;
238    }
239
240}
Note: See TracBrowser for help on using the repository browser.