summaryrefslogtreecommitdiff
path: root/src/timetable_cmd.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-04-12 01:28:11 +0200
committerPeterN <peter@fuzzle.org>2019-04-13 12:49:18 +0100
commit801cbea9cce1e04e6921bb087add8206cffe1fe1 (patch)
tree9ac04e07320af1b5bd0fa8e822ec571e6bd58303 /src/timetable_cmd.cpp
parent5b77102b63f77bfbad02ae3383b87fbef6e60e7d (diff)
downloadopenttd-801cbea9cce1e04e6921bb087add8206cffe1fe1.tar.xz
Codechange: use std::sort() for all std::vector types
Diffstat (limited to 'src/timetable_cmd.cpp')
-rw-r--r--src/timetable_cmd.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index 4ab7c746f..2b2de28a9 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -216,15 +216,12 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
* Order vehicles based on their timetable. The vehicles will be sorted in order
* they would reach the first station.
*
- * @param ap First Vehicle pointer.
- * @param bp Second Vehicle pointer.
+ * @param a First Vehicle pointer.
+ * @param b Second Vehicle pointer.
* @return Comparison value.
*/
-static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp)
+static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
{
- const Vehicle *a = *ap;
- const Vehicle *b = *bp;
-
VehicleOrderID a_order = a->cur_real_order_index;
VehicleOrderID b_order = b->cur_real_order_index;
int j = (int)b_order - (int)a_order;
@@ -242,15 +239,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp
/* First check the order index that accounted for loading, then just the raw one. */
int i = (int)b_order - (int)a_order;
- if (i != 0) return i;
- if (j != 0) return j;
+ if (i != 0) return i < 0;
+ if (j != 0) return j < 0;
/* Look at the time we spent in this order; the higher, the closer to its destination. */
i = b->current_order_time - a->current_order_time;
- if (i != 0) return i;
+ if (i != 0) return i < 0;
/* If all else is equal, use some unique index to sort it the same way. */
- return b->unitnumber - a->unitnumber;
+ return b->unitnumber < a->unitnumber;
}
/**
@@ -295,7 +292,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
int num_vehs = (uint)vehs.size();
if (num_vehs >= 2) {
- QSortT(vehs.data(), vehs.size(), &VehicleTimetableSorter);
+ std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter);
}
int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v);