So this remove the newGRF problems we could met because AIEngine cannot answer some queries until a vehicle was built with that engine.
It should support any newGRF, but a special handling for 2cc trainset is include as it was need.
The library offer some other helpers for engine & vehicle, mostly aim at train : function to track information, a more advance CanPullCargo function that allow you to bypass ai_special_flag setting from newGRF. An automated function to find best engine base on your own heuristic (but one is provide per default).
Everything in it is made to do its work alone, the library is able to buy and sell vehicle itself to discover new properties of a never built engine, test train locomotive compatibility with wagons, or apply a constrain : gives me the best wagon with that train or gives me the best train and wagon to carry wood...
This is a generic implementation of a class i use in DictatorAI to handle my engines, so now everyone could benefits from it too, and get more accurate information to base their heuristic to find out what could be the best engine.
The library is made so it doesn't even need to be instanciate, but you need to keep its import name, so to use it just add:
Code: Select all
import("Library.cEngineLib", "cEngineLib", 8);
You can get it from your favorite bananas dealer. The source code is there : http://dev.openttdcoop.org/projects/ailib-cengine
Thank you for using it & reporting bugs.
Here's an incomplete list of functions from the API :
Engine functions:
- * GetBestEngine : to find out the best engine.
- * Incompatibility & blacklisting functions and their handling
- * EngineFilter : a function to remove classic conditions out of list of engines
- * GetLength : get the length of an engine unrefit or refit to a cargo (like AIVehicle.GetLength but works on engine)
- * GetCapacity : same as AIEngine.GetCapacity but can report the capacity of the engine when refit to a cargo
- * IsLocomotive: is engine a locomotive
- * CanPullCargo : like AIEngine.CanPullCargo but can bypass the ai_special_flags from newGRF
- * GetPrice : Get price of an engine including refit costs if need.
- * VehicleGetWeight : Get The total weight of a vehicle (with handling of freight_trains)
- * VehicleGetMaxTractiveEffort : Get the total tractive effort from the vehicle
- * VehicleGetMaxPower : Get the total power from the vehicle
- * VehicleGetRailTypeUse : Get the railtype the vehicle is running on
- * VehicleGetMaxSpeed : Get the max speed the vehicle could do (handling railtype limit and wagons speed limit)
- * VehicleGetNumberOfLocomotive : Get number of locos present in the vehicle
- * VehicleLackPower : Answer if your vehicle need more loco to carry its cargo load (handle slope_steepness, freight_train and train_acceleration_model)
- * VehicleGetNumberOfWagons : Get number of wagons vehicle have (excluding loco engine)
- * VehicleRestrictLength : Sell wagons from vehicle to keep it under a length limit
- * GetMaxWagons : Get maximum number of wagons that could be use within a length limit
- * IsDepotTile : Get if the tile have any depot
- * GetDepotType : Get the type of depot found at a tile
- * RailTypeGetFastestType : Get the railtype that can reach the highest speed
- * RailTypeGetSpeed : Get the speed of a railtype