summaryrefslogtreecommitdiff
path: root/engine.h
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-01-12 15:52:18 +0000
committerpeter1138 <peter1138@openttd.org>2006-01-12 15:52:18 +0000
commit90aff7a026c8e833d78e932575995485c2da9e47 (patch)
tree2a159338918aa7b1a61fab6e18f4e28ae2b27950 /engine.h
parent28ca056d56bb716e125745c16876408527fdc278 (diff)
downloadopenttd-90aff7a026c8e833d78e932575995485c2da9e47.tar.xz
(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)
Diffstat (limited to 'engine.h')
-rw-r--r--engine.h81
1 files changed, 81 insertions, 0 deletions
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 */