Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Fri Apr 19, 2019 3:21 pm

All times are UTC

Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Jul 24, 2013 7:22 pm 
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
This library handle engines properties by recording them in a base and returning results from it when query.
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:
import("Library.cEngineLib", "cEngineLib", 8);

The API documentation is inside the library, and some notes and examples are provided in the readme.
You can get it from your favorite bananas dealer. The source code is there :

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.
Vehicle functions:
    * 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
Misc functions:
    * 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

Last edited by krinn on Mon Jan 19, 2015 3:15 pm, edited 3 times in total.

PostPosted: Fri Aug 09, 2013 9:07 pm 
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
I have upload version 5 of the library that should be (except bugfixes) the final version, also add some more functions.

PostPosted: Thu Aug 22, 2013 9:29 am 
Transport Coordinator
Transport Coordinator
User avatar

Joined: Fri Dec 19, 2008 5:03 am
Posts: 314
Location: Indonesia
seems like a liltle bug here

Lindingstone Transport, 12th Jan 1983.png
Lindingstone Transport, 12th Jan 1983.png [ 23.85 KiB | Viewed 2807 times ]

Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
PostPosted: Thu Aug 22, 2013 9:55 am 
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Thank you fanioz, the problem with little bug in lib, is that it makes the AI crash, so there's no tiny bug.

I've upload v6 with the fix.

PostPosted: Mon Oct 28, 2013 4:59 pm 
Traffic Manager
Traffic Manager

Joined: Mon Mar 18, 2013 10:22 pm
Posts: 165
Thank you for this library, I am enjoying its features :)

I found 2 bugs, functions named cEngine, not cEngineLib, on lines 772 and 938, version 6 (Same issue as previous bug I think, renaming correctly causes those functions to work).

PostPosted: Wed Oct 30, 2013 1:35 pm 
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Thank you R2dical, i have commit the fixes and update the library version in bananas.
I suppose everyone can guess what was the original name of the library in my AI, and of course i still use it as derivative name into my AI hence why i didn't catch them.

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.