Development
AI Programming
- API Documentation
- Introduction
- info.nut file
- main.nut file
- Basics
- Using the road pathfinder
- Using the rail pathfinder
- Saving / Loading data
- Things you need to know
- Squirrel
- Lists
- Coping with OTTD errors
- Trams
- AI Libraries
- Forum
- Forum FAQ
- AI Behavior
- ShortNames in use
AIs
All articles in NoAI categoryTrams 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:
AIRoad.SetCurrentRoadType(AIRoad.ROADTYPE_TRAM);
and conversly to switch back to road vehicules :
AIRoad.SetCurrentRoadType(AIRoad.ROADTYPE_ROAD);
Now if you do:
AIRoad.BuildRoad(33412, 33413);
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, AIEngine
and 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 AIStation
. Use HasRoadType
to check if the tile/station has a tile/station for either Road or Tram.
WARNING
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:
AIRoad.IsRoadTypeAvailable(AIRoad.ROADTYPE_TRAM);
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.