Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trying to make CE change possible

File size: 6.7 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);    // put your code in here:
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->setCollisionType(WorldEntity::Kinematic);
55        this->setVelocity(0,0,-100);
56        this->model_ = new Model(this);
57        this->model_->setMeshSource("can.mesh");
58        this->attach(this->model_);
59        this->lifetime_ = 100;
60       
61        if (GameMode::isMaster())
62        {
63            this->enableCollisionCallback();
64            this->setCollisionResponse(false);
65            this->setCollisionType(Kinematic);
66
67            this->collisionShape_ = new ConeCollisionShape(this);
68            this->collisionShape_->setRadius(3);
69            this->collisionShape_->setHeight(500);
70            this->attachCollisionShape(this->collisionShape_);
71
72            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
73        }
74       
75        this->camPosition_ = new CameraPosition(this);
76        this->camPosition_->setPosition(0,0,0);
77        this->attach( this->camPosition_ );
78        this->addCameraPosition( this->camPosition_ );
79    }
80
81    /**
82    @brief
83        Destructor. Destroys controller, if present.
84    */
85    Rocket::~Rocket()
86    {
87        if(this->isInitialized())
88        {
89            this->collisionShape_->destroy();
90            this->model_->destroy();
91           
92            if (GameMode::isMaster() && this->owner_)
93                this->owner_->getPlayer()->startControl(this->originalControllableEntity_);
94            this->camPosition_->destroy();
95        }
96    }
97
98    /**
99    @brief
100        Method for creating a Rocket through XML.
101    */
102    void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
103    {
104        // this calls the XMLPort function of the parent class
105        SUPER(Rocket, XMLPort, xmlelement, mode);
106    }
107   
108    void Rocket::setOwner(Pawn* owner)
109    {
110        this->owner_ = owner;
111           
112        this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
113        this->owner_->getPlayer()->startControl(this);
114    }
115
116    /**
117    @brief
118        Defines which actions the Rocket has to take in each tick.
119    @param dt
120        The length of the tick.
121    */
122    void Rocket::tick(float dt)
123    {
124        SUPER(Rocket, tick, dt);
125       
126        this->setAngularVelocity(this->localAngularVelocity_);
127    }
128   
129    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
130    {
131        if (!this->bDestroy_ && GameMode::isMaster())
132        {
133            if (otherObject == this->owner_)
134                return false;
135
136            this->bDestroy_ = true;
137
138            if (this->owner_)
139            {
140                {
141                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
142                    effect->setPosition(this->getPosition());
143                    effect->setOrientation(this->getOrientation());
144                    effect->setDestroyAfterLife(true);
145                    effect->setSource("Orxonox/explosion3");
146                    effect->setLifetime(2.0f);
147                }
148                {
149                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
150                    effect->setPosition(this->getPosition());
151                    effect->setOrientation(this->getOrientation());
152                    effect->setDestroyAfterLife(true);
153                    effect->setSource("Orxonox/smoke4");
154                    effect->setLifetime(3.0f);
155                }
156            }
157
158            float dmg = this->damage_;
159            if (this->owner_)
160                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
161
162            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
163            if (victim)
164                victim->damage(dmg, this->owner_);
165        }
166        return false;
167    }
168   
169    void Rocket::destroyObject()
170    {
171        if (GameMode::isMaster())
172            this->destroy();
173    }
174
175    /**
176    @brief
177        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
178    @param value
179        The vector determining the amount of the angular movement.
180    */
181    void Rocket::rotateYaw(const Vector2& value)
182    {
183        this->localAngularVelocity_.y = value.x;
184    }
185
186    /**
187    @brief
188        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
189    @param value
190        The vector determining the amount of the angular movement.
191    */
192    void Rocket::rotatePitch(const Vector2& value)
193    {
194        this->localAngularVelocity_.x = value.x;
195    }
196
197    /**
198    @brief
199        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
200    @param value
201        The vector determining the amount of the angular movement.
202    */
203    void Rocket::rotateRoll(const Vector2& value)
204    {
205        this->localAngularVelocity_.z = value.x;
206    }
207   
208}
Note: See TracBrowser for help on using the repository browser.