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

Cargodest destination selection not dependent on distance #2481

Closed
DorpsGek opened this issue Dec 27, 2008 · 3 comments
Closed

Cargodest destination selection not dependent on distance #2481

DorpsGek opened this issue Dec 27, 2008 · 3 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

PhilSophus opened the ticket and wrote:

I wanted to document the cargodest destination selection algorithm as this is the last item missing in the Wiki. When reading the code, I stumbled across the following code in RoutingSystem::GetDestination() in routing.cpp:

00604 uint dist = DistanceManhattan(GetStation(from)->xy, GetStation(target)->xy);
00605 uint maxdist = MapSize();
00606 uint sector = dist * 5 / maxdist;
00607
00608 /* Station is too far away */
00609 if (RandomRange(4) < sector) continue;

From my understanding, sector is intended to be the distance between source and destination normalized to 0..4. However, according to the above code it will always be 0, as MapSize() is the number of tiles in the map, i.e. MapSizeX() * MapSizeY(). So, a destination will never be rejected due to being too far away and the destination selection is not dependent on distance at all.

Line 605 should probably read as follows:

00605 uint maxdist = MapSizeX() + MapSizeY();

This way it is really the maximum achievable Manhattan distance on the map.

Reported version: Cargodest
Operating system: All


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

scoz wrote:

Applied the patch on my personal build. I'll let you know if things seem better as the game progresses(new game with all the fancy new patches I've found)


This comment was imported from FlySpray: https://bugs.openttd.org/task/2481#comment5173

@DorpsGek
Copy link
Member Author

Aali wrote:

The proposed change can cause some serious infinite loops, you should also change:

00609 if (RandomRange(4) < sector) continue;

to

00609 if (RandomRange(5) < sector) continue;

if you want to try this.


This comment was imported from FlySpray: https://bugs.openttd.org/task/2481#comment5361

@DorpsGek
Copy link
Member Author

peter1138 closed the ticket.

Reason for closing: Out of date

Cargodest is obsolete


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

@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) 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/)
Projects
None yet
Development

No branches or pull requests

1 participant