Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Dec 12, 2018 1:23 pm

All times are UTC




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Nov 08, 2014 11:45 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
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:
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:
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:
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:
AIToyLib.ToyAskMoney(amount_of_money);


For a gamescript:
Add needed libs
Code:
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:
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:
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 Mon Nov 10, 2014 9:33 am, edited 1 time in total.

Top
   
PostPosted: Sat Nov 08, 2014 11:47 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Couldn't add more than 3 tar in previous message, so the AI sample is here...


Attachments:
AIToyLibTest-1.tar [30 KiB]
Downloaded 98 times
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 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-2018 phpBB Limited

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