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 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

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);

This comment has been minimized.

Copy link
@frosch123

frosch123 Apr 13, 2020

Member

Missing root cause analysis.

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

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 merged commit 93a7ff6 into OpenTTD:master Apr 16, 2020
8 checks passed
8 checks passed
Commit checker
Details
OpenTTD CI Build #20200413.4 succeeded
Details
OpenTTD CI (Linux linux-amd64-clang-3.9) Linux linux-amd64-clang-3.9 succeeded
Details
OpenTTD CI (Linux linux-amd64-gcc-6) Linux linux-amd64-gcc-6 succeeded
Details
OpenTTD CI (Linux linux-i386-gcc-6) Linux linux-i386-gcc-6 succeeded
Details
OpenTTD CI (MacOS) MacOS succeeded
Details
OpenTTD CI (Windows Win32) Windows Win32 succeeded
Details
OpenTTD CI (Windows Win64) Windows Win64 succeeded
Details
LordAro added a commit to LordAro/OpenTTD that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.