summaryrefslogtreecommitdiff
path: root/src/newgrf_string_type.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-01-15 13:19:49 +0000
committerrubidium <rubidium@openttd.org>2008-01-15 13:19:49 +0000
commit26c621945d36e18cce2e86e0edbac9e525ba77db (patch)
tree674e51d7f086d490a4dcb2fded3e60d9f94042d3 /src/newgrf_string_type.h
parent0078fd1699fc594b46827d3680b31fd79f0d9bd2 (diff)
downloadopenttd-26c621945d36e18cce2e86e0edbac9e525ba77db.tar.xz
(svn r11862) -Fix [FS#1559]: when two NewGRFs 'fight' to define the same cargo it could happen that the strings are defined by one cargo and the 'action2' by another and when one assumes that both come from the same NewGRF... So store the GRF ID with the strings. To be extra sure add the same protection mechanism to industries and towns too.
Diffstat (limited to 'src/newgrf_string_type.h')
-rw-r--r--src/newgrf_string_type.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/newgrf_string_type.h b/src/newgrf_string_type.h
new file mode 100644
index 000000000..4a0bdd790
--- /dev/null
+++ b/src/newgrf_string_type.h
@@ -0,0 +1,54 @@
+/* $Id$ */
+
+/** @file newgrf_string_type.h */
+
+#ifndef NEWGRF_STRING_TYPE_H
+#define NEWGRF_STRING_TYPE_H
+
+#include "strings_type.h"
+
+/**
+ * A string with the required information to perform a GRF string remapping.
+ */
+struct GRFMappedStringID
+{
+private:
+ /** The GRF ID associated to the to-be-remapped string */
+ uint32 grfid;
+ /** The string; when grfid != 0 it should be remapped */
+ StringID string;
+
+public:
+ /**
+ * Create the struct.
+ * @param str the string to store (or remap)
+ * @param grf_id the GRF to remap it with
+ */
+ GRFMappedStringID(StringID str, uint32 grf_id) : grfid(grf_id), string(str) {}
+
+ /**
+ * An empty string.
+ */
+ GRFMappedStringID() {}
+
+ /** Cast operator, returns the string */
+ inline operator StringID() const
+ {
+ return string;
+ }
+
+ /** Assigns the string and resets the GRF ID. */
+ GRFMappedStringID& operator = (StringID str)
+ {
+ string = str;
+ grfid = 0;
+ return *this;
+ }
+
+ /**
+ * Map the string.
+ */
+ void MapString();
+};
+
+#endif /* NEWGRF_STRING_TYPE_H */