Thoughts on AIRoad with trams

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
Maninthebox
Engineer
Engineer
Posts: 113
Joined: 08 Aug 2008 11:35
Contact:

Thoughts on AIRoad with trams

Post by Maninthebox »

I realize I've discussed the getneigbourroadcount function before (http://www.tt-forums.net/viewtopic.php?f=65&t=38859), but it's time to do it again :)

The problem I'm facing at the moment is that trams is not a simple switch of roadtype like stated in the wiki, but actually shows some problems with the AIRoad class. If it's all working as intended, then perhaps the documentation can be made at bit clearer for some functions what to expect from then if you're using trams.

Allow me to illustrate: I would like to build a passenger tram stop in a town on a busy shopping street ;) So I look for road tiles, filter out the tiles already having a station on them and then select the tiles which have exactly 2 neighbours to make sure I'm not trying to build on a crossing (it's the same code I use for inline bus stops, but with extra debugging now):

Code: Select all

370             area.AddRectangle(AITown.GetLocation(town) - AIMap.GetTileIndex(curRange, curRange),
 AITown.GetLocation(town) + AIMap.GetTileIndex(curRange, curRange));
371
372             AIRoad.SetCurrentRoadType(AIRoad.ROADTYPE_ROAD);
373             area.Valuate(AIRoad.IsRoadTile);
374             area.KeepValue(1);
375             Debug("Town road tiles count (road mode): " + area.Count());
376
377             AIRoad.SetCurrentRoadType(AIRoad.ROADTYPE_TRAM);
378             area.Valuate(AIRoad.IsRoadTile);
379             area.KeepValue(1);
380             Debug("Town road tiles count (tram mode): " + area.Count());
381
382             area.Valuate(AIRoad.IsDriveThroughRoadStationTile);
383             area.KeepValue(0);
384             Debug("Town road tiles count without station (tram mode): " + area.Count());
385             area.Valuate(AIRoad.GetNeighbourRoadCount);
386             area.KeepValue(2);  // entrance and exit; allow 1 as well?
387             Debug("Town road tiles count with 2 neighbours (tram mode): " + area.Count());
The 4 debug statements give the following counts with a certain range:
35 road tiles (road mode)
35 road tiles (tram mode)
34 road tiles without stations (tram mode)
0 road tiles with 2 neighbours (tram mode)

And I can assure you there's plenty road tiles with exactly 2 neigbouring road tiles. So: IsRoadTile checks for road, regardless of current roadtype, whereas the neighbour count is actually dependent on the current roadtype. Wouldn't it be best if both were to be showing the same behaviour? After all, setcurrentroadtype says: "Set the RoadType for all further AIRoad functions." Or perhaps change the functions to have an extra optional parameter roadtype which defaults to the current type ( GetNeighBourRoadCount(tile, roadtype = currenttype) ), because now I have to switch to road to select a tile, then switch to tram to build the stop.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests