[NoGo] City Growth Limiter

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
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

[NoGo] City Growth Limiter

Post by Sylf »

Since the introduction of version 1.2 beta series of this game, that includes a small feature that shows the rate of town growth, on this particular server that I help to maintain (coop's Welcome Server), I've seen multiple instance of pointless city growth by random players. (It's just too fun to watch how fast a city can grow, and they get to boast to others how they've accomplished such a feat.)

Then it just dawned on me - is it possible to limit the city growth by rate of the passengers transported from that city?

With that idea, with some tips from planetmaker and inspiration from Zuu's Neighbors are Important script (actually, I copied much of the code from it), I came up with this crude script. It checks the rate of passengers and mail transported compared to what that city generated. More of them are transported - the town grows faster. Also, smaller cities will grow at faster pace. That's all this script does. It doesn't add any cargo requirements for the city growth.

I wanted to post the script here first before posting it on bananas to see
1) are there any bugs people come across?
2) what do people think about the growth rate set by the script?
3) any other feed back?
Last edited by Sylf on 30 Aug 2014 07:04, edited 1 time in total.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] City Growth Limiter

Post by Zuu »

You can probably remove this from the Start function:

Code: Select all

Log.Info("Create town list ... (can take a while on large maps)", Log.LVL_INFO);
Just looping over all towns and add them to a list is not that slow even with lots of towns. What I do is to for each town also loop over all other towns. That is why it take long time on maps with many towns.


Edit: Perhaps degrade this log statement to LVL_DEBUG or LVL_SUB_DECISIONS:

Code: Select all

	Log.Info("End of Town Management.", Log.LVL_INFO);
Otherwise you use the log system for no good really if you log everything at the same log level, you could just use GSLog.Info(..) directly.


Edit2: In Town.nut, use Helper.GetPAXCargo() and Helper.GetMailCargo() to aquire the id of those cargos instead of hard coding 0 and 2. That way you keep better compatibility with NewGRFs. Both those functions cache the result in a hidden global variable, so except for the first call, they are very fast.

Edit3: You should change version.nut to indicate the version of your Game Script, which I believe is 1 and not 3. Usually this value is kept in info.nut, but I moved it to version.nut that is included by both info.nut and main.nut so that I can access the version number of the script at run time. If you don't need that you can remove version.nut and replace SELF_VERSION with 1 in info.nut.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] City Growth Limiter

Post by Sylf »

Thanks for the code review, Zuu.

The comment about log level was a good one. The comment about cargo class helper was very helpful. I assumed there would be such function somewhere, but I couldn't find it on my own before posting it.

I made the fixes to address those issues, as well as to fine tune other sections of the script. Here's the updated version. I'll go ahead and post this to bananas and wait for more reactions.
Attachments
City_Growth_Limiter-1.1.tar
(29 KiB) Downloaded 614 times
kmo300
Engineer
Engineer
Posts: 2
Joined: 03 Jun 2011 12:20

Re: [NoGo] City Growth Limiter

Post by kmo300 »

hello,
how can I use the script? So where do I extract it to?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] City Growth Limiter

Post by Zuu »

You must use OpenTTD 1.2 beta or a recent nightly.

Preferable download it using the in-game online content download. That way you get dependencies automatically. If you can't use online content, place
  • City_Growth_Limiter-1.1.tar in OpenTTD/game
  • SuperLib-19.tar in OpenTTD/game/library
Where OpenTTD can either be your installation directory or eg. C:users<your name>DocumentsOpenTTD or the equivalent of that on your OS.

Edit: Link to the NoGo edition of SuperLib and not the AI edition.
Last edited by Zuu on 22 Jan 2012 11:12, edited 1 time in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: [NoGo] City Growth Limiter

Post by MinchinWeb »

Zuu wrote:
Zuu, you link to the AI version of your library, not the GameScript version (which is what is needed here).
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] City Growth Limiter

Post by Zuu »

Thanks for noticing. I've fixed my post.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: [NoGo] City Growth Limiter

Post by Alberth »

Your script is generating a lot of town growth commands, which are the same almost every time.
This causes a lot of useless network traffic in MP games.

Attached you will find a patch with a possible solution, I hope it is of use to you.
Attachments
changes.patch
(2.33 KiB) Downloaded 371 times
leifbk
Chairman
Chairman
Posts: 814
Joined: 23 Dec 2013 16:33
Location: Bærum, Norway

Re: [NoGo] City Growth Limiter

Post by leifbk »

This script doesn't seem to work in ottd 1.4.0. I tried it in a new game, and set the passenger and mail limits to 20 %, and the population totally exploded.
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] City Growth Limiter

Post by Sylf »

I just uploaded updated version of this script on bananas. It should work well with OpenTTD 1.4 and up.

I've reworked much of the code inside. Not only should it work well, it shoud be more efficient, thanks to ideas contained in Alberth's patch above.

More details in this update:
  • The calculation for growth rate for each town is much simpler: If the goal is met, rate is set to OpenTTD default. If it's not met, city won't grow.
  • The transport rate is now displayed in the town dialog window
  • The growth rate for the city is updated only if the new rate is different from the last time the transport rate is checked
  • The script exits immediately upon loading the map if town_growth_rate is set to 0
  • The script exits immediately upon loading the map if both pax rate and mail rate parameters are set to 0%
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: [NoGo] City Growth Limiter

Post by Transportman »

Starting a game with this GS and setting the required mail to 0 results in a script crash.
Attachments
Unnamed, 1st Jan 2173.png
Unnamed, 1st Jan 2173.png (123.66 KiB) Viewed 2578 times
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] City Growth Limiter

Post by Sylf »

Thanks for checking it out and reporting that bug.

I made the fix, and uploaded version 5 (complete with changelog file this time!) to bananas.
User avatar
V453000 :)
President
President
Posts: 946
Joined: 01 Feb 2011 11:22
Location: Beer

Re: [NoGo] City Growth Limiter

Post by V453000 :) »

Thanks! :)
ImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: [NoGo] City Growth Limiter

Post by Transportman »

Bug-ish report: This script seems to disable the setting to fund new buildings, is that intended behavior?

Feature Request-ish request: Would it be possible to increase the maximum value for the minimum size setting? Currently it is limited to 1000 inhabitants, which I think is a bit low. Personally I would prefer to only have limits after ~2000-3000 inhabitants.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: [NoGo] City Growth Limiter

Post by romazoon »

Hi, i tried to add this script to (the famous) Cindini's scenario, and when launching a game the script crash right a the start.
Also the AI/script window poping up have nothing written inside !
(i tried on 1.4.0 and on 1.4.2)

Of course i m assuming we can add a script to a scenario after creation (it seems to work with other script at least), but i may be wrong ;)
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] City Growth Limiter

Post by Sylf »

@Transportman Yes, I disabled funding of new buildings specifically. It's not a bug. If you want to grow a town for a brief period of time, you can run advertisement campaigns, and that should help in the cities where the transport % has fallen below the requirements. I may still give an option to re-enable funding of new buildings.

As for the request, I'll probably allow it - I will look into it at the same time I fix the issue seen in Cindini scenario.

@romazoon As the game script debug console does not indicate any reason for crash what so ever, it may take a while before I can find exactly what is causing the crash at all. I'll report back when I find anything on this issue.
User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: [NoGo] City Growth Limiter

Post by romazoon »

i know i should have made a screenshot but i didnt my apologies... the very first time the script crash showed up, something was written(one small line) about API 1.4.0 (or 1.4.2 i m not so sure anymore) but not in red. when i retried nothing at all was written.

Have you reproduced the script crash with my indication or ? and no rush from me, take your time ;)
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] City Growth Limiter

Post by Sylf »

Yes, the script crashed when I loaded this script on your scenario.

It is almost an intended behavior, actually. The script expects the town growth speed set to something other than "None" in advanced settings. Change this setting in your scenario before loading the script, and it will work without crashing.

On the technical side... It wasn't really crashing. The script terminated itself because it detected the above advanced setting. But because the game script engine doesn't expect the script to terminate, the game reported that the script crashed.

I'm going to release a new version that will display a friendly message before crashing itself.
User avatar
romazoon
Tycoon
Tycoon
Posts: 1291
Joined: 20 Jun 2010 23:16

Re: [NoGo] City Growth Limiter

Post by romazoon »

thanks for that answer, i effectively had growth on off.
GNRD
Engineer
Engineer
Posts: 9
Joined: 12 Mar 2015 02:41

Re: [NoGo] City Growth Limiter

Post by GNRD »

Hello! I have created a fork of "City Growth Limiter" v6, named "City Growth Limiter Minimal" (super imaginative)
with a simple premise:

> The script now only focuses on vanilla passenger transport, and with that
> It should be as simple, smooth and fast as I can possibly make it.

It is basically a reorganization and simplification of the code by Sylf, with a few minor additions. I consider it a
"sub-set"/"stripped-down" version of Sylf's gamescript, and that's why I don't think it merits its own thread but a
post here.

This is the changelog:

Code: Select all

version 1 - March 17, 2015
* The GameScript now only focuses on Passenger transport (no Mail requirements).
* The Gamescript now only supports vanilla cargos (but it could still work with other sets).
* Dropped SuperLib dependency. There are now no external dependencies aside from NoGo (built in).
* Added some error checking to prevent misbehavior with some NewGRFs and game settings.
* The main loop's workload is now distributed along the 28-day cycle with respect to town count.
* Rearranged internal structure to suit new limitations and requirements.
* Added Spanish translation for in-game messages.
It has been working very well, but you are welcome to take a look at the code and tell me if I've messed everything up!
Or what could be improved.

The license requires I put my name around when I change the code, but really all credit for this goes to Sylf.

(Uploaded script here)
Attachments
CiGrLiMin-1.zip
(14.22 KiB) Downloaded 241 times
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 27 guests