[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 "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 | |
---|
[2662] | 43 | Projectile::Projectile(BaseObject* creator) : MovableEntity(creator) |
---|
[2099] | 44 | { |
---|
| 45 | RegisterObject(Projectile); |
---|
| 46 | |
---|
| 47 | this->setConfigValues(); |
---|
[2662] | 48 | this->bDestroy_ = false; |
---|
| 49 | this->owner_ = 0; |
---|
[8386] | 50 | this->damage_ = 115; |
---|
| 51 | ///////////////////me |
---|
| 52 | this->healthdamage_ = 0; |
---|
| 53 | this->shielddamage_ = 0; |
---|
| 54 | ///////////////////end me |
---|
[2099] | 55 | |
---|
[2662] | 56 | // Get notification about collisions |
---|
[2099] | 57 | |
---|
[2896] | 58 | if (GameMode::isMaster()) |
---|
[2099] | 59 | { |
---|
[6417] | 60 | this->setMass(1.0); |
---|
[2662] | 61 | this->enableCollisionCallback(); |
---|
[3105] | 62 | this->setCollisionResponse(false); |
---|
[2662] | 63 | this->setCollisionType(Kinematic); |
---|
| 64 | |
---|
| 65 | SphereCollisionShape* shape = new SphereCollisionShape(this); |
---|
[3105] | 66 | shape->setRadius(20); |
---|
[2662] | 67 | this->attachCollisionShape(shape); |
---|
| 68 | |
---|
[5929] | 69 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Projectile::destroyObject, this))); |
---|
[2099] | 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | Projectile::~Projectile() |
---|
| 74 | { |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | void Projectile::setConfigValues() |
---|
| 78 | { |
---|
| 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_) |
---|
[5929] | 91 | this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick() |
---|
[2662] | 92 | } |
---|
| 93 | |
---|
| 94 | void Projectile::destroyObject() |
---|
| 95 | { |
---|
[2896] | 96 | if (GameMode::isMaster()) |
---|
[5929] | 97 | this->destroy(); |
---|
[2662] | 98 | } |
---|
| 99 | |
---|
[8183] | 100 | //////////////////////////me edit |
---|
[2662] | 101 | bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 102 | { |
---|
[2896] | 103 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
[2099] | 104 | { |
---|
[2918] | 105 | if (otherObject == this->owner_) |
---|
[3105] | 106 | return false; |
---|
[2918] | 107 | |
---|
[2662] | 108 | this->bDestroy_ = true; |
---|
| 109 | |
---|
[8183] | 110 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL |
---|
[8152] | 111 | |
---|
[2662] | 112 | if (this->owner_) |
---|
[2099] | 113 | { |
---|
[8183] | 114 | if (!victim || (victim && !victim->hasShield())) //same like below |
---|
[2099] | 115 | { |
---|
[2662] | 116 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 117 | effect->setPosition(this->getPosition()); |
---|
| 118 | effect->setOrientation(this->getOrientation()); |
---|
| 119 | effect->setDestroyAfterLife(true); |
---|
| 120 | effect->setSource("Orxonox/explosion3"); |
---|
| 121 | effect->setLifetime(2.0f); |
---|
[2099] | 122 | } |
---|
[8183] | 123 | if (!victim || (victim && !victim->hasShield())) //same like above |
---|
[2662] | 124 | { |
---|
| 125 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
| 126 | effect->setPosition(this->getPosition()); |
---|
| 127 | effect->setOrientation(this->getOrientation()); |
---|
| 128 | effect->setDestroyAfterLife(true); |
---|
| 129 | effect->setSource("Orxonox/smoke4"); |
---|
| 130 | effect->setLifetime(3.0f); |
---|
| 131 | } |
---|
[8152] | 132 | if (victim && victim->hasShield()) |
---|
| 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/engineglow"); |
---|
| 139 | effect->setLifetime(0.5f); |
---|
| 140 | } |
---|
[2099] | 141 | } |
---|
[2662] | 142 | |
---|
| 143 | if (victim) |
---|
[8183] | 144 | { |
---|
[8386] | 145 | victim->hit(this->owner_, contactPoint, this->damage_, this->healthdamage_, this->shielddamage_); |
---|
[8183] | 146 | victim->startReloadCountdown(); |
---|
| 147 | } |
---|
[2099] | 148 | } |
---|
[2662] | 149 | return false; |
---|
[2099] | 150 | } |
---|
[8183] | 151 | //////////////////////////////////////////////////////////////////////end edit |
---|
[2099] | 152 | |
---|
[5929] | 153 | void Projectile::setOwner(Pawn* owner) |
---|
[2099] | 154 | { |
---|
[5929] | 155 | this->owner_ = owner; |
---|
[2099] | 156 | } |
---|
| 157 | } |
---|