[3053] | 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 | * Hagen Seifert |
---|
| 24 | * Co-authors: |
---|
[8706] | 25 | * simonmie |
---|
[3053] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[8855] | 29 | /** |
---|
| 30 | @file HsW01.h |
---|
| 31 | @brief Implementation of the HsW01 class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[3053] | 34 | #include "HsW01.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
[7284] | 38 | #include "core/command/Executor.h" |
---|
[8855] | 39 | |
---|
[5737] | 40 | #include "graphics/Model.h" |
---|
[5735] | 41 | #include "weaponsystem/Weapon.h" |
---|
| 42 | #include "weaponsystem/WeaponPack.h" |
---|
| 43 | #include "weaponsystem/WeaponSystem.h" |
---|
[6417] | 44 | #include "worldentities/WorldEntity.h" |
---|
| 45 | #include "worldentities/pawns/Pawn.h" |
---|
[3053] | 46 | |
---|
[8855] | 47 | #include "weapons/projectiles/Projectile.h" |
---|
| 48 | #include "weapons/MuzzleFlash.h" |
---|
| 49 | |
---|
[3053] | 50 | namespace orxonox |
---|
| 51 | { |
---|
[9667] | 52 | RegisterClass(HsW01); |
---|
[3053] | 53 | |
---|
[9667] | 54 | HsW01::HsW01(Context* context) : WeaponMode(context) |
---|
[3053] | 55 | { |
---|
| 56 | RegisterObject(HsW01); |
---|
| 57 | |
---|
[8855] | 58 | this->reloadTime_ = 0.25f; |
---|
| 59 | this->damage_ = 0.0f; //default 15 |
---|
[10294] | 60 | this->speed_ = 750.0f; |
---|
[8855] | 61 | this->delay_ = 0.0f; |
---|
[3053] | 62 | this->setMunitionName("LaserMunition"); |
---|
[9526] | 63 | this->mesh_ = "laserbeam.mesh"; |
---|
[3053] | 64 | |
---|
[9526] | 65 | |
---|
[10290] | 66 | this->delayTimer_.setTimer(this->delay_, false, createExecutor(createFunctor(&HsW01::shot, this))); |
---|
[3053] | 67 | this->delayTimer_.stopTimer(); |
---|
[6417] | 68 | |
---|
[11108] | 69 | this->setFireSound("sounds/Weapon_HsW01.ogg"); |
---|
| 70 | this->setReloadSound("sounds/Reload_HsW01.ogg", 0.5); |
---|
[11052] | 71 | |
---|
| 72 | hudImageString_ = "Orxonox/WSHUD_WM_HsW01"; |
---|
[3053] | 73 | } |
---|
| 74 | |
---|
[6417] | 75 | HsW01::~HsW01() |
---|
| 76 | { |
---|
| 77 | } |
---|
| 78 | |
---|
[3053] | 79 | void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 80 | { |
---|
| 81 | SUPER(HsW01, XMLPort, xmlelement, mode); |
---|
| 82 | |
---|
| 83 | XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode); |
---|
| 84 | XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode); |
---|
[9526] | 85 | XMLPortParam(HsW01, "projectileMesh", setMesh, getMesh, xmlelement, mode); |
---|
[9945] | 86 | XMLPortParam(HsW01, "sound", setSound, getSound, xmlelement, mode); |
---|
[11493] | 87 | XMLPortParam(HsW01, "speed", setSpeed, getSpeed, xmlelement, mode); |
---|
[3053] | 88 | } |
---|
| 89 | |
---|
[8855] | 90 | /** |
---|
| 91 | @brief |
---|
| 92 | Set the firing delay. |
---|
| 93 | @param delay |
---|
| 94 | The firing delay in seconds. |
---|
| 95 | */ |
---|
| 96 | void HsW01::setDelay(float delay) |
---|
[3053] | 97 | { |
---|
[8855] | 98 | this->delay_ = delay; |
---|
[3053] | 99 | this->delayTimer_.setInterval(this->delay_); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void HsW01::fire() |
---|
| 103 | { |
---|
| 104 | this->delayTimer_.startTimer(); |
---|
| 105 | } |
---|
| 106 | |
---|
[8855] | 107 | /** |
---|
| 108 | @brief |
---|
| 109 | Fires the weapon. Creates a projectile and fires it. |
---|
| 110 | */ |
---|
[3053] | 111 | void HsW01::shot() |
---|
| 112 | { |
---|
[6417] | 113 | assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); |
---|
[8855] | 114 | |
---|
| 115 | // Create the projectile. |
---|
[9667] | 116 | Projectile* projectile = new Projectile(this->getContext()); |
---|
| 117 | Model* model = new Model(projectile->getContext()); |
---|
[9526] | 118 | model->setMeshSource(mesh_); |
---|
[3053] | 119 | model->setCastShadows(false); |
---|
| 120 | projectile->attach(model); |
---|
| 121 | model->setScale(5); |
---|
| 122 | |
---|
[6417] | 123 | this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition()); |
---|
[3053] | 124 | projectile->setOrientation(this->getMuzzleOrientation()); |
---|
| 125 | projectile->setPosition(this->getMuzzlePosition()); |
---|
[10296] | 126 | projectile->setVelocity(this->getMuzzleDirection() * this->speed_); |
---|
[3053] | 127 | |
---|
[8855] | 128 | projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); |
---|
[3053] | 129 | projectile->setDamage(this->getDamage()); |
---|
[8706] | 130 | projectile->setShieldDamage(this->getShieldDamage()); |
---|
| 131 | projectile->setHealthDamage(this->getHealthDamage()); |
---|
[3053] | 132 | |
---|
[8855] | 133 | // Display the muzzle flash. |
---|
| 134 | this->HsW01::muzzleflash(); |
---|
[3053] | 135 | } |
---|
[8855] | 136 | |
---|
| 137 | /** |
---|
| 138 | @brief |
---|
| 139 | Displays the muzzle flash. |
---|
| 140 | */ |
---|
| 141 | void HsW01::muzzleflash() |
---|
| 142 | { |
---|
[9667] | 143 | MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext()); |
---|
[8855] | 144 | this->getWeapon()->attach(muzzleFlash); |
---|
| 145 | muzzleFlash->setPosition(this->getMuzzleOffset()); |
---|
| 146 | muzzleFlash->setMaterial(this->material_); |
---|
| 147 | } |
---|
[3053] | 148 | } |
---|