Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 4, 2016, 11:54:04 PM (9 years ago)
Author:
fvultier
Message:

A few modifications in the weapon system: WeaponModes may play a reload sound now. Fireing Sounds of WeaponModes may overlap now. New weapon: FlameGun, a flame thrower for close combat (e.g. for the FPS player)

Location:
code/trunk/src/orxonox/weaponsystem
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.cc

    r11071 r11108  
    7777        hudImageString_ = "Orxonox/WSHUD_WM_Unknown";
    7878
    79         if( GameMode::isMaster() )
    80         {
    81             this->defSndWpnFire_ = new WorldSound(this->getContext());
    82             this->defSndWpnFire_->setLooping(false);
    83             this->defSndWpnFire_->setVolume(0.8f);
    84             this->bSoundAttached_ = false;
    85         }
    86         else
    87             this->defSndWpnFire_ = 0;
     79        this->fireSoundPath_ = BLANKSTRING;
     80        this->fireSoundVolume_ = 1.0;
     81        this->fireSounds_.clear();
     82
     83        this->reloadSoundPath_ = BLANKSTRING;
     84        this->reloadSoundVolume_ = 1.0;
     85        this->reloadSound_ = nullptr;
    8886    }
    8987
     
    9290        if (this->isInitialized())
    9391        {
    94             if (this->defSndWpnFire_)
    95                 this->defSndWpnFire_->destroy();
     92            for (auto sound : fireSounds_)
     93            {
     94                sound->destroy();
     95            }
    9696        }
    9797    }
     
    121121    {
    122122        (*reloadTime) = this->reloadTime_;
    123         if( !this->bSoundAttached_ && GameMode::isMaster() )
    124         {
    125             assert(this->getWeapon());
    126             this->getWeapon()->attach(this->defSndWpnFire_);
    127             this->bSoundAttached_ = true;
    128         }
    129123       
    130124        // Fireing is only possible if this weapon mode is not reloading and there is enough munition
     
    147141                        // The time needed to reload is the sum of the reload time of the weapon mode and the magazine.
    148142                        tempReloadtime = this->reloadTime_ + this->munition_->getReloadTime();
    149                     }                       
     143                    }
     144                    playReloadSound();
    150145                }
     146            }
     147
     148            // For stacked munition, a reload sound is played after every fired projectile
     149            if (this->munition_->getMunitionDeployment() == MunitionDeployment::Stack)
     150            {
     151                playReloadSound();
    151152            }
    152153
     
    156157            this->reloadTimer_.startTimer();
    157158
    158             if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying()))
    159             {
    160                 this->defSndWpnFire_->play();
    161             }
    162 
     159            // Play the fire sound and fire the weapon mode
     160            this->playFireSound();
    163161            this->fire();
    164162
     
    250248    void WeaponMode::reloaded()
    251249    {
    252         if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying())
    253         {
    254             this->defSndWpnFire_->stop();
    255         }
    256250        this->bReloading_ = false;
    257251    }
     
    282276    }
    283277
    284     void WeaponMode::setDefaultSound(const std::string& soundPath)
    285     {
    286         if( this->defSndWpnFire_ )
    287             this->defSndWpnFire_->setSource(soundPath);
    288     }
    289 
    290     const std::string& WeaponMode::getDefaultSound()
    291     {
    292         if( this->defSndWpnFire_ )
    293             return this->defSndWpnFire_->getSource();
    294         else
    295             return BLANKSTRING;
    296     }
    297 
    298     void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume)
    299     {
    300         if (this->defSndWpnFire_)
    301         {
    302             this->defSndWpnFire_->setSource(soundPath);
    303             this->defSndWpnFire_->setVolume(soundVolume);
    304         }
    305     }
    306 
     278    void WeaponMode::setFireSound(const std::string& soundPath, const float soundVolume)
     279    {
     280        fireSoundPath_ = soundPath;
     281        fireSoundVolume_ = soundVolume;
     282    }
     283
     284    const std::string& WeaponMode::getFireSound()
     285    {
     286        return fireSoundPath_;
     287    }
     288
     289    void WeaponMode::setReloadSound(const std::string& soundPath, const float soundVolume)
     290    {
     291        reloadSoundPath_ = soundPath;
     292        reloadSoundVolume_ = soundVolume;
     293    }
     294
     295    const std::string& WeaponMode::getReloadSound()
     296    {
     297        return reloadSoundPath_;
     298    }
     299
     300    void WeaponMode::playFireSound()
     301    {
     302        WorldSound* unusedSound = nullptr;
     303
     304        if (!GameMode::isMaster())
     305        {
     306            return;
     307        }
     308
     309        // If no sound path or no weapon was specified, then no sound is played.
     310        if (fireSoundPath_ == BLANKSTRING || !this->getWeapon())
     311        {
     312            return;
     313        }
     314
     315        // Search in the sound list for a WorldSound that may be used. It must be an idle WorldSound instance (i.e. it is not playing a sound now)
     316        for (auto sound : fireSounds_)
     317        {
     318            if( sound && !(sound->isPlaying()))
     319            {
     320                // Unused sound found
     321                unusedSound = sound;
     322                break;
     323            }
     324        }
     325
     326        // If no unused sound was found, create a new one and add it to the list
     327        if (!unusedSound)
     328        {
     329            unusedSound = new WorldSound(this->getContext());
     330            fireSounds_.push_back(unusedSound);
     331            unusedSound->setLooping(false);
     332            unusedSound->setSource(fireSoundPath_);
     333            unusedSound->setVolume(fireSoundVolume_);
     334            this->getWeapon()->attach(unusedSound);
     335        }
     336
     337        // Play the fire sound
     338        unusedSound->play();
     339    }
     340
     341    void WeaponMode::playReloadSound()
     342    {
     343        if (!GameMode::isMaster())
     344        {
     345            return;
     346        }
     347
     348        // If no sound path or no weapon was specified, then no sound is played.
     349        if (reloadSoundPath_ == BLANKSTRING || !this->getWeapon())
     350        {
     351            return;
     352        }
     353
     354        // Create a reload WorldSound if not done yet
     355        if (!reloadSound_)
     356        {
     357            reloadSound_ = new WorldSound(this->getContext());
     358            reloadSound_->setSource(reloadSoundPath_);
     359            reloadSound_->setVolume(reloadSoundVolume_);
     360            this->getWeapon()->attach(reloadSound_);
     361        }
     362
     363        // Play the reload sound
     364        reloadSound_->play();
     365    }
    307366}
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.h

    r11071 r11108  
    3434
    3535#include <string>
     36#include <vector>
    3637#include "util/Math.h"
    3738#include "core/BaseObject.h"
     
    5455            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    5556
    56             bool fire(float* reloadTime);
     57            virtual bool fire(float* reloadTime);
    5758            bool reload();
    58 
    59             // Interacting with the default Firing sound
    60             void setDefaultSound(const std::string& soundPath);
    61             const std::string& getDefaultSound();
    62             void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume);
    6359
    6460            // Munition
     
    155151            void updateMunition();
    156152        protected:
     153            // Interacting with the firing sound
     154            void setFireSound(const std::string& soundPath, const float soundVolume = 1.0);
     155            const std::string& getFireSound();
     156            void playFireSound();
     157
     158            // Interacting with the reloading sound
     159            void setReloadSound(const std::string& soundPath, const float soundVolume = 1.0);
     160            const std::string& getReloadSound();
     161            void playReloadSound();
     162
    157163            virtual void fire() = 0;
    158164
     
    188194            Quaternion muzzleOrientation_;
    189195
    190             WorldSound* defSndWpnFire_;
    191             bool bSoundAttached_;
     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
     201            WorldSound* reloadSound_;
    192202    };
    193203}
Note: See TracChangeset for help on using the changeset viewer.