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/WeaponPack.cc

    r2914 r2915  
    2323 *      Martin Polak
    2424 *   Co-authors:
    25  *      ... *
     25 *      ...
     26 *
    2627 */
    2728
     
    3637#include "WeaponSlot.h"
    3738#include "WeaponSystem.h"
     39#include "DefaultWeaponmodeLink.h"
    3840
    3941namespace orxonox
     
    5557
    5658        if (this->isInitialized() && this->weaponSystem_)
     59        {
    5760            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        }
    5868    }
    5969
     
    6373
    6474        XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
     75        XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode);
    6576    }
    6677
     
    8091    }
    8192
     93    void WeaponPack::removeWeapon(Weapon * weapon)
     94    {
     95        if (!weapon)
     96            return;
     97
     98        this->weapons_.erase(weapon);
     99        weapon->setWeaponPack(0);
     100    }
     101
    82102    Weapon * WeaponPack::getWeapon(unsigned int index) const
    83103    {
     
    94114    }
    95115
    96     void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)
     116    void WeaponPack::setWeaponSystemToAllWeapons()
    97117    {
    98118        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    99             (*it)->setWeaponSystem(weaponSystem);
     119            (*it)->setWeaponSystem(this->weaponSystem_);
    100120    }
    101121
     
    108128        }
    109129    }
     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    }
    110157}
Note: See TracChangeset for help on using the changeset viewer.