SuperLib: Helper, Direction, Tile, ... libraries

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Kogut wrote:SuperLib 28 is not appearing in BaNaNaS for r25561 and 1.3.2-RC1. 27 appears to be the top available version.
Strange. I can find version 28 in 1.3.2-RC1 (see attachment, assuming you refer to the AI edition).

If I look at the Banans manager, the only restriction set is that at minimum OpenTTD 1.1 is required.
Attachments
SuperLib 28 in 1.3.2-RC1.png
SuperLib 28 in 1.3.2-RC1.png (26.42 KiB) Viewed 6705 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

It is appearing in "main menu|check online content" list, it is not appearing in "main menu|AI/game scripts settings|check online content" list.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Kogut wrote:It is appearing in "main menu|check online content" list, it is not appearing in "main menu|AI/game scripts settings|check online content" list.
I haven't checked the source code, but my guess is that "main menu|AI/game scripts settings|check online content" will filter on AI/GSes and only include other content if it is a dependency for an AI or GS.

Edit: To clarify, my guess is that there is no AI yet that depend on SuperLib 28.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

I discovered that in current OpenTTD demolishing a demolished tile is free. Therefore _SuperLib_Money::BurnMoney is not working properly. Here is a fixed version (unfortunately the new one affects multiple tiles, not only single one :( ).

Code: Select all


function _SuperLib_Money::BurnMoney()
{
	while(true)
	{
		local empty_tile = _SuperLib_Tile.GetRandomTile();
		if(AITile.IsBuildable(empty_tile))
		{
			if(!AITile.DemolishTile(empty_tile)) break;
		}
	}
}

Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by HGus »

You can still use a single tile by alternating demolition and building (a single tree is enough) :?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

That is a great idea, thanks! This version includes this idea, handles next game mechanics change (loan, negative bank balance and bankruptcy) and fixes situation where money spending was interrupted.

Code: Select all

function _SuperLib_Money::BurnMoney()
{
	AICompany.SetLoanAmount(AICompany.GetMaxLoanAmount());
	local empty_tile = null;
	while(true)
	{
		for(local i = 0; i < 1000; i++)
		{
			empty_tile = _SuperLib_Tile.GetRandomTile();
			if(AITile.IsBuildable(empty_tile))
			{
				while(true)
				{
					if(!AITile.DemolishTile(empty_tile)) 
					{
						if(AIError.GetLastError() == AIError.ERR_NOT_ENOUGH_CASH) {
							return;
						}
						break;
					}
					if(!AITile.PlantTree(empty_tile)) 
					{
						if(AIError.GetLastError() == AIError.ERR_NOT_ENOUGH_CASH) {
							return;
						}
						break;
					}
				}
			}
		}
		AIController.Sleep(500);
	}
}
Note:

Code: Select all

	/*
	 * Wastes money (may be used to ensure bankruptcy)
	 * Note that this function will probably not return until your AI
	 * has wasted all its money.
may now be

Code: Select all

	/*
	 * Wastes money (may be used to ensure bankruptcy)
as it always will waste all money before returning.

EDIT: It would be a good idea to add documentation of returned value to BuildNextToRoad (it seems to be null on failure, tile index of constructed structure on success).

EDIT2: I just discovered that Squirrell includes enums - http://www.squirrel-lang.org/doc/squirrel2.html#d0e925 (what seems a proper solution for "what" parameter in BuildNextToRoad)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Kogut wrote:EDIT: It would be a good idea to add documentation of returned value to BuildNextToRoad (it seems to be null on failure, tile index of constructed structure on success).
This has been fixed in the next version that will shortly be announced.
Kogut wrote:EDIT2: I just discovered that Squirrell includes enums - http://www.squirrel-lang.org/doc/squirrel2.html#d0e925 (what seems a proper solution for "what" parameter in BuildNextToRoad)
I suspect that enums fail to work for the same reason that consts don't work. At least in SuperLib, I have settled for using static members to emulate enums. See for example direction.nut. In this case, the "what" string is just not a simple enum. For MagicDTRS, it is also used to specify the length of the DTRS to build. That said you can use the named methods declared above BuildNextToRoad for possible more pretty code to call construction of a specific thing in situations when you don't need to handle the things in a generic way.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Version 30
changelog wrote:Feature:
  • Story.NewStoryPage2 - returns an array with both page id and page elements
Fix:
  • Airport::GetNumAircraftInAirportQueue didn't support heliports. (HGus)
  • Use improved Money::BurnMoney by Kogut
  • Document return value of BuildNextToRoad

Thanks to Kogut and HGus for the contributions included in this release.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Update - Version 31

Sorry, I found a problem in version 30 just after releasing it. This update ensure that the StoryBook API is not reported to be existing in eg. 1.3.2-RC2 and other 1.3.x RCs.
changelog wrote: Fix:
  • Detection of if StoryBook API exist gave false positives on 1.3.x RCs
    released later in time than the introduction of StoryBook. Now look for
    cargodist as a sign that StoryBook also exist. (a check for the revision
    when StoryBook and CargoDist was introduced in trunk filters out old patch
    CargoDist builds)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

Unfortunately there is problem also with v31.
Attachments
Bez tytułu.png
Bez tytułu.png (54.22 KiB) Viewed 900 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Kogut wrote:Unfortunately there is problem also with v31.
Hmm, it appears that what triggers it is that GSGoal is used as default arg parameters and therefore is evaluated at compile time.

I'll figure out a solution on how to bend the packaging to solve this. (one is to use a compiler also for the AI edition, but that slows down development)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Update - Version 32
changelog wrote:Fix:
  • AI version of SuperLib 30 and 31 was not working because OpenTTD interpreted
    GSGoal in story.nut too early (and killed the AI because of that)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by R2dical »

Pretty awesome set of scripts. I'm taking a shot at writing an AI to expand my programming knowledge :)

Anyway, maybe I am doing something dense, but I am getting the same crash you reported fixed in version 32 ?(
Attachments
Crash.png
Crash.png (18.36 KiB) Viewed 899 times
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

This one is a different one, 31 would crash before "RadAI Started". But anyway - thanks for report!
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

AI Update - Version 33

This update is only for AIs. For GSs version 32 is still the last version.

Changelog:

Code: Select all

Fix:
- The NoBuild custom RPF had usage of GS API (roadpathfinder.nut)
- Fix: Station.IsCargoSupplied used GS API calls (station.nut)
(The now only remaining location where GS API is used explicitly is in story.nut, which is not included in the AI edition - as those includes are commented out in the AI/master version and only activated by the GS edition compiler)

Thank you for the report.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

There is a report about a bug in SimpleAI. It appears in GetInflationRate function that was imported to SuperLib.

http://www.tt-forums.net/viewtopic.php? ... 6#p1087476

So once new version of SimpleAI will be released also SuperLib should be updated.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Thanks Kogut for the reminder. I've fixed this locally and will include it in the next release.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Update - Version 35

Sorry for the version spam today. I hope this is the last version.

Changelog:

Code: Select all

Change:
- Require minimum r25621 to consider StoryBook existing. r25620 and r25621
fixes two important bugs of the StoryBook. Before that it is better to fall
back to GSGoal.Question than annoying users with these known bugs.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Kogut »

Code: Select all

	return (money / 100) * _SuperLib_Money.GetInflationRate();
I am not sure whatever it is OK that money%100 is ignored (for example Inflate(90) will always return 0).

Maybe

Code: Select all

	return (money / 100) * _SuperLib_Money.GetInflationRate() + (money % 100) * _SuperLib_Money.GetInflationRate();
?

On the other hand - it is hard to imagine that such amount of money will be used in AI code.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Bing [Bot] and 12 guests