AI Speed commands

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Thargoid wrote:
Also as I said in the thread I'm sure I've seen the hired escorts and some other ships fly, dead-stop, tumble and then shoot off again at speed, which would be another manifestation of this kind of action.
Ill look at it. But according to the code a full dead stop is never possible. All movement goes over the function appluThrust:

Code: Select all

- (void) applyThrust:(double) delta_t
{
	GLfloat dt_thrust = thrust * delta_t;
	BOOL	canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
	BOOL	isUsingAfterburner = (canBurn && (flightSpeed > maxFlightSpeed) && (desired_speed >= flightSpeed));
	float	max_available_speed = maxFlightSpeed;
	if (canBurn) max_available_speed *= [self afterburnerFactor];
	
	position = vector_add(position, vector_multiply_scalar(velocity, delta_t));
	
	if (thrust)
	{
		GLfloat velmag = magnitude(velocity);
		if (velmag)
		{
			GLfloat vscale = fmaxf((velmag - dt_thrust) / velmag, 0.0f);
			scale_vector(&velocity, vscale);
		}
	}

	if (behaviour == BEHAVIOUR_TUMBLE)  return;

	// check for speed
	if (desired_speed > max_available_speed)
		desired_speed = max_available_speed;

	if (flightSpeed > desired_speed)
	{
		[self decrease_flight_speed: dt_thrust];
		if (flightSpeed < desired_speed)   flightSpeed = desired_speed;
	}
	if (flightSpeed < desired_speed)
	{
		[self increase_flight_speed: dt_thrust];
		if (flightSpeed > desired_speed)   flightSpeed = desired_speed;
	}
	[self moveForward: delta_t*flightSpeed];

	// burn fuel at the appropriate rate
	if (isUsingAfterburner) // no fuelconsumption on slowdown
	{
		fuel_accumulator -= delta_t * AFTERBURNER_NPC_BURNRATE;
		while (fuel_accumulator < 0.0)
		{
			fuel--;
			fuel_accumulator += 1.0;
		}
	}
}
Tumble is even a special case that breaks of halfway. ............ you are right. Not a bug, but very intentionally.
After the break off halfway the code, the speed is decreased but also the [self moveForward: delta_t*flightSpeed]; makes that the actual ship is moved forward according to speed. performTumble is maybe mend as full stop as a very special effect :?: With any other behaviour it will slow down according the thrust settings.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The mineswept missiles are dead-stopping, or at least achieving a very small distance once their AI's are set to the new one. They're certainly not flying for the ~8 seconds that a max speed/thrust calculation would suggest, presuming the speed is reduced by thrust value per second (and if it's any faster clock cycle that will mean almost any ship or missile with "normal" thrust levels will dead-stop).

Follow the sequence in the PM and you'll see what I mean (just be careful of the station, it's quite nasty if provoked :twisted: ). Something's not working to plan somewhere here.

And if performTumble at speed is supposed to stop, tumble then carry on, then all I can say is it looks extremely odd when a ship in flight (especially at high speed or under injectors) does it ;)
Post Reply