diff options
author | glx <glx@openttd.org> | 2019-12-15 22:45:18 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-12-21 20:13:03 +0100 |
commit | 1f6b3a37f9c39adb22eb61d3153b0c62bfa20551 (patch) | |
tree | 15486a7d6bb1445f3d6f1cbf40f98c1552368c08 /src/engine_base.h | |
parent | 1c92ba8ebed55e5455d6f57508db8ce55071d6eb (diff) | |
download | openttd-1f6b3a37f9c39adb22eb61d3153b0c62bfa20551.tar.xz |
Codechange: Replace FOR_ALL_ENGINES with range-based for loops
Diffstat (limited to 'src/engine_base.h')
-rw-r--r-- | src/engine_base.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/engine_base.h b/src/engine_base.h index df43f3f78..1328f66a1 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -141,6 +141,17 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { } uint32 GetGRFID() const; + + /** + * Returns an iterable ensemble of all valid engines of the given type + * @param vt the VehicleType for engines to be valid + * @param from index of the first engine to consider + * @return an iterable ensemble of all valid engines of the given type + */ + static Pool::IterateWrapper<Engine> IterateType(VehicleType vt, size_t from = 0) + { + return Pool::IterateWrapper<Engine>(from, [vt](size_t index) { return Engine::Get(index)->type == vt; }); + } }; struct EngineIDMapping { @@ -165,11 +176,6 @@ struct EngineOverrideManager : std::vector<EngineIDMapping> { extern EngineOverrideManager _engine_mngr; -#define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start) -#define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0) - -#define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type) - static inline const EngineInfo *EngInfo(EngineID e) { return &Engine::Get(e)->info; |