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

Fix: [AI/GS] AreWaterTilesConnected wasn't handling aqueducts properly #8074

Merged
merged 1 commit into from Apr 16, 2020

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Apr 10, 2020

PR 8074 test AI.zip
aqueduct scenario.zip

There are 2 bugs being fixed. I have attached a scenario and an AI that must run with each other.

Bug 1: As an example, tiles 1700 and 1764 are connected, but AreWaterTilesConnected reports that they're not. There are others similar tiles that fall into the same bug.
Bug 2: As an example, tiles 2032 and 2096 aren't connected, but AreWaterTilesConnected reports that they are.

This PR attempts to fix those cases while still maintaining the results the same for the other test cases. I'm sure I didn't handle all the possible cases, but I hope the fixes don't break anything.

Donfingfield Transport, 2160-06-22

@frosch123
Copy link
Member

This bug is missing a root cause analysis.
GetTileTrackStatus() is used by pathfinders, and is very correct.
Replicating the functionality in custom code is prone to errors, in this case I would guess that aqueducts can be entered from below the aqueduct.

The real issue seems to be, that the direction passed to GetTileTrackStatus needs an additional GetReverseDiagDir, since GetTileTrackStatus expects an exitdir, while to_other_tile seems to be an enterdir.

@@ -62,13 +63,20 @@
DiagDirection to_other_tile = ::DiagdirBetweenTiles(t2, t1);

/* Determine the reachable tracks from the shared edge */
TrackBits gtts1 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t1, TRANSPORT_WATER, 0, to_other_tile)) & ::DiagdirReachesTracks(to_other_tile);
TrackBits gtts1 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t1, TRANSPORT_WATER, 0, INVALID_DIAGDIR)) & ::DiagdirReachesTracks(to_other_tile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing root cause analysis.

@frosch123
Copy link
Member

Maybe you also want to check the same for roads and rails.
I am quite sure those methods are also broken, though slightly different.

@frosch123 frosch123 added the backport requested This PR should be backport to current release (RC / stable) label Apr 16, 2020
@frosch123 frosch123 merged commit 93a7ff6 into OpenTTD:master Apr 16, 2020
LordAro pushed a commit to LordAro/OpenTTD that referenced this pull request May 10, 2020
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Jul 27, 2020
@SamuXarick SamuXarick deleted the aqueduct-connection-errors branch December 19, 2020 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants