summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-03-02 19:57:55 +0000
committerrubidium <rubidium@openttd.org>2007-03-02 19:57:55 +0000
commit6887fbbaaf73751fe0675e322c83fddcdb9f09d8 (patch)
treebaf0114c5b078fac47801649ac634ca9bf1d3a89
parent517f2bcc57c5ef62ead1185790d7c3ec9e1cf1f2 (diff)
downloadopenttd-6887fbbaaf73751fe0675e322c83fddcdb9f09d8.tar.xz
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
-rw-r--r--src/industry_gui.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 9cbe0c3f2..cc95a1de6 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -552,25 +552,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 = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
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, 3, "Resorting industries list");
}