Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 5, 2009, 11:27:54 PM (16 years ago)
Author:
landauf
Message:

merged weaponsystem branch back to trunk

Location:
code/trunk
Files:
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/weaponSystem/Munition.cc

    r2662 r2893  
    105105    void Munition::fillBullets()
    106106    {
    107 //COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;
    108107        this->bullets_ = this->maxBullets_;
    109108    }
  • code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc

    r2662 r2893  
    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    }
     
    6568        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
    6669        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
     70        XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);
     71        XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);
     72        XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode);
    6773    }
    6874
     
    7379    }
    7480
     81    void Weapon::setMunition()
     82    {
     83        this->munition_->setMaxBullets(this->bulletAmount_);
     84        this->munition_->setMaxMagazines(this->magazineAmount_);
     85    }
    7586
    7687    void Weapon::fire()
    7788    {
    78 //COUT(0) << "LaserGun::fire, this=" << this << std::endl;
    7989        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
    8090        {
    81 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
    82 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
    8391            this->bulletReadyToShoot_ = false;
    84             if ( this->munition_->bullets() > 0)
     92            if ( this->unlimitedMunition_== true )
    8593            {
    8694                //shoot
    87                 this->takeBullets();
     95                this->reloadBullet();
    8896                this->createProjectile();
    8997            }
    90             //if there are no bullets, but magazines
    91             else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
    92             {
    93 //COUT(0) << "LaserGun::fire - no bullets" << std::endl;
    94                 this->takeMagazines();
    95             }
    9698            else
    9799            {
    98 //COUT(0) << "LaserGun::fire - no magazines" << std::endl;
    99                 //actions
     100                if ( this->munition_->bullets() > 0)
     101                {
     102                    //shoot and reload
     103                    this->takeBullets();
     104                    this->reloadBullet();
     105                    this->createProjectile();
     106                }
     107                //if there are no bullets, but magazines
     108                else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
     109                {
     110                    //reload magazine
     111                    this->takeMagazines();
     112                    this->reloadMagazine();
     113                }
     114                else
     115                {
     116                    //no magazines
     117                }
    100118            }
    101119        }
    102120        else
    103121        {
    104 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
    105             //actions
     122            //weapon not reloaded
    106123        }
    107124
     
    109126
    110127
     128    //weapon reloading
    111129    void Weapon::bulletTimer(float bulletLoadingTime)
    112130    {
    113 //COUT(0) << "Weapon::bulletTimer started" << std::endl;
    114131        this->bReloading_ = true;
    115132        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     
    117134    void Weapon::magazineTimer(float magazineLoadingTime)
    118135    {
    119 //COUT(0) << "Weapon::magazineTimer started" << std::endl;
    120136        this->bReloading_ = true;
    121137        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
     
    132148        this->bReloading_ = false;
    133149        this->munition_->fillBullets();
    134         this->magazineReadyToShoot_ = true;
    135         this->bulletReadyToShoot_ = true;
    136     }
     150    }
     151
    137152
    138153
    139154    void Weapon::attachNeededMunition(std::string munitionName)
    140155    {
    141 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
    142         //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
     156        /*  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
     157        */
    143158        if (this->parentWeaponSystem_)
    144159        {
    145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
     160            //getMunitionType returns 0 if there is no such munitionType
    146161            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
    147162            if ( munition )
     163            {
    148164                this->munition_ = munition;
     165                this->setMunition();
     166            }
    149167            else
    150168            {
    151                 //create new munition with identifier
    152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
     169                //create new munition with identifier because there is no such munitionType
    153170                this->munitionIdentifier_ = ClassByString(munitionName);
    154171                this->munition_ = this->munitionIdentifier_.fabricate(this);
    155172                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
     173                this->setMunition();
    156174            }
    157175        }
     
    159177
    160178
    161      /*get and set functions
    162      *
    163      */
    164 
    165     void Weapon::setMunitionType(std::string munitionType)
    166     {   this->munitionType_ = munitionType; }
    167 
    168     const std::string Weapon::getMunitionType()
    169     {   return this->munitionType_;  }
    170 
    171     void Weapon::setBulletLoadingTime(float loadingTime)
    172     {   this->bulletLoadingTime_ = loadingTime; }
    173 
    174     const float Weapon::getBulletLoadingTime()
    175     {   return this->bulletLoadingTime_;  }
    176 
    177     void Weapon::setMagazineLoadingTime(float loadingTime)
    178     {   this->magazineLoadingTime_ = loadingTime; }
    179 
    180     const float Weapon::getMagazineLoadingTime()
    181     {   return this->magazineLoadingTime_;  }
    182 
    183 
    184179    Munition * Weapon::getAttachedMunition(std::string munitionType)
    185180    {
    186 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
    187181        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
    188 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
    189182        return this->munition_;
    190183    }
    191184
     185
     186    //these function are defined in the weapon classes
    192187    void Weapon::takeBullets() { };
    193188    void Weapon::createProjectile() { };
    194189    void Weapon::takeMagazines() { };
     190    void Weapon::reloadBullet() { };
     191    void Weapon::reloadMagazine() { };
     192
     193
     194    //get and set functions for XMLPort
     195    void Weapon::setMunitionType(std::string munitionType)
     196    {   this->munitionType_ = munitionType; }
     197
     198    const std::string Weapon::getMunitionType()
     199    {   return this->munitionType_;  }
     200
     201    void Weapon::setBulletLoadingTime(float loadingTime)
     202    {   this->bulletLoadingTime_ = loadingTime; }
     203
     204    const float Weapon::getBulletLoadingTime()
     205    {   return this->bulletLoadingTime_;  }
     206
     207    void Weapon::setMagazineLoadingTime(float loadingTime)
     208    {   this->magazineLoadingTime_ = loadingTime; }
     209
     210    const float Weapon::getMagazineLoadingTime()
     211    {   return this->magazineLoadingTime_;  }
     212
     213    void Weapon::setBulletAmount(unsigned int amount)
     214    {   this->bulletAmount_ = amount; }
     215
     216    const unsigned int Weapon::getBulletAmount()
     217    {   return this->bulletAmount_;  }
     218
     219    void Weapon::setMagazineAmount(unsigned int amount)
     220    {   this->magazineAmount_ = amount; }
     221
     222    const unsigned int Weapon::getMagazineAmount()
     223    {   return this->magazineAmount_;   }
     224
     225    void Weapon::setUnlimitedMunition(bool unlimitedMunition)
     226    {   this->unlimitedMunition_ = unlimitedMunition;   }
     227
     228    const bool Weapon::getUnlimitedMunition()
     229    {   return this->unlimitedMunition_;    }
    195230
    196231}
  • code/trunk/src/orxonox/objects/weaponSystem/Weapon.h

    r2662 r2893  
    6262            void magazineReloaded();
    6363
     64            //XMLPort functions
    6465            virtual void setMunitionType(std::string munitionType);
    6566            virtual const std::string getMunitionType();
     
    6869            virtual void setMagazineLoadingTime(float loadingTime);
    6970            virtual const float getMagazineLoadingTime();
     71            virtual void setBulletAmount(unsigned int amount);
     72            virtual const unsigned int getBulletAmount();
     73            virtual void setMagazineAmount(unsigned int amount);
     74            virtual const unsigned int getMagazineAmount();
     75            virtual void setUnlimitedMunition(bool unlimitedMunition);
     76            virtual const bool getUnlimitedMunition();
    7077
     78            //weapon actions
    7179            virtual void takeBullets();
    7280            virtual void takeMagazines();
    7381            virtual void createProjectile();
     82            virtual void reloadBullet();
     83            virtual void reloadMagazine();
    7484
     85            //manually set or reset
     86            virtual void setWeapon();
     87            virtual void setMunition();
     88           
    7589            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
    7690                { this->parentWeaponSystem_=parentWeaponSystem; };
     
    8397                { return this->attachedToWeaponSlot_; }
    8498
    85             virtual void setWeapon();
    8699
    87100        private:
     
    91104            bool bulletReadyToShoot_;
    92105            bool magazineReadyToShoot_;
     106            bool unlimitedMunition_;
    93107            float bulletLoadingTime_;
    94108            float magazineLoadingTime_;
     109            unsigned int bulletAmount_;
     110            unsigned int magazineAmount_;
    95111            std::string munitionType_;
    96112
  • code/trunk/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2710 r2893  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponPack.h

    r2710 r2893  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2662 r2893  
    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
     62           
    6763            //should be possible to choose which slot to use
     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) );
     
    8380                        if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 )
    8481                        {
    85 //COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl;
    8682                            this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) );
    8783                            this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
     
    9995    {
    10096        //fires all WeaponSlots available for this weaponSet attached from the WeaponPack
    101 //COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl;
    10297        if (this->attachedWeaponPack_)
    10398            this->attachedWeaponPack_->fire();
  • code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2826 r2893  
    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
     
    5251        RegisterObject(WeaponSystem);
    5352
    54         this->activeWeaponSet_ = 0;
    5553        this->parentPawn_ = 0;
    5654    }
     
    8482    }
    8583
    86     //returns the Pointer to the munitionType
     84
     85    //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition
    8786    Munition * WeaponSystem::getMunitionType(std::string munitionType)
    8887    {
    89 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;
    9088        std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
    9189        if (it != this->munitionSet_.end())
     
    9694
    9795
    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 */
    108 
    109 
    11096    //n is the n'th weaponSet, starting with zero
    111     //SpaceShip.cc only needs to have the keybinding to a specific Set-number n
     97    //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)
     98    //in future this could be well defined and not only for 3 different WeaponModes
    11299    void WeaponSystem::fire(WeaponMode::Enum n)
    113100    {
     
    125112                break;
    126113        }
    127 //COUT(0) << "WeaponSystem::fire" << std::endl;
    128114        if (set < (int)this->weaponSets_.size())
    129 //COUT(0) << "WeaponSystem::fire - after if" << std::endl;
    130115            this->weaponSets_[set]->fire();
    131116    }
  • code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2826 r2893  
    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
     
    7474            std::vector<WeaponPack *> weaponPacks_;
    7575            std::map<std::string, Munition *> munitionSet_;
    76             WeaponSet *activeWeaponSet_;
    7776            Pawn *parentPawn_;
    7877    };
  • code/trunk/src/orxonox/objects/weaponSystem/munitions/CMakeLists.txt

    r2710 r2893  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  LaserGunMunition.cc
     3  FusionMunition.cc
    34)
  • code/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc

    r2662 r2893  
    4343        RegisterObject(LaserGunMunition);
    4444
     45        //default if not defined in XML
    4546        this->maxBullets_ = 40;
    4647        this->maxMagazines_ = 100;
  • code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2662 r2893  
    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/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2662 r2893  
    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.