- Timestamp:
- Mar 19, 2009, 4:55:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
r2778 r2804 42 42 { 43 43 RegisterObject(Weapon); 44 44 45 this->bulletReadyToShoot_ = true; 45 46 this->magazineReadyToShoot_ = true; 46 47 this->parentWeaponSystem_ = 0; 47 48 this->attachedToWeaponSlot_ = 0; 48 this->munition_ = 0;49 49 this->bulletLoadingTime_ = 0; 50 50 this->magazineLoadingTime_ = 0; 51 51 this->bReloading_ = false; 52 52 this->bulletAmount_= 0; 53 this->magazineAmount_ = 0; 54 this->munition_ = 0; 55 this->unlimitedMunition_ = false; 53 56 this->setObjectMode(0x0); 54 57 } … … 66 69 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 67 70 XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode); 71 XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode); 72 XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode); 73 XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode); 68 74 } 69 75 … … 74 80 } 75 81 82 void Weapon::setMunition() 83 { 84 this->munition_->setMaxBullets(this->bulletAmount_); 85 this->munition_->setMaxMagazines(this->magazineAmount_); 86 } 76 87 77 88 void Weapon::fire() 78 89 { 79 //COUT(0) << "LaserGun::fire, this=" << this<< std::endl;90 COUT(0) << "Weapon::fire" << std::endl; 80 91 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 81 92 { 82 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 83 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl; 93 COUT(0) << "Weapon::fire 2" << std::endl; 84 94 this->bulletReadyToShoot_ = false; 85 if ( this->munition_->bullets() > 0) 86 { 95 if ( this->unlimitedMunition_== true ) 96 { 97 COUT(0) << "Weapon::fire 3" << std::endl; 87 98 //shoot 88 this-> takeBullets();99 this->reloadBullet(); 89 100 this->createProjectile(); 90 101 } 91 //if there are no bullets, but magazines92 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )93 {94 //COUT(0) << "LaserGun::fire - no bullets" << std::endl;95 this->takeMagazines();96 }97 102 else 98 103 { 99 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 100 //no magazines 104 COUT(0) << "Weapon::fire 4" << std::endl; 105 if ( this->munition_->bullets() > 0) 106 { 107 COUT(0) << "Weapon::fire 5" << std::endl; 108 //shoot 109 this->takeBullets(); 110 this->reloadBullet(); 111 this->createProjectile(); 112 } 113 //if there are no bullets, but magazines 114 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 115 { 116 COUT(0) << "Weapon::fire 6" << std::endl; 117 this->takeMagazines(); 118 this->reloadMagazine(); 119 } 120 else 121 { 122 //no magazines 123 } 101 124 } 102 125 } 103 126 else 104 127 { 105 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets()<< std::endl;128 COUT(0) << "Weapon::fire not reloaded" << std::endl; 106 129 //weapon not reloaded 107 130 } … … 109 132 } 110 133 111 134 /* 135 * weapon reloading 136 */ 112 137 void Weapon::bulletTimer(float bulletLoadingTime) 113 138 { 114 //COUT(0) << "Weapon::bulletTimer started" << std::endl;115 139 this->bReloading_ = true; 116 140 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); … … 118 142 void Weapon::magazineTimer(float magazineLoadingTime) 119 143 { 120 //COUT(0) << "Weapon::magazineTimer started" << std::endl;121 144 this->bReloading_ = true; 122 145 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); … … 140 163 void Weapon::attachNeededMunition(std::string munitionName) 141 164 { 142 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; 143 //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 144 //if the weapon shares one munitionType put it into sharedMunitionSet 145 //else to munitionSet 165 /* 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 166 * if the weapon shares one munitionType put it into sharedMunitionSet else to munitionSet 167 */ 146 168 if (this->parentWeaponSystem_) 147 169 { … … 154 176 else 155 177 { 156 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;157 178 //getMunitionType returns 0 if there is no such munitionType 158 179 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); … … 162 183 { 163 184 //create new munition with identifier because there is no such munitionType 164 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;165 185 this->munitionIdentifier_ = ClassByString(munitionName); 166 186 this->munition_ = this->munitionIdentifier_.fabricate(this); … … 168 188 } 169 189 } 190 this->setMunition(); 170 191 } 171 192 } 193 194 195 Munition * Weapon::getAttachedMunition(std::string munitionType) 196 { 197 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 198 return this->munition_; 199 } 200 201 202 //these function are defined in the weapon classes 203 void Weapon::takeBullets() { }; 204 void Weapon::createProjectile() { }; 205 void Weapon::takeMagazines() { }; 206 void Weapon::reloadBullet() { }; 207 void Weapon::reloadMagazine() { }; 172 208 173 209 … … 175 211 * 176 212 */ 177 178 213 void Weapon::setMunitionType(std::string munitionType) 179 214 { this->munitionType_ = munitionType; } … … 200 235 { return this->bSharedMunition_; } 201 236 202 203 Munition * Weapon::getAttachedMunition(std::string munitionType) 204 { 205 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; 206 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 207 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; 208 return this->munition_; 209 } 210 211 void Weapon::takeBullets() { }; 212 void Weapon::createProjectile() { }; 213 void Weapon::takeMagazines() { }; 237 void Weapon::setBulletAmount(unsigned int amount) 238 { this->bulletAmount_ = amount; } 239 240 const unsigned int Weapon::getBulletAmount() 241 { return this->bulletAmount_; } 242 243 void Weapon::setMagazineAmount(unsigned int amount) 244 { this->magazineAmount_ = amount; } 245 246 const unsigned int Weapon::getMagazineAmount() 247 { return this->magazineAmount_; } 248 249 void Weapon::setUnlimitedMunition(bool unlimitedMunition) 250 { this->unlimitedMunition_ = unlimitedMunition; } 251 252 const bool Weapon::getUnlimitedMunition() 253 { return this->unlimitedMunition_; } 214 254 215 255 }
Note: See TracChangeset
for help on using the changeset viewer.