Changeset 10821 for code/branches/cpp11_v2/src/orxonox/weaponsystem
- Timestamp:
- Nov 21, 2015, 7:05:53 PM (9 years ago)
- Location:
- code/branches/cpp11_v2/src/orxonox/weaponsystem
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/orxonox/weaponsystem/Munition.cc
r10768 r10821 55 55 Munition::~Munition() 56 56 { 57 for ( std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)58 delete it->second;57 for (auto & elem : this->currentMagazines_) 58 delete elem.second; 59 59 } 60 60 … … 268 268 { 269 269 // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition) 270 for ( std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)271 if ( it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)270 for (const auto & elem : this->currentMagazines_) 271 if (elem.second->munition_ < this->maxMunitionPerMagazine_ && elem.second->bLoaded_) 272 272 return true; 273 273 } … … 316 316 { 317 317 bool change = false; 318 for ( std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)318 for (auto & elem : this->currentMagazines_) 319 319 { 320 320 // Add munition if the magazine isn't full (but only to loaded magazines) 321 if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)321 if (amount > 0 && elem.second->munition_ < this->maxMunitionPerMagazine_ && elem.second->bLoaded_) 322 322 { 323 it->second->munition_++;323 elem.second->munition_++; 324 324 amount--; 325 325 change = true; -
code/branches/cpp11_v2/src/orxonox/weaponsystem/Weapon.cc
r10768 r10821 61 61 this->weaponPack_->removeWeapon(this); 62 62 63 for ( std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)64 it->second->destroy();63 for (auto & elem : this->weaponmodes_) 64 elem.second->destroy(); 65 65 } 66 66 } … … 85 85 { 86 86 unsigned int i = 0; 87 for ( std::multimap<unsigned int, WeaponMode*>::const_iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)87 for (const auto & elem : this->weaponmodes_) 88 88 { 89 89 if (i == index) 90 return it->second;90 return elem.second; 91 91 92 92 ++i; … … 136 136 void Weapon::reload() 137 137 { 138 for ( std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)139 it->second->reload();138 for (auto & elem : this->weaponmodes_) 139 elem.second->reload(); 140 140 } 141 141 … … 148 148 void Weapon::notifyWeaponModes() 149 149 { 150 for ( std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)151 it->second->setWeapon(this);150 for (auto & elem : this->weaponmodes_) 151 elem.second->setWeapon(this); 152 152 } 153 153 } -
code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponPack.cc
r10768 r10821 76 76 void WeaponPack::fire(unsigned int weaponmode) 77 77 { 78 for ( std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)79 ( *it)->fire(weaponmode);78 for (auto & elem : this->weapons_) 79 (elem)->fire(weaponmode); 80 80 } 81 81 … … 86 86 void WeaponPack::reload() 87 87 { 88 for ( std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)89 ( *it)->reload();88 for (auto & elem : this->weapons_) 89 (elem)->reload(); 90 90 } 91 91 … … 114 114 unsigned int i = 0; 115 115 116 for ( std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)116 for (const auto & elem : this->weapons_) 117 117 { 118 118 if (i == index) 119 return ( *it);119 return (elem); 120 120 ++i; 121 121 } … … 132 132 { 133 133 unsigned int i = 0; 134 for ( std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)134 for (const auto & elem : this->links_) 135 135 { 136 136 if (i == index) 137 return ( *it);137 return (elem); 138 138 139 139 ++i; … … 144 144 unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const 145 145 { 146 for ( std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)147 if (( *it)->getFiremode() == firemode)148 return ( *it)->getWeaponmode();146 for (const auto & elem : this->links_) 147 if ((elem)->getFiremode() == firemode) 148 return (elem)->getWeaponmode(); 149 149 150 150 return WeaponSystem::WEAPON_MODE_UNASSIGNED; -
code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponSet.cc
r10768 r10821 63 63 { 64 64 // Fire all WeaponPacks with their defined weaponmode 65 for ( std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)66 if ( it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED)67 it->first->fire(it->second);65 for (auto & elem : this->weaponpacks_) 66 if (elem.second != WeaponSystem::WEAPON_MODE_UNASSIGNED) 67 elem.first->fire(elem.second); 68 68 } 69 69 … … 71 71 { 72 72 // Reload all WeaponPacks with their defined weaponmode 73 for ( std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)74 it->first->reload();73 for (auto & elem : this->weaponpacks_) 74 elem.first->reload(); 75 75 } 76 76 -
code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponSystem.cc
r10768 r10821 106 106 { 107 107 unsigned int i = 0; 108 for ( std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)108 for (const auto & elem : this->weaponSlots_) 109 109 { 110 110 ++i; 111 111 if (i > index) 112 return ( *it);112 return (elem); 113 113 } 114 114 return nullptr; … … 153 153 { 154 154 unsigned int i = 0; 155 for ( std::map<unsigned int, WeaponSet*>::const_iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)155 for (const auto & elem : this->weaponSets_) 156 156 { 157 157 ++i; 158 158 if (i > index) 159 return it->second;159 return elem.second; 160 160 } 161 161 return nullptr; … … 168 168 169 169 unsigned int freeSlots = 0; 170 for ( std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)171 { 172 if (!( *it)->isOccupied())170 for (auto & elem : this->weaponSlots_) 171 { 172 if (!(elem)->isOccupied()) 173 173 ++freeSlots; 174 174 } … … 184 184 // Attach all weapons to the first free slots (and to the Pawn) 185 185 unsigned int i = 0; 186 for ( std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)187 { 188 if (!( *it)->isOccupied() && i < wPack->getNumWeapons())186 for (auto & elem : this->weaponSlots_) 187 { 188 if (!(elem)->isOccupied() && i < wPack->getNumWeapons()) 189 189 { 190 190 Weapon* weapon = wPack->getWeapon(i); 191 ( *it)->attachWeapon(weapon);191 (elem)->attachWeapon(weapon); 192 192 this->getPawn()->attach(weapon); 193 193 ++i; … … 196 196 197 197 // Assign the desired weaponmode to the firemodes 198 for ( std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)199 { 200 unsigned int weaponmode = wPack->getDesiredWeaponmode( it->first);198 for (auto & elem : this->weaponSets_) 199 { 200 unsigned int weaponmode = wPack->getDesiredWeaponmode(elem.first); 201 201 if (weaponmode != WeaponSystem::WEAPON_MODE_UNASSIGNED) 202 it->second->setWeaponmodeLink(wPack, weaponmode);202 elem.second->setWeaponmodeLink(wPack, weaponmode); 203 203 } 204 204 … … 219 219 220 220 // Remove all added links from the WeaponSets 221 for ( std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)222 it->second->removeWeaponmodeLink(wPack);221 for (auto & elem : this->weaponSets_) 222 elem.second->removeWeaponmodeLink(wPack); 223 223 224 224 // Remove the WeaponPack from the WeaponSystem … … 231 231 { 232 232 unsigned int i = 0; 233 for ( std::vector<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)233 for (const auto & elem : this->weaponPacks_) 234 234 { 235 235 ++i; 236 236 if (i > index) 237 return ( *it);237 return (elem); 238 238 } 239 239 return nullptr; … … 268 268 // Check if the WeaponSet belongs to this WeaponSystem 269 269 bool foundWeaponSet = false; 270 for ( std::map<unsigned int, WeaponSet *>::iterator it2 = this->weaponSets_.begin(); it2 != this->weaponSets_.end(); ++it2)271 { 272 if ( it2->second == wSet)270 for (auto & elem : this->weaponSets_) 271 { 272 if (elem.second == wSet) 273 273 { 274 274 foundWeaponSet = true; … … 296 296 void WeaponSystem::reload() 297 297 { 298 for ( std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)299 it->second->reload();298 for (auto & elem : this->weaponSets_) 299 elem.second->reload(); 300 300 } 301 301
Note: See TracChangeset
for help on using the changeset viewer.