MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TrainEngineCapacitySorter

Function TrainEngineCapacitySorter

src/build_vehicle_gui.cpp:320–332  ·  view source on GitHub ↗

* Determines order of train engines by capacity * @param a first engine to compare * @param b second engine to compare * @return for descending order: returns true if a < b. Vice versa for ascending order */

Source from the content-addressed store, hash-verified

318 * @return for descending order: returns true if a < b. Vice versa for ascending order
319 */
320static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
321{
322 const RailVehicleInfo *rvi_a = RailVehInfo(a.engine_id);
323 const RailVehicleInfo *rvi_b = RailVehInfo(b.engine_id);
324
325 int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
326 int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
327 int r = va - vb;
328
329 /* Use EngineID to sort instead since we want consistent sorting */
330 if (r == 0) return EngineNumberSorter(a, b);
331 return _engine_sort_direction ? r > 0 : r < 0;
332}
333
334/**
335 * Determines order of train engines by engine / wagon

Callers

nothing calls this directly

Calls 3

RailVehInfoFunction · 0.85
EngineNumberSorterFunction · 0.70

Tested by

no test coverage detected