extern void object::Move( )
{
	int     list[], i; // liste des objets cherchés
	int		slide;
	object  item;
	point	opp;
	float   dist, value;

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

	slide = cmdline(0);

	i = 0;
	list[i++] = Car;

	wait(rand());
	while ( true )
	{
		if ( glu() )  // bloqué dans les plantes ?
		{
			for ( i=0 ; i<slide ; i++ )
			{
				motor(-1, 1);
				wait(0.5);
				motor(1, -1);
				wait(0.5);
			}
		}

		item = radar(Trax);
		if ( item != null )
		{
			dist = distance2d(item.position, position);
			if ( dist < 20 )  // autre trax proche ?
			{
				opp.x = 2*position.x - item.position.x;
				opp.y = 2*position.y - item.position.y;
				opp.z = 2*position.z - item.position.z;
				go(opp, 2);  // fuite
				continue;
			}
		}

		item = radar(list);
		if ( item != null )
		{
			dist = go(item.position, 2);  // avance 2 secondes
			if ( dist < 0.5 )  // bloqué ?
			{
				motor(-1, -1);  // recule
				wait(3);

				value = rand()*2-1;
				motor(value, -value);  // tourne
				wait(3);

				motor(1, 1);  // avance
				wait(2);
			}
			continue;
		}

		wait(1);
	}
}

float object::go(point target, float delay)
{
	point   init;
	float   power, dist;
	int     i;

	init = position;
	power = direction(target);
	dist = distance2d(position, target);

	if ( dist < 30 and abs(power) > 135 )  // dans le dos ?
	{
		for ( i=0 ; i<2 ; i++ )
		{
			motor(0.0, 0.5);  // avance en zig-zag
			wait(delay/4);
			motor(0.5, 0.0);
			wait(delay/4);
		}
	}
	else
	{
		power /= 45;
		if ( power > 0 )
		{
			motor(1-power, 1);
		}
		else
		{
			motor(1, 1+power);
		}
		wait(delay);
	}
	return distance2d(init, position);
}

bool object::glu()
{
	object  item;

	item = radar(Greenery);
	if ( item == null )  return false;
	return ( distance2d(item.position, position) < 2 );
}
