teshiron wrote:
(and I'm stubborn -- I want to figure it out myself and not shamelessly
stealborrow a method from another AI

)
Until then, I might make the number of vehicles a configurable setting in v4, and I welcome suggestions for other ways to tackle the problem.
So what do you want?
I am working on an AI as well. I use station ratings to figure out if another vehicle is needed. I'm going to have to rant a little, figuring this out was a little tricky.
A main difference between your AI and mine is that my buses have a full load in their first order. This means that bus and truck orders are very similar, I have the same function create them (the only difference is the given cargo ID). Full Load at station 1, regular stop at Station 2, then go to the depot if needed.
The tricky part is that Get Station Ratings requires a cargo ID. It is tough to tackle from the station side of things, because how do we know that there is only one cargo/industry within the range of the station. My solution is with the depots, every route has its own. This means:
Code:
local depotList = AIDepotList(AITile.TRANSPORT_ROAD);
foreach (depot, index in depotList){
Sleep(1);
local vehicleList = AIVehicleList_Depot(depot);
local vehicle = vehicleList.Begin();
local stationPos = AIOrder.GetOrderDestination (vehicle, 0);
local station = AIStation.GetStationID(stationPos);
local engine = AIVehicle.GetEngineType(vehicle);
local cargo = AIEngine.GetCargoType(engine);
if (AIStation.GetCargoRating (station, cargo) < 63) {
takeLoan();
local newVehicle = AIVehicle.CloneVehicle(AIOrder.GetOrderDestination (vehicle, 2), vehicle, false); // OrderDestination 2 is the Depot
AIVehicle.StartStopVehicle (newVehicle);
repayLoan();
}
}
Every route has its main station kept at very-good ratings. I have issues with over-building. Right now this is controlled by a Sleep(2500) between every call to this function. That is pretty much my whole while (true) loop. Every few years check for a new route, otherwise just maintain ratings.