Index: /code/branches/portals/data/levels/portals.oxw
===================================================================
--- /code/branches/portals/data/levels/portals.oxw	(revision 8242)
+++ /code/branches/portals/data/levels/portals.oxw	(revision 8243)
@@ -26,16 +26,26 @@
   >
 
+    <Template name=portalEventTemplate>
+        <PortalEndPoint>
+            <events>
+                <execute>
+                    <EventListener event="portal" />
+                </execute>
+            </events>
+        </PortalEndPoint>
+    </Template>
 
-	<PortalEndPoint position="0,0,0" id="1">
-		<attached>
-			<Billboard material="Examples/Flare" />
-		</attached>
-	</PortalEndPoint>
-	<PortalEndPoint position="-100,0,0" id="2">
-		<attached>
-			<Billboard material="Examples/Flare2" />
-		</attached>
-	</PortalEndPoint>
-	<PortalLink fromID="1" toID="2" />
+    <Template name=portalDefault>
+        <PortalEndPoint>
+            <attached>
+                <Billboard material="Portals/Default" />
+            </attached>
+        </PortalEndPoint>
+    </Template>
+
+    <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
+    <PortalEndPoint position="-400,0,0" id="2" distance="40" lookat="0,100,0" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
+    <PortalLink fromID="1" toID="2" />
+    <PortalLink fromID="2" toID="1" />
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
Index: /code/branches/portals/src/modules/objects/triggers/MultiTrigger.h
===================================================================
--- /code/branches/portals/src/modules/objects/triggers/MultiTrigger.h	(revision 8242)
+++ /code/branches/portals/src/modules/objects/triggers/MultiTrigger.h	(revision 8243)
@@ -146,4 +146,6 @@
             inline bool isTarget(BaseObject* target)
                 { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
+                
+            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
 
         protected:
@@ -158,5 +160,4 @@
             void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
 
-            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
             void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
 
Index: /code/branches/portals/src/modules/portals/PortalEndPoint.cc
===================================================================
--- /code/branches/portals/src/modules/portals/PortalEndPoint.cc	(revision 8242)
+++ /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;
-    }
 
 }
Index: /code/branches/portals/src/modules/portals/PortalEndPoint.h
===================================================================
--- /code/branches/portals/src/modules/portals/PortalEndPoint.h	(revision 8242)
+++ /code/branches/portals/src/modules/portals/PortalEndPoint.h	(revision 8243)
@@ -11,8 +11,9 @@
 #include "graphics/Billboard.h"
 #include "objects/triggers/DistanceMultiTrigger.h"
+#include "core/EventIncludes.h"
 
 namespace orxonox
 {
-    class _PortalsExport PortalEndPoint : public DistanceMultiTrigger
+    class _PortalsExport PortalEndPoint : public StaticEntity
     {
         public:
@@ -20,5 +21,10 @@
             virtual ~PortalEndPoint();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            //virtual void tick(float dt);
+            inline void setTargets(const std::string & targets)
+            {
+                this->trigger_->addTargets(targets);
+            }
+            
+            void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
             static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< maps integer id values to portalendpoints
             inline void setID(unsigned int id)
@@ -31,11 +37,25 @@
                 return this->id_;
             }
-            void jumpOut(WorldEntity * entity); //!< relocate an entity to the position of the endpoint and add it to the set of recentlyPortedOut entities
-            void tick(float dt);
-            bool hasRecentlyJumpedOut(WorldEntity * entity); //!< check if a certain entity recently jumped out of this endpoint
+            inline void setTemplate(const std::string & name)
+            {
+                this->templateName_ = name;
+                this->addTemplate(name);
+            }
+            inline const std::string & getTemplate()
+            {
+                return this->templateName_;
+            }
+            bool execute(bool bTriggered, BaseObject* trigger);
+            void jumpOut(MobileEntity * entity);
         protected:
         private:
             unsigned int id_;
-            std::set<WorldEntity *> recentlyJumpedOut_; //!< Entities which recently jumped out of this EndPoint, hence they shouldn't be pulled in again if the endpoint is the beginning of a link
+            DistanceMultiTrigger * trigger_;
+            std::string templateName_;
+            void setEventTemplate(const std::string & temp)
+            {
+                this->addTemplate(temp);
+            }
+            std::set<MobileEntity *> recentlyJumpedOut_; //!< Entities which recently jumped out of this EndPoint, hence they shouldn't be pulled in again if the endpoint is the beginning of a link
     };
 
Index: /code/branches/portals/src/modules/portals/PortalLink.cc
===================================================================
--- /code/branches/portals/src/modules/portals/PortalLink.cc	(revision 8242)
+++ /code/branches/portals/src/modules/portals/PortalLink.cc	(revision 8243)
@@ -2,10 +2,13 @@
 #include "core/XMLPort.h"
 #include "objects/triggers/MultiTriggerContainer.h"
+#include "worldentities/MobileEntity.h"
 
 namespace orxonox
 {
     CreateFactory(PortalLink);
+
+    std::map<PortalEndPoint *, PortalEndPoint *> PortalLink::links_s;
     
-    PortalLink::PortalLink(BaseObject* creator) : EventListener(creator), fromID_(0), toID_(0), from_(0), to_(0), activationRadius_(20)
+    PortalLink::PortalLink(BaseObject* creator) : BaseObject(creator), fromID_(0), toID_(0), from_(0), to_(0)
     {
         RegisterObject(PortalLink);
@@ -24,7 +27,7 @@
         if(mode == XMLPort::LoadObject)
         {
-            this->from_ = PortalEndPoint::idMap_s[this->fromID_];
-            this->to_   = PortalEndPoint::idMap_s[this->toID_];
-            recentlyPorted.clear();
+            PortalEndPoint * from = PortalEndPoint::idMap_s[this->fromID_];
+            PortalEndPoint * to   = PortalEndPoint::idMap_s[this->toID_];
+            PortalLink::links_s[from] = to;
         }
     }
@@ -34,25 +37,21 @@
         SUPER(PortalLink, tick, dt);
     }
-    
-    void PortalLink::processEvent(Event& event)
+
+    void PortalLink::use(MobileEntity* entity, PortalEndPoint * entrance)
     {
-        EventListener::processEvent(event);
-        if(!event.activate_)
+        if(entrance == 0)
         {
+            // TODO COUT
             return;
         }
-        MultiTriggerContainer * origin = dynamic_cast<MultiTriggerContainer *>(event.originator_);
-        if(!origin)
-        {
+        
+        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
+        
+        if(endpoint == PortalLink::links_s.end())  // entrance has no corresponding exit
             return;
-        }
-        PortalEndPoint * eventFrom = dynamic_cast<PortalEndPoint *>(origin->getOriginator());
-        WorldEntity * eventEntity = dynamic_cast<WorldEntity *>(origin->getData());
-        if(eventFrom != this->from_ || !eventEntity || eventFrom->hasRecentlyJumpedOut(eventEntity) == true)
-        {
-            return;
-        }
-        to_->jumpOut(eventEntity);
+        
+        endpoint->second->jumpOut(entity);
     }
 
+
 }
Index: /code/branches/portals/src/modules/portals/PortalLink.h
===================================================================
--- /code/branches/portals/src/modules/portals/PortalLink.h	(revision 8242)
+++ /code/branches/portals/src/modules/portals/PortalLink.h	(revision 8243)
@@ -8,9 +8,9 @@
 #include "objects/eventsystem/EventListener.h"
 
-#include <set>
+#include <map>
 
 namespace orxonox
 {
-    class _PortalsExport PortalLink : public EventListener
+    class _PortalsExport PortalLink : public BaseObject
     {
         public:
@@ -36,8 +36,8 @@
                 return this->toID_;
             }
-            void use(WorldEntity * entity);
-            virtual void processEvent(Event& event);
+            static void use(MobileEntity * entity, PortalEndPoint * entrance);
         protected:
         private:
+            static std::map<PortalEndPoint *, PortalEndPoint *> links_s;
             unsigned int fromID_;
             unsigned int toID_;
@@ -45,6 +45,4 @@
             PortalEndPoint* to_;
             float activationRadius_;
-            std::set<WorldEntity *> recentlyPorted;
-            ObjectList<WorldEntity>::iterator it_;
             bool isNowPortable(WorldEntity * ent);
     };
