Code: Select all
// Pick an engine (ship)
local Engines = AIEngineList(AIVehicle.VT_WATER);
// Keep only buildable engines
Engines.Valuate(AIEngine.IsBuildable);
Engines.KeepValue(true.tointeger());
// TO-DO: Keep only engines we can afford AIEngine.GetPrice(EngineID)
// Keep only ships for this cargo
Engines.Valuate(AIEngine.CanRefitCargo, CargoNo);
Engines.KeepValue(true.tointeger());
// Keep only ships under max capacity
// "In case it can transport multiple cargoes, it returns the first/main."
Engines.Valuate(AIEngine.GetCapacity);
Engines.RemoveAboveValue((AIIndustry.GetLastMonthProduction(MetaLib.Industry.GetIndustryID(BuildPair[0]), CargoNo) * this._CapacityDays)/365);
// Pick the fastest one
Engines.Valuate(AIEngine.GetMaxSpeed);
Engines.Sort(AIList.SORT_BY_VALUE, AIList.SORT_DESCENDING);
local PickedEngine = Engines.Begin();
Log.Note("Picked engine: " + AIEngine.GetName(PickedEngine), 2);
(I do have FISH 0.9.2, and OpenGFX+ Trains 0.2.5, among others NewGRF active)