extern void object::Move( )
{
	float	last, rel, abs, progress, dist, lp, ls, lost, over;
	point	p;
	object	item;
	int		counter, lng;
	bool	win;

	lng = language();
	errmode(0);  // ne stoppe pas si erreur
	while ( ismovie() != 0 )  wait(1);

	if ( tstarter() == 1 )
	{
		wait(3);
		action(6);  // flic
		wait(4);  // attend 3,2,1,go
		action(0);  // normal
	}
	else
	{
		action(6);  // flic
		wait(2.5);  // attend go
		action(0);  // normal
	}

	item = radar(Car);
	if ( item == null )  return;

	abs = 0.2;
	last = abstime();
	lost = 0;
	win = false;

	over = 10;
	if ( gamelevel() == 1 )  over = 20;
	if ( gamelevel() == 2 )  over = 15;
	if ( gamelevel() == 3 )  over = 12;

	counter = 3;
	progress = abs/5;
	lp = progress;
	ls = progress;
	p = traject(progress);
	gotoim(p);

	while ( true )
	{
		rel = abstime()-last;
		last += rel;
		if ( win && rel == 0 )  rel = 0.1;

		dist = distance2d(position, item.position);
		abs += rel*(2-dist/5);  // temps absolu prop. à 1/d

		progress = abs/5;
		p = traject(progress);
		gotoim(p);
		turnim(direction(item.position));

		// Choix de l'action du robot.
		if ( dist < 9 )
		{
			action(0);  // normal
		}
		else
		{
			action(6);  // flic
			lost += rel;
		}

		// Détection du sens de parcourt.
		if ( progress > ls )
		{
			ls = progress;
		}
		else
		{
			if ( ls-progress > 0.2 )
			{
				if ( lng == 1 )  message("Mauvais sens !!!", DisplayError);
				if ( lng == 2 )  message("Wrong direction !!!", DisplayError);
				if ( lng == 3 )  message("Falsche Richtung !!!", DisplayError);
				ls = progress;
			}
		}

		// Décompte du nombre  de tours.
		if ( progress > lp+1 )
		{
			counter --;
			iprogress();  // red led -> green
			if ( counter == 0 )
			{
				action(6);
				if ( lng == 1 )  message("Bravo, entraînement terminé", DisplayMessage);
				if ( lng == 2 )  message("Training finished, well done", DisplayMessage);
				if ( lng == 3 )  message("Bravo, Training beendet", DisplayMessage);
				superwin();
				win = true;
			}
			lp = progress;
		}

		// Détection du temps dépassé.
		if ( lost > over )
		{
			action(6);
			if ( lng == 1 )  message("Vous êtes trop lent. Recommencez ...", DisplayError);
			if ( lng == 2 )  message("You are too slow, try again ...", DisplayError);
			if ( lng == 3 )  message("Sie sind zu langsam, versuchen Sie es nochmal ...", DisplayError);
			wait(2);
			superlost();
			wait(100);
			return;
		}
	}
}

// Calcule un point sur la trajectoire formée d'une droite,
// d'un demi-cercle, d'une droite et d'un demi-cercle.
//
//  0.00 /---->----\ 0.35
//       |         |
//  0.85 \----<----/ 0.50

point traject(float progress)
{
	point	p;

	if ( progress < 0 )  progress = 0;
	progress = progress%1;

	p.z = 0;
	if ( progress < 0.35 )  // up line ?
	{
		progress = progress/0.35;
		p.x = 50+40*progress;
		p.y = 55;
	}
	else if ( progress < 0.5 )  // right circle ?
	{
		progress = (progress-0.35)/0.15;
		p.x = 90+5*sin(progress*180);
		p.y = 50+5*cos(progress*180);
	}
	else if ( progress < 0.85 )  // down line ?
	{
		progress = (progress-0.5)/0.35;
		p.x = 90-40*progress;
		p.y = 45;
	}
	else  // left circle ?
	{
		progress = (progress-0.85)/0.15;
		p.x = 50-5*sin(progress*180);
		p.y = 50-5*cos(progress*180);
	}
	return p;
}

