Index: /code/branches/ScriptableController/data/gui/scripts/testscript.lua
===================================================================
--- /code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10064)
+++ /code/branches/ScriptableController/data/gui/scripts/testscript.lua	(revision 10065)
@@ -1,12 +1,15 @@
---k = 1.2
+-- Set some test variables
+xm = 1000 
+ym = 0
+zm = 0
 
---orxonox.execute("orxout message test " .. k)
+xl = -1000 
+yl = 3000 
+zl = -1000
 
--- Set some test variables
-x = 1.1
-y = 2.2
-z = 3.3
+d = 5
+Tabs = 0
 
---os.execute("sleep " .. 2)
+pi = 3.1415
 
 -- Get a local pointer to a scriptcontroller
@@ -15,5 +18,25 @@
 -- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
-  ctrl:eventScheduler("moveToPosition_beta", x, y, z, 0.01)
+  -- Move to the starting point at (xl+3000,yl,zl) while looking 
+  -- at xl,yl,zl over the time span of 3 seconds
+  ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 3, 0)
+
+  -- From there, perform a rotation around the harvester placed there
+  -- in 100 steps
+  dt = math.pi/100
+  for t = 0,math.pi,dt do
+    xt = math.cos(t)
+    yt = math.sin(t)
+
+    ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, 3*dt, 3*t+2.9)
+  end
+
+  -- Update absolute time
+  Tabs = 3*math.pi + 2.9
+
+  -- Move away again, still looking at the station
+  ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4)
+
+
 end
 
Index: /code/branches/ScriptableController/data/levels/levelTry.oxw
===================================================================
--- /code/branches/ScriptableController/data/levels/levelTry.oxw	(revision 10064)
+++ /code/branches/ScriptableController/data/levels/levelTry.oxw	(revision 10065)
@@ -47,4 +47,5 @@
     <SpawnPoint team=0 position="3200,0,0" lookat="2800,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
 
+    <!--
     <StaticEntity position  = "2800,0,0" mass=10000 collisionType=static >
       <attached>
@@ -52,22 +53,23 @@
       </attached>
       <collisionShapes>
-        <BoxCollisionShape  position="-560,0,0" halfExtents="115,100,245" /><!-- Three lower boxes -->
+        <BoxCollisionShape  position="-560,0,0" halfExtents="115,100,245" />
         <BoxCollisionShape  position="290,0,-480" halfExtents="115,100,245" yaw=-120 />
         <BoxCollisionShape  position="290,0,480" halfExtents="115,100,245" yaw=-240 />
-        <BoxCollisionShape  position="-280,0,0" halfExtents="163,50,50" /><!-- Three lower connections -->
+        <BoxCollisionShape  position="-280,0,0" halfExtents="163,50,50" />
         <BoxCollisionShape  position="140,0,-240" halfExtents="163,50,50" yaw=-120 />
         <BoxCollisionShape  position="140,0,240" halfExtents="163,50,50" yaw=-240 />
-        <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" /><!-- Upper Tower -->
+        <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" />
         <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-120 />
         <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-240 />
-        <BoxCollisionShape  position="0,400,0" halfExtents="43,110,26" yaw=-30 /><!-- Middle one-->
-        <BoxCollisionShape  position="-200,100,0" halfExtents="26,50,43" /><!--Three lower legs -->
+        <BoxCollisionShape  position="0,400,0" halfExtents="43,110,26" yaw=-30 />
+        <BoxCollisionShape  position="-200,100,0" halfExtents="26,50,43" />
         <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=-30 />
         <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=30 />
-        <BoxCollisionShape  position="-100,264,0" halfExtents="26,105,43" roll=-49 /><!--Three upper legs -->
+        <BoxCollisionShape  position="-100,264,0" halfExtents="26,105,43" roll=-49 />
         <BoxCollisionShape  position="50,264,-87" halfExtents="26,105,43" roll=-49 yaw=-120 />
         <BoxCollisionShape  position="50,264,87" halfExtents="26,105,43" roll=-49 yaw=-240 />
       </collisionShapes>
     </StaticEntity>
+    -->
 
 
@@ -77,4 +79,15 @@
     />
 
+    <StaticEntity position  = "0,0,0" mass=10000 collisionType=static >
+      <attached>
+        <Model mesh="HydroHarvester.mesh" mass=10 position="0,0,0" scale=10 />
+      </attached>
+    </StaticEntity>
+
+    <StaticEntity position  = "-1000,3000,-1000" mass=10000 collisionType=static >
+      <attached>
+        <Model mesh="HydroHarvester.mesh" mass=10 position="0,0,0" scale=80 />
+      </attached>
+    </StaticEntity>
 
 <!-- ControllerDirector waits for the event takeControl to attach a new Controller -->
@@ -84,15 +97,6 @@
                 <EventListener event="takeControl" />
             </takeControl>
-
         </events>
-
     </ControllerDirector>
-
-<!-- -->
-    <ScriptController position="0,0,1">
-
-
-    </ScriptController>
-
 
 <!-- FPS Player as destination of the dock -->
Index: /code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc
===================================================================
--- /code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10064)
+++ /code/branches/ScriptableController/src/orxonox/controllers/ControllerDirector.cc	(revision 10065)
@@ -89,5 +89,5 @@
        /* Assemble a string to define a controller id variable in lua space */
        std::stringstream tmp;
-       tmp << "newctrlid = " << ctrlid;
+       tmp << "newctrlid = " << ctrlid << endl;
        std::string todo = tmp.str();
        
Index: /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
===================================================================
--- /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10064)
+++ /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc	(revision 10065)
@@ -36,33 +36,61 @@
 namespace orxonox
 {
-    float scTime=0;  /*initialize time, to coordinate eventTime*/
-
-
-    std::vector<event> eventList;
-
-    
-
     RegisterClass(ScriptController);
 
-    //ScriptController::ScriptController(Context* context, ControllableEntity* CE) : ArtificialController(context)
     ScriptController::ScriptController(Context* context) : ArtificialController(context)
     {
         RegisterObject(ScriptController);
-        //set_controlled(CE);
+
+        /* By default, this controller has ID 0, which means it is not assigned
+         * to anything yet. 
+         */
         this->ctrlid_ = 0;
+
+
+        /* Set default values for all variables */
+        /* - pointers to zero */
+        this->player_ = NULL;
+        this->entity_ = NULL;
+
+        /* - times */
+        this->scTime = 0.0f;
+        this->timeToTarget = 0.0f;
+        this->eventTime = 0.0f;
+
+        /* - Points in space */
+        this->target = Vector3(0,0,0);
+        this->startpos = Vector3(0,0,0);
+        this->lookAtPosition = Vector3(0,0,0);
+
+        /* - Processing flag */
+        this->processing = false;
+
+        /* - Counters */
+        this->eventno = 0;
+
     }
 
     void ScriptController::takeControl(int ctrlid)
     {
+        /* Output some debugging information */
         orxout() << "ScriptController: Taking control" << endl;
         orxout() << "This-pointer: " << this << endl;
+
+        /* Set the controller ID (the argument here should be nonzero) */
         this->ctrlid_ = ctrlid;
+
+        /* Store the entity pointer in a private variable */
         this->entity_ = this->player_->getControllableEntity();
         assert(this->entity_);
-
+         
+        /* Add the controller here to this entity. Apparently this still leaves
+         * any preexisting human controllers in place. 
+         */
         this->entity_->setDestroyWhenPlayerLeft(false);
         this->player_->pauseControl();
         this->entity_->setController(this);
         this->setControllableEntity(this->entity_);
+        this->entity_->mouseLook();
+        this->entity_->setVisible(false);
     }
 
@@ -75,13 +103,7 @@
     //}
 
-    void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-    	//XMLPortParam(ScriptController, BaseObject, "lsrc", set_luasrc, xmlelement, mode);
-
-    }
-
     const Vector3& ScriptController::getPosition()
     {
-        return this->entity_->getPosition();
+      return this->entity_->getPosition();
     }
 
@@ -104,5 +126,7 @@
         // TODO: do some selection here. Currently just returns the first one
         if( (*it)->getID() > 0 )
+        { orxout() << "Controller to return: " << *it << endl;
           return *it; 
+        }
       
       }
@@ -112,9 +136,16 @@
     void ScriptController::execute(event ev)
     {
-        if(ev.fctName=="moveToPosition_beta")
-        {
-
-            moveToPosition_beta(ev.xCoord,ev.yCoord,ev.zCoord);
-        }
+        orxout() << "Executing event " << ev.fctName 
+          << " with parameters:\n " 
+          << ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n"
+          << ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n"
+          << ev.duration << endl;
+
+        this->eventTime = 0.0f;
+        this->startpos = this->entity_->getPosition();
+        this->processing = true;
+
+        if(ev.fctName == "mal")
+          moveAndLook(ev.x1, ev.y1, ev.z1, ev.x2, ev.y2, ev.z2, ev.duration);
     }
 
@@ -122,6 +153,6 @@
     void ScriptController::tick(float dt)
     {
-
-        
+        /* Call the tick function of the classes we derive from */
+        SUPER(ScriptController, tick, dt);
 
         /* If this controller has no entity entry, do nothing */
@@ -129,107 +160,127 @@
           return;
 
-        //orxout() << "Rotating!" << endl;
-
-        //this->entity_->rotateYaw(-1.0f * 100.0f * dt);
-        //this->entity_->rotatePitch(0.8f * 100.0f);
-
-        if(eventList.size() > 0 && eventList[0].eventTime<=scTime)
+        //orxout() << "Size 0: " << this->eventList.size() << endl;
+
+        /* See if time has come for the next event to be run */
+        if(this->eventList.size() > 0 && this->eventList[0].eventTime <= scTime)
         {
-            /*TO DO: execute the function: eventList[0].fctName*/
-
-            execute(eventList[0]);
-            eventList.erase(eventList.begin());
-        }
-
-        SUPER(ScriptController, tick, dt);
-
-        scTime=scTime+dt;
-    }
-
-
-
-
-    void ScriptController::moveToPosition_beta(float x, float y, float z )
-    {
-
-        orxout()<<"moveToPosition_beta executed"<<endl;
-        //const Vector3 local = this->getPosition();
-        const Vector3 target = Vector3(100*x,100*y,100*z);
-        //Vector3 way = target-local;
-        orxout() << "Moving This-pointer: " << this << endl;
-       
-        
-        //this->entity_->lookAt(target);
-        //this->entity_->moveFrontBack(-1000*target.length());      
-
-        if(this->entity_!=NULL)
-            orxout()<<"not-NULL-entity"<<endl;
-
-        if(this->player_!=NULL)
-            orxout()<<"not-NULL-player"<<endl;
-
-        orxout() << this->player_->getClientID() << endl; // IMPOSSIBLE TO ACCESS this->player AND this->entity
-        
-        //this->entity_ = this->player_->getClientID();//getControllableEntity();
-
-            //if(this->entity_==this->player_->getControllableEntity())
-            //orxout()<<"same entity"<<endl;
-
-        /* This works fine */
-        orxout()<<x<<"  "<<y<<"  "<<z<<endl;
-    }
-
-    void ScriptController::eventScheduler(std::string instruction, float x, float y, float z, float executionTime)
-    {
-
-
-        /*put data (from LUA) into time-sorted eventList*/ 
-        /*nimmt den befehl und die argumente aus luascript und ertellt einen struct pro event, diese structs werden sortiert nach eventTime*/
-        struct event tmp;
-        tmp.fctName=instruction;
-        tmp.xCoord=x;
-        tmp.yCoord=y;
-        tmp.zCoord=z;
-        tmp.eventTime=executionTime;
-
-        orxout()<<tmp.fctName<<endl;
-
-        if(eventList.size()==0)
-        {
-            orxout()<<"eventList empty (01)"<<endl;
-            eventList.insert(eventList.begin(), tmp);
-            orxout()<<"first event added"<<endl;
-        }
-
-
-       for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
-            {
-
-                if(tmp.eventTime<it->eventTime)
-                {
-                    eventList.insert(it,tmp);
-                    orxout()<<"new event added"<<endl;
-                }
-
-            }
-
-       
-       if(eventList.size()==0)
-            orxout()<<"eventList empty"<<endl;
-
-        else
-            orxout()<<"eventList is not empty"<<endl;
-
-        
-    }
-
-
-
-    /* TODO:    struct event erweitern um mehr funktionen benutzen zu koennen
-
-                mehr funktionen definieren (und dann in  execute if(...))
-                NB: viele noetige funktionen sind schon in artificial- bzw formationcontroller vorhanden */        
-
-
-
+          /* Execute the next event on the list */
+          this->execute(this->eventList[0]);
+          this->eventList.erase(this->eventList.begin());
+          this->eventno -= 1;
+          //orxout() << "Size 1: " << this->eventList.size() << endl;
+          //orxout() << "Eventno is now: " << this->eventno << endl;
+        }
+
+        /* Update the local timers in this object */
+        scTime += dt;
+        eventTime += dt;
+
+        /* If we've arrived at the target, stop processing */
+        if( eventTime > timeToTarget && this->processing == true)
+        { this->processing = false;
+
+          //orxout() << "Size 4: " << this->eventList.size() << endl;
+          //orxout() << "Eventno: " << this->eventno << endl;
+          
+          if( this->eventno == 0 )
+          {
+            this->entity_->mouseLook();
+            this->entity_->setVisible(true);
+          }
+        }
+
+        /* Get a variable that specifies how far along the trajectory
+         * we are 
+         */
+        float dl = eventTime / timeToTarget; 
+
+        /* Do some moving */
+        if( this->processing )
+        { 
+          /* Set the position to the correct place in the trajectory */
+          this->entity_->setPosition( (1-dl)*startpos + dl * target );
+
+          /* Look at the specified position */
+          this->entity_->lookAt(lookAtPosition);
+
+          /* Force mouse look */
+          if( this->entity_->isInMouseLook() == false )
+            this->entity_->mouseLook();
+        }
+    }
+
+    void ScriptController::moveAndLook(
+      float xm, float ym, float zm,
+      float xl, float yl, float zl,
+      float t )
+    {
+      orxout()<<"moveAndLook executed"<<endl;
+
+      /* Set the local variables required for this event */
+      this->target = Vector3(xm,ym,zm);
+      this->lookAtPosition = Vector3(xl,yl,zl);
+      this->timeToTarget = t;
+
+
+      orxout() << "Moving This-pointer: " << this << endl;
+
+      if(this->entity_ != NULL)
+        orxout()<<"not-NULL-entity"<<endl;
+      else 
+        return;
+
+      if(this->player_ != NULL)
+        orxout()<<"not-NULL-player"<<endl;
+      else 
+        return;
+    }
+
+    void ScriptController::eventScheduler(std::string instruction, 
+      float x1, float y1, float z1, 
+      float x2, float y2, float z2, 
+      float duration, float executionTime)
+    {
+      /* put data (from LUA) into time-sorted eventList*/ 
+      /* Nimmt den befehl und die argumente aus luascript und ertellt einen
+       * struct pro event, diese structs werden sortiert nach eventTime
+       */
+      struct event tmp;
+
+      /* Fill the structure with all the provided information */
+      tmp.fctName = instruction;
+      tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
+      tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
+      tmp.duration = duration;
+      tmp.eventTime = executionTime;
+
+      orxout() << tmp.fctName << endl;
+
+      /* Add the created event to the event list */
+      if(eventList.size()==0)
+      { /* The list is still empty, just add it */
+        orxout() << "eventList empty (01)" << endl;
+        eventList.insert(eventList.begin(), tmp);
+        this->eventno += 1;
+        return; /* Nothing more to do, the event was added */
+      }
+
+      /* Event was not added yet since the list was not empty. Walk through
+       * the list of events and add it so that the events are correctly in
+       * order.
+       */
+      for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
+      { if(tmp.eventTime < it->eventTime)
+        { eventList.insert(it,tmp);
+          this->eventno += 1;
+          orxout()<<"new event added"<<endl;
+          return;
+        }
+      }
+
+      /* If the event was still not added here, it belongs in the end of the list */
+      eventList.insert(eventList.end(), tmp);
+      this->eventno += 1;
+
+    }
 }
Index: /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
===================================================================
--- /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10064)
+++ /code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h	(revision 10065)
@@ -42,7 +42,13 @@
     {   
         std::string fctName;
-        float xCoord;
-        float yCoord;
-        float zCoord;
+        float x1;
+        float y1;
+        float z1;
+
+        float x2;
+        float y2;
+        float z2;
+
+        float duration;
 
         float eventTime;
@@ -54,31 +60,28 @@
     {  // tolua_export
         public:
-            //ScriptController(Context* context, ControllableEntity* CE);
             ScriptController(Context* context);
 
             virtual ~ScriptController() { }
 
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             
             void takeControl(int ctrlid);
             void setPlayer(PlayerInfo* player) { this->player_ = player; }
            
-           
-
-            //void set_luasrc(std::string);
-            //void set_controlled(ControllableEntity*);
-
             virtual void tick(float dt);
 
             // LUA interface
             // tolua_begin 
-            void moveToPosition_beta(float x, float y, float z);
+            void moveAndLook(float xm, float ym, float zm,
+              float xl, float yl, float zl, float t);
 
-            void eventScheduler(std::string instruction, float x, float y, float z, float time);
+            void eventScheduler(std::string instruction, 
+              float x1, float y1, float z1, 
+              float x2, float y2, float z2, 
+              float duration, float executionTime);
 
             static ScriptController* getScriptController();
 
             int getID() { return ctrlid_; }
-            
 
             // tolua_end
@@ -88,10 +91,41 @@
 
         private:
-            // name of the LUA-sourcefile that shall be executed->see XMLPort-function
-            std::string luasrc;		
+            /* Information about the player that this ScriptController will
+             * control */
+            /* - Player pointer */
             PlayerInfo* player_;
+
+            /* - Entity pointer, this is for convenience and will be the same as 
+             *   player_->getControllableEntity() 
+             */
             ControllableEntity* entity_;
+
+            /* Controller ID, defaults to 0 and is set using takeControl() */
             int ctrlid_;
 
+            /* List of events to walk through */
+            std::vector<event> eventList;
+            unsigned int eventno;
+
+            /* Time since the creation of this ScriptController object */
+            float scTime;  
+
+            /* Boolean that specifies whether we're processing an event right
+             * now */
+            bool processing;
+
+            /* Data about the point to go to and what to look at */
+            /* - Target position */
+            Vector3 target;
+
+            /* - Time it should take to get there */
+            float timeToTarget;
+
+            /* - Time this event has been going on for */
+            float eventTime;
+            Vector3 startpos;
+
+            /* - Position to look at during that transition */
+            Vector3 lookAtPosition;
 
     };// tolua_export
