The International Simutrans Forum

Simutrans Extended => Simutrans Extended Development => Topic started by: Vladki on July 11, 2020, 12:28:30 PM

Title: Public right of way and diversions
Post by: Vladki on July 11, 2020, 12:28:30 PM
I have prepared a few use examples where diversion check does not work as expected.   (max_diversion_tiles = 25)

1. (744,844) - cannot remove the diagonal (public road), although a short diversion is available. Here the problem may be caused by the diversion being formed by roads of two different players (elemental and derpy). I tried similar tricks on those many farm roads and it  worked well, even if the diversion was owned by 3 different players, and 4th did the removal of puhblic road...
Ah I found it - the diversion road was of lesser quality (tarmac) than removed public road (asphalt). That would be nice to tell players somehow.

2. Frequent case when I hit problems with diversions is raising or lowering city roads at crossings, to join stops around the corner. E.g (983,945). All roads around the corner block are less than 20 tiles. But you cannot delete the crossing tile with "r", and also you cannot disconnect any road from the crossing with "q" (it is just disconnecting, not removing). However you can break any of the roads leading away if the break is one or more tiles further. You can even break two roads at the same time (N+S or E+W). But you cannot raise or lower the crossing tile itself, which is often desired.
Title: Re: Public right of way and diversions
Post by: jamespetts on July 22, 2020, 02:52:23 PM
Thank you for the report. I note that 1 is not a bug.

Looking at no. 2, there are two relevant things here. First of all, the maximum diversion tiles is set to 25 and some of the diversionary routes necessary from this tile are exactly 25 tiles. I have just modified the code so that, if the diversionary route is less than or equal to (rather than just less than) the number of specified tiles, the route will be acceptable.

However, this does not allow that tile to be deleted. This is because one of the three diversionary routes necessary, that between 983,946 and 983,944 is measured as requiring a diversionary route of 33 tiles, whereas the maximum is 25. Having counted the tiles manually, it seems that it ought to be counting 23 tiles. The trouble is that the calculation of this route is done in intern_calc_route, which is complex code largely unchanged from Standard and very hard to debug. This is the basic vehicle pathfinding code, so, if there is an error here, it is a fundamental and very difficult error to deal with, and is not specific to the diversionary route system, and may even be common to Standard.
Title: Re: Public right of way and diversions
Post by: Vladki on July 22, 2020, 03:20:11 PM
OK. I tried with allowed diversion of 35 and was able to delete the crossing. So the problem is really in the pathfinding that it does not find the shortest diversion path. In that case the default diversion limit should be increased greatly. In real world diversions can be even 10s of kilometers long.

And perhaps an info in the refusal message, that the diversion would be x tiles, but allowed is only y tiles would be nice.
Title: Re: Public right of way and diversions
Post by: jamespetts on July 22, 2020, 05:13:18 PM
I suspect that the issue with the pathfinding is that it tries to find the lowest cost route, and the cost is not just the length of the route, but the number of corners and uphill/downhill segments. This is intended for vehicle pathfinding, but is not suitable for use in this context. I will have to look into disabling these elements when pathfinding for diversions.
Title: Re: Public right of way and diversions
Post by: jamespetts on July 22, 2020, 06:38:52 PM
I have just pushed a change that stops the path finder from taking into account turns and slopes in calculating the length of the route. However, this seems not to have affected the 33 tile route found in the above example.
Title: Possible public right of way diversion bug
Post by: Matthew on July 30, 2020, 06:04:07 PM
I am having problems building a public right of way diversion. It's very possible that I'm making a mistake, so please point out my error if so.

Steps to reproduce:
1. Download this Bridgewater-Brunel save (
2. Start a new instance of Simutrans-Extended 30/JUL/2020 (#26a3557) with pak128.Britain-Ex. (It must be a new instance to bypass the password protection).
3. Open the save.
4. Check that you are the Insular Navigation Company.
5. Go to (6850,1504) and build a MacAdam road due west to (6841,1504) and then south to (6841,1506).
6. Now try to demolish the previously existing route between those endpoints (running along the 1506th meridian) with either the Road Removal or general Demolition tools.
7. You will see the "Cannot remove a public right of way..." message.

Expected behaviour: You can remove the existing route because you have built a diversion of less than 18 tiles and of an equal or higher standard than the existing route.

It may be helpful to use the object ownership tool (O) to see the layout details.

EDIT: Apologies, this appears to be a duplicate of this bug (,20143.0.html), but I can't delete this thread. I hope this save is a useful test case anyway and it reinforces the case for greatly increasing the max_diversion_tiles value. This should be a very straightforward diversion.
Title: Re: Public right of way and diversions
Post by: jamespetts on August 15, 2020, 12:12:09 PM
I have merged the two topics.