summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-04-12 17:24:34 +0000
committermaedhros <maedhros@openttd.org>2007-04-12 17:24:34 +0000
commitf2a14a813aefd84d11f540017d6400760d2dccca (patch)
tree5610013827e8a819441d28bafece386e0ad98632 /src
parent3d81de8d7ecda44d3683163c1d8ecbdb7c17aaca (diff)
downloadopenttd-f2a14a813aefd84d11f540017d6400760d2dccca.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt8
-rw-r--r--src/saveload.cpp2
-rw-r--r--src/settings.cpp2
-rw-r--r--src/settings_gui.cpp2
-rw-r--r--src/town.h22
-rw-r--r--src/town_cmd.cpp43
-rw-r--r--src/variables.h3
7 files changed, 52 insertions, 30 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 20f1ae7d7..ac808b46b 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1135,6 +1135,14 @@ STR_CONFIG_PATCHES_TOOLBAR_POS_CENTER :Centre
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
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 9e3ca0768..4d3ea107c 100644
--- 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!
diff --git a/src/settings.cpp b/src/settings.cpp
index 2836df2d7..c622ecbbb 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1392,6 +1392,8 @@ const SettingDesc _patch_settings[] = {
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 */
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 0f601a19f..1917f06a9 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -637,6 +637,8 @@ static const char *_patches_economy[] = {
"ending_year",
"smooth_economy",
"allow_shares",
+ "town_growth_rate",
+ "larger_towns",
};
static const char *_patches_ai[] = {
diff --git a/src/town.h b/src/town.h
index 832fd913b..75157bde3 100644
--- a/src/town.h
+++ b/src/town.h
@@ -126,11 +126,11 @@ struct Town {
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 @@ enum {
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.
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index ba2166fe8..13d32d24e 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -363,11 +363,11 @@ static void TileLoop_Town(TileIndex tile)
_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 @@ static void UpdateTownGrowRate(Town *t)
{
int n;
Station *st;
- byte m;
+ uint16 m;
Player *p;
/* Reset player ratings if they're low */
@@ -1687,22 +1687,21 @@ static void UpdateTownGrowRate(Town *t)
}
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 @@ static void UpdateTownGrowRate(Town *t)
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 @@ static const SaveLoad _town_desc[] = {
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),
diff --git a/src/variables.h b/src/variables.h
index 97581628f..ce1df0898 100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -225,6 +225,9 @@ struct Patches {
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;