ToyLib libraries to provide money to toy AIs

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

Post Reply
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

ToyLib libraries to provide money to toy AIs

Post by krinn »

Here's ToyLib that are libraries to allow any gamescript to gave money to other AIs that are toys or eyes candy AI, allowing them to stay alive.
Right now of course no GS support that, and no AIs too, but with the libs any AIs can run and ask money to a GS that handle that.

The key is to implement this, the AIs just need to add the lib and the GS just need to add the GS version of the lib.

Done that because i get bore streetcars get out of money and collapse, while i could implement this into my gamescript (well, ok only awards as it's the only i have done), building libs will allow any GS to gave that feature, so you could have a nocargoal or transportgoal (Zuu if you read this) or your favorite GS to play with, but still have your little toy AI keep doing their work. Isn't that nice, having both of the two worlds?

So ToyLib is 4 parts : ToyLib for GS, ToyLib for AI, a simple test AI, and a test GS (that i will upload to bananas), as it do nothing, yes, nothing by itself, but use the lib so its only work is providing money. Some users may wish play with a "no GS" stock openttd but still allow the toys AI to not collapse.

Everything is under GPLv2 license, the repo is again host (thank you very much guys!!!) there : https://dev.openttdcoop.org/projects/gslibrary-toy/
The libs use SCP to communicate with the AIs and avoid anyone use it to cheat for money. So only AIs can ask money, and only ones using the libs. If i see AI that aren't for toys/eyes candy... purpose using it to cheat, i will add a blacklist in it, as right now, any AI using the lib is allow to ask money (yeah, i might be foul, but i trust AI authors). GS can use a function to enable/disable giving money, so if the GS author add the option, server admins should still keep their trust on your script.

The libs are made to handle SCP for you, so SCP usage is abstract to anyone not knowing SCP, i've done the implementation as easy and minimal as i could. (Look at the samples given to see how it's easy).

Here's howto adapt your script to use them :
For an AI:
Add needed libs

Code: Select all

import("Library.AIToyLib", "AIToyLib", 1); // importing the ToyLib
import("Library.SCPLib", "SCPLib", 45); // If your AI use SCP you have that already
Add the lib init part somewhere in your AI init

Code: Select all

local dummy_init = AIToyLib(null); // for an AI not using SCP
local dummy_init = AIToyLib(your_scp_handle); // for an AI using SCP
within your AI loop, add

Code: Select all

AIToyLib.Check(); // for an AI not using SCP only, AI using SCP don't need that
And here's the function to ask some money

Code: Select all

AIToyLib.ToyAskMoney(amount_of_money);
For a gamescript:
Add needed libs

Code: Select all

import("Library.GSToyLib", "GSToyLib", 1); // importing the ToyLib
import("Library.SCPLib", "SCPLib", 45); // GS using SCP have that already
Add the lib init part somewhere in your GS init

Code: Select all

local dummy_init = GSToyLib(null); // for a GS not using SCP
local dummy_init = GSToyLib(your_scp_handle); // for a GS using SCP
within your GS loop add

Code: Select all

GSToyLib.Check(); // For a GS not using SCP only, GS using SCP don't need it
The gamescript part of the lib have more functions for gamescript, i highly encourage GS authors to support the GSToyLib.MoneyHandling function that will allow or disallow the lib to sent money as option to the user. See the GSToyLibHelper for an example implementation.
I have add a function to output stats of companies that get money from your GS (see GSToyLib.LogStats), server admin might enjoy having the option to use that function.
Last edited by krinn on 10 Nov 2014 09:33, edited 1 time in total.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: ToyLib libraries to provide money to toy AIs

Post by krinn »

Couldn't add more than 3 tar in previous message, so the AI sample is here...
Attachments
AIToyLibTest-1.tar
(30 KiB) Downloaded 256 times
User avatar
Firrel
Traffic Manager
Traffic Manager
Posts: 135
Joined: 13 Aug 2019 17:06

Re: ToyLib libraries to provide money to toy AIs

Post by Firrel »

Hi krinn,

I have been using ToyLib in RenewedVillageGrowth + CityLifeAI combination to create toy traffic and it is fantastic for this purpose. Since OpenTTD 1.11, GSCompany::ChangeBankBalance takes one extra parameter to refer to a location to show text effect on. After upgrading the GS to API version 12, the GSToyLib stopped working because of the wrong number of parameters. Would it be possible to fix this problem in a new release?
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: ToyLib libraries to provide money to toy AIs

Post by krinn »

hi,
i'm really out of time to get deep into this
what's your proposal for the fix? set last parametrer to GSMap::TILE_INVALID seems obvious

i will look if i still have the banana access to upload it after.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: ToyLib libraries to provide money to toy AIs

Post by krinn »

i hope this work, i can't test it myself now
i don't have access anymore to banana myself
Attachments
GSToyLib.2.tar
(40 KiB) Downloaded 32 times
User avatar
Firrel
Traffic Manager
Traffic Manager
Posts: 135
Joined: 13 Aug 2019 17:06

Re: ToyLib libraries to provide money to toy AIs

Post by Firrel »

Yes, that is the fix for it. Thank you for the fast reply.

I would like to have the updated version on BaNaNaS so that it can be automatically downloaded together with the GS. To regain access, there is a User migration guide. If you dont want to maintain it anymore, I can make the release.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: ToyLib libraries to provide money to toy AIs

Post by krinn »

please do, i won't have time or will to migrate
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests