summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-04-02 11:03:56 +0000
committeryexo <yexo@openttd.org>2010-04-02 11:03:56 +0000
commit316384a26f5fd3d9e22a004ba801a3744a6b1cc6 (patch)
treef4d3de4e3760eb5a273e870f8136bdf1058c8e08
parentb68fb8c6ed1b3b1bb43bfee97790e83bf8905714 (diff)
downloadopenttd-316384a26f5fd3d9e22a004ba801a3744a6b1cc6.tar.xz
(svn r19538) -Fix: sorting industries by production was broken for newgrf industries
-rw-r--r--src/industry_gui.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index a7c7b207e..9b8433059 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -1009,18 +1009,14 @@ protected:
/** Sort industries by production and name */
static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b)
{
- int r = 0;
-
- if ((*a)->produced_cargo[0] == CT_INVALID) {
- if ((*b)->produced_cargo[0] != CT_INVALID) return -1;
- } else {
- if ((*b)->produced_cargo[0] == CT_INVALID) return 1;
-
- r = ((*a)->last_month_production[0] + (*a)->last_month_production[1]) -
- ((*b)->last_month_production[0] + (*b)->last_month_production[1]);
+ uint prod_a = 0, prod_b = 0;
+ for (uint i = 0; i < lengthof((*a)->produced_cargo); i++) {
+ if ((*a)->produced_cargo[i] != CT_INVALID) prod_a += (*a)->last_month_production[i];
+ if ((*b)->produced_cargo[i] != CT_INVALID) prod_b += (*b)->last_month_production[i];
}
+ int r = prod_a - prod_b;
- return (r == 0) ? IndustryNameSorter(a, b) : r;
+ return (r == 0) ? IndustryTypeSorter(a, b) : r;
}
/** Sort industries by transported cargo and name */