summaryrefslogtreecommitdiff
path: root/src/engine.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.h')
-rw-r--r--src/engine.h36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/engine.h b/src/engine.h
index cd238b8a6..6ee7d18c4 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -262,40 +262,32 @@ static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
* Engine Replacement stuff
************************************************************************/
+struct EngineRenew;
/**
- * Struct to store engine replacements. DO NOT USE outside of engine.c. Is
+ * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
* it.
*/
-struct EngineRenew {
- EngineRenewID index;
- EngineID from;
- EngineID to;
- EngineRenew *next;
- GroupID group_id;
-};
+DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000)
/**
- * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
+ * Struct to store engine replacements. DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
* it.
*/
-DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000)
+struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> {
+ EngineID from;
+ EngineID to;
+ EngineRenew *next;
+ GroupID group_id;
-/**
- * Check if a EngineRenew really exists.
- */
-static inline bool IsValidEngineRenew(const EngineRenew *er)
-{
- return er->from != INVALID_ENGINE;
-}
+ EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {}
+ ~EngineRenew() { this->from = INVALID_ENGINE; }
-static inline void DeleteEngineRenew(EngineRenew *er)
-{
- er->from = INVALID_ENGINE;
-}
+ bool IsValid() const { return this->from != INVALID_ENGINE; }
+};
-#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->from != INVALID_ENGINE) if (IsValidEngineRenew(er))
+#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->IsValid())
#define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0)