summaryrefslogtreecommitdiff
path: root/src/newgrf_text.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-12-08 13:44:01 +0000
committeryexo <yexo@openttd.org>2010-12-08 13:44:01 +0000
commitac0e83a7e22c3ed94130b2fc4de62fe38478b121 (patch)
tree2829f35d5085adfb5b9a3b01bbf4bba98c16cc52 /src/newgrf_text.cpp
parent5c181fe5564926c0f23cfe483a1245fa2ee3c7c4 (diff)
downloadopenttd-ac0e83a7e22c3ed94130b2fc4de62fe38478b121.tar.xz
(svn r21435) -Fix: NewGRF strings that referenced a value that was set by a string command later in the string failed
Diffstat (limited to 'src/newgrf_text.cpp')
-rw-r--r--src/newgrf_text.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index a1b07ad3b..ff77c441c 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -863,6 +863,13 @@ struct TextRefStack {
TextRefStack() : used(false) {}
+ TextRefStack(const TextRefStack &stack) :
+ position(stack.position),
+ used(stack.used)
+ {
+ memcpy(this->stack, stack.stack, sizeof(this->stack));
+ }
+
uint8 PopUnsignedByte() { assert(this->position < lengthof(this->stack)); return this->stack[this->position++]; }
int8 PopSignedByte() { return (int8)this->PopUnsignedByte(); }
@@ -920,6 +927,34 @@ static TextRefStack _newgrf_error_textrefstack;
static TextRefStack *_newgrf_textrefstack = &_newgrf_normal_textrefstack;
/**
+ * Check whether the NewGRF text stack is in use.
+ * @return True iff the NewGRF text stack is used.
+ */
+bool UsingNewGRFTextStack()
+{
+ return _newgrf_textrefstack->used;
+}
+
+/**
+ * Create a backup of the current NewGRF text stack.
+ * @return A copy of the current text stack.
+ */
+struct TextRefStack *CreateTextRefStackBackup()
+{
+ return new TextRefStack(*_newgrf_textrefstack);
+}
+
+/**
+ * Restore a copy of the text stack to the used stack.
+ * @param backup The copy to restore.
+ */
+void RestoreTextRefStackBackup(struct TextRefStack *backup)
+{
+ *_newgrf_textrefstack = *backup;
+ delete backup;
+}
+
+/**
* Prepare the TTDP compatible string code parsing
* @param numEntries number of entries to copy from the registers
*/