Index: code/branches/pickup2/src/orxonox/pickup/PickupSpawner.cc
===================================================================
--- code/branches/pickup2/src/orxonox/pickup/PickupSpawner.cc	(revision 5947)
+++ code/branches/pickup2/src/orxonox/pickup/PickupSpawner.cc	(revision 5953)
@@ -46,4 +46,5 @@
 namespace orxonox
 {
+
     const float PickupSpawner::bounceSpeed_s = 6.0f;
     const float PickupSpawner::rotationSpeed_s = 1.0f;
@@ -60,10 +61,30 @@
     PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator)
     {
+        this->initialize();
+    }
+
+    PickupSpawner::PickupSpawner(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)
+    {
+        this->initialize();
+  
+        //TODO: Does this actually work?
+        this->itemTemplateName_ = item->getIdentifier()->getName();
+        this->itemTemplate_ = Template::getTemplate(this->itemTemplateName_);
+
+        this->triggerDistance_ = triggerDistance;
+        this->respawnTime_ = respawnTime;
+        this->setMaxSpawnedItems(maxSpawnedItems);
+    }
+
+    void PickupSpawner::initialize(void)
+    {
         RegisterObject(PickupSpawner);
 
-        this->itemTemplate_ = 0;
+        this->itemTemplate_ = NULL;
         this->triggerDistance_ = 20;
         this->respawnTime_ = 0.0f;
         this->tickSum_ = 0.0f;
+        this->maxSpawnedItems_ = INF;
+        this->spawnsRemaining_ = INF;
     }
 
@@ -92,4 +113,5 @@
         XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
         XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
+        XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode);
 
         //TODO: Kill hack.
@@ -137,4 +159,10 @@
     }
 
+    void PickupSpawner::setMaxSpawnedItems(int items)
+    {
+        this->maxSpawnedItems_ = items;
+        this->spawnsRemaining_ = items;
+    }
+
     /**
     @brief
@@ -148,4 +176,5 @@
         if (this->isActive())
         {
+            //! Triggers as soon as a Pawn is in the specified distance.
             for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
             {
@@ -154,4 +183,6 @@
                     this->trigger(*it);
             }
+
+            //! Animation.
             this->yaw(Radian(rotationSpeed_s*dt));
             this->tickSum_ += bounceSpeed_s*dt;
@@ -174,18 +205,23 @@
     void PickupSpawner::trigger(Pawn* pawn)
     {
-        if (this->isActive() && this->itemTemplate_ && this->itemTemplate_->getBaseclassIdentifier())
-        {
-            BaseObject* newObject = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this);
-            BaseItem* asItem = orxonox_cast<BaseItem*>(newObject);
-            if (asItem)
+        if (this->isActive() && this->itemTemplate_ && this->itemTemplate_->getBaseclassIdentifier()) //!< Checks whether PickupItem is active, amongst other things.
+        {
+            BaseItem* item = this->getItem();
+            if (item != NULL) //!< If the conversion was successful.
             {
-                asItem->setPickupIdentifier(this->itemTemplateName_);
-                asItem->addTemplate(this->itemTemplate_);
-
-                if (asItem->pickedUp(pawn))
+                item->setPickupIdentifier(this->itemTemplateName_); //TODO: Needed?
+                item->addTemplate(this->itemTemplate_); //TODO: Does what?
+
+                if(item->pickedUp(pawn))
                 {
                     COUT(3) << this->itemTemplateName_ << " got picked up." << std::endl;
 
-                    if (this->respawnTime_ > 0.0f)
+
+                    if(this->spawnsRemaining_ != INF)
+                    {
+                        this->spawnsRemaining_--;
+                    }
+
+                    if (this->spawnsRemaining_ != 0 && this->respawnTime_ > 0.0f)
                     {
                         this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
@@ -196,7 +232,28 @@
                 }
                 else
-                    newObject->destroy();
+                {
+                    item->destroy();
+                }
             }
         }
+
+        if(this->spawnsRemaining_ == 0)
+        {
+            COUT(3) << "PickupSpawner empty, selfdistruct initialized." << std::endl;
+            this->setActive(false);
+            this->destroy();
+        }
+    }
+
+    /**
+    @brief
+        Creates a BaseItem of the type specified by the PickupSpawner.
+    @return
+        The BaseItem created.
+    */    
+    BaseItem* PickupSpawner::getItem(void)
+    {
+        BaseObject* newItem = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this); //!< Creates new object of specified item type.
+        return orxonox_cast<BaseItem*>(newItem);
     }
 
