[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: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "Projectile.h" |
---|
| 31 | |
---|
| 32 | #include <OgreBillboard.h> |
---|
| 33 | |
---|
| 34 | #include "core/CoreIncludes.h" |
---|
| 35 | #include "core/Executor.h" |
---|
| 36 | #include "core/ConfigValueIncludes.h" |
---|
| 37 | #include "core/Iterator.h" |
---|
| 38 | #include "tools/ParticleInterface.h" |
---|
| 39 | |
---|
[2100] | 40 | #include "objects/worldentities/Model.h" |
---|
| 41 | #include "objects/worldentities/ParticleSpawner.h" |
---|
[2494] | 42 | #include "objects/collisionshapes/SphereCollisionShape.h" |
---|
[2493] | 43 | #include "core/Core.h" |
---|
[2099] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[2493] | 47 | Projectile::Projectile(BaseObject* creator) : MovableEntity(creator) |
---|
[2099] | 48 | { |
---|
| 49 | RegisterObject(Projectile); |
---|
| 50 | |
---|
| 51 | this->setConfigValues(); |
---|
[2494] | 52 | this->bDestroy_ = false; |
---|
| 53 | this->owner_ = 0; |
---|
[2099] | 54 | |
---|
[2466] | 55 | // Get notification about collisions |
---|
| 56 | this->enableCollisionCallback(); |
---|
| 57 | |
---|
[2494] | 58 | this->setCollisionType(Kinematic); |
---|
[2099] | 59 | |
---|
[2494] | 60 | SphereCollisionShape* shape = new SphereCollisionShape(this); |
---|
| 61 | shape->setRadius(10); |
---|
| 62 | this->attachCollisionShape(shape); |
---|
| 63 | |
---|
[2497] | 64 | if(Core::isMaster()) |
---|
[2099] | 65 | this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | Projectile::~Projectile() |
---|
| 69 | { |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void Projectile::setConfigValues() |
---|
| 73 | { |
---|
| 74 | SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); |
---|
| 75 | SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | void Projectile::tick(float dt) |
---|
| 80 | { |
---|
| 81 | SUPER(Projectile, tick, dt); |
---|
| 82 | |
---|
| 83 | if (!this->isActive()) |
---|
| 84 | return; |
---|
[2494] | 85 | |
---|
| 86 | if (this->bDestroy_) |
---|
| 87 | delete this; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void Projectile::destroyObject() |
---|
| 91 | { |
---|
[2497] | 92 | if (Core::isMaster()) |
---|
| 93 | delete this; |
---|
[2494] | 94 | } |
---|
| 95 | |
---|
| 96 | bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 97 | { |
---|
[2497] | 98 | if (!this->bDestroy_ && Core::isMaster()) |
---|
[2099] | 99 | { |
---|
[2494] | 100 | this->bDestroy_ = true; |
---|
| 101 | |
---|
| 102 | if (this->owner_) |
---|
[2099] | 103 | { |
---|
| 104 | { |
---|
[2494] | 105 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 106 | effect->setPosition(this->getPosition()); |
---|
| 107 | effect->setOrientation(this->getOrientation()); |
---|
| 108 | effect->setDestroyAfterLife(true); |
---|
| 109 | effect->setSource("Orxonox/explosion3"); |
---|
| 110 | effect->setLifetime(2.0f); |
---|
[2099] | 111 | } |
---|
[2494] | 112 | { |
---|
| 113 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 114 | effect->setPosition(this->getPosition()); |
---|
| 115 | effect->setOrientation(this->getOrientation()); |
---|
| 116 | effect->setDestroyAfterLife(true); |
---|
| 117 | effect->setSource("Orxonox/smoke4"); |
---|
| 118 | effect->setLifetime(3.0f); |
---|
| 119 | } |
---|
[2099] | 120 | } |
---|
[2497] | 121 | |
---|
| 122 | Pawn* victim = dynamic_cast<Pawn*>(otherObject); |
---|
| 123 | if (victim) |
---|
| 124 | victim->damage(this->damage_, this->owner_); |
---|
[2099] | 125 | } |
---|
[2494] | 126 | return false; |
---|
[2099] | 127 | } |
---|
[2497] | 128 | |
---|
| 129 | void Projectile::destroyedPawn(Pawn* pawn) |
---|
| 130 | { |
---|
| 131 | if (this->owner_ == pawn) |
---|
| 132 | this->owner_ = 0; |
---|
| 133 | } |
---|
[2099] | 134 | } |
---|