void Game::animtest()
{
   if (game->isClient())
      return;

   setGameThread();

   map("animtest");

   HANDLE player, bot;
   HANDLE botai;

   while (!player)
   {
      // find our player
      int i, num_players;

      num_players=numPlayers();
      i=0;
      while (i<num_players)
      {
         HANDLE p;
         p = getPlayer(i);
         if (!p->getAI())
         {
            player=p;
            break;
         }
         i+=1;
      }
      sleep;
   }

   while (!bot)
   {
      // find our bot
      int i, num_players;

      num_players=numPlayers();
      i=0;
      while (i<num_players)
      {
         HANDLE p;
         p = getPlayer(i);
         if (p->getAI())
         {
            bot=p;
            botai=p->getAI();
            break;
         }
         i+=1;
      }
      sleep;
   }

   HANDLE this_thread;
   this_thread = get_this_thread();

   while (~bot && ~player)
   {
      int msg;

      msg = this_thread->getNextMessage();
      while (msg) //forward all messages received to the rules
      {
         // handle message
         string command;
         if (msg==ANIMTEST_COMMAND)
         {
            string command;

            command = this_thread->getMessageParam1();

            if (command=="walk")
               botai->walk();
            else if (command=="run")
               botai->run();
            else if (command=="look")
            {
               HANDLE joint;

               joint = this_thread->getMessageParam2();
               botai->setFacing(joint->getPos());
               botai->setLookWhereMove(false);
            }
            else if (command=="act")
               botai->playAct(ANIMTEST_ACT);
            else if (command=="wait")
               botai->wait(ANIMTEST_WAIT);
           
         }
         msg = this_thread->getNextMessage();
      }
      sleep;
   }

   slog("!!!! game over !!!!");
}

void Trigger::animtest_walk()
{
   if (game->isServer())
      game->postGameMessage(ANIMTEST_COMMAND, "walk");
}

void Trigger::animtest_run()
{
   if (game->isServer())
   {
      game->postGameMessage(ANIMTEST_COMMAND, "run");
   }
}

void Trigger::animtest_playact()
{
   if (game->isServer())
   {
      game->postGameMessage(ANIMTEST_COMMAND, "act");
   }
}

void Trigger::animtest_wait()
{
   if (game->isServer())
   {
      game->postGameMessage(ANIMTEST_COMMAND, "wait");
   }
}

void Trigger::animtest_look_nw()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_nw");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_n()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_n");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_ne()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_ne");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_e()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_e");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_se()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_se");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_s()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_s");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_sw()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_sw");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}

void Trigger::animtest_look_w()
{
   if (game->isServer())
   {
      HANDLE model;

      model = trigger_owner->getModel();
      if (model)
      {
         HANDLE joint;
         joint = model->getJoint("look_w");
         if (joint)
            game->postGameMessage(ANIMTEST_COMMAND, "look", joint);
      }
   }
}
