diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- 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_textre 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 */