OpenTTD

Tasklist

FS#2280 - AIVehicle.GetLocation not being updated during the travel

Attached to Project: OpenTTD
Opened by Julio Pedreira (jpedreira) - Monday, 08 September 2008, 17:33 GMT
Last edited by Patric Stout (TrueBrain) - Thursday, 11 September 2008, 11:03 GMT
Type Bug
Category Script → NoAI
Status Closed
Assigned To No-one
Operating System Linux
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

I'm using r14249-noai.

It seems that AIVehicle.GetLocation is not properly updated during the travel.

You can test it with:
local pos= AIOrder.ResolveOrderPosition(airplane, AIOrder.CURRENT_ORDER) ;
local destination_tile= AIOrder.GetOrderDestination(airplane, pos);
local current_tile= AIVehicle.GetLocation(airplane);
local airport= AIStation.GetStationID(destination_tile);
AILog.Info("Airplane "+AIVehicle.GetName(airplane)+ " going to "+ AIStation.GetName(airport)+", distance: "+AIMap.DistanceSquare(destination_tile, current_tile));
This task depends upon

Closed by  Patric Stout (TrueBrain)
Thursday, 11 September 2008, 11:03 GMT
Reason for closing:  Implemented
Additional comments about closing:  Commited in r14288.
Comment by Julio Pedreira (jpedreira) - Monday, 08 September 2008, 23:33 GMT
I've patched it for myself. The problem was due to:

1. In file "src/aircraft_cmd.cpp", in function "AircraftController", the following is done:
/* If vehicle is in the air, use tile coordinate 0. */
if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
which means that, if airplane is flying, tile 0 is used for computations.

2. In file "src/noai/api/ai_vehicle.cpp", in function "GetLocation", the following is done:
return ::GetVehicle(vehicle_id)->tile;
whic means that if airplane is flying, tile 0 is returned!!


To fix it, i've changed last mentioned line for:
if(::GetVehicle(vehicle_id)->tile!= 0)
return ::GetVehicle(vehicle_id)->tile;
else{
int32 x_pos= ::GetVehicle(vehicle_id)->x_pos/TILE_SIZE;
int32 y_pos= ::GetVehicle(vehicle_id)->y_pos/TILE_SIZE;
return TileXY(x_pos, y_pos);
}


If there's any way I can help you, like posting the patch or something... just tell.

Thank you,

Julio Pedreira.
Comment by Julio Pedreira (jpedreira) - Monday, 08 September 2008, 23:50 GMT
Patch is attached
   patch (0.6 KiB)

Loading...