From f89b0e8c45ba5fedff1d1baf5ce8fab0129ceb14 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 Nov 2016 20:53:42 -0400 Subject: TITANIC: Fixes to show speaking NPC image in conversation view --- engines/titanic/pet_control/pet_text.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engines/titanic/pet_control/pet_text.cpp') diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp index 78dceb7a31..97bb0be02d 100644 --- a/engines/titanic/pet_control/pet_text.cpp +++ b/engines/titanic/pet_control/pet_text.cpp @@ -173,7 +173,7 @@ void CPetText::draw(CScreenManager *screenManager) { tempRect.grow(-2); int oldFontNumber = screenManager->setFontNumber(_fontNumber); - screenManager->writeString(SURFACE_BACKBUFFER, tempRect, _scrollTop, _lines, _textCursor); + _linesStart = screenManager->writeString(SURFACE_BACKBUFFER, tempRect, _scrollTop, _lines, _textCursor); screenManager->setFontNumber(oldFontNumber); } @@ -450,7 +450,7 @@ void CPetText::hideCursor() { } } -int CPetText::getNPCNum(uint npcId, uint startIndex) { +int CPetText::getNPCNum(uint ident, uint startIndex) { if (!_stringsMerged) { mergeStrings(); if (!_stringsMerged) @@ -461,18 +461,20 @@ int CPetText::getNPCNum(uint npcId, uint startIndex) { if (startIndex < 5 || startIndex >= size) return -1; - // Loop through string - for (const char *strP = _lines.c_str(); size >= 5; ++strP, --size) { + // Loop backwards from the starting index to find an NPC ident sequence + for (const char *strP = _lines.c_str() + startIndex; + strP >= (_lines.c_str() + 5); --strP) { if (*strP == 26) { byte id = *(strP - 2); - if (id == npcId) + if (id == ident) return *(strP - 1); + strP -= 3; } else if (*strP == 27) { - strP += 4; + strP -= 4; } } - return - 1; + return -1; } void CPetText::setFontNumber(int fontNumber) { -- cgit v1.2.3