Index: code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt	(revision 2915)
@@ -6,4 +6,5 @@
   WeaponSlot.cc
   WeaponSystem.cc
+  DefaultWeaponmodeLink.cc
 )
 
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc	(revision 2915)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc	(revision 2915)
@@ -0,0 +1,63 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "DefaultWeaponmodeLink.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "WeaponSystem.h"
+
+namespace orxonox
+{
+    CreateFactory(DefaultWeaponmodeLink);
+
+    DefaultWeaponmodeLink::DefaultWeaponmodeLink(BaseObject* creator) : BaseObject(creator)
+    {
+        RegisterObject(DefaultWeaponmodeLink);
+
+        this->firemode_ = WeaponSystem::FIRE_MODE_UNASSIGNED;
+        this->weaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED;
+
+COUT(0) << "+DefaultWeaponmodeLink" << std::endl;
+    }
+
+    DefaultWeaponmodeLink::~DefaultWeaponmodeLink()
+    {
+COUT(0) << "~DefaultWeaponmodeLink" << std::endl;
+    }
+
+    void DefaultWeaponmodeLink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(DefaultWeaponmodeLink, XMLPort, xmlelement, mode);
+
+        XMLPortParam(DefaultWeaponmodeLink, "firemode",   setFiremode,   getFiremode,   xmlelement, mode);
+        XMLPortParam(DefaultWeaponmodeLink, "weaponmode", setWeaponmode, getWeaponmode, xmlelement, mode);
+    }
+}
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h	(revision 2915)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h	(revision 2915)
@@ -0,0 +1,62 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#ifndef _DefaultWeaponmodeLink_H__
+#define _DefaultWeaponmodeLink_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/BaseObject.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport DefaultWeaponmodeLink : public BaseObject
+    {
+        public:
+            DefaultWeaponmodeLink(BaseObject* creator);
+            virtual ~DefaultWeaponmodeLink();
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+            inline void setFiremode(const unsigned int firemode)
+                { this->firemode_ = firemode; }
+            inline unsigned int getFiremode() const
+                { return this->firemode_; }
+
+            inline void setWeaponmode(const unsigned int weaponmode)
+                { this->weaponmode_ = weaponmode; }
+            inline unsigned int getWeaponmode() const
+                { return this->weaponmode_; }
+
+        private:
+            unsigned int firemode_;
+            unsigned int weaponmode_;
+    };
+}
+
+#endif /* _DefaultWeaponmodeLink_H__ */
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc	(revision 2915)
@@ -34,4 +34,5 @@
 
 #include "Munition.h"
+#include "WeaponPack.h"
 #include "WeaponSystem.h"
 
@@ -64,4 +65,6 @@
     {
 COUT(0) << "~Weapon" << std::endl;
+        if (this->isInitialized() && this->weaponPack_)
+            this->weaponPack_->removeWeapon(this);
     }
 
@@ -69,4 +72,5 @@
     {
         SUPER(Weapon, XMLPort, xmlelement, mode);
+
         XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
         XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc	(revision 2915)
@@ -23,5 +23,6 @@
  *      Martin Polak
  *   Co-authors:
- *      ... *
+ *      ...
+ *
  */
 
@@ -36,4 +37,5 @@
 #include "WeaponSlot.h"
 #include "WeaponSystem.h"
+#include "DefaultWeaponmodeLink.h"
 
 namespace orxonox
@@ -55,5 +57,13 @@
 
         if (this->isInitialized() && this->weaponSystem_)
+        {
             this->weaponSystem_->removeWeaponPack(this);
+
+            while (!this->weapons_.empty())
+                delete (*this->weapons_.begin());
+
+            for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); )
+                delete (*(it++));
+        }
     }
 
@@ -63,4 +73,5 @@
 
         XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
+        XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode);
     }
 
@@ -80,4 +91,13 @@
     }
 
+    void WeaponPack::removeWeapon(Weapon * weapon)
+    {
+        if (!weapon)
+            return;
+
+        this->weapons_.erase(weapon);
+        weapon->setWeaponPack(0);
+    }
+
     Weapon * WeaponPack::getWeapon(unsigned int index) const
     {
@@ -94,8 +114,8 @@
     }
 
-    void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)
+    void WeaponPack::setWeaponSystemToAllWeapons()
     {
         for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
-            (*it)->setWeaponSystem(weaponSystem);
+            (*it)->setWeaponSystem(this->weaponSystem_);
     }
 
@@ -108,3 +128,30 @@
         }
     }
+
+    void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
+    {
+        this->links_.insert(link);
+    }
+
+    DefaultWeaponmodeLink* WeaponPack::getDefaultWeaponmodeLink(unsigned int index) const
+    {
+        unsigned int i = 0;
+        for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
+        {
+            if (i == index)
+                return (*it);
+
+            ++i;
+        }
+        return 0;
+    }
+
+    unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const
+    {
+        for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
+            if ((*it)->getFiremode() == firemode)
+                return (*it)->getWeaponmode();
+
+        return WeaponSystem::WEAPON_MODE_UNASSIGNED;
+    }
 }
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h	(revision 2915)
@@ -50,4 +50,5 @@
 
             void addWeapon(Weapon * weapon);
+            void removeWeapon(Weapon * weapon);
             Weapon * getWeapon(unsigned int index) const;
 
@@ -55,17 +56,24 @@
                 { return this->weapons_.size(); }
 
-            unsigned int getDesiredWeaponmode(unsigned int firemode) { return 0; } // TODO
+            void addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link);
+            DefaultWeaponmodeLink* getDefaultWeaponmodeLink(unsigned int index) const;
 
-            void attachNeededMunitionToAllWeapons();
+            unsigned int getDesiredWeaponmode(unsigned int firemode) const;
 
             inline void setWeaponSystem(WeaponSystem *weaponSystem)
-                { this->weaponSystem_ = weaponSystem; this->setWeaponSystemToAllWeapons(weaponSystem); }
+            {
+                this->weaponSystem_ = weaponSystem;
+                this->setWeaponSystemToAllWeapons();
+                this->attachNeededMunitionToAllWeapons();
+            }
             inline WeaponSystem * getWeaponSystem() const
                 { return this->weaponSystem_; }
 
         private:
-            void setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem);
+            void setWeaponSystemToAllWeapons();
+            void attachNeededMunitionToAllWeapons();
 
             std::set<Weapon *> weapons_;
+            std::set<DefaultWeaponmodeLink *> links_;
             WeaponSystem * weaponSystem_;
     };
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc	(revision 2915)
@@ -23,5 +23,6 @@
  *      Martin Polak
  *   Co-authors:
- *      ... *
+ *      ...
+ *
  */
 
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc	(revision 2915)
@@ -63,12 +63,18 @@
                 this->pawn_->setWeaponSystem(0);
 
-            for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
-                delete (it++)->second;
-
-            for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
-                delete (*(it++));
-
-            for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
-                delete (*(it++));
+//            for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
+//                delete (it++)->second;
+            while (!this->weaponSets_.empty())
+                delete (this->weaponSets_.begin()->second);
+
+//            for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
+//                delete (*(it++));
+            while (!this->weaponPacks_.empty())
+                delete (*this->weaponPacks_.begin());
+
+//            for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
+//                delete (*(it++));
+            while (!this->weaponSlots_.empty())
+                delete (*this->weaponSlots_.begin());
         }
     }
@@ -79,5 +85,5 @@
             return;
 
-        this->weaponSlots_.insert(wSlot);
+        this->weaponSlots_.push_back(wSlot);
         wSlot->setWeaponSystem(this);
     }
@@ -91,5 +97,12 @@
             this->removeWeaponPack(wSlot->getWeapon()->getWeaponPack());
 
-        this->weaponSlots_.erase(wSlot);
+        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+        {
+            if ((*it) == wSlot)
+            {
+                this->weaponSlots_.erase(it);
+                break;
+            }
+        }
     }
 
@@ -97,5 +110,5 @@
     {
         unsigned int i = 0;
-        for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+        for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
         {
             ++i;
@@ -159,5 +172,5 @@
 
         unsigned int freeSlots = 0;
-        for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
         {
             if (!(*it)->isOccupied())
@@ -175,5 +188,5 @@
         // Attach all weapons to the first free slots (and to the Pawn)
         unsigned int i = 0;
-        for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+        for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
         {
             if (!(*it)->isOccupied() && i < wPack->getNumWeapons())
@@ -196,5 +209,4 @@
         this->weaponPacks_.insert(wPack);
         wPack->setWeaponSystem(this);
-        wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this?
 
         return true;
@@ -231,5 +243,16 @@
     bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
     {
-        // TODO
+        if (!wSlot1 || !wSlot2)
+            return false;
+
+        Weapon* weapon1 = wSlot1->getWeapon();
+        Weapon* weapon2 = wSlot2->getWeapon();
+
+        wSlot1->attachWeapon(weapon2);
+        wSlot2->attachWeapon(weapon1);
+
+        return true;
+        // In the future, certain weapons might not fit to some slots. Swapping would then be
+        // impossible and the returnvalue would be false.
     }
 
Index: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
===================================================================
--- code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h	(revision 2914)
+++ code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h	(revision 2915)
@@ -35,4 +35,5 @@
 #include <set>
 #include <map>
+#include <vector>
 
 #include "core/BaseObject.h"
@@ -93,5 +94,5 @@
         private:
             std::map<unsigned int, WeaponSet *> weaponSets_;
-            std::set<WeaponSlot *> weaponSlots_;
+            std::vector<WeaponSlot *> weaponSlots_;
             std::set<WeaponPack *> weaponPacks_;
             std::map<std::string, Munition *> munitionSet_;
