(svn r9342) [0.5] -Backport from trunk (r8980, r9065, r9339): 0.5
authorrubidium
Mon, 19 Mar 2007 18:54:48 +0000
branch0.5
changeset 5460 c86169e59c08
parent 5459 74356913b47d
child 5461 03285c9589f9
(svn r9342) [0.5] -Backport from trunk (r8980, r9065, r9339):
- Fix: the industry list should also be (re)set when the number of industries is 0 (r8980)
- Fix: possible dereference of NULL pointer (r9065)
- Codechange: disable shares by default and increase the default maximum distance from edge for oil refineries (r9339)
industry_gui.c
road_cmd.c
settings.c
--- a/industry_gui.c	Mon Mar 19 18:47:10 2007 +0000
+++ b/industry_gui.c	Mon Mar 19 18:54:48 2007 +0000
@@ -553,26 +553,30 @@
 	return r;
 }
 
+/**
+ * Makes a sorted industry list.
+ * When there are no industries, the list has to be made. This so when one
+ * starts a new game without industries after playing a game with industries
+ * the list is not populated with invalid industries from the previous game.
+ */
 static void MakeSortedIndustryList(void)
 {
 	const Industry* i;
 	int n = 0;
 
-	/* Don't attempt a sort if there are no industries */
-	if (GetNumIndustries() == 0) return;
-
 	/* Create array for sorting */
 	_industry_sort = realloc((void *)_industry_sort, (GetMaxIndustryIndex() + 1) * sizeof(_industry_sort[0]));
-	if (_industry_sort == NULL)
-		error("Could not allocate memory for the industry-sorting-list");
+	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
 
-	FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
+	/* Don't attempt a sort if there are no industries */
+	if (GetNumIndustries() != 0) {
+		FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
+		qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
+	}
 
 	_num_industry_sort = n;
 	_last_industry = NULL; // used for "cache"
 
-	qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
-
 	DEBUG(misc, 1) ("Resorting Industries list...");
 }
 
--- a/road_cmd.c	Mon Mar 19 18:47:10 2007 +0000
+++ b/road_cmd.c	Mon Mar 19 18:54:48 2007 +0000
@@ -71,7 +71,7 @@
 		// you can remove all kind of roads with extra dynamite
 		if (_patches.extra_dynamite) return true;
 
-		t = ClosestTownFromTile(tile, _patches.dist_local_authority);
+		t = ClosestTownFromTile(tile, (uint)-1);
 
 		SetDParam(0, t->index);
 		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
--- a/settings.c	Mon Mar 19 18:47:10 2007 +0000
+++ b/settings.c	Mon Mar 19 18:54:48 2007 +0000
@@ -1350,7 +1350,7 @@
 	 SDT_VAR(Patches, starting_year,    SLE_INT32, 0,NC,  1950, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
 	 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,  true,            STR_CONFIG_PATCHES_ALLOW_SHARES,     NULL),
+	SDT_BOOL(Patches, allow_shares,               0, 0, false,            STR_CONFIG_PATCHES_ALLOW_SHARES,     NULL),
 
 	/***************************************************************************/
 	/* AI section of the GUI-configure patches window */
@@ -1465,7 +1465,7 @@
 	/***************************************************************************/
 	/* Terrain genation related patch options */
 	SDT_CONDVAR(Patches,      land_generator,           SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   1,                   0,    1,               0, STR_CONFIG_PATCHES_LAND_GENERATOR,           NULL),
-	SDT_CONDVAR(Patches,      oil_refinery_limit,       SLE_UINT8,  30, SL_MAX_VERSION, 0, 0,   16,                  12,   48,               0, STR_CONFIG_PATCHES_OIL_REF_EDGE_DISTANCE,    NULL),
+	SDT_CONDVAR(Patches,      oil_refinery_limit,       SLE_UINT8,  30, SL_MAX_VERSION, 0, 0,   32,                  12,   48,               0, STR_CONFIG_PATCHES_OIL_REF_EDGE_DISTANCE,    NULL),
 	SDT_CONDVAR(Patches,      tgen_smoothness,          SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   1,                   0,    3,               0, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN,     NULL),
 	SDT_CONDVAR(Patches,      generation_seed,          SLE_UINT32, 30, SL_MAX_VERSION, 0, 0,    GENERATE_NEW_SEED,   0, MAX_UVALUE(uint32), 0, STR_NULL,                                    NULL),
 	SDT_CONDVAR(Patches,      tree_placer,              SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   2,                   0,    2,               0, STR_CONFIG_PATCHES_TREE_PLACER,              NULL),