Trams are, from the AI point of view, similar as it is for any player to road vehicles. When constructing something in AIRoad, you specify if you want to build road objects, or tram objects via AIRoad.SetCurrentRoadType. For example, to switch to Tram building:
and conversly to switch back to road vehicules :
Now if you do:
At those tiles a tram track will be produced. As you might understand it is important to keep track in which mode you are, else you might be in for a surprise ;)
As you might expect,
AIVehicle have a function:
GetRoadType, which either returns
AIRoad.ROADTYPE_INVALID if the object is not a road object, or else if it is a tram or road. So it is easy to find and select the engine or vehicle you want/like.
AIRoad also has the ability to check of any tile if it is either a road-tile or a tram-tile. The same goes for
HasRoadType to check if the tile/station has a tile/station for either Road or Tram.
You have to be careful if you want to make an AI that supports trams. As you can see, it is a simple switch to go from road to tram, and game-wise there is not much difference between road vehicles and tram vehicles, besides the fact trams look cool! The problem with trams is, you need a separate grf for it to work. Not everyone has this grf. So it is possible that when you try:
On your computer it tells you: true, and on some other computer it tells you: false. So never make your AI depend on trams, and always make sure to check if trams are available before using them. Of course it is perfectly acceptable to fall back to road in case tram is not available. Nothing really changes.