Possible infrastructure count overflow leading to negative infrastructure maintenance costs #7665
Version of OpenTTD
Tested on 20190707-master-g1e723934a1 and 20200509-master-g61e1a45100, 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
The text was updated successfully, but these errors were encountered:
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: