Changeset - r6454:106dbc6c677f
[Not reviewed]
master
0 7 0
maedhros - 17 years ago 2007-04-12 17:24:34
maedhros@openttd.org
(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.
7 files changed with 52 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -1135,6 +1135,14 @@ STR_CONFIG_PATCHES_TOOLBAR_POS_CENTER   
 
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
src/saveload.cpp
Show inline comments
 
@@ -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!
 

	
src/settings.cpp
Show inline comments
 
@@ -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 */
src/settings_gui.cpp
Show inline comments
 
@@ -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[] = {
src/town.h
Show inline comments
 
@@ -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.
src/town_cmd.cpp
Show inline comments
 
@@ -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),
 

	
src/variables.h
Show inline comments
 
@@ -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;
0 comments (0 inline, 0 general)