- Timestamp:
- Apr 12, 2009, 12:34:55 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2914 r2915 23 23 * Martin Polak 24 24 * Co-authors: 25 * ... * 25 * ... 26 * 26 27 */ 27 28 … … 36 37 #include "WeaponSlot.h" 37 38 #include "WeaponSystem.h" 39 #include "DefaultWeaponmodeLink.h" 38 40 39 41 namespace orxonox … … 55 57 56 58 if (this->isInitialized() && this->weaponSystem_) 59 { 57 60 this->weaponSystem_->removeWeaponPack(this); 61 62 while (!this->weapons_.empty()) 63 delete (*this->weapons_.begin()); 64 65 for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); ) 66 delete (*(it++)); 67 } 58 68 } 59 69 … … 63 73 64 74 XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode); 75 XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode); 65 76 } 66 77 … … 80 91 } 81 92 93 void WeaponPack::removeWeapon(Weapon * weapon) 94 { 95 if (!weapon) 96 return; 97 98 this->weapons_.erase(weapon); 99 weapon->setWeaponPack(0); 100 } 101 82 102 Weapon * WeaponPack::getWeapon(unsigned int index) const 83 103 { … … 94 114 } 95 115 96 void WeaponPack::setWeaponSystemToAllWeapons( WeaponSystem * weaponSystem)116 void WeaponPack::setWeaponSystemToAllWeapons() 97 117 { 98 118 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 99 (*it)->setWeaponSystem( weaponSystem);119 (*it)->setWeaponSystem(this->weaponSystem_); 100 120 } 101 121 … … 108 128 } 109 129 } 130 131 void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link) 132 { 133 this->links_.insert(link); 134 } 135 136 DefaultWeaponmodeLink* WeaponPack::getDefaultWeaponmodeLink(unsigned int index) const 137 { 138 unsigned int i = 0; 139 for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it) 140 { 141 if (i == index) 142 return (*it); 143 144 ++i; 145 } 146 return 0; 147 } 148 149 unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const 150 { 151 for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it) 152 if ((*it)->getFiremode() == firemode) 153 return (*it)->getWeaponmode(); 154 155 return WeaponSystem::WEAPON_MODE_UNASSIGNED; 156 } 110 157 }
Note: See TracChangeset
for help on using the changeset viewer.