(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list

Also slightly change these sorting criteria: If an industry produces more than one type of cargo sort by the sum (amount) resp. minimum (%) instead of the mean
This commit is contained in:
tron 2006-08-15 13:31:43 +00:00
parent 49b7b1e0eb
commit 721987817e
1 changed files with 51 additions and 34 deletions

View File

@ -478,47 +478,64 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{ {
const Industry* i = *(const Industry**)a; const Industry* i = *(const Industry**)a;
const Industry* j = *(const Industry**)b; const Industry* j = *(const Industry**)b;
char buf1[96]; int r;
int r = 0;
switch (_industry_sort_order >> 1) { switch (_industry_sort_order >> 1) {
/* case 0: Sort by Name (handled later) */ default: NOT_REACHED();
case 1: /* Sort by Type */ case 0: /* Sort by Name (handled later) */
r = i->type - j->type;
break;
// 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] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
if (i->produced_cargo[1] == CT_INVALID) // 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] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
r = 0; r = 0;
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list break;
r = 1;
else case 1: /* Sort by Type */
r = -1; r = i->type - j->type;
break; break;
}
case 3: /* Sort by Transported amount */ case 2: /* Sort by Production */
if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo? if (i->produced_cargo[0] == CT_INVALID) {
if (i->produced_cargo[1] == CT_INVALID) // producing one or two things? r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8); } else {
else if (j->produced_cargo[0] == CT_INVALID) {
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; r = 1;
} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting } else {
r = 0; r =
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list (i->total_production[0] + i->total_production[1]) -
r = 1; (j->total_production[0] + j->total_production[1]);
else }
r = -1; }
break; break;
case 3: /* Sort by transported fraction */
if (i->produced_cargo[0] == CT_INVALID) {
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
} else {
if (j->produced_cargo[0] == CT_INVALID) {
r = 1;
} else {
int pi;
int pj;
pi = i->pct_transported[0] * 100 >> 8;
if (i->produced_cargo[1] != CT_INVALID) {
int p = i->pct_transported[1] * 100 >> 8;
if (p < pi) pi = p;
}
pj = j->pct_transported[0] * 100 >> 8;
if (j->produced_cargo[1] != CT_INVALID) {
int p = j->pct_transported[1] * 100 >> 8;
if (p < pj) pj = p;
}
r = pi - pj;
}
}
break;
} }
// default to string sorting if they are otherwise equal // default to string sorting if they are otherwise equal
if (r == 0) { if (r == 0) {
char buf1[96];
SetDParam(0, i->town->index); SetDParam(0, i->town->index);
GetString(buf1, STR_TOWN); GetString(buf1, STR_TOWN);