summaryrefslogtreecommitdiff
path: root/src/rail_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2015-10-30 17:24:30 +0000
committerfrosch <frosch@openttd.org>2015-10-30 17:24:30 +0000
commit2d636266f59e8f5e88c3460b9adb8889442108d8 (patch)
tree2ce70a31ab745556593c46cb72d5c2341b34cc69 /src/rail_cmd.cpp
parent312809228d52009191e2000cc1a49272b48f9699 (diff)
downloadopenttd-2d636266f59e8f5e88c3460b9adb8889442108d8.tar.xz
(svn r27427) -Fix: Use the NewGRF railtype sorting order in the infrastructure window.
Diffstat (limited to 'src/rail_cmd.cpp')
-rw-r--r--src/rail_cmd.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 743e6e193..2010f9b30 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -44,6 +44,8 @@
typedef SmallVector<Train *, 16> TrainList;
RailtypeInfo _railtypes[RAILTYPE_END];
+RailType _sorted_railtypes[RAILTYPE_END];
+uint8 _sorted_railtypes_size;
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
@@ -110,6 +112,17 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti)
}
/**
+ * Compare railtypes based on their sorting order.
+ * @param first The railtype to compare to.
+ * @param second The railtype to compare.
+ * @return True iff the first should be sorted before the second.
+ */
+static int CDECL CompareRailTypes(const RailType *first, const RailType *second)
+{
+ return GetRailTypeInfo(*first)->sorting_order - GetRailTypeInfo(*second)->sorting_order;
+}
+
+/**
* Resolve sprites of custom rail types
*/
void InitRailTypes()
@@ -118,6 +131,14 @@ void InitRailTypes()
RailtypeInfo *rti = &_railtypes[rt];
ResolveRailTypeGUISprites(rti);
}
+
+ _sorted_railtypes_size = 0;
+ for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
+ if (_railtypes[rt].label != 0) {
+ _sorted_railtypes[_sorted_railtypes_size++] = rt;
+ }
+ }
+ QSortT(_sorted_railtypes, _sorted_railtypes_size, CompareRailTypes);
}
/**