Index: code/branches/pickup2/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/branches/pickup2/src/orxonox/weaponsystem/WeaponMode.cc	(revision 5942)
+++ code/branches/pickup2/src/orxonox/weaponsystem/WeaponMode.cc	(revision 6412)
@@ -32,4 +32,6 @@
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
+#include "controllers/Controller.h"
+#include "worldentities/pawns/Pawn.h"
 
 #include "Munition.h"
@@ -37,4 +39,7 @@
 #include "WeaponPack.h"
 #include "WeaponSystem.h"
+#include "WeaponSlot.h"
+
+#include "sound/WorldSound.h"
 
 namespace orxonox
@@ -61,9 +66,26 @@
 
         this->damage_ = 0;
+
         this->muzzleOffset_ = Vector3::ZERO;
+        this->muzzlePosition_ = Vector3::ZERO;
+        this->muzzleOrientation_ = Quaternion::IDENTITY;
+
+        if( GameMode::isMaster() )
+        {
+            this->defSndWpnFire_ = new WorldSound(this);
+            this->defSndWpnFire_->setLooping(false);
+            this->bSoundAttached_ = false;
+        }
+        else
+            this->defSndWpnFire_ = 0;
     }
 
     WeaponMode::~WeaponMode()
     {
+        if (this->isInitialized())
+        {
+            if (this->defSndWpnFire_)
+                this->defSndWpnFire_->destroy();
+        }
     }
 
@@ -90,4 +112,10 @@
     {
         (*reloadTime) = this->reloadTime_;
+        if( !this->bSoundAttached_ && GameMode::isMaster() )
+        {
+            assert(this->getWeapon());
+            this->getWeapon()->attach(this->defSndWpnFire_);
+            this->bSoundAttached_ = true;
+        }
 
         if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this))
@@ -108,4 +136,9 @@
             this->reloadTimer_.startTimer();
 
+            if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying()))
+            {
+                this->defSndWpnFire_->play();
+            }
+
             this->fire();
 
@@ -145,5 +178,9 @@
     {
         this->munitionname_ = munitionname;
-        this->munitiontype_ = ClassByString(this->munitionname_);
+        Identifier* identifier = ClassByString(this->munitionname_);
+        if (identifier)
+            this->munitiontype_ = identifier;
+        else
+            COUT(2) << "Warning: No munition class defined in WeaponMode " << this->getName() << std::endl;
         this->updateMunition();
     }
@@ -191,29 +228,49 @@
     void WeaponMode::reloaded()
     {
+        if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying())
+        {
+            this->defSndWpnFire_->stop();
+        }
         this->bReloading_ = false;
     }
 
-    Vector3 WeaponMode::getMuzzlePosition() const
+    void WeaponMode::computeMuzzleParameters(const Vector3& target)
     {
         if (this->weapon_)
-            return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_);
-        else
-            return this->muzzleOffset_;
-    }
-
-    const Quaternion& WeaponMode::getMuzzleOrientation() const
+        {
+            this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_;
+
+            Vector3 muzzleDirection;
+            muzzleDirection = target - this->muzzlePosition_;
+//             COUT(0) << "muzzleDirection " << muzzleDirection << endl;
+            this->muzzleOrientation_ = (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection) * this->weapon_->getWorldOrientation();
+        }
+        else
+        {
+            this->muzzlePosition_ = this->muzzleOffset_;
+            this->muzzleOrientation_ = Quaternion::IDENTITY;
+        }
+    }
+
+    Vector3 WeaponMode::getMuzzleDirection() const
     {
         if (this->weapon_)
-            return this->weapon_->getWorldOrientation();
-        else
-            return Quaternion::IDENTITY;
-    }
-
-    Vector3 WeaponMode::getMuzzleDirection() const
-    {
-        if (this->weapon_)
-            return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT);
+            return (this->getMuzzleOrientation() * WorldEntity::FRONT);
         else
             return WorldEntity::FRONT;
     }
+
+    void WeaponMode::setDefaultSound(const std::string& soundPath)
+    {
+        if( this->defSndWpnFire_ )
+            this->defSndWpnFire_->setSource(soundPath);
+    }
+
+    const std::string& WeaponMode::getDefaultSound()
+    {
+        if( this->defSndWpnFire_ )
+            return this->defSndWpnFire_->getSource();
+        else
+            return BLANKSTRING;
+    }
 }
