src/autoreplace_base.h
changeset 8708 0c29fbc79be4
parent 8653 a83f7a536919
equal deleted inserted replaced
8707:55835d8fbfcd 8708:0c29fbc79be4
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file autoreplace_base.h Base class for autoreplaces/autorenews. */
       
     4 
       
     5 #ifndef AUTOREPLACE_BASE_H
       
     6 #define AUTOREPLACE_BASE_H
       
     7 
       
     8 #include "oldpool.h"
       
     9 #include "autoreplace_type.h"
       
    10 
       
    11 /**
       
    12  * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
       
    13  * placed here so the only exception to this rule, the saveload code, can use
       
    14  * it.
       
    15  */
       
    16 DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000)
       
    17 
       
    18 /**
       
    19  * Struct to store engine replacements. DO NOT USE outside of engine.c. Is
       
    20  * placed here so the only exception to this rule, the saveload code, can use
       
    21  * it.
       
    22  */
       
    23 struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> {
       
    24 	EngineID from;
       
    25 	EngineID to;
       
    26 	EngineRenew *next;
       
    27 	GroupID group_id;
       
    28 
       
    29 	EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {}
       
    30 	~EngineRenew() { this->from = INVALID_ENGINE; }
       
    31 
       
    32 	inline bool IsValid() const { return this->from != INVALID_ENGINE; }
       
    33 };
       
    34 
       
    35 #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())
       
    36 #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0)
       
    37 
       
    38 #endif /* AUTOREPLACE_BASE_H */