Page 6 of 9

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

Posted: 06 Jul 2013 18:38
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.

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

Posted: 07 Jul 2013 12:02
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.

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

Posted: 07 Jul 2013 17:27
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.

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

Posted: 08 Jul 2013 08:25
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;
		}
	}
}


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

Posted: 09 Jul 2013 21:09
by HGus
You can still use a single tile by alternating demolition and building (a single tree is enough) :?

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

Posted: 10 Jul 2013 04:00
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)

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

Posted: 15 Jul 2013 11:50
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.

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

Posted: 15 Jul 2013 11:52
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.

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

Posted: 15 Jul 2013 12:29
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)

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

Posted: 15 Jul 2013 13:02
by Kogut
Unfortunately there is problem also with v31.

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

Posted: 15 Jul 2013 13:25
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)

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

Posted: 15 Jul 2013 13:56
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)

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

Posted: 18 Jul 2013 20:16
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 ?(

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

Posted: 19 Jul 2013 05:52
by Kogut
This one is a different one, 31 would crash before "RadAI Started". But anyway - thanks for report!

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

Posted: 19 Jul 2013 08:09
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.

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

Posted: 21 Jul 2013 08:47
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.

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

Posted: 21 Jul 2013 15:46
by Zuu
Thanks Kogut for the reminder. I've fixed this locally and will include it in the next release.

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

Posted: 21 Jul 2013 16:13
by Zuu

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

Posted: 21 Jul 2013 18:39
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.

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

Posted: 21 Jul 2013 22:25
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.