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