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

NPF refuses to pathfind when the destination tile is the same as where the vehicle currently is #7060

Closed
SamuXarick opened this issue Jan 13, 2019 · 5 comments

Comments

@SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Jan 13, 2019

For ships this means it will reverse (do a 180º turn) when there are tracks in front of it. It does not walk back. This doesn't happen with OPF or YAPF.

kefingway-on-sea transport 1950-01-11
NPF reverses the ship at the end of the tile. The other pathfinders walk back the tiles ahead.

Best way to reproduce:
Send a ship to a buoy as the only order.

@J0anJosep

This comment has been minimized.

Copy link
Contributor

@J0anJosep J0anJosep commented Jan 13, 2019

Yes. Seems a bug.
Changing just the end lines of this function

Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
{
	...

	if (ftd.best_trackdir == INVALID_TRACKDIR) {
		/* We are already at our target. Just do something
		 * @todo maybe display error?
		 * @todo: go straight ahead if possible? */
		path_found = true;
		return FindFirstTrack(tracks);
	}

	/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
	 * the direction we need to take to get there, if ftd.best_bird_dist is not 0,
	 * we did not find our target, but ftd.best_trackdir contains the direction leading
	 * to the tile closest to our target. */
	path_found = (ftd.best_bird_dist == 0);
	/* Discard enterdir information, making it a normal track */
	return TrackdirToTrack(ftd.best_trackdir);
}

Solves the problem.
But this is not how it is supposed to work. I will look further, as NPF should ignore first tile, and it is not ignoring it.

@PeterN

This comment has been minimized.

Copy link
Member

@PeterN PeterN commented Jan 17, 2019

Okay, but why does it need to pathfind to reach the tile its already at?

Or do you mean it refuses to pathfind through the vehicle's current tile? If so, what is wrong with turning around?

@J0anJosep

This comment has been minimized.

Copy link
Contributor

@J0anJosep J0anJosep commented Jan 17, 2019

Okay, but why does it need to pathfind to reach the tile its already at?

Because it is leaving the tile and needs to find a path back.

Or do you mean it refuses to pathfind through the vehicle's current tile?

Yes. NPF fails if destination tile is origin tile at the moment. It returns INVALID_TRACKDIR. I am looking into it. I have a branch here (6 commits), but I still have to investigate whether this works and doesn't cause new problems.

If so, what is wrong with turning around?

What is wrong in choosing a track on next tile? Are all-of-a-sudden-180º-turns better?

@PeterN

This comment has been minimized.

Copy link
Member

@PeterN PeterN commented Jan 17, 2019

I don't know, I'm just asking questions to work out what the actual problem is!

@J0anJosep

This comment has been minimized.

Copy link
Contributor

@J0anJosep J0anJosep commented Jan 17, 2019

I don't know either. Maybe just reversing is ok, but other pathfinders go ahead. I don't think reversing is ok in this situation, but I am not sure about it.

J0anJosep added a commit to J0anJosep/OpenTTD that referenced this issue Jan 26, 2019
@LordAro LordAro closed this in aa63517 Jan 31, 2019
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.