/* * 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: * Fabien Vultier * Co-authors: * ... * */ /** @file MineProjectile.h @brief Implementation of the MineProjectile class. */ #include "MineProjectile.h" #include "core/CoreIncludes.h" #include "core/command/Executor.h" #include "core/EventIncludes.h" #include "graphics/Model.h" namespace orxonox { RegisterClass(MineProjectile); MineProjectile::MineProjectile(Context* context) : MovableEntity(context), BasicProjectile() { RegisterObject(MineProjectile); this->bActive_ = false; this->maxTimeUntilExplosion_ = 10.0f; this->timeUntilActivation_ = 1.0f; rings_ = new MovableEntity(this->getContext()); this->attach(rings_); rings_->setPosition(Vector3(0.0,0.0,0.0)); rings_->setAngularVelocity(Vector3(0.0,5.0,0.0)); modelCore_ = new Model(this->getContext()); modelCore_->setMeshSource("Mine_Core.mesh"); modelCore_->setScale(15.0); this->attach(modelCore_); modelCore_->setPosition(Vector3(0,0,0)); modelRing1_ = new Model(this->getContext()); modelRing1_->setMeshSource("Mine_Ring.mesh"); modelRing1_->setScale(15.0); rings_->attach(modelRing1_); modelRing1_->setPosition(Vector3(0,0,0)); modelRing1_->yaw(Degree(0)); modelRing2_ = new Model(this->getContext()); modelRing2_->setMeshSource("Mine_Ring.mesh"); modelRing2_->setScale(15.0); rings_->attach(modelRing2_); modelRing2_->setPosition(Vector3(0,0,0)); modelRing2_->yaw(Degree(180)); if (GameMode::isMaster()) { this->setMass(10.0f); this->setFriction(100.0f); this->enableCollisionCallback(); this->setCollisionResponse(false); this->setCollisionType(Dynamic); // Create a sphere collision shape and attach it to the projectile. collisionShape_ = new SphereCollisionShape(this->getContext()); collisionShape_->setRadius(10.0f); this->attachCollisionShape(collisionShape_); // Create a distance trigger and attach it to the projectile. distanceTrigger_ = new DistanceTrigger(this->getContext()); this->attach(distanceTrigger_); distanceTrigger_->setPosition(Vector3(0,0,0)); distanceTrigger_->setDistance(40.0f); distanceTrigger_->addTarget("Pawn"); distanceTrigger_->setStayActive(true); this->addEventSource(distanceTrigger_, "explode"); } } MineProjectile::~MineProjectile() { if (this->isInitialized()) { /*if (modelCore_ != NULL) { modelCore_->destroy(); }*/ if (distanceTrigger_) distanceTrigger_->destroy(); } } void MineProjectile::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(MineProjectile, XMLEventPort, xmlelement, mode); XMLPortEventState(MineProjectile, BaseObject, "explode", Explode, xmlelement, mode); } /** @brief TODO */ void MineProjectile::setMaxTimeUntilExplosion(float maxTimeUntilExplosion) { if (maxTimeUntilExplosion >= 0) { this->maxTimeUntilExplosion_ = maxTimeUntilExplosion; if (GameMode::isMaster()) { this->explodeTimer_.setTimer(this->maxTimeUntilExplosion_, false, createExecutor(createFunctor(&MineProjectile::Explode, this))); } } else { this->maxTimeUntilExplosion_ = 0; } } /** @brief TODO */ void MineProjectile::setTimeUntilActivation(float timeUntilActivation) { timeUntilActivation_ = timeUntilActivation; if (GameMode::isMaster()) { this->activationTimer_.setTimer(this->timeUntilActivation_, false, createExecutor(createFunctor(&MineProjectile::Activate, this))); } } /** @brief TODO */ void MineProjectile::Explode() { orxout() << "MineProjectile::Explode" << endl; this->destroyLater(); } /** @brief TODO */ void MineProjectile::Activate() { orxout() << "MineProjectile::Activate" << endl; bActive_ = true; } }