The International Simutrans Forum

 

Author Topic: bug in slope_t::opposite  (Read 502 times)

0 Members and 1 Guest are viewing this topic.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
bug in slope_t::opposite
« on: June 06, 2020, 09:07:20 PM »
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:

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: bug in slope_t::opposite
« Reply #1 on: June 07, 2020, 01:43:09 PM »
Thank you. Since the AI almost never ever build tunnels, this was indeed overlooked for a long time.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: bug in slope_t::opposite
« Reply #2 on: June 08, 2020, 04:28:00 PM »
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.