Page 1 of 2

Migrations GS

Posted: 28 Aug 2019 15:40
by thexa4
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'

Re: Migrations GS

Posted: 29 Aug 2019 05:48
by perverted monkey
:D And this is your first post! Fantastic for a newcomer!

Re: Migrations GS

Posted: 31 Aug 2019 05:26
by arikover
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!

Re: Migrations GS

Posted: 31 Aug 2019 09:16
by thexa4
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.

Re: Migrations GS

Posted: 01 Sep 2019 22:33
by arikover
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?

Re: Migrations GS

Posted: 02 Sep 2019 07:52
by _dp_
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.

Re: Migrations GS

Posted: 02 Sep 2019 09:03
by thexa4
Thanks for the report, I thought only some buildings didn't demolish properly. I'll see if I can fix it.

Re: Migrations GS

Posted: 02 Sep 2019 21:54
by randomallfront
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

Posted: 03 Sep 2019 21:59
by thexa4
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.

Re: Migrations GS

Posted: 09 Sep 2019 18:45
by thexa4
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.

Re: Migrations GS

Posted: 15 Oct 2019 21:14
by kvwrd
Hello. How do you watch logs?

Re: Migrations GS

Posted: 15 Oct 2019 21:43
by thexa4

Re: Migrations GS

Posted: 20 Oct 2019 23:34
by arikover
Hello,

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);
		...
		}
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?

Re: Migrations GS

Posted: 21 Oct 2019 08:37
by thexa4
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.

Re: Migrations GS

Posted: 21 Oct 2019 18:21
by arikover
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!

Re: Migrations GS

Posted: 01 Nov 2019 02:38
by 2TallTyler
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.

Image

Re: Migrations GS

Posted: 05 Nov 2019 13:55
by thexa4
Released version 3 based on feedback. It's compatible with older saves.
I am under the impression that the _removeBuilding functions follows a pattern: it screens buildings from southeast to the northwest.
I made tile selection random. Settings now contain an option to bias the selection to be roughly spherical.
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.
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.
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).
This is intentional. Bridges owned by other players aren't removed.
Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
They are limited to whatever the local industry can support. Right now they don't need to meet any requirements other than having work.
The town generator doesn't seem to take into account minimum distance between towns.
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?

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

Posted: 08 Dec 2019 23:53
by R-TEAM
thexa4 wrote: 05 Nov 2019 13:55 Released version 3 based on feedback. It's compatible with older saves.
........
Can towns grow in the usual way by delivering cargo/pax, or are they limited to whatever population the local industry can support?
They are limited to whatever the local industry can support. Right now they don't need to meet any requirements other than having work.
........
would it be possible to make the "vanilla" growth as an additional growth option ?
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

Posted: 09 Dec 2019 00:03
by thexa4
R-TEAM wrote: 08 Dec 2019 23:53 would it be possible to make the "vanilla" growth as an additional growth option ?
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.

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

Posted: 09 Dec 2019 01:13
by R-TEAM
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]