changeset 6454:b0788d6496a9 draft

(svn r9613) -Feature: Make it possible to have some control over the town growth. The default rate is TTD's original rate, and to approximate OpenTTD's previous behaviour the rate should be set to "Fast" or "Very Fast". Town growth can be switched off entirely, and if so, buildings will not be rebuilt. It is also possible to specify a proportion of towns that grow twice as fast as the others.
author maedhros <maedhros@openttd.org>
date Thu, 12 Apr 2007 17:24:34 +0000
parents 666fc3ef3174
children d686356a6da6
files src/lang/english.txt src/saveload.cpp src/settings.cpp src/settings_gui.cpp src/town.h src/town_cmd.cpp src/variables.h
diffstat 7 files changed, 52 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1135,6 +1135,14 @@
 STR_CONFIG_PATCHES_TOOLBAR_POS_RIGHT                            :Right
 STR_CONFIG_PATCHES_SNAP_RADIUS                                  :{LTBLUE}Window snap radius: {ORANGE}{STRING1} px
 STR_CONFIG_PATCHES_SNAP_RADIUS_DISABLED                         :{LTBLUE}Window snap radius: {ORANGE}disabled
+STR_CONFIG_PATCHES_TOWN_GROWTH                                  :{LTBLUE}Town growth speed: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_TOWN_GROWTH_NONE                             :None
+STR_CONFIG_PATCHES_TOWN_GROWTH_SLOW                             :Slow
+STR_CONFIG_PATCHES_TOWN_GROWTH_NORMAL                           :Normal
+STR_CONFIG_PATCHES_TOWN_GROWTH_FAST                             :Fast
+STR_CONFIG_PATCHES_TOWN_GROWTH_VERY_FAST                        :Very fast
+STR_CONFIG_PATCHES_LARGER_TOWNS                                 :{LTBLUE}Proportion of towns that will grow twice as fast: {ORANGE}1 in {STRING1}
+STR_CONFIG_PATCHES_LARGER_TOWNS_DISABLED                        :{LTBLUE}Proportion of towns that will grow twice as fast: {ORANGE}None
 
 STR_CONFIG_PATCHES_GUI                                          :{BLACK}Interface
 STR_CONFIG_PATCHES_CONSTRUCTION                                 :{BLACK}Construction
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -28,7 +28,7 @@
 #include "variables.h"
 #include <setjmp.h>
 
-extern const uint16 SAVEGAME_VERSION = 53;
+extern const uint16 SAVEGAME_VERSION = 54;
 uint16 _sl_version;       ///< the major savegame version identifier
 byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1392,6 +1392,8 @@
 	 SDT_VAR(Patches, ending_year,      SLE_INT32,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_ENDING_YEAR,  NULL),
 	SDT_BOOL(Patches, smooth_economy,             0, 0,  true,            STR_CONFIG_PATCHES_SMOOTH_ECONOMY,   NULL),
 	SDT_BOOL(Patches, allow_shares,               0, 0, false,            STR_CONFIG_PATCHES_ALLOW_SHARES,     NULL),
+	SDT_CONDVAR(Patches, town_growth_rate, SLE_UINT8, 54, SL_MAX_VERSION, 0, MS, 2, 0,   4, 0, STR_CONFIG_PATCHES_TOWN_GROWTH,  NULL),
+	SDT_CONDVAR(Patches, larger_towns,     SLE_UINT8, 54, SL_MAX_VERSION, 0, D0, 4, 0, 255, 1, STR_CONFIG_PATCHES_LARGER_TOWNS, NULL),
 
 	/***************************************************************************/
 	/* AI section of the GUI-configure patches window */
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -637,6 +637,8 @@
 	"ending_year",
 	"smooth_economy",
 	"allow_shares",
+	"town_growth_rate",
+	"larger_towns",
 };
 
 static const char *_patches_ai[] = {
--- a/src/town.h
+++ b/src/town.h
@@ -126,11 +126,11 @@
 	uint16 new_act_water;
 
 	/* Time until we rebuild a house. */
-	byte time_until_rebuild;
+	uint16 time_until_rebuild;
 
 	/* When to grow town next time. */
-	byte grow_counter;
-	byte growth_rate;
+	uint16 grow_counter;
+	int16 growth_rate;
 
 	/* Fund buildings program in action? */
 	byte fund_buildings_months;
@@ -234,14 +234,14 @@
 	RATING_BRIBE_DOWN_TO = -50        // XXX SHOULD BE SOMETHING LOWER?
 };
 
-enum {
-/* This is the base "normal" number of towns on the 8x8 map, when
- * one town should get grown per tick. The other numbers of towns
- * are then scaled based on that. */
-	TOWN_GROWTH_FREQUENCY = 23,
-/* Simple value that indicates the house has reached final stage of construction*/
-	TOWN_HOUSE_COMPLETED  =  3,
-};
+/** This is the number of ticks between towns being processed for building new
+ * houses or roads. This value originally came from the size of the town array
+ * in TTD. */
+static const byte TOWN_GROWTH_FREQUENCY = 70;
+
+/** Simple value that indicates the house has reached the final stage of
+ * construction. */
+static const byte TOWN_HOUSE_COMPLETED = 3;
 
 /** This enum is used in conjonction with town->flags12.
  * IT simply states what bit is used for.
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -363,11 +363,11 @@
 	_current_player = OWNER_TOWN;
 
 	if (hs->building_flags & BUILDING_HAS_1_TILE && HASBIT(t->flags12, TOWN_IS_FUNDED) && CanDeleteHouse(tile) && --t->time_until_rebuild == 0) {
-		t->time_until_rebuild = GB(r, 16, 6) + 130;
+		t->time_until_rebuild = GB(r, 16, 8) + 192;
 
 		ClearTownHouse(t, tile);
 
-		/* rebuild with another house? */
+		/* Rebuild with another house? */
 		if (GB(r, 24, 8) >= 12) DoBuildTownHouse(t, tile);
 	}
 
@@ -1662,7 +1662,7 @@
 {
 	int n;
 	Station *st;
-	byte m;
+	uint16 m;
 	Player *p;
 
 	/* Reset player ratings if they're low */
@@ -1687,22 +1687,21 @@
 	}
 
 	CLRBIT(t->flags12, TOWN_IS_FUNDED);
+	if (_patches.town_growth_rate == 0) return;
+
+	/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the
+	 * number of times towns are processed before a new building is built. */
+	static const uint16 _grow_count_values[2][6] = {
+		{ 120, 120, 120, 100,  80,  60 }, ///< Fund new buildings has been activated
+		{ 320, 420, 300, 220, 160, 100 }  ///< Normal values
+	};
 
 	if (t->fund_buildings_months != 0) {
-		static const byte _grow_count_values[6] = {
-			60, 60, 60, 50, 40, 30
-		};
-		m = _grow_count_values[min(n, 5)];
+		m = _grow_count_values[0][min(n, 5)];
 		t->fund_buildings_months--;
-	} else if (n == 0) {
-		m = 160;
-		if (!CHANCE16(1, 12))
-			return;
 	} else {
-		static const byte _grow_count_values[5] = {
-			210, 150, 110, 80, 50
-		};
-		m = _grow_count_values[min(n, 5) - 1];
+		m = _grow_count_values[1][min(n, 5)];
+		if (n == 0 && !CHANCE16(1, 12)) return;
 	}
 
 	if (_opt.landscape == LT_ARCTIC) {
@@ -1713,6 +1712,9 @@
 			return;
 	}
 
+	m >>= (_patches.town_growth_rate - 1);
+	if (_patches.larger_towns != 0 && (t->index % _patches.larger_towns) == 0) m /= 2;
+
 	t->growth_rate = m / (t->num_houses / 50 + 1);
 	if (m <= t->grow_counter)
 		t->grow_counter = m;
@@ -1957,9 +1959,14 @@
 	    SLE_VAR(Town, new_act_food,          SLE_UINT16),
 	    SLE_VAR(Town, new_act_water,         SLE_UINT16),
 
-	    SLE_VAR(Town, time_until_rebuild,    SLE_UINT8),
-	    SLE_VAR(Town, grow_counter,          SLE_UINT8),
-	    SLE_VAR(Town, growth_rate,           SLE_UINT8),
+	SLE_CONDVAR(Town, time_until_rebuild,    SLE_UINT8,                  0, 53),
+	SLE_CONDVAR(Town, grow_counter,          SLE_UINT8,                  0, 53),
+	SLE_CONDVAR(Town, growth_rate,           SLE_UINT8,                  0, 53),
+
+	SLE_CONDVAR(Town, time_until_rebuild,    SLE_UINT16,                 54, SL_MAX_VERSION),
+	SLE_CONDVAR(Town, grow_counter,          SLE_UINT16,                 54, SL_MAX_VERSION),
+	SLE_CONDVAR(Town, growth_rate,           SLE_INT16,                  54, SL_MAX_VERSION),
+
 	    SLE_VAR(Town, fund_buildings_months, SLE_UINT8),
 	    SLE_VAR(Town, road_build_months,     SLE_UINT8),
 
--- a/src/variables.h
+++ b/src/variables.h
@@ -225,6 +225,9 @@
 
 	uint8 scrollwheel_scrolling;
 	uint8 scrollwheel_multiplier;
+
+	uint8 town_growth_rate; ///< Town growth rate
+	uint8 larger_towns;     ///< 1 in the specified number of towns will grow twice as fast
 };
 
 VARDEF Patches _patches;