Transport Tycoon Forums

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

All times are UTC




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Industry Stabilizer
PostPosted: Sat May 25, 2013 1:09 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Fri Dec 16, 2011 5:08 pm
Posts: 166
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 370 times


Last edited by Aphid on Tue Jul 30, 2013 3:03 am, edited 1 time in total.
Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Wed Jul 17, 2013 8:18 am 
Offline
Traffic Manager
Traffic Manager

Joined: Mon Mar 18, 2013 10:22 pm
Posts: 165
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:
data = {sv_base = base_production,

to
Code:
local data = {sv_base = base_production,


Attachments:
Crash.jpg
Crash.jpg [ 61.36 KiB | Viewed 8431 times ]
Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Tue Jul 30, 2013 3:12 am 
Offline
Traffic Manager
Traffic Manager

Joined: Fri Dec 16, 2011 5:08 pm
Posts: 166
It's been fixed. I've also updated the superlib versions of both my scripts.

Thanks for the bug report.


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Tue Dec 17, 2013 7:30 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Fri Dec 16, 2011 5:08 pm
Posts: 166
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


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Tue Dec 17, 2013 8:45 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
ISLib::Rebuild():
Code:
   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)


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Tue Mar 25, 2014 3:04 am 
Offline
Engineer
Engineer

Joined: Tue Mar 18, 2014 3:57 am
Posts: 7
HI!!! i stay keeping that error
"log index doesn't exist..."

any idea of what can i do to fix this?


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Fri May 08, 2015 12:56 pm 
Offline
Engineer
Engineer

Joined: Sun May 11, 2008 8:29 am
Posts: 9
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.


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Fri May 08, 2015 1:48 pm 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
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.


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Sat May 09, 2015 9:34 am 
Offline
Engineer
Engineer

Joined: Sun May 11, 2008 8:29 am
Posts: 9
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.


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Thu May 14, 2015 5:50 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Fri Dec 16, 2011 5:08 pm
Posts: 166
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?


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Sun May 17, 2015 5:17 am 
Offline
Engineer
Engineer

Joined: Sun May 11, 2008 8:29 am
Posts: 9
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


Top
   
 Post subject: Re: Industry Stabilizer
PostPosted: Sun May 17, 2015 10:39 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
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:
   Log.Info("Saving data", Log.LVL_INFO);
=>
Code:
   GSLog.Info("Saving data");


Line 54:
Code:
   Log.Info("Loading data from savegame made with version " + version + " of the game script", Log.LVL_INFO);
=>
Code:
   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)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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.