Industry Stabilizer

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
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Industry Stabilizer

Post by Aphid »

This little script will prevent your map's industries from 'dying out'. It's useful on multiplayer servers that can run a prolonged amount of time without resetting.

It will automatically re-prospect your industries whenever it detects a production going 'low'.

There's a couple settings;

1: Interval which which to prospect. Range 5-480, Default is 32 days. Recommended to keep it at this level or higher, the script may overcompensate if it is set lower.
2: percentage to sustain of starting production. Usually 80-90% is a decent amount. Note that you can set this above 100% to get extra industries. Setting it to 0% effectively turns the script off.
3: debug level.


EDIT: This script is also incredibly useful for citybuilder servers for gauging their maps. You can use this to balance out your cargo requirements. For example run it a couple dozen times on generated maps and jot down the numbers it comes up with. Take the average over the measurement set and you get a ratio of demands. For example one map had a WATER of 2782 and a GRAIN of 7013, and a FRUT of 1902. That would mean 8915 food per 2782 water. In other words setting the food requirement about 3.2x the water requirement makes sense.

I was considering incorporating it in CityBuilder as an option; with also the option to automatically adjust Cargo Requirements based on the ratios. It doesn't make much sense when I can't obtain the production ratios of industry though.
Attachments
IndustryStabilizer.tar
(12 KiB) Downloaded 743 times
Last edited by Aphid on 30 Jul 2013 03:03, edited 1 time in total.
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: Industry Stabilizer

Post by R2dical »

Cool script!

I'm getting a crash though, seems it happens when the script tries to save.

EDIT: Defining the "data" variable first, in line 62 of main.nut, solved the crash.

Code: Select all

data = {sv_base = base_production,
to

Code: Select all

local data = {sv_base = base_production,
Attachments
Crash.jpg
Crash.jpg (61.36 KiB) Viewed 13936 times
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Industry Stabilizer

Post by Aphid »

It's been fixed. I've also updated the superlib versions of both my scripts.

Thanks for the bug report.
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Industry Stabilizer

Post by Aphid »

Industry Stabilizer has been split up into a script and library.

The script provides a bare-bones implementation of the library and is useful for reference purposes.
You can now incorporate the library into your own script in order to create or balance industry on your map according to your own production wishes.

The library can also be used to effectively create industry up to a certain production cap due to the way it's organized.
Effectively, nothing has changed in the gamescript.

EDIT: Industry Stabilizer also no longer depends on the SuperLib library because it used only one redundant function from there.

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

Re: Industry Stabilizer

Post by Zuu »

ISLib::Rebuild():

Code: Select all

	local OldConstr = GSGameSettings.GetValue("construction.raw_industry_construction");
	GSGameSettings.SetValue("construction.raw_industry_construction", 2);
Game Scripts are not limited by this setting in what industries it can build as long as no company mode is in scope. I see now that the docs are not perfectly clear about this. However, if you read the OpenTTD source code I think you can agree with my point. Thus the docs will get updated at next time the online docs are updated from source code (my guess is that you may need to allow up to 24h for that).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
maxucao
Engineer
Engineer
Posts: 8
Joined: 18 Mar 2014 03:57

Re: Industry Stabilizer

Post by maxucao »

HI!!! i stay keeping that error
"log index doesn't exist..."

any idea of what can i do to fix this?
topcatdk
Engineer
Engineer
Posts: 9
Joined: 11 May 2008 08:29

Re: Industry Stabilizer

Post by topcatdk »

Hi, I hope I don't get in trouble for reviving this old topic

I noticed this script a few days ago, I was (once again) hoping to find a newgrf that could prevent huge maps from becoming industry-barren before I could connect the far reaches, which has killed the game many times for me, and this showed up.

I did a test of it, fast-forward for 50 years and YES there were still raw-industries everywhere, even the fast-industry-killing-mode (smooth economy) now seems viable to actually play on a huge map, fun times ahead.

However I did get the same crash as the user above when saving, as the code failing is "log.info...." (always ironic when code made to help find bugs are the cause of crashes) I simply commented the offending line out in main.nut. Crash fixed, but I got a new one when loading, same cause, same fix.

The only (minor) problem is the oil-sources, if there are many land-wells their number will drop over time and they are often replaced by rigs... Hmm perhaps it is possible to make a script that maintain the number of each (raw)industry rather than the map-wide production for each cargo.
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: Industry Stabilizer

Post by Sylf »

topcatdk wrote:The only (minor) problem is the oil-sources, if there are many land-wells their number will drop over time and they are often replaced by rigs... Hmm perhaps it is possible to make a script that maintain the number of each (raw)industry rather than the map-wide production for each cargo.
The problem probably is not that of the script, but the game mechanics itself. Oil wells start to run dry after 1950 in temperate map. They will flourish in arctic or tropical maps.
topcatdk
Engineer
Engineer
Posts: 9
Joined: 11 May 2008 08:29

Re: Industry Stabilizer

Post by topcatdk »

Some bad wording on my part, sorry for that.

No it is not a fault in the script, in temperate climate it is however a result of the calculation method. The issue is very much rooted in the game's love of building Oil rigs wherever there is a piece of water free. As the script looks at the map-wide production of oil, it'll seem just fine even as the number of wells drops.

I've tried combining the script with manual industries, set to allow changes/closure but prohibit random construction of new ones, that very much reduced the issue, there's still a migration in numbers from wells to rigs, due to the script randomly choosing one when needing more oil, but it'll happen more slowly, and (in theory) ends up with the same amount of wells and rigs

EDIT: The above statement assumes starting a map with many wells and few (if any) rigs.
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Industry Stabilizer

Post by Aphid »

In the end, the script will put in a 'random industry', so, assuming an equilibrium is reached:

Suppose a well produces W units/mo, and a platform produces P units/mo. Wells decline at a rate of Rw, and platforms at Rp.

Then the ratios will be so that W * (1 - Rw) = P * (1 - Rp) when the equilibrium is reached.

So say the average well has half the production and decays twice as quickly, you end up with a 1:4 ratio.
Unfortunately, this ratio is independent of the water density on the map. So if you have say 10% water coverage, you end up with 40x as many oil rigs 'per water tile' compared to oil wells 'per land tile'. Dial the numbers even further and you can get some crazy amount of rigs per tile, I guess.

So, how do we 'fix' the issue?

I propose trying this:

1) I currently count cargo production in a 32-slot array, one for each cargo type.
2) Instead, use a 64-slot array, where we split the production using the first 32 slots for land-based, and the last 32 for water-based.
3) Separately build industries for both production numbers, so we get a 'water-based' set of industries for each primary cargo as well as a 'land-based' and production is maintained for both sets 'separately'.

The consequence would be that the oil well/rig situation will develop in the same way fish fields would in FIRS.

Would this seem like an okay idea?
Second, could you point me towards line numbers for those crashes?
topcatdk
Engineer
Engineer
Posts: 9
Joined: 11 May 2008 08:29

Re: Industry Stabilizer

Post by topcatdk »

Thank you for replying.

The crashes happen in line 46 and 54, both lines are "log.info..." and the error is something like "index log don't exist".

As for the wells/rigs issue I don't think it's worth the effort to try and change how the script works, I'm now 120 years into a game where I combined this script with manual industries (allow changes/closure, no random building of industries) and there's still plenty of wells around in the areas I've not started to service yet, so as long as the game's rig-building fetish is somehow blocked the problem is very minor.

Thank you for your work on the script, much appreciated
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Industry Stabilizer

Post by Zuu »

I just had a quick look at version 1 (top of thread) and version 6 (last from bananas). In version 1, the script includes SuperLib.Log as Log. In version 6, it do no longer import SuperLib, but have two lines of code 46 and 54 that calls Log.Info() from SuperLib. Those are easy to change into GSLog.Info if you just want to make the script work.

Line 46:

Code: Select all

	Log.Info("Saving data", Log.LVL_INFO);
=>

Code: Select all

	GSLog.Info("Saving data");
Line 54:

Code: Select all

	Log.Info("Loading data from savegame made with version " + version + " of the game script", Log.LVL_INFO);
=>

Code: Select all

	GSLog.Info("Loading data from savegame made with version " + version + " of the game script");
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 31 guests