Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2778 for code/branches


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

Location:
code/branches/weaponsystem/src/orxonox/objects/weaponSystem
Files:
5 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
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h

    r2662 r2778  
    6868            virtual void setMagazineLoadingTime(float loadingTime);
    6969            virtual const float getMagazineLoadingTime();
     70            virtual void setSharedMunition(bool bSharedMunition);
     71            virtual const bool getSharedMunition();
    7072
    7173            virtual void takeBullets();
     
    9193            bool bulletReadyToShoot_;
    9294            bool magazineReadyToShoot_;
     95            bool bSharedMunition_;
    9396            float bulletLoadingTime_;
    9497            float magazineLoadingTime_;
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2662 r2778  
    5656    void WeaponSet::attachWeaponPack(WeaponPack *wPack)
    5757    {
    58 //COUT(0) << "WeaponSet::attachWeaponPack" << std::endl;
    59 //COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl;
    60 //COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl;
    61 //COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl;
    6258        if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )
    6359        {
    64 //COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl;
    6560            this->attachedWeaponPack_ = wPack;
    6661            int wPackWeapon = 0;    //WeaponCounter for Attaching
    6762            //should be possible to choose which slot to use
     63
     64            //attach every weapon of the weaponPack to a weaponSlot
    6865            for (  int i=0; i < wPack->getSize() ; i++  )
    6966            {
    7067                //at the moment this function only works for one weaponPack in the entire WeaponSystem...
     68                //it also takes the first free weaponSlot...
    7169                if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full
    7270                {
    73 //COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl;
    7471                    this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
    7572                    this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2710 r2778  
    3838
    3939
    40 /* WEAPONSYSTEM
    41  * creates the WeaponSystem and the ability to use weapons and munition
    42  * loads the weapon the whole weaponSystem setting from an xml file
     40/* WeaponSystem
    4341 *
     42 *  www.orxonox.net/wiki/WeaponSystem
    4443 */
    4544
     
    8483    }
    8584
    86     //returns the Pointer to the munitionType
     85    void WeaponSystem::setNewSharedMunition(std::string munitionType, Munition * munitionToAdd)
     86    {
     87        this->munitionSharedSet_[munitionType] = munitionToAdd;
     88    }
     89
     90    //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition
    8791    Munition * WeaponSystem::getMunitionType(std::string munitionType)
    8892    {
    8993//COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;
    90         std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
    91         if (it != this->munitionSet_.end())
     94        std::map<std::string, Munition *>::const_iterator it = this->munitionSharedSet_.find(munitionType);
     95        if (it != this->munitionSharedSet_.end())
    9296            return it->second;
    9397        else
     
    96100
    97101
    98 /*
    99     //the first weaponSet is at n=0
    100     void WeaponSystem::setActiveWeaponSet(unsigned int n)
    101     {
    102         if (n < this->weaponSets_.size())
    103             this->activeWeaponSet_ = this->weaponSets_[n];
    104         else
    105             this->activeWeaponSet_ = this->weaponSets_[0];
    106     }
    107 */
     102
    108103
    109104
    110105    //n is the n'th weaponSet, starting with zero
    111     //SpaceShip.cc only needs to have the keybinding to a specific Set-number n
     106    //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)
    112107    void WeaponSystem::fire(WeaponMode::Enum n)
    113108    {
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2710 r2778  
    5353            //void fire();
    5454            void fire(WeaponMode::Enum fireMode);
    55             //void setActiveWeaponSet(unsigned int n);
    5655            void attachWeaponPack(WeaponPack * wPack, unsigned int firemode);
    5756            WeaponSet * getWeaponSetPointer(unsigned int n);
     
    5958            WeaponPack * getWeaponPackPointer(unsigned int n);
    6059            void setNewMunition(std::string munitionType, Munition * munitionToAdd);
     60            void setNewSharedMunition(std::string munitionType, Munition * munitionToAdd);
    6161            Munition * getMunitionType(std::string munitionType);
    6262
     
    7373            std::vector<WeaponSlot *> weaponSlots_;
    7474            std::vector<WeaponPack *> weaponPacks_;
     75            std::map<std::string, Munition *> munitionSharedSet_;
    7576            std::map<std::string, Munition *> munitionSet_;
    7677            WeaponSet *activeWeaponSet_;
Note: See TracChangeset for help on using the changeset viewer.