Migrations GS

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
thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Migrations GS

Post by thexa4 » 28 Aug 2019 15:40

I like to play longer games with sailboats and noticed that towns don't occur near the coast as often as you'd expect for early start dates. To fix that I've made a gamescript that manages the population on the map and moves them near places where there is work.

Let me know if you encounter any issues / crashes.

Description
Makes the people in your OpenTTD world migrate to places that provide work.
Transporting cargo from an industry creates jobs that cause unemployed population to move nearby the industry.

Website: https://gitlab.com/thexa4/migrations
Issues: https://gitlab.com/thexa4/migrations/issues (or here)

Installation
Through OpenTTD online content page or by unpacking the tar to the right location.
migrations-2.tar
(40 KiB) Downloaded 83 times
Recommended Game Settings
- Towns: Custom(1-20).
- Industry: between Minimal and Low.
- (optional) NewGRF Sailing Ships enabled
- (optional) Starting time 1830
Attachments
migrations-1.tar
(40 KiB) Downloaded 36 times
Last edited by thexa4 on 03 Sep 2019 21:48, edited 3 times in total.

perverted monkey
Engineer
Engineer
Posts: 40
Joined: 02 Mar 2009 02:07

Re: Migrations GS

Post by perverted monkey » 29 Aug 2019 05:48

:D And this is your first post! Fantastic for a newcomer!

arikover
Route Supervisor
Route Supervisor
Posts: 395
Joined: 15 Jun 2007 09:27
Skype: madchimiste
Location: Berlin, Deutschland

Re: Migrations GS

Post by arikover » 31 Aug 2019 05:26

I really like this idea! Particularly the fact that new towns are founded around serviced industries. Really cool!

I have a suggestion: I think that would be neat to follow the movement of population somehow. I was thinking of a "Log level" setting for the gamescript (similar to other gamescripts, like Balanced City Growth for example), with different levels of "verbosity": Info and Debug
  • Debug would be similar to what is displayed in the log at the moment
  • Info would be somewhat shorter and less cryptic, with actual town names:

Code: Select all

People moved to Cool City from:
- Dulltown
- Boring Junction
That way, you could monitor which town are growing (pretty obvious), and which town are shrinking (less obvious).

I did not peek at the code, so I have a couple questions:
  • Is the the migration depending on how much cargo is moved from an industry?
  • Does it work better when multiple industries are served?
  • Can a town become a ghost town (population = 0) if everybody moves out?
Interesting idea for a script, thank for this!

thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 31 Aug 2019 09:16

Adding another log level shouldn't be too hard. I'll see if I can add that.
Is the the migration depending on how much cargo is moved from an industry?
Yes, the amount of services used of the combined industry in that grid zone is used to compute the sustainable population. If the sustainable population is higher than the actual population it tries to move people.
Does it work better when multiple industries are served?
No, it counts all industry equally.
Can a town become a ghost town (population = 0) if everybody moves out?
There seems to be a limit on how many buildings you can remove in a town as a gamescript. I haven't seen it reduce any city to 0 yet.

arikover
Route Supervisor
Route Supervisor
Posts: 395
Joined: 15 Jun 2007 09:27
Skype: madchimiste
Location: Berlin, Deutschland

Re: Migrations GS

Post by arikover » 01 Sep 2019 22:33

Hello again!
thexa4 wrote:
31 Aug 2019 09:16
Adding another log level shouldn't be too hard. I'll see if I can add that.
Well actually you already have a setting for 3 log levels (Info, verbose, Debug), but there doesn't seem to be a difference between the 3 at the moment...

I would like to report a problem: when I service an industry, a city appears and start to grow. So far so good. But other cities don't shrink, even when they are quite big. A quick look in the log:

Code: Select all

demolish <tile_ID> = false ... ERR_PRECONDITION_FAILED
...
failed to demolish building in town <town_ID>
So far, I always have these. Towns don't shrink.

As far as I can see, there are 2 preconditions for DemolishTile():
Precondition
GSMap::IsValidTile(tile).
Valid GSCompanyMode active in scope.
Tiles seem to be valid, so maybe there is a problem with GSCompanyMode here?

_dp_
Engineer
Engineer
Posts: 127
Joined: 18 Dec 2013 12:32

Re: Migrations GS

Post by _dp_ » 02 Sep 2019 07:52

arikover wrote:
01 Sep 2019 22:33
Precondition
GSMap::IsValidTile(tile).
Valid GSCompanyMode active in scope.
Tiles seem to be valid, so maybe there is a problem with GSCompanyMode here?
Yeah, script doesn't seem to change companies and deities can't destroy houses. Also keep in mind that even if script uses another company it will have to deal with town authority which isn't that easy. Afaict there are 2 reliable solutions - either use 0 rating cost houses newgrf like Luukland CB or require magic bulldozer to be enabled.

thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 02 Sep 2019 09:03

Thanks for the report, I thought only some buildings didn't demolish properly. I'll see if I can fix it.

randomallfront
Engineer
Engineer
Posts: 5
Joined: 29 Jul 2018 17:39

Re: Migrations GS

Post by randomallfront » 02 Sep 2019 21:54

I tried something like this once. Only solution I could find was to require a dummy AI to be in certain slot, and for this AI to constantly cheat money to bribe towns in order to keep razing buildings. It somehow worked, but it was a bit cumbersome.

thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 03 Sep 2019 21:59

Released version 2 based on feedback. It's compatible with older saves.
That way, you could monitor which town are growing (pretty obvious), and which town are shrinking (less obvious).
I've added explicit logging of which cities are growing. Unless the script mentions immigration, people are taken from all cities that aren't scheduled to grow. I'll see if I can add the list of which cities they were taken from but I didn't manage to get it in this version.
But other cities don't shrink, even when they are quite big.
I've submitted a pull request to allow GameScripts to destroy tiles, lets hope it gets merged. Because all demolishes currently fail it treats all growth as if people are immigrating. If you want a build with the fix enabled to test with, let me know.

Total changelog:
  • Cleaned up logging.
  • Script now keeps track of people in already destroyed houses that didn't get a destination. (global population now always increases)
  • Should now be compatible with down to 1.4.0.
  • Warning about missing save function is gone.

thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 09 Sep 2019 18:45

The patch to allow the script to demolish buildings has been merged into OpenTTD so the nighty build should work with migrations.

I noticed I forgot to lock town growth so I'm considering adding that in for next version.

kvwrd
Engineer
Engineer
Posts: 24
Joined: 02 Nov 2008 15:46

Re: Migrations GS

Post by kvwrd » 15 Oct 2019 21:14

Hello. How do you watch logs?

thexa4
Engineer
Engineer
Posts: 6
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 15 Oct 2019 21:43


Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 0 guests