AIRoad.RemoveRoad() failing

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

AIRoad.RemoveRoad() failing

Post by MinchinWeb »

I was trying to remove extra roads using AIRoad.RemoveRoad(), but it kept leaving little bits of road, almost all (all?) on steep slopes. The road would have originally been a straight line down the hill, with the road tiles removed in a random order. Using AIRoad.RemoveRoadFull() seems to fix it. Is this a feature, or a bug?
Attachments
Road Removal Fail 2.png
Road Removal Fail 2.png (119.67 KiB) Viewed 2020 times
Road Removal Fail.png
Road Removal Fail.png (164.05 KiB) Viewed 2020 times
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIRoad.RemoveRoad() failing

Post by Yexo »

It's a bug of your AI, not a big in OpenTTD. The upper part of a sloped road tile can't be removed without the lower part of the same tile. If you use AIRoad,RemoveRoad() in a random order, you'll try to remove the upper part of a tile before the lower part of that tile. That'll fail partially, so the upper part of that tile stays while the lower part of the adjacent tile will be removed (and AIRoad.RemoveRoad() returns True since part of the road is removed).Later you'll remove the lower part of the same tile, which will succeed, leaving a half-tile road at the upper half of the tile as you can see in your screenshots. Using AIRoad.RemoveRoadFull() is one solution, however using that you might remove a roadbit too much at the connecting road. Another solution that works in every case would to first call AIRoad.RemoveRoad() form the tile connection the stray road tile to the existing road and call AIRoad.RmoeveRoadFull() for the rest of the road you want to remove.
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: AIRoad.RemoveRoad() failing

Post by MinchinWeb »

If I were to use RemoveRoad() going up the hill, would that solve the problem (thus removing the lower part of the road before the top part)?
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIRoad.RemoveRoad() failing

Post by Yexo »

Yes. Be aware of roads that go uphill, downhill and uphill again.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests