Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 19, 2009, 4:55:08 PM (16 years ago)
Author:
polakma
Message:

some enhancements, but not working…

File:
1 edited

Legend:

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

    r2778 r2804  
    4242    {
    4343        RegisterObject(Weapon);
     44
    4445        this->bulletReadyToShoot_ = true;
    4546        this->magazineReadyToShoot_ = true;
    4647        this->parentWeaponSystem_ = 0;
    4748        this->attachedToWeaponSlot_ = 0;
    48         this->munition_ = 0;
    4949        this->bulletLoadingTime_ = 0;
    5050        this->magazineLoadingTime_ = 0;
    5151        this->bReloading_ = false;
    52 
     52        this->bulletAmount_= 0;
     53        this->magazineAmount_ = 0;
     54        this->munition_ = 0;
     55        this->unlimitedMunition_ = false;
    5356        this->setObjectMode(0x0);
    5457    }
     
    6669        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
    6770        XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode);
     71        XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);
     72        XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);
     73        XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode);
    6874    }
    6975
     
    7480    }
    7581
     82    void Weapon::setMunition()
     83    {
     84        this->munition_->setMaxBullets(this->bulletAmount_);
     85        this->munition_->setMaxMagazines(this->magazineAmount_);
     86    }
    7687
    7788    void Weapon::fire()
    7889    {
    79 //COUT(0) << "LaserGun::fire, this=" << this << std::endl;
     90COUT(0) << "Weapon::fire" << std::endl;
    8091        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
    8192        {
    82 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
    83 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
     93COUT(0) << "Weapon::fire 2" << std::endl;
    8494            this->bulletReadyToShoot_ = false;
    85             if ( this->munition_->bullets() > 0)
    86             {
     95            if ( this->unlimitedMunition_== true )
     96            {
     97COUT(0) << "Weapon::fire 3" << std::endl;
    8798                //shoot
    88                 this->takeBullets();
     99                this->reloadBullet();
    89100                this->createProjectile();
    90101            }
    91             //if there are no bullets, but magazines
    92             else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
    93             {
    94 //COUT(0) << "LaserGun::fire - no bullets" << std::endl;
    95                 this->takeMagazines();
    96             }
    97102            else
    98103            {
    99 //COUT(0) << "LaserGun::fire - no magazines" << std::endl;
    100                 //no magazines
     104COUT(0) << "Weapon::fire 4" << std::endl;
     105                if ( this->munition_->bullets() > 0)
     106                {
     107COUT(0) << "Weapon::fire 5" << std::endl;
     108                    //shoot
     109                    this->takeBullets();
     110                    this->reloadBullet();
     111                    this->createProjectile();
     112                }
     113                //if there are no bullets, but magazines
     114                else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
     115                {
     116COUT(0) << "Weapon::fire 6" << std::endl;
     117                    this->takeMagazines();
     118                    this->reloadMagazine();
     119                }
     120                else
     121                {
     122                    //no magazines
     123                }
    101124            }
    102125        }
    103126        else
    104127        {
    105 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
     128COUT(0) << "Weapon::fire not reloaded" << std::endl;
    106129            //weapon not reloaded
    107130        }
     
    109132    }
    110133
    111 
     134    /*
     135    * weapon reloading
     136    */
    112137    void Weapon::bulletTimer(float bulletLoadingTime)
    113138    {
    114 //COUT(0) << "Weapon::bulletTimer started" << std::endl;
    115139        this->bReloading_ = true;
    116140        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     
    118142    void Weapon::magazineTimer(float magazineLoadingTime)
    119143    {
    120 //COUT(0) << "Weapon::magazineTimer started" << std::endl;
    121144        this->bReloading_ = true;
    122145        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
     
    140163    void Weapon::attachNeededMunition(std::string munitionName)
    141164    {
    142 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
    143         //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
     165        /*  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
     167        */
    146168        if (this->parentWeaponSystem_)
    147169        {
     
    154176            else
    155177            {
    156 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
    157178                //getMunitionType returns 0 if there is no such munitionType
    158179                Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     
    162183                {
    163184                    //create new munition with identifier because there is no such munitionType
    164 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
    165185                    this->munitionIdentifier_ = ClassByString(munitionName);
    166186                    this->munition_ = this->munitionIdentifier_.fabricate(this);
     
    168188                }
    169189            }
     190            this->setMunition();
    170191        }
    171192    }
     193
     194
     195    Munition * Weapon::getAttachedMunition(std::string munitionType)
     196    {
     197        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
     198        return this->munition_;
     199    }
     200
     201
     202    //these function are defined in the weapon classes
     203    void Weapon::takeBullets() { };
     204    void Weapon::createProjectile() { };
     205    void Weapon::takeMagazines() { };
     206    void Weapon::reloadBullet() { };
     207    void Weapon::reloadMagazine() { };
    172208
    173209
     
    175211     *
    176212     */
    177 
    178213    void Weapon::setMunitionType(std::string munitionType)
    179214    {   this->munitionType_ = munitionType; }
     
    200235    {   return this->bSharedMunition_;  }
    201236
    202 
    203     Munition * Weapon::getAttachedMunition(std::string munitionType)
    204     {
    205 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
    206         this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
    207 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
    208         return this->munition_;
    209     }
    210 
    211     void Weapon::takeBullets() { };
    212     void Weapon::createProjectile() { };
    213     void Weapon::takeMagazines() { };
     237    void Weapon::setBulletAmount(unsigned int amount)
     238    {   this->bulletAmount_ = amount; }
     239
     240    const unsigned int Weapon::getBulletAmount()
     241    {   return this->bulletAmount_;  }
     242
     243    void Weapon::setMagazineAmount(unsigned int amount)
     244    {   this->magazineAmount_ = amount; }
     245
     246    const unsigned int Weapon::getMagazineAmount()
     247    {   return this->magazineAmount_;  }
     248
     249    void Weapon::setUnlimitedMunition(bool unlimitedMunition)
     250    {   this->unlimitedMunition_ = unlimitedMunition;   }
     251
     252    const bool Weapon::getUnlimitedMunition()
     253    {   return this->unlimitedMunition_;    }
    214254
    215255}
Note: See TracChangeset for help on using the changeset viewer.