rubidium@6872: /* $Id$ */ rubidium@6872: rubidium@6872: /** @file autoreplace_base.h Base class for autoreplaces/autorenews. */ rubidium@6872: rubidium@6872: #ifndef AUTOREPLACE_BASE_H rubidium@6872: #define AUTOREPLACE_BASE_H rubidium@6872: rubidium@6872: #include "oldpool.h" rubidium@6872: #include "autoreplace_type.h" rubidium@6872: rubidium@6872: /** rubidium@6872: * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is rubidium@6872: * placed here so the only exception to this rule, the saveload code, can use rubidium@6872: * it. rubidium@6872: */ rubidium@6872: DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) rubidium@6872: rubidium@6872: /** rubidium@6872: * Struct to store engine replacements. DO NOT USE outside of engine.c. Is rubidium@6872: * placed here so the only exception to this rule, the saveload code, can use rubidium@6872: * it. rubidium@6872: */ rubidium@6872: struct EngineRenew : PoolItem { rubidium@6872: EngineID from; rubidium@6872: EngineID to; rubidium@6872: EngineRenew *next; rubidium@6872: GroupID group_id; rubidium@6872: rubidium@6872: EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {} rubidium@6872: ~EngineRenew() { this->from = INVALID_ENGINE; } rubidium@6872: rubidium@6872: inline bool IsValid() const { return this->from != INVALID_ENGINE; } rubidium@6872: }; rubidium@6872: rubidium@6872: #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()) rubidium@6872: #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) rubidium@6872: rubidium@6872: #endif /* AUTOREPLACE_BASE_H */