Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 12, 2009, 5:05:18 PM (16 years ago)
Author:
polakma
Message:

now you can choose between shared munition and normal munition

File:
1 edited

Legend:

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

    r2662 r2778  
    6565        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
    6666        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
     67        XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode);
    6768    }
    6869
     
    9798            {
    9899//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
    99                 //actions
     100                //no magazines
    100101            }
    101102        }
     
    103104        {
    104105//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
    105             //actions
     106            //weapon not reloaded
    106107        }
    107108
     
    141142//COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
    142143        //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
     144        //if the weapon shares one munitionType put it into sharedMunitionSet
     145        //else to munitionSet
    143146        if (this->parentWeaponSystem_)
    144147        {
    145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
    146             Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
    147             if ( munition )
    148                 this->munition_ = munition;
    149             else
    150             {
    151                 //create new munition with identifier
    152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
     148            if (this->bSharedMunition_ == false)
     149            {
    153150                this->munitionIdentifier_ = ClassByString(munitionName);
    154151                this->munition_ = this->munitionIdentifier_.fabricate(this);
    155152                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
    156153            }
     154            else
     155            {
     156//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
     157                //getMunitionType returns 0 if there is no such munitionType
     158                Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     159                if ( munition )
     160                    this->munition_ = munition;
     161                else
     162                {
     163                    //create new munition with identifier because there is no such munitionType
     164//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
     165                    this->munitionIdentifier_ = ClassByString(munitionName);
     166                    this->munition_ = this->munitionIdentifier_.fabricate(this);
     167                    this->parentWeaponSystem_->setNewSharedMunition(munitionName, this->munition_);
     168                }
     169            }
    157170        }
    158171    }
     
    180193    const float Weapon::getMagazineLoadingTime()
    181194    {   return this->magazineLoadingTime_;  }
     195
     196    void Weapon::setSharedMunition(bool bSharedMunition)
     197    {   this->bSharedMunition_ = bSharedMunition; }
     198
     199    const bool Weapon::getSharedMunition()
     200    {   return this->bSharedMunition_;  }
    182201
    183202
Note: See TracChangeset for help on using the changeset viewer.