scummvm/engines/hopkins/talk.cpp

1111 lines
34 KiB
C++
Raw Normal View History

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/system.h"
#include "common/endian.h"
#include "common/file.h"
#include "common/textconsole.h"
#include "hopkins/talk.h"
#include "hopkins/files.h"
#include "hopkins/globals.h"
#include "hopkins/graphics.h"
#include "hopkins/hopkins.h"
#include "hopkins/objects.h"
namespace Hopkins {
TalkManager::TalkManager() {
2012-12-19 08:00:22 +01:00
_characterBuffer = NULL;
_characterPalette = NULL;
_characterSprite = NULL;
_characterAnim = NULL;
2012-12-19 08:00:22 +01:00
_characterSize = 0;
STATI = false;
2013-01-20 00:56:19 +01:00
_dialogueMesgId1 = _dialogueMesgId2 = _dialogueMesgId3 = _dialogueMesgId4 = 0;
_paletteBufferIdx = 0;
}
void TalkManager::setParent(HopkinsEngine *vm) {
_vm = vm;
}
void TalkManager::PARLER_PERSO(const Common::String &filename) {
2012-12-26 21:30:51 +01:00
Common::String spriteFilename;
_vm->_fontManager.hideText(5);
_vm->_fontManager.hideText(9);
_vm->_eventsManager.VBL();
2013-01-20 00:56:19 +01:00
_vm->_graphicsManager._scrollStatus = 1;
bool oldDisableInventFl = _vm->_globals._disableInventFl;
_vm->_globals._disableInventFl = true;
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_fileManager.searchCat(filename, 5);
_characterSize = _vm->_globals._catalogSize;
if (_characterBuffer == g_PTRNUL) {
_characterBuffer = _vm->_fileManager.loadFile(filename);
_characterSize = _vm->_fileManager.fileSize(filename);
}
_vm->_globals._saveData->_data[svField4] = 0;
2012-12-26 21:30:51 +01:00
getStringFromBuffer(40, spriteFilename, (const char *)_characterBuffer);
getStringFromBuffer(0, _questionsFilename, (const char *)_characterBuffer);
getStringFromBuffer(20, _answersFilename, (const char *)_characterBuffer);
if (_vm->_globals._language == LANG_FR) {
2012-12-19 08:00:22 +01:00
_answersFilename = _questionsFilename = "RUE.TXT";
} else if (_vm->_globals._language == LANG_EN) {
2012-12-19 08:00:22 +01:00
_answersFilename = _questionsFilename = "RUEAN.TXT";
} else if (_vm->_globals._language == LANG_SP) {
2012-12-19 08:00:22 +01:00
_answersFilename = _questionsFilename = "RUEES.TXT";
}
2013-01-20 00:56:19 +01:00
_dialogueMesgId1 = (int16)READ_LE_UINT16((uint16 *)_characterBuffer + 40);
_paletteBufferIdx = 20 * (int16)READ_LE_UINT16((uint16 *)_characterBuffer + 42) + 110;
2012-12-26 21:30:51 +01:00
_characterSprite = _vm->_fileManager.searchCat(spriteFilename, 7);
if (_characterSprite) {
_characterSprite = _vm->_objectsManager.loadSprite(spriteFilename);
} else {
_characterSprite = _vm->_objectsManager.loadSprite("RES_SAN.RES");
}
2012-12-19 08:00:22 +01:00
if (_vm->_graphicsManager._lineNbr == SCREEN_WIDTH)
_vm->_saveLoadManager.saveFile("TEMP.SCR", _vm->_graphicsManager._vesaScreen, 307200);
2012-12-19 08:00:22 +01:00
else if (_vm->_graphicsManager._lineNbr == (SCREEN_WIDTH * 2))
_vm->_saveLoadManager.saveFile("TEMP.SCR", _vm->_graphicsManager._vesaScreen, 614400);
2012-12-19 08:00:22 +01:00
if (!_vm->_graphicsManager._lineNbr)
_vm->_graphicsManager._scrollOffset = 0;
_vm->_graphicsManager.NB_SCREEN(true);
2012-10-29 23:08:23 +01:00
_vm->_objectsManager.PERSO_ON = true;
searchCharacterPalette(_paletteBufferIdx, false);
startCharacterAnim0(_paletteBufferIdx, false);
initCharacterAnim();
2013-01-20 00:56:19 +01:00
_dialogueMesgId2 = _dialogueMesgId1 + 1;
_dialogueMesgId3 = _dialogueMesgId1 + 2;
_dialogueMesgId4 = _dialogueMesgId1 + 3;
int oldMouseCursorId = _vm->_eventsManager._mouseCursorId;
2012-12-11 08:31:07 +01:00
_vm->_eventsManager._mouseCursorId = 4;
_vm->_eventsManager.changeMouseCursor(0);
if (!_vm->_globals._introSpeechOffFl) {
int answer = 0;
int dlgAnswer;
do {
dlgAnswer = dialogQuestion();
if (dlgAnswer != _dialogueMesgId4)
answer = dialogAnswer(dlgAnswer);
2012-12-26 21:30:51 +01:00
if (answer == -1)
dlgAnswer = _dialogueMesgId4;
_vm->_eventsManager.VBL();
} while (dlgAnswer != _dialogueMesgId4);
}
if (_vm->_globals._introSpeechOffFl) {
int idx = 1;
int answer;
do
answer = dialogAnswer(idx++);
while (answer != -1);
}
clearCharacterAnim();
_vm->_globals._introSpeechOffFl = false;
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_globals.freeMemory(_characterBuffer);
_characterSprite = _vm->_globals.freeMemory(_characterSprite);
_vm->_graphicsManager.NB_SCREEN(false);
2012-10-24 23:20:26 +11:00
_vm->_saveLoadManager.load("TEMP.SCR", _vm->_graphicsManager._vesaScreen);
g_system->getSavefileManager()->removeSavefile("TEMP.SCR");
2012-10-24 23:20:26 +11:00
2012-10-29 23:08:23 +01:00
_vm->_objectsManager.PERSO_ON = false;
_vm->_eventsManager._mouseCursorId = oldMouseCursorId;
_vm->_eventsManager.changeMouseCursor(oldMouseCursorId);
_vm->_graphicsManager.SETCOLOR3(253, 100, 100, 100);
if (_vm->getIsDemo() == false)
_vm->_graphicsManager.SETCOLOR3(254, 0, 0, 0);
_vm->_graphicsManager.initColorTable(145, 150, _vm->_graphicsManager._palette);
2013-01-07 08:33:55 +01:00
_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
_vm->_graphicsManager.lockScreen();
_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaScreen, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
_vm->_graphicsManager.unlockScreen();
memcpy(_vm->_graphicsManager._vesaBuffer, _vm->_graphicsManager._vesaScreen, 614399);
_vm->_globals._disableInventFl = oldDisableInventFl;
_vm->_graphicsManager.DD_VBL();
for (int i = 0; i <= 4; i++)
_vm->_eventsManager.VBL();
2013-01-20 00:56:19 +01:00
_vm->_graphicsManager._scrollStatus = 0;
}
void TalkManager::PARLER_PERSO2(const Common::String &filename) {
2013-01-07 19:59:38 +02:00
// TODO: The original disables the mouse cursor here
STATI = true;
bool oldDisableInventFl = _vm->_globals._disableInventFl;
_vm->_globals._disableInventFl = true;
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_fileManager.searchCat(filename, 5);
_characterSize = _vm->_globals._catalogSize;
if (_characterBuffer == g_PTRNUL) {
_characterBuffer = _vm->_fileManager.loadFile(filename);
_characterSize = _vm->_fileManager.fileSize(filename);
}
_vm->_globals._saveData->_data[svField4] = 0;
2012-12-26 21:30:51 +01:00
getStringFromBuffer(0, _questionsFilename, (const char *)_characterBuffer);
getStringFromBuffer(20, _answersFilename, (const char *)_characterBuffer);
switch (_vm->_globals._language) {
case LANG_EN:
2012-12-19 08:00:22 +01:00
_questionsFilename = "RUEAN.TXT";
_answersFilename = "RUEAN.TXT";
break;
case LANG_FR:
2012-12-19 08:00:22 +01:00
_questionsFilename = "RUE.TXT";
_answersFilename = "RUE.TXT";
break;
case LANG_SP:
2012-12-19 08:00:22 +01:00
_questionsFilename = "RUEES.TXT";
_answersFilename = "RUEES.TXT";
break;
}
2013-01-20 00:56:19 +01:00
_dialogueMesgId1 = (int16)READ_LE_UINT16((uint16 *)_characterBuffer + 40);
_paletteBufferIdx = 20 * (int16)READ_LE_UINT16((uint16 *)_characterBuffer + 42) + 110;
searchCharacterPalette(_paletteBufferIdx, false);
2013-01-20 00:56:19 +01:00
_dialogueMesgId2 = _dialogueMesgId1 + 1;
_dialogueMesgId3 = _dialogueMesgId1 + 2;
_dialogueMesgId4 = _dialogueMesgId1 + 3;
int oldMouseCursorId = _vm->_eventsManager._mouseCursorId;
2012-12-11 08:31:07 +01:00
_vm->_eventsManager._mouseCursorId = 4;
_vm->_eventsManager.changeMouseCursor(0);
if (!_vm->_globals._introSpeechOffFl) {
int answer;
do {
answer = dialogQuestion();
if (answer != _dialogueMesgId4) {
if (dialogAnswer(answer) == -1)
answer = _dialogueMesgId4;
}
} while (answer != _dialogueMesgId4);
}
if (_vm->_globals._introSpeechOffFl) {
int idx = 1;
int answer;
2013-01-24 00:05:36 +01:00
do
answer = dialogAnswer(idx++);
while (answer != -1);
}
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_globals.freeMemory(_characterBuffer);
_vm->_eventsManager._mouseCursorId = oldMouseCursorId;
_vm->_eventsManager.changeMouseCursor(oldMouseCursorId);
_vm->_graphicsManager.initColorTable(145, 150, _vm->_graphicsManager._palette);
2013-01-07 08:33:55 +01:00
_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
2013-01-07 19:59:38 +02:00
// TODO: The original reenables the mouse cursor here
_vm->_globals._disableInventFl = oldDisableInventFl;
STATI = false;
}
2012-12-26 21:30:51 +01:00
void TalkManager::getStringFromBuffer(int srcStart, Common::String &dest, const char *srcData) {
dest = Common::String(srcData + srcStart);
}
int TalkManager::dialogQuestion() {
if (STATI) {
uint16 *bufPtr = (uint16 *)_characterBuffer + 48;
int curVal = (int16)READ_LE_UINT16(bufPtr);
if (curVal != 0)
_vm->_objectsManager.setBobAnimation(curVal);
if (curVal != 1)
_vm->_objectsManager.setBobAnimation((int16)READ_LE_UINT16(bufPtr + 1));
if (curVal != 2)
_vm->_objectsManager.setBobAnimation((int16)READ_LE_UINT16(bufPtr + 2));
if (curVal != 3)
_vm->_objectsManager.setBobAnimation((int16)READ_LE_UINT16(bufPtr + 3));
if (curVal != 4)
_vm->_objectsManager.setBobAnimation((int16)READ_LE_UINT16(bufPtr + 4));
} else {
2012-12-27 18:41:52 +01:00
dialogWait();
}
2013-01-20 00:56:19 +01:00
int sentence1LineNumb = VERIF_BOITE(_dialogueMesgId1, _questionsFilename, 65);
int sentence2LineNumb = VERIF_BOITE(_dialogueMesgId2, _questionsFilename, 65);
int sentence3LineNumb = VERIF_BOITE(_dialogueMesgId3, _questionsFilename, 65);
int sentence4LineNumb = VERIF_BOITE(_dialogueMesgId4, _questionsFilename, 65);
int sentence4PosY = 420 - 20 * sentence4LineNumb;
int sentence3PosY = sentence4PosY - 20 * sentence3LineNumb;
int sentence2PosY = sentence3PosY - 20 * sentence2LineNumb;
int sentence1PosY = sentence2PosY - 20 * sentence1LineNumb;
2013-01-20 00:56:19 +01:00
_vm->_fontManager.initTextBuffers(5, _dialogueMesgId1, _questionsFilename, 5, sentence1PosY, 0, 65, 255);
_vm->_fontManager.initTextBuffers(6, _dialogueMesgId2, _questionsFilename, 5, sentence2PosY, 0, 65, 255);
_vm->_fontManager.initTextBuffers(7, _dialogueMesgId3, _questionsFilename, 5, sentence3PosY, 0, 65, 255);
_vm->_fontManager.initTextBuffers(8, _dialogueMesgId4, _questionsFilename, 5, sentence4PosY, 0, 65, 255);
_vm->_fontManager.showText(5);
_vm->_fontManager.showText(6);
_vm->_fontManager.showText(7);
_vm->_fontManager.showText(8);
int retVal = -1;
bool loopCond = false;
do {
int mousePosY = _vm->_eventsManager.getMouseY();
if (sentence1PosY < mousePosY && mousePosY < (sentence2PosY - 1)) {
_vm->_fontManager.setOptimalColor(6, 7, 8, 5);
2013-01-20 00:56:19 +01:00
retVal = _dialogueMesgId1;
}
if (sentence2PosY < mousePosY && mousePosY < (sentence3PosY - 1)) {
_vm->_fontManager.setOptimalColor(5, 7, 8, 6);
2013-01-20 00:56:19 +01:00
retVal = _dialogueMesgId2;
}
if (sentence3PosY < mousePosY && mousePosY < (sentence4PosY - 1)) {
_vm->_fontManager.setOptimalColor(5, 6, 8, 7);
2013-01-20 00:56:19 +01:00
retVal = _dialogueMesgId3;
}
if (sentence4PosY < mousePosY && mousePosY < 419) {
_vm->_fontManager.setOptimalColor(5, 6, 7, 8);
2013-01-20 00:56:19 +01:00
retVal = _dialogueMesgId4;
}
_vm->_eventsManager.VBL();
if (_vm->_eventsManager.getMouseButton())
loopCond = true;
if (retVal == -1)
loopCond = false;
} while (!_vm->shouldQuit() && !loopCond);
_vm->_soundManager.mixVoice(retVal, 1);
_vm->_fontManager.hideText(5);
_vm->_fontManager.hideText(6);
_vm->_fontManager.hideText(7);
_vm->_fontManager.hideText(8);
if (STATI) {
uint16 *bufPtr = (uint16 *)_characterBuffer + 48;
int curVal = (int16)READ_LE_UINT16(bufPtr);
if (curVal != 0)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 1);
if (curVal != 1)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 2);
if (curVal != 2)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 3);
if (curVal != 3)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 4);
if (curVal != 4)
_vm->_objectsManager.stopBobAnimation(curVal);
} else {
2012-12-27 18:41:52 +01:00
dialogTalk();
}
_vm->_eventsManager.VBL();
return retVal;
}
int TalkManager::dialogAnswer(int idx) {
int charIdx;
byte *charBuf;
for (charBuf = _characterBuffer + 110, charIdx = 0; (int16)READ_LE_UINT16(charBuf) != idx; charBuf += 20) {
++charIdx;
if ((int16)READ_LE_UINT16((uint16 *)_characterBuffer + 42) < charIdx)
return -1;
}
int mesgId = (int16)READ_LE_UINT16((uint16 *)charBuf + 1);
int mesgPosX = (int16)READ_LE_UINT16((uint16 *)charBuf + 2);
int mesgPosY = (int16)READ_LE_UINT16((uint16 *)charBuf + 3);
int mesgLength = (int16)READ_LE_UINT16((uint16 *)charBuf + 4);
_dialogueMesgId1 = (int16)READ_LE_UINT16((uint16 *)charBuf + 5);
_dialogueMesgId2 = (int16)READ_LE_UINT16((uint16 *)charBuf + 6);
_dialogueMesgId3 = (int16)READ_LE_UINT16((uint16 *)charBuf + 7);
int v6 = (int16)READ_LE_UINT16((uint16 *)charBuf + 8);
int v7 = (int16)READ_LE_UINT16((uint16 *)charBuf + 9);
if (v7)
_vm->_globals._saveData->_data[svField4] = v7;
if (!v6)
v6 = 10;
if (STATI) {
uint16 *bufPtr = (uint16 *)_characterBuffer + 43;
int curVal = (int16)READ_LE_UINT16(bufPtr);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 1);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 2);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 3);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 4);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
} else {
VISU_PARLE();
}
if (!_vm->_soundManager._textOffFl) {
_vm->_fontManager.initTextBuffers(9, mesgId, _answersFilename, mesgPosX, mesgPosY, 5, mesgLength, 252);
_vm->_fontManager.showText(9);
}
if (!_vm->_soundManager.mixVoice(mesgId, 1)) {
2012-12-11 08:31:07 +01:00
_vm->_eventsManager._curMouseButton = 0;
_vm->_eventsManager._mouseButton = 0;
if (_vm->getIsDemo()) {
for (int i = 0; i < v6; i++) {
_vm->_eventsManager.VBL();
}
} else {
for (int i = 0; i < v6; i++) {
_vm->_eventsManager.VBL();
2012-12-11 08:31:07 +01:00
if (_vm->_eventsManager._mouseButton || _vm->_eventsManager._curMouseButton)
break;
if (_vm->_eventsManager.getMouseButton() && i + 1 > abs(v6 / 5))
break;
}
}
}
if (!_vm->_soundManager._textOffFl)
_vm->_fontManager.hideText(9);
if (STATI) {
uint16 *bufPtr = (uint16 *)_characterBuffer + 43;
int curVal = (int16)READ_LE_UINT16(bufPtr);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 1);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 2);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 3);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
curVal = (int16)READ_LE_UINT16(bufPtr + 4);
if (curVal)
_vm->_objectsManager.stopBobAnimation(curVal);
} else {
2012-12-27 18:41:52 +01:00
dialogEndTalk();
}
int result = 0;
2013-01-20 00:56:19 +01:00
if (!_dialogueMesgId1)
result = -1;
return result;
}
void TalkManager::searchCharacterPalette(int startIdx, bool dark) {
int palettePos = 0;
size_t curIdx = startIdx;
for (;;) {
if (READ_BE_UINT24(&_characterBuffer[curIdx]) == MKTAG24('P', 'A', 'L')) {
palettePos = curIdx;
break;
}
++curIdx;
if (_characterSize == curIdx)
return;
}
_characterPalette = _characterBuffer + palettePos + 5;
_characterPalette[0] = 0;
_characterPalette[1] = 0;
_characterPalette[2] = 0;
_characterPalette[759] = 255;
_characterPalette[760] = 255;
_characterPalette[762] = 0;
_characterPalette[763] = 0;
_characterPalette[764] = 0;
_characterPalette[765] = 224;
_characterPalette[766] = 224;
_characterPalette[767] = 255;
if (!dark)
_characterPalette[761] = 86;
else
_characterPalette[761] = 255;
2013-01-07 08:33:55 +01:00
_vm->_graphicsManager.setPaletteVGA256(_characterPalette);
_vm->_graphicsManager.initColorTable(145, 150, _characterPalette);
}
2012-12-27 18:41:52 +01:00
void TalkManager::dialogWait() {
for (int idx = 26; idx <= 30; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
BOB_VISU_PARLE(idx);
}
}
2012-12-27 18:41:52 +01:00
void TalkManager::dialogTalk() {
for (int idx = 26; idx <= 30; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
_vm->_objectsManager.BOB_OFF(idx);
}
for (int idx = 26; idx <= 30; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
_vm->_objectsManager.resetBob(idx);
}
}
2012-12-27 18:41:52 +01:00
void TalkManager::dialogEndTalk() {
for (int idx = 21; idx <= 25; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
_vm->_objectsManager.BOB_OFF(idx);
}
_vm->_eventsManager.VBL();
_vm->_eventsManager.VBL();
for (int idx = 21; idx <= 25; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
_vm->_objectsManager.resetBob(idx);
}
}
int TalkManager::VERIF_BOITE(int idx, const Common::String &file, int a3) {
int v9;
int v10;
char v11;
char v13;
2012-09-30 21:21:09 +10:00
int v15;
byte *ptr;
int v17;
byte *v19;
2012-10-24 23:20:26 +11:00
uint32 indexData[4047];
Common::String filename;
Common::String dest;
Common::File f;
int filesize;
_vm->_fontManager._fontFixedWidth = 11;
2012-10-24 23:20:26 +11:00
// Build up the filename
filename = dest = file;
2012-10-24 23:20:26 +11:00
while (filename.lastChar() != '.')
filename.deleteLastChar();
filename += "IND";
if (!f.open(filename))
error("Could not open file - %s", filename.c_str());
filesize = f.size();
assert(filesize < 16188);
2012-10-24 23:20:26 +11:00
for (int i = 0; i < (filesize / 4); ++i)
indexData[i] = f.readUint32LE();
f.close();
if (!f.open(dest))
error("Error opening file - %s", dest.c_str());
2012-10-24 23:20:26 +11:00
f.seek(indexData[idx]);
ptr = _vm->_globals.allocMemory(2058);
if (ptr == g_PTRNUL)
error("temporary TEXT");
f.read(ptr, 2048);
f.close();
v19 = ptr;
for (int i = 0; i < 2048; i++) {
v13 = *v19;
2012-12-21 01:26:11 +01:00
if ((byte)(*v19 + 46) > 27) {
if ((byte)(v13 + 80) > 27) {
if ((byte)(v13 - 65) <= 25 || (byte)(v13 - 97) <= 25)
v13 = 32;
} else {
v13 -= 79;
}
} else {
v13 = *v19 + 111;
}
*v19 = v13;
v19++;
}
for (int i = 0; i < 2048; i++) {
if ( ptr[i] == 10 || ptr[i] == 13 )
ptr[i] = 0;
}
v9 = 0;
v15 = (11 * a3) - 4;
int lineCount = 0;
do {
v10 = 0;
for (;;) {
v17 = v10;
do {
v11 = ptr[v9 + v10];
++v10;
} while (v11 != ' ' && v11 != '%');
if (v10 >= v15 / _vm->_fontManager._fontFixedWidth) {
if (v11 == '%')
v11 = ' ';
break;
}
if (v11 == '%') {
v17 = v10;
break;
}
}
++lineCount;
v9 += v17;
} while (v11 != '%');
free(ptr);
return lineCount;
}
void TalkManager::VISU_PARLE() {
for (int idx = 21; idx <= 25; ++idx) {
if (_vm->_globals.Bqe_Anim[idx]._enabledFl)
BOB_VISU_PARLE(idx);
}
}
void TalkManager::BOB_VISU_PARLE(int idx) {
int v4;
byte *v5;
_vm->_objectsManager._priorityFl = true;
if (!_vm->_globals._bob[idx].field0) {
_vm->_objectsManager.resetBob(idx);
v5 = _vm->_globals.Bqe_Anim[idx]._data;
v4 = (int16)READ_LE_UINT16(v5 + 2);
if (!v4)
v4 = 1;
if ((int16)READ_LE_UINT16(v5 + 24)) {
_vm->_globals._bob[idx]._isSpriteFl = true;
_vm->_globals._bob[idx]._zoomFactor = 0;
_vm->_globals._bob[idx]._flipFl = false;
_vm->_globals._bob[idx]._animData = _vm->_globals.Bqe_Anim[idx]._data;
_vm->_globals._bob[idx].field0 = 10;
v5 = _characterSprite;
_vm->_globals._bob[idx]._spriteData = _characterSprite;
_vm->_globals._bob[idx].field1E = v4;
_vm->_globals._bob[idx].field20 = -1;
_vm->_globals._bob[idx].field22 = 0;
_vm->_globals._bob[idx]._offsetY = 0;
}
}
}
void TalkManager::startCharacterAnim0(int startIdx, bool readOnlyFl) {
int animIdx = 0;
size_t curIdx = startIdx;
for (;;) {
2013-01-30 00:17:08 +01:00
if (READ_BE_UINT32(&_characterBuffer[curIdx]) == MKTAG('A', 'N', 'I', 'M') && _characterBuffer[curIdx + 4] == 1) {
animIdx = curIdx;
break;
}
++curIdx;
if (_characterSize == curIdx)
return;
}
_characterAnim = _characterBuffer + animIdx + 25;
if (!readOnlyFl) {
int idx = 0;
int v7;
do {
v7 = (int16)READ_LE_UINT16(&_characterAnim[2 * idx + 4]);
if (v7 && _vm->_globals._speed != 501)
_vm->_graphicsManager.fastDisplay(_characterSprite, _vm->_eventsManager._startPos.x + (int16)READ_LE_UINT16(&_characterAnim[2 * idx]),
(int16)READ_LE_UINT16(&_characterAnim[2 * idx + 2]), _characterAnim[2 * idx + 8]);
idx += 5;
} while (_vm->_globals._speed != 501 && v7);
}
}
/**
* Initialize character animation
*/
void TalkManager::initCharacterAnim() {
uint16 *bufPtr = (uint16 *)_characterBuffer + 43;
byte *animPtr = _characterBuffer + 110;
int curVal = (int16)READ_LE_UINT16(bufPtr);
if (curVal)
searchCharacterAnim(21, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 1);
if (curVal)
searchCharacterAnim(22, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 2);
if (curVal)
searchCharacterAnim(23, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 3);
if (curVal)
searchCharacterAnim(24, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 4);
if (curVal)
searchCharacterAnim(25, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 5);
if (curVal)
searchCharacterAnim(26, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 6);
if (curVal)
searchCharacterAnim(27, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 7);
if (curVal)
searchCharacterAnim(28, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 8);
if (curVal)
searchCharacterAnim(29, animPtr, curVal, _characterSize);
curVal = (int16)READ_LE_UINT16(bufPtr + 9);
if (curVal)
searchCharacterAnim(30, animPtr, curVal, _characterSize);
}
void TalkManager::clearCharacterAnim() {
for (int idx = 21; idx <= 34; ++idx) {
_vm->_globals.Bqe_Anim[idx]._data = _vm->_globals.freeMemory(_vm->_globals.Bqe_Anim[idx]._data);
_vm->_globals.Bqe_Anim[idx]._enabledFl = false;
}
}
bool TalkManager::searchCharacterAnim(int idx, const byte *bufPerso, int animId, int bufferSize) {
bool result = false;
for (int bufPos = 0; bufPos <= bufferSize; bufPos++) {
if (READ_BE_UINT32(bufPerso + bufPos) == MKTAG('A', 'N', 'I', 'M') && bufPerso[bufPos + 4] == animId) {
int bufIndx = bufPos + 5;
const byte *curPtr = bufPerso + bufIndx;
int animLength = 0;
bool loopCond = false;
do {
if (READ_BE_UINT32(curPtr) == MKTAG('A', 'N', 'I', 'M') || READ_BE_UINT24(curPtr) == MKTAG24('F', 'I', 'N'))
loopCond = true;
if (bufIndx > bufferSize) {
_vm->_globals.Bqe_Anim[idx]._enabledFl = false;
_vm->_globals.Bqe_Anim[idx]._data = g_PTRNUL;
return false;
}
++bufIndx;
++animLength;
++curPtr;
} while (!loopCond);
_vm->_globals.Bqe_Anim[idx]._data = _vm->_globals.allocMemory(animLength + 50);
_vm->_globals.Bqe_Anim[idx]._enabledFl = true;
memcpy(_vm->_globals.Bqe_Anim[idx]._data, (const byte *)(bufPerso + bufPos + 5), 20);
int v23 = (int16)READ_LE_UINT16(bufPos + bufPerso + 29);
WRITE_LE_UINT16(_vm->_globals.Bqe_Anim[idx]._data + 20, (int16)READ_LE_UINT16(bufPos + bufPerso + 25));
WRITE_LE_UINT16(_vm->_globals.Bqe_Anim[idx]._data + 22, (int16)READ_LE_UINT16(bufPos + bufPerso + 27));
WRITE_LE_UINT16(_vm->_globals.Bqe_Anim[idx]._data + 24, v23);
WRITE_LE_UINT16(_vm->_globals.Bqe_Anim[idx]._data + 26, (int16)READ_LE_UINT16(bufPos + bufPerso + 31));
_vm->_globals.Bqe_Anim[idx]._data[28] = bufPerso[bufPos + 33];
_vm->_globals.Bqe_Anim[idx]._data[29] = bufPerso[bufPos + 34];
byte *bqeCurData = _vm->_globals.Bqe_Anim[idx]._data + 20;
const byte *curBufPerso = bufPos + bufPerso + 25;
for (int i = 1; i < 5000; i++) {
bqeCurData += 10;
curBufPerso += 10;
if (!v23)
break;
v23 = (int16)READ_LE_UINT16(curBufPerso + 4);
WRITE_LE_UINT16(bqeCurData, (int16)READ_LE_UINT16(curBufPerso));
WRITE_LE_UINT16(bqeCurData + 2, (int16)READ_LE_UINT16(curBufPerso + 2));
WRITE_LE_UINT16(bqeCurData + 4, v23);
WRITE_LE_UINT16(bqeCurData + 6, (int16)READ_LE_UINT16(curBufPerso + 6));
bqeCurData[8] = curBufPerso[8];
bqeCurData[9] = curBufPerso[9];
}
result = true;
}
if (READ_BE_UINT24(&bufPerso[bufPos]) == MKTAG24('F', 'I', 'N'))
result = true;
if (result)
break;
}
return result;
}
2013-01-18 18:52:19 +01:00
void TalkManager::REPONSE(int zone, int verb) {
uint16 v7;
byte *v8;
int opcodeType;
uint16 v11;
int v12;
int lastOpcodeResult;
2013-01-27 01:25:46 +01:00
bool tagFound;
bool v16;
bool innerLoopCond;
byte *ptr;
2013-01-18 18:52:19 +01:00
byte zoneObj = zone;
byte verbObj = verb;
bool outerLoopFl;
2013-01-27 01:25:46 +01:00
do {
outerLoopFl = false;
tagFound = false;
if (_vm->_globals._answerBuffer == g_PTRNUL)
2013-01-27 01:25:46 +01:00
return;
byte *curAnswerBuf = _vm->_globals._answerBuffer;
for (;;) {
if (READ_BE_UINT24(curAnswerBuf) == MKTAG24('F', 'I', 'N'))
return;
if (READ_BE_UINT24(curAnswerBuf) == MKTAG24('C', 'O', 'D')) {
if (curAnswerBuf[3] == zoneObj && curAnswerBuf[4] == verbObj)
tagFound = true;
}
if (!tagFound)
curAnswerBuf++;
else
break;
2013-01-27 01:25:46 +01:00
}
// 'COD' tag found
curAnswerBuf += 5;
ptr = _vm->_globals.allocMemory(620);
assert(ptr != g_PTRNUL);
memset(ptr, 0, 620);
v7 = 0;
v12 = 0;
innerLoopCond = false;
do {
v16 = false;
if (READ_BE_UINT16(&curAnswerBuf[v7]) == MKTAG16('F', 'C')) {
++v12;
assert(v12 < (620 / 20));
v8 = (ptr + 20 * v12);
v11 = 0;
do {
assert(v11 < 20);
v8[v11++] = curAnswerBuf[v7++];
if (READ_BE_UINT16(&curAnswerBuf[v7]) == MKTAG16('F', 'F')) {
v16 = true;
v8[v11] = 'F';
v8[v11 + 1] = 'F';
++v7;
}
} while (!v16);
}
if (!v16) {
uint32 signature24 = READ_BE_UINT24(&curAnswerBuf[v7]);
if (signature24 == MKTAG24('C', 'O', 'D') || signature24 == MKTAG24('F', 'I', 'N'))
innerLoopCond = true;
}
curAnswerBuf += v7 + 1;
v7 = 0;
} while (!innerLoopCond);
innerLoopCond = false;
lastOpcodeResult = 1;
do {
opcodeType = _vm->_scriptManager.handleOpcode(ptr + 20 * lastOpcodeResult);
if (_vm->shouldQuit())
return;
if (opcodeType == 2)
// GOTO
lastOpcodeResult = _vm->_scriptManager.handleGoto(ptr + 20 * lastOpcodeResult);
else if (opcodeType == 3)
// IF
lastOpcodeResult = _vm->_scriptManager.handleIf(ptr, lastOpcodeResult);
if (lastOpcodeResult == -1)
error("Invalid IFF function");
if (opcodeType == 1 || opcodeType == 4)
// Already handled opcode or END IF
++lastOpcodeResult;
else if (!opcodeType || opcodeType == 5)
// EXIT
innerLoopCond = true;
else if (opcodeType == 6) {
// JUMP
_vm->_globals.freeMemory(ptr);
zoneObj = _vm->_objectsManager._jumpZone;
verbObj = _vm->_objectsManager._jumpVerb;
outerLoopFl = true;
break;
}
} while (!innerLoopCond);
} while (outerLoopFl);
2013-01-27 01:25:46 +01:00
_vm->_globals.freeMemory(ptr);
_vm->_globals._saveData->_data[svField2] = 0;
return;
}
void TalkManager::REPONSE2(int a1, int a2) {
int indx = 0;
if (a2 != 5 || _vm->_globals._saveData->_data[svField3] != 4)
2013-01-18 18:52:19 +01:00
return;
if (a1 == 22 || a1 == 23) {
_vm->_objectsManager.setFlipSprite(0, false);
_vm->_objectsManager.setSpriteIndex(0, 62);
_vm->_objectsManager.SPACTION(_vm->_objectsManager._forestSprite, "2,3,4,5,6,7,8,9,10,11,12,-1,", 0, 0, 4, false);
2013-01-18 18:52:19 +01:00
if (a1 == 22) {
_vm->_objectsManager.lockAnimX(6, _vm->_objectsManager.getBobPosX(3));
_vm->_objectsManager.lockAnimX(8, _vm->_objectsManager.getBobPosX(3));
} else { // a1 == 23
_vm->_objectsManager.lockAnimX(6, _vm->_objectsManager.getBobPosX(4));
_vm->_objectsManager.lockAnimX(8, _vm->_objectsManager.getBobPosX(4));
}
_vm->_objectsManager.stopBobAnimation(3);
_vm->_objectsManager.stopBobAnimation(4);
_vm->_objectsManager.setBobAnimation(6);
_vm->_soundManager.PLAY_SAMPLE2(1);
_vm->_objectsManager.SPACTION1(_vm->_objectsManager._forestSprite, "13,14,15,14,13,12,13,14,15,16,-1,", 0, 0, 4);
2013-01-18 18:52:19 +01:00
do
_vm->_eventsManager.VBL();
while (_vm->_objectsManager.getBobAnimDataIdx(6) < 12);
2013-01-18 18:52:19 +01:00
_vm->_objectsManager.stopBobAnimation(6);
_vm->_objectsManager.setBobAnimation(8);
switch (_vm->_globals._screenId) {
case 35:
indx = 201;
break;
case 36:
indx = 203;
break;
case 37:
indx = 205;
break;
case 38:
indx = 207;
break;
case 39:
indx = 209;
break;
case 40:
indx = 211;
break;
case 41:
indx = 213;
break;
}
_vm->_globals._saveData->_data[indx] = 2;
2013-01-18 18:52:19 +01:00
_vm->_objectsManager.disableZone(22);
_vm->_objectsManager.disableZone(23);
} else if (a1 == 20 || a1 == 21) {
_vm->_objectsManager.setFlipSprite(0, true);
_vm->_objectsManager.setSpriteIndex(0, 62);
_vm->_objectsManager.SPACTION(_vm->_objectsManager._forestSprite, "2,3,4,5,6,7,8,9,10,11,12,-1,", 0, 0, 4, true);
2013-01-18 18:52:19 +01:00
if (a1 == 20) {
_vm->_objectsManager.lockAnimX(5, _vm->_objectsManager.getBobPosX(1));
_vm->_objectsManager.lockAnimX(7, _vm->_objectsManager.getBobPosX(1));
} else { // a1 == 21
_vm->_objectsManager.lockAnimX(5, _vm->_objectsManager.getBobPosX(2));
_vm->_objectsManager.lockAnimX(7, _vm->_objectsManager.getBobPosX(2));
}
_vm->_objectsManager.stopBobAnimation(1);
_vm->_objectsManager.stopBobAnimation(2);
_vm->_objectsManager.setBobAnimation(5);
_vm->_soundManager.PLAY_SAMPLE2(1);
_vm->_objectsManager.SPACTION1(_vm->_objectsManager._forestSprite, "13,14,15,14,13,12,13,14,15,16,-1,", 0, 0, 4);
2013-01-18 18:52:19 +01:00
do
_vm->_eventsManager.VBL();
while (_vm->_objectsManager.getBobAnimDataIdx(5) < 12);
2013-01-18 18:52:19 +01:00
_vm->_objectsManager.stopBobAnimation(5);
_vm->_objectsManager.setBobAnimation(7);
switch (_vm->_globals._screenId) {
case 35:
indx = 200;
break;
case 36:
indx = 202;
break;
case 37:
indx = 204;
break;
case 38:
indx = 206;
break;
case 39:
indx = 208;
break;
case 40:
indx = 210;
break;
case 41:
indx = 212;
break;
}
_vm->_globals._saveData->_data[indx] = 2;
2013-01-18 18:52:19 +01:00
_vm->_objectsManager.disableZone(21);
_vm->_objectsManager.disableZone(20);
}
}
void TalkManager::OBJET_VIVANT(const Common::String &a2) {
byte *v11;
Common::String s;
Common::String v20;
Common::String v22;
Common::String v23;
_vm->_fontManager.hideText(5);
_vm->_fontManager.hideText(9);
_vm->_eventsManager.VBL();
2013-01-20 00:56:19 +01:00
_vm->_graphicsManager._scrollStatus = 1;
2013-01-11 01:50:29 +01:00
_vm->_linesManager.clearAllZones();
_vm->_linesManager.resetLines();
_vm->_globals.resetCache();
for (int i = 0; i <= 44; i++)
_vm->_globals.BOBZONE[i] = 0;
_vm->_objectsManager._zoneNum = -1;
2012-12-11 08:31:07 +01:00
_vm->_eventsManager._mouseCursorId = 4;
_vm->_eventsManager.changeMouseCursor(0);
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_fileManager.searchCat(a2, 5);
_characterSize = _vm->_globals._catalogSize;
if (_characterBuffer == g_PTRNUL) {
_characterBuffer = _vm->_fileManager.loadFile(a2);
_characterSize = _vm->_fileManager.fileSize(a2);
}
2012-12-26 21:30:51 +01:00
getStringFromBuffer(40, v23, (const char *)_characterBuffer);
getStringFromBuffer(0, v22, (const char *)_characterBuffer);
getStringFromBuffer(20, v20, (const char *)_characterBuffer);
2012-12-19 08:00:22 +01:00
if (v20 == "NULL")
v20 = Common::String::format("IM%d", _vm->_globals._screenId);
2012-12-19 08:00:22 +01:00
_characterSprite = _vm->_fileManager.searchCat(v23, 7);
2012-12-19 08:00:22 +01:00
if (_characterSprite)
_characterSprite = _vm->_objectsManager.loadSprite(v23);
2012-12-19 08:00:22 +01:00
else
_characterSprite = _vm->_objectsManager.loadSprite("RES_SAN.RES");
2012-12-19 08:00:22 +01:00
if (_vm->_graphicsManager._lineNbr == SCREEN_WIDTH)
_vm->_saveLoadManager.saveFile("TEMP.SCR", _vm->_graphicsManager._vesaScreen, 307200);
2012-12-19 08:00:22 +01:00
else if (_vm->_graphicsManager._lineNbr == (SCREEN_WIDTH * 2))
_vm->_saveLoadManager.saveFile("TEMP.SCR", _vm->_graphicsManager._vesaScreen, 614400);
2012-12-19 08:00:22 +01:00
if (!_vm->_graphicsManager._lineNbr)
_vm->_graphicsManager._scrollOffset = 0;
_vm->_graphicsManager.NB_SCREEN(true);
_paletteBufferIdx = 20 * (int16)READ_LE_UINT16((uint16 *)_characterBuffer + 42) + 110;
_vm->_graphicsManager.NB_SCREEN(true);
2012-10-29 23:08:23 +01:00
_vm->_objectsManager.PERSO_ON = true;
searchCharacterPalette(_paletteBufferIdx, true);
startCharacterAnim0(_paletteBufferIdx, false);
2013-01-27 01:25:46 +01:00
v11 = _vm->_globals._answerBuffer;
_vm->_globals._answerBuffer = g_PTRNUL;
_vm->_globals.NOMARCHE = true;
_vm->_objectsManager.INILINK(v22);
2012-10-29 23:08:23 +01:00
_vm->_objectsManager.PERSO_ON = true;
_vm->_globals.GOACTION = false;
_vm->_objectsManager._zoneNum = -1;
initCharacterAnim();
VISU_PARLE();
2012-12-27 18:41:52 +01:00
dialogWait();
_vm->_graphicsManager.INI_ECRAN2(v22, true);
_vm->_globals.NOMARCHE = true;
_vm->_objectsManager._forceZoneFl = true;
_vm->_objectsManager._zoneNum = -1;
do {
2012-12-26 21:30:51 +01:00
int mouseButton = _vm->_eventsManager.getMouseButton();
if (mouseButton == 1)
_vm->_objectsManager.handleLeftButton();
2012-12-26 21:30:51 +01:00
else if (mouseButton == 2)
_vm->_objectsManager.handleRightButton();
2012-12-26 21:30:51 +01:00
2012-12-26 07:56:26 +01:00
_vm->_objectsManager.checkZone();
if (_vm->_globals.GOACTION)
_vm->_objectsManager.PARADISE();
_vm->_eventsManager.VBL();
} while (!_vm->_globals._exitId);
2012-12-27 18:41:52 +01:00
dialogEndTalk();
dialogTalk();
clearCharacterAnim();
clearCharacterAnim();
_vm->_globals._introSpeechOffFl = false;
2012-12-19 08:00:22 +01:00
_characterBuffer = _vm->_globals.freeMemory(_characterBuffer);
_characterSprite = _vm->_globals.freeMemory(_characterSprite);
_vm->_graphicsManager.NB_SCREEN(false);
2013-01-11 01:50:29 +01:00
_vm->_linesManager.clearAllZones();
_vm->_linesManager.resetLines();
_vm->_globals.resetCache();
for (int i = 0; i <= 44; i++)
_vm->_globals.BOBZONE[i] = 0;
2013-01-27 01:25:46 +01:00
_vm->_globals.freeMemory(_vm->_globals._answerBuffer);
_vm->_globals._answerBuffer = v11;
_vm->_objectsManager._disableFl = true;
_vm->_objectsManager.INILINK(v20);
_vm->_graphicsManager.INI_ECRAN2(v20, true);
_vm->_objectsManager._disableFl = false;
_vm->_globals.NOMARCHE = false;
if (_vm->_globals._exitId == 101)
_vm->_globals._exitId = 0;
_vm->_saveLoadManager.load("TEMP.SCR", _vm->_graphicsManager._vesaScreen);
g_system->getSavefileManager()->removeSavefile("TEMP.SCR");
2012-10-29 23:08:23 +01:00
_vm->_objectsManager.PERSO_ON = false;
2012-12-11 08:31:07 +01:00
_vm->_eventsManager._mouseCursorId = 4;
_vm->_eventsManager.changeMouseCursor(4);
_vm->_graphicsManager.SETCOLOR3(253, 100, 100, 100);
if (!_vm->getIsDemo())
_vm->_graphicsManager.SETCOLOR3(254, 0, 0, 0);
_vm->_graphicsManager.initColorTable(145, 150, _vm->_graphicsManager._palette);
2013-01-07 08:33:55 +01:00
_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
_vm->_graphicsManager.lockScreen();
_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaScreen, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
_vm->_graphicsManager.unlockScreen();
2013-01-07 08:33:55 +01:00
_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
memcpy(_vm->_graphicsManager._vesaBuffer, _vm->_graphicsManager._vesaScreen, 614399);
_vm->_globals._disableInventFl = false;
_vm->_graphicsManager.DD_VBL();
for (int i = 0; i <= 4; i++)
_vm->_eventsManager.VBL();
2013-01-20 00:56:19 +01:00
_vm->_graphicsManager._scrollStatus = 0;
}
} // End of namespace Hopkins