Index: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	(revision 8301)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	(revision 8404)
@@ -50,4 +50,5 @@
         this->setShowDistance(2500);
         this->setHealthDecrease(1);
+        this->setReaction(0);
         
         RegisterObject(SpaceBoundaries);
@@ -62,9 +63,4 @@
         delete this->centerRadar_;
         
-        if(this->boundary_ != NULL)
-        {
-            delete this->boundary_;
-        }
-        
         this->pawnsIn_.clear();
         
@@ -106,5 +102,5 @@
         {
             Billboard *tmp = new Billboard(this);
-            setBillboardOptions( tmp );
+            this->setBillboardOptions( tmp );
             tmp->setPosition(position);
             billboardAdministration tmp2 = { true, tmp };
@@ -171,4 +167,13 @@
         return this->healthDecrease_;
     }
+    
+    void SpaceBoundaries::setReaction(int mode)
+    {
+        this->reaction_ = mode;
+    }
+    int SpaceBoundaries::getReaction()
+    {
+        return this->reaction_;
+    }
 
     void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -179,8 +184,10 @@
         XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
         XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
     }
     
     void SpaceBoundaries::tick(float dt)
     {
+        this->checkWhoIsIn();
         this->removeAllBillboards();
         COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
@@ -188,41 +195,40 @@
         float distance;
         bool humanItem;
-        for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
-        {
-            Pawn* currentPawn = *current;
-            distance = this->computeDistance(currentPawn);
-            humanItem = this->isHumanPlayer(currentPawn);
-            COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
-            if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
-            {
-                COUT(0) << "You are leaving the area" << std::endl; // message for debugging
-                if(humanItem)
-                {
-                    COUT(0) << "humanItem ist true" << std::endl;
-                    this->displayWarning("Attention! You are leaving the area!");
-                } else {
-                    
-                }
-            }
-            if( (this->maxDistance_ - distance) < this->showDistance_)
-            {
-                // Zeige Grenze an!
-                this->displayBoundaries(currentPawn);
-            }
-            if(distance > this->maxDistance_)
-            {
-                if(humanItem)
-                {
-                    COUT(0) << "Health should be decreasing!" << std::endl;
-                    this->displayWarning("You are out of the area now!");
-                    currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
-                } else {
-                    
-                }
-                
-                this->bounceBack(currentPawn);
-            }
-        }
-        this->checkWhoIsIn();
+        for( std::list<WeakPtr<Pawn> >::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
+        {
+            Pawn* currentPawn = current->get();
+            if( currentPawn && currentPawn->getNode() ) 
+            {
+                distance = this->computeDistance(currentPawn);
+                humanItem = this->isHumanPlayer(currentPawn);
+                COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
+                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
+                {
+                    COUT(0) << "You are near by the boundaries!" << std::endl; // message for debugging
+                    if(humanItem)
+                    {
+                        COUT(0) << "humanItem ist true" << std::endl;
+                        this->displayWarning("Attention! You are near by the boundaries!");
+                    }
+                }
+                if( (this->maxDistance_ - distance) < this->showDistance_ )
+                {
+                    this->displayBoundaries(currentPawn); // Zeige Grenze an!
+                }
+                if(distance > this->maxDistance_ && (this->reaction_ == 1) )
+                {
+                    if( humanItem )
+                    {
+                        COUT(0) << "Health should be decreasing!" << std::endl;
+                        this->displayWarning("You are out of the area now!");
+                    }
+                    currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_);
+                }
+                if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Annahme: Ein Pawn kann von einem Tick bis zum nächsten nicht mehr als 100 Distanzeinheiten zurücklegen.
+                {
+                    this->conditionalBounceBack(currentPawn, distance, dt);
+                }
+            }
+        }
     }
     
@@ -254,13 +260,16 @@
     }
     
-    void SpaceBoundaries::bounceBack(Pawn *item)
+    void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
     {
         Vector3 normal = item->getPosition() - this->getPosition();
-        if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt.
+        normal.normalise();
+        Vector3 velocity = item->getVelocity();
+        float normalSpeed = item->getVelocity().dotProduct(normal);
+        
+        /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde.
+           Falls ja: Spicke es zurück. */
+        if( currentDistance + normalSpeed * dt > this->maxDistance_ )
         {
             float dampingFactor = 0.5;
-        
-            normal.normalise();
-            Vector3 velocity = item->getVelocity();
             velocity = velocity.reflect(normal);
             Vector3 acceleration = item->getAcceleration();
