From ac0e83a7e22c3ed94130b2fc4de62fe38478b121 Mon Sep 17 00:00:00 2001 From: yexo Date: Wed, 8 Dec 2010 13:44:01 +0000 Subject: (svn r21435) -Fix: NewGRF strings that referenced a value that was set by a string command later in the string failed --- src/newgrf_text.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/newgrf_text.cpp') 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(); } @@ -919,6 +926,34 @@ static TextRefStack _newgrf_error_textrefstack; /** The stack that is used for TTDP compatible string code parsing */ 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 -- cgit v1.2.3-54-g00ecf