summaryrefslogtreecommitdiff
path: root/industry_gui.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-06 18:15:13 +0000
committerdarkvater <darkvater@openttd.org>2004-09-06 18:15:13 +0000
commitbf0652d3fce57024fe56f75d43898a261fea7570 (patch)
treeff59ad94248c5c270741fe954c139e1f953b197c /industry_gui.c
parentdf1397a47e68cf07d0a0d4fe02758f4b4f8c469f (diff)
downloadopenttd-bf0652d3fce57024fe56f75d43898a261fea7570.tar.xz
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
-Fix: Sorter icon pointing down 'v' sorts in every window lowest value first, '^' highest value first -CodeChange: move Dropdownlist from settings_gui.c to widget.c. More in place there.
Diffstat (limited to 'industry_gui.c')
-rw-r--r--industry_gui.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/industry_gui.c b/industry_gui.c
index de697f918..b67f2360f 100644
--- a/industry_gui.c
+++ b/industry_gui.c
@@ -388,45 +388,44 @@ static byte _last_industry_idx;
static byte _industry_sort_order;
-static int CDECL IndustrySorter(const void *a, const void *b)
+static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{
char buf1[96];
- Industry *i, *j;
byte val;
+ Industry *i = DEREF_INDUSTRY(*(byte*)a);
+ Industry *j = DEREF_INDUSTRY(*(byte*)b);
int r = 0;
- i = DEREF_INDUSTRY(*(byte*)a);
- j = DEREF_INDUSTRY(*(byte*)b);
-
switch (_industry_sort_order >> 1) {
- case 0:
- r = 0;
- break;
- case 1: /* Case 1, sort by type */
+ /* case 0: Sort by Name (handled later) */
+ case 1: /* Sort by Type */
r = i->type - j->type;
break;
- case 2: /* Case 2, sort by production */
- if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo?
- if (i->produced_cargo[1] == 0xFF) //producing one or two things?
+ // FIXME - Production & Transported sort need to be inversed...but, WTF it does not wanna!
+ // FIXME - And no simple --> "if (!(_industry_sort_order & 1)) r = -r;" hack at the bottom!!
+ case 2: { /* Sort by Production */
+ if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
+ if (i->produced_cargo[1] == 0xFF) // producing one or two things?
r = j->total_production[0] - i->total_production[0];
else
r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2;
- } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting
+ } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
r = 0;
- else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list
+ else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
break;
- case 3: /* Case 3, sort by transportation */
- if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo?
- if (i->produced_cargo[1] == 0xFF) //producing one or two things?
+ }
+ case 3: /* Sort by Transported amount */
+ if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
+ if (i->produced_cargo[1] == 0xFF) // producing one or two things?
r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8);
else
r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2;
- } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting
+ } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
r = 0;
- else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list
+ else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
@@ -446,9 +445,7 @@ static int CDECL IndustrySorter(const void *a, const void *b)
r = strcmp(buf1, _bufcache);
}
- if (_industry_sort_order & 1)
- r = -r;
-
+ if (_industry_sort_order & 1) r = -r;
return r;
}
@@ -464,7 +461,7 @@ static void MakeSortedIndustryList()
_num_industry_sort = n;
_last_industry_idx = 255; // used for "cache"
- qsort(_industry_sort, n, 1, IndustrySorter);
+ qsort(_industry_sort, n, 1, GeneralIndustrySorter);
DEBUG(misc, 1) ("Resorting Industries list...");
}