[12129] | 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 | |
---|
| 23 | * The WagnisGun, WagnisProjectile and WagnisCursor was made to be used as a "cursor", by fireing invisible projectiles at an object. |
---|
| 24 | * You can then monitor the Objects HP in order to know which one has been hit (=clicked). And yes, it isn't a very beautiful solution. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include "WagnisGun.h" |
---|
| 28 | |
---|
| 29 | #include "core/CoreIncludes.h" |
---|
| 30 | #include "core/XMLPort.h" |
---|
| 31 | #include "core/command/Executor.h" |
---|
| 32 | |
---|
| 33 | #include "graphics/Model.h" |
---|
| 34 | #include "weaponsystem/Weapon.h" |
---|
| 35 | #include "weaponsystem/WeaponPack.h" |
---|
| 36 | #include "weaponsystem/WeaponSystem.h" |
---|
| 37 | #include "worldentities/WorldEntity.h" |
---|
| 38 | #include "worldentities/pawns/Pawn.h" |
---|
| 39 | |
---|
| 40 | #include "weapons/projectiles/WagnisProjectile.h" |
---|
| 41 | #include "weapons/MuzzleFlash.h" |
---|
| 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | RegisterClass(WagnisGun); |
---|
| 46 | |
---|
| 47 | WagnisGun::WagnisGun(Context* context) : WeaponMode(context) |
---|
| 48 | { |
---|
| 49 | RegisterObject(WagnisGun); |
---|
| 50 | |
---|
[12169] | 51 | this->reloadTime_ = 0.5f; |
---|
[12129] | 52 | this->damage_ = 0.0f; //default 15 |
---|
[12136] | 53 | this->speed_ = 800.0f; |
---|
[12129] | 54 | this->delay_ = 0.0f; |
---|
| 55 | this->setMunitionName("LaserMunition"); |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | this->delayTimer_.setTimer(this->delay_, false, createExecutor(createFunctor(&WagnisGun::shot, this))); |
---|
| 60 | this->delayTimer_.stopTimer(); |
---|
| 61 | hudImageString_ = "Orxonox/WSHUD_WM_HsW01"; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | WagnisGun::~WagnisGun() |
---|
| 65 | { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void WagnisGun::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 69 | { |
---|
| 70 | SUPER(WagnisGun, XMLPort, xmlelement, mode); |
---|
| 71 | |
---|
| 72 | XMLPortParam(WagnisGun, "delay", setDelay, getDelay, xmlelement, mode); |
---|
| 73 | XMLPortParam(WagnisGun, "material", setMaterial, getMaterial, xmlelement, mode); |
---|
| 74 | XMLPortParam(WagnisGun, "projectileMesh", setMesh, getMesh, xmlelement, mode); |
---|
| 75 | XMLPortParam(WagnisGun, "sound", setSound, getSound, xmlelement, mode); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | @brief |
---|
| 80 | Set the firing delay. |
---|
| 81 | @param delay |
---|
| 82 | The firing delay in seconds. |
---|
| 83 | */ |
---|
| 84 | void WagnisGun::setDelay(float delay) |
---|
| 85 | { |
---|
| 86 | this->delay_ = delay; |
---|
| 87 | this->delayTimer_.setInterval(this->delay_); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void WagnisGun::fire() |
---|
| 91 | { |
---|
| 92 | this->delayTimer_.startTimer(); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | @brief |
---|
| 97 | Fires the weapon. Creates a projectile and fires it. |
---|
| 98 | */ |
---|
| 99 | void WagnisGun::shot() |
---|
| 100 | { |
---|
| 101 | assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); |
---|
| 102 | |
---|
| 103 | // Create the projectile. |
---|
| 104 | WagnisProjectile* projectile = new WagnisProjectile(this->getContext()); |
---|
| 105 | |
---|
| 106 | this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition()); |
---|
| 107 | projectile->setOrientation(this->getMuzzleOrientation()); |
---|
| 108 | projectile->setPosition(this->getMuzzlePosition()); |
---|
| 109 | projectile->setVelocity(this->getMuzzleDirection() * this->speed_); |
---|
| 110 | |
---|
| 111 | projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); |
---|
| 112 | projectile->setDamage(this->getDamage()); |
---|
| 113 | projectile->setShieldDamage(this->getShieldDamage()); |
---|
| 114 | projectile->setHealthDamage(this->getHealthDamage()); |
---|
| 115 | } |
---|
| 116 | } |
---|