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 1 commit into from Apr 16, 2020


Copy link

@SamuXarick SamuXarick commented Apr 10, 2020

PR 8074 test

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

Copy link

@frosch123 frosch123 commented Apr 13, 2020

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

@frosch123 frosch123 Apr 13, 2020

Choose a reason for hiding this comment

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

Missing root cause analysis.

@SamuXarick SamuXarick force-pushed the aqueduct-connection-errors branch from c5d33e1 to 03c4fed Compare Apr 13, 2020
@SamuXarick SamuXarick force-pushed the aqueduct-connection-errors branch from 03c4fed to b42ebb4 Compare Apr 13, 2020
@SamuXarick SamuXarick requested a review from frosch123 Apr 14, 2020
Copy link

@frosch123 frosch123 commented Apr 16, 2020

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 label Apr 16, 2020
@frosch123 frosch123 merged commit 93a7ff6 into OpenTTD:master Apr 16, 2020
8 checks passed
LordAro pushed a commit to LordAro/OpenTTD that referenced this issue May 10, 2020
@LordAro LordAro added backported and removed backport requested labels Jul 27, 2020
@SamuXarick SamuXarick deleted the aqueduct-connection-errors branch Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants