Patch: Limiting population growth

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
ic111
Director
Director
Posts: 608
Joined: 17 Jul 2007 17:56

Patch: Limiting population growth

Post by ic111 »

An idea for a probably fairly small patch that came to my mind these days.

Cities in OpenTTD have the problem that they grow without limit, until they occupy major parts of the landscape. Even if you play with the goal of building up a complete transportation network, one that serves all cities at least in some region, and offers capacity to all passengers that want to travel, you will very likely fail at some point of time.

One can forbid cities building roads. This effectively limits city growth to zero (at least in the long term). This has IMHO two disadvantages: (a) you are responsible yourself for building the roads, (b) the surprise which also contributes to gameplay is completely eliminated, you won´t look into some area of map for the first time after some months or years, and be surprised about the new urban district...

My idea is: Introduce two settings,
(1) Maximum allowed population on the whole map,
(2) Rate of population increase per year (or maybe month)

Add a check to the decision wether a city builds a new house, that checks wether the total population on map is smaller than the maximum allowed population on map. If that check fails, don´t build the house.

... and periodically, adapt the maximum allowed population based on the rate of population increase.

Example:
Maximum population in 1969 100000, rate of increase per year 1%, then the maximum allowed population in 1970 would be 101000.
If, say, the actual population in 1969 would be 100139 after some huge building was built, then no city would be allowed to build a new house until the population dropped below 100000 again, or the year 1970 is reached.

Theoretically, using this concept, one could even simulate a shrinking population, one would just need to set the population increase to a negative value.

This way, city growth could work as usual, without manual intervention like building roads because the cities aren´t allowed to do so, but the players would have control over the question, what population they wish on map. At least in single player mode, one could adapt those settings in-game as needed.

Hopefully, city growth is quite random, if e.g. every 1st of month, the same city tries to build a new house, and on the 2nd another city, this would obviously interfere with that concept. I hope this isn´t the case, otherwise a patch would have to be somewhat bigger....


One technical question: Is this possible, having a setting that is changed automatically periodically based on another setting? If no, is there another way to achieve what I described above?

... what do you think about the idea?

Patch published 10th September 2015, version 1.

Contents:
Patch 005: Savegame bump for config variables.
Patch 010: Introduce two settings, population limit, and growth rate on population limit.
Patch 020: Adjust the population limit based on the growth rate in the monthly town loop.
Patch 030: Introduce a cached total map population value, as we don´t want to recalculate that every time a city thinks about growing. It is discarded every fifth day (an arbitrarily chosen interval)
Patch 040: Prevent city growth if cached total map population is beyond the limit.
Attachments
PopulationLimit_V01.zip
Patch limiting population.
(7.15 KiB) Downloaded 56 times
Last edited by ic111 on 10 Sep 2015 21:54, edited 3 times in total.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Limiting population growth

Post by planetmaker »

In principle this is already possible. Town growth can be game script-scripted. All the city builder scripts do that. New settings for this effect would collide with existing game scripts.
ic111
Director
Director
Posts: 608
Joined: 17 Jul 2007 17:56

Re: Limiting population growth

Post by ic111 »

But as far as I get it, a game script must be installed before a game is started, or do I miss something?

So is there, if a game script is used, any possibility to adjust the setting in-game?
New settings for this effect would collide with existing game scripts.
Obviously only when enabled, at least I would regard it as standard for such a feature, that it can be disabled at all.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Limiting population growth

Post by Eddi »

ic111 wrote:So is there, if a game script is used, any possibility to adjust the setting in-game?
you cannot change the game script (easily) after game start, but the script may offer settings that can be changed during the game. also, the game script itself can react to the current game state and decide to adjust the values on its own.

i agree with planetmaker here, controlling town growth is a primary feature of game scripts, adding such a rigid setting is throwing a wrench into the workings of game scripts, and it'll probably not fit many people's play styles.
ic111
Director
Director
Posts: 608
Joined: 17 Jul 2007 17:56

Re: Limiting population growth

Post by ic111 »

Disclaimer: This is / might be my first contact with game scripts.

I just had a look on a hopefully similar game script, Renewed_City_Growth-5.

If I get the API at http://nogo.openttd.org/api/trunk/classGSTown.html right, then my only chance to influence what I want to influence is calling GSTown.SetGrowthRate. Or do I miss some feature of that API?

As parameters I would need TOWN_GROWTH_NONE and TOWN_GROWTH_NORMAL.

The question is: Does the former also result in buildings being replaced / demolished seldom or never? My idea about this is clearly, once the limit is reached, those two actions should proceed as usual, just growth should stop until those two actions lead to a population below the limit. Thus, directly influencing the decision "build this house now, or not?" would probably be the better choice, although that seems to be impossible using game scripts (unless I miss something, of course).

So, obviously, that would result in a less fine control, the limit would rather be a value where the game script starts to limit growth. Not bad, but of course there is the danger that this would lead to a saw tooth development of the total population, i.e. the population drops below the limit, all growths go to NORMAL (I certainly will not start with setting up my own growth rates for this), population raises some 1000 above the limit, all growth rates drop to NONE, in the next month houses are only demolished, not built, population drops below the limit, and so on...

At least, my idea was not that houses are only built in odd months...

The total population would be something that I need to calculate every time the script runs, i.e. iterate over all towns and sum it up. Seems feasible, doesn´t it?


So far just some random thoughts about this, I will think about wether I give a game script a try, or write a patch just for me. The latter is probably the simpler solution in terms of my workload, given I find some way to adjust a C++ settig programmatically (this is the only difficult aspect of this I can think of).
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: Limiting population growth

Post by Sylf »

I haven't read the code behind the TOWN_GROWTH_NONE constant. But from my experience using it, it acts exactly as the "The town is not growing" state without the GS not taking over the growth of the town. So, when an old building gets torn down, a replacement is automatically built.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Limiting population growth

Post by Eddi »

ic111 wrote:Or do I miss some feature of that API?
The "ExpandTown" function?
ic111
Director
Director
Posts: 608
Joined: 17 Jul 2007 17:56

Re: Limiting population growth

Post by ic111 »

I don´t see that ExpandTown can help me.

ExpandTown builds some given amount of houses. But I explicitely don´t want to deal with determining that number, I just want towns do what they used to do, and prevent further growth if the map is already too populated.

Sylf: Thank you.
ic111
Director
Director
Posts: 608
Joined: 17 Jul 2007 17:56

Re: Patch: Limiting population growth

Post by ic111 »

I chose the option "Implement a patch, mainly for myself".

Contents:
Patch 005: Savegame bump for config variables.
Patch 010: Introduce two settings, population limit, and growth rate on population limit.
Patch 020: Adjust the population limit based on the growth rate in the monthly town loop.
Patch 030: Introduce a cached total map population value, as we don´t want to recalculate that every time a city thinks about growing. It is discarded every fifth day (an arbitrarily chosen interval)
Patch 040: Prevent city growth if cached total map population is beyond the limit.

Testcase:
Two cities, linked by a railway, population limit below the current population, let the railway cycle a year. The cities won´t build a new building.

Disabling it:
Set the population limit to zero in order to disable it.

Reasons why I chose a patch:
(1) I have finer control this way, can cache the total population, can make a new decision every time a town tries to grow. This prevents population staying constant for a whole month until the next monthly loop.
(2) IMHO, this population limit can be used separate to game scripts: A game script e.g. decides that towns that receive food grow much faster than towns that do not receive food. Or the same with passengers. Or something else. My limit can be used separately: If the overall population resulting of all those micro decisions grows to to a undesired large value, one can slow down growth. I.e. I can use a game script that honors food, and at the same time limit total population. I.e. two separate dimensions.

Use it if you have fun with it, if not ignore it, at least it should solve a problem I had in my games for quite a long time.
Attachments
PopulationLimit_V01.zip
Patch introducing population limit.
(7.15 KiB) Downloaded 50 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests