Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Goto Depot not always working for road vehicles. #249

Closed
DorpsGek opened this issue Jul 18, 2006 · 1 comment
Closed

Bugfix: Goto Depot not always working for road vehicles. #249

DorpsGek opened this issue Jul 18, 2006 · 1 comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay

Comments

@DorpsGek
Copy link
Member

mart3p opened the ticket and wrote:

There is an error in the function GetVehicleTrackDir in vehicle.c that often returns incorrect values for road vehicles. This function is used when pathfinding to depots by YAPF and NPF. This bug is in the trunk code but also in 0.4.7, maybe it should also be fixed for 0.4.8.

To reproduce the error:-

  1. Ensure YAPF is selected for road vehicles or NPF is on.
  2. Build 2 road vehicle stops and a depot with a number of bends and T-junctions between them.
  3. Set a road vehicle to run between the stops.
  4. Click on the vehicle's 'Goto Depot' button as it is entering a bend or a T-junction. The message "Can't send vehicle to Depot... Unable to find local depot" often occurs even when there is an easily reachable depot within a few tiles

Cause of error:-
The line:
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
is causing the problem. When a vehicle is entering or exiting a bend, using v->direction to determine the vehicle's TrackDir does not work, as the direction the vehicle is facing is not a valid TrackDir for the tile that the vehicle is on. For example, when first entering a road bend tile the vehicle is pointing across the tile, but there is no possible track across the tile in that direction.

Fix:-
The vehicle's TrackDir can easily be determined as in is held by vehicle->u.road.state while the vehicle is moving along a normal road. Note, vehicle->u.road.state holds different information while the vehicle is in a road stop or depot, but GetVehicleTrackDir already treats these as a separate cases.

The only slight difficulty with this is that a road vehicle's vehicle->u.road.state uses the unused values of TrackDir (values 0x6, 0x7, 0xE and 0xF) to indicate that the vehicle is turning around (through 180°). In these cases the existing code (using vehicle->direction to determine the TrackDir) can still be used.

The attached patch contains the necessary change to correct this bug.

Attachments

Reported version: 0.4.7
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/249
@DorpsGek
Copy link
Member Author

Darkvater closed the ticket.

Reason for closing: Fixed


This comment was imported from FlySpray: https://bugs.openttd.org/task/249

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Vehicles patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay labels Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay
Projects
None yet
Development

No branches or pull requests

1 participant