/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Vedat Aydin * Co-authors: * ... * */ #include "ExplosionPart.h" #include "core/XMLPort.h" namespace orxonox { RegisterClass(ExplosionPart); ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context) { RegisterObject(ExplosionPart); this->bStop_ = false; this->LOD_ = LODParticle::Normal; this->mesh_ = ""; this->effect1_ = ""; this->effect2_ = ""; this->model_= new Model(this->getContext()); this->effect1Particle_= NULL; this->effect2Particle_= NULL; this->explosionEntity_ = new MovableEntity(this->getContext()); } ExplosionPart::~ExplosionPart() { if (this->isInitialized()) { if (this->effect1Particle_) { this->model_->detachOgreObject(this->effect1Particle_->getParticleSystem()); delete this->effect1Particle_; } if (this->effect2Particle_) { this->model_->detachOgreObject(this->effect2Particle_->getParticleSystem()); delete this->effect2Particle_; } } } void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(ExplosionPart, XMLPort, xmlelement, mode); XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues(""); XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50); XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100); XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues(""); XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues(""); } void ExplosionPart::Explode() { orxout() << "Explode" << endl; this->model_->setVisible(true); //this->explosionEntity_->setSyncMode(0); //this->model_->setSyncMode(0); if(effect1_ != "") { this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_); this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem()); } if(effect2_ != "") { this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_); this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem()); } this->explosionEntity_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(minSpeed_,maxSpeed_)); this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); this->explosionEntity_->setScale(4); this->explosionEntity_->attach(model_); this->attach(explosionEntity_); if (GameMode::isMaster()) { this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this))); } } void ExplosionPart::stop() { if (this->effect1Particle_) this->effect1Particle_->setEnabled(false); if (this->effect2Particle_) this->effect2Particle_->setEnabled(false); if (this->model_) this->model_->setVisible(false); if (GameMode::isMaster()) { this->bStop_ = true; this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this))); } } void ExplosionPart::setMesh(const std::string& newString) { if(newString != "") { this->mesh_ = newString; this->model_->setMeshSource(mesh_); this->model_->setVisible(false); } } void ExplosionPart::setEffect1(const std::string& newString) { this->effect1_ = newString; } void ExplosionPart::setEffect2(const std::string& newString) { this->effect2_ = newString; } void ExplosionPart::setMinSpeed(float speed) { this->minSpeed_ = speed; } void ExplosionPart::setMaxSpeed(float speed) { this->maxSpeed_ = speed; } std::string& ExplosionPart::getMesh() { return this->mesh_; } std::string& ExplosionPart::getEffect1() { return this->effect1_; } std::string& ExplosionPart::getEffect2() { return this->effect2_; } float ExplosionPart::getMinSpeed() { return this->minSpeed_; } float ExplosionPart::getMaxSpeed() { return this->maxSpeed_; } }