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

Function EngineRunningCostSorter

src/build_vehicle_gui.cpp:261–270  ·  view source on GitHub ↗

* Determines order of engines by running costs * @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

259 * @return for descending order: returns true if a < b. Vice versa for ascending order
260 */
261static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
262{
263 Money va = Engine::Get(a.engine_id)->GetRunningCost();
264 Money vb = Engine::Get(b.engine_id)->GetRunningCost();
265 int r = ClampTo<int32_t>(va - vb);
266
267 /* Use EngineID to sort instead since we want consistent sorting */
268 if (r == 0) return EngineNumberSorter(a, b);
269 return _engine_sort_direction ? r > 0 : r < 0;
270}
271
272/**
273 * Determines order of engines by running costs

Callers 1

Calls 2

EngineNumberSorterFunction · 0.70
GetRunningCostMethod · 0.45

Tested by

no test coverage detected