Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 26, 2009, 2:56:39 PM (15 years ago)
Author:
polakma
Message:

added unlimited munition, reverted shared munition and fixed some bugs

File:
1 edited

Legend:

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

    r2804 r2852  
    6868        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
    6969        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
    70         XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode);
    7170        XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);
    7271        XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);
     
    8887    void Weapon::fire()
    8988    {
    90 COUT(0) << "Weapon::fire" << std::endl;
    9189        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
    9290        {
    93 COUT(0) << "Weapon::fire 2" << std::endl;
    9491            this->bulletReadyToShoot_ = false;
    9592            if ( this->unlimitedMunition_== true )
    9693            {
    97 COUT(0) << "Weapon::fire 3" << std::endl;
    9894                //shoot
    9995                this->reloadBullet();
     
    10298            else
    10399            {
    104 COUT(0) << "Weapon::fire 4" << std::endl;
    105100                if ( this->munition_->bullets() > 0)
    106101                {
    107 COUT(0) << "Weapon::fire 5" << std::endl;
    108                     //shoot
     102                    //shoot and reload
    109103                    this->takeBullets();
    110104                    this->reloadBullet();
     
    114108                else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
    115109                {
    116 COUT(0) << "Weapon::fire 6" << std::endl;
     110                    //reload magazine
    117111                    this->takeMagazines();
    118112                    this->reloadMagazine();
     
    126120        else
    127121        {
    128 COUT(0) << "Weapon::fire not reloaded" << std::endl;
    129122            //weapon not reloaded
    130123        }
     
    132125    }
    133126
    134     /*
    135     * weapon reloading
    136     */
     127
     128    //weapon reloading
    137129    void Weapon::bulletTimer(float bulletLoadingTime)
    138130    {
     
    156148        this->bReloading_ = false;
    157149        this->munition_->fillBullets();
    158         this->magazineReadyToShoot_ = true;
    159         this->bulletReadyToShoot_ = true;
    160     }
     150    }
     151
    161152
    162153
     
    164155    {
    165156        /*  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
    166         *   if the weapon shares one munitionType put it into sharedMunitionSet else to munitionSet
    167157        */
    168158        if (this->parentWeaponSystem_)
    169159        {
    170             if (this->bSharedMunition_ == false)
    171             {
     160            //getMunitionType returns 0 if there is no such munitionType
     161            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     162            if ( munition )
     163            {
     164                this->munition_ = munition;
     165                this->setMunition();
     166            }
     167            else
     168            {
     169                //create new munition with identifier because there is no such munitionType
    172170                this->munitionIdentifier_ = ClassByString(munitionName);
    173171                this->munition_ = this->munitionIdentifier_.fabricate(this);
    174172                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
    175             }
    176             else
    177             {
    178                 //getMunitionType returns 0 if there is no such munitionType
    179                 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
    180                 if ( munition )
    181                     this->munition_ = munition;
    182                 else
    183                 {
    184                     //create new munition with identifier because there is no such munitionType
    185                     this->munitionIdentifier_ = ClassByString(munitionName);
    186                     this->munition_ = this->munitionIdentifier_.fabricate(this);
    187                     this->parentWeaponSystem_->setNewSharedMunition(munitionName, this->munition_);
    188                 }
    189             }
    190             this->setMunition();
     173                this->setMunition();
     174            }
    191175        }
    192176    }
     
    208192
    209193
    210      /*get and set functions
    211      *
    212      */
     194    //get and set functions for XMLPort
    213195    void Weapon::setMunitionType(std::string munitionType)
    214196    {   this->munitionType_ = munitionType; }
     
    229211    {   return this->magazineLoadingTime_;  }
    230212
    231     void Weapon::setSharedMunition(bool bSharedMunition)
    232     {   this->bSharedMunition_ = bSharedMunition; }
    233 
    234     const bool Weapon::getSharedMunition()
    235     {   return this->bSharedMunition_;  }
    236 
    237213    void Weapon::setBulletAmount(unsigned int amount)
    238214    {   this->bulletAmount_ = amount; }
     
    245221
    246222    const unsigned int Weapon::getMagazineAmount()
    247     {   return this->magazineAmount_;  }
     223    {   return this->magazineAmount_;   }
    248224
    249225    void Weapon::setUnlimitedMunition(bool unlimitedMunition)
Note: See TracChangeset for help on using the changeset viewer.