Index: trunk/src/world_entities/npcs/generic_npc.cc
===================================================================
--- trunk/src/world_entities/npcs/generic_npc.cc	(revision 8805)
+++ trunk/src/world_entities/npcs/generic_npc.cc	(revision 8894)
@@ -38,4 +38,22 @@
 CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
 
+#include "script_class.h"
+CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,
+                       // Move
+                        addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo))
+                        ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime))
+                        ->addMethod("turnTo", ExecutorLua4ret<GenericNPC,bool,float,float,float,float>(&GenericNPC::turnTo))
+                       // Display
+                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
+                        ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
+                       // Coordinates
+                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
+                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
+                        ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
+                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
+                        ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
+                            
+                       );
+
 
 
@@ -52,4 +70,10 @@
 }
 
+
+GenericNPC::GenericNPC()
+  : NPC(NULL)
+{
+
+}
 
 /**
@@ -75,4 +99,5 @@
   this->soundBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
 
+  time = 30.0f;
   // collision reaction registration
 //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
@@ -136,10 +161,10 @@
 
   // check if this is the current goal
-  if( this->destCoor != destCoor && this->destDir != destDir)
+  if( this->destCoor != destCoor || this->destDir != destDir)
   {
-    this->destCoor = Vector(x, y, 0.0f);
-    this->destDir = Quaternion(Vector(qx, qy, qz), qu);
-
-    float time = 5.0f;
+    this->destCoor = destCoor;
+    this->destDir = destDir;
+
+    //float time = 100.0f;
 
     if( this->currentAnim != NULL)
@@ -147,6 +172,12 @@
 
     this->currentAnim = new Animation3D(this);
-    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f);
-    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
+
+    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
+    this->currentAnim->play();
+
+    this->setAnimation(RUN, MD2_ANIM_LOOP);
   }
 
@@ -157,4 +188,21 @@
 
 
+/**
+ * walk to a specific place with direction
+ *
+ * @param x: x coordinate to go to
+ * @param y: y coordinate to go to
+ * @param z: z coordinate to go to
+ *
+ * without turning itself
+ */
+float GenericNPC::walkTo(float x, float y, float z)
+{
+  Quaternion q = this->getAbsDir();
+
+  //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
+
+  return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
+}
 
 /**
@@ -188,4 +236,247 @@
 
 
+
+/**
+ * run to a specific place with direction
+ *
+ * @param x: x coordinate to go to
+ * @param y: y coordinate to go to
+ * @param z: z coordinate to go to
+ * @param qu: angle to rotate
+ * @param qx: x coordinate of rotation vector
+ * @param qy: y coordinate of rotation vector
+ * @param qz: z coordinate of rotation vector
+ *
+ */
+float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
+{
+  Vector destCoor = Vector(x, y, z);
+  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
+
+  // check if this is the current goal
+  if( this->destCoor != destCoor || this->destDir != destDir)
+  {
+    this->destCoor = destCoor;
+    this->destDir = destDir;
+
+    float time = 5.0f;
+
+    if( this->currentAnim != NULL)
+      delete this->currentAnim;
+
+    this->currentAnim = new Animation3D(this);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
+
+
+    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
+    this->currentAnim->play();
+
+    this->setAnimation(RUN, MD2_ANIM_LOOP);
+  }
+
+  // calculate the distance
+  Vector distance = this->getAbsCoor() - this->destCoor;
+  return distance.len();
+}
+
+
+/**
+ * run to a specific place with direction
+ *
+ * @param x: x coordinate to go to
+ * @param y: y coordinate to go to
+ * @param qu: angle to rotate
+ * @param qx: x coordinate of rotation vector
+ * @param qy: y coordinate of rotation vector
+ * @param qz: z coordinate of rotation vector
+ *
+ */
+float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
+{
+  this->runTo(x, y, 0.0f, qu, qx, qy, qz);
+}
+
+
+/**
+ * run to a specific place with direction
+ *
+ * @param coor: vector place
+ * @param dir: direction
+ *
+ */
+float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
+{
+  this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
+}
+
+
+/**
+ * crouch to a specific place with direction
+ *
+ * @param x: x coordinate to go to
+ * @param y: y coordinate to go to
+ * @param z: z coordinate to go to
+ * @param qu: angle to rotate
+ * @param qx: x coordinate of rotation vector
+ * @param qy: y coordinate of rotation vector
+ * @param qz: z coordinate of rotation vector
+ *
+ */
+float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
+{
+  Vector destCoor = Vector(x, y, z);
+  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
+
+  // check if this is the current goal
+  if( this->destCoor != destCoor || this->destDir != destDir)
+  {
+    this->destCoor = destCoor;
+    this->destDir = destDir;
+
+
+    if( this->currentAnim != NULL)
+      delete this->currentAnim;
+
+    this->currentAnim = new Animation3D(this);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
+
+
+    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
+    this->currentAnim->play();
+
+    this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
+  }
+
+  // calculate the distance
+  Vector distance = this->getAbsCoor() - this->destCoor;
+  return distance.len();
+}
+
+
+/**
+ * couch to a specific place with direction
+ *
+ * @param x: x coordinate to go to
+ * @param y: y coordinate to go to
+ * @param qu: angle to rotate
+ * @param qx: x coordinate of rotation vector
+ * @param qy: y coordinate of rotation vector
+ * @param qz: z coordinate of rotation vector
+ *
+ */
+float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz)
+{
+  this->crouchTo(x, y, 0.0f, qu, qx, qy, qz);
+}
+
+
+
+/**
+ * crouch to a specific place with direction
+ *
+ * @param coor: vector place
+ * @param dir: direction
+ *
+ */
+float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
+{
+  this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
+}
+
+
+/**
+ * stops the generic animation
+ */
+void GenericNPC::stop()
+{
+  if( this->currentAnim != NULL)
+  {
+    this->currentAnim->stop();
+    delete this->currentAnim;
+    this->currentAnim = NULL;
+
+    this->setAnimation(STAND, MD2_ANIM_LOOP);
+  }
+}
+
+
+/**
+ * lookat a world entity
+ * @param worldEntity: the worldentity to look at
+ */
+float GenericNPC::lookAt(WorldEntity* worldEntity)
+{}
+
+
+/**
+ * turns to a given direction
+ */
+bool GenericNPC::turnTo(float qu, float qx, float qy, float qz)
+{
+  Quaternion destDir = Quaternion(Vector(qx, qy, qz).getNormalized(), qu);
+
+  printf("Turning: %f, %f, %f, %f \n",qu,qx,qy,qz);
+  // check if this is the current goal
+  if( this->destDir != destDir)
+  {
+//     if( this->currentAnim != NULL)
+//       this->currentAnim->stop();
+//
+    PRINTF(0)("SET ANIMATION\n");
+    this->destDir = destDir;
+//
+
+
+    if( this->currentAnim != NULL)
+      delete this->currentAnim;
+
+    this->setAbsDir(destDir);
+/*
+    this->currentAnim = new Animation3D(this);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
+    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
+
+
+    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
+    this->currentAnim->play();*/
+
+    this->setAnimation(STAND, MD2_ANIM_LOOP);
+  }
+
+  // calculate the distance
+  Vector distance = this->getAbsCoor() - this->destCoor;
+  return distance.len();
+}
+
+
+
+/**
+ * talk to a world entity and play a sound/music/voice
+ * @param worldEntity: entity
+ * @param dialogNr: sound nr to be played (from the xml load tags)
+ */
+float GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
+{}
+
+
+/**
+ * world entity to shoot at if there is any weapon on the npc
+ * @param entity: entity to shoot entity
+ */
+void GenericNPC::shootAt(WorldEntity* entity)
+{}
+
+
+
+
+
+
+
+
+
+
 /**
  * tick this world entity
@@ -196,4 +487,5 @@
   if( likely(this->getModel(0) != NULL))
     ((InteractiveModel*)this->getModel(0))->tick(time);
+
 }
 
Index: trunk/src/world_entities/npcs/generic_npc.h
===================================================================
--- trunk/src/world_entities/npcs/generic_npc.h	(revision 8805)
+++ trunk/src/world_entities/npcs/generic_npc.h	(revision 8894)
@@ -28,4 +28,5 @@
 {
  public:
+  GenericNPC();
   GenericNPC(const TiXmlElement* root);
   virtual ~GenericNPC ();
@@ -38,29 +39,48 @@
   inline void setVolume(float vol) { this->soundVolume = vol; }
 
-  void playAnimation(int animationIndex, int animPlaybackMode);
 
-  void playSound(std::string filename);
-  void playSound(int i);
+  /* npc controlling functions */
 
-  float lookAt(WorldEntity* worldEntity);
-
+  /* walking functions */
   float walkTo(const Vector& coordinate, const Quaternion& dir);
+  float walkTo(float x, float y, float z);
   float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz);
   float walkTo(float x, float y, float qu, float qx, float qy, float qz);
 
+  /* running functions */
   float runTo(const Vector& coordinate, const Quaternion& dir);
   float runTo(float x, float y, float z, float qu, float qx, float qy, float qz);
   float runTo(float x, float y, float qu, float qx, float qy, float qz);
 
+  /* couching functinos */
   float crouchTo(const Vector& coordinate, const Quaternion& dir);
   float crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz);
   float crouchTo(float x, float y, float qu, float qx, float qy, float qz);
 
+  /* stopping the movement */
+  void stop();
+
+  /* some oriantation functions */
+  float lookAt(WorldEntity* worldEntity);
+  bool turnTo(float qu, float qx, float qy, float qz);
+
+  /* talking funcitons*/
   float talkTo(WorldEntity* worldEntity, int dialogNr);
+
+  /* shooting functions */
+  void shootAt(WorldEntity* entity);
+
+
+  /* some generic control funtions */
+  void playAnimation(int animationIndex, int animPlaybackMode);
+  void playSound(std::string filename);
+  void playSound(int i);
+
+  void setTime(float newTime){ this->time = newTime; };
+  
+  virtual void tick (float time);
 
 
   void destroy();
-
-  virtual void tick (float time);
 
 
@@ -74,4 +94,5 @@
 
    Animation3D*                            currentAnim;
+   float                                   time;          //!< Duration of the action
 };
 
Index: trunk/src/world_entities/npcs/npc.cc
===================================================================
--- trunk/src/world_entities/npcs/npc.cc	(revision 8805)
+++ trunk/src/world_entities/npcs/npc.cc	(revision 8894)
@@ -50,5 +50,6 @@
 void NPC::loadParams(const TiXmlElement* root)
 {
-  WorldEntity::loadParams(root);
+  if(root != NULL)
+   WorldEntity::loadParams(root);
 }
 
