[10836] | 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 | * Fabien Vultier |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file MineProjectile.h |
---|
| 31 | @brief Implementation of the MineProjectile class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "MineProjectile.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "graphics/Model.h" |
---|
| 38 | #include "core/command/Executor.h" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterClass(MineProjectile); |
---|
| 43 | |
---|
[10889] | 44 | MineProjectile::MineProjectile(Context* context) : MovableEntity(context), BasicProjectile() |
---|
[10836] | 45 | { |
---|
| 46 | RegisterObject(MineProjectile); |
---|
| 47 | |
---|
[10889] | 48 | this->bActive_ = false; |
---|
| 49 | this->maxTimeUntilExplosion_ = 10.0f; |
---|
| 50 | this->timeUntilActivation_ = 1.0f; |
---|
[10836] | 51 | |
---|
[10889] | 52 | rings_ = new MovableEntity(this->getContext()); |
---|
| 53 | this->attach(rings_); |
---|
| 54 | rings_->setPosition(Vector3(0.0,0.0,0.0)); |
---|
| 55 | rings_->setAngularVelocity(Vector3(0.0,5.0,0.0)); |
---|
| 56 | |
---|
| 57 | modelCore_ = new Model(this->getContext()); |
---|
| 58 | modelCore_->setMeshSource("Mine_Core.mesh"); |
---|
| 59 | modelCore_->setScale(15.0); |
---|
| 60 | this->attach(modelCore_); |
---|
| 61 | modelCore_->setPosition(Vector3(0,0,0)); |
---|
| 62 | |
---|
| 63 | modelRing1_ = new Model(this->getContext()); |
---|
| 64 | modelRing1_->setMeshSource("Mine_Ring.mesh"); |
---|
| 65 | modelRing1_->setScale(15.0); |
---|
| 66 | rings_->attach(modelRing1_); |
---|
| 67 | modelRing1_->setPosition(Vector3(0,0,0)); |
---|
| 68 | modelRing1_->yaw(Degree(0)); |
---|
| 69 | |
---|
| 70 | modelRing2_ = new Model(this->getContext()); |
---|
| 71 | modelRing2_->setMeshSource("Mine_Ring.mesh"); |
---|
| 72 | modelRing2_->setScale(15.0); |
---|
| 73 | rings_->attach(modelRing2_); |
---|
| 74 | modelRing2_->setPosition(Vector3(0,0,0)); |
---|
| 75 | modelRing2_->yaw(Degree(180)); |
---|
| 76 | |
---|
| 77 | if (GameMode::isMaster()) |
---|
| 78 | { |
---|
| 79 | this->setMass(10.0f); |
---|
| 80 | this->setFriction(100.0f); |
---|
| 81 | this->enableCollisionCallback(); |
---|
| 82 | this->setCollisionResponse(false); |
---|
| 83 | this->setCollisionType(Dynamic); |
---|
| 84 | |
---|
| 85 | // Create a sphere collision shape and attach it to the projectile. |
---|
| 86 | collisionShape_ = new SphereCollisionShape(this->getContext()); |
---|
| 87 | collisionShape_->setRadius(10.0f); |
---|
| 88 | this->attachCollisionShape(collisionShape_); |
---|
| 89 | |
---|
| 90 | // Create a distance trigger and attach it to the projectile. |
---|
| 91 | distanceTrigger_ = new DistanceTrigger(this->getContext()); |
---|
| 92 | this->attach(distanceTrigger_); |
---|
| 93 | distanceTrigger_->setPosition(Vector3(0,0,0)); |
---|
| 94 | distanceTrigger_->setDistance(40.0f); |
---|
| 95 | distanceTrigger_->addTarget("Pawn"); |
---|
| 96 | distanceTrigger_->setStayActive(true); |
---|
| 97 | } |
---|
[10836] | 98 | } |
---|
| 99 | |
---|
[10889] | 100 | MineProjectile::~MineProjectile() |
---|
| 101 | { |
---|
| 102 | /*if (modelCore_ != NULL) |
---|
| 103 | { |
---|
| 104 | modelCore_->destroy(); |
---|
| 105 | }*/ |
---|
| 106 | /*if (distanceTrigger_ != NULL) |
---|
| 107 | { |
---|
| 108 | distanceTrigger_->destroy(); |
---|
| 109 | }*/ |
---|
| 110 | } |
---|
| 111 | |
---|
[10836] | 112 | /** |
---|
| 113 | @brief |
---|
[10889] | 114 | TODO |
---|
[10836] | 115 | */ |
---|
[10889] | 116 | void MineProjectile::setMaxTimeUntilExplosion(float maxTimeUntilExplosion) |
---|
[10836] | 117 | { |
---|
[10889] | 118 | if (maxTimeUntilExplosion >= 0) |
---|
[10836] | 119 | { |
---|
[10889] | 120 | this->maxTimeUntilExplosion_ = maxTimeUntilExplosion; |
---|
| 121 | if (GameMode::isMaster()) |
---|
| 122 | { |
---|
| 123 | this->explodeTimer_.setTimer(this->maxTimeUntilExplosion_, false, createExecutor(createFunctor(&MineProjectile::Explode, this))); |
---|
| 124 | } |
---|
[10836] | 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
[10889] | 128 | this->maxTimeUntilExplosion_ = 0; |
---|
[10836] | 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | @brief |
---|
[10889] | 134 | TODO |
---|
[10836] | 135 | */ |
---|
[10889] | 136 | void MineProjectile::setTimeUntilActivation(float timeUntilActivation) |
---|
| 137 | { |
---|
| 138 | timeUntilActivation_ = timeUntilActivation; |
---|
[10836] | 139 | |
---|
[10889] | 140 | if (GameMode::isMaster()) |
---|
| 141 | { |
---|
| 142 | this->activationTimer_.setTimer(this->timeUntilActivation_, false, createExecutor(createFunctor(&MineProjectile::Activate, this))); |
---|
| 143 | } |
---|
| 144 | } |
---|
[10836] | 145 | |
---|
| 146 | /** |
---|
| 147 | @brief |
---|
[10889] | 148 | TODO |
---|
[10836] | 149 | */ |
---|
| 150 | void MineProjectile::Explode() |
---|
| 151 | { |
---|
[10889] | 152 | orxout() << "MineProjectile::Explode" << endl; |
---|
[10836] | 153 | |
---|
| 154 | this->destroyLater(); |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | } |
---|
[10889] | 158 | |
---|
| 159 | /** |
---|
| 160 | @brief |
---|
| 161 | TODO |
---|
| 162 | */ |
---|
| 163 | void MineProjectile::Activate() |
---|
| 164 | { |
---|
| 165 | orxout() << "MineProjectile::Activate" << endl; |
---|
| 166 | |
---|
| 167 | bActive_ = true; |
---|
| 168 | } |
---|
[10836] | 169 | } |
---|