Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11108 for code/trunk


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
Files:
6 added
28 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/levels/includes/weaponSettingsFPS.oxi

    r11052 r11108  
    1010      <WeaponSet firemode=0 />
    1111      <WeaponSet firemode=1 />
     12      <WeaponSet firemode=2 />
    1213    </weaponsets>
    1314    <weaponpacks>
     
    1920        </links>
    2021        <Weapon>
    21           <HsW01 mode=0 munitionpershot=0 delay=0.0 damage=2.5 material="Flares/point_lensflare" muzzleoffset=" 0.7, -0.3, -3" />
    22           <LightningGun mode=1 muzzleoffset="0,0,0" damage=3.14159 shielddamage=20/>
     22          <HsW01 mode=0 munitionpershot=0 delay=0.0 damage=2.5 material="Flares/point_lensflare" muzzleoffset="0.7,-0.3,-3" />
     23          <FlameGun mode=1 munitionpershot=1 damage=0.5 muzzleoffset="0.7,-0.3,-3"/>
     24          <LightningGun mode=2 muzzleoffset="0,0,0" damage=3.14159 shielddamage=20/>
    2325        </Weapon>
    24         <LaserGun
    25             position="0,0,0"
    26             munitionType="LaserGunMunition"
    27             bulletLoadingTime="0.2"
    28             magazineLoadingTime="5.0"
    29             speed="1000"
    30             unlimitedMunition=true
    31         />
    32         <!--LaserGun
    33             position="0,0,0"
    34             munitionType="LaserGunMunition"
    35             bulletLoadingTime="0.2"
    36             magazineLoadingTime="5.0"
    37             speed="1250"
    38             unlimitedMunition=true
    39         />
    40       </WeaponPack>
    41       <WeaponPack firemode=1>
    42         <Fusion
    43             position="0,0,0"
    44             munitionType="FusionMunition"
    45             bulletLoadingTime="0.3"
    46             magazineLoadingTime="3"
    47             speed="600"
    48             unlimitedMunition=true
    49         /-->
    5026      </WeaponPack>
    5127    </weaponpacks>
    5228    <munition>
    5329      <LaserMunition initialmagazines=8 maxmagazines=8 munitionpermagazine=5 replenishamount=1 replenishinterval=7.5/>
     30      <FlameMunition initialmagazines=8 maxmagazines=8 munitionpermagazine=20/>
    5431      <LightningMunition initialmagazines=2 maxmagazines=2 munitionpermagazine=8 />
    5532    </munition>
  • code/trunk/data/levels/includes/weaponSettingsGhost.oxi

    r11052 r11108  
    22      <WeaponSlot position=" 1.3,4.66,-20" />
    33      <WeaponSlot position="-1.3,4.66,-20" />
    4       <WeaponSlot position="13.7,4.66,-20" />
    5       <WeaponSlot position="-16.3,4.66,-20" />
     4      <WeaponSlot position="0,4.66,-20" />
    65    </weaponslots>
    76    <weaponsets>
     
    98      <WeaponSet firemode=1 />
    109      <WeaponSet firemode=2 />
    11       <WeaponSet firemode=2 />
     10      <WeaponSet firemode=3 />
    1211    </weaponsets>
    1312    <weaponpacks>
     
    1716          <DefaultWeaponmodeLink firemode=1 weaponmode=1 />
    1817          <DefaultWeaponmodeLink firemode=2 weaponmode=2 />
     18          <DefaultWeaponmodeLink firemode=3 weaponmode=3 />
    1919        </links>
    2020        <Weapon>
    2121          <HsW01 mode=0 munitionpershot=1 healthdamage=3.14159 delay=0 material="Flares/point_lensflare" />
    2222          <HsW01 mode=0 munitionpershot=1 healthdamage=3.14159 delay=0.125 material="Flares/point_lensflare" muzzleoffset=" 0.5,0.6,1.7" />
    23           <LightningGun mode=1 muzzleoffset="0,0,0" damage=30 shielddamage=10 />
     23          <FusionFire mode=1 muzzleoffset="0,0,0" damage=30 shielddamage=10 />
    2424        </Weapon>
    2525        <Weapon>
    2626          <HsW01 mode=0 munitionpershot=1 damage=3.14159 delay=0  material="Flares/point_lensflare" />
    2727          <HsW01 mode=0 munitionpershot=1 damage=3.14159 delay=0.125 material="Flares/point_lensflare" muzzleoffset="-0.5,0.6,1.7" />
    28           <LightningGun mode=1 muzzleoffset="0,0,0" damage=30 shielddamage=10 />
     28          <FusionFire mode=1 muzzleoffset="0,0,0" damage=30 shielddamage=10 />
    2929        </Weapon>
    3030        <Weapon>
    31           <SimpleRocketFire mode=2 munitionpershot=1 muzzleoffset="0,0,0" damage=50 />
    32         </Weapon>
    33         <Weapon>
    34           <SimpleRocketFire mode=2 munitionpershot=1 muzzleoffset="0,0,0" damage=50 delay=0.1 />
     31          <FlameGun mode=2 munitionpershot=1 damage=0.5 muzzleoffset="0,0,0"/>
     32          <SplitGun mode=3 munitionpershot=1 damage=6.0 muzzleoffset="0.5,0.6,1.7" splittime=0.2 numberofsplits=2 numberofchilds=3 spread=0.1 damagereduction=2.0 />
    3533        </Weapon>
    3634      </WeaponPack>
     
    3836    <munition>
    3937      <LaserMunition initialmagazines=8 maxmagazines=8 munitionpermagazine=10 replenishamount=1 replenishinterval=7.5/>
    40       <LightningMunition initialmagazines=4 maxmagazines=4 munitionpermagazine=8 />
    41       <RocketMunition initialmagazines=5 maxmagazines=5 munitionpermagazine=1 />
     38      <FusionMunition initialmagazines=4 maxmagazines=4 munitionpermagazine=8 />
     39      <FlameMunition initialmagazines=8 maxmagazines=8 munitionpermagazine=20/>
     40      <SplitMunition initialmagazines=8 maxmagazines=8 munitionpermagazine=5/>
    4241    </munition>
  • code/trunk/data/levels/templates/pickupRepresentationTemplates.oxt

    r11052 r11108  
    360360        <MunitionContainer munitiontype="RocketMunition" munitionamount=0 magazinesamount=10 />
    361361        <MunitionContainer munitiontype="IceMunition" munitionamount=0 magazinesamount=10 />
     362        <MunitionContainer munitiontype="FlameMunition" munitionamount=0 magazinesamount=10 />
    362363        <MunitionContainer munitiontype="GravityBombMunition" munitionamount=0 magazinesamount=10 />
    363364        <MunitionContainer munitiontype="MineMunition" munitionamount=0 magazinesamount=10 />
  • code/trunk/src/modules/weapons/munitions/CMakeLists.txt

    r11052 r11108  
    66  GravityBombMunition.cc
    77  IceMunition.cc
     8  FlameMunition.cc
    89  SplitMunition.cc
    910  MineMunition.cc
  • code/trunk/src/modules/weapons/munitions/LaserMunition.cc

    r11071 r11108  
    5555        this->replenishAmount_ = 1;
    5656
    57         this->reloadTime_ = 0.5f;
     57        this->reloadTime_ = 0.6f;
    5858    }
    5959}
  • code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc

    r11099 r11108  
    5454        this->bDestroy_ = false;
    5555
     56        // Default is destroying the projectile after collision
     57        this->destroyAfterCollision_ = true;
     58
    5659        // Default damage must be zero, otherwise it would be above zero if no settings are made in the weaponsettings xml file.
    5760        // same thing for all weaponmodes files
     
    8790                return false;
    8891
    89             this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
    90                                     // The projectile is destroyed by its tick()-function (in the following tick).
     92            if (getDestroyAfterCollision())
     93            {
     94                this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
     95                                        // The projectile is destroyed by its tick()-function (in the following tick).
     96                                        // TODO: Use destroyLater() for this
     97            }
    9198
    9299            Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is nullptr
  • code/trunk/src/modules/weapons/projectiles/BasicProjectile.h

    r11099 r11108  
    119119            bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
    120120            void destroyCheck(void);
     121            inline void setDestroyAfterCollision(bool destroyAfterCollision)
     122                { destroyAfterCollision_ = destroyAfterCollision; }
     123            inline bool getDestroyAfterCollision() const
     124                { return destroyAfterCollision_; }
    121125
    122126        private:
     
    130134
    131135            bool bDestroy_; //!< Boolean, to check whether a projectile should be destroyed.
     136            bool destroyAfterCollision_; //!< Boolean, defines whether the projectile gets detroyed after a collision.
    132137    };
    133138}
  • code/trunk/src/modules/weapons/projectiles/CMakeLists.txt

    r11052 r11108  
    77  SplitGunProjectile.cc
    88  IceGunProjectile.cc
     9  FlameGunProjectile.cc
    910  Rocket.cc
    1011  RocketOld.cc
  • code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc

    r11071 r11108  
    4747
    4848        this->textureIndex_ = 1;
    49         this->setMass(2);
     49        this->setMass(0.1f);
    5050        this->setCollisionType(CollisionType::Dynamic);
    5151        this->maxTextureIndex_ = 8;
  • code/trunk/src/modules/weapons/projectiles/ParticleProjectile.cc

    r11071 r11108  
    4343    RegisterClass(ParticleProjectile);
    4444
    45     ParticleProjectile::ParticleProjectile(Context* context) : BillboardProjectile(context)
     45    ParticleProjectile::ParticleProjectile(Context* context) : Projectile(context)
    4646    {
    4747        RegisterObject(ParticleProjectile);
    4848
    49         if (GameMode::showsGraphics())
    50         {
    51             // Create the particles.
    52             this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::Normal);
    53             this->attachOgreObject(this->particles_->getParticleSystem());
    54             this->particles_->setKeepParticlesInLocalSpace(0);
     49        this->particles_ = nullptr;
    5550
    56             for (unsigned int i = 0; i < this->particles_->getNumEmitters(); ++i)
    57                 this->particles_->getEmitter(i)->setDirection(-WorldEntity::FRONT);
    58         }
    59         else
    60             this->particles_ = nullptr;
     51        //setEffect("Orxonox/sparks2");
    6152    }
    6253
     
    8273            this->particles_->setEnabled(this->isVisible());
    8374    }
     75
     76    void ParticleProjectile::setEffect(const std::string& effect)
     77    {
     78        // If we already have a particle interface, delete it
     79        if (this->particles_)
     80        {
     81            this->detachOgreObject(this->particles_->getParticleSystem());
     82            delete this->particles_;
     83            this->particles_ = nullptr;
     84        }
     85
     86        if (GameMode::showsGraphics())
     87        {
     88            // Create the particles.
     89            this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), effect, LODParticle::Normal);
     90            this->attachOgreObject(this->particles_->getParticleSystem());
     91            this->particles_->setKeepParticlesInLocalSpace(0);
     92
     93            for (unsigned int i = 0; i < this->particles_->getNumEmitters(); ++i)
     94                this->particles_->getEmitter(i)->setDirection(-WorldEntity::FRONT);
     95        }
     96        else
     97        {
     98            this->particles_ = nullptr;
     99        }
     100    }
    84101}
  • code/trunk/src/modules/weapons/projectiles/ParticleProjectile.h

    r11071 r11108  
    4848    @ingroup WeaponsProjectiles
    4949    */
    50     class _WeaponsExport ParticleProjectile : public BillboardProjectile
     50    class _WeaponsExport ParticleProjectile : public Projectile
    5151    {
    5252        public:
     
    5454            virtual ~ParticleProjectile();
    5555            virtual void changedVisibility() override;
     56            virtual void setEffect(const std::string& effect);
    5657
    5758        private:
  • code/trunk/src/modules/weapons/projectiles/Projectile.cc

    r11071 r11108  
    5454        if (GameMode::isMaster())
    5555        {
    56             this->setMass(1.0f);
     56            this->setMass(0.1f);
    5757            this->enableCollisionCallback();
    5858            this->setCollisionResponse(false);
  • code/trunk/src/modules/weapons/projectiles/SplitGunProjectile.cc

    r11099 r11108  
    5252        this->spread_ = 0.2f;
    5353        this->damageReduction_ = 1.0f;
     54        this->splitSound_ = nullptr;
     55
     56        this->setSplitSound("sounds/Weapon_SplitGun.ogg", 0.8);
     57    }
     58
     59    SplitGunProjectile::~SplitGunProjectile()
     60    {
     61        if (this->isInitialized())
     62        {
     63            if (splitSound_)
     64            {
     65                splitSound_->destroy();
     66            }
     67        }
    5468    }
    5569
     
    158172
    159173            numberOfSplits_ = 0;
     174
     175            if (splitSound_)
     176            {
     177                splitSound_->play();
     178            }
    160179        }
    161180    }
     181
     182    void SplitGunProjectile::setSplitSound(const std::string& soundPath, const float soundVolume)
     183    {
     184        if (!splitSound_)
     185        {
     186            this->splitSound_ = new WorldSound(this->getContext());
     187            this->splitSound_->setLooping(false);
     188            this->attach(splitSound_);
     189        }
     190
     191        this->splitSound_->setSource(soundPath);
     192        this->splitSound_->setVolume(soundVolume);
     193    }
    162194}
  • code/trunk/src/modules/weapons/projectiles/SplitGunProjectile.h

    r11052 r11108  
    2828
    2929/**
    30     @file IceGunProjectile.h
     30    @file SplitGunProjectile.h
    3131    @brief Definition of the SplitGunProjectile class.
    3232*/
     
    4040#include "tools/Timer.h"
    4141#include "BillboardProjectile.h"
     42#include "sound/WorldSound.h"
    4243
    4344namespace orxonox
     
    5556        public:
    5657            SplitGunProjectile(Context* context);
    57             virtual ~SplitGunProjectile() {}
     58            virtual ~SplitGunProjectile();
    5859
    5960            virtual void setNumberOfSplits(int numberOfSplits);
     
    6263            virtual void setSpread(float spread);
    6364            virtual void setDamageReduction(float damageReduction);
     65            virtual void setSplitSound(const std::string& soundPath, const float soundVolume = 1.0);
    6466
    6567        private:           
     
    7072            float damageReduction_; //The damage of a child projectile is reduced by this factor
    7173            Timer splitTimer_;
     74            WorldSound* splitSound_; //Sound played if the projectile splits
    7275
    7376            virtual void split();           
  • code/trunk/src/modules/weapons/weaponmodes/CMakeLists.txt

    r11052 r11108  
    77  SplitGun.cc
    88  IceGun.cc
     9  FlameGun.cc
    910  RocketFire.cc
    1011  RocketFireOld.cc
  • code/trunk/src/modules/weapons/weaponmodes/EnergyDrink.cc

    r11052 r11108  
    5959        this->speed_ = 750.0f;
    6060        this->delay_ = 0.0f;
     61        this->timerStarted_ = false;
    6162        this->setMunitionName("FusionMunition");
     63        this->setFireSound("sounds/Weapon_EnergyDrink.ogg");
    6264
    6365        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&EnergyDrink::shot, this)));
     
    9395    void EnergyDrink::fire()
    9496    {
    95         this->delayTimer_.startTimer();
     97        if (!timerStarted_)
     98        {
     99            this->delayTimer_.startTimer();
     100            this->timerStarted_ = true;
     101        }
     102    }
     103
     104    bool EnergyDrink::fire(float* reloadTime)
     105    {
     106        if (!timerStarted_)
     107        {
     108            return WeaponMode::fire(reloadTime);
     109        }
     110
     111        return false;
    96112    }
    97113
     
    102118    void EnergyDrink::shot()
    103119    {
     120        this->timerStarted_ = false;
     121
    104122        // Create the projectile
    105123        Projectile* projectile = new Projectile(this->getContext());
  • code/trunk/src/modules/weapons/weaponmodes/EnergyDrink.h

    r11071 r11108  
    5757            virtual ~EnergyDrink() {}
    5858
     59            virtual bool fire(float* reloadTime) override;
    5960            virtual void fire() override;
    6061            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
     
    8990            float delay_; //!< The firing delay.
    9091            Timer delayTimer_; //!< The timer to delay the firing.
     92            bool timerStarted_;
    9193    };
    9294}
  • code/trunk/src/modules/weapons/weaponmodes/FusionFire.cc

    r11052 r11108  
    5858
    5959        this->setMunitionName("FusionMunition");
     60        this->setFireSound("sounds/Weapon_FusionFire.ogg");
    6061
    6162        hudImageString_ = "Orxonox/WSHUD_WM_FusionFire";
  • code/trunk/src/modules/weapons/weaponmodes/GravityBombFire.cc

    r11052 r11108  
    3030
    3131        this->setMunitionName("GravityBombMunition");
    32         this->setDefaultSoundWithVolume("sounds/Rocket_launch.ogg",0.8);    ///< sets sound of the bomb as it is fired.
     32        this->setFireSound("sounds/Rocket_launch.ogg",0.8);    ///< sets sound of the bomb as it is fired.
    3333
    3434        hudImageString_ = "Orxonox/WSHUD_WM_GravityBombFire";
  • code/trunk/src/modules/weapons/weaponmodes/HsW01.cc

    r11052 r11108  
    6262        this->setMunitionName("LaserMunition");
    6363        this->mesh_ = "laserbeam.mesh";
    64         this->sound_ = "sounds/Weapon_HsW01.ogg";
    6564
    6665
     
    6867        this->delayTimer_.stopTimer();
    6968
    70         this->setDefaultSound(this->sound_);
     69        this->setFireSound("sounds/Weapon_HsW01.ogg");
     70        this->setReloadSound("sounds/Reload_HsW01.ogg", 0.5);
    7171
    7272        hudImageString_ = "Orxonox/WSHUD_WM_HsW01";
  • code/trunk/src/modules/weapons/weaponmodes/IceGun.cc

    r11052 r11108  
    6060
    6161        this->setMunitionName("IceMunition");
    62         this->setDefaultSound("sounds/Weapon_LightningGun.ogg");
     62        this->setFireSound("sounds/Weapon_LightningGun.ogg");
     63        this->setReloadSound("sounds/Reload_IceGun.ogg", 0.4);
    6364
    6465        hudImageString_ = "Orxonox/WSHUD_WM_IceGun";
  • code/trunk/src/modules/weapons/weaponmodes/LaserFire.cc

    r11052 r11108  
    4141#include "worldentities/pawns/Pawn.h"
    4242
    43 #include "weapons/projectiles/ParticleProjectile.h"
     43#include "weapons/projectiles/BillboardProjectile.h"
    4444
    4545namespace orxonox
     
    5656
    5757        this->setMunitionName("LaserMunition");
     58        this->setFireSound("sounds/Weapon_LaserFire.ogg");
     59        this->setReloadSound("sounds/Reload_LaserFire.ogg", 0.8);
    5860
    5961        hudImageString_ = "Orxonox/WSHUD_WM_LaserFire";
     
    6668    void LaserFire::fire()
    6769    {
    68         ParticleProjectile* projectile = new ParticleProjectile(this->getContext());
     70        BillboardProjectile* projectile = new BillboardProjectile(this->getContext());
    6971
    7072        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
  • code/trunk/src/modules/weapons/weaponmodes/LightningGun.cc

    r11052 r11108  
    5555
    5656        this->setMunitionName("LightningMunition");
    57         this->setDefaultSound("sounds/Weapon_LightningGun.ogg");
     57        this->setFireSound("sounds/Weapon_LightningGun.ogg");
    5858
    5959        hudImageString_ = "Orxonox/WSHUD_WM_LightningGun";
  • code/trunk/src/modules/weapons/weaponmodes/MineGun.cc

    r11052 r11108  
    5757
    5858        this->setMunitionName("MineMunition");
    59         this->setDefaultSound("sounds/mineactivate.ogg");
     59        this->setFireSound("sounds/mineactivate.ogg");
    6060
    6161        hudImageString_ = "Orxonox/WSHUD_WM_MineGun";
  • code/trunk/src/modules/weapons/weaponmodes/SimpleRocketFire.cc

    r11052 r11108  
    6262
    6363        this->setMunitionName("RocketMunition");
    64         this->setDefaultSoundWithVolume("sounds/Rocket_launch.ogg",0.4f);
     64        this->setFireSound("sounds/Rocket_launch.ogg",0.4f);
    6565        // The firing sound of the Rocket is played in Rocket.cc (because of OpenAl sound positioning)
    6666
  • code/trunk/src/modules/weapons/weaponmodes/SplitGun.cc

    r11052 r11108  
    6161
    6262        this->setMunitionName("SplitMunition");
    63         this->setDefaultSound("sounds/Weapon_LightningGun.ogg");
     63        this->setFireSound("sounds/Weapon_SplitGun.ogg", 0.5);
     64        this->setReloadSound("sounds/Reload_SplitGun.ogg", 0.8);
    6465
    6566        hudImageString_ = "Orxonox/WSHUD_WM_SplitGun";
  • 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.