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: AirportGetNearestTown incorrectly assumed first TileIterator result was origin. #11565

Merged
merged 1 commit into from Dec 9, 2023

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Dec 9, 2023

Motivation / Problem

AirportGetNearestTown uses the first result of TileIterator and assumes it is the origin tile. However not all TileIterators are equal, and some do not start at the top-corner, so the perimeter check was wrong.

AirportTileTableIterator iterates the tiles in the airport spec, which is made up from a list of offsets. These can start anywhere within the layout.

As the perimeter is used to limit the range of tiles that are checked, if it is wrong then some tiles will be missed, which can result in the wrong town being returned. This then leads on to station noise level being applied/removed from the wrong town.

Description

As the caller already has the origin tile, pass that and use it to determine the perimeter instead.

This issue was found by asserting that TileX(cur_tile) and TileY(cur_tile) were within the perimeter bounds.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@PeterN PeterN force-pushed the fix-airport-get-nearest-town branch from 1115f8a to 08f7a10 Compare December 9, 2023 00:52
src/station_cmd.cpp Outdated Show resolved Hide resolved
…ult was origin.

Not all TileIterators are equal, and some do not start at the top-corner, so the perimeter check was wrong. As the caller already has thie origin tile, use that instead.
@PeterN PeterN force-pushed the fix-airport-get-nearest-town branch from 08f7a10 to a989a11 Compare December 9, 2023 02:24
@PeterN PeterN merged commit c0ea058 into OpenTTD:master Dec 9, 2023
20 checks passed
@PeterN PeterN deleted the fix-airport-get-nearest-town branch December 9, 2023 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants