260 |
260 |
261 /************************************************************************ |
261 /************************************************************************ |
262 * Engine Replacement stuff |
262 * Engine Replacement stuff |
263 ************************************************************************/ |
263 ************************************************************************/ |
264 |
264 |
|
265 struct EngineRenew; |
|
266 /** |
|
267 * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is |
|
268 * placed here so the only exception to this rule, the saveload code, can use |
|
269 * it. |
|
270 */ |
|
271 DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) |
|
272 |
265 /** |
273 /** |
266 * Struct to store engine replacements. DO NOT USE outside of engine.c. Is |
274 * Struct to store engine replacements. DO NOT USE outside of engine.c. Is |
267 * placed here so the only exception to this rule, the saveload code, can use |
275 * placed here so the only exception to this rule, the saveload code, can use |
268 * it. |
276 * it. |
269 */ |
277 */ |
270 struct EngineRenew { |
278 struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> { |
271 EngineRenewID index; |
|
272 EngineID from; |
279 EngineID from; |
273 EngineID to; |
280 EngineID to; |
274 EngineRenew *next; |
281 EngineRenew *next; |
275 GroupID group_id; |
282 GroupID group_id; |
276 }; |
283 |
277 |
284 EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {} |
278 /** |
285 ~EngineRenew() { this->from = INVALID_ENGINE; } |
279 * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is |
286 |
280 * placed here so the only exception to this rule, the saveload code, can use |
287 bool IsValid() const { return this->from != INVALID_ENGINE; } |
281 * it. |
288 }; |
282 */ |
289 |
283 DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) |
290 #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()) |
284 |
|
285 /** |
|
286 * Check if a EngineRenew really exists. |
|
287 */ |
|
288 static inline bool IsValidEngineRenew(const EngineRenew *er) |
|
289 { |
|
290 return er->from != INVALID_ENGINE; |
|
291 } |
|
292 |
|
293 static inline void DeleteEngineRenew(EngineRenew *er) |
|
294 { |
|
295 er->from = INVALID_ENGINE; |
|
296 } |
|
297 |
|
298 #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)) |
|
299 #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) |
291 #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) |
300 |
292 |
301 |
293 |
302 /** |
294 /** |
303 * A list to group EngineRenew directives together (such as per-player). |
295 * A list to group EngineRenew directives together (such as per-player). |