From 90aff7a026c8e833d78e932575995485c2da9e47 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Thu, 12 Jan 2006 15:52:18 +0000 Subject: (svn r3396) - Autoreplace changes: - Change fixed array per player to a single pool. This avoids future problems with vehicle numbers and decreases savegame size. Engine replacements from previous savegames will be lost. - Move engine replacement code from players.c to engine.c. (thanks to blathijs for rewriting this) --- engine.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'engine.h') diff --git a/engine.h b/engine.h index be8e21aa7..7b32c96a5 100644 --- a/engine.h +++ b/engine.h @@ -7,6 +7,7 @@ */ #include "sprite.h" +#include "pool.h" typedef struct RailVehicleInfo { byte image_index; @@ -102,6 +103,10 @@ enum { NUM_VEHICLE_TYPES = 6 }; +enum { + INVALID_ENGINE = 0xFFFF, +}; + void AddTypeToEngines(void); void StartupEngines(void); @@ -283,4 +288,80 @@ void UnloadWagonOverrides(void); void UnloadCustomEngineSprites(void); void UnloadCustomEngineNames(void); +/************************************************************************ + * Engine Replacement stuff + ************************************************************************/ + +/** + * 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. + */ +struct EngineRenew { + uint16 index; + EngineID from; + EngineID to; + struct EngineRenew *next; +}; + +typedef struct EngineRenew EngineRenew; + +/** + * 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. + */ +extern MemoryPool _engine_renew_pool; + +/** + * DO NOT USE outside of engine.c. Is + * placed here so the only exception to this rule, the saveload code, can use + * it. + */ +static inline EngineRenew *GetEngineRenew(uint16 index) +{ + return (EngineRenew*)GetItemFromPool(&_engine_renew_pool, index); +} + + +/** + * A list to group EngineRenew directives together (such as per-player). + */ +typedef EngineRenew* EngineRenewList; + +/** + * Remove all engine replacement settings for the player. + * @param er The renewlist for a given player. + * @return The new renewlist for the player. + */ +void RemoveAllEngineReplacement(EngineRenewList* erl); + +/** + * Retrieve the engine replacement in a given renewlist for an original engine type. + * @param erl The renewlist to search in. + * @param engine Engine type to be replaced. + * @return The engine type to replace with, or INVALID_ENGINE if no + * replacement is in the list. + */ +EngineID EngineReplacement(EngineRenewList erl, EngineID engine); + +/** + * Add an engine replacement to the given renewlist. + * @param erl The renewlist to add to. + * @param old_engine The original engine type. + * @param new_engine The replacement engine type. + * @param flags The calling command flags. + * @return 0 on success, CMD_ERROR on failure. + */ +int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, uint32 flags); + +/** + * Remove an engine replacement from a given renewlist. + * @param erl The renewlist from which to remove the replacement + * @param engine The original engine type. + * @param flags The calling command flags. + * @return 0 on success, CMD_ERROR on failure. + */ +int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags); + #endif /* ENGINE_H */ -- cgit v1.2.3-54-g00ecf