NoAI RoadTypes and RattRoads

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
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

NoAI RoadTypes and RattRoads

Post by RailwAI »

I tried to improve support for rattroads (multiple road types), but I'm a bit lost how I could detect the roadtype on a specific tile. There is no AIRoad.GetRoadType(tile), probabaly because a tile could contain both a tram road and a normal road. There is however a function AIRoad.HasRoadType(tile, roadType), but it works different from what I would expect. Could someone check if this is working as intended, a bug in rattroads newGRF or a bug in the NoAI API?
I have built 4 roads, as below, then I check what AIRoad.HasRoadType returns for different parameters: I try every available roadtype, as well as the "default" roadTypes and check 4 tiles with each a different roadtype on it. Seemingly all roadtiles have all road-roadtypes on it according to the API.
image_2021-03-29_211202.png
image_2021-03-29_211202.png (47.96 KiB) Viewed 1043 times
image_2021-03-29_211609.png
image_2021-03-29_211609.png (5.36 KiB) Viewed 1043 times
User avatar
Firrel
Engineer
Engineer
Posts: 118
Joined: 13 Aug 2019 17:06

Re: NoAI RoadTypes and RattRoads

Post by Firrel »

I have also encountered this behaviour. You can find the function code here. I dont understand it well enough to make assumptions if that is correctly implemented.

You can however use a workaround by using function AIRoad.ConvertRoadType in TestMode, which will return false with error ERR_ALREADY_BUILT when you try to upgrade with the same road type.
User avatar
RailwAI
Engineer
Engineer
Posts: 75
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: NoAI RoadTypes and RattRoads

Post by RailwAI »

The ::GetRoadTramType in the code hints that the function actually checks if for the given RoadType, it is checked whether the corresponding RoadTramType is present on the tile.
I think the best solution would be to have a new function GetRoadtype(tile, RoadTramType) introduced.
Edit: This might need some more rework, because the functions AIEngine.GetRoadType and AIVehicle.GetRoadType do not use any of the 'new' RoadTypes, but they return RoadType.ROADTYPE_ROAD / RoadType.ROADTYPE_TRAM. That behaviour matches more to the definition of RoadTramType.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 19 guests