[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: |
---|
[10908] | 23 | * Jannis Holzer |
---|
[10836] | 24 | * Fabien Vultier |
---|
| 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | @file MineProjectile.h |
---|
| 32 | @brief Implementation of the MineProjectile class. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "MineProjectile.h" |
---|
| 36 | |
---|
| 37 | #include "core/CoreIncludes.h" |
---|
[10908] | 38 | #include "graphics/Model.h" |
---|
[10897] | 39 | #include "core/command/Executor.h" |
---|
[10908] | 40 | #include "graphics/ParticleSpawner.h" |
---|
| 41 | #include "worldentities/pawns/Pawn.h" |
---|
[10897] | 42 | #include "core/EventIncludes.h" |
---|
[10908] | 43 | #include "sound/WorldSound.h" |
---|
[10836] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
| 47 | RegisterClass(MineProjectile); |
---|
| 48 | |
---|
[10908] | 49 | const float MineProjectile::collisionShapeRadius_ = 15.0f; |
---|
| 50 | const float MineProjectile::damageRadius_ = 200.0f; |
---|
| 51 | const float MineProjectile::triggerRadius_ = 100.0f; |
---|
| 52 | |
---|
[10889] | 53 | MineProjectile::MineProjectile(Context* context) : MovableEntity(context), BasicProjectile() |
---|
[10836] | 54 | { |
---|
| 55 | RegisterObject(MineProjectile); |
---|
| 56 | |
---|
[10908] | 57 | this->bAllowExplosion_ = false; |
---|
[10889] | 58 | this->maxTimeUntilExplosion_ = 10.0f; |
---|
| 59 | this->timeUntilActivation_ = 1.0f; |
---|
[10836] | 60 | |
---|
[10908] | 61 | //Create movable entities |
---|
| 62 | rings1_ = new MovableEntity(this->getContext()); |
---|
| 63 | this->attach(rings1_); |
---|
| 64 | rings1_->setPosition(Vector3(0.0,0.0,0.0)); |
---|
| 65 | rings1_->setAngularVelocity(Vector3(0.0,5.0,0.0)); |
---|
[10889] | 66 | |
---|
[10908] | 67 | rings2_ = new MovableEntity(this->getContext()); |
---|
| 68 | this->attach(rings2_); |
---|
| 69 | rings2_->setPosition(Vector3(0.0,0.0,0.0)); |
---|
| 70 | rings2_->setAngularVelocity(Vector3(0.0,0.0,5.0)); |
---|
| 71 | |
---|
| 72 | core_ = new MovableEntity(this->getContext()); |
---|
| 73 | this->attach(core_); |
---|
| 74 | core_->setPosition(Vector3(0.0,0.0,0.0)); |
---|
| 75 | core_->setAngularVelocity(Vector3(2.5,2.5,0.0)); |
---|
| 76 | |
---|
| 77 | //Create Models |
---|
| 78 | //Core |
---|
[10889] | 79 | modelCore_ = new Model(this->getContext()); |
---|
| 80 | modelCore_->setMeshSource("Mine_Core.mesh"); |
---|
| 81 | modelCore_->setScale(15.0); |
---|
[10908] | 82 | core_->attach(modelCore_); |
---|
[10889] | 83 | modelCore_->setPosition(Vector3(0,0,0)); |
---|
| 84 | |
---|
[10908] | 85 | //Ring 1 |
---|
[10889] | 86 | modelRing1_ = new Model(this->getContext()); |
---|
| 87 | modelRing1_->setMeshSource("Mine_Ring.mesh"); |
---|
| 88 | modelRing1_->setScale(15.0); |
---|
[10908] | 89 | rings1_->attach(modelRing1_); |
---|
[10889] | 90 | modelRing1_->setPosition(Vector3(0,0,0)); |
---|
| 91 | modelRing1_->yaw(Degree(0)); |
---|
[10908] | 92 | //Ring 2 |
---|
[10889] | 93 | modelRing2_ = new Model(this->getContext()); |
---|
| 94 | modelRing2_->setMeshSource("Mine_Ring.mesh"); |
---|
| 95 | modelRing2_->setScale(15.0); |
---|
[10908] | 96 | rings1_->attach(modelRing2_); |
---|
[10889] | 97 | modelRing2_->setPosition(Vector3(0,0,0)); |
---|
| 98 | modelRing2_->yaw(Degree(180)); |
---|
[10908] | 99 | //Ring 3 |
---|
| 100 | modelRing3_ = new Model(this->getContext()); |
---|
| 101 | modelRing3_->setMeshSource("Mine_Ring.mesh"); |
---|
| 102 | modelRing3_->setScale(15.0); |
---|
| 103 | rings2_->attach(modelRing3_); |
---|
| 104 | modelRing3_->setPosition(Vector3(0,0,0)); |
---|
| 105 | modelRing3_->yaw(Degree(90)); |
---|
| 106 | //Ring 4 |
---|
| 107 | modelRing4_ = new Model(this->getContext()); |
---|
| 108 | modelRing4_->setMeshSource("Mine_Ring.mesh"); |
---|
| 109 | modelRing4_->setScale(15.0); |
---|
| 110 | rings2_->attach(modelRing4_); |
---|
| 111 | modelRing4_->setPosition(Vector3(0,0,0)); |
---|
| 112 | modelRing4_->yaw(Degree(270)); |
---|
[10889] | 113 | |
---|
[10908] | 114 | emitter_ = NULL; |
---|
| 115 | |
---|
[10889] | 116 | if (GameMode::isMaster()) |
---|
| 117 | { |
---|
| 118 | this->setMass(10.0f); |
---|
| 119 | this->setFriction(100.0f); |
---|
| 120 | this->enableCollisionCallback(); |
---|
| 121 | this->setCollisionResponse(false); |
---|
| 122 | this->setCollisionType(Dynamic); |
---|
| 123 | |
---|
| 124 | // Create a sphere collision shape and attach it to the projectile. |
---|
| 125 | collisionShape_ = new SphereCollisionShape(this->getContext()); |
---|
[10908] | 126 | collisionShape_->setRadius(collisionShapeRadius_); |
---|
[10889] | 127 | this->attachCollisionShape(collisionShape_); |
---|
[10908] | 128 | collisionShape_->setPosition(Vector3(0,0,0)); |
---|
[10889] | 129 | |
---|
| 130 | // Create a distance trigger and attach it to the projectile. |
---|
| 131 | distanceTrigger_ = new DistanceTrigger(this->getContext()); |
---|
| 132 | this->attach(distanceTrigger_); |
---|
| 133 | distanceTrigger_->setPosition(Vector3(0,0,0)); |
---|
[10908] | 134 | distanceTrigger_->setDistance(triggerRadius_); |
---|
[10889] | 135 | distanceTrigger_->addTarget("Pawn"); |
---|
[10908] | 136 | distanceTrigger_->setStayActive(false); |
---|
[10897] | 137 | |
---|
| 138 | this->addEventSource(distanceTrigger_, "explode"); |
---|
[10889] | 139 | } |
---|
[10836] | 140 | } |
---|
| 141 | |
---|
[10889] | 142 | MineProjectile::~MineProjectile() |
---|
| 143 | { |
---|
[10897] | 144 | if (this->isInitialized()) |
---|
[10889] | 145 | { |
---|
[10908] | 146 | modelCore_->destroy(); |
---|
| 147 | modelRing1_->destroy(); |
---|
| 148 | modelRing2_->destroy(); |
---|
| 149 | modelRing3_->destroy(); |
---|
| 150 | modelRing4_->destroy(); |
---|
| 151 | |
---|
| 152 | distanceTrigger_->destroy(); |
---|
| 153 | |
---|
| 154 | if (emitter_) |
---|
[10897] | 155 | { |
---|
[10908] | 156 | emitter_->destroy(); |
---|
| 157 | } |
---|
[10897] | 158 | } |
---|
[10889] | 159 | } |
---|
| 160 | |
---|
[10908] | 161 | /** |
---|
| 162 | @brief |
---|
| 163 | TODO |
---|
| 164 | */ |
---|
[10897] | 165 | void MineProjectile::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 166 | { |
---|
| 167 | SUPER(MineProjectile, XMLEventPort, xmlelement, mode); |
---|
[10908] | 168 | XMLPortEventState(MineProjectile, BaseObject, "explode", explode, xmlelement, mode); |
---|
[10897] | 169 | } |
---|
| 170 | |
---|
[10836] | 171 | /** |
---|
| 172 | @brief |
---|
[10889] | 173 | TODO |
---|
[10836] | 174 | */ |
---|
[10889] | 175 | void MineProjectile::setMaxTimeUntilExplosion(float maxTimeUntilExplosion) |
---|
[10836] | 176 | { |
---|
[10889] | 177 | if (maxTimeUntilExplosion >= 0) |
---|
[10836] | 178 | { |
---|
[10889] | 179 | this->maxTimeUntilExplosion_ = maxTimeUntilExplosion; |
---|
| 180 | if (GameMode::isMaster()) |
---|
| 181 | { |
---|
[10908] | 182 | this->explodeTimer_.setTimer(this->maxTimeUntilExplosion_, false, createExecutor(createFunctor(&MineProjectile::explode, this))); |
---|
[10889] | 183 | } |
---|
[10836] | 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
[10889] | 187 | this->maxTimeUntilExplosion_ = 0; |
---|
[10836] | 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
| 192 | @brief |
---|
[10889] | 193 | TODO |
---|
[10836] | 194 | */ |
---|
[10889] | 195 | void MineProjectile::setTimeUntilActivation(float timeUntilActivation) |
---|
| 196 | { |
---|
| 197 | timeUntilActivation_ = timeUntilActivation; |
---|
[10836] | 198 | |
---|
[10889] | 199 | if (GameMode::isMaster()) |
---|
| 200 | { |
---|
[10908] | 201 | this->activationTimer_.setTimer(this->timeUntilActivation_, false, createExecutor(createFunctor(&MineProjectile::allowExplosion, this))); |
---|
[10889] | 202 | } |
---|
| 203 | } |
---|
[10836] | 204 | |
---|
| 205 | /** |
---|
| 206 | @brief |
---|
[10889] | 207 | TODO |
---|
[10836] | 208 | */ |
---|
[10908] | 209 | void MineProjectile::explode() |
---|
[10836] | 210 | { |
---|
[10908] | 211 | if (bAllowExplosion_) |
---|
| 212 | { |
---|
| 213 | if (GameMode::isMaster()) |
---|
| 214 | { |
---|
| 215 | // Damage all pawns within the damage radius |
---|
| 216 | for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) |
---|
| 217 | { |
---|
| 218 | Vector3 distanceVector = it->getWorldPosition()-this->getWorldPosition(); |
---|
| 219 | if(distanceVector.length()< damageRadius_) |
---|
| 220 | { |
---|
| 221 | it->hit(this->getShooter(), it->getWorldPosition(), NULL, this->getDamage(), this->getHealthDamage(), this->getShieldDamage()); |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | } |
---|
[10836] | 225 | |
---|
[10908] | 226 | this->destructionEffect(); |
---|
| 227 | this->destroyLater(); |
---|
| 228 | } |
---|
| 229 | } |
---|
[10836] | 230 | |
---|
[10908] | 231 | /** |
---|
| 232 | @brief |
---|
| 233 | TODO |
---|
| 234 | */ |
---|
| 235 | void MineProjectile::allowExplosion() |
---|
| 236 | { |
---|
| 237 | // Allow explosion |
---|
| 238 | bAllowExplosion_ = true; |
---|
| 239 | // Add particle effect |
---|
| 240 | emitter_ = new ParticleEmitter(this->getContext()); |
---|
| 241 | this->attach(emitter_); |
---|
| 242 | emitter_->setOrientation(this->getOrientation()); |
---|
| 243 | emitter_->setSource("Orxonox/mineparticle"); |
---|
[10836] | 244 | } |
---|
[10889] | 245 | |
---|
| 246 | /** |
---|
| 247 | @brief |
---|
| 248 | TODO |
---|
| 249 | */ |
---|
[10908] | 250 | void MineProjectile::destructionEffect() |
---|
[10889] | 251 | { |
---|
[10908] | 252 | ParticleSpawner *effect1, *effect2, *effect3; |
---|
| 253 | |
---|
| 254 | effect1 = new ParticleSpawner(this->getContext()); |
---|
| 255 | effect2 = new ParticleSpawner(this->getContext()); |
---|
| 256 | effect3 = new ParticleSpawner(this->getContext()); |
---|
[10889] | 257 | |
---|
[10908] | 258 | effect1->setPosition(this->getPosition()); |
---|
| 259 | effect1->setOrientation(this->getOrientation()); |
---|
| 260 | effect1->setDestroyAfterLife(true); |
---|
| 261 | effect1->setSource("Orxonox/MineExpl"); |
---|
| 262 | effect1->setLifetime(2.5f); |
---|
| 263 | |
---|
| 264 | effect2->setPosition(this->getPosition()); |
---|
| 265 | effect2->setOrientation(this->getOrientation()); |
---|
| 266 | effect2->setDestroyAfterLife(true); |
---|
| 267 | effect2->setSource("Orxonox/MineExpl1"); |
---|
| 268 | effect2->setLifetime(2.5f); |
---|
| 269 | |
---|
| 270 | effect3->setPosition(this->getPosition()); |
---|
| 271 | effect3->setOrientation(this->getOrientation()); |
---|
| 272 | effect3->setDestroyAfterLife(true); |
---|
| 273 | effect3->setSource("Orxonox/MineExpl2"); |
---|
| 274 | effect3->setLifetime(2.5f); |
---|
| 275 | |
---|
| 276 | // Explosion sound effect. |
---|
| 277 | WeakPtr<WorldSound> explosionSound_ = new WorldSound(getContext()); |
---|
| 278 | explosionSound_->setSource("sounds/GravityFieldExplosion.ogg"); |
---|
| 279 | explosionSound_->setVolume(1.0); |
---|
| 280 | explosionSound_->play(); |
---|
[10889] | 281 | } |
---|
[10836] | 282 | } |
---|