[3087] | 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 | * Benjamin de Capitani |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "BigExplosion.h" |
---|
| 30 | |
---|
[3196] | 31 | #include "util/Exception.h" |
---|
[3087] | 32 | #include "core/CoreIncludes.h" |
---|
[3196] | 33 | #include "core/GameMode.h" |
---|
[7284] | 34 | #include "core/command/Executor.h" |
---|
[3196] | 35 | #include "tools/ParticleInterface.h" |
---|
[5735] | 36 | #include "Scene.h" |
---|
[5737] | 37 | #include "graphics/ParticleSpawner.h" |
---|
| 38 | #include "graphics/Model.h" |
---|
[7176] | 39 | #include "MovableEntity.h" |
---|
[3087] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[9667] | 43 | RegisterClass(BigExplosion); |
---|
[3087] | 44 | |
---|
[9837] | 45 | BigExplosion::BigExplosion(Context* context) : MobileEntity(context) |
---|
[3087] | 46 | { |
---|
| 47 | RegisterObject(BigExplosion); |
---|
| 48 | |
---|
| 49 | if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) ) |
---|
| 50 | ThrowException(AbortLoading, "Can't create BigExplosion, no scene or no scene manager given."); |
---|
[7176] | 51 | |
---|
[3087] | 52 | this->bStop_ = false; |
---|
[3280] | 53 | this->LOD_ = LODParticle::Normal; |
---|
[3087] | 54 | |
---|
| 55 | if ( GameMode::showsGraphics() ) |
---|
| 56 | { |
---|
| 57 | try |
---|
| 58 | { |
---|
| 59 | this->init(); |
---|
| 60 | } |
---|
[7174] | 61 | catch (const std::exception& ex) |
---|
[3087] | 62 | { |
---|
[8858] | 63 | orxout(internal_error) << "Couldn't load particle effect in BigExplosion: " << ex.what() << endl; |
---|
[3087] | 64 | this->initZero(); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | this->initZero(); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (GameMode::isMaster()) |
---|
| 73 | { |
---|
[5929] | 74 | this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&BigExplosion::stop, this))); |
---|
[3087] | 75 | } |
---|
[7176] | 76 | |
---|
[3087] | 77 | this->registerVariables(); |
---|
| 78 | } |
---|
| 79 | |
---|
[9879] | 80 | BigExplosion::BigExplosion(Context* context, Vector3 initVelocity) : MobileEntity(context) |
---|
| 81 | { |
---|
| 82 | RegisterObject(BigExplosion); |
---|
| 83 | this->setVelocity(initVelocity); |
---|
| 84 | |
---|
| 85 | if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) ) |
---|
| 86 | ThrowException(AbortLoading, "Can't create BigExplosion, no scene or no scene manager given."); |
---|
| 87 | |
---|
| 88 | this->bStop_ = false; |
---|
| 89 | this->LOD_ = LODParticle::Normal; |
---|
| 90 | |
---|
| 91 | if ( GameMode::showsGraphics() ) |
---|
| 92 | { |
---|
| 93 | try |
---|
| 94 | { |
---|
| 95 | this->init(); |
---|
| 96 | } |
---|
| 97 | catch (const std::exception& ex) |
---|
| 98 | { |
---|
| 99 | orxout(internal_error) << "Couldn't load particle effect in BigExplosion: " << ex.what() << endl; |
---|
| 100 | this->initZero(); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
| 105 | this->initZero(); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (GameMode::isMaster()) |
---|
| 109 | { |
---|
| 110 | this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&BigExplosion::stop, this))); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | this->registerVariables(); |
---|
| 114 | } |
---|
| 115 | |
---|
[3087] | 116 | void BigExplosion::init() |
---|
| 117 | { |
---|
[9667] | 118 | this->debrisEntity1_ = new MovableEntity(this->getContext()); |
---|
| 119 | this->debrisEntity2_ = new MovableEntity(this->getContext()); |
---|
| 120 | this->debrisEntity3_ = new MovableEntity(this->getContext()); |
---|
| 121 | this->debrisEntity4_ = new MovableEntity(this->getContext()); |
---|
[7176] | 122 | |
---|
[7163] | 123 | this->debrisEntity1_->setSyncMode(0); |
---|
| 124 | this->debrisEntity2_->setSyncMode(0); |
---|
| 125 | this->debrisEntity3_->setSyncMode(0); |
---|
| 126 | this->debrisEntity4_->setSyncMode(0); |
---|
[3087] | 127 | |
---|
[9667] | 128 | this->debris1_ = new Model(this->getContext()); |
---|
| 129 | this->debris2_ = new Model(this->getContext()); |
---|
| 130 | this->debris3_ = new Model(this->getContext()); |
---|
| 131 | this->debris4_ = new Model(this->getContext()); |
---|
[7176] | 132 | |
---|
[7163] | 133 | this->debris1_->setSyncMode(0); |
---|
| 134 | this->debris2_->setSyncMode(0); |
---|
| 135 | this->debris3_->setSyncMode(0); |
---|
| 136 | this->debris4_->setSyncMode(0); |
---|
[3087] | 137 | |
---|
[9837] | 138 | this->explosion_ = new MobileEntity(this->getContext()); |
---|
[7163] | 139 | this->explosion_->setSyncMode(0); |
---|
[3087] | 140 | |
---|
| 141 | this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 142 | this->debrisSmoke2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 143 | this->debrisSmoke3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 144 | this->debrisSmoke4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 145 | |
---|
| 146 | this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 147 | this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 148 | this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 149 | this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 150 | |
---|
| 151 | this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
| 152 | this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
| 153 | this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
| 154 | this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
| 155 | this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
| 156 | this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
| 157 | this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
| 158 | this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
| 159 | |
---|
| 160 | this->debris1_->setMeshSource("CockpitDebris.mesh"); |
---|
| 161 | this->debris2_->setMeshSource("WingDebris1.mesh"); |
---|
| 162 | this->debris3_->setMeshSource("BodyDebris1.mesh"); |
---|
| 163 | this->debris4_->setMeshSource("WingDebris2.mesh"); |
---|
| 164 | |
---|
| 165 | this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 166 | this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 167 | this->debrisEntity1_->setScale(4); |
---|
| 168 | |
---|
| 169 | this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 170 | this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 171 | this->debrisEntity2_->setScale(4); |
---|
| 172 | |
---|
| 173 | this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 174 | this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 175 | this->debrisEntity3_->setScale(4); |
---|
| 176 | |
---|
| 177 | this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 178 | this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 179 | this->debrisEntity4_->setScale(4); |
---|
| 180 | |
---|
| 181 | this->debrisEntity1_->attach(debris1_); |
---|
| 182 | this->debrisEntity2_->attach(debris2_); |
---|
| 183 | this->debrisEntity3_->attach(debris3_); |
---|
| 184 | this->debrisEntity4_->attach(debris4_); |
---|
| 185 | |
---|
[9869] | 186 | // /////////////////////// |
---|
| 187 | // TODO: particleSpawner is a static entity. It should probably be dynamic, for better explosions. |
---|
| 188 | // |
---|
[9667] | 189 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[9879] | 190 | orxout() << "vel " << this->getVelocity() << endl; |
---|
| 191 | // effect->setVelocity(this->getVelocity()); |
---|
[3087] | 192 | effect->setDestroyAfterLife(true); |
---|
| 193 | effect->setSource("Orxonox/explosion2b"); |
---|
| 194 | effect->setLifetime(4.0f); |
---|
[7163] | 195 | effect->setSyncMode(0); |
---|
[3087] | 196 | |
---|
[9667] | 197 | ParticleSpawner* effect2 = new ParticleSpawner(this->getContext()); |
---|
[9869] | 198 | // effect2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 200)); |
---|
[3087] | 199 | effect2->setDestroyAfterLife(true); |
---|
| 200 | effect2->setSource("Orxonox/smoke6"); |
---|
| 201 | effect2->setLifetime(4.0f); |
---|
[7163] | 202 | effect2->setSyncMode(0); |
---|
[3087] | 203 | |
---|
| 204 | this->explosion_->attach(effect); |
---|
| 205 | this->explosion_->attach(effect2); |
---|
| 206 | |
---|
| 207 | this->attach(explosion_); |
---|
| 208 | this->attach(debrisEntity1_); |
---|
| 209 | this->attach(debrisEntity2_); |
---|
| 210 | this->attach(debrisEntity3_); |
---|
| 211 | this->attach(debrisEntity4_); |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | for(int i=0;i<10;i++) |
---|
| 215 | { |
---|
[9667] | 216 | Model* part1 = new Model(this->getContext()); |
---|
| 217 | Model* part2 = new Model(this->getContext()); |
---|
[3087] | 218 | |
---|
[9667] | 219 | MovableEntity* partEntity1 = new MovableEntity(this->getContext()); |
---|
| 220 | MovableEntity* partEntity2 = new MovableEntity(this->getContext()); |
---|
[7176] | 221 | |
---|
[7163] | 222 | part1->setSyncMode(0); |
---|
| 223 | part2->setSyncMode(0); |
---|
| 224 | partEntity1->setSyncMode(0); |
---|
| 225 | partEntity2->setSyncMode(0); |
---|
[3087] | 226 | |
---|
| 227 | partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100)); |
---|
| 228 | partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 229 | partEntity1->setScale(rnd(1, 3)); |
---|
| 230 | |
---|
| 231 | partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100)); |
---|
| 232 | partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 233 | partEntity2->setScale(rnd(1, 3)); |
---|
| 234 | |
---|
| 235 | part1->setMeshSource("SmallPart1.mesh"); |
---|
| 236 | part2->setMeshSource("SmallPart2.mesh"); |
---|
| 237 | |
---|
| 238 | partEntity1->attach(part1); |
---|
| 239 | partEntity2->attach(part2); |
---|
| 240 | |
---|
| 241 | this->attach(partEntity1); |
---|
| 242 | this->attach(partEntity2); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | void BigExplosion::initZero() |
---|
| 247 | { |
---|
| 248 | this->debrisFire1_ = 0; |
---|
| 249 | this->debrisFire2_ = 0; |
---|
| 250 | this->debrisFire3_ = 0; |
---|
| 251 | this->debrisFire4_ = 0; |
---|
| 252 | |
---|
| 253 | this->debrisSmoke1_ = 0; |
---|
| 254 | this->debrisSmoke2_ = 0; |
---|
| 255 | this->debrisSmoke3_ = 0; |
---|
| 256 | this->debrisSmoke4_ = 0; |
---|
| 257 | |
---|
| 258 | this->explosionSmoke_=0; |
---|
| 259 | this->explosionFire_=0; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | BigExplosion::~BigExplosion() |
---|
| 263 | { |
---|
| 264 | if (this->isInitialized()) |
---|
| 265 | { |
---|
| 266 | if (this->debrisFire1_) |
---|
| 267 | { |
---|
| 268 | this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
[9667] | 269 | delete this->debrisFire1_; |
---|
[3087] | 270 | } |
---|
| 271 | if (this->debrisSmoke1_) |
---|
| 272 | { |
---|
| 273 | this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
[9667] | 274 | delete this->debrisSmoke1_; |
---|
[3087] | 275 | } |
---|
| 276 | |
---|
| 277 | if (this->debrisFire2_) |
---|
| 278 | { |
---|
| 279 | this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
[9667] | 280 | delete this->debrisFire2_; |
---|
[3087] | 281 | } |
---|
| 282 | if (this->debrisSmoke2_) |
---|
| 283 | { |
---|
| 284 | this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
[9667] | 285 | delete this->debrisSmoke2_; |
---|
[3087] | 286 | } |
---|
| 287 | |
---|
| 288 | if (this->debrisFire3_) |
---|
| 289 | { |
---|
| 290 | this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
[9667] | 291 | delete this->debrisFire3_; |
---|
[3087] | 292 | } |
---|
| 293 | if (this->debrisSmoke3_) |
---|
| 294 | { |
---|
| 295 | this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
[9667] | 296 | delete this->debrisSmoke3_; |
---|
[3087] | 297 | } |
---|
| 298 | |
---|
| 299 | if (this->debrisFire4_) |
---|
| 300 | { |
---|
| 301 | this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
[9667] | 302 | delete this->debrisFire4_; |
---|
[3087] | 303 | } |
---|
| 304 | if (this->debrisSmoke4_) |
---|
| 305 | { |
---|
| 306 | this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
[9667] | 307 | delete this->debrisSmoke4_; |
---|
[3087] | 308 | } |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | void BigExplosion::registerVariables() |
---|
| 313 | { |
---|
[3280] | 314 | registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged)); |
---|
| 315 | registerVariable(this->bStop_, VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop)); |
---|
[3087] | 316 | } |
---|
| 317 | |
---|
| 318 | void BigExplosion::LODchanged() |
---|
| 319 | { |
---|
| 320 | if (this->debrisFire1_) |
---|
| 321 | this->debrisFire1_->setDetailLevel(this->LOD_); |
---|
| 322 | if (this->debrisSmoke1_) |
---|
| 323 | this->debrisSmoke1_->setDetailLevel(this->LOD_); |
---|
| 324 | |
---|
| 325 | if (this->debrisFire2_) |
---|
| 326 | this->debrisFire2_->setDetailLevel(this->LOD_); |
---|
| 327 | if (this->debrisSmoke2_) |
---|
| 328 | this->debrisSmoke2_->setDetailLevel(this->LOD_); |
---|
| 329 | |
---|
| 330 | if (this->debrisFire3_) |
---|
| 331 | this->debrisFire3_->setDetailLevel(this->LOD_); |
---|
| 332 | if (this->debrisSmoke3_) |
---|
| 333 | this->debrisSmoke3_->setDetailLevel(this->LOD_); |
---|
| 334 | |
---|
| 335 | if (this->debrisFire4_) |
---|
| 336 | this->debrisFire4_->setDetailLevel(this->LOD_); |
---|
| 337 | if (this->debrisSmoke4_) |
---|
| 338 | this->debrisSmoke4_->setDetailLevel(this->LOD_); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | void BigExplosion::checkStop() |
---|
| 342 | { |
---|
| 343 | if (this->bStop_) |
---|
| 344 | this->stop(); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | void BigExplosion::stop() |
---|
| 348 | { |
---|
| 349 | if (this->debrisFire1_) |
---|
| 350 | this->debrisFire1_->setEnabled(false); |
---|
| 351 | if (this->debrisSmoke1_) |
---|
| 352 | this->debrisSmoke1_->setEnabled(false); |
---|
| 353 | |
---|
| 354 | if (this->debrisFire2_) |
---|
| 355 | this->debrisFire2_->setEnabled(false); |
---|
| 356 | if (this->debrisSmoke2_) |
---|
| 357 | this->debrisSmoke2_->setEnabled(false); |
---|
| 358 | |
---|
| 359 | if (this->debrisFire3_) |
---|
| 360 | this->debrisFire3_->setEnabled(false); |
---|
| 361 | if (this->debrisSmoke3_) |
---|
| 362 | this->debrisSmoke3_->setEnabled(false); |
---|
| 363 | |
---|
| 364 | if (this->debrisFire4_) |
---|
| 365 | this->debrisFire4_->setEnabled(false); |
---|
| 366 | if (this->debrisSmoke4_) |
---|
| 367 | this->debrisSmoke4_->setEnabled(false); |
---|
| 368 | |
---|
| 369 | if (GameMode::isMaster()) |
---|
| 370 | { |
---|
| 371 | this->bStop_ = true; |
---|
[5929] | 372 | this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this))); |
---|
[3087] | 373 | } |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | /* TODO |
---|
| 377 | |
---|
| 378 | void BigExplosion::setDebrisMeshes() |
---|
| 379 | { |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | void BigExplosion::getDebrisMeshes() |
---|
| 383 | { |
---|
| 384 | |
---|
| 385 | } |
---|
| 386 | */ |
---|
| 387 | } |
---|