FS#5344 - GSRoad::RemoveRoadFull() does not remove N/S half road pieces

Attached to Project: OpenTTD
Opened by xOR (xOR) - Thursday, 25 October 2012, 17:15 GMT
Last edited by Leif Linse (Zuu) - Thursday, 25 October 2012, 19:34 GMT
Type Bug
Category Script → Goal/Game script
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version 1.2.2
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


If GSRoad::RemoveRoadFull() is called with the same tile for start and end (so to remove only the road pieces on one tile) it does not remove single half road pieces if they are in north our south of the tile, only if they are in east or west.
This task depends upon

Closed by  Leif Linse (Zuu)
Thursday, 25 October 2012, 19:34 GMT
Reason for closing:  Fixed
Additional comments about closing:  Improved precondition check in r24628. See task comment for further details.
Comment by Leif Linse (Zuu) - Thursday, 25 October 2012, 19:33 GMT
We had a discussion among the devs, and agreed that the ScriptRoaod::RemoveRoad and ScriptRoaod::RemoveRoadFull functions are intended only for use when start != end.

In r24628 we have enforced this precondition and improved the documentation on this matter.

Before resolving this report there was a discussion at which may be of interest:

For removal of road bits on a tile you should be able to use RemoveRoad and use a start and end tile that are neighbours. If you plan to open up a feature request for a way to remove individual road bits, it would be useful if you provide a useful case when the current API doesn't provide a solution.

Thank you for the report.
Comment by xOR (xOR) - Thursday, 25 October 2012, 19:58 GMT
In my code the start and end is dynamic depending on other things, it can be a single tile or more tiles. So my workaround when I found this problem was to put the code like this:
if (start == end)
  GSRoad.RemoveRoadFull(start, end);

Works well, just looks a bit strange to me. I am tempted to ask the question "why can a RemoveRoad function not...remove road? in all cases?".

But I guess there is some internal technical limitation that makes it hard to enable that function to be used for a single tile? Anyway, I don't think a feature request is necessary here, from the chat log I saw the suggestion to just use the clear function for single tiles and this is what I am doing already, so no need for further changes on my side.
Comment by Thijs Marinussen (Yexo) - Saturday, 27 October 2012, 21:19 GMT
Because RemoveRoad detects the direction in which to remove road from it's parameters. If you remove road with a crossing in between the result will not be the same as using DemolishTile on all tiles. Because for a single tile no direction can be inferred from the start/end pair, there is nothing "good" to do. Removing both directions of road would be inconsistent with the multi-tile case, as is removing no road. The only sensible thing to do is to make start!=end a precondition and check for that, making it explicit in the documentation that that special case is not allowed.
Comment by Thijs Marinussen (Yexo) - Saturday, 27 October 2012, 21:19 GMT
Might I also ask why you use RemoveRoadFull instead of RemoveRoad?
Comment by xOR (xOR) - Sunday, 28 October 2012, 16:13 GMT
Thanks for the explanation, it makes sense now. I am using RemoveRoadFull because that's what I want: have the full road removed (so the full tile cleared from road tiles).