Page 1 of 1

NoAI RoadTypes and RattRoads

Posted: 29 Mar 2021 19:18
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 1170 times
image_2021-03-29_211609.png
image_2021-03-29_211609.png (5.36 KiB) Viewed 1170 times

Re: NoAI RoadTypes and RattRoads

Posted: 30 Mar 2021 15:20
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.

Re: NoAI RoadTypes and RattRoads

Posted: 31 Mar 2021 16:50
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.