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

Function EngineIntroDateSorter

src/build_vehicle_gui.cpp:129–138  ·  view source on GitHub ↗

* Determines order of engines by introduction date * @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

127 * @return for descending order: returns true if a < b. Vice versa for ascending order
128 */
129static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
130{
131 const auto va = Engine::Get(a.engine_id)->intro_date;
132 const auto vb = Engine::Get(b.engine_id)->intro_date;
133 const auto r = va - vb;
134
135 /* Use EngineID to sort instead since we want consistent sorting */
136 if (r == 0) return EngineNumberSorter(a, b);
137 return _engine_sort_direction ? r > 0 : r < 0;
138}
139
140/* cached values for EngineNameSorter to spare many GetString() calls */
141static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() };

Callers

nothing calls this directly

Calls 1

EngineNumberSorterFunction · 0.70

Tested by

no test coverage detected