News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

bug in slope_t::opposite

Started by kierongreen, June 06, 2020, 09:07:20 PM

0 Members and 1 Guest are viewing this topic.

kierongreen

this is more to document a fix that I'll be apply to trunk tonight hopefully - not sure how long this has been there as it only is triggered under very specific circumstances - for example when the AI was trying to build a bridge or tunnel from a double slope

In ribi.h there is the line
static type opposite(type x) { return is_single(x) ? (x & 7 ? (40 - x) : (80 - x * 2)) : flat; }

this should be (I believe but will test further):
static type opposite(type x) { return is_single(x) ? (x & 7 ? (40 - x) : (80 - x)) : flat; }

x can (with double heights) be 4, 8, 12, 24, 28, 36, 56 or 72. This function returns 36, 64, 28, 32, 12, 4, -32 and -64 respectively for these values, whereas the corrected function will return 36, 72, 28, 56, 12, 4, 24 and 8.

opposite was only called by tunnelbauer - where it creates a mask to remove wayobjs and wegbauer, where it is in the routines to automatically create bridges and tunnels.

For following screenshots set up simple situations for the AI to deal with. As this behaviour only triggered on double height slopes it wouldn't be apparent in pak64

And in pak128.Britain when you have a single height situation it's also correct:

However for double height situations you end up with this:

Or more simply this:

prissi

Thank you. Since the AI almost never ever build tunnels, this was indeed overlooked for a long time.

kierongreen

Just to say a fix to both slope_t::opposite, and then the wider AI bridge builder has been added to trunk as this was needed to avoid further errors including a crash. I have tested this as much as I can today but please do more and if you encounter any issues let me know.