Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc

    r11052 r11071  
    5252        RegisterObject(WeaponSystem);
    5353
    54         this->pawn_ = 0;
     54        this->pawn_ = nullptr;
    5555    }
    5656
     
    6060        {
    6161            if (this->pawn_)
    62                 this->pawn_->setWeaponSystem(0);
     62                this->pawn_->setWeaponSystem(nullptr);
    6363
    6464            while (!this->weaponSets_.empty())
     
    106106    {
    107107        unsigned int i = 0;
    108         for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     108        for (WeaponSlot* weaponSlot : this->weaponSlots_)
    109109        {
    110110            ++i;
    111111            if (i > index)
    112                 return (*it);
    113         }
    114         return 0;
     112                return weaponSlot;
     113        }
     114        return nullptr;
    115115    }
    116116
     
    153153    {
    154154        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& mapEntry : this->weaponSets_)
    156156        {
    157157            ++i;
    158158            if (i > index)
    159                 return it->second;
    160         }
    161         return 0;
     159                return mapEntry.second;
     160        }
     161        return nullptr;
    162162    }
    163163
     
    168168
    169169        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 (WeaponSlot* weaponSlot : this->weaponSlots_)
     171        {
     172            if (!weaponSlot->isOccupied())
    173173                ++freeSlots;
    174174        }
     
    184184        // Attach all weapons to the first free slots (and to the Pawn)
    185185        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 (WeaponSlot* weaponSlot : this->weaponSlots_)
     187        {
     188            if (!weaponSlot->isOccupied() && i < wPack->getNumWeapons())
    189189            {
    190190                Weapon* weapon = wPack->getWeapon(i);
    191                 (*it)->attachWeapon(weapon);
     191                weaponSlot->attachWeapon(weapon);
    192192                this->getPawn()->attach(weapon);
    193193                ++i;
     
    196196
    197197        // 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 (const auto& mapEntry : this->weaponSets_)
     199        {
     200            unsigned int weaponmode = wPack->getDesiredWeaponmode(mapEntry.first);
    201201            if (weaponmode != WeaponSystem::WEAPON_MODE_UNASSIGNED)
    202                 it->second->setWeaponmodeLink(wPack, weaponmode);
     202                mapEntry.second->setWeaponmodeLink(wPack, weaponmode);
    203203        }
    204204
     
    213213        // Remove all weapons from their WeaponSlot
    214214        unsigned int i = 0;
    215         Weapon* weapon = 0;
     215        Weapon* weapon = nullptr;
    216216        while ((weapon = wPack->getWeapon(i++)))
    217217            if (weapon->getWeaponSlot())
     
    219219
    220220        // 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 (const auto& mapEntry : this->weaponSets_)
     222            mapEntry.second->removeWeaponmodeLink(wPack);
    223223
    224224        // Remove the WeaponPack from the WeaponSystem
     
    231231    {
    232232        unsigned int i = 0;
    233         for (std::vector<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
     233        for (WeaponPack* weaponPack : this->weaponPacks_)
    234234        {
    235235            ++i;
    236236            if (i > index)
    237                 return (*it);
    238         }
    239         return 0;
    240     }
    241 
    242     std::vector<WeaponPack *> * WeaponSystem::getAllWeaponPacks()
    243     {
    244         return &weaponPacks_;
    245     }   
     237                return weaponPack;
     238        }
     239        return nullptr;
     240    }
    246241
    247242    bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
     
    273268        // Check if the WeaponSet belongs to this WeaponSystem
    274269        bool foundWeaponSet = false;
    275         for (std::map<unsigned int, WeaponSet *>::iterator it2 = this->weaponSets_.begin(); it2 != this->weaponSets_.end(); ++it2)
    276         {
    277             if (it2->second == wSet)
     270        for (const auto& mapEntry : this->weaponSets_)
     271        {
     272            if (mapEntry.second == wSet)
    278273            {
    279274                foundWeaponSet = true;
     
    301296    void WeaponSystem::reload()
    302297    {
    303         for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
    304             it->second->reload();
     298        for (const auto& mapEntry : this->weaponSets_)
     299            mapEntry.second->reload();
    305300    }
    306301
     
    308303    {
    309304        if (!identifier || !identifier->getIdentifier())
    310             return 0;
     305            return nullptr;
    311306
    312307        std::map<Identifier *, Munition *>::iterator it = this->munitions_.find(identifier->getIdentifier());
     
    317312        else
    318313        {
    319             return NULL;
     314            return nullptr;
    320315        }
    321316    }
     
    323318    void WeaponSystem::addMunition(Munition* munition)
    324319    {
    325         if (munition == NULL)
     320        if (munition == nullptr)
    326321        {
    327322            return;
     
    337332        else
    338333        {
    339             orxout(internal_warning) << "Adding munition failed. identifier == NULL " << endl;
     334            orxout(internal_warning) << "Adding munition failed. identifier == nullptr " << endl;
    340335        }
    341336    }
     
    343338    void WeaponSystem::updateMunition()
    344339    {
    345         for (std::vector<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
    346         {
    347             (*it)->updateMunition();
     340        for (WeaponPack* weaponPack : this->weaponPacks_)
     341        {
     342            weaponPack->updateMunition();
    348343        }
    349344    }
Note: See TracChangeset for help on using the changeset viewer.