Index: trunk/src/world_entities/npcs/door.cc
===================================================================
--- trunk/src/world_entities/npcs/door.cc	(revision 9003)
+++ trunk/src/world_entities/npcs/door.cc	(revision 9003)
@@ -0,0 +1,200 @@
+
+
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific
+   main-programmer: Patrick Boenzli
+   co-programmer:
+*/
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
+
+
+#include "util/loading/factory.h"
+#include "util/loading/load_param.h"
+
+#include "interactive_model.h"
+
+
+#include "door.h"
+#include "class_list.h"
+
+
+using namespace std;
+
+
+CREATE_FACTORY(Door, CL_DOOR);
+
+
+
+//! list of all different animations a std md2model supports
+sAnim Door::animationList[2] =
+{
+ // begin, end, fps, interruptable
+  {   0,  15,  30,  0 },   //!< OPEN
+  {   15, 29,  30,  0 }    //!< CLOSE
+};
+
+
+
+Door::Door ()
+{
+  this->init();
+}
+
+
+Door::Door(const TiXmlElement* root)
+{
+
+  this->setClassID(CL_DOOR, "Door");
+  this->scale = 1.0f;
+
+  if( root != NULL)
+    this->loadParams(root);
+
+  this->toList(OM_COMMON);
+  this->bLocked = false;
+
+  this->loadMD2Texture("maps/doors.jpg");
+  this->loadModel("models/creatures/doors.md2", this->scale);
+
+  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
+}
+
+
+Door::~Door ()
+{}
+
+
+
+/**
+ * loads the Settings of a MD2Creature from an XML-element.
+ * @param root the XML-element to load the MD2Creature's properties from
+ */
+void Door::loadParams(const TiXmlElement* root)
+{
+  WorldEntity::loadParams(root);
+
+  LoadParam(root, "action-radius", this, Door, setActionRadius)
+      .describe("sets the action radius of the door")
+      .defaultValues(3.0);
+  LoadParam(root, "scale", this, Door, setScale)
+      .describe("sets the scale of the door")
+      .defaultValues(1.0);
+}
+
+
+/**
+ * sets the animatin of this entity
+ */
+void  Door::setAnimation(int animNum, int playbackMode)
+{
+  if( likely(this->getModel(0) != NULL))
+    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
+                                                         animationList[animNum].lastFrame,
+                                                         animationList[animNum].fps,
+                                                         animationList[animNum].bStoppable,
+                                                         playbackMode);
+}
+
+
+/**
+ * ticks the door
+ * @param time: time since last tick
+ */
+void Door::tick (float time)
+{
+  if( likely(this->getModel(0) != NULL))
+    ((InteractiveModel*)this->getModel(0))->tick(time);
+
+  if( !this->bOpen)
+  {
+    if( this->checkOpen())
+    {
+      this->open();
+    }
+  }
+  else
+  {
+    if( !this->checkOpen())
+    {
+      this->close();
+    }
+  }
+
+}
+
+
+/**
+ * open the door
+ */
+void Door::open()
+{
+  if( this->bLocked)
+    return;
+
+  this->setAnimation(DOOR_OPEN, MD2_ANIM_ONCE);
+  this->bOpen = true;
+}
+
+
+/**
+ * close the door
+ */
+void Door::close()
+{
+  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
+  this->bOpen = false;
+}
+
+
+
+/**
+ * checks if the door is open
+ */
+bool Door::checkOpen()
+{
+
+  std::list<BaseObject*>::const_iterator it;
+  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
+  WorldEntity* entity;
+  float distance;
+
+  if( list == NULL)
+    return false;
+
+  // for all players
+  for( it = list->begin(); it != list->end(); it++)
+  {
+    entity = dynamic_cast<WorldEntity*>(*it);
+
+    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
+    if( distance < this->actionRadius)
+      return true;
+  }
+
+
+  list = ClassList::getList(CL_GENERIC_NPC);
+  if( list == NULL)
+    return false;
+  for( it = list->begin(); it != list->end(); it++)
+  {
+    entity = dynamic_cast<WorldEntity*>(*it);
+
+    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
+    if( distance < this->actionRadius)
+      return true;
+  }
+
+  return false;
+}
+
+
+
Index: trunk/src/world_entities/npcs/door.h
===================================================================
--- trunk/src/world_entities/npcs/door.h	(revision 9003)
+++ trunk/src/world_entities/npcs/door.h	(revision 9003)
@@ -0,0 +1,60 @@
+#ifndef _DOOR_H
+#define _DOOR_H
+
+#include "world_entity.h"
+
+#include "md2/md2Model.h"
+
+class TiXmlElement;
+
+
+//! animation names enumeration
+typedef enum DoorAnimType
+{
+  DOOR_OPEN = 0,
+  DOOR_CLOSE,
+
+  DOOR_MAX_ANIMATIONS
+};
+
+
+class Door : public WorldEntity
+{
+  public:
+    Door ();
+    Door(const TiXmlElement* root);
+    virtual ~Door ();
+
+    virtual void loadParams(const TiXmlElement* root);
+
+    void setActionRadius(float radius) { this->actionRadius = radius; }
+    void setScale(float scale) { this->scale = scale; }
+
+    void open();
+    void close();
+
+    void lock() { this->bLocked = true; }
+    void unlock() { this->bLocked = false; }
+    bool isLocked() const { return this->bLocked; }
+
+
+    virtual void tick (float time);
+
+
+  private:
+    bool checkOpen();
+    void setAnimation(int animNum, int playbackMode = 0);
+
+
+  private:
+    bool           bOpen;             //!< true if the door is open
+    bool           bLocked;           //!< true if this door is locked
+    float          actionRadius;      //!< action radius
+    float          scale;             //!< the scale of the model
+
+    static sAnim   animationList[2];  //!< list of the animations
+
+
+};
+
+#endif /* _DOOR_H */
Index: trunk/src/world_entities/npcs/generic_npc.cc
===================================================================
--- trunk/src/world_entities/npcs/generic_npc.cc	(revision 8894)
+++ trunk/src/world_entities/npcs/generic_npc.cc	(revision 9003)
@@ -17,4 +17,6 @@
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
 
+#include "generic_npc.h"
+
 
 #include "util/loading/factory.h"
@@ -28,11 +30,4 @@
 #include "loading/resource_manager.h"
 
-#include "generic_npc.h"
-
-#include "animation/animation3d.h"
-
-using namespace std;
-
-
 
 CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
@@ -40,12 +35,13 @@
 #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
+                        // Move
+                        addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))
+                        ->addMethod("runTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::runTo))
+                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
+                        ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))
+                        // Display
                         ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
                         ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
-                       // Coordinates
+                        // Coordinates
                         ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
                         ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
@@ -53,5 +49,5 @@
                         ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
                         ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
-                            
+
                        );
 
@@ -62,5 +58,5 @@
  */
 GenericNPC::GenericNPC(const TiXmlElement* root)
-  : NPC(root)
+    : NPC(root)
 {
   this->init();
@@ -71,18 +67,9 @@
 
 
-GenericNPC::GenericNPC()
-  : NPC(NULL)
-{
-
-}
-
 /**
  * deconstructor
  */
 GenericNPC::~GenericNPC ()
-{
-  if( this->currentAnim != NULL)
-    delete this->currentAnim;
-}
+{}
 
 
@@ -100,6 +87,7 @@
 
   time = 30.0f;
+
   // collision reaction registration
-//   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
+  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
 }
 
@@ -128,4 +116,41 @@
 
 
+
+/**
+ * @returns the current animation number
+ */
+int GenericNPC::getAnimation()
+{
+  if( likely(this->getModel(0) != NULL))
+    return ((InteractiveModel*)this->getModel(0))->getAnimation();
+  else
+    return -1;
+}
+
+
+
+/**
+ * @returns true if animation is finished
+ */
+bool GenericNPC::isAnimationFinished()
+{
+  if( likely(this->getModel(0) != NULL))
+    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
+  else
+    return false;
+}
+
+
+/**
+ * sets the animation speed of this entity
+ */
+void GenericNPC::setAnimationSpeed(float speed)
+{
+  if( likely(this->getModel(0) != NULL))
+    ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed);
+}
+
+
+
 /**
  * sets the animation of this npc
@@ -146,243 +171,6 @@
  */
 void GenericNPC::playSound(std::string filename)
-{
-
-}
-
-
-/**
- * walt to
- * @param coordinate: coordinate to go to
- */
-float GenericNPC::walkTo(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 = 100.0f;
-
-    if( this->currentAnim != NULL)
-      delete this->currentAnim;
-
-    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->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();
-}
-
-
-/**
- * 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);
-}
-
-/**
- * walk 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::walkTo(float x, float y, float qu, float qx, float qy, float qz)
-{
-  return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
-}
-
-
-/**
- * walk to a specific place with direction
- *
- * @param coor: vector place
- * @param dir: direction
- *
- */
-float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
-{
-  return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
-}
-
-
-
-/**
- * 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);
-}
+{}
+
 
 
@@ -391,14 +179,229 @@
  */
 void GenericNPC::stop()
-{
-  if( this->currentAnim != NULL)
-  {
-    this->currentAnim->stop();
-    delete this->currentAnim;
-    this->currentAnim = NULL;
-
+{}
+
+
+
+void GenericNPC::initNPC()
+{
+  if (!this->behaviourList.empty())
+  {
+    GenericNPC::Anim currentAnimation = this->behaviourList.front();
+
+    switch(this->behaviourList.front().type)
+    {
+      case Walk:
+      {
+        if( this->getAnimation() != RUN)
+          this->setAnimation(RUN, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor());
+        dir.y = 0.0f;
+        dir.getNormalized();
+        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
+
+        this->setAnimationSpeed(0.5f);
+      }
+        break;
+      case Run:
+      {
+        if( this->getAnimation() != RUN)
+          this->setAnimation(RUN, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
+        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
+
+        this->setAnimationSpeed(1.0f);
+      }
+        break;
+      case Crouch:
+      {
+        if( this->getAnimation() != CROUCH_WALK)
+          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
+        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
+
+        this->setAnimationSpeed(1.0f);
+      }
+        break;
+      case LookAt:
+        if( this->getAnimation() != STAND)
+          this->setAnimation(STAND, MD2_ANIM_LOOP);
+        break;
+      case Shoot:
+        if( this->getAnimation() != STAND)
+          this->setAnimation(STAND, MD2_ANIM_LOOP);
+        break;
+
+      default:
+        if( this->getAnimation() != STAND)
+          this->setAnimation(STAND, MD2_ANIM_LOOP);
+        break;
+
+    }
+  }
+}
+
+
+void GenericNPC::nextStep()
+{
+  if (!this->behaviourList.empty())
+    this->behaviourList.pop_front();
+  else
+    return;
+
+
+  if (!this->behaviourList.empty())
+  {
+    GenericNPC::Anim currentAnimation = this->behaviourList.front();
+
+    switch( currentAnimation.type)
+    {
+      case Walk:
+      {
+        if( this->getAnimation() != RUN)
+          this->setAnimation(RUN, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor());
+        dir.y = 0.0f;
+        dir.getNormalized();
+        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
+
+        this->setAnimationSpeed(0.5f);
+      }
+        break;
+      case Run:
+      {
+        if( this->getAnimation() != RUN)
+          this->setAnimation(RUN, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
+        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
+
+        this->setAnimationSpeed(1.0f);
+      }
+        break;
+      case Crouch:
+      {
+        if( this->getAnimation() != CROUCH_WALK)
+          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
+
+        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
+        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
+
+        this->setAnimationSpeed(1.0f);
+      }
+        break;
+      case LookAt:
+      {
+        if( this->getAnimation() != STAND)
+          this->setAnimation(STAND, MD2_ANIM_LOOP);
+      }
+        break;
+      case Shoot:
+        if( this->getAnimation() != STAND)
+        this->setAnimation(STAND, MD2_ANIM_LOOP);
+        break;
+
+      default:
+        if( this->getAnimation() != STAND)
+        this->setAnimation(STAND, MD2_ANIM_LOOP);
+        break;
+
+    }
+  }
+  else
+  {
     this->setAnimation(STAND, MD2_ANIM_LOOP);
   }
 }
+
+
+
+
+void GenericNPC::walkTo(const Vector& coordinate)
+{
+
+  GenericNPC::Anim anim;
+  anim.v = coordinate;
+  anim.type = Walk;
+  anim.speed = 30.0f;
+
+  if( this->behaviourList.empty())
+  {
+    this->behaviourList.push_back(anim);
+    this->initNPC();
+  }
+  else
+    this->behaviourList.push_back(anim);
+}
+
+void GenericNPC::walkTo(float x, float y, float z)
+{
+  //printf("Walking to %f, %f, %f \n",x,y,z);
+  this->walkTo(Vector(x,y,z));
+
+}
+
+/* running functions */
+void GenericNPC::runTo(const Vector& coordinate)
+{
+  GenericNPC::Anim anim;
+  anim.v = coordinate;
+  anim.type = Run;
+  anim.speed = 60.0f;
+
+  if( this->behaviourList.empty())
+  {
+    this->behaviourList.push_back(anim);
+    this->initNPC();
+  }
+  else
+    this->behaviourList.push_back(anim);
+}
+
+void GenericNPC::runTo(float x, float y, float z)
+{
+  this->runTo(Vector(x,y,z));
+}
+
+/* couching functinos */
+void GenericNPC::crouchTo(const Vector& coordinate)
+{
+  GenericNPC::Anim anim;
+  anim.v = coordinate;
+  anim.type = Crouch;
+
+  if( this->behaviourList.empty())
+  {
+    this->behaviourList.push_back(anim);
+    this->initNPC();
+  }
+  else
+    this->behaviourList.push_back(anim);
+}
+void GenericNPC::crouchTo(float x, float y, float z)
+{
+  this->crouchTo(Vector(x,y,z));
+}
+
+
+
+void GenericNPC::turnTo(float degreeInY)
+{
+  GenericNPC::Anim anim;
+  anim.q = Quaternion(Vector(0,1,0), degreeInY);
+  anim.type = TurnTo;
+
+  if( this->behaviourList.empty())
+  {
+    this->behaviourList.push_back(anim);
+    this->initNPC();
+  }
+  else
+    this->behaviourList.push_back(anim);
+}
+
 
 
@@ -407,48 +410,19 @@
  * @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();
-}
+void GenericNPC::lookAt(WorldEntity* worldEntity)
+{
+  GenericNPC::Anim anim;
+  anim.entity = worldEntity;
+  anim.type = LookAt;
+
+  if( this->behaviourList.empty())
+  {
+    this->behaviourList.push_back(anim);
+    this->initNPC();
+  }
+  else
+    this->behaviourList.push_back(anim);
+}
+
 
 
@@ -459,5 +433,5 @@
  * @param dialogNr: sound nr to be played (from the xml load tags)
  */
-float GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
+void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
 {}
 
@@ -483,8 +457,83 @@
  * @param time: time in seconds expirded since the last tick
  */
-void GenericNPC::tick (float time)
+void GenericNPC::tick (float dt)
 {
   if( likely(this->getModel(0) != NULL))
-    ((InteractiveModel*)this->getModel(0))->tick(time);
+    ((InteractiveModel*)this->getModel(0))->tick(dt);
+
+
+  if (!this->behaviourList.empty())
+  {
+    GenericNPC::Anim currentAnimation = this->behaviourList.front();
+
+    switch( currentAnimation.type)
+    {
+      case Walk:
+        {
+          Vector dest = currentAnimation.v - this->getAbsCoor();
+          if (dest.len() < .5)
+            this->nextStep();
+          else
+          {
+            dest.y = 0.0f;
+            this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
+
+          }
+        }
+        break;
+
+      case Run:
+      {
+        Vector dest = currentAnimation.v - this->getAbsCoor();
+        if (dest.len() < .5)
+          this->nextStep();
+        else
+        {
+          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
+        }
+      }
+      break;
+
+      case Crouch:
+      {
+        Vector dest = currentAnimation.v - this->getAbsCoor();
+        if (dest.len() < .5)
+          this->nextStep();
+        else
+        {
+          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
+        }
+      }
+      break;
+
+      case TurnTo:
+        //Quaternion direction = this->
+        break;
+
+      case LookAt:
+        break;
+
+      case Shoot:
+        break;
+
+      default:
+        break;
+
+    }
+  }
+
+  // physical falling of the player
+  if( !this->isOnGround())
+  {
+    this->fallVelocity += 300.0f * dt;
+    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
+   // PRINTF(0)("%s is not on ground\n", this->getName());
+  }
+  else
+  {
+    this->fallVelocity = 0.0f;
+  }
+
+  this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
 
 }
@@ -495,4 +544,6 @@
 {
   int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
+
+  this->setAnimationSpeed(1.0f);
 
   if( randi == 1)
Index: trunk/src/world_entities/npcs/generic_npc.h
===================================================================
--- trunk/src/world_entities/npcs/generic_npc.h	(revision 8894)
+++ trunk/src/world_entities/npcs/generic_npc.h	(revision 9003)
@@ -10,11 +10,6 @@
 #include "npc.h"
 
-#include <string>
 
 #include "sound_source.h"
-
-#include "vector.h"
-#include "quaternion.h"
-
 
 namespace OrxSound{ class SoundSource; }
@@ -27,44 +22,43 @@
 class GenericNPC : public NPC
 {
+
+
  public:
-  GenericNPC();
-  GenericNPC(const TiXmlElement* root);
+  GenericNPC(const TiXmlElement* root = NULL);
   virtual ~GenericNPC ();
 
-  void init();
   virtual void loadParams(const TiXmlElement* root);
 
-  void setAnimation(int animationIndex, int animPlaybackMode);
   /** sets the sound volume to @param vol: volume of the sound */
   inline void setVolume(float vol) { this->soundVolume = vol; }
 
 
-  /* npc controlling functions */
 
+  bool finalGoalReached() { return this->behaviourList.empty(); };
+
+  /* npc controlling functions to be Queued */
   /* 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);
+  void walkTo(const Vector& coordinate);
+  void walkTo(float x, float y, float z);
 
   /* 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);
+  void runTo(const Vector& coordinate);
+  void runTo(float x, float y, float z);
 
   /* 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);
+  void crouchTo(const Vector& coordinate);
+  void crouchTo(float x, float y, float z);
 
   /* stopping the movement */
   void stop();
+  void nextStep();
 
   /* some oriantation functions */
-  float lookAt(WorldEntity* worldEntity);
-  bool turnTo(float qu, float qx, float qy, float qz);
+  void lookAt(WorldEntity* worldEntity);
+  void turnTo(float qu, float qx, float qy, float qz);
+  void turnTo(float degreeInY);
 
   /* talking funcitons*/
-  float talkTo(WorldEntity* worldEntity, int dialogNr);
+  void talkTo(WorldEntity* worldEntity, int dialogNr);
 
   /* shooting functions */
@@ -77,6 +71,4 @@
   void playSound(int i);
 
-  void setTime(float newTime){ this->time = newTime; };
-  
   virtual void tick (float time);
 
@@ -84,10 +76,52 @@
   void destroy();
 
+  private:
+    void init();
+
+    void setAnimation(int animationIndex, int animPlaybackMode);
+    int getAnimation();
+    bool isAnimationFinished();
+    void setAnimationSpeed(float speed);
+
+    void initNPC();
+
 
  private:
+
+   typedef enum {
+    Walk,
+    Run,
+    Crouch,
+    Jump,
+    TurnTo,
+    LookAt,
+    TalkTo,
+
+    Shoot,
+
+
+   } AnimType;
+
+   typedef struct Anim
+   {
+     Vector        v;
+     Quaternion    q;
+
+
+     WorldEntity*  entity;
+     float         speed;
+
+
+     AnimType      type;
+   };
+   typedef std::list<GenericNPC::Anim>     genNPCAnimList;
+
+
+
    OrxSound::SoundSource                   soundSource;
    OrxSound::SoundBuffer*                  soundBuffer;
    float                                   soundVolume;
 
+   std::list<GenericNPC::Anim>             behaviourList;
    Vector                                  destCoor;
    Quaternion                              destDir;
@@ -95,4 +129,5 @@
    Animation3D*                            currentAnim;
    float                                   time;          //!< Duration of the action
+   float                                   fallVelocity;
 };
 
Index: trunk/src/world_entities/npcs/npc.cc
===================================================================
--- trunk/src/world_entities/npcs/npc.cc	(revision 8894)
+++ trunk/src/world_entities/npcs/npc.cc	(revision 9003)
@@ -29,4 +29,5 @@
 
   this->toList(OM_GROUP_00);
+
 }
 
Index: trunk/src/world_entities/npcs/repair_station.cc
===================================================================
--- trunk/src/world_entities/npcs/repair_station.cc	(revision 9003)
+++ trunk/src/world_entities/npcs/repair_station.cc	(revision 9003)
@@ -0,0 +1,197 @@
+
+
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific
+   main-programmer: Patrick Boenzli
+   co-programmer:
+*/
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
+
+
+#include "util/loading/factory.h"
+#include "util/loading/load_param.h"
+
+#include "interactive_model.h"
+
+
+#include "repair_station.h"
+#include "class_list.h"
+
+
+using namespace std;
+
+
+CREATE_FACTORY(RepairStation, CL_DOOR);
+
+
+
+//! list of all different animations a std md2model supports
+// sAnim RepairStation::animationList[2] =
+// {
+//  // begin, end, fps, interruptable
+//   {   0,  10,  30,  0 },   //!< OPEN
+//   {   10, 20,  30,  0 }    //!< CLOSE
+// };
+
+
+sAnim RepairStation::animationList[8] =
+{
+ // begin, end, fps, interruptable
+  {   0,  12,  20,  0 },   //!< CYCLE01
+  {   12, 24,  30,  0 },   //!< CYCLE02
+  {   24, 40,  10,  0 },   //!< CYCLE03
+  {   40, 55,  30,  0 },   //!< CYCLE04
+  {   55, 68,  20,  0 },   //!< CYCLE05
+  {   68, 81,  30,  0 },   //!< CYCLE06
+  {   81, 89,  40,  0 },   //!< CYCLE07
+  {   89, 99,  30,  0 }    //!< CYCLE08
+};
+
+
+
+RepairStation::RepairStation ()
+{
+  this->init();
+}
+
+
+RepairStation::RepairStation(const TiXmlElement* root)
+{
+
+  this->setClassID(CL_DOOR, "RepairStation");
+  this->scale = 1.0f;
+
+  if( root != NULL)
+    this->loadParams(root);
+
+  this->toList(OM_COMMON);
+
+  this->bActivated = true;
+  this->animationStep = 1;
+  this->animationCurrent = REPAIR_CYCLE01;
+
+  this->loadMD2Texture("maps/repairstation.jpg");
+  this->loadModel("models/creatures/repairstation.md2", this->scale);
+
+  this->setAnimation(REPAIR_CYCLE01, MD2_ANIM_ONCE);
+}
+
+
+RepairStation::~RepairStation ()
+{}
+
+
+
+/**
+ * loads the Settings of a MD2Creature from an XML-element.
+ * @param root the XML-element to load the MD2Creature's properties from
+ */
+void RepairStation::loadParams(const TiXmlElement* root)
+{
+  WorldEntity::loadParams(root);
+
+  LoadParam(root, "scale", this, RepairStation, setScale)
+      .describe("sets the scale of the repair station")
+      .defaultValues(1.0);
+}
+
+
+/**
+ * sets the animatin of this entity
+ */
+void  RepairStation::setAnimation(int animNum, int playbackMode)
+{
+  if( likely(this->getModel(0) != NULL))
+    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
+                                                         animationList[animNum].lastFrame,
+                                                         animationList[animNum].fps,
+                                                         animationList[animNum].bStoppable,
+                                                         playbackMode);
+}
+
+
+/**
+ * @returns the current animation number
+ */
+int RepairStation::getAnimation()
+{
+  if( likely(this->getModel(0) != NULL))
+    return ((InteractiveModel*)this->getModel(0))->getAnimation();
+  else
+    return -1;
+}
+
+
+
+/**
+ * @returns true if animation is finished
+ */
+bool RepairStation::isAnimationFinished()
+{
+  if( likely(this->getModel(0) != NULL))
+    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
+  else
+    return false;
+}
+
+
+/**
+ * this activates the repair station and makes it working
+ */
+void RepairStation::activate()
+{
+  this->animationStep = 1;
+  this->bActivated = true;
+}
+
+
+/**
+ * this deactivates the repair station
+ */
+void RepairStation::deactivate()
+{
+  this->animationStep = 0;
+  this->bActivated = false;
+}
+
+
+/**
+ * this toggles the rotation direction
+ */
+void RepairStation::toggleRotation()
+{
+  this->animationStep *= -1;
+}
+
+
+/**
+ * ticks the door
+ * @param time: time since last tick
+ */
+void RepairStation::tick (float time)
+{
+  if( likely(this->getModel(0) != NULL))
+    ((InteractiveModel*)this->getModel(0))->tick(time);
+
+  if( !this->bActivated)
+    return;
+
+  if( this->isAnimationFinished())
+  {
+    this->animationCurrent = (this->animationCurrent + this->animationStep) % REPAIR_MAX_ANIMATIONS;
+    this->setAnimation( this->animationCurrent, MD2_ANIM_ONCE);
+  }
+}
+
+
+
+
Index: trunk/src/world_entities/npcs/repair_station.h
===================================================================
--- trunk/src/world_entities/npcs/repair_station.h	(revision 9003)
+++ trunk/src/world_entities/npcs/repair_station.h	(revision 9003)
@@ -0,0 +1,63 @@
+#ifndef _REPAIR_STATION_H
+#define _REPAIR_STATION_H
+
+#include "world_entity.h"
+
+#include "md2/md2Model.h"
+
+class TiXmlElement;
+
+
+//! animation names enumeration
+typedef enum RepairStationAnimType
+{
+  REPAIR_CYCLE01 = 0,
+  REPAIR_CYCLE02,
+  REPAIR_CYCLE03,
+  REPAIR_CYCLE04,
+  REPAIR_CYCLE05,
+  REPAIR_CYCLE06,
+  REPAIR_CYCLE07,
+  REPAIR_CYCLE08,
+
+  REPAIR_MAX_ANIMATIONS
+};
+
+
+class RepairStation : public WorldEntity
+{
+  public:
+    RepairStation ();
+    RepairStation(const TiXmlElement* root);
+    virtual ~RepairStation ();
+
+    virtual void loadParams(const TiXmlElement* root);
+
+    void setScale(float scale) { this->scale = scale; }
+
+    void activate();
+    void deactivate();
+    void toggleRotation();
+
+    virtual void tick (float time);
+
+
+  private:
+    void setAnimation(int animNum, int playbackMode = 0);
+    int getAnimation();
+    bool isAnimationFinished();
+
+
+  private:
+    float          scale;             //!< the scale of the model
+
+    static sAnim   animationList[8];  //!< list of the animations
+
+    int            animationCurrent;  //!< number of the current animation
+    int            animationStep;     //!< the incrementation step of the animation
+
+    bool           bActivated;        //!< true if activated
+
+};
+
+#endif /* _REPAIR_STATION_H */
