[GS] Think globally, act locally

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

Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

[GS] Think globally, act locally

Post by Wahazar »

I found interesting script on bananas: Town_and_Industry_Control-3.1, which was created for limiting random growth of industry: it require to serve certain percentage of industry to have chance of new industry to be built.
Very clever idea, I hate map cluttered by insane amount of industries (especially when grfs such FIRS are active and industry is not limited by town number).
Unfortunately, script have some bugs (author forgot to change fraction to percentage) and seems that it is unfinished, no impact of served towns was taken into account, and there was some other issues, for example sharp conditions.

Therefore I decided to rewrote it.

Now there is something like macroeconomic index, which depend on:
[*]ratio of served towns to total number of towns
[*]ratio of served industries to total number of industries
[*]amount of game years.
Both served towns and industries can increase this index, but elapse time make it harder.
New industry would be appear if macroeconomic index is high enough to be considered as indices f wealth economy, or if number of served industries meets predefined criteria.
If option "Try to keep the number of industries on map" is checked, new industries would also replace closed ones, if economy index is not utterly negative.

Additionally, small towns require passenger and mail service for growth, medium (population threshold depend on economy index) require food and/or good cargo delivered, and large towns require fuel and building materials (it is possible to omit this by setting zero requirements). Any grf which use FOOD, GOOD, PETR and BDMT cargo designators should be compatible with this script.
Town growth is very slow, if global economy index is utterly negative.

I uploaded this script to Bananas.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
sevenfm
Engineer
Engineer
Posts: 117
Joined: 25 Jul 2016 23:44
Location: Soviet Russia

Re: [GS] Think globally, act locally

Post by sevenfm »

Very interesting script! I tested it in a quick game and I have some questions:
1. How the transported percentage is calculated? I can understand it for pass/mail - the town produces passengers and mail so the game calculates amount of produced/transported, but how it calculates percentage of other goods? How much food/goods/etc I need to deliver to a town, does it depend on town size?
2. In my test the town with population of about 1300 had high passenger transport percent so the town window showed 'growing', but the town population was actually decreasing, probably because of low economy index (like -30). Other towns that had no passenger service did not change population.
3. It seems you don't need to deliver mail, just transporting passengers is enough for very high percentage (like 96%), is there a way to change it so the town would need both pass and mail transport, for example 70% pass and 30% mail percentage is taken into account, so to achieve high percentage you will need to transport both high percentages of pass and mail, but pass is more important?
4. Using slow vehicles to transport passengers (like horse busses from PolRoad set) results in pass percentage jumping from very high to very low in some months, probably because travel time is greater than month (like 43 days).
5. You don't need to connect towns, just local service is enough to grow town, is there a way to change it so the town will also/only take into account pass/mail transported from other towns?
6. Amount of game years making game more complex seems too artificial for me, just like inflation that I never use - I don't like that game becomes harder just because time passes and not because something happens in a game world. Is there a way to change it, for example use total number of industries as a limiting factor, so every new industry on the map makes raising economy index a bit harder? I also like to start early like in 1700 or 1800 and don't want the game to became too hard in 1900 or so just because I like to start with horses and sails.
7. Maybe take into account total town population on map, so even if you serve all industries on map and all towns and the economy index is still too low for new industries to open, you can grow population and it will allow new industries.

Thank you!

I am using Spring 2013, ECS, TTRS Early Mod, started test in 1830, started script with default settings.
I like trains. They are soothing.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Thanks for review! I want to emphasise, that I'm not a original author, it is just remake of James work.

Some issues were fixed, v.6 is here: http://openttd-polska.pl/attachment.php?aid=1069
The most important change is, that there are now following modes of town growth:
1. below 5k citizens, pass+mail must be fulfilled to enable typical openttd mode of growht,
above 5k, growth depend on pass, mail and consumer goods have impact on town growth rate (the lattero nes with higher weight), above 10k additionally industry goods must to be delivered
(it is still possible to grow without these but much harder).
1.
How the transported percentage is calculated?
It was not calculated properly, it is fixed now.
2. Economy mood have no impact on small towns (currently I even removed this feature). Shrinking occurs when one building is replaced by another smaller (or in construction stage), it is openttd feature.
BTW, this script protect small towns, if town is below 35, it will regrow itself.
3. I prefer general categories in contrary to specific cargo, which can be or cannot be accepted.
4. in case of larger towns (above 5k), growth speed is now calculated as an average of current and previous growth value, it should give more smooth model.
5. No idea how to handle this, but maybe it can be done by creating some subsidies from/to given town and checking if they are fulfilled?
6. Original script had hard limit of served industry limit. Feature with economy depend on game years is for give possibility of creating additional industries short after start of the game. It is just easier to fulfil requirements at the start, but don't mind if you can't - requirement is not scaled linearly, but asymptotically to the number defined by script settings.
7. Good idea. Some kind of average town population.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
sevenfm
Engineer
Engineer
Posts: 117
Joined: 25 Jul 2016 23:44
Location: Soviet Russia

Re: [GS] Think globally, act locally

Post by sevenfm »

sevenfm wrote:4. Using slow vehicles to transport passengers (like horse busses from PolRoad set) results in pass percentage jumping from very high to very low in some months, probably because travel time is greater than month (like 43 days).
Found that it was a bug in Spring2013 which incorrectly calculates supplied cargo, and as a result GetLastMonthTransportedPercentage returns garbage if supplied+received cargo exceeds town production last month, so it's not a problem of script.
In OpenTTD 1.6.1 GetLastMonthTransportedPercentage works fine.
McZapkie wrote:5. No idea how to handle this, but maybe it can be done by creating some subsidies from/to given town and checking if they are fulfilled?
Should be possible using something like GSStationList_CargoPlannedByFrom, by analyzing town stations and cargo flow.
Creates a list of origin stations of cargo planned to pass a station, with the monthly amounts of cargo planned for each of those origin stations as values.
https://nogo.openttd.org/docs/trunk/cla ... l#_details
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

New version 7 is available on bananas (and tested on my JGRPP server).

I'd rewritten town growth mechanism, using town goals for smaller towns, rules are now as follows, depending on population
below 25: town will regrow itself
below 250: standard growth
below 2500: standard growth with passenger goal threshold
below 5000: standard growth with passenger and mail threshold (+food if not temperate, regardless of town location)
below 10000: growth depend on passenger and mail transport (above goals still apply)
below 20000: growth depend on passenger, mail and consumer goods transport (ibidem)
above 20000: growth depend on passenger, mail consumer good and industry resources transport (ibidem).

Additionally, if town is well served, there is chance to create subsidy from this town to another one, no matter if other one is already served or not, distance is not limited (but probability is lower). It works fine with cargodist, however I recommend to diminish subsidy announcements (there is lot of them).
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Version 12 was uploaded to bananas.
Town growth model was tweaked. There are three cargo groups: consumer goods, raw energy and farm resources, industry supplies - which are required when town exceed 5k, 10k and 20k inhabitants, accordingly.

Beside of passenger subsidies, mail subsidies are generated as well, but are rare - occurs only between large towns and if economy index is positive.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

New version 13 is available, subsidy generation is tweaked to avoid multiple subsidies for given town pair, and town growth is tweaked.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Version 14 was released.
I decided to make stockpiles for raw and energy goods, thus town growth is more smooth now in case of irregular supplies.
It doesn't apply to consumer supplies such food, goods etc, they should be supplied often, but usually it is not an issue, industry grfs such FIRS or ECS usually are spawning such industries near town, thus one can supply batch of raw products and gain stable stream of consumer goods using local delivery vehicles.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
dol422
Transport Coordinator
Transport Coordinator
Posts: 310
Joined: 29 Dec 2015 20:06
Location: England

Re: [GS] Think globally, act locally

Post by dol422 »

It seems the script crashes upon game load. Index 'TE_GOOD' is non-existant.

Screenshot below
Attachments
Think Globally, Act Locally Crash.png
(247.19 KiB) Not downloaded yet
Take a look at: http://www.tt-forums.net/viewtopic.php?f=47&t=74993
Why do it tomorrow when you can do it today
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Thanks for report, my typo, should be TE_GOODS, I was testing it only in winter climate and didn't notice it.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: [GS] Think globally, act locally

Post by romazoon »

Very nice work with this script, i like it a lot.

Though i just experienced a script crash, i was bulldozing a few unserviced industries before it happened.
Attachments
Baan Baa Railways, 12_02_2000.png
(79.15 KiB) Not downloaded yet
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Thanks for testing. I added two null assertions in v.17, it should help.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Question: Minimum number of industries?

Post by HapticTactic »

Hi, McZapkie! Thank you for this outstanding script. Enjoying it a lot in multiplayer!

I have a question: Is it currently possible to somehow limit the minimum number of industries of a given type occuring on the map? Because we play the game really slowly and carefully (we have custom difficulty on our server forcing players to invest money wisely and fine-tune flow of cargo and maintenance costs), we always get to the point where there is only one instance for all types of industries we had no time to serve yet (because the industries were closed and no new industries appear because our global economy index does not make enough impact yet).

An example: In my current game I finally decided I would transport wood from a forest to a paper mill. However the lone forest is so far from the lone paper mill on this map that it is currently financially impossible to realize this project. And this often happens for all neglected industries.

Any suggestions for this?

Thanks!

Best regards
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

I recommend to disable closure of industries (both FIRS and ECS have such option)
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

I play with standard OTTD industries.

So there is no way to have industries closing but still make the game playable on large maps? I would like the script to punish me somehow but not to the point where there are only single instances for each type of industry, if you know what I mean.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

HapticTactic wrote:I play with standard OTTD industries.
What about viewtopic.php?t=50564 then?
Standard industries, but with more option for closure/creation etc.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

Thanks. Will check it out.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Another advice is to use small density of industries - for example Very Low setting.
Especially it is important in case of FIRS, where you need to fulfill economy index requirement for generating newer industries such plastic plants etc. In such case, custom numbers of towns + 1 industry per tow are recommended.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

Thank man! Appreciate the tips. I am currently testing a new game with some settings changed so I will see how it goes.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

How does "Fund new buildings" in towns work with your script? I experimented with it a bit but it isn't clear to me.

Thank you.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests