Index: trunk/src/lib/util/count_pointer.h
===================================================================
--- trunk/src/lib/util/count_pointer.h	(revision 6669)
+++ trunk/src/lib/util/count_pointer.h	(revision 6669)
@@ -0,0 +1,56 @@
+/*!
+ * @file count_pointer.h Contains the Counted Pointer Class, that points to Member-Objects.
+ */
+
+#ifndef _COUNT_POINTER_H
+#define _COUNT_POINTER_H
+
+template <typename X> class CountPointer
+{
+public:
+    explicit CountPointer(X* p = 0) // allocate a new counter
+        : itsCounter(0) { if (p) itsCounter = new counter(p); }
+    ~CountPointer() { release(); }
+    CountPointer(const CountPointer& r) { acquire(r.itsCounter); }
+    CountPointer& operator=(const CountPointer& r)
+    {
+        if (this != &r) {
+            release();
+            acquire(r.itsCounter);
+        }
+        return *this;
+    }
+    X& operator*()  const { return *itsCounter->ptr; }
+    X* operator->() const { return itsCounter->ptr; }
+    X* get()        const { return itsCounter ? itsCounter->ptr : 0; }
+    bool unique()   const { return (itsCounter ? itsCounter->count == 1 : true); }
+    virtual unsigned int count() const { return (this->itsCounter ? itsCounter->count : 0); }
+private:
+
+    struct counter {
+        counter(X* p = 0, unsigned c = 1) : ptr(p), count(c) {}
+        X*          ptr;
+        unsigned    count;
+    }* itsCounter;
+
+    void acquire(counter* c)
+    {
+      // increment the count
+        itsCounter = c;
+        if (c) ++c->count;
+    }
+
+    void release()
+    {
+      // decrement the count, delete if it is 0
+        if (itsCounter) {
+            if (--itsCounter->count == 0) {
+                delete itsCounter->ptr;
+                delete itsCounter;
+            }
+            itsCounter = 0;
+        }
+    }
+};
+
+#endif /* _COUNT_POINTER_H */
Index: trunk/src/world_entities/playable.cc
===================================================================
--- trunk/src/world_entities/playable.cc	(revision 6664)
+++ trunk/src/world_entities/playable.cc	(revision 6669)
@@ -52,5 +52,5 @@
 void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
 {
-  this->weaponMan->addWeapon(weapon, configID, slotID);
+  this->weaponMan->addWeapon(weapon);
 
   this->weaponConfigChanged();
Index: trunk/src/world_entities/weapons/ammo_container.cc
===================================================================
--- trunk/src/world_entities/weapons/ammo_container.cc	(revision 6664)
+++ trunk/src/world_entities/weapons/ammo_container.cc	(revision 6669)
@@ -32,5 +32,6 @@
    this->setClassID(CL_AMMO_CONTAINER, "AmmoContainer");
 
-
+   this->energy = 0.0;
+   this->maxEnergy = maxEnergy;
 }
 
Index: trunk/src/world_entities/weapons/ammo_container.h
===================================================================
--- trunk/src/world_entities/weapons/ammo_container.h	(revision 6664)
+++ trunk/src/world_entities/weapons/ammo_container.h	(revision 6669)
@@ -22,6 +22,6 @@
   virtual ~AmmoContainer();
 
+  bool operator=(ClassID projectileType) const { return (this->projectileType == projectileType); };
   ClassID getProjectileType() const { return this->projectileType; };
-
 
   float increaseEnergy(float energy);
Index: trunk/src/world_entities/weapons/weapon.h
===================================================================
--- trunk/src/world_entities/weapons/weapon.h	(revision 6664)
+++ trunk/src/world_entities/weapons/weapon.h	(revision 6669)
@@ -16,4 +16,6 @@
 
 #include "world_entity.h"
+#include "count_pointer.h"
+#include "ammo_container.h"
 
 // FORWARD DECLARATION
@@ -105,5 +107,5 @@
     inline void setCapability(long capabilities) { this->capability = capabilities; };
     /** @returns the Capabilities of this Weapon */
-    inline long getCapability() { return this->capability; };
+    inline long getCapability() const { return this->capability; };
     void setProjectileType(ClassID projectile);
     void setProjectileType(const char* projectile);
@@ -139,4 +141,5 @@
     inline float getLoadedEnergyMax() const { return this->energyLoadedMax; };
     inline float getEnergyMax() const { return this->energyMax; };
+    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
     inline float getEnergy() const { return this->energy; };
     inline float getLoadedEnergy() const { return this->energyLoaded; };
@@ -200,4 +203,5 @@
     float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
     float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
+    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
     float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
     float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
Index: trunk/src/world_entities/weapons/weapon_manager.cc
===================================================================
--- trunk/src/world_entities/weapons/weapon_manager.cc	(revision 6664)
+++ trunk/src/world_entities/weapons/weapon_manager.cc	(revision 6669)
@@ -203,4 +203,12 @@
 }
 
+
+bool WeaponManager::addWeapon(Weapon* weapon)
+{
+  int weaponConf = this->currentConfigID;
+  int slot;
+  if (slot = this->getNextFreeSlot(weaponConf, weapon->getCapability()) == -1 )
+    this->addWeapon(weapon, weaponConf, slot);
+}
 
 /**
@@ -246,4 +254,5 @@
   //! @todo check if the weapon is already assigned to another config in another slot
   this->configs[configID][slotID] = weapon;
+  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
   if (this->parent != NULL)
   {
@@ -420,5 +429,5 @@
 /**
  * private gets the next free slot in a certain weaponconfig
- * @param the selected weaponconfig
+ * @param the selected weaponconfig -1 if none found
  */
 int WeaponManager::getNextFreeSlot(int configID, long capability)
@@ -434,4 +443,14 @@
 }
 
+CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType)
+{
+  for (unsigned int i = 0; i < this->ammo.size(); i++)
+  {
+    if (this->ammo[i]->getProjectileType() == projectileType)
+      return this->ammo[i];
+  }
+  this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType)));
+  return this->ammo.back();
+}
 
 
Index: trunk/src/world_entities/weapons/weapon_manager.h
===================================================================
--- trunk/src/world_entities/weapons/weapon_manager.h	(revision 6664)
+++ trunk/src/world_entities/weapons/weapon_manager.h	(revision 6669)
@@ -17,4 +17,7 @@
 #include "crosshair.h"
 #include "weapon.h"
+
+#include "count_pointer.h"
+#include "ammo_container.h"
 
 // FORWARD DECLARATION
@@ -72,6 +75,7 @@
 
     bool addWeapon(Weapon* weapon);
-    bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
+    bool addWeapon(Weapon* weapon, int configID, int slotID = -1);
     void removeWeapon(Weapon* weapon, int configID = -1);
+
     Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; };
 
@@ -82,4 +86,7 @@
     void previousWeaponConfig();
     void changeWeaponConfig(int weaponConfig);
+
+    float addAmmunition(ClassID projectileType, float ammo);
+
 
     /** @returns a fixed target namely the Crosshair's 3D position */
@@ -97,4 +104,5 @@
  // private:
     int getNextFreeSlot(int configID, long capability = WTYPE_ALL);
+    CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType);
 
   private:
@@ -112,4 +120,6 @@
     Crosshair*              crosshair;                                //!< an aim.
     tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
+
+    std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers
 };
 
