Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2009, 12:34:55 AM (15 years ago)
Author:
landauf
Message:
  • switched back to std::vector for the WeaponSlots to keep them in the same order as in the XML file
  • added DefaultWeaponmodeLink, a class which links weaponmodes (a property of a Weapon or a WeaponPack) with firemodes (one firemode corresponds to one WeaponSet). This can be changed later (for example in a nice GUI), but DefaultWeaponmodeLink defines the default value.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2914 r2915  
    6363                this->pawn_->setWeaponSystem(0);
    6464
    65             for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
    66                 delete (it++)->second;
    67 
    68             for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
    69                 delete (*(it++));
    70 
    71             for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
    72                 delete (*(it++));
     65//            for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
     66//                delete (it++)->second;
     67            while (!this->weaponSets_.empty())
     68                delete (this->weaponSets_.begin()->second);
     69
     70//            for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
     71//                delete (*(it++));
     72            while (!this->weaponPacks_.empty())
     73                delete (*this->weaponPacks_.begin());
     74
     75//            for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
     76//                delete (*(it++));
     77            while (!this->weaponSlots_.empty())
     78                delete (*this->weaponSlots_.begin());
    7379        }
    7480    }
     
    7985            return;
    8086
    81         this->weaponSlots_.insert(wSlot);
     87        this->weaponSlots_.push_back(wSlot);
    8288        wSlot->setWeaponSystem(this);
    8389    }
     
    9197            this->removeWeaponPack(wSlot->getWeapon()->getWeaponPack());
    9298
    93         this->weaponSlots_.erase(wSlot);
     99        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     100        {
     101            if ((*it) == wSlot)
     102            {
     103                this->weaponSlots_.erase(it);
     104                break;
     105            }
     106        }
    94107    }
    95108
     
    97110    {
    98111        unsigned int i = 0;
    99         for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     112        for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
    100113        {
    101114            ++i;
     
    159172
    160173        unsigned int freeSlots = 0;
    161         for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     174        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
    162175        {
    163176            if (!(*it)->isOccupied())
     
    175188        // Attach all weapons to the first free slots (and to the Pawn)
    176189        unsigned int i = 0;
    177         for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     190        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
    178191        {
    179192            if (!(*it)->isOccupied() && i < wPack->getNumWeapons())
     
    196209        this->weaponPacks_.insert(wPack);
    197210        wPack->setWeaponSystem(this);
    198         wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this?
    199211
    200212        return true;
     
    231243    bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
    232244    {
    233         // TODO
     245        if (!wSlot1 || !wSlot2)
     246            return false;
     247
     248        Weapon* weapon1 = wSlot1->getWeapon();
     249        Weapon* weapon2 = wSlot2->getWeapon();
     250
     251        wSlot1->attachWeapon(weapon2);
     252        wSlot2->attachWeapon(weapon1);
     253
     254        return true;
     255        // In the future, certain weapons might not fit to some slots. Swapping would then be
     256        // impossible and the returnvalue would be false.
    234257    }
    235258
Note: See TracChangeset for help on using the changeset viewer.