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

Function EngineCostSorter

src/build_vehicle_gui.cpp:193–202  ·  view source on GitHub ↗

* Determines order of engines by purchase cost * @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

191 * @return for descending order: returns true if a < b. Vice versa for ascending order
192 */
193static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
194{
195 Money va = Engine::Get(a.engine_id)->GetCost();
196 Money vb = Engine::Get(b.engine_id)->GetCost();
197 int r = ClampTo<int32_t>(va - vb);
198
199 /* Use EngineID to sort instead since we want consistent sorting */
200 if (r == 0) return EngineNumberSorter(a, b);
201 return _engine_sort_direction ? r > 0 : r < 0;
202}
203
204/**
205 * Determines order of engines by speed

Callers

nothing calls this directly

Calls 2

EngineNumberSorterFunction · 0.70
GetCostMethod · 0.45

Tested by

no test coverage detected