[2049] | 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 | * Martin Polak |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
| 32 | #include "core/XMLPort.h" |
---|
| 33 | #include "util/Debug.h" |
---|
| 34 | |
---|
[2096] | 35 | #include "Weapon.h" |
---|
| 36 | |
---|
[2049] | 37 | namespace orxonox |
---|
| 38 | { |
---|
[2327] | 39 | CreateFactory(Weapon); |
---|
| 40 | |
---|
[2097] | 41 | Weapon::Weapon(BaseObject* creator) : BaseObject(creator) |
---|
[2049] | 42 | { |
---|
| 43 | RegisterObject(Weapon); |
---|
[2232] | 44 | this->bulletReadyToShoot_ = true; |
---|
| 45 | this->magazineReadyToShoot_ = true; |
---|
[2337] | 46 | this->parentWeaponSystem_ = 0; |
---|
| 47 | this->parentWeaponSlot_ = 0; |
---|
| 48 | this->munition_ = 0; |
---|
[2049] | 49 | } |
---|
| 50 | |
---|
| 51 | Weapon::~Weapon() |
---|
| 52 | { |
---|
| 53 | } |
---|
[2096] | 54 | |
---|
[2145] | 55 | |
---|
| 56 | void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[2096] | 57 | { |
---|
[2232] | 58 | SUPER(Weapon, XMLPort, xmlelement, mode); |
---|
[2331] | 59 | XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); |
---|
[2049] | 60 | } |
---|
[2096] | 61 | |
---|
[2145] | 62 | void Weapon::fire() |
---|
[2096] | 63 | { |
---|
| 64 | |
---|
| 65 | } |
---|
[2232] | 66 | |
---|
| 67 | |
---|
| 68 | void Weapon::bulletTimer() |
---|
[2203] | 69 | { |
---|
[2232] | 70 | this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); |
---|
[2203] | 71 | } |
---|
[2232] | 72 | void Weapon::magazineTimer() |
---|
[2097] | 73 | { |
---|
[2232] | 74 | this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); |
---|
[2145] | 75 | } |
---|
[2097] | 76 | |
---|
[2232] | 77 | void Weapon::bulletReloaded() |
---|
| 78 | { this->bulletReadyToShoot_ = true; } |
---|
| 79 | |
---|
| 80 | void Weapon::magazineReloaded() |
---|
| 81 | { this->magazineReadyToShoot_ = true; } |
---|
| 82 | |
---|
| 83 | |
---|
[2203] | 84 | void Weapon::attachNeededMunition(std::string munitionName) |
---|
[2145] | 85 | { |
---|
[2232] | 86 | //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem |
---|
[2331] | 87 | if (this->parentWeaponSystem_) |
---|
[2186] | 88 | { |
---|
[2331] | 89 | Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); |
---|
| 90 | if ( munition ) |
---|
| 91 | this->munition_ = munition; |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | //create new munition with identifier |
---|
[2337] | 95 | COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; |
---|
[2331] | 96 | this->munitionIdentifier_ = ClassByString(munitionName); |
---|
| 97 | this->munition_ = this->munitionIdentifier_.fabricate(this); |
---|
| 98 | this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); |
---|
| 99 | } |
---|
[2186] | 100 | } |
---|
[2097] | 101 | } |
---|
[2186] | 102 | |
---|
[2203] | 103 | |
---|
| 104 | /*get and set functions |
---|
| 105 | * |
---|
| 106 | */ |
---|
[2331] | 107 | |
---|
| 108 | void Weapon::setMunitionType(std::string munitionType) |
---|
[2347] | 109 | { |
---|
| 110 | COUT(0) << "Weapon::setMunitionType (XMLPort) "<< munitionType << std::endl; |
---|
| 111 | this->munitionType_ = munitionType; } |
---|
[2331] | 112 | |
---|
[2354] | 113 | const std::string Weapon::getMunitionType() |
---|
[2331] | 114 | { return this->munitionType_; } |
---|
| 115 | |
---|
[2337] | 116 | Munition * Weapon::getAttachedMunition(std::string munitionType) |
---|
| 117 | { |
---|
[2354] | 118 | COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; |
---|
| 119 | this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); |
---|
[2337] | 120 | COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; |
---|
| 121 | return this->munition_; } |
---|
[2203] | 122 | |
---|
[2232] | 123 | void Weapon::setBulletLoadingTime(float loadingTime) |
---|
| 124 | { this->bulletLoadingTime_ = loadingTime; } |
---|
[2203] | 125 | |
---|
[2232] | 126 | float Weapon::getBulletLoadingTime() |
---|
| 127 | { return this->bulletLoadingTime_; } |
---|
[2203] | 128 | |
---|
[2232] | 129 | void Weapon::setMagazineLoadingTime(float loadingTime) |
---|
| 130 | { this->magazineLoadingTime_ = loadingTime; } |
---|
[2203] | 131 | |
---|
[2232] | 132 | float Weapon::getMagazineLoadingTime() |
---|
| 133 | { return this->magazineLoadingTime_; } |
---|
| 134 | |
---|
| 135 | void Weapon::setBulletReadyToShoot(bool b) |
---|
| 136 | { this->bulletReadyToShoot_ = b; } |
---|
| 137 | |
---|
| 138 | bool Weapon::getBulletReadyToShoot() |
---|
| 139 | { return this->bulletReadyToShoot_; } |
---|
| 140 | |
---|
| 141 | void Weapon::setMagazineReadyToShoot(bool b) |
---|
| 142 | { this->magazineReadyToShoot_ = b; } |
---|
| 143 | |
---|
| 144 | bool Weapon::getMagazineReadyToShoot() |
---|
| 145 | { return this->magazineReadyToShoot_; } |
---|
| 146 | |
---|
| 147 | Timer<Weapon> * Weapon::getBulletTimer() |
---|
| 148 | { return &this->bulletReloadTimer_; } |
---|
| 149 | |
---|
| 150 | Timer<Weapon> * Weapon::getMagazineTimer() |
---|
| 151 | { return &this->magazineReloadTimer_; } |
---|
[2096] | 152 | } |
---|