/* * 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: * Hagen Seifert * Co-authors: * simonmie * */ /** @file HsW01.h @brief Implementation of the HsW01 class. */ #include "BallGun.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "core/command/Executor.h" #include "graphics/Model.h" #include "weaponsystem/Weapon.h" #include "weaponsystem/WeaponPack.h" #include "weaponsystem/WeaponSystem.h" #include "worldentities/WorldEntity.h" #include "worldentities/pawns/Pawn.h" #include "weapons/projectiles/Projectile.h" #include "weapons/MuzzleFlash.h" #include "weapons/projectiles/BallProjectile.h" namespace orxonox { RegisterClass(BallGun); BallGun::BallGun(Context* context) : WeaponMode(context) { RegisterObject(BallGun); this->reloadTime_ = 0.25f; this->damage_ = 0.0f; //default 15 this->speed_ = 750.0f; this->delay_ = 0.0f; this->setMunitionName("BallMunition"); this->mesh_ = "laserbeam.mesh"; this->delayTimer_.setTimer(this->delay_, false, createExecutor(createFunctor(&BallGun::shot, this))); this->delayTimer_.stopTimer(); this->setFireSound("sounds/Weapon_HsW01.ogg"); this->setReloadSound("sounds/Reload_HsW01.ogg", 0.5); hudImageString_ = "Orxonox/WSHUD_WM_HsW01"; } BallGun::~BallGun() { } void BallGun::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(BallGun, XMLPort, xmlelement, mode); XMLPortParam(BallGun, "delay", setDelay, getDelay, xmlelement, mode); XMLPortParam(BallGun, "material", setMaterial, getMaterial, xmlelement, mode); XMLPortParam(BallGun, "projectileMesh", setMesh, getMesh, xmlelement, mode); XMLPortParam(BallGun, "sound", setSound, getSound, xmlelement, mode); } /** @brief Set the firing delay. @param delay The firing delay in seconds. */ void BallGun::setDelay(float delay) { orxout() << "delay" << endl; this->delay_ = delay; this->delayTimer_.setInterval(this->delay_); } void BallGun::fire() { orxout() << "fire" << endl; this->delayTimer_.startTimer(); } /** @brief Fires the weapon. Creates a projectile and fires it. */ void BallGun::shot() { assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); orxout() << "SHOT!" << endl; // Create the projectile. Projectile* projectile = new BallProjectile(this->getContext()); Model* model = new Model(projectile->getContext()); model->setMeshSource(mesh_); model->setCastShadows(false); projectile->attach(model); model->setScale(5); this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition()); projectile->setOrientation(this->getMuzzleOrientation()); projectile->setPosition(this->getMuzzlePosition()); projectile->setVelocity(this->getMuzzleDirection() * this->speed_); projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); projectile->setDamage(this->getDamage()); projectile->setShieldDamage(this->getShieldDamage()); projectile->setHealthDamage(this->getHealthDamage()); // Display the muzzle flash. this->BallGun::muzzleflash(); } /** @brief Displays the muzzle flash. */ void BallGun::muzzleflash() { MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext()); this->getWeapon()->attach(muzzleFlash); muzzleFlash->setPosition(this->getMuzzleOffset()); muzzleFlash->setMaterial(this->material_); } }