Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

some enhancements, but not working…

Location:
code/branches/weaponsystem/src/orxonox/objects/weaponSystem
Files:
10 edited

Legend:

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

    r2662 r2804  
    105105    void Munition::fillBullets()
    106106    {
    107 //COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;
    108107        this->bullets_ = this->maxBullets_;
    109108    }
  • 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}
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h

    r2778 r2804  
    6262            void magazineReloaded();
    6363
     64            //XMLPort functions
    6465            virtual void setMunitionType(std::string munitionType);
    6566            virtual const std::string getMunitionType();
     
    7071            virtual void setSharedMunition(bool bSharedMunition);
    7172            virtual const bool getSharedMunition();
     73            virtual void setBulletAmount(unsigned int amount);
     74            virtual const unsigned int getBulletAmount();
     75            virtual void setMagazineAmount(unsigned int amount);
     76            virtual const unsigned int getMagazineAmount();
     77            virtual void setUnlimitedMunition(bool unlimitedMunition);
     78            virtual const bool getUnlimitedMunition();
    7279
     80            //weapon actions
    7381            virtual void takeBullets();
    7482            virtual void takeMagazines();
    7583            virtual void createProjectile();
     84            virtual void reloadBullet();
     85            virtual void reloadMagazine();
    7686
     87            //manually set or reset
     88            virtual void setWeapon();
     89            virtual void setMunition();
     90           
    7791            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
    7892                { this->parentWeaponSystem_=parentWeaponSystem; };
     
    8599                { return this->attachedToWeaponSlot_; }
    86100
    87             virtual void setWeapon();
    88101
    89102        private:
     
    94107            bool magazineReadyToShoot_;
    95108            bool bSharedMunition_;
     109            bool unlimitedMunition_;
    96110            float bulletLoadingTime_;
    97111            float magazineLoadingTime_;
     112            unsigned int bulletAmount_;
     113            unsigned int magazineAmount_;
    98114            std::string munitionType_;
    99115
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2710 r2804  
    6363        for (int i=0; i < (int) this->weapons_.size(); i++)
    6464        {
    65 //COUT(0) << "WeaponPack::fire (attached from WeaponSet)  from Weapon: "<< i << std::endl;
    6665            this->weapons_[i]->getAttachedToWeaponSlot()->fire();
    6766        }
     
    8382    void WeaponPack::setFireMode(unsigned int firemode)
    8483    {
    85 //COUT(0) << "WeaponPack::setFireMode " << std::endl;
    8684        this->firemode_ = firemode;
    8785    }
     
    9492    void WeaponPack::addWeapon(Weapon * weapon)
    9593    {
    96 //COUT(0) << "WeaponPack::addWeapon:" << weapon << "   munition " << weapon->getMunitionType() << std::endl;
    9794        this->weapons_.push_back(weapon);
    9895    }
     
    117114        {
    118115            this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());
    119             //hack!
    120116            this->weapons_[i]->setWeapon();
    121117        }
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.h

    r2710 r2804  
    5959            const Weapon * getWeapon(unsigned int index);
    6060
     61            //functions with effect to all weapons of the weaponPack
    6162            //functions needed for creating Pointer to the right objects (-->Pawn.cc)
    6263            void setParentWeaponSystemToAllWeapons(WeaponSystem * weaponSystem);
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2778 r2804  
    6060            this->attachedWeaponPack_ = wPack;
    6161            int wPackWeapon = 0;    //WeaponCounter for Attaching
     62           
    6263            //should be possible to choose which slot to use
    63 
    6464            //attach every weapon of the weaponPack to a weaponSlot
    6565            for (  int i=0; i < wPack->getSize() ; i++  )
     
    8080                        if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 )
    8181                        {
    82 //COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl;
    8382                            this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) );
    8483                            this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
     
    9695    {
    9796        //fires all WeaponSlots available for this weaponSet attached from the WeaponPack
    98 //COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl;
    9997        if (this->attachedWeaponPack_)
    10098            this->attachedWeaponPack_->fire();
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2778 r2804  
    5151        RegisterObject(WeaponSystem);
    5252
    53         this->activeWeaponSet_ = 0;
    5453        this->parentPawn_ = 0;
    5554    }
     
    9190    Munition * WeaponSystem::getMunitionType(std::string munitionType)
    9291    {
    93 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;
    9492        std::map<std::string, Munition *>::const_iterator it = this->munitionSharedSet_.find(munitionType);
    9593        if (it != this->munitionSharedSet_.end())
     
    105103    //n is the n'th weaponSet, starting with zero
    106104    //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)
     105    //in future this could be well defined and not only for 3 different WeaponModes
    107106    void WeaponSystem::fire(WeaponMode::Enum n)
    108107    {
     
    120119                break;
    121120        }
    122 //COUT(0) << "WeaponSystem::fire" << std::endl;
    123121        if (set < (int)this->weaponSets_.size())
    124 //COUT(0) << "WeaponSystem::fire - after if" << std::endl;
    125122            this->weaponSets_[set]->fire();
    126123    }
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2778 r2804  
    7575            std::map<std::string, Munition *> munitionSharedSet_;
    7676            std::map<std::string, Munition *> munitionSet_;
    77             WeaponSet *activeWeaponSet_;
    7877            Pawn *parentPawn_;
    7978    };
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2662 r2804  
    5353    }
    5454
     55    void LaserGun::reloadBullet()
     56    {
     57        this->bulletTimer(this->bulletLoadingTime_);
     58    }
     59
     60    void LaserGun::reloadMagazine()
     61    {
     62        this->magazineTimer(this->magazineLoadingTime_);
     63    }
     64
    5565    void LaserGun::takeBullets()
    5666    {
    57 //COUT(0) << "LaserGun::takeBullets" << std::endl;
    5867        this->munition_->removeBullets(1);
    59         this->bulletTimer(this->bulletLoadingTime_);
    6068    }
    6169
     
    6371    {
    6472        this->munition_->removeMagazines(1);
    65         this->magazineTimer(this->magazineLoadingTime_);
    6673    }
    6774
    6875    void LaserGun::createProjectile()
    6976    {
    70 //COUT(0) << "LaserGun::createProjectile" << std::endl;
    7177        BillboardProjectile* projectile = new ParticleProjectile(this);
    7278        projectile->setOrientation(this->getWorldOrientation());
  • code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2662 r2804  
    5151            virtual void takeMagazines();
    5252            virtual void createProjectile();
     53            virtual void reloadBullet();
     54            virtual void reloadMagazine();
    5355
    5456        private:
Note: See TracChangeset for help on using the changeset viewer.