summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2004-12-11 11:00:54 +0000
committertron <tron@openttd.org>2004-12-11 11:00:54 +0000
commitf995fd08a104045ee7942409e2518e3e726df62b (patch)
treed170d1a36793ef3da280f9bc6634e909d63e8616
parent0ba5123cef72c427c010f9ce8bcb6003e1de72bd (diff)
downloadopenttd-f995fd08a104045ee7942409e2518e3e726df62b.tar.xz
(svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
Also add the number sorter to sort by vehicle number if the cargo capacity is equal.
-rw-r--r--vehicle_gui.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 5dd09734d..09dcb9e84 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -246,24 +246,21 @@ int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
int CDECL VehicleCargoSorter(const void *a, const void *b)
{
- // FIXME - someone write a normal cargo sorter that also works by cargo_cap,
- // FIXME - since I seem to be unable to do so :S
const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ const Vehicle *v;
int r = 0;
int i;
- byte _cargo_counta[NUM_CARGO];
- byte _cargo_countb[NUM_CARGO];
+ uint _cargo_counta[NUM_CARGO];
+ uint _cargo_countb[NUM_CARGO];
memset(_cargo_counta, 0, sizeof(_cargo_counta));
memset(_cargo_countb, 0, sizeof(_cargo_countb));
- do {
- _cargo_counta[va->cargo_type]++;
- } while ( (va = va->next) != NULL);
+ for (v = va; v != NULL; v = v->next)
+ _cargo_counta[v->cargo_type] += v->cargo_cap;
- do {
- _cargo_countb[vb->cargo_type]++;
- } while ( (vb = vb->next) != NULL);
+ for (v = vb; v != NULL; v = v->next)
+ _cargo_countb[v->cargo_type] += v->cargo_cap;
for (i = 0; i < NUM_CARGO; i++) {
r = _cargo_counta[i] - _cargo_countb[i];
@@ -271,6 +268,8 @@ int CDECL VehicleCargoSorter(const void *a, const void *b)
break;
}
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
+
return (_internal_sort_order & 1) ? -r : r;
}