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: 8
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-3.tar
(40 KiB) Downloaded 4 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 37 times
migrations-2.tar
(40 KiB) Downloaded 83 times
Last edited by thexa4 on 05 Nov 2019 14:18, edited 4 times in total.

perverted monkey
Engineer
Engineer
Posts: 41
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: 398
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: 8
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: 398
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_
Traffic Manager
Traffic Manager
Posts: 130
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: 8
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: 8
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: 8
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: 8
Joined: 28 Aug 2019 15:29

Re: Migrations GS

Post by thexa4 » 15 Oct 2019 21:43


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

Re: Migrations GS

Post by arikover » 20 Oct 2019 23:34

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?

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

Re: Migrations GS

Post by thexa4 » 21 Oct 2019 08:37

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.

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

Re: Migrations GS

Post by arikover » 21 Oct 2019 18:21

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!

2TallTyler
Engineer
Engineer
Posts: 4
Joined: 11 Aug 2019 18:15

Re: Migrations GS

Post by 2TallTyler » 01 Nov 2019 02:38

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

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

Re: Migrations GS

Post by thexa4 » 05 Nov 2019 13:55

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.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests