Testers wanted, whether this doesn't cause pathological behaviour, ie. wrong
buildings in wrong town areas (high buildings in outskirts or small towns, or
vice versa) or being it too difficult to grow a small town, and of course if it
helps to grow large cities :-).

It aims to make it possible to grow town even above certain number of houses,
which was basically impossible before, also trying to make some growth tables
to scale even for very large cities (with quite arbitrary parameters, just
informed guesses :) and also tries to make the town growth at least very
slightly exponential instead of linear (but the exponential growth has a very
small constant so it comes into play from population of about 3000, doubling
after each other 3000 ppl).

BTW for the town growth what's relevant is number of houses, not population -
they are related but the correlation isn't very tight, you can have a house
with population of 6 and a house with population of 250 (these are the extreme
values). What roughly holds is that cities with population about 4000 have
about 80 houses while cities of ~ 6000 have ~ 100 houses, +/- 20 houses :)

I wonder how big town would be possible to grow with this patch, there're no
theoretical limits, at least no limits I'm aware of.  With the original
algorithm the limit is at 72 houses, above that the town grows with the same
speed as if there would be no stations in the town (that means you have a
chance for one new house per year :).

Note that this patch also merges some town growth fixes from TTDPatch
(http://groups.google.com/groups?as_umsgid=b2du9i%241a863c%242%40ID%2D37968.news.dfncis.de).

Index: town_cmd.c
===================================================================
--- town_cmd.c	(revision 814)
+++ town_cmd.c	(working copy)
@@ -347,9 +347,12 @@
 	if (c->flags12&1) {
 		int i = c->grow_counter - 1;
 		if (i < 0) {
+			printf("[%d] about to grow...\n", c->index);
 			if (GrowTown(c)) {
+				printf("Grown\n");
 				i = c->growth_rate;
 			} else {
+				printf("Will grow again\n");
 				i = 0;	
 			}
 		}
@@ -640,7 +643,8 @@
 	TILE_ASSERT(tile);
 
 	// Number of times to search.
-	_grow_town_result = 20;
+	_grow_town_result = 10 + c->num_houses / 4;
+	printf("[%d] pop %d houses %d grow rate %d grow town %d\n", c->index, c->population, c->num_houses, c->growth_rate, _grow_town_result);
 
 	do {
 		// Get a bitmask of the road blocks on a tile
@@ -741,32 +745,45 @@
 static void UpdateTownRadius(Town *c)
 {
 	static const uint16 _town_radius_data[23][5] = {
-		{ 4,  0,  0,  0,  0},
+		{ 4,  0,  0,  0,  0}, // 0
 		{16,  0,  0,  0,  0},
 		{25,  0,  0,  0,  0},
 		{36,  0,  0,  0,  0},
 		{49,  0,  4,  0,  0},
-		{64,  0,  4,  0,  0},
+		{64,  0,  4,  0,  0}, // 20
 		{64,  0,  9,  0,  1},
 		{64,  0,  9,  0,  4},
 		{64,  0, 16,  0,  4},
 		{81,  0, 16,  0,  4},
-		{81,  0, 16,  0,  4},
+		{81,  0, 16,  0,  4}, // 40
 		{81,  0, 25,  0,  9},
 		{81, 36, 25,  0,  9},
 		{81, 36, 25, 16,  9},
 		{81, 49,  0, 25,  9},
-		{81, 64,  0, 25,  9},
+		{81, 64,  0, 25,  9}, // 60
 		{81, 64,  0, 36,  9},
 		{81, 64,  0, 36, 16},
-		{ 0, 81,  0, 49, 16},
-		{ 0, 81,  0, 49, 25},
-		{ 0,100,  0, 49, 25},
-		{ 0,100,  0, 64, 25},
-		{ 0,100,  0, 64, 36},
+		{100, 81,  0, 49, 16},
+		{100, 81,  0, 49, 25},
+		{121, 81,  0, 49, 25}, // 80
+		{121, 81,  0, 49, 25},
+		{121, 81,  0, 49, 36}, // 88
 	};
-	int i = min(c->num_houses, 88) >> 2;
-	memcpy(c->radius, _town_radius_data[i], sizeof(c->radius));
+
+	if (c->num_houses < 92) {
+		memcpy(c->radius, _town_radius_data[c->num_houses / 4], sizeof(c->radius));
+	} else {
+		int mass = c->num_houses / 8;
+		// At least very roughly extrapolate. Empirical numbers.
+		c->radius[0] = mass * mass;
+		mass -= mass / 4;
+		c->radius[1] = mass * mass;
+		c->radius[2] = 0;
+		mass -= mass / 4;
+		c->radius[3] = mass * mass;
+		mass -= mass / 2;
+		c->radius[4] = mass * mass;
+	}
 }
 
 static void UpdateTownVirtCoord(Town *c)
@@ -1547,9 +1564,14 @@
 
 	c->flags12 &= ~1;
 
+	printf("[%d] r %d n %d\n", c->index, c->radius[0], n);
+
 	if (c->fund_buildings_months != 0) {
+		static const byte _grow_count_values[6] = {
+			60, 60, 60, 50, 40, 30
+		};
+		m = _grow_count_values[min(n, 5)];
 		c->fund_buildings_months--;
-		m = 60;
 	} else if (n == 0) {
 		m = 160;
 		if (!CHANCE16(1, 12))
@@ -1562,17 +1584,19 @@
 	}
 
 	if (_opt.landscape == LT_HILLY) {
-		if ((_map_type_and_height[c->xy] & 0xF) * 8 >= _opt.snow_line &&	c->act_food == 0)
+		if ((_map_type_and_height[c->xy] & 0xF) * 8 >= _opt.snow_line && c->act_food == 0 && c->population > 90)
 			return;
 	} else if (_opt.landscape == LT_DESERT) {
-		if (GetMapExtraBits(c->xy) == 1 && (c->act_food==0 || c->act_paper==0))
+		if (GetMapExtraBits(c->xy) == 1 && (c->act_food==0 || c->act_paper==0) && c->population > 60)
 			return;
 	}
 
-	c->growth_rate = m;
+	c->growth_rate = m / (c->num_houses / 50 + 1);
 	if (m <= c->grow_counter)
 		c->grow_counter = m;
 
+	printf("[%d] rate %d counter %d\n", c->index, c->growth_rate, c->grow_counter);
+
 	c->flags12 |= 1;
 }
 
