Migrations GS
Moderator: OpenTTD Developers
Migrations GS
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.
Recommended Game Settings
- Towns: Custom(1-20).
- Industry: between Minimal and Low.
- (optional) NewGRF Sailing Ships enabled + 1830 start
Challenging Game Settings
- Size: at least 512x256
- Terrain type: Mountainous
- Variety distribution: Medium
- Sea level: Medium
- Towns: Custom(1-20).
- Industries: Normal
- Date: 1705
- Smoothness: Smooth
- Rivers: Many
- NewGRF 'eGRVTS'
- NewGRF 'From 1700'
- NewGRF 'Improved Town Industries' (Industry elevation requirements: On, Nuclear Energy chain: On, Waste & Recycling chain: On, Population requirement: 1000)
- NewGRF 'Improved Town Layouts
- NewGRF 'OpenGFX+ Road Vehicles'
- NewGRF 'OpenGFX+ Trains'
- NewGRF 'Transmitter By Date'
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.
Recommended Game Settings
- Towns: Custom(1-20).
- Industry: between Minimal and Low.
- (optional) NewGRF Sailing Ships enabled + 1830 start
Challenging Game Settings
- Size: at least 512x256
- Terrain type: Mountainous
- Variety distribution: Medium
- Sea level: Medium
- Towns: Custom(1-20).
- Industries: Normal
- Date: 1705
- Smoothness: Smooth
- Rivers: Many
- NewGRF 'eGRVTS'
- NewGRF 'From 1700'
- NewGRF 'Improved Town Industries' (Industry elevation requirements: On, Nuclear Energy chain: On, Waste & Recycling chain: On, Population requirement: 1000)
- NewGRF 'Improved Town Layouts
- NewGRF 'OpenGFX+ Road Vehicles'
- NewGRF 'OpenGFX+ Trains'
- NewGRF 'Transmitter By Date'
- Attachments
-
- migrations-8.tar
- (50 KiB) Downloaded 1 time
Last edited by thexa4 on 22 May 2025 08:41, edited 12 times in total.
-
- Traffic Manager
- Posts: 161
- Joined: 02 Mar 2009 02:07
Re: Migrations GS

-
- Route Supervisor
- Posts: 466
- Joined: 15 Jun 2007 09:27
- Skype: madchimiste
- Location: Berlin, Deutschland
Re: Migrations GS
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
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:
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
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?
Re: Migrations GS
Adding another log level shouldn't be too hard. I'll see if I can add that.
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.Is the the migration depending on how much cargo is moved from an industry?
No, it counts all industry equally.Does it work better when multiple industries are served?
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.Can a town become a ghost town (population = 0) if everybody moves out?
-
- Route Supervisor
- Posts: 466
- Joined: 15 Jun 2007 09:27
- Skype: madchimiste
- Location: Berlin, Deutschland
Re: Migrations GS
Hello again!
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:
So far, I always have these. Towns don't shrink.
As far as I can see, there are 2 preconditions for DemolishTile():
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...thexa4 wrote: 31 Aug 2019 09:16 Adding another log level shouldn't be too hard. I'll see if I can add that.
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>
As far as I can see, there are 2 preconditions for DemolishTile():
Tiles seem to be valid, so maybe there is a problem with GSCompanyMode here?Precondition
GSMap::IsValidTile(tile).
Valid GSCompanyMode active in scope.
Re: Migrations GS
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.arikover wrote: 01 Sep 2019 22:33Tiles seem to be valid, so maybe there is a problem with GSCompanyMode here?Precondition
GSMap::IsValidTile(tile).
Valid GSCompanyMode active in scope.
Re: Migrations GS
Thanks for the report, I thought only some buildings didn't demolish properly. I'll see if I can fix it.
-
- Engineer
- Posts: 5
- Joined: 29 Jul 2018 17:39
Re: Migrations GS
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.
Re: Migrations GS
Released version 2 based on feedback. It's compatible with older saves.
Total changelog:
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.That way, you could monitor which town are growing (pretty obvious), and which town are shrinking (less obvious).
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.But other cities don't shrink, even when they are quite big.
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.
Re: Migrations GS
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.
I noticed I forgot to lock town growth so I'm considering adding that in for next version.
Re: Migrations GS
Hello. How do you watch logs?
Re: Migrations GS
You can find it here: https://wiki.openttd.org/AI:Need_To_Kno ... ebug_Panel
-
- Route Supervisor
- Posts: 466
- Joined: 15 Jun 2007 09:27
- Skype: madchimiste
- Location: Berlin, Deutschland
Re: Migrations GS
Hello,
I found some "bugs", so I modified a bit the function _removeBuilding():
These were not really bugs (the script works well), but I think it is better like that. Do you think you'll apply these modifications?
I found some "bugs", so I modified a bit the function _removeBuilding():
- I removed the water tiles from the "tiles" array, because when trying to remove a building, the script would sometimes remove water tiles, and that was annoying for ships.
- I also sorted the array so that the surrounding buildings are removed before the central ones.
Code: Select all
function _removeBuilding() {
...
tiles.Valuate(GSTile.GetTownAuthority)
tiles.KeepValue(currentChoice)
tiles.Valuate(GSTile.IsBuildable);
tiles.KeepValue(0); // houses are not buildable
tiles.Valuate(GSTile.GetOwner);
tiles.KeepValue(-1);
tiles.Valuate(GSRoad.IsRoadTile);
tiles.KeepValue(0);
tiles.Valuate(_isIndustry);
tiles.KeepValue(0);
// here what I added
tiles.Valuate(GSTile.IsWaterTile);
tiles.KeepValue(0);
tiles.Valuate(GSTile.GetDistanceSquareToTile, townPos);
tiles.Sort(GSList.SORT_BY_VALUE, GSList.SORT_DESCENDING);
...
}
Re: Migrations GS
The water one is a nice addition, thanks for the patch!
I'm not sure about removing buildings from the edges first. Won't that result in very round towns instead of the deserted towns you get now? Maybe I can add it as an option.
I'm not sure about removing buildings from the edges first. Won't that result in very round towns instead of the deserted towns you get now? Maybe I can add it as an option.
-
- Route Supervisor
- Posts: 466
- Joined: 15 Jun 2007 09:27
- Skype: madchimiste
- Location: Berlin, Deutschland
Re: Migrations GS
I am under the impression that the _removeBuilding functions follows a pattern: it screens buildings from southeast to the northwest. At some point, I had towns lacking a city centre, and having houses only in the north and the west.
That is why I wanted the buildings to be removed more evenly, based on their distance to the city centre (removing buildings from the outskirts, then inwards). That results in round-ish towns, yes. I don't think this "round" solution is worth an option in your script.
Instead, I wanted to totally randomize the removal-process, but I didn't find a quick way to do this. I will try and find a solution.
I'm happy that the water-thing pleases you.
Keep up the good work!
That is why I wanted the buildings to be removed more evenly, based on their distance to the city centre (removing buildings from the outskirts, then inwards). That results in round-ish towns, yes. I don't think this "round" solution is worth an option in your script.
Instead, I wanted to totally randomize the removal-process, but I didn't find a quick way to do this. I will try and find a solution.
I'm happy that the water-thing pleases you.
Keep up the good work!
- 2TallTyler
- Director
- Posts: 573
- Joined: 11 Aug 2019 18:15
- Contact:
Re: Migrations GS
I'm having a lot of fun with this GameScript. Thanks for contributing it. A couple possible bug/interesting behavior reports:
I'm playing with version 2 from BaNaNaS, and it every few months it bulldozes ocean tiles (but leaves buildings untouched), temporarily stranding boats until the tiles regenerate. Do I not have the current version?
When towns created in the scenario editor get completely bulldozed to 0 population, roads stay but any bridges are deleted (have not tried bridges built by the GS).
Could you explain how this affects regular town growth? Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
The town generator doesn't seem to take into account minimum distance between towns. It just built Uniontown next to my initial city (built in the scenario editor), St. James. It seems much closer than I would be allowed to found a town.

I'm playing with version 2 from BaNaNaS, and it every few months it bulldozes ocean tiles (but leaves buildings untouched), temporarily stranding boats until the tiles regenerate. Do I not have the current version?
When towns created in the scenario editor get completely bulldozed to 0 population, roads stay but any bridges are deleted (have not tried bridges built by the GS).
Could you explain how this affects regular town growth? Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
The town generator doesn't seem to take into account minimum distance between towns. It just built Uniontown next to my initial city (built in the scenario editor), St. James. It seems much closer than I would be allowed to found a town.

Re: Migrations GS
Released version 3 based on feedback. It's compatible with older saves.
Total changelog:
I made tile selection random. Settings now contain an option to bias the selection to be roughly spherical.I am under the impression that the _removeBuilding functions follows a pattern: it screens buildings from southeast to the northwest.
There was a bug in version 2 that caused it to not filter out water tiles for destruction. Thanks to arikover this problem has been fixed in version 3.I'm playing with version 2 from BaNaNaS, and it every few months it bulldozes ocean tiles (but leaves buildings untouched), temporarily stranding boats until the tiles regenerate.
This is intentional. Bridges owned by other players aren't removed.When towns created in the scenario editor get completely bulldozed to 0 population, roads stay but any bridges are deleted (have not tried bridges built by the GS).
They are limited to whatever the local industry can support. Right now they don't need to meet any requirements other than having work.Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
It currently doesn't have a minimum required distance but it limits the amount of cities in one 'grid' to one (unless there already was more than one town when the game starts). The scenario editor city probably sits very close to a grid border. Do you feel adding a limit minimum distance would be beneficial?The town generator doesn't seem to take into account minimum distance between towns.
Total changelog:
- Water tiles are no longer considered when finding a building to remove.
- Removal is now random instead of deterministic.
- Added option to bias building removal to spherical towns. (makes towns smaller instead of ghost towns)
- Fixed bug that would make the script ignore towns without industry when finding a building to remove.
Re: Migrations GS
would it be possible to make the "vanilla" growth as an additional growth option ?thexa4 wrote: 05 Nov 2019 13:55 Released version 3 based on feedback. It's compatible with older saves.
........They are limited to whatever the local industry can support. Right now they don't need to meet any requirements other than having work.Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
........
Understand the relation from migration>Workplace - but towns should grown from vanilla factors too (or maybe better ideas - give various good scripts for this, but it is only one script alowed ...)
Regards
Re: Migrations GS
The code didn't disable vanilla growth earlier but that caused the population to keep expanding without bounds. The code is written so it can easily add concurrently running scripts so integrating another growth script would be doable.R-TEAM wrote: 08 Dec 2019 23:53 would it be possible to make the "vanilla" growth as an additional growth option ?
If you comment out the following line you should be able to run with vanilla and migrations: https://gitlab.com/thexa4/migrations/bl ... er.nut#L34
Re: Migrations GS
The growth scripts "i" found good developed, realistic and challanging was :
viewtopic.php?f=65&t=57963
viewtopic.php?f=65&t=74685
would be nice to have all 3 (with Migration) combined - as all 3 doing slightly different aspects of city growth
[and then no need for vanilla growth - as it is anyway replaced]
viewtopic.php?f=65&t=57963
viewtopic.php?f=65&t=74685
would be nice to have all 3 (with Migration) combined - as all 3 doing slightly different aspects of city growth

[and then no need for vanilla growth - as it is anyway replaced]
Who is online
Users browsing this forum: No registered users and 21 guests