Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2016, 4:53:34 PM (9 years ago)
Author:
fvultier
Message:

merged discharger, thats the last one

Location:
code/branches/presentationFS16
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationFS16

  • code/branches/presentationFS16/src/orxonox/weaponsystem/Weapon.cc

    r11071 r11208  
    9999        Fire this Weapon with the the WeaponMode defined by @param mode
    100100    */
    101     void Weapon::fire(unsigned int mode)
     101    void Weapon::push(unsigned int mode)
    102102    {
    103103        // To avoid firing with more than one mode at the same time, we lock the weapon (reloading) for
     
    114114        // Note: The reloading of each WeaponMode is internally handled by each A, B and C.
    115115        //       The reloading of the weapon is only performed to avoid firing with different modes at the same time.
     116   
     117   
    116118        if (this->bReloading_ && this->reloadingWeaponmode_ != mode)
    117119            return;
     
    123125        {
    124126            float reloading_time = 0;
    125             if (it->second->fire(&reloading_time))
     127            if (it->second->push(&reloading_time))
     128            {
     129                this->bReloading_ = true;
     130                this->reloadingWeaponmode_ = mode;
     131
     132                this->reloadTimer_.setInterval(reloading_time);
     133                this->reloadTimer_.startTimer();
     134            }
     135        }
     136    }
     137
     138    void Weapon::release(unsigned int mode)
     139    {
     140        if (this->bReloading_ && this->reloadingWeaponmode_ != mode)
     141            return;
     142
     143        std::multimap<unsigned int, WeaponMode*>::iterator start = this->weaponmodes_.lower_bound(mode);
     144        std::multimap<unsigned int, WeaponMode*>::iterator end   = this->weaponmodes_.upper_bound(mode);
     145
     146        for (std::multimap<unsigned int, WeaponMode*>::iterator it = start; it != end; ++it)
     147        {
     148            float reloading_time = 0;
     149            if (it->second->release(&reloading_time))
    126150            {
    127151                this->bReloading_ = true;
  • code/branches/presentationFS16/src/orxonox/weaponsystem/Weapon.h

    r11071 r11208  
    5252            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    5353
    54             void fire(unsigned int mode);
     54            void push(unsigned int mode);
     55            void release(unsigned int mode);
    5556            void reload();
    5657
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponMode.cc

    r11108 r11208  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Johannes Sager
    2727 *
    2828 */
     
    6363        this->bAutoReload_ = true;
    6464        this->bParallelReload_ = true;
     65        this->chargeable_ = false;              // most weapons are not chargeable
     66        this->charges_ = 0;                     // always start with no charges
     67        this->maxCharges_ = 100;                // default maximum charges one can have are 100
    6568
    6669        this->reloadTimer_.setTimer(0.0f, false, createExecutor(createFunctor(&WeaponMode::reloaded, this)));
     
    121124    {
    122125        (*reloadTime) = this->reloadTime_;
    123        
    124126        // Fireing is only possible if this weapon mode is not reloading and there is enough munition
    125127        if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this))
     
    169171    }
    170172
     173    bool WeaponMode::push(float* reloadTime)
     174    {
     175
     176        if( this->chargeable_)                                                                                                          // chargeable weapons are supposed to charge on push
     177        {
     178            this->munition_ = this->weapon_->getWeaponPack()->getWeaponSystem()->getMunition(&this->munitiontype_);                     // updates the pointer to the munition(which we use in the next step)
     179            if(this->charges_ < this->maxCharges_ && this->bReloading_ == false && this->munition_->canTakeMunition(1, this))           // charges up unless:
     180            {                                                                                                                           // - we are fully charged
     181                this->charges_ += 1;                                                                                                    // - we are reloading
     182            }                                                                                                                           // - we have no munition
     183            return false;
     184        }
     185        else                                                                                                                            // normal (not chargeable) weapons are supposed to fire on push
     186        {
     187            return fire(reloadTime);
     188        }
     189    }
     190
     191    bool WeaponMode::release(float* reloadTime)                 
     192    {
     193        if( this->chargeable_)                                                                                                          // chargeable weapons are supposed to fire on release
     194        {
     195            return fire(reloadTime);
     196        }
     197        else                                                                                                                            // normal (not chargeable) weapons should do nothing on release
     198        {
     199            return false;
     200        }
     201    }
     202
    171203    bool WeaponMode::reload()
    172204    {
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponMode.h

    r11108 r11208  
    2424 *      Fabian 'x3n' Landau
    2525 *   Co-authors:
    26  *      ...
     26 *      Johannes Sager
    2727 *
    2828 */
     
    4545    /**
    4646    @brief
    47         A WeaponMode defines how a Weapon is used. It specifies what kind of @ref orxonox::Projectile is created when you fire it, how much time it takes to reload, what sound you hear while shooting, how much damage the projectile deals to a target, ...
     47        A WeaponMode defines how a Weapon is used. It specifies what kind of
     48        @ref orxonox::Projectile is created when you fire it, how much time it takes to reload,
     49        what sound you hear while shooting, how much damage the projectile deals to a target, ...
    4850    */
    4951    class _OrxonoxExport WeaponMode : public BaseObject
     
    5557            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    5658
     59            virtual bool push(float* reloadTime);
     60            virtual bool release(float* reloadTime);
    5761            virtual bool fire(float* reloadTime);
    5862            bool reload();
     
    106110
    107111            // Fire
     112            inline unsigned int getMaxCharges()                 // get the maximum of charges one can have
     113                { return this->maxCharges_;}
     114            inline unsigned int getCharges()                    // get the current amount of charges
     115                { return this->charges_;}
     116            inline bool isChargeable()                          // returns if the weaponmode is chargeable
     117                { return this->chargeable_;}
    108118            inline void setDamage(float damage)
    109119                { this->damage_ = damage;}
     
    166176            unsigned int initialMagazines_;
    167177            unsigned int munitionPerShot_;
     178            unsigned int charges_;                  // current amount of charges only matters for chargeable weapons(chargeable == true)
     179            unsigned int maxCharges_;               // maximum amount of charges (is initialized with 100 in weaponmode.cc) only matters for chargeable weapons(chargeable == true)
    168180
    169181            float reloadTime_;
    170             bool bAutoReload_; // If true, the weapon reloads the magazine automatically.
    171             bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading.
     182            bool bAutoReload_;                      // If true, the weapon reloads the magazine automatically.
     183            bool bParallelReload_;                  // If true, the weapon reloads in parallel to the magazine reloading.
     184            bool chargeable_;                       // If true, the weapon charges up on push and fires on release
    172185
    173186            float damage_;
     
    189202
    190203            Timer reloadTimer_;
    191             bool bReloading_; // If true, this weapon mode is marked as reloading.
     204            bool bReloading_;                       // If true, this weapon mode is marked as reloading.
    192205
    193206            Vector3 muzzlePosition_;
    194207            Quaternion muzzleOrientation_;
    195208
    196             std::string fireSoundPath_; // The path of the sound played when fireing
    197             float fireSoundVolume_; // The volume of the sound played when fireing
    198             std::vector<WorldSound*> fireSounds_; // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.
    199             std::string reloadSoundPath_; // The path of the sound played when reloading
    200             float reloadSoundVolume_; // The volume of the sound played when reloading
     209            std::string fireSoundPath_;             // The path of the sound played when fireing
     210            float fireSoundVolume_;                 // The volume of the sound played when fireing
     211            std::vector<WorldSound*> fireSounds_;   // List of sounds used by the weapon mode. Because multiple sounds may overlap, we need mor than one WorldSound instance.
     212            std::string reloadSoundPath_;           // The path of the sound played when reloading
     213            float reloadSoundVolume_;               // The volume of the sound played when reloading
    201214            WorldSound* reloadSound_;
    202215    };
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponPack.cc

    r11071 r11208  
    7474        Fire all weapons in this WeaponSet with the defined weaponmode.
    7575    */
    76     void WeaponPack::fire(unsigned int weaponmode)
     76    void WeaponPack::push(unsigned int weaponmode)
    7777    {
    7878        for (Weapon* weapon : this->weapons_)
    79             weapon->fire(weaponmode);
     79            weapon->push(weaponmode);
     80    }
     81
     82    void WeaponPack::release(unsigned int weaponmode)
     83    {
     84        for (Weapon* weapon : this->weapons_)
     85            weapon->release(weaponmode);
    8086    }
    8187
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponPack.h

    r11071 r11208  
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    4747
    48             void fire(unsigned int weaponmode);
     48            void push(unsigned int weaponmode);
     49            void release(unsigned int weaponmode);
    4950            void reload();
    5051
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSet.cc

    r11071 r11208  
    6060    }
    6161
    62     void WeaponSet::fire()
     62    void WeaponSet::push()
    6363    {
    6464        // Fire all WeaponPacks with their defined weaponmode
    6565        for (const auto& mapEntry : this->weaponpacks_)
    6666            if (mapEntry.second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
    67                 mapEntry.first->fire(mapEntry.second);
     67                mapEntry.first->push(mapEntry.second);
     68    }
     69
     70    void WeaponSet::release()
     71    {
     72        // Fire all WeaponPacks with their defined weaponmode
     73        for (const auto& mapEntry : this->weaponpacks_)
     74            if (mapEntry.second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
     75                mapEntry.first->release(mapEntry.second);
    6876    }
    6977
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSet.h

    r11071 r11208  
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    4747
    48             void fire();
     48            void push();
     49            void release();
    4950            void reload();
    5051
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSystem.cc

    r11099 r11208  
    287287        Fires the @ref orxonox::WeaponSet with the specified firemode.
    288288    */
    289     void WeaponSystem::fire(unsigned int firemode)
     289    void WeaponSystem::push(unsigned int firemode)
    290290    {
    291291        std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(firemode);
    292292        if (it != this->weaponSets_.end() && it->second)
    293             it->second->fire();
     293            it->second->push();
     294    }
     295
     296    void WeaponSystem::release(unsigned int firemode)
     297    {
     298        std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.find(firemode);
     299        if (it != this->weaponSets_.end() && it->second)
     300            it->second->release();
    294301    }
    295302
  • code/branches/presentationFS16/src/orxonox/weaponsystem/WeaponSystem.h

    r11176 r11208  
    7676            void changeWeaponmode(WeaponPack * wPack, WeaponSet * wSet, unsigned int weaponmode);
    7777
    78             void fire(unsigned int firemode);
     78            void push(unsigned int firemode);
     79            void release(unsigned int firemode);
    7980            void reload();
    8081
Note: See TracChangeset for help on using the changeset viewer.