- Timestamp:
- Apr 10, 2009, 12:05:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2912 r2914 35 35 #include "Weapon.h" 36 36 #include "WeaponSlot.h" 37 #include "WeaponSystem.h" 37 38 38 39 namespace orxonox … … 45 46 46 47 this->weaponSystem_ = 0; 47 this->firemode_ = 0;48 48 49 49 COUT(0) << "+WeaponPack" << std::endl; … … 53 53 { 54 54 COUT(0) << "~WeaponPack" << std::endl; 55 56 if (this->isInitialized() && this->weaponSystem_) 57 this->weaponSystem_->removeWeaponPack(this); 55 58 } 56 59 … … 60 63 61 64 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode); 62 XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);63 65 } 64 66 65 int WeaponPack::getSize() const67 void WeaponPack::fire(unsigned int weaponmode) 66 68 { 67 return this->weapons_.size(); 68 } 69 70 void WeaponPack::fire() 71 { 72 for (int i=0; i < (int) this->weapons_.size(); i++) 73 { 74 this->weapons_[i]->getAttachedToWeaponSlot()->fire(); 75 } 76 } 77 78 Weapon * WeaponPack::getWeaponPointer(unsigned int n) const 79 { 80 return this->weapons_[n]; 81 } 82 83 void WeaponPack::setFireMode(unsigned int firemode) 84 { 85 this->firemode_ = firemode; 86 } 87 88 unsigned int WeaponPack::getFireMode() const 89 { 90 return this->firemode_; 69 for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 70 (*it)->fire(); 91 71 } 92 72 93 73 void WeaponPack::addWeapon(Weapon * weapon) 94 74 { 95 this->weapons_.push_back(weapon); 75 if (!weapon) 76 return; 77 78 this->weapons_.insert(weapon); 79 weapon->setWeaponPack(this); 96 80 } 97 81 98 constWeapon * WeaponPack::getWeapon(unsigned int index) const82 Weapon * WeaponPack::getWeapon(unsigned int index) const 99 83 { 100 return weapons_[index]; 84 unsigned int i = 0; 85 86 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 87 { 88 if (i == index) 89 return (*it); 90 ++i; 91 } 92 93 return 0; 101 94 } 102 95 103 96 void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem) 104 97 { 105 for (s ize_t i = 0; i < this->weapons_.size(); i++)106 this->weapons_[i]->setWeaponSystem(weaponSystem);98 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 99 (*it)->setWeaponSystem(weaponSystem); 107 100 } 108 101 109 102 void WeaponPack::attachNeededMunitionToAllWeapons() 110 103 { 111 for (s ize_t i = 0; i < this->weapons_.size(); i++)104 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 112 105 { 113 this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());114 this->weapons_[i]->setWeapon();106 (*it)->attachNeededMunition((*it)->getMunitionType()); 107 (*it)->setWeapon(); 115 108 } 116 109 }
Note: See TracChangeset
for help on using the changeset viewer.