Index: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc	(revision 12303)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc	(revision 12304)
@@ -34,4 +34,27 @@
 namespace orxonox
 {
+
+    //Check if there is a collision
+        bool findpos(Vector3 one, Vector3 other){
+       if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
+        return false;
+        }
+
+    //All positions in the map, see documentation
+     Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
+        Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
+        Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
+        Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
+        Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
+        Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
+        Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
+        Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
+        Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
+        Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
+        Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
+        Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
+        Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
+        Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66
+
     RegisterClass(PacmanGhost);
 
@@ -47,4 +70,5 @@
 
         this->velocity = Vector3(0, 0, 0);
+
         this->setCollisionType(CollisionType::Dynamic);
         
@@ -72,70 +96,7 @@
         Method for creating a ghost through XML.
     */
-    void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+     void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(PacmanGhost, XMLPort, xmlelement, mode);
-
-    }
-
-
-   /* //All positions in the map, see documentation
-    Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
-        Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
-        Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
-        Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
-        Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
-        Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
-        Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
-        Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
-        Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
-        Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
-        Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
-        Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
-        Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
-        Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66*/
-
-    /**
-    @brief
-        Defines which actions the ghost has to take in each tick.
-    @param dt
-        The length of the tick.
-    */
-    void PacmanGhost::tick(float dt)
-    {
-        SUPER(PacmanGhost, tick, dt);
-
-        this->actuelposition = this->getPosition();
-        
-        //Stop, if target arrived
-        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
-                 this->ismoving = false;
-        }
-
-        //Move, if ghost hasn't arrived yet
-        if(this->ismoving){
-            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
-                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
-                move(dt, actuelposition, velocity);
-            }    
-            if(!(abs(this->actuelposition.x-target_x)<0.5)){
-                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
-                move(dt, actuelposition, velocity);
-            }
-        }
-
-    }
-
-
-    //Random choice of new target (not used in game, but useful)
-    void PacmanGhost::setnewTarget(int firstdec){
-        
-    	  decision = rand()%1;
-            switch(decision){
-                case 0:
-                    this->target_x = possibleposition[firstdec].x;
-                    this->target_z = possibleposition[firstdec].z; 
-                    this->ismoving = true;
-                    break;
-    		}
     }
 
@@ -164,5 +125,5 @@
         
         //Rotate ghost in the direction of movement 
-        if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1))
+        if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)){
             if(velocity.x<0){
                  this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0)));  
@@ -171,5 +132,6 @@
                  this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0)));  
             }
-        if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1))
+        }
+        if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)){
             if(velocity.z<0){
                  this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0)));  
@@ -178,12 +140,7 @@
                  this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0)));  
             }
+        }
                      
      }
-    }
-
-    //Check if there is a collision
-    bool PacmanGhost::findpos(Vector3 one, Vector3 other){
-       if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
-        return false;
     }
 
@@ -213,3 +170,16 @@
         speed ++;
     }
+
+    Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){
+        //given that the position of a pacman is generally not "neat",
+        //we need to set it to the nearest point on the map
+        // if the pacman is not moving anymore, i.e. has reached a point
+        int i=0;
+        while(!(findpos(possibleposition[i], posToSet))){
+            i++;
+        }
+        return possibleposition[i];
+    }
+
+
 }
