summaryrefslogtreecommitdiff
path: root/vehicle_gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'vehicle_gui.c')
-rw-r--r--vehicle_gui.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c
index ed5fc1666..5d0536d76 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -6,23 +6,11 @@
/* General Vehicle GUI based procedures that are independent of vehicle types */
void InitializeVehiclesGuiList()
{
- bool *i;
- for (i = _train_sort_dirty; i != endof(_train_sort_dirty); i++)
- *i = true;
-
- for (i = _aircraft_sort_dirty; i != endof(_aircraft_sort_dirty); i++)
- *i = true;
-
- for (i = _ship_sort_dirty; i != endof(_ship_sort_dirty); i++)
- *i = true;
-
- for (i = _road_sort_dirty; i != endof(_road_sort_dirty); i++)
- *i = true;
-
- for (i = _vehicle_sort_dirty; i != endof(_vehicle_sort_dirty); i++)
- *i = true;
-
- //memset(_train_sort_dirty, true, sizeof(_train_sort_dirty));
+ memset(_train_sort_dirty, true, sizeof(_train_sort_dirty));
+ memset(_aircraft_sort_dirty, true, sizeof(_aircraft_sort_dirty));
+ memset(_ship_sort_dirty, true, sizeof(_ship_sort_dirty));
+ memset(_road_sort_dirty, true, sizeof(_road_sort_dirty));
+ memset(_vehicle_sort_dirty, true, sizeof(_vehicle_sort_dirty));
}
// draw the vehicle profit button in the vehicle list window.
@@ -59,15 +47,15 @@ int CDECL VehicleUnsortedSorter(const void *a, const void *b)
return DEREF_VEHICLE((*(const SortStruct*)a).index)->index - DEREF_VEHICLE((*(const SortStruct*)b).index)->index;
}
+// if the sorting criteria had the same value, sort vehicle by unitnumber
+#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
+
int CDECL VehicleNumberSorter(const void *a, const void *b)
{
const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->unitnumber - vb->unitnumber;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
-
return (_internal_sort_order & 1) ? -r : r;
}
@@ -97,8 +85,7 @@ int CDECL VehicleNameSorter(const void *a, const void *b)
r = strcmp(buf1, _bufcache); // sort by name
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}
@@ -109,8 +96,7 @@ int CDECL VehicleAgeSorter(const void *a, const void *b)
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->age - vb->age;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}
@@ -121,8 +107,7 @@ int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->profit_this_year - vb->profit_this_year;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}
@@ -133,8 +118,7 @@ int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->profit_last_year - vb->profit_last_year;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}
@@ -175,8 +159,7 @@ int CDECL VehicleReliabilitySorter(const void *a, const void *b)
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->reliability - vb->reliability;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}
@@ -187,8 +170,7 @@ int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
int r = va->max_speed - vb->max_speed;
- if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
- r = va->unitnumber - vb->unitnumber;
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
return (_internal_sort_order & 1) ? -r : r;
}