Patch: Limit Town 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
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Patch: Limit Town Growth

Post by wleader »

This is my first little patch to Open TTD. What it does is add a population limit to town growth. On the Economy page of the patch config you can set a value from 0 to 255 indicating the population limit of all towns. Setting this value to zero disables the limit. If the value was 1 towns with a population greater than 100 will not grow. If the value was 20, towns with a population greater than 2000 will not grow. However towns can grow past this value. Say for example a town has a population of 995, and the limit is set to 10 (1000 population.) then this town could grow. It might grow above 1000, but it will not grow again until its population shrinks down below 1000. The nice result is that the towns population continues to fluctuate and buildings decay and rebuild giving the town a nice dynamic feel despite the growth limit. This really wasn't what I intended when I started the patch, but because of the way the town grow code works, I think its a pretty pleasant side effect. Smaller towns that are below the population limit will continue to grow normally.

I have been testing this patch on revision 9867 of the trunk.
Attachments
Shows the patch config for limiting town growth.
Shows the patch config for limiting town growth.
LimitTownGrowth.png (89.44 KiB) Viewed 8849 times
Limit_Town_Size_r4.patch
patch to limit town growth and move town patches to their own patch page.
(6.33 KiB) Downloaded 304 times
Last edited by wleader on 09 Jun 2007 22:26, edited 2 times in total.
User avatar
skidd13
OpenTTD Developer
OpenTTD Developer
Posts: 522
Joined: 03 Mar 2005 10:49
Location: Germany

Post by skidd13 »

Check how to bump a savegame. Your patch will get problems with older savegames.
What does that mean - the circumstances? I determine what circumstances prevail. -- Napoleon Bonaparte
---
If we cannot end now our differences, at least we can help make the world safe for diversity. -- John F. Kennedy
---
Our problems are man-made, therefore they may be solved by man. No problem of human destiny is beyond human beings. -- John F. Kennedy
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

skidd13,

I think I see the problem, would you agree that

Code: Select all

SDT_VAR(Patches, town_size_limit,   SLE_UINT8, 0, NC, 0, 0, SL_MAX_VERSION, 1, STR_CONFIG_PATCHES_TOWN_SIZE_LIMIT, NULL),
should be:

Code: Select all

SDT_VAR(Patches, town_size_limit,   SLE_UINT8, NS, NC, 0, 0, SL_MAX_VERSION, 1, STR_CONFIG_PATCHES_TOWN_SIZE_LIMIT, NULL),
That would specify to sync with the network, save in openttd.cfg and do not save in the save game. Only trouble is that line does not compile. NS is not defined.

alternately after reading the wiki page again (which seems to be slightly out of date) that I could just resolve this by making a change to saveload.cpp?:

Code: Select all

extern const uint16 SAVEGAME_VERSION = 59;
becomes
extern const uint16 SAVEGAME_VERSION = 60;
User avatar
skidd13
OpenTTD Developer
OpenTTD Developer
Posts: 522
Joined: 03 Mar 2005 10:49
Location: Germany

Post by skidd13 »

The saveload.cpp thing is right but you should use SDT_CONDVAR(...) from revision 60 (current SL_MAX_VERSION +1) to SL_MAX_VERSION.
What does that mean - the circumstances? I determine what circumstances prevail. -- Napoleon Bonaparte
---
If we cannot end now our differences, at least we can help make the world safe for diversity. -- John F. Kennedy
---
Our problems are man-made, therefore they may be solved by man. No problem of human destiny is beyond human beings. -- John F. Kennedy
User avatar
Maedhros
OpenTTD Developer
OpenTTD Developer
Posts: 603
Joined: 30 Mar 2006 18:24
Location: Durham, UK

Post by Maedhros »

wleader wrote:That would specify to sync with the network, save in openttd.cfg and do not save in the save game. Only trouble is that line does not compile. NS is not defined.
Yeah, NS was removed as it causes desyncs (it didn't syncronise the value when you joined a game; only when you changed the setting). I didn't know it was in the wiki as well...
No-one's more important than the earthworm.
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

Ok, I think I have fixed the savegame issue you described. Here is a revised version of the patch.

{patch removed}
Last edited by wleader on 09 Jun 2007 22:23, edited 1 time in total.
User avatar
skidd13
OpenTTD Developer
OpenTTD Developer
Posts: 522
Joined: 03 Mar 2005 10:49
Location: Germany

Post by skidd13 »

Looks fine now. If you wanna play a bit further with the code, try to add another tab in the patch_settings window and group the town settings together. ;)
What does that mean - the circumstances? I determine what circumstances prevail. -- Napoleon Bonaparte
---
If we cannot end now our differences, at least we can help make the world safe for diversity. -- John F. Kennedy
---
Our problems are man-made, therefore they may be solved by man. No problem of human destiny is beyond human beings. -- John F. Kennedy
Acerbus
Engineer
Engineer
Posts: 94
Joined: 08 Dec 2006 21:42
Location: Estonia

Post by Acerbus »

A really nice patch you got there! What about making separate options for towns and cities and maybe even allowing to set the limit individually for each town?
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

skidd13,

Your just trying to hook another developer.. :) But maybe your right. there does seem to be a lot of town related patches now, so re-organizing may be appropriate.

Acerbus,

While I have no doubt that this could be done, it would involve adding to the town structure, which I would expect would cause changes to loading and saving. Additionally there would have to be a change to the Town GUI too. For me, since I don't really know what I am doing yet, It seems like a lot of work for something I don't really see a benefit to gameplay. I think that manipulating these things directly for each city only lends itself to abuse.

However, I have been looking at the code and there is another patch for lager_towns that causes some towns to instead be 'cities' that grow faster. This already exists as a boolean value in a town, so I could use it to have a town size limit and a seperate city size limit.

Code: Select all

	uint32 pop_limit = t->larger_town ? (_patches.city_size_limit * 100) : (_patches.town_size_limit * 100);
	if ((pop_limit != 0) && (t->population >= pop_limit)){
		return false;
	}
The result would be that Some towns would grow faster with a different limit than others, but without any control over which towns grow faster and larger. This way with this patch enabled, some towns could still be larger than others and still have a population limit. Since this is so easy to do I might just try it out. But I have a concert to go to so I probably won't get a chance to put up a patch until tomorrow night.
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

That was easier to do than I realized.

{patch removed}
Attachments
shows the town patches category.
shows the town patches category.
TownPatches.png (39.8 KiB) Viewed 8460 times
Last edited by wleader on 09 Jun 2007 22:24, edited 1 time in total.
User avatar
skidd13
OpenTTD Developer
OpenTTD Developer
Posts: 522
Joined: 03 Mar 2005 10:49
Location: Germany

Post by skidd13 »

Nice work, but don't change the order of existing SDT_*VAR's, that will change the savegame. ;) So change the positions only in settings_gui.cpp.
What does that mean - the circumstances? I determine what circumstances prevail. -- Napoleon Bonaparte
---
If we cannot end now our differences, at least we can help make the world safe for diversity. -- John F. Kennedy
---
Our problems are man-made, therefore they may be solved by man. No problem of human destiny is beyond human beings. -- John F. Kennedy
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

Skidd13, If we don't want to change the order of the vars, does that mean that all new variables like this should be added at the end just before SDT_END()?

I'm gonna have to update the wiki with all the stuff I've learned.
User avatar
skidd13
OpenTTD Developer
OpenTTD Developer
Posts: 522
Joined: 03 Mar 2005 10:49
Location: Germany

Post by skidd13 »

If you change the sequence of existing SDT_* stuff you change the savegame internaly (that would normaly break the savegame compatibility).
You can add SDT_COND* stuff everywhere cause it is limited to min and max revison (and so keep the savegame compatibility).
What does that mean - the circumstances? I determine what circumstances prevail. -- Napoleon Bonaparte
---
If we cannot end now our differences, at least we can help make the world safe for diversity. -- John F. Kennedy
---
Our problems are man-made, therefore they may be solved by man. No problem of human destiny is beyond human beings. -- John F. Kennedy
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

Here is the latest version of my patch.
  • Limit town and city sizes seperately
    Move Town Patches to their own page in the patch settings.
Enjoy!
wleader
Engineer
Engineer
Posts: 123
Joined: 18 May 2007 09:04

Post by wleader »

Nothing new, I just removed old versions of the patch and updated the first message in the thread with the latest version of the patch. Consider this thread maintenance.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 6 guests