Hello!
SuperLib is
- A utility library for AIs and Game Scripts
- divided into sub libraries (Helper, Tile, Direction, Road, Station, etc.)
- based on code that has been refactored out of CluelessPlus, PAXLink and a few more of my AI/GS projects. Mostly it is functions that more than one AI or GS project uses. But also in some cases it is methods that just might be useful for others or fit well in the library.
- licensed under the GPL 2 license
- automatically downloaded when you download most of my AIs and Game Scripts
SuperLib is not
- SuperLib is not useful for players unless it is a dependency for an AI or GS you want to use or write.
The Name
"Super" comes from that it is a library consisting of many sub libraries.
Sub libraries
- Log
A log system with support for log levels and user selection of which levels to print.
Helper
Sign functions, List functions, Max/Min/Clamp etc., GetPAXCargo
Money
Get information about available amonut of money etc. Also, take temporary max loans and re-store the old balance.
Tile
GetTileRelative, GetNeighbours (4 and 8), IsUpSlope(tile, direction), IsBuildOnSlope_UpSlope(tile, direction), etc.
Direction
Contains functions and constants for working with directions between tiles.
Also see this image: http://wiki.openttd.org/Image:Directions.png
Engine
Get travel time for new engines over some distance. Check if there exist an engine for a given cargo.
Vehicle
Where are the vehicles? On a station? Within a given tile list? Does a given tile list has one or more vehicles on it?
Industry
Is a given cargo produced by a given industry?
Station
Check if a given cargo is accepted by a station. Get a list of all the front tiles or why not demolish a station? ;-) It can also get a list of all vehicles that visit a station and get the type of station that a given vehicle needs.
Airport
Build/upgrade airports for industries and towns.
Order
Get the current destination of a vehicle (could for example be a depot not in the order list). Removal of all orders of a vehicle with shared orders without breaking the shared-status. Get a list of stations from a vehicle etc.
OrderList
1. Create an instance of this class
2. Build a list of desired orders
3. Tell it to apply the desired orders to a vehicle
4. Repeat 3. for any number of vehicles you want.
OrderList has been designed to not remove orders more than necessary when changing orders of a vehicle, to reduce the risk of it loosing the current destination it heads towards.
RoadPathFinder
A wrapper around the A* based road path finder library. It changes some costs and adds ability to cross rail/canals with bridges.
RoadBuilder
A class that connects two tiles by first path finding and then building road. If road building fails, it repeats a few times before giving up. This class also contains a static member to replace a level rail crossing with a road bridge.
Road
Build road stops for industries and towns.
Rail
Check if two adjacent rail tiles are connected.
Story
Helper methods for working with GSStoryBook. (this sub library is only available in the GS edition)
Usage
As a bonus from my decision to put the shared code between my AIs in a library it will be easier for other AI developers to reuse this code by simply loading the library. A short explanation on how the library is intended to be included and used follows here.
Code: Select all
import("util.superlib", "SuperLib", 2); // Import SuperLib version 2
/* For the sub libraries that you want to use,
* you might want to give them shorter names
* like this:
*/
Helper <- SuperLib.Helper;
Tile <- SuperLib.Tile;
Direction <- SuperLib.Direction;
Code: Select all
Helper.SetSign(tile, "my sign");
// Or if you didn't create the "Helper" short name:
SuperLib.Helper.SetSign(tile, "my sign");
You can also browse the source code here: http://hg.openttdcoop.org/superlib
Get SuperLib
- BaNaNaS - in game content download
- BaNaNaS - website: http://bananas.openttd.org/en/ailibrary/
- hg - development version - http://dev.openttdcoop.org/projects/superlib/repository
Old versions
Old AI editions can be found here: http://noai.openttd.org/downloads/Libraries/
For GS, check out from VCS the revision of that version, edit nogo_translator.py so that the paths there work for you and then run the script to compile the GS edition from the master edition which is for AIs.
Uploading of AIs (or GSs) that use SuperLib to BaNaNaS
When you upload an AI or GS via the web interface for BaNaNaS, you can currently only set the last version of each library as dependencies. So either you need to get that changed by convincing TrueBrain to do that, or you have to make sure your AI works with the last version of SuperLib.
If you need to specify an old version as dependency, it is possible if you use musa instead of the web interface.
I will not make any promises regarding backward compatibility etc. as this library was mainly created to give me somewhere to put shared code. (2012: However over the years since I first started SuperLib, the backward compatibility have been hold for most cases except fixed bugs. The only thing that I really can think of is that I from time to time update the library to use the API version of the last released stable, but at that time most users should have already upgraded to that stable.)
Contributions
Contributions to the library are welcome.
-------------------------------------------------------
Old first post
Hello!
As you probably know I maintain both PAXLink and CluelessPlus. While they behaviour quite differently to the player they still share quite some code. Maintaining the same code at two locations is not good when this code grows. Therefore I have decided to move towards creating libraries of the common code so that it can be shared between the two AIs. As a bonus other people will have easier to access and reuse this code.
My utility functions are organized as static functions in different classes depending on the category of the function.
Since only one main class can exist in a NoAI libraries I had two choises
- Make one library of each utility class.
- Make one super class and then add the utility classes as sub classes.
For now I have went for the first option. This may in the future create a quite large set of libraries which could be an argument of trying to make one big library containing all the utility functions. For me it would probably be easier to maintain one library than many but my first attempts of creating a super-library failed so for now I have made three separate libraries. Making a big library will also solve the problem that you can't have cyclic dependant libraries which already has required me to duplicate one function.
Preview
Below I've listed some functions that exist in the three different libraries and attached them. I'll upload them to BaNaNaS either as separate libraries or as a super-library depending on how I choose to continue when I will upload next CluelessPlus or PAXLink version.
Util.Helper
Sign functions, List functions, Max/Min/Clamp etc., GetPAXCargo Util.Direction
Depends on Helper
Contains functions and constants for working with directions between tiles.
Also see this image: http://wiki.openttd.org/Image:Directions.png Util.Tile
Depends on Helper and Direction
GetTileRelative, GetNeighbours (4 and 8), IsUpSlope(tile, direction), IsBuildOnSlope_UpSlope(tile, direction), etc.
If you think it is a better idea I could release my libraries in a 'Zuu' category.
Edit: 2010-03-10: I've disabled smilies, so that "8)" isn't turned into a smiley.