summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-03-28 12:25:09 +0000
committerterkhen <terkhen@openttd.org>2010-03-28 12:25:09 +0000
commit217a98e69b56d74b53d915d15bd73e000005935d (patch)
treec4869b011ba7db7dc8c5a0b68a58f59c4d3cadd5 /src/industry_gui.cpp
parent5193ed0fc1aecf9492a29e6ce87f07ee53d21ab6 (diff)
downloadopenttd-217a98e69b56d74b53d915d15bd73e000005935d.tar.xz
(svn r19521) -Codechange: Use a IndustryType array to sort industries by name instead of a LegendAndColour array.
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index a0bebce8a..1bf565656 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -96,6 +96,40 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons
}
}
+IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES];
+
+/** Sort industry types by their name. */
+static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryType *b)
+{
+ static char industry_name[2][64];
+
+ const IndustrySpec *indsp1 = GetIndustrySpec(*a);
+ SetDParam(0, indsp1->name);
+ GetString(industry_name[0], STR_JUST_STRING, lastof(industry_name[0]));
+
+ const IndustrySpec *indsp2 = GetIndustrySpec(*b);
+ SetDParam(0, indsp2->name);
+ GetString(industry_name[1], STR_JUST_STRING, lastof(industry_name[1]));
+
+ int r = strcmp(industry_name[0], industry_name[1]);
+
+ /* If the names are equal, sort by industry type. */
+ return (r != 0) ? r : (*a - *b);
+}
+
+/** Initialize the list of sorted industry types.
+ */
+void SortIndustryTypes()
+{
+ /* Add each industry type to the list. */
+ for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
+ _sorted_industry_types[i] = i;
+ }
+
+ /* Sort industry types by name. */
+ QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter);
+}
+
/** Command callback. In case of failure to build an industry, show an error message.
* @param result Result of the command.
* @param tile Tile where the industry is placed.