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

AI builds impossible/broken tiles #6951

Closed
nielsmh opened this issue Oct 30, 2018 · 2 comments
Closed

AI builds impossible/broken tiles #6951

nielsmh opened this issue Oct 30, 2018 · 2 comments
Labels
bug Something isn't working component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) regression It used to work, and now it's broken.

Comments

@nielsmh
Copy link
Contributor

nielsmh commented Oct 30, 2018

While testing another issue, I had an AI build this:
image

AI used in RailwAI v7 on master rev 50efaa2. Not tested with other AI scripts yet.
Does not happen in 1.8.0.

It seems the AI somehow builds two impossible tiles, and after building those it can't continue building the intended route. Using the switch company cheat, it is possible to demolish these tiles. (It's very cheap or free to do so.) The impossible tiles cause Hall of Mirrors effects when zooming, moving GUI over them, etc.

@nielsmh nielsmh added component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) bug Something isn't working regression It used to work, and now it's broken. labels Oct 30, 2018
@nielsmh
Copy link
Contributor Author

nielsmh commented Oct 30, 2018

It turns out the issue is that the AI selects railtype 0x20 or 0x21 (decimal 32 and 33) even though they don't exist. The cause is that a HasBit test is done with 32 bit wide integers, where it should be 64 bit wide, so a test for values >= 32 truncates. This means that a company with railtypes 0 and 1 (normal and elrail) available also appears to have railtypes 32 and 33 available. Those have higher ID, so the AI might assume they are automatically better.

OpenTTD/src/rail.cpp

Lines 188 to 191 in 50efaa2

bool HasRailtypeAvail(const CompanyID company, const RailType railtype)
{
return HasBit(Company::Get(company)->avail_railtypes, railtype);
}

The HasRailtypeAvail function is used for all relevant tests, it appears, and changing the HasBit call to explicitly use an uint64 template appears to fix this issue.

nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Oct 30, 2018
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Oct 30, 2018
@nielsmh
Copy link
Contributor Author

nielsmh commented Oct 30, 2018

The presence of this bug seems to be compiler-dependent, which you might expect. It's not present on a Linux system with g++ 8.2.1, only confirmed on Windows with Visual C++ 2015 Update 3.

nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Oct 30, 2018
Some compilers (like VC++ 2015) will otherwise narrow it in some contexts where it should not be.
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Oct 30, 2018
Some compilers (like VC++ 2015) will otherwise narrow it in some contexts where it should not be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) regression It used to work, and now it's broken.
Projects
None yet
Development

No branches or pull requests

1 participant