Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Possible infrastructure count overflow leading to negative infrastructure maintenance costs #7665
Version of OpenTTD
Tested on 20190707-master-g1e723934a1, though bug probably present since the dawn of OpenTTD
When you have more than 2,147,483,647 road pieces, then the infrastructure count should just keep on going up with no overflow.
When you have more than 2,147,483,647 road pieces, the infrastructure count in the company window does not overflow right away, but in the infrastructure detail window, it does. Additionally, without NewGRFs and with default settings, the amount you are paying for road infrastructure maintenance yearly (proportional to approximately [count]^1.5) flips from positive £32.654 trillion to negative £32.654 trillion.
EDIT: At 4,294,967,296 road pieces (and all multiples thereof), the infrastructure count in the company window DOES overflow, going back to 0. In both cases, the cause is that all infrastructure counts are stored as 32-bit integers (uint32 in the company window, signed int32 for infrastructure details window and infrastructure cost calculation).
Savegame to test/reproduce
Sharkey & Co., 3002-07-20D (overflow).zip
Steps to reproduce
Company infrastructure counts are stored as 32-bit unsigned (
However, infrastructure counts are also stored and updated as if they were 32-bit signed (
The same signed 32-bit infrastructure counts are used to calculate the maintenance cost of a piece of infrastructure in this function:
which is invoked in: