aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorFlorian Kagerer2009-02-02 23:20:55 +0000
committerFlorian Kagerer2009-02-02 23:20:55 +0000
commit44e6c3c6303556f88dc209c8732d666a3ae5b46f (patch)
treed1c275c0355a25ac42967ce34d853a8814b4c0d4 /engines/kyra
parenteb9ac6648fadf1fa822b9b0b90f6dfa8992dde72 (diff)
downloadscummvm-rg350-44e6c3c6303556f88dc209c8732d666a3ae5b46f.tar.gz
scummvm-rg350-44e6c3c6303556f88dc209c8732d666a3ae5b46f.tar.bz2
scummvm-rg350-44e6c3c6303556f88dc209c8732d666a3ae5b46f.zip
KYRA: cleanup
svn-id: r36207
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/gui.h6
-rw-r--r--engines/kyra/gui_lol.cpp156
-rw-r--r--engines/kyra/gui_lol.h15
-rw-r--r--engines/kyra/lol.cpp19
-rw-r--r--engines/kyra/lol.h3
-rw-r--r--engines/kyra/script_lol.cpp33
-rw-r--r--engines/kyra/script_tim.cpp630
-rw-r--r--engines/kyra/script_tim.h93
-rw-r--r--engines/kyra/sequences_lol.cpp11
-rw-r--r--engines/kyra/text_lol.cpp10
10 files changed, 536 insertions, 440 deletions
diff --git a/engines/kyra/gui.h b/engines/kyra/gui.h
index 1b524b7752..76cc5a5169 100644
--- a/engines/kyra/gui.h
+++ b/engines/kyra/gui.h
@@ -159,12 +159,6 @@ public:
// utilities for thumbnail creation
virtual void createScreenThumbnail(Graphics::Surface &dst) = 0;
- // LOL tim player specific
- virtual void drawDialogueBox(int numStr, const char *s1, const char *s2, const char *s3) {}
- virtual uint16 processDialogue() { return 0; }
- virtual void update() {}
- virtual char *getTableString(int id) { return 0; }
-
protected:
KyraEngine_v1 *_vm;
Screen *_screen;
diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp
index 3e00b32b0d..112bc6396f 100644
--- a/engines/kyra/gui_lol.cpp
+++ b/engines/kyra/gui_lol.cpp
@@ -610,8 +610,6 @@ int LoLEngine::clickedUnk32(Button *button) {
}
GUI_LoL::GUI_LoL(LoLEngine *vm) : GUI(vm), _vm(vm), _screen(vm->_screen) {
- memset(_dialogueButtonString, 0, 3 * sizeof(const char*));
- _dialogueButtonPosX = _dialogueButtonPosY = _dialogueNumButtons = _dialogueButtonXoffs = _dialogueHighlightedButton = 0;
_scrollUpFunctor = BUTTON_FUNCTOR(GUI_LoL, this, &GUI_LoL::scrollUp);
_scrollDownFunctor = BUTTON_FUNCTOR(GUI_LoL, this, &GUI_LoL::scrollDown);
}
@@ -695,159 +693,5 @@ int GUI_LoL::processButtonList(Button *list, uint16 inputFlag, int8 mouseWheel)
return returnValue;
}
-void GUI_LoL::drawDialogueBox(int numStr, const char *s1, const char *s2, const char *s3) {
- if (numStr == 1 && _vm->_speechFlag) {
- _screen->setScreenDim(5);
- _dialogueButtonString[0] = _dialogueButtonString[1] = _dialogueButtonString[2] = 0;
- } else {
- _screen->setScreenDim(5);
- _dialogueNumButtons = numStr;
- _dialogueButtonString[0] = s1;
- _dialogueButtonString[1] = s2;
- _dialogueButtonString[2] = s3;
- _dialogueHighlightedButton = 0;
-
- const ScreenDim *d = _screen->getScreenDim(5);
- _dialogueButtonPosY = d->sy + d->h - 9;
-
- if (numStr == 1) {
- _dialogueButtonXoffs = 0;
- _dialogueButtonPosX = d->sx + d->w - 77;
- } else {
- _dialogueButtonXoffs = d->w / numStr;
- _dialogueButtonPosX = d->sx + (_dialogueButtonXoffs >> 1) - 37;
- }
-
- drawDialogueButtons();
- }
-
- if (!_vm->shouldQuit())
- _vm->removeInputTop();
-}
-
-void GUI_LoL::drawDialogueButtons() {
- int cp = _screen->setCurPage(0);
- Screen::FontId of = _screen->setFont(Screen::FID_6_FNT);
-
- int x = _dialogueButtonPosX;
-
- for (int i = 0; i < _dialogueNumButtons; i++) {
- _vm->gui_drawBox(x, _dialogueButtonPosY, 74, 9, 136, 251, -1);
- _screen->printText(_dialogueButtonString[i], x + 37 - (_screen->getTextWidth(_dialogueButtonString[i])) / 2,
- _dialogueButtonPosY + 2, _dialogueHighlightedButton == i ? 144 : 254, 0);
- x += _dialogueButtonXoffs;
- }
- _screen->setFont(of);
- _screen->setCurPage(cp);
-}
-
-uint16 GUI_LoL::processDialogue() {
- int df = _dialogueHighlightedButton;
- int res = 0;
- int x = _dialogueButtonPosX;
-
- for (int i = 0; i < _dialogueNumButtons; i++) {
- if (_vm->posWithinRect(_vm->_mouseX, _vm->_mouseY, x, _dialogueButtonPosY, x + 74, _dialogueButtonPosY + 9)) {
- _dialogueHighlightedButton = i;
- break;
- }
- x += _dialogueButtonXoffs;
- }
-
- if (_dialogueNumButtons == 0) {
- int e = _vm->checkInput(0, false) & 0xCF;
- _vm->removeInputTop();
-
- if (e == 200) {
- _vm->snd_dialogueSpeechUpdate(1);
- //_dlgTimer = 0;
- }
-
- if (_vm->snd_characterSpeaking() != 2) {
- //if (_dlgTimer < _system->getMillis()) {
- res = 1;
- if (!_vm->shouldQuit())
- _vm->removeInputTop();
- //}
- }
- } else {
- int e = _vm->checkInput(0, false);
- _vm->removeInputTop();
- switch (e) {
- case 100:
- case 101:
- _vm->snd_dialogueSpeechUpdate(1);
- //_dlgTimer = 0;
- res = _dialogueHighlightedButton + 1;
- break;
-
- case 110:
- case 111:
- if (_dialogueNumButtons > 1 && _dialogueHighlightedButton > 0)
- _dialogueHighlightedButton--;
- break;
-
- case 112:
- case 113:
- if (_dialogueNumButtons > 1 && _dialogueHighlightedButton < (_dialogueNumButtons - 1))
- _dialogueHighlightedButton++;
- break;
-
- case 200:
- case 300:
- x = _dialogueButtonPosX;
-
- for (int i = 0; i < _dialogueNumButtons; i++) {
- if (_vm->posWithinRect(_vm->_mouseX, _vm->_mouseY, x, _dialogueButtonPosY, x + 74, _dialogueButtonPosY + 9)) {
- _dialogueHighlightedButton = i;
- res = _dialogueHighlightedButton + 1;
- break;
- }
- x += _dialogueButtonXoffs;
- }
-
- break;
-
- default:
- break;
- }
- }
-
- if (df != _dialogueHighlightedButton)
- drawDialogueButtons();
-
- if (res == 0)
- return 0;
-
- _vm->updatePortraits();
-
- if (!_vm->textEnabled() && _vm->_hideControls) {
- _screen->setScreenDim(5);
- const ScreenDim *d = _screen->getScreenDim(5);
- _screen->hideMouse();
- _screen->fillRect(d->sx, d->sy + d->h - 9, d->sx + d->w - 1, d->sy + d->h - 1, d->unkA);
- _screen->showMouse();
- } else {
- const ScreenDim *d = _screen->_curDim;
- _screen->hideMouse();
- _screen->fillRect(d->sx, d->sy, d->sx + d->w - 2, d->sy + d->h - 1, d->unkA);
- _screen->clearDim(4);
- _screen->setScreenDim(4);
- _screen->showMouse();
- //_screen->setDialogueColumn(8, 0);
- //_screen->setDialogueLine(8, 0);
- }
-
- return res;
-}
-
-char *GUI_LoL::getTableString(int id) {
- return (char *) _vm->getLangString(id);
-}
-
-void GUI_LoL::update() {
- _vm->update();
-}
-
} // end of namespace Kyra
diff --git a/engines/kyra/gui_lol.h b/engines/kyra/gui_lol.h
index 52dde8b6b5..1f4fab6be2 100644
--- a/engines/kyra/gui_lol.h
+++ b/engines/kyra/gui_lol.h
@@ -47,12 +47,6 @@ public:
// utilities for thumbnail creation
void createScreenThumbnail(Graphics::Surface &dst) {}
- // tim player specific
- void drawDialogueBox(int numStr, const char *s1, const char *s2, const char *s3);
- uint16 processDialogue();
- void update();
- char *getTableString(int id);
-
private:
LoLEngine *_vm;
Screen_LoL *_screen;
@@ -77,15 +71,6 @@ private:
const char *getMenuTitle(const Menu &menu) { return 0; }
const char *getMenuItemTitle(const MenuItem &menuItem) { return 0; }
const char *getMenuItemLabel(const MenuItem &menuItem) { return 0; }
-
- void drawDialogueButtons();
-
- const char *_dialogueButtonString[3];
- uint16 _dialogueButtonPosX;
- uint16 _dialogueButtonPosY;
- int _dialogueNumButtons;
- uint16 _dialogueButtonXoffs;
- int _dialogueHighlightedButton;
};
} // end of namespace Kyra
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp
index 0cca35201f..1d3519483a 100644
--- a/engines/kyra/lol.cpp
+++ b/engines/kyra/lol.cpp
@@ -41,6 +41,7 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy
_screen = 0;
_gui = 0;
_dlg = 0;
+ _tim = 0;
switch (_flags.lang) {
case Common::EN_ANY:
@@ -313,7 +314,7 @@ Common::Error LoLEngine::init() {
_gui->initStaticData();
initButtonList();
- _tim = new TIMInterpreter(this, _screen, _system);
+ _tim = new TIMInterpreter_LoL(this, _screen, _system);
assert(_tim);
_dlg = new TextDisplayer_LoL(this, _screen);
@@ -464,6 +465,8 @@ Common::Error LoLEngine::go() {
setupPrologueData(false);
+ _tim = new TIMInterpreter_LoL(this, _screen, _system);
+
if (!shouldQuit() && (processSelection == 0 || processSelection == 3))
startup();
@@ -478,6 +481,11 @@ Common::Error LoLEngine::go() {
runLoop();
}
+ delete _tim;
+ _tim = 0;
+
+ // TODO: outro
+
return Common::kNoError;
}
@@ -669,10 +677,6 @@ void LoLEngine::startup() {
_screen->_dimLineCount = 0;
- // reconfigure TIM player for ingame scripts
- _tim->toggleDialogueSpeech(speechEnabled());
- _tim->toggleRefresh(true);
-
setMouseCursorToItemInHand();
}
@@ -1212,7 +1216,6 @@ bool LoLEngine::snd_playCharacterSpeech(int id, int8 speaker, int) {
} while (_sound->voiceIsPlaying());
strcpy(_activeVoiceFile, *playList.begin());
- _tim->setActiveSpeechFile(_activeVoiceFile);
_sound->voicePlayFromList(playList);
@@ -1220,7 +1223,7 @@ bool LoLEngine::snd_playCharacterSpeech(int id, int8 speaker, int) {
delete []*i;
playList.clear();
- _tim->setDialogueCompleteFlag(0);
+ _tim->_dialogueComplete = 0;
return true;
}
@@ -1241,7 +1244,7 @@ int LoLEngine::snd_dialogueSpeechUpdate(int finish) {
//_dlgTimer = 0;
if (finish)
- _tim->setDialogueCompleteFlag(1);
+ _tim->_dialogueComplete = 1;
return 1;
}
diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h
index 736b2f4894..74d3dd96cb 100644
--- a/engines/kyra/lol.h
+++ b/engines/kyra/lol.h
@@ -223,6 +223,7 @@ struct ButtonDef {
class LoLEngine : public KyraEngine_v1 {
friend class GUI_LoL;
friend class TextDisplayer_LoL;
+friend class TIMInterpreter_LoL;
public:
LoLEngine(OSystem *system, const GameFlags &flags);
~LoLEngine();
@@ -232,6 +233,7 @@ public:
private:
Screen_LoL *_screen;
GUI_LoL *_gui;
+
TIMInterpreter *_tim;
Common::Error init();
@@ -476,7 +478,6 @@ private:
int olol_assignCustomSfx(EMCState *script);
// tim scripts
- TIMInterpreter::Animation *initTimAnimStruct(int index, const char *filename, int x, int y, uint16 copyPara, uint16 wsaFlags);
TIM *_activeTim[10];
// tim opcode
diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp
index 38059f48bc..6486233cd8 100644
--- a/engines/kyra/script_lol.cpp
+++ b/engines/kyra/script_lol.cpp
@@ -384,7 +384,7 @@ int LoLEngine::olol_loadDoorShapes(EMCState *script) {
}
int LoLEngine::olol_initAnimStruct(EMCState *script) {
- if (initTimAnimStruct(stackPos(1), stackPosString(0), stackPos(2), stackPos(3), stackPos(4), stackPos(5)))
+ if (_tim->initAnimStruct(stackPos(1), stackPosString(0), stackPos(2), stackPos(3), stackPos(4), 0, stackPos(5)))
return 1;
return 0;
}
@@ -636,37 +636,6 @@ int LoLEngine::olol_assignCustomSfx(EMCState *script) {
#pragma mark -
-TIMInterpreter::Animation *LoLEngine::initTimAnimStruct(int index, const char *filename, int x, int y, uint16 copyPara, uint16 wsaFlags) {
- TIMInterpreter::Animation *a = _tim->initAnimStructIntern(index, filename, x, y, copyPara, wsaFlags);
-
- _tim->setWsaDrawPage2(0);
-
- if (wsaFlags & 1) {
- if (_screen->_fadeFlag != 1)
- _screen->fadeClearSceneWindow(10);
- memcpy(_screen->getPalette(3) + 384, _screen->_currentPalette + 384, 384);
- } else if (wsaFlags & 2) {
- _screen->fadeToBlack(10);
- }
-
- if (wsaFlags & 7) {
- _screen->hideMouse();
- a->wsa->setDrawPage(0);
- a->wsa->setX(x);
- a->wsa->setY(y);
- a->wsa->displayFrame(0, 0);
- _screen->showMouse();
- }
-
- if (wsaFlags & 3) {
- _screen->loadSpecialColours(_screen->getPalette(3));
- _screen->fadePalette(_screen->getPalette(3), 10);
- _screen->_fadeFlag = 0;
- }
-
- return a;
-}
-
int LoLEngine::tlol_setupPaletteFade(const TIM *tim, const uint16 *param) {
debugC(3, kDebugLevelScriptFuncs, "LoLEngine::t2_playSoundEffect(%p, %p) (%d)", (const void*)tim, (const void*)param, param[0]);
_screen->getFadeParams(_screen->getPalette(0), param[0], _tim->_palDelayInc, _tim->_palDiff);
diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp
index d9d5e186fb..9a08848352 100644
--- a/engines/kyra/script_tim.cpp
+++ b/engines/kyra/script_tim.cpp
@@ -28,17 +28,18 @@
#include "kyra/resource.h"
#include "kyra/sound.h"
#include "kyra/wsamovie.h"
-#include "kyra/gui_lol.h"
+#include "kyra/lol.h"
+#include "kyra/screen_lol.h"
#include "common/endian.h"
namespace Kyra {
-TIMInterpreter::TIMInterpreter(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *system) : _vm(vm), _screen(screen), _system(system), _currentTim(0) {
+TIMInterpreter::TIMInterpreter(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system) : _vm(engine), _screen(screen_v2), _system(system), _currentTim(0) {
#define COMMAND(x) { &TIMInterpreter::x, #x }
#define COMMAND_UNIMPL() { 0, 0 }
#define cmd_return(n) cmd_return_##n
- static const CommandEntry commandProcsHOF[] = {
+ static const CommandEntry commandProcs[] = {
// 0x00
COMMAND(cmd_initFunc0),
COMMAND(cmd_stopCurFunc),
@@ -75,69 +76,26 @@ TIMInterpreter::TIMInterpreter(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *sy
COMMAND(cmd_initFuncNow),
COMMAND(cmd_stopFuncNow),
// 0x1C
- COMMAND(cmd_processDialogue),
- COMMAND(cmd_dialogueBox),
- COMMAND(cmd_return(n1))
- };
-
- static const CommandEntry commandProcsLOL[] = {
- // 0x00
- COMMAND(cmd_initFunc0),
- COMMAND(cmd_stopAllFuncs),
- COMMAND(cmd_initWSA),
- COMMAND(cmd_uninitWSA),
- // 0x04
- COMMAND(cmd_initFunc),
- COMMAND(cmd_stopFunc),
- COMMAND(cmd_wsaDisplayFrame),
- COMMAND_UNIMPL(),
- // 0x08
- COMMAND(cmd_loadVocFile),
- COMMAND(cmd_unloadVocFile),
- COMMAND(cmd_playVocFile),
- COMMAND_UNIMPL(),
- // 0x0C
- COMMAND(cmd_loadSoundFile),
COMMAND(cmd_return(1)),
- COMMAND(cmd_playMusicTrack),
- COMMAND_UNIMPL(),
- // 0x10
- COMMAND(cmd_return(1)),
- COMMAND(cmd_return(1)),
- COMMAND_UNIMPL(),
- COMMAND_UNIMPL(),
- // 0x14
- COMMAND(cmd_setLoopIp),
- COMMAND(cmd_continueLoop),
- COMMAND(cmd_resetLoopIp),
- COMMAND(cmd_resetAllRuntimes),
- // 0x18
COMMAND(cmd_return(1)),
- COMMAND(cmd_execOpcode),
- COMMAND(cmd_initFuncNow),
- COMMAND(cmd_stopFuncNow),
- // 0x1C
- COMMAND(cmd_processDialogue),
- COMMAND(cmd_dialogueBox),
COMMAND(cmd_return(n1))
- };
+ };
#undef cmd_return
+#undef COMMAND_UNIMPL
+#undef COMMAND
- _commands = vm->game() == GI_LOL ? commandProcsLOL : commandProcsHOF ;
- _commandsSize = vm->game() == GI_LOL ? ARRAYSIZE(commandProcsLOL) : ARRAYSIZE(commandProcsHOF);
+ _commands = commandProcs ;
+ _commandsSize = ARRAYSIZE(commandProcs);
memset(&_animations, 0, sizeof(_animations));
_langData = 0;
_textDisplayed = false;
_textAreaBuffer = new uint8[320*40];
assert(_textAreaBuffer);
- _dlgSpeechEnabled = false;
- _refresh = false;
_drawPage2 = 8;
- _palDelayInc = _palDiff = _palDelayAcc = 0;
+ _palDelayInc = _palDiff = _palDelayAcc = 0;
_dialogueComplete = 0;
- _activeVoiceFile = 0;
}
TIMInterpreter::~TIMInterpreter() {
@@ -146,10 +104,10 @@ TIMInterpreter::~TIMInterpreter() {
}
TIM *TIMInterpreter::load(const char *filename, const Common::Array<const TIMOpcode*> *opcodes) {
- if (!_vm->resource()->exists(filename))
+ if (!vm()->resource()->exists(filename))
return 0;
- ScriptFileParser file(filename, _vm->resource());
+ ScriptFileParser file(filename, vm()->resource());
if (!file)
error("Couldn't open TIM file '%s'", filename);
@@ -204,7 +162,7 @@ void TIMInterpreter::unload(TIM *&tim) const {
void TIMInterpreter::setLangData(const char *filename) {
delete[] _langData;
- _langData = _vm->resource()->fileData(filename, 0);
+ _langData = vm()->resource()->fileData(filename, 0);
}
int TIMInterpreter::exec(TIM *tim, bool loop) {
@@ -218,25 +176,16 @@ int TIMInterpreter::exec(TIM *tim, bool loop) {
}
do {
- if (_refresh)
- _vm->gui()->update();
+ update();
+
for (_currentFunc = 0; _currentFunc < TIM::kCountFuncs; ++_currentFunc) {
TIM::Function &cur = _currentTim->func[_currentFunc];
if (_currentTim->procFunc != -1)
execCommand(28, &_currentTim->procParam);
- if (_refresh)
- _vm->gui()->update();
-
- if (_dlgSpeechEnabled && _currentTim->procParam > 1 && cur.loopIp) {
- if (!_vm->sound()->voiceIsPlaying(_activeVoiceFile)) {
- cur.loopIp = 0;
- _currentTim->dlgFunc = _currentFunc;
- advanceToOpcode(21);
- _currentTim->dlgFunc = -1;
- }
- }
+ update();
+ checkSpeechProgress();
bool running = true;
int cnt = 0;
@@ -245,8 +194,7 @@ int TIMInterpreter::exec(TIM *tim, bool loop) {
if (_currentTim->procFunc != -1)
execCommand(28, &_currentTim->procParam);
- if (_refresh)
- _vm->gui()->update();
+ update();
}
int8 opcode = int8(cur.ip[2] & 0xFF);
@@ -278,20 +226,15 @@ int TIMInterpreter::exec(TIM *tim, bool loop) {
if (cur.ip) {
cur.ip += cur.ip[0];
cur.lastTime = cur.nextTime;
- cur.nextTime += (cur.ip[1] ) * _vm->tickLength();
+ cur.nextTime += (cur.ip[1] ) * vm()->tickLength();
}
}
}
- } while (loop && !_vm->shouldQuit());
+ } while (loop && !vm()->shouldQuit());
return _currentTim->clickedButton;
}
-void TIMInterpreter::stopAllFuncs(TIM *tim) {
- for (int i = 0; i < TIM::kCountFuncs; ++i)
- tim->func[i].ip = 0;
-}
-
void TIMInterpreter::refreshTimersAfterPause(uint32 elapsedTime) {
if (!_currentTim)
return;
@@ -308,7 +251,7 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) {
char *text = getTableEntry(textId);
if (_textDisplayed) {
- _screen->copyBlockToPage(0, 0, 160, 320, 40, _textAreaBuffer);
+ screen()->copyBlockToPage(0, 0, 160, 320, 40, _textAreaBuffer);
_textDisplayed = false;
}
@@ -327,7 +270,7 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) {
}
if (filename[0])
- _vm->sound()->voicePlay(filename);
+ vm()->sound()->voicePlay(filename);
if (text[0] == '$')
text = strchr(text + 1, '$') + 1;
@@ -337,13 +280,13 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) {
if (flags < 0) {
static const uint8 colorMap[] = { 0x00, 0xF0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- _screen->setFont(Screen::FID_8_FNT);
- _screen->setTextColorMap(colorMap);
- _screen->_charWidth = -2;
+ screen()->setFont(Screen::FID_8_FNT);
+ screen()->setTextColorMap(colorMap);
+ screen()->_charWidth = -2;
}
- _screen->_charOffset = -4;
- _screen->copyRegionToBuffer(0, 0, 160, 320, 40, _textAreaBuffer);
+ screen()->_charOffset = -4;
+ screen()->copyRegionToBuffer(0, 0, 160, 320, 40, _textAreaBuffer);
_textDisplayed = true;
char backupChar = 0;
@@ -359,14 +302,14 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) {
nextLine[0] = '\0';
}
- int width = _screen->getTextWidth(str);
+ int width = screen()->getTextWidth(str);
if (flags >= 0)
- _screen->printText(str, (320 - width) >> 1, 160 + heightAdd, 0xF0, 0x00);
+ screen()->printText(str, (320 - width) >> 1, 160 + heightAdd, 0xF0, 0x00);
else
- _screen->printText(str, (320 - width) >> 1, 188, 0xF0, 0x00);
+ screen()->printText(str, (320 - width) >> 1, 188, 0xF0, 0x00);
- heightAdd += _screen->getFontHeight();
+ heightAdd += screen()->getFontHeight();
str += strlen(str);
if (backupChar) {
@@ -375,14 +318,14 @@ void TIMInterpreter::displayText(uint16 textId, int16 flags) {
}
}
- _screen->_charOffset = 0;
+ screen()->_charOffset = 0;
if (flags < 0) {
static const uint8 colorMap[] = { 0x00, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00 };
- _screen->setFont(Screen::FID_INTRO_FNT);
- _screen->setTextColorMap(colorMap);
- _screen->_charWidth = 0;
+ screen()->setFont(Screen::FID_INTRO_FNT);
+ screen()->setTextColorMap(colorMap);
+ screen()->_charWidth = 0;
}
}
@@ -397,7 +340,7 @@ void TIMInterpreter::setupTextPalette(uint index, int fadePalette) {
};
for (int i = 0; i < 15; ++i) {
- uint8 *palette = _screen->getPalette(0) + (240 + i) * 3;
+ uint8 *palette = screen()->getPalette(0) + (240 + i) * 3;
uint8 c1 = (((15 - i) << 2) * palTable[index*3+0]) / 100;
uint8 c2 = (((15 - i) << 2) * palTable[index*3+1]) / 100;
@@ -409,13 +352,21 @@ void TIMInterpreter::setupTextPalette(uint index, int fadePalette) {
}
if (!fadePalette && !_palDiff) {
- _screen->setScreenPalette(_screen->getPalette(0));
+ screen()->setScreenPalette(screen()->getPalette(0));
} else {
- _screen->getFadeParams(_screen->getPalette(0), fadePalette, _palDelayInc, _palDiff);
+ screen()->getFadeParams(screen()->getPalette(0), fadePalette, _palDelayInc, _palDiff);
_palDelayAcc = 0;
}
}
+KyraEngine_v1 *TIMInterpreter::vm() {
+ return _vm;
+}
+
+Screen_v2 *TIMInterpreter::screen() {
+ return _screen;
+}
+
TIMInterpreter::Animation *TIMInterpreter::initAnimStruct(int index, const char *filename, int x, int y, int, int offscreenBuffer, uint16 wsaFlags) {
Animation *anim = &_animations[index];
anim->x = x;
@@ -428,11 +379,11 @@ TIMInterpreter::Animation *TIMInterpreter::initAnimStruct(int index, const char
char file[32];
snprintf(file, 32, "%s.WSA", filename);
- if (_vm->resource()->exists(file)) {
+ if (vm()->resource()->exists(file)) {
anim->wsa = new WSAMovie_v2(_vm, _screen);
assert(anim->wsa);
- anim->wsa->open(file, wsaOpenFlags, (index == 1) ? _screen->getPalette(0) : 0);
+ anim->wsa->open(file, wsaOpenFlags, (index == 1) ? screen()->getPalette(0) : 0);
}
if (anim->wsa && anim->wsa->opened()) {
@@ -442,20 +393,20 @@ TIMInterpreter::Animation *TIMInterpreter::initAnimStruct(int index, const char
anim->y = y = 0;
if (wsaFlags & 2) {
- _screen->fadePalette(_screen->getPalette(1), 15, 0);
- _screen->clearPage(8);
- _screen->checkedPageUpdate(8, 4);
- _screen->updateScreen();
+ screen()->fadePalette(screen()->getPalette(1), 15, 0);
+ screen()->clearPage(8);
+ screen()->checkedPageUpdate(8, 4);
+ screen()->updateScreen();
}
if (wsaFlags & 4) {
snprintf(file, 32, "%s.CPS", filename);
- if (_vm->resource()->exists(file)) {
- _screen->loadBitmap(file, 3, 3, _screen->getPalette(0));
- _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 8, Screen::CR_NO_P_CHECK);
- _screen->checkedPageUpdate(8, 4);
- _screen->updateScreen();
+ if (vm()->resource()->exists(file)) {
+ screen()->loadBitmap(file, 3, 3, screen()->getPalette(0));
+ screen()->copyRegion(0, 0, 0, 0, 320, 200, 2, 8, Screen::CR_NO_P_CHECK);
+ screen()->checkedPageUpdate(8, 4);
+ screen()->updateScreen();
}
anim->wsa->setX(x);
@@ -465,50 +416,26 @@ TIMInterpreter::Animation *TIMInterpreter::initAnimStruct(int index, const char
}
if (wsaFlags & 2)
- _screen->fadePalette(_screen->getPalette(0), 30, 0);
+ screen()->fadePalette(screen()->getPalette(0), 30, 0);
} else {
if (wsaFlags & 2) {
- _screen->fadePalette(_screen->getPalette(1), 15, 0);
- _screen->clearPage(8);
- _screen->checkedPageUpdate(8, 4);
- _screen->updateScreen();
+ screen()->fadePalette(screen()->getPalette(1), 15, 0);
+ screen()->clearPage(8);
+ screen()->checkedPageUpdate(8, 4);
+ screen()->updateScreen();
}
snprintf(file, 32, "%s.CPS", filename);
- if (_vm->resource()->exists(file)) {
- _screen->loadBitmap(file, 3, 3, _screen->getPalette(0));
- _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 8, Screen::CR_NO_P_CHECK);
- _screen->checkedPageUpdate(8, 4);
- _screen->updateScreen();
+ if (vm()->resource()->exists(file)) {
+ screen()->loadBitmap(file, 3, 3, screen()->getPalette(0));
+ screen()->copyRegion(0, 0, 0, 0, 320, 200, 2, 8, Screen::CR_NO_P_CHECK);
+ screen()->checkedPageUpdate(8, 4);
+ screen()->updateScreen();
}
if (wsaFlags & 2)
- _screen->fadePalette(_screen->getPalette(0), 30, 0);
- }
-
- return anim;
-}
-
-TIMInterpreter::Animation *TIMInterpreter::initAnimStructIntern(int index, const char *filename, int x, int y, uint16 copyPara, uint16 wsaFlags) {
- Animation *anim = &_animations[index];
- anim->x = x;
- anim->y = y;
- anim->wsaCopyParams = wsaFlags;
-
- uint16 wsaOpenFlags = 0;
- if (wsaFlags & 0x10)
- wsaOpenFlags |= 2;
- if (wsaFlags & 8)
- wsaOpenFlags |= 1;
-
- char file[32];
- snprintf(file, 32, "%s.WSA", filename);
-
- if (_vm->resource()->exists(file)) {
- anim->wsa = new WSAMovie_v2(_vm, _screen);
- assert(anim->wsa);
- anim->wsa->open(file, wsaOpenFlags, _screen->getPalette(3));
+ screen()->fadePalette(screen()->getPalette(0), 30, 0);
}
return anim;
@@ -539,22 +466,6 @@ const char *TIMInterpreter::getCTableEntry(uint idx) const {
return (const char *)(_langData + READ_LE_UINT16(_langData + (idx<<1)));
}
-void TIMInterpreter::advanceToOpcode(int opcode) {
- TIM::Function *f = &_currentTim->func[_currentTim->dlgFunc];
- uint16 len = f->ip[0];
-
- while ((f->ip[2] & 0xFF) != opcode) {
- if ((f->ip[2] & 0xFF) == 1) {
- f->ip[0] = len;
- break;
- }
- len = f->ip[0];
- f->ip += len;
- }
-
- f->nextTime = _system->getMillis();
-}
-
int TIMInterpreter::execCommand(int cmd, const uint16 *param) {
if (cmd < 0 || cmd >= _commandsSize) {
warning("Calling unimplemented TIM command %d from file '%s'", cmd, _currentTim->filename);
@@ -587,6 +498,11 @@ int TIMInterpreter::cmd_stopCurFunc(const uint16 *param) {
return -2;
}
+void TIMInterpreter::stopAllFuncs(TIM *tim) {
+ for (int i = 0; i < TIM::kCountFuncs; ++i)
+ tim->func[i].ip = 0;
+}
+
int TIMInterpreter::cmd_initWSA(const uint16 *param) {
const int index = param[0];
@@ -653,7 +569,7 @@ int TIMInterpreter::cmd_wsaDisplayFrame(const uint16 *param) {
anim.wsa->setDrawPage((anim.wsaCopyParams & 0x4000) != 0 ? 2 : _drawPage2);
anim.wsa->displayFrame(frame, anim.wsaCopyParams & 0xF0FF, 0, 0);
if (!_drawPage2)
- _screen->updateScreen();
+ screen()->updateScreen();
return 1;
}
@@ -683,9 +599,9 @@ int TIMInterpreter::cmd_playVocFile(const uint16 *param) {
const int volume = (param[1] * 255) / 100;
if (index < ARRAYSIZE(_vocFiles) && !_vocFiles[index].empty())
- _vm->sound()->voicePlay(_vocFiles[index].c_str(), volume, true);
+ vm()->sound()->voicePlay(_vocFiles[index].c_str(), volume, true);
else
- _vm->snd_playSoundEffect(index, volume);
+ vm()->snd_playSoundEffect(index, volume);
return 1;
}
@@ -693,27 +609,20 @@ int TIMInterpreter::cmd_playVocFile(const uint16 *param) {
int TIMInterpreter::cmd_loadSoundFile(const uint16 *param) {
const char *file = (const char *)(_currentTim->text + READ_LE_UINT16(_currentTim->text + (param[0]<<1)));
- _vm->sound()->loadSoundFile(file);
- if (_vm->gameFlags().gameID == GI_LOL)
- _vm->sound()->loadSfxFile(file);
+ vm()->sound()->loadSoundFile(file);
+ if (vm()->gameFlags().gameID == GI_LOL)
+ vm()->sound()->loadSfxFile(file);
return 1;
}
int TIMInterpreter::cmd_playMusicTrack(const uint16 *param) {
- _vm->sound()->playTrack(param[0]);
+ vm()->sound()->playTrack(param[0]);
return 1;
}
int TIMInterpreter::cmd_setLoopIp(const uint16 *param) {
- if (_dlgSpeechEnabled) {
- if (_vm->sound()->voiceIsPlaying(_activeVoiceFile))
- _currentTim->func[_currentFunc].loopIp = _currentTim->func[_currentFunc].ip;
- else
- advanceToOpcode(21);
- } else {
- _currentTim->func[_currentFunc].loopIp = _currentTim->func[_currentFunc].ip;
- }
+ _currentTim->func[_currentFunc].loopIp = _currentTim->func[_currentFunc].ip;
return 1;
}
@@ -725,13 +634,11 @@ int TIMInterpreter::cmd_continueLoop(const uint16 *param) {
func.ip = func.loopIp;
- if (!_vm->sound()->voiceIsPlaying(_activeVoiceFile)) {
- uint16 factor = param[0];
- if (factor) {
- const uint32 random = _vm->_rnd.getRandomNumberRng(0, 0x8000);
- uint32 waitTime = (random * factor) / 0x8000;
- func.nextTime += waitTime * _vm->tickLength();
- }
+ uint16 factor = param[0];
+ if (factor) {
+ const uint32 random = vm()->_rnd.getRandomNumberRng(0, 0x8000);
+ uint32 waitTime = (random * factor) / 0x8000;
+ func.nextTime += waitTime * vm()->tickLength();
}
return -2;
@@ -788,9 +695,9 @@ int TIMInterpreter::cmd_stopFuncNow(const uint16 *param) {
}
int TIMInterpreter::cmd_stopAllFuncs(const uint16 *param) {
- while (_currentTim->dlgFunc == -1 && _currentTim->clickedButton == 0 && !_vm->shouldQuit()) {
- _vm->gui()->update();
- _currentTim->clickedButton = _vm->gui()->processDialogue();
+ while (_currentTim->dlgFunc == -1 && _currentTim->clickedButton == 0 && vm()->shouldQuit()) {
+ update();
+ _currentTim->clickedButton = processDialogue();
}
for (int i = 0; i < TIM::kCountFuncs; ++i)
@@ -799,13 +706,358 @@ int TIMInterpreter::cmd_stopAllFuncs(const uint16 *param) {
return -1;
}
-int TIMInterpreter::cmd_processDialogue(const uint16 *param) {
- int res = _vm->gui()->processDialogue();
+// LOL version of the TIM interpreter
+
+TIMInterpreter_LoL::TIMInterpreter_LoL(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system) :
+ TIMInterpreter(engine, screen_v2, system), _vm(engine) {
+ #define COMMAND(x) { &TIMInterpreter_LoL::x, #x }
+ #define COMMAND_UNIMPL() { 0, 0 }
+ #define cmd_return(n) cmd_return_##n
+ static const CommandEntry commandProcs[] = {
+ // 0x00
+ COMMAND(cmd_initFunc0),
+ COMMAND(cmd_stopAllFuncs),
+ COMMAND(cmd_initWSA),
+ COMMAND(cmd_uninitWSA),
+ // 0x04
+ COMMAND(cmd_initFunc),
+ COMMAND(cmd_stopFunc),
+ COMMAND(cmd_wsaDisplayFrame),
+ COMMAND_UNIMPL(),
+ // 0x08
+ COMMAND(cmd_loadVocFile),
+ COMMAND(cmd_unloadVocFile),
+ COMMAND(cmd_playVocFile),
+ COMMAND_UNIMPL(),
+ // 0x0C
+ COMMAND(cmd_loadSoundFile),
+ COMMAND(cmd_return(1)),
+ COMMAND(cmd_playMusicTrack),
+ COMMAND_UNIMPL(),
+ // 0x10
+ COMMAND(cmd_return(1)),
+ COMMAND(cmd_return(1)),
+ COMMAND_UNIMPL(),
+ COMMAND_UNIMPL(),
+ // 0x14
+ COMMAND(cmd_setLoopIp),
+ COMMAND(cmd_continueLoop),
+ COMMAND(cmd_resetLoopIp),
+ COMMAND(cmd_resetAllRuntimes),
+ // 0x18
+ COMMAND(cmd_return(1)),
+ COMMAND(cmd_execOpcode),
+ COMMAND(cmd_initFuncNow),
+ COMMAND(cmd_stopFuncNow),
+ // 0x1C
+ COMMAND(cmd_processDialogue),
+ COMMAND(cmd_dialogueBox),
+ COMMAND(cmd_return(n1))
+ };
+ #undef cmd_return
+ #undef COMMAND_UNIMPL
+ #undef COMMAND
+
+ _commands = commandProcs ;
+ _commandsSize = ARRAYSIZE(commandProcs);
+
+ _screen = engine->_screen;
+
+ _drawPage2 = 0;
+
+ memset(_dialogueButtonString, 0, 3 * sizeof(const char*));
+ _dialogueButtonPosX = _dialogueButtonPosY = _dialogueNumButtons = _dialogueButtonXoffs = _dialogueHighlightedButton = 0;
+}
+
+TIMInterpreter::Animation *TIMInterpreter_LoL::initAnimStruct(int index, const char *filename, int x, int y, int copyPara, int, uint16 wsaFlags) {
+ Animation *anim = &_animations[index];
+ anim->x = x;
+ anim->y = y;
+ anim->wsaCopyParams = wsaFlags;
+
+ uint16 wsaOpenFlags = 0;
+ if (wsaFlags & 0x10)
+ wsaOpenFlags |= 2;
+ if (wsaFlags & 8)
+ wsaOpenFlags |= 1;
+
+ char file[32];
+ snprintf(file, 32, "%s.WSA", filename);
+
+ if (_vm->resource()->exists(file)) {
+ anim->wsa = new WSAMovie_v2(_vm, TIMInterpreter::_screen);
+ assert(anim->wsa);
+ anim->wsa->open(file, wsaOpenFlags, _screen->getPalette(3));
+ }
+
+ if (wsaFlags & 1) {
+ if (_screen->_fadeFlag != 1)
+ _screen->fadeClearSceneWindow(10);
+ memcpy(_screen->getPalette(3) + 384, _screen->_currentPalette + 384, 384);
+ } else if (wsaFlags & 2) {
+ _screen->fadeToBlack(10);
+ }
+
+ if (wsaFlags & 7) {
+ _screen->hideMouse();
+ anim->wsa->setDrawPage(0);
+ anim->wsa->setX(x);
+ anim->wsa->setY(y);
+ anim->wsa->displayFrame(0, 0);
+ _screen->showMouse();
+ }
+
+ if (wsaFlags & 3) {
+ _screen->loadSpecialColours(_screen->getPalette(3));
+ _screen->fadePalette(_screen->getPalette(3), 10);
+ _screen->_fadeFlag = 0;
+ }
+
+ return anim;
+}
+
+KyraEngine_v1 *TIMInterpreter_LoL::vm() {
+ return _vm;
+}
+
+Screen_v2 *TIMInterpreter_LoL::screen() {
+ return _screen;
+}
+
+void TIMInterpreter_LoL::advanceToOpcode(int opcode) {
+ TIM::Function *f = &_currentTim->func[_currentTim->dlgFunc];
+ uint16 len = f->ip[0];
+
+ while ((f->ip[2] & 0xFF) != opcode) {
+ if ((f->ip[2] & 0xFF) == 1) {
+ f->ip[0] = len;
+ break;
+ }
+ len = f->ip[0];
+ f->ip += len;
+ }
+
+ f->nextTime = _system->getMillis();
+}
+
+void TIMInterpreter_LoL::drawDialogueBox(int numStr, const char *s1, const char *s2, const char *s3) {
+ if (numStr == 1 && _vm->_speechFlag) {
+ _screen->setScreenDim(5);
+ _dialogueButtonString[0] = _dialogueButtonString[1] = _dialogueButtonString[2] = 0;
+ } else {
+ _screen->setScreenDim(5);
+ _dialogueNumButtons = numStr;
+ _dialogueButtonString[0] = s1;
+ _dialogueButtonString[1] = s2;
+ _dialogueButtonString[2] = s3;
+ _dialogueHighlightedButton = 0;
+
+ const ScreenDim *d = _screen->getScreenDim(5);
+ _dialogueButtonPosY = d->sy + d->h - 9;
+
+ if (numStr == 1) {
+ _dialogueButtonXoffs = 0;
+ _dialogueButtonPosX = d->sx + d->w - 77;
+ } else {
+ _dialogueButtonXoffs = d->w / numStr;
+ _dialogueButtonPosX = d->sx + (_dialogueButtonXoffs >> 1) - 37;
+ }
+
+ drawDialogueButtons();
+ }
+
+ if (!_vm->shouldQuit())
+ _vm->removeInputTop();
+}
+
+void TIMInterpreter_LoL::drawDialogueButtons() {
+ int cp = _screen->setCurPage(0);
+ Screen::FontId of = _screen->setFont(Screen::FID_6_FNT);
+
+ int x = _dialogueButtonPosX;
+
+ for (int i = 0; i < _dialogueNumButtons; i++) {
+ _vm->gui_drawBox(x, _dialogueButtonPosY, 74, 9, 136, 251, -1);
+ _screen->printText(_dialogueButtonString[i], x + 37 - (_screen->getTextWidth(_dialogueButtonString[i])) / 2,
+ _dialogueButtonPosY + 2, _dialogueHighlightedButton == i ? 144 : 254, 0);
+ x += _dialogueButtonXoffs;
+ }
+ _screen->setFont(of);
+ _screen->setCurPage(cp);
+}
+
+uint16 TIMInterpreter_LoL::processDialogue() {
+ int df = _dialogueHighlightedButton;
+ int res = 0;
+ int x = _dialogueButtonPosX;
+
+ for (int i = 0; i < _dialogueNumButtons; i++) {
+ if (_vm->posWithinRect(_vm->_mouseX, _vm->_mouseY, x, _dialogueButtonPosY, x + 74, _dialogueButtonPosY + 9)) {
+ _dialogueHighlightedButton = i;
+ break;
+ }
+ x += _dialogueButtonXoffs;
+ }
+
+ if (_dialogueNumButtons == 0) {
+ int e = _vm->checkInput(0, false) & 0xCF;
+ _vm->removeInputTop();
+
+ if (e == 200) {
+ _vm->snd_dialogueSpeechUpdate(1);
+ //_dlgTimer = 0;
+ }
+
+ if (_vm->snd_characterSpeaking() != 2) {
+ //if (_dlgTimer < _system->getMillis()) {
+ res = 1;
+ if (!_vm->shouldQuit())
+ _vm->removeInputTop();
+ //}
+ }
+ } else {
+ int e = _vm->checkInput(0, false);
+ _vm->removeInputTop();
+ switch (e) {
+ case 100:
+ case 101:
+ _vm->snd_dialogueSpeechUpdate(1);
+ //_dlgTimer = 0;
+ res = _dialogueHighlightedButton + 1;
+ break;
+
+ case 110:
+ case 111:
+ if (_dialogueNumButtons > 1 && _dialogueHighlightedButton > 0)
+ _dialogueHighlightedButton--;
+ break;
+
+ case 112:
+ case 113:
+ if (_dialogueNumButtons > 1 && _dialogueHighlightedButton < (_dialogueNumButtons - 1))
+ _dialogueHighlightedButton++;
+ break;
+
+ case 200:
+ case 300:
+ x = _dialogueButtonPosX;
+
+ for (int i = 0; i < _dialogueNumButtons; i++) {
+ if (_vm->posWithinRect(_vm->_mouseX, _vm->_mouseY, x, _dialogueButtonPosY, x + 74, _dialogueButtonPosY + 9)) {
+ _dialogueHighlightedButton = i;
+ res = _dialogueHighlightedButton + 1;
+ break;
+ }
+ x += _dialogueButtonXoffs;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (df != _dialogueHighlightedButton)
+ drawDialogueButtons();
+
+ if (res == 0)
+ return 0;
+
+ _vm->updatePortraits();
+
+ if (!_vm->textEnabled() && _vm->_hideControls) {
+ _screen->setScreenDim(5);
+ const ScreenDim *d = _screen->getScreenDim(5);
+ _screen->hideMouse();
+ _screen->fillRect(d->sx, d->sy + d->h - 9, d->sx + d->w - 1, d->sy + d->h - 1, d->unkA);
+ _screen->showMouse();
+ } else {
+ const ScreenDim *d = _screen->_curDim;
+ _screen->hideMouse();
+ _screen->fillRect(d->sx, d->sy, d->sx + d->w - 2, d->sy + d->h - 1, d->unkA);
+ _screen->clearDim(4);
+ _screen->setScreenDim(4);
+ _screen->showMouse();
+ //_screen->setDialogueColumn(8, 0);
+ //_screen->setDialogueLine(8, 0);
+ }
+
+ return res;
+}
+
+void TIMInterpreter_LoL::update() {
+ _vm->update();
+}
+
+void TIMInterpreter_LoL::checkSpeechProgress() {
+ if (_vm->speechEnabled() && _currentTim->procParam > 1 && _currentTim->func[_currentFunc].loopIp) {
+ if (_vm->snd_characterSpeaking() != 2) {
+ _currentTim->func[_currentFunc].loopIp = 0;
+ _currentTim->dlgFunc = _currentFunc;
+ advanceToOpcode(21);
+ _currentTim->dlgFunc = -1;
+ }
+ }
+}
+
+char *TIMInterpreter_LoL::getTableString(int id) {
+ return _vm->getLangString(id);
+}
+
+int TIMInterpreter_LoL::execCommand(int cmd, const uint16 *param) {
+ if (cmd < 0 || cmd >= _commandsSize) {
+ warning("Calling unimplemented TIM command %d from file '%s'", cmd, _currentTim->filename);
+ return 0;
+ }
+
+ if (_commands[cmd].proc == 0) {
+ warning("Calling unimplemented TIM command %d from file '%s'", cmd, _currentTim->filename);
+ return 0;
+ }
+
+ debugC(5, kDebugLevelScript, "TIMInterpreter::%s(%p)", _commands[cmd].desc, (const void* )param);
+ return (this->*_commands[cmd].proc)(param);
+}
+
+int TIMInterpreter_LoL::cmd_setLoopIp(const uint16 *param) {
+ if (_vm->speechEnabled()) {
+ if (_vm->snd_characterSpeaking() == 2)
+ _currentTim->func[_currentFunc].loopIp = _currentTim->func[_currentFunc].ip;
+ else
+ advanceToOpcode(21);
+ } else {
+ _currentTim->func[_currentFunc].loopIp = _currentTim->func[_currentFunc].ip;
+ }
+ return 1;
+}
+
+int TIMInterpreter_LoL::cmd_continueLoop(const uint16 *param) {
+ TIM::Function &func = _currentTim->func[_currentFunc];
+
+ if (!func.loopIp)
+ return -2;
+
+ func.ip = func.loopIp;
+
+ if (_vm->snd_characterSpeaking() != 2) {
+ uint16 factor = param[0];
+ if (factor) {
+ const uint32 random = _vm->_rnd.getRandomNumberRng(0, 0x8000);
+ uint32 waitTime = (random * factor) / 0x8000;
+ func.nextTime += waitTime * _vm->tickLength();
+ }
+ }
+
+ return -2;
+}
+
+int TIMInterpreter_LoL::cmd_processDialogue(const uint16 *param) {
+ int res = processDialogue();
if (!res ||!_currentTim->procParam)
return 0;
- if (_vm->sound()->voiceIsPlaying(_activeVoiceFile))
- _dialogueComplete = 0;
+ _vm->snd_dialogueSpeechUpdate(0);
_currentTim->func[_currentTim->procFunc].loopIp = 0;
_currentTim->dlgFunc = _currentTim->procFunc;
@@ -818,7 +1070,7 @@ int TIMInterpreter::cmd_processDialogue(const uint16 *param) {
return res;
}
-int TIMInterpreter::cmd_dialogueBox(const uint16 *param) {
+int TIMInterpreter_LoL::cmd_dialogueBox(const uint16 *param) {
uint16 func = *param;
assert(func < TIM::kCountFuncs);
_currentTim->procParam = func;
@@ -829,14 +1081,14 @@ int TIMInterpreter::cmd_dialogueBox(const uint16 *param) {
for (int i = 1; i < 4; i++) {
if (param[i] != 0xffff) {
- tmpStr[i-1] = _vm->gui()->getTableString(param[i]);
+ tmpStr[i-1] = getTableString(param[i]);
cnt++;
} else {
tmpStr[i-1] = 0;
}
}
- _vm->gui()->drawDialogueBox(cnt, tmpStr[0], tmpStr[1], tmpStr[2]);
+ drawDialogueBox(cnt, tmpStr[0], tmpStr[1], tmpStr[2]);
return -3;
}
diff --git a/engines/kyra/script_tim.h b/engines/kyra/script_tim.h
index 5e31d40b9b..c595b8c50a 100644
--- a/engines/kyra/script_tim.h
+++ b/engines/kyra/script_tim.h
@@ -89,24 +89,18 @@ public:
uint16 wsaCopyParams;
};
- TIMInterpreter(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *system);
- ~TIMInterpreter();
+ TIMInterpreter(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system);
+ virtual ~TIMInterpreter();
TIM *load(const char *filename, const Common::Array<const TIMOpcode*> *opcodes);
void unload(TIM *&tim) const;
- Animation *initAnimStructIntern(int index, const char *filename, int x, int y, uint16 copyPara, uint16 wsaFlags);
+ virtual Animation *initAnimStruct(int index, const char *filename, int x, int y, int, int offscreenBuffer, uint16 wsaFlags);
int freeAnimStruct(int index);
void setLangData(const char *filename);
void clearLangData() { delete[] _langData; _langData = 0; }
- void toggleDialogueSpeech(bool enable) { _dlgSpeechEnabled = enable; }
- void toggleRefresh(bool enable) { _refresh = enable; }
- void setWsaDrawPage2(int pageNum) { _drawPage2 = pageNum; }
- void setDialogueCompleteFlag(int val) { _dialogueComplete = val; }
- void setActiveSpeechFile(const char *filename) { _activeVoiceFile = filename; }
-
const char *getCTableEntry(uint idx) const;
void resetFinishedFlag() { _finished = false; }
@@ -121,9 +115,15 @@ public:
void displayText(uint16 textId, int16 flags);
void setupTextPalette(uint index, int fadePalette);
+ int _drawPage2;
+
int _palDelayInc, _palDiff, _palDelayAcc;
+ int _dialogueComplete;
-private:
+protected:
+ virtual KyraEngine_v1 *vm();
+ virtual Screen_v2 *screen();
+
KyraEngine_v1 *_vm;
Screen_v2 *_screen;
OSystem *_system;
@@ -135,9 +135,12 @@ private:
Common::String _vocFiles[120];
- Animation *initAnimStruct(int index, const char *filename, int x, int y, int, int offscreenBuffer, uint16 wsaFlags);
Animation _animations[TIM::kWSASlots];
+ virtual void update() {}
+ virtual void checkSpeechProgress() {}
+ virtual uint16 processDialogue() { return 1; }
+
char _audioFilename[32];
uint8 *_langData;
@@ -145,15 +148,7 @@ private:
bool _textDisplayed;
uint8 *_textAreaBuffer;
- bool _dlgSpeechEnabled;
- bool _refresh;
- int _drawPage2;
-
- int _dialogueComplete;
- const char *_activeVoiceFile;
-
- void advanceToOpcode(int del);
- int execCommand(int cmd, const uint16 *param);
+ virtual int execCommand(int cmd, const uint16 *param);
typedef int (TIMInterpreter::*CommandProc)(const uint16 *);
struct CommandEntry {
@@ -177,26 +172,70 @@ private:
int cmd_playVocFile(const uint16 *param);
int cmd_loadSoundFile(const uint16 *param);
int cmd_playMusicTrack(const uint16 *param);
- int cmd_setLoopIp(const uint16 *param);
- int cmd_continueLoop(const uint16 *param);
+ virtual int cmd_setLoopIp(const uint16 *param);
+ virtual int cmd_continueLoop(const uint16 *param);
int cmd_resetLoopIp(const uint16 *param);
int cmd_resetAllRuntimes(const uint16 *param);
int cmd_execOpcode(const uint16 *param);
int cmd_initFuncNow(const uint16 *param);
int cmd_stopFuncNow(const uint16 *param);
-
int cmd_stopAllFuncs(const uint16 *param);
- int cmd_processDialogue(const uint16 *param);
- int cmd_dialogueBox(const uint16 *param);
-
#define cmd_return(n, v) \
int cmd_return_##n(const uint16 *) { return v; }
-
cmd_return( 1, 1);
cmd_return(n1, -1);
#undef cmd_return
};
+class LoLEngine;
+class Screen_LoL;
+class TIMInterpreter_LoL : public TIMInterpreter {
+friend class LoLEngine;
+public:
+ TIMInterpreter_LoL(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system);
+ Animation *initAnimStruct(int index, const char *filename, int x, int y, int copyPara, int, uint16 wsaFlags);
+
+private:
+ KyraEngine_v1 *vm();
+ Screen_v2 *screen();
+
+ void update();
+ void checkSpeechProgress();
+ uint16 processDialogue();
+
+ char *getTableString(int id);
+ void advanceToOpcode(int opcode);
+
+ void drawDialogueBox(int numStr, const char *s1, const char *s2, const char *s3);
+ void drawDialogueButtons();
+
+ LoLEngine *_vm;
+ Screen_LoL *_screen;
+
+ const char *_dialogueButtonString[3];
+ uint16 _dialogueButtonPosX;
+ uint16 _dialogueButtonPosY;
+ int _dialogueNumButtons;
+ uint16 _dialogueButtonXoffs;
+ int _dialogueHighlightedButton;
+
+ virtual int execCommand(int cmd, const uint16 *param);
+
+ typedef int (TIMInterpreter_LoL::*CommandProc)(const uint16 *);
+ struct CommandEntry {
+ CommandProc proc;
+ const char *desc;
+ };
+
+ const CommandEntry *_commands;
+ int _commandsSize;
+
+ int cmd_setLoopIp(const uint16 *param);
+ int cmd_continueLoop(const uint16 *param);
+ int cmd_processDialogue(const uint16 *param);
+ int cmd_dialogueBox(const uint16 *param);
+};
+
} // end of namespace Kyra
#endif
diff --git a/engines/kyra/sequences_lol.cpp b/engines/kyra/sequences_lol.cpp
index e4255e04c4..5ef6ae5f41 100644
--- a/engines/kyra/sequences_lol.cpp
+++ b/engines/kyra/sequences_lol.cpp
@@ -117,13 +117,15 @@ void LoLEngine::setupPrologueData(bool load) {
void LoLEngine::showIntro() {
debugC(9, kDebugLevelMain, "LoLEngine::showIntro()");
+ _tim = new TIMInterpreter(this, _screen, _system);
+
uint8 *pal = _screen->getPalette(0);
memset(pal, 0, 768);
_screen->setScreenPalette(pal);
_screen->clearPage(0);
_screen->clearPage(4);
- _screen->clearPage(8);
+ _screen->clearPage(8);
TIM *intro = _tim->load("LOLINTRO.TIM", &_timIntroOpcodes);
@@ -170,12 +172,16 @@ void LoLEngine::showIntro() {
for (int i = 0; i < TIM::kWSASlots; i++)
_tim->freeAnimStruct(i);
+ delete _tim;
+ _tim = 0;
+
_screen->fadePalette(_screen->getPalette(1), 30, 0);
}
int LoLEngine::chooseCharacter() {
debugC(9, kDebugLevelMain, "LoLEngine::chooseCharacter()");
+ _tim = new TIMInterpreter(this, _screen, _system);
_tim->setLangData("LOLINTRO.DIP");
_screen->loadFont(Screen::FID_9_FNT, "FONT9P.FNT");
@@ -260,6 +266,9 @@ int LoLEngine::chooseCharacter() {
_tim->clearLangData();
+ delete _tim;
+ _tim = 0;
+
return _charSelection;
}
diff --git a/engines/kyra/text_lol.cpp b/engines/kyra/text_lol.cpp
index e1e7dfd756..d5d287a661 100644
--- a/engines/kyra/text_lol.cpp
+++ b/engines/kyra/text_lol.cpp
@@ -40,11 +40,11 @@ TextDisplayer_LoL::TextDisplayer_LoL(LoLEngine *vm, Screen_LoL *screen) : _vm(vm
_out = new char[1024];
memset(_out, 0, 1024);
- _backupBuffer = new byte[40];
- memset(_out, 0, 40);
+ _backupBuffer = new byte[20];
+ memset(_backupBuffer, 0, 20);
_currentLine = new char[85];
- memset(_out, 0, 85);
+ memset(_currentLine, 0, 85);
_pageBuffer1 = new uint8[0xfa00];
_pageBuffer2 = new uint8[0xfa00];
@@ -139,7 +139,7 @@ void TextDisplayer_LoL::setAnimParameters(const char *str, int x, uint8 col1, ui
void TextDisplayer_LoL::play(int dim, char *str, EMCState *script, int16 *paramList, int16 paramIndex) {
memcpy(_curPara, _stringParameters, 15 * sizeof(char*));
- //char *cmds = _curPara[0];
+ //char *cmds = _curPara[0];
if (dim == 3) {
if (_vm->_updateFlags & 2) {
@@ -166,7 +166,7 @@ void TextDisplayer_LoL::play(int dim, char *str, EMCState *script, int16 *paramL
int cp = _screen->setCurPage(0);
Screen::FontId of = _screen->setFont(Screen::FID_9_FNT);
- memset(_backupBuffer, 0, 40);
+ memset(_backupBuffer, 0, 20);
if (preprocessString(str, script, paramList, paramIndex)) {
//vsnprintf(_out, 1024, str, cmds);