[2099] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
[8542] | 25 | * simonmie |
---|
[2099] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Projectile.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
[3196] | 32 | #include "core/ConfigValueIncludes.h" |
---|
| 33 | #include "core/GameMode.h" |
---|
[7284] | 34 | #include "core/command/Executor.h" |
---|
[3196] | 35 | #include "objects/collisionshapes/SphereCollisionShape.h" |
---|
[5735] | 36 | #include "worldentities/pawns/Pawn.h" |
---|
[5737] | 37 | #include "graphics/ParticleSpawner.h" |
---|
[2099] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[3088] | 41 | CreateFactory(Projectile); |
---|
[3105] | 42 | |
---|
[8492] | 43 | Projectile::Projectile(BaseObject* creator) : MovableEntity(creator), BasicProjectile() |
---|
[2099] | 44 | { |
---|
| 45 | RegisterObject(Projectile); |
---|
| 46 | |
---|
| 47 | this->setConfigValues(); |
---|
[8542] | 48 | this->owner_ = 0; |
---|
[2099] | 49 | |
---|
[2662] | 50 | // Get notification about collisions |
---|
[2896] | 51 | if (GameMode::isMaster()) |
---|
[2099] | 52 | { |
---|
[6417] | 53 | this->setMass(1.0); |
---|
[2662] | 54 | this->enableCollisionCallback(); |
---|
[3105] | 55 | this->setCollisionResponse(false); |
---|
[2662] | 56 | this->setCollisionType(Kinematic); |
---|
| 57 | |
---|
| 58 | SphereCollisionShape* shape = new SphereCollisionShape(this); |
---|
[3105] | 59 | shape->setRadius(20); |
---|
[2662] | 60 | this->attachCollisionShape(shape); |
---|
| 61 | |
---|
[5929] | 62 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Projectile::destroyObject, this))); |
---|
[2099] | 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | Projectile::~Projectile() |
---|
| 67 | { |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void Projectile::setConfigValues() |
---|
| 71 | { |
---|
| 72 | SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void Projectile::tick(float dt) |
---|
| 77 | { |
---|
[2809] | 78 | SUPER(Projectile, tick, dt); |
---|
[2099] | 79 | |
---|
| 80 | if (!this->isActive()) |
---|
| 81 | return; |
---|
| 82 | |
---|
[8492] | 83 | if (this->getBDestroy()) |
---|
[5929] | 84 | this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick() |
---|
[2662] | 85 | } |
---|
| 86 | |
---|
| 87 | void Projectile::destroyObject() |
---|
| 88 | { |
---|
[2896] | 89 | if (GameMode::isMaster()) |
---|
[5929] | 90 | this->destroy(); |
---|
[2662] | 91 | } |
---|
| 92 | |
---|
[8542] | 93 | /* Calls the collidesAgainst function of BasicProjectile |
---|
| 94 | */ |
---|
[2662] | 95 | bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 96 | { |
---|
[8538] | 97 | return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); |
---|
[8492] | 98 | } |
---|
| 99 | |
---|
[5929] | 100 | void Projectile::setOwner(Pawn* owner) |
---|
[2099] | 101 | { |
---|
[5929] | 102 | this->owner_ = owner; |
---|
[2099] | 103 | } |
---|
| 104 | } |
---|