Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6066 was 6066, checked in by rgrieder, 14 years ago

Fixed msvc build: file migration problem.

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