From 11b1c6f2eee0d4f51dc99352e2755b3ae7d68a8f Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 19 Mar 2007 18:54:48 +0000 Subject: [PATCH] (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 | 20 ++++++++++++-------- road_cmd.c | 2 +- settings.c | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/industry_gui.c b/industry_gui.c index 13fbac9cc9..07e738fc1e 100644 --- a/industry_gui.c +++ b/industry_gui.c @@ -553,26 +553,30 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b) 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..."); } diff --git a/road_cmd.c b/road_cmd.c index 6c06809a23..6c9fa28a91 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -71,7 +71,7 @@ static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool* edge_roa // 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; diff --git a/settings.c b/settings.c index 5df543d3b7..498049ddfb 100644 --- a/settings.c +++ b/settings.c @@ -1350,7 +1350,7 @@ const SettingDesc _patch_settings[] = { 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 @@ const SettingDesc _patch_settings[] = { /***************************************************************************/ /* 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),