Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2331


Ignore:
Timestamp:
Dec 3, 2008, 5:13:34 PM (15 years ago)
Author:
polakma
Message:

fixed attaching

Location:
code/branches/weapon2/src/orxonox/objects/weaponSystem
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc

    r2327 r2331  
    5454    {
    5555        SUPER(Weapon, XMLPort, xmlelement, mode);
     56        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
    5657    }
    5758
     
    8182    {
    8283        //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
    83         if ( this->parentWeaponSystem_->getMunitionType(munitionName) )
    84             this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionName);
    85         else
     84        if (this->parentWeaponSystem_)
    8685        {
    87             //create new munition with identifier
    88             this->munitionIdentifier_ = ClassByString(munitionName);
    89             this->munition_ = this->munitionIdentifier_.fabricate(this);
    90             this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
     86            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     87            if ( munition )
     88                this->munition_ = munition;
     89            else
     90            {
     91                //create new munition with identifier
     92                this->munitionIdentifier_ = ClassByString(munitionName);
     93                this->munition_ = this->munitionIdentifier_.fabricate(this);
     94                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
     95            }
    9196        }
    9297    }
     
    96101     *
    97102     */
     103
     104    void Weapon::setMunitionType(std::string munitionType)
     105    {   this->munitionType_ = munitionType; }
     106
     107    std::string Weapon::getMunitionType()
     108    {   return this->munitionType_;  }
     109
    98110    Munition * Weapon::getAttachedMunition()
    99111    {   return this->munition_; }
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h

    r2327 r2331  
    7070            Timer<Weapon> *getMagazineTimer();
    7171
     72            void setMunitionType(std::string munitionType);
     73            std::string getMunitionType();
     74
    7275            inline void setParentWeaponSlot(WeaponSlot *parentWeaponSlot)
    7376                { this->parentWeaponSlot_=parentWeaponSlot; };
     
    8588            float magazineLoadingTime_;
    8689            Munition *munition_;
     90            std::string munitionType_;
    8791
    8892            WeaponSlot *parentWeaponSlot_;
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2327 r2331  
    4646
    4747        this->parentWeaponSystem_ = 0;
    48         this->firemode_ = 1;
     48        this->firemode_ = 0;
    4949
    5050    }
     
    6868        for (int i=0; i < (int) this->weapons_.size(); i++)
    6969        {
    70 COUT(0) << "WeaponPack::fire (attached from WeaponSet)"<< i << std::endl;
     70COUT(0) << "WeaponPack::fire (attached from WeaponSet)  from Weapon: "<< i << std::endl;
    7171            this->weapons_[i]->fire();
    7272        }
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2327 r2331  
    6363    {
    6464        wPack->setParentWeaponSystem(this);
    65         this->weaponSets_[firemode]->attachWeaponPack(wPack);
    66         this->weaponPacks_[firemode] = wPack;
     65        if (firemode < this->weaponSets_.size())
     66            this->weaponSets_[firemode]->attachWeaponPack(wPack);
     67        this->weaponPacks_.push_back(wPack);
    6768    }
    6869
     
    8586    Munition * WeaponSystem::getMunitionType(std::string munitionType)
    8687    {
    87         return this->munitionSet_[munitionType];
     88        std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
     89        if (it != this->munitionSet_.end())
     90            return it->second;
     91        else
     92            return 0;
    8893    }
    8994
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2327 r2331  
    4949
    5050        //how could it be loaded by XML
    51         this->attachNeededMunition("LaserGunMunition");
     51        this->attachNeededMunition(this->getMunitionType());
    5252    }
    5353
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2272 r2331  
    5555            float speed_;
    5656
    57 
    5857    };
    5958}
Note: See TracChangeset for help on using the changeset viewer.