[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 | |
---|
[9939] | 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 | |
---|
| 80 | void BigExplosion::init() |
---|
| 81 | { |
---|
[10669] | 82 | |
---|
| 83 | orxout() << "BigExplosion" << endl; |
---|
| 84 | |
---|
[9667] | 85 | this->debrisEntity1_ = new MovableEntity(this->getContext()); |
---|
| 86 | this->debrisEntity2_ = new MovableEntity(this->getContext()); |
---|
| 87 | this->debrisEntity3_ = new MovableEntity(this->getContext()); |
---|
| 88 | this->debrisEntity4_ = new MovableEntity(this->getContext()); |
---|
[7176] | 89 | |
---|
[7163] | 90 | this->debrisEntity1_->setSyncMode(0); |
---|
| 91 | this->debrisEntity2_->setSyncMode(0); |
---|
| 92 | this->debrisEntity3_->setSyncMode(0); |
---|
| 93 | this->debrisEntity4_->setSyncMode(0); |
---|
[3087] | 94 | |
---|
[9667] | 95 | this->debris1_ = new Model(this->getContext()); |
---|
| 96 | this->debris2_ = new Model(this->getContext()); |
---|
| 97 | this->debris3_ = new Model(this->getContext()); |
---|
| 98 | this->debris4_ = new Model(this->getContext()); |
---|
[7176] | 99 | |
---|
[7163] | 100 | this->debris1_->setSyncMode(0); |
---|
| 101 | this->debris2_->setSyncMode(0); |
---|
| 102 | this->debris3_->setSyncMode(0); |
---|
| 103 | this->debris4_->setSyncMode(0); |
---|
[3087] | 104 | |
---|
[9952] | 105 | this->explosion_ = new StaticEntity(this->getContext()); |
---|
[7163] | 106 | this->explosion_->setSyncMode(0); |
---|
[3087] | 107 | |
---|
| 108 | this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 109 | this->debrisSmoke2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 110 | this->debrisSmoke3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 111 | this->debrisSmoke4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); |
---|
| 112 | |
---|
| 113 | this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 114 | this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 115 | this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 116 | this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_); |
---|
| 117 | |
---|
| 118 | this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
| 119 | this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
| 120 | this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
| 121 | this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
| 122 | this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
| 123 | this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
| 124 | this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
| 125 | this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
| 126 | |
---|
| 127 | this->debris1_->setMeshSource("CockpitDebris.mesh"); |
---|
| 128 | this->debris2_->setMeshSource("WingDebris1.mesh"); |
---|
| 129 | this->debris3_->setMeshSource("BodyDebris1.mesh"); |
---|
| 130 | this->debris4_->setMeshSource("WingDebris2.mesh"); |
---|
| 131 | |
---|
| 132 | this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 133 | this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 134 | this->debrisEntity1_->setScale(4); |
---|
| 135 | |
---|
| 136 | this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 137 | this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 138 | this->debrisEntity2_->setScale(4); |
---|
| 139 | |
---|
| 140 | this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 141 | this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 142 | this->debrisEntity3_->setScale(4); |
---|
| 143 | |
---|
| 144 | this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100)); |
---|
| 145 | this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 146 | this->debrisEntity4_->setScale(4); |
---|
| 147 | |
---|
| 148 | this->debrisEntity1_->attach(debris1_); |
---|
| 149 | this->debrisEntity2_->attach(debris2_); |
---|
| 150 | this->debrisEntity3_->attach(debris3_); |
---|
| 151 | this->debrisEntity4_->attach(debris4_); |
---|
| 152 | |
---|
[9667] | 153 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[3087] | 154 | effect->setDestroyAfterLife(true); |
---|
| 155 | effect->setSource("Orxonox/explosion2b"); |
---|
| 156 | effect->setLifetime(4.0f); |
---|
[7163] | 157 | effect->setSyncMode(0); |
---|
[3087] | 158 | |
---|
[9667] | 159 | ParticleSpawner* effect2 = new ParticleSpawner(this->getContext()); |
---|
[3087] | 160 | effect2->setDestroyAfterLife(true); |
---|
| 161 | effect2->setSource("Orxonox/smoke6"); |
---|
| 162 | effect2->setLifetime(4.0f); |
---|
[7163] | 163 | effect2->setSyncMode(0); |
---|
[3087] | 164 | |
---|
| 165 | this->explosion_->attach(effect); |
---|
| 166 | this->explosion_->attach(effect2); |
---|
| 167 | |
---|
| 168 | this->attach(explosion_); |
---|
| 169 | this->attach(debrisEntity1_); |
---|
| 170 | this->attach(debrisEntity2_); |
---|
| 171 | this->attach(debrisEntity3_); |
---|
| 172 | this->attach(debrisEntity4_); |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | for(int i=0;i<10;i++) |
---|
| 176 | { |
---|
[9667] | 177 | Model* part1 = new Model(this->getContext()); |
---|
| 178 | Model* part2 = new Model(this->getContext()); |
---|
[3087] | 179 | |
---|
[9667] | 180 | MovableEntity* partEntity1 = new MovableEntity(this->getContext()); |
---|
| 181 | MovableEntity* partEntity2 = new MovableEntity(this->getContext()); |
---|
[7176] | 182 | |
---|
[7163] | 183 | part1->setSyncMode(0); |
---|
| 184 | part2->setSyncMode(0); |
---|
| 185 | partEntity1->setSyncMode(0); |
---|
| 186 | partEntity2->setSyncMode(0); |
---|
[3087] | 187 | |
---|
| 188 | partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100)); |
---|
| 189 | partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 190 | partEntity1->setScale(rnd(1, 3)); |
---|
| 191 | |
---|
| 192 | partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100)); |
---|
| 193 | partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
| 194 | partEntity2->setScale(rnd(1, 3)); |
---|
| 195 | |
---|
| 196 | part1->setMeshSource("SmallPart1.mesh"); |
---|
| 197 | part2->setMeshSource("SmallPart2.mesh"); |
---|
| 198 | |
---|
| 199 | partEntity1->attach(part1); |
---|
| 200 | partEntity2->attach(part2); |
---|
| 201 | |
---|
| 202 | this->attach(partEntity1); |
---|
| 203 | this->attach(partEntity2); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | void BigExplosion::initZero() |
---|
| 208 | { |
---|
| 209 | this->debrisFire1_ = 0; |
---|
| 210 | this->debrisFire2_ = 0; |
---|
| 211 | this->debrisFire3_ = 0; |
---|
| 212 | this->debrisFire4_ = 0; |
---|
| 213 | |
---|
| 214 | this->debrisSmoke1_ = 0; |
---|
| 215 | this->debrisSmoke2_ = 0; |
---|
| 216 | this->debrisSmoke3_ = 0; |
---|
| 217 | this->debrisSmoke4_ = 0; |
---|
| 218 | |
---|
| 219 | this->explosionSmoke_=0; |
---|
| 220 | this->explosionFire_=0; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | BigExplosion::~BigExplosion() |
---|
| 224 | { |
---|
| 225 | if (this->isInitialized()) |
---|
| 226 | { |
---|
| 227 | if (this->debrisFire1_) |
---|
| 228 | { |
---|
| 229 | this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem()); |
---|
[9667] | 230 | delete this->debrisFire1_; |
---|
[3087] | 231 | } |
---|
| 232 | if (this->debrisSmoke1_) |
---|
| 233 | { |
---|
| 234 | this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem()); |
---|
[9667] | 235 | delete this->debrisSmoke1_; |
---|
[3087] | 236 | } |
---|
| 237 | |
---|
| 238 | if (this->debrisFire2_) |
---|
| 239 | { |
---|
| 240 | this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem()); |
---|
[9667] | 241 | delete this->debrisFire2_; |
---|
[3087] | 242 | } |
---|
| 243 | if (this->debrisSmoke2_) |
---|
| 244 | { |
---|
| 245 | this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem()); |
---|
[9667] | 246 | delete this->debrisSmoke2_; |
---|
[3087] | 247 | } |
---|
| 248 | |
---|
| 249 | if (this->debrisFire3_) |
---|
| 250 | { |
---|
| 251 | this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem()); |
---|
[9667] | 252 | delete this->debrisFire3_; |
---|
[3087] | 253 | } |
---|
| 254 | if (this->debrisSmoke3_) |
---|
| 255 | { |
---|
| 256 | this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem()); |
---|
[9667] | 257 | delete this->debrisSmoke3_; |
---|
[3087] | 258 | } |
---|
| 259 | |
---|
| 260 | if (this->debrisFire4_) |
---|
| 261 | { |
---|
| 262 | this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem()); |
---|
[9667] | 263 | delete this->debrisFire4_; |
---|
[3087] | 264 | } |
---|
| 265 | if (this->debrisSmoke4_) |
---|
| 266 | { |
---|
| 267 | this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem()); |
---|
[9667] | 268 | delete this->debrisSmoke4_; |
---|
[3087] | 269 | } |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | void BigExplosion::registerVariables() |
---|
| 274 | { |
---|
[3280] | 275 | registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged)); |
---|
| 276 | registerVariable(this->bStop_, VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop)); |
---|
[3087] | 277 | } |
---|
| 278 | |
---|
| 279 | void BigExplosion::LODchanged() |
---|
| 280 | { |
---|
| 281 | if (this->debrisFire1_) |
---|
| 282 | this->debrisFire1_->setDetailLevel(this->LOD_); |
---|
| 283 | if (this->debrisSmoke1_) |
---|
| 284 | this->debrisSmoke1_->setDetailLevel(this->LOD_); |
---|
| 285 | |
---|
| 286 | if (this->debrisFire2_) |
---|
| 287 | this->debrisFire2_->setDetailLevel(this->LOD_); |
---|
| 288 | if (this->debrisSmoke2_) |
---|
| 289 | this->debrisSmoke2_->setDetailLevel(this->LOD_); |
---|
| 290 | |
---|
| 291 | if (this->debrisFire3_) |
---|
| 292 | this->debrisFire3_->setDetailLevel(this->LOD_); |
---|
| 293 | if (this->debrisSmoke3_) |
---|
| 294 | this->debrisSmoke3_->setDetailLevel(this->LOD_); |
---|
| 295 | |
---|
| 296 | if (this->debrisFire4_) |
---|
| 297 | this->debrisFire4_->setDetailLevel(this->LOD_); |
---|
| 298 | if (this->debrisSmoke4_) |
---|
| 299 | this->debrisSmoke4_->setDetailLevel(this->LOD_); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | void BigExplosion::checkStop() |
---|
| 303 | { |
---|
| 304 | if (this->bStop_) |
---|
| 305 | this->stop(); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | void BigExplosion::stop() |
---|
| 309 | { |
---|
| 310 | if (this->debrisFire1_) |
---|
| 311 | this->debrisFire1_->setEnabled(false); |
---|
| 312 | if (this->debrisSmoke1_) |
---|
| 313 | this->debrisSmoke1_->setEnabled(false); |
---|
| 314 | |
---|
| 315 | if (this->debrisFire2_) |
---|
| 316 | this->debrisFire2_->setEnabled(false); |
---|
| 317 | if (this->debrisSmoke2_) |
---|
| 318 | this->debrisSmoke2_->setEnabled(false); |
---|
| 319 | |
---|
| 320 | if (this->debrisFire3_) |
---|
| 321 | this->debrisFire3_->setEnabled(false); |
---|
| 322 | if (this->debrisSmoke3_) |
---|
| 323 | this->debrisSmoke3_->setEnabled(false); |
---|
| 324 | |
---|
| 325 | if (this->debrisFire4_) |
---|
| 326 | this->debrisFire4_->setEnabled(false); |
---|
| 327 | if (this->debrisSmoke4_) |
---|
| 328 | this->debrisSmoke4_->setEnabled(false); |
---|
| 329 | |
---|
| 330 | if (GameMode::isMaster()) |
---|
| 331 | { |
---|
| 332 | this->bStop_ = true; |
---|
[5929] | 333 | this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this))); |
---|
[3087] | 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | /* TODO |
---|
| 338 | |
---|
| 339 | void BigExplosion::setDebrisMeshes() |
---|
| 340 | { |
---|
| 341 | |
---|
| 342 | } |
---|
| 343 | void BigExplosion::getDebrisMeshes() |
---|
| 344 | { |
---|
| 345 | |
---|
| 346 | } |
---|
| 347 | */ |
---|
| 348 | } |
---|