mirror of https://github.com/OpenTTD/OpenTTD
(svn r6736) - Add a function to get the list position of an engine ID, for use with sorting. This is basically a reversed version of GetRailVehAtPosition()
parent
0ad5dbfdb9
commit
8d2bf45123
|
@ -1124,6 +1124,7 @@ StringID GetCustomEngineName(EngineID engine)
|
||||||
// Functions for changing the order of vehicle purchase lists
|
// Functions for changing the order of vehicle purchase lists
|
||||||
// This is currently only implemented for rail vehicles.
|
// This is currently only implemented for rail vehicles.
|
||||||
static EngineID _engine_list_order[NUM_TRAIN_ENGINES];
|
static EngineID _engine_list_order[NUM_TRAIN_ENGINES];
|
||||||
|
static byte _engine_list_position[NUM_TRAIN_ENGINES];
|
||||||
|
|
||||||
void ResetEngineListOrder(void)
|
void ResetEngineListOrder(void)
|
||||||
{
|
{
|
||||||
|
@ -1131,12 +1132,32 @@ void ResetEngineListOrder(void)
|
||||||
|
|
||||||
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
||||||
_engine_list_order[i] = i;
|
_engine_list_order[i] = i;
|
||||||
|
_engine_list_position[i] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the EngineID at position pos.
|
||||||
|
* Used when drawing a(n unsorted) list of engines.
|
||||||
|
* @param pos List position/
|
||||||
|
* @return The EngineID at the requested position.
|
||||||
|
*/
|
||||||
EngineID GetRailVehAtPosition(EngineID pos)
|
EngineID GetRailVehAtPosition(EngineID pos)
|
||||||
{
|
{
|
||||||
return _engine_list_order[pos];
|
if (pos < NUM_TRAIN_ENGINES) return _engine_list_order[pos];
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list position of an engine.
|
||||||
|
* Used when sorting a list of engines.
|
||||||
|
* @param engine ID of the engine.
|
||||||
|
* @return The list position of the engine.
|
||||||
|
*/
|
||||||
|
uint16 ListPositionOfEngine(EngineID engine)
|
||||||
|
{
|
||||||
|
if (engine < NUM_TRAIN_ENGINES) return _engine_list_position[engine];
|
||||||
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlterRailVehListOrder(EngineID engine, EngineID target)
|
void AlterRailVehListOrder(EngineID engine, EngineID target)
|
||||||
|
@ -1160,4 +1181,9 @@ void AlterRailVehListOrder(EngineID engine, EngineID target)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the engine list position (a reverse of engine list order)
|
||||||
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
||||||
|
_engine_list_position[_engine_list_order[i]] = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ void UnloadCustomEngineNames(void);
|
||||||
|
|
||||||
void ResetEngineListOrder(void);
|
void ResetEngineListOrder(void);
|
||||||
EngineID GetRailVehAtPosition(EngineID pos);
|
EngineID GetRailVehAtPosition(EngineID pos);
|
||||||
|
uint16 ListPositionOfEngine(EngineID engine);
|
||||||
void AlterRailVehListOrder(EngineID engine, EngineID target);
|
void AlterRailVehListOrder(EngineID engine, EngineID target);
|
||||||
|
|
||||||
#endif /* NEWGRF_ENGINE_H */
|
#endif /* NEWGRF_ENGINE_H */
|
||||||
|
|
Loading…
Reference in New Issue