Index: code/branches/portals/src/modules/portals/PortalEndPoint.cc
===================================================================
--- code/branches/portals/src/modules/portals/PortalEndPoint.cc	(revision 8200)
+++ code/branches/portals/src/modules/portals/PortalEndPoint.cc	(revision 8243)
@@ -1,4 +1,8 @@
 #include "PortalEndPoint.h"
 #include "core/XMLPort.h"
+#include "objects/triggers/MultiTriggerContainer.h"
+#include "portals/PortalLink.h"
+#include "worldentities/MobileEntity.h"
+
 
 namespace orxonox
@@ -8,12 +12,14 @@
     std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
 
-    PortalEndPoint::PortalEndPoint(BaseObject* creator) : DistanceMultiTrigger(creator), id_(0)
+    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
     {
         RegisterObject(PortalEndPoint);
+        this->trigger_->setName("portal");
+        this->attach(trigger_);
     }
     
     PortalEndPoint::~PortalEndPoint()
     {
-      
+    
     }
 
@@ -21,5 +27,10 @@
     {
         SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
+        
         XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
+        XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
+        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
+        XMLPortParamLoadOnly(PortalEndPoint, "eventTemplate", setEventTemplate, xmlelement, mode);
+        XMLPortParamLoadOnly(PortalEndPoint, "target", setTargets, xmlelement, mode).defaultValues("Pawn");
         
         if(mode == XMLPort::LoadObject)
@@ -29,24 +40,54 @@
     }
 
-    void PortalEndPoint::tick(float dt)
+    void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        SUPER(PortalEndPoint, tick, dt);
+        SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
+        
+        XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
     }
 
-    void PortalEndPoint::jumpOut(WorldEntity* entity)
+    bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger)
+    {
+        MultiTriggerContainer * cont = orxonox_cast<MultiTriggerContainer *>(trigger);
+        if(cont == 0)
+            return true;
+        
+        DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator());
+        if(originatingTrigger == 0)
+        {
+            COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
+            return true;
+        }
+        
+        if(this->getAttachedObjects().find(orxonox_cast<WorldEntity *>(originatingTrigger)) == this->getAttachedObjects().end())  // only necessary if events have the same name
+            return true;
+        
+        MobileEntity * entity = orxonox_cast<MobileEntity *>(cont->getData());
+        if(entity == 0)
+            return true;
+        
+        if(bTriggered)
+        {
+            if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not recently jumped out of it
+            {
+                PortalLink::use(entity, this);
+            }
+        }
+        else
+        {
+            this->recentlyJumpedOut_.erase(entity);
+        }
+        
+        return true;
+    }
+
+    void PortalEndPoint::jumpOut(MobileEntity* entity)
     {
         this->recentlyJumpedOut_.insert(entity);
-        entity->setPosition(this->getPosition());
+        entity->setPosition(this->getWorldPosition());
+        entity->rotate(this->getWorldOrientation());
+        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
     }
 
-    bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)
-    {
-        if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())
-        {
-            return false;
-        }
-        else
-            return true;
-    }
 
 }
