Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 24, 2015, 10:51:18 PM (9 years ago)
Author:
fvultier
Message:

There is now a HUD that shows the status of the weapon system: all weapons, weapon modes and their munition. Progress bars show the progress of replenishing munition.

Location:
code/branches/fabienHS15/src/orxonox
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/orxonox/weaponsystem/CMakeLists.txt

    r5781 r10688  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  Munition.cc
     3  ReplenishingMunition.cc
    34  Weapon.cc
    45  WeaponMode.cc
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc

    r9667 r10688  
    4545        this->magazines_ = 10;
    4646
    47         this->bUseSeparateMagazines_ = false;
    48         this->bStackMunition_ = true;
     47        this->deployment_ = DEPLOYMENT_STACK;
    4948        this->bAllowMunitionRefilling_ = true;
    5049        this->bAllowMultiMunitionRemovementUnderflow_ = true;
    5150
    52         this->reloadTime_ = 0;
     51        this->reloadTime_ = 0.5f;
    5352    }
    5453
     
    6160    Munition::Magazine* Munition::getMagazine(WeaponMode* user) const
    6261    {
    63         if (this->bUseSeparateMagazines_)
     62        if (deployment_ == DEPLOYMENT_SEPARATE)
    6463        {
    6564            // For separated magazines we definitively need a given user
     
    8786        if (magazine)
    8887        {
    89             if (this->bStackMunition_)
     88            if (deployment_ == DEPLOYMENT_STACK)
    9089                // With stacked munition every magazine contributes to the total amount
    9190                return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_;
     
    109108    unsigned int Munition::getNumMagazines() const
    110109    {
    111         if (this->bStackMunition_)
     110        if (deployment_ == DEPLOYMENT_STACK)
    112111        {
    113112            // If we stack munition and the current magazine is still full, it counts too
     
    122121    unsigned int Munition::getMaxMunition() const
    123122    {
    124         if (this->bStackMunition_)
     123        if (deployment_ == DEPLOYMENT_STACK)
    125124            return this->maxMunitionPerMagazine_ * this->maxMagazines_;
    126125        else
     
    135134            unsigned int munition = magazine->munition_;
    136135
    137             // If we stack munition, we con't care about the current magazine - we just need enough munition in total
    138             if (this->bStackMunition_)
     136            // If we stack munition, we don't care about the current magazine - we just need enough munition in total
     137            if (deployment_ == DEPLOYMENT_STACK)
    139138                munition += this->maxMunitionPerMagazine_ * this->magazines_;
    140139
     
    169168            {
    170169                // Not enough munition
    171                 if (this->bStackMunition_)
     170                if (deployment_ == DEPLOYMENT_STACK)
    172171                {
    173172                    // We stack munition, so just take what we can and then load the next magazine
     
    199198    {
    200199        // As long as we have enough magazines (and don't stack munition) we can reload
    201         return (this->magazines_ > 0 && !this->bStackMunition_);
     200        return (this->magazines_ > 0 && !deployment_ == DEPLOYMENT_STACK);
    202201    }
    203202
     
    207206        if (magazine)
    208207        {
    209             if (this->bStackMunition_)
     208            if (deployment_ == DEPLOYMENT_STACK)
    210209                // With stacked munition, we never have to reload
    211210                return false;
     
    231230
    232231        // If we use separate magazines for each user, we definitively need a user given
    233         if (this->bUseSeparateMagazines_ && !user)
     232        if (deployment_ == DEPLOYMENT_SEPARATE && !user)
    234233            return false;
    235234
    236235        // If we don't use separate magazines, set user to 0
    237         if (!this->bUseSeparateMagazines_)
     236        if (!deployment_ == DEPLOYMENT_SEPARATE)
    238237            user = 0;
    239238
     
    260259            return false;
    261260
    262         if (this->bStackMunition_)
     261        if (deployment_ == DEPLOYMENT_STACK)
    263262        {
    264263            // If we stack munition, we can always add munition until we reach the limit
     
    281280            return false;
    282281
    283         if (this->bStackMunition_)
     282        if (deployment_ == DEPLOYMENT_STACK)
    284283        {
    285284            // Stacking munition means, if a magazine gets full, the munition adds to a new magazine
     
    340339        // TODO: 'amount' is not used
    341340
    342         if (this->bStackMunition_)
     341        if (deployment_ == DEPLOYMENT_STACK)
    343342            // If we stack munition, we can always add new magazines because they contribute directly to the munition
    344343            return (this->getNumMunition(0) < this->getMaxMunition());
     
    357356
    358357        // If zero or less magazines are needed, we definitively don't need more magazines (unless we stack munition - then a magazine contributes directly to the munition)
    359         if (needed_magazines <= 0 && !this->bStackMunition_)
     358        if (needed_magazines <= 0 && !deployment_ == DEPLOYMENT_STACK)
    360359            return false;
    361360
     
    369368            // We get more magazines than we need, so just add the needed amount
    370369            this->magazines_ += needed_magazines;
    371             if (this->bStackMunition_)
     370            if (deployment_ == DEPLOYMENT_STACK)
    372371            {
    373372                // We stack munition, so the additional amount contributes directly to the munition of the current magazine
     
    383382    bool Munition::canRemoveMagazines(unsigned int amount) const
    384383    {
    385         if (this->bStackMunition_)
     384        if (deployment_ == DEPLOYMENT_STACK)
    386385        {
    387386            if (this->magazines_ >= amount)
     
    422421            this->magazines_ -= amount;
    423422        }
    424         else if (this->bStackMunition_)
     423        else if (deployment_ == DEPLOYMENT_STACK)
    425424        {
    426425            // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine
     
    437436    {
    438437        // If we use separate magazines, we need a user
    439         if (this->bUseSeparateMagazines_ && !user)
     438        if (deployment_ == DEPLOYMENT_SEPARATE && !user)
    440439            return false;
    441440
    442441        // If we don't use separate magazines, set user to 0
    443         if (!this->bUseSeparateMagazines_)
     442        if (!deployment_ == DEPLOYMENT_SEPARATE)
    444443            user = 0;
    445444
     
    465464        this->bLoaded_ = false;
    466465
    467         if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->bStackMunition_)
     466        if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == DEPLOYMENT_STACK)
    468467        {
    469468            const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this));
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h

    r9667 r10688  
    3939namespace orxonox
    4040{
     41    enum Deployment
     42    {
     43        DEPLOYMENT_SHARE,
     44        DEPLOYMENT_STACK,
     45        DEPLOYMENT_SEPARATE
     46    };
     47
     48
    4149    class _OrxonoxExport Munition : public BaseObject
    42     {
     50    {       
    4351        struct Magazine
    4452        {
     
    6876            inline unsigned int getMaxMunitionPerMagazine() const
    6977                { return this->maxMunitionPerMagazine_; }
     78            inline bool getUseSeparateMagazines() const
     79                { return deployment_ == DEPLOYMENT_SEPARATE; }
     80            inline bool getStackMunition() const
     81                { return deployment_ == DEPLOYMENT_STACK; }
    7082
    7183            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
     
    95107            std::map<WeaponMode*, Magazine*> currentMagazines_;
    96108
    97             bool bUseSeparateMagazines_;
    98             bool bStackMunition_;
     109            Deployment deployment_;
     110
    99111            bool bAllowMunitionRefilling_;
    100112            bool bAllowMultiMunitionRemovementUnderflow_;
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.cc

    r10650 r10688  
    134134    }
    135135
     136    /**
     137    @brief
     138        Reload all @ref orxonox::WeaponMode weapon modes of this weapon.
     139    */
    136140    void Weapon::reload()
    137141    {
  • code/branches/fabienHS15/src/orxonox/weaponsystem/Weapon.h

    r10650 r10688  
    5757            void addWeaponmode(WeaponMode* weaponmode);
    5858            WeaponMode* getWeaponmode(unsigned int index) const;
     59            inline std::multimap<unsigned int, WeaponMode*>* getAllWeaponmodes()
     60                { return &weaponmodes_; }
     61            inline int getNumWeaponModes() const
     62                { return weaponmodes_.size(); }
    5963
    6064            /**
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.cc

    r10650 r10688  
    7575        this->muzzleOrientation_ = Quaternion::IDENTITY;
    7676
     77        hudImageString_ = "WSHUD_WM_Unknown";
     78
    7779        if( GameMode::isMaster() )
    7880        {
     
    125127            this->bSoundAttached_ = true;
    126128        }
    127 
     129       
     130        // Fireing is only possible if this weapon mode is not reloading and there is enough munition
    128131        if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this))
    129132        {
     
    134137                if (this->munition_->reload(this))
    135138                {
     139                    // If true, the weapon reloads in parallel to the magazine reloading
    136140                    if (this->bParallelReload_)
     141                    {
     142                        // The time needed to reload is the maximum of the reload time of the weapon mode and the magazine.
    137143                        tempReloadtime = std::max(this->reloadTime_, this->munition_->getReloadTime());
     144                    }                       
    138145                    else
     146                    {
     147                        // The time needed to reload is the sum of the reload time of the weapon mode and the magazine.
    139148                        tempReloadtime = this->reloadTime_ + this->munition_->getReloadTime();
     149                    }                       
    140150                }
    141151            }
    142152
     153            // Mark this weapon mode as reloading and start the reload timer
    143154            this->bReloading_ = true;
    144155            this->reloadTimer_.setInterval(tempReloadtime);
     
    283294    }
    284295
    285     void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){
    286         if (this->defSndWpnFire_) {
     296    void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume)
     297    {
     298        if (this->defSndWpnFire_)
     299        {
    287300            this->defSndWpnFire_->setSource(soundPath);
    288301            this->defSndWpnFire_->setVolume(soundVolume);
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponMode.h

    r10650 r10688  
    3838#include "core/class/SubclassIdentifier.h"
    3939#include "tools/Timer.h"
     40#include "Munition.h"
    4041
    4142namespace orxonox
     
    104105            inline bool getParallelReload() const
    105106                { return this->bParallelReload_; }
     107            inline bool getReloading() const
     108                { return this->bReloading_; }
    106109
    107110
     
    147150            Vector3 getTarget();
    148151
     152            inline const std::string& getHUDImageString() const
     153                { return this->hudImageString_; }           
     154
    149155        protected:
    150156            virtual void fire() = 0;
     
    155161
    156162            float reloadTime_;
    157             bool bAutoReload_;
    158             bool bParallelReload_;
     163            bool bAutoReload_; // If true, the weapon reloads the magazine automatically.
     164            bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading.
    159165
    160166            float damage_;
     
    162168            float shielddamage_;
    163169            Vector3 muzzleOffset_;
     170
     171            std::string hudImageString_;
    164172
    165173        private:
     
    175183
    176184            Timer reloadTimer_;
    177             bool bReloading_;
     185            bool bReloading_; // If true, this weapon mode is marked as reloading.
    178186
    179187            Vector3 muzzlePosition_;
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.cc

    r10650 r10688  
    124124    }
    125125
     126    std::vector<Weapon*>* WeaponPack::getAllWeapons()
     127    {
     128        return &weapons_;       
     129    }   
     130
    126131    void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
    127132    {
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponPack.h

    r9667 r10688  
    5252            void removeWeapon(Weapon * weapon);
    5353            Weapon * getWeapon(unsigned int index) const;
     54            std::vector<Weapon*>* getAllWeapons();
    5455
    5556            inline size_t getNumWeapons() const
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.cc

    r10650 r10688  
    240240    }
    241241
     242    std::vector<WeaponPack *> * WeaponSystem::getAllWeaponPacks()
     243    {
     244        return &weaponPacks_;
     245    }   
     246
    242247    bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
    243248    {
  • code/branches/fabienHS15/src/orxonox/weaponsystem/WeaponSystem.h

    r10650 r10688  
    6767            void removeWeaponPack(WeaponPack * wPack);
    6868            WeaponPack * getWeaponPack(unsigned int index) const;
     69            std::vector<WeaponPack *> * getAllWeaponPacks();
    6970
    7071            // configure slots and firemodes
  • code/branches/fabienHS15/src/orxonox/worldentities/pawns/Pawn.cc

    r10650 r10688  
    554554    }
    555555
     556    std::vector<WeaponPack *> * Pawn::getAllWeaponPacks()
     557    {
     558        if (this->weaponSystem_)
     559            return this->weaponSystem_->getAllWeaponPacks();
     560        else
     561            return 0;       
     562    }   
     563
    556564    //Tell the Map (RadarViewable), if this is a playership
    557565    void Pawn::startLocalHumanControl()
  • code/branches/fabienHS15/src/orxonox/worldentities/pawns/Pawn.h

    r10437 r10688  
    154154            void addWeaponPackXML(WeaponPack * wPack);
    155155            WeaponPack * getWeaponPack(unsigned int index) const;
     156            std::vector<WeaponPack *> * getAllWeaponPacks();
    156157
    157158            virtual void addedWeaponPack(WeaponPack* wPack) {}
Note: See TracChangeset for help on using the changeset viewer.