diff options
author | Johannes Schickel | 2007-07-29 16:31:29 +0000 |
---|---|---|
committer | Johannes Schickel | 2007-07-29 16:31:29 +0000 |
commit | 076d6b1bc1c4f62732ff46a0931c6bc28ef9a08f (patch) | |
tree | 830715c57e5786762b2794071c6e5431c008e4c4 /engines | |
parent | b01232f08ad34ac16e36a83e32ca741fc8fc2169 (diff) | |
download | scummvm-rg350-076d6b1bc1c4f62732ff46a0931c6bc28ef9a08f.tar.gz scummvm-rg350-076d6b1bc1c4f62732ff46a0931c6bc28ef9a08f.tar.bz2 scummvm-rg350-076d6b1bc1c4f62732ff46a0931c6bc28ef9a08f.zip |
Restructure Kyrandia sourcecode (part 2, compiling works again)
svn-id: r28296
Diffstat (limited to 'engines')
36 files changed, 3237 insertions, 2883 deletions
diff --git a/engines/kyra/animator_v1.cpp b/engines/kyra/animator_v1.cpp index 7683bb6417..4169b59a36 100644 --- a/engines/kyra/animator_v1.cpp +++ b/engines/kyra/animator_v1.cpp @@ -26,15 +26,15 @@ #include "common/stdafx.h" #include "common/endian.h" -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/screen.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/sprites.h" #include "common/system.h" namespace Kyra { -ScreenAnimator::ScreenAnimator(KyraEngine *vm, OSystem *system) { +ScreenAnimator::ScreenAnimator(KyraEngine_v1 *vm, OSystem *system) { _vm = vm; _screen = vm->screen(); _initOk = false; diff --git a/engines/kyra/animator_v1.h b/engines/kyra/animator_v1.h index e817be86d5..8b554adf12 100644 --- a/engines/kyra/animator_v1.h +++ b/engines/kyra/animator_v1.h @@ -27,7 +27,7 @@ #define KYRA_ANIMATOR_H namespace Kyra { -class KyraEngine; +class KyraEngine_v1; class Screen; struct AnimObject { @@ -53,7 +53,7 @@ struct AnimObject { class ScreenAnimator { public: - ScreenAnimator(KyraEngine *vm, OSystem *system); + ScreenAnimator(KyraEngine_v1 *vm, OSystem *system); virtual ~ScreenAnimator(); operator bool() const { return _initOk; } @@ -101,7 +101,7 @@ public: int _brandonScaleY; protected: - KyraEngine *_vm; + KyraEngine_v1 *_vm; Screen *_screen; OSystem *_system; bool _initOk; diff --git a/engines/kyra/debugger.cpp b/engines/kyra/debugger.cpp index d5909bd8b0..0a1974c3f4 100644 --- a/engines/kyra/debugger.cpp +++ b/engines/kyra/debugger.cpp @@ -27,35 +27,35 @@ #include "common/config-manager.h" #include "common/system.h" #include "kyra/debugger.h" -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/screen.h" namespace Kyra { -Debugger::Debugger(KyraEngine *vm) - : GUI::Debugger() { +Debugger_v1::Debugger_v1(KyraEngine_v1 *vm) + : Debugger(vm) { _vm = vm; - DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit)); - DCmd_Register("enter", WRAP_METHOD(Debugger, cmd_enterRoom)); - DCmd_Register("rooms", WRAP_METHOD(Debugger, cmd_listRooms)); - DCmd_Register("flags", WRAP_METHOD(Debugger, cmd_listFlags)); - DCmd_Register("toggleflag", WRAP_METHOD(Debugger, cmd_toggleFlag)); - DCmd_Register("queryflag", WRAP_METHOD(Debugger, cmd_queryFlag)); - DCmd_Register("timers", WRAP_METHOD(Debugger, cmd_listTimers)); - DCmd_Register("settimercountdown", WRAP_METHOD(Debugger, cmd_setTimerCountdown)); - DCmd_Register("give", WRAP_METHOD(Debugger, cmd_giveItem)); + DCmd_Register("continue", WRAP_METHOD(Debugger_v1, Cmd_Exit)); + DCmd_Register("enter", WRAP_METHOD(Debugger_v1, cmd_enterRoom)); + DCmd_Register("rooms", WRAP_METHOD(Debugger_v1, cmd_listRooms)); + DCmd_Register("flags", WRAP_METHOD(Debugger_v1, cmd_listFlags)); + DCmd_Register("toggleflag", WRAP_METHOD(Debugger_v1, cmd_toggleFlag)); + DCmd_Register("queryflag", WRAP_METHOD(Debugger_v1, cmd_queryFlag)); + DCmd_Register("timers", WRAP_METHOD(Debugger_v1, cmd_listTimers)); + DCmd_Register("settimercountdown", WRAP_METHOD(Debugger_v1, cmd_setTimerCountdown)); + DCmd_Register("give", WRAP_METHOD(Debugger_v1, cmd_giveItem)); } -void Debugger::preEnter() { +void Debugger_v1::preEnter() { //_vm->midi.pause(1); } -void Debugger::postEnter() { +void Debugger_v1::postEnter() { //_vm->midi.pause(0); } -bool Debugger::cmd_enterRoom(int argc, const char **argv) { +bool Debugger_v1::cmd_enterRoom(int argc, const char **argv) { uint direction = 0; if (argc > 1) { int room = atoi(argv[1]); @@ -93,7 +93,7 @@ bool Debugger::cmd_enterRoom(int argc, const char **argv) { return true; } -bool Debugger::cmd_listRooms(int argc, const char **argv) { +bool Debugger_v1::cmd_listRooms(int argc, const char **argv) { for (int i = 0; i < _vm->_roomTableSize; i++) { DebugPrintf("%-3i: %-10s", i, _vm->_roomFilenameTable[_vm->_roomTable[i].nameIndex]); if (!(i % 8)) @@ -104,7 +104,7 @@ bool Debugger::cmd_listRooms(int argc, const char **argv) { return true; } -bool Debugger::cmd_listFlags(int argc, const char **argv) { +bool Debugger_v1::cmd_listFlags(int argc, const char **argv) { for (int i = 0; i < (int)sizeof(_vm->_flagsTable)*8; i++) { DebugPrintf("(%-3i): %-5i", i, _vm->queryGameFlag(i)); if (!(i % 10)) @@ -114,7 +114,7 @@ bool Debugger::cmd_listFlags(int argc, const char **argv) { return true; } -bool Debugger::cmd_toggleFlag(int argc, const char **argv) { +bool Debugger_v1::cmd_toggleFlag(int argc, const char **argv) { if (argc > 1) { uint flag = atoi(argv[1]); if (_vm->queryGameFlag(flag)) @@ -129,7 +129,7 @@ bool Debugger::cmd_toggleFlag(int argc, const char **argv) { return true; } -bool Debugger::cmd_queryFlag(int argc, const char **argv) { +bool Debugger_v1::cmd_queryFlag(int argc, const char **argv) { if (argc > 1) { uint flag = atoi(argv[1]); DebugPrintf("Flag %i is %i\n", flag, _vm->queryGameFlag(flag)); @@ -140,14 +140,14 @@ bool Debugger::cmd_queryFlag(int argc, const char **argv) { return true; } -bool Debugger::cmd_listTimers(int argc, const char **argv) { +bool Debugger_v1::cmd_listTimers(int argc, const char **argv) { for (int i = 0; i < ARRAYSIZE(_vm->_timers); i++) DebugPrintf("Timer %-2i: Active: %-3s Countdown: %-6i\n", i, _vm->_timers[i].active ? "Yes" : "No", _vm->_timers[i].countdown); return true; } -bool Debugger::cmd_setTimerCountdown(int argc, const char **argv) { +bool Debugger_v1::cmd_setTimerCountdown(int argc, const char **argv) { if (argc > 2) { uint timer = atoi(argv[1]); uint countdown = atoi(argv[2]); @@ -160,7 +160,7 @@ bool Debugger::cmd_setTimerCountdown(int argc, const char **argv) { return true; } -bool Debugger::cmd_giveItem(int argc, const char **argv) { +bool Debugger_v1::cmd_giveItem(int argc, const char **argv) { if (argc == 2) { int item = atoi(argv[1]); diff --git a/engines/kyra/debugger.h b/engines/kyra/debugger.h index 2d0e82c220..16b1e42a58 100644 --- a/engines/kyra/debugger.h +++ b/engines/kyra/debugger.h @@ -31,14 +31,21 @@ namespace Kyra { class KyraEngine; +class KyraEngine_v1; class Debugger : public GUI::Debugger { public: - Debugger(KyraEngine *vm); + Debugger(KyraEngine *vm) {} virtual ~Debugger() {} // we need this for __SYMBIAN32__ archaic gcc/UIQ +}; + +class Debugger_v1 : public Debugger { +public: + Debugger_v1(KyraEngine_v1 *vm); + virtual ~Debugger_v1() {} // we need this for __SYMBIAN32__ archaic gcc/UIQ protected: - KyraEngine *_vm; + KyraEngine_v1 *_vm; virtual void preEnter(); virtual void postEnter(); diff --git a/engines/kyra/gui_v1.cpp b/engines/kyra/gui_v1.cpp index fe051dd75c..2452185c24 100644 --- a/engines/kyra/gui_v1.cpp +++ b/engines/kyra/gui_v1.cpp @@ -23,11 +23,11 @@ * */ -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/screen.h" #include "kyra/script.h" #include "kyra/text.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/sound.h" #include "common/config-manager.h" @@ -37,14 +37,14 @@ namespace Kyra { -void KyraEngine::registerDefaultSettings() { +void KyraEngine_v1::registerDefaultSettings() { // Most settings already have sensible defaults. This one, however, is // specific to the Kyra engine. ConfMan.registerDefault("walkspeed", 2); ConfMan.registerDefault("cdaudio", _flags.platform == Common::kPlatformFMTowns); } -void KyraEngine::readSettings() { +void KyraEngine_v1::readSettings() { int talkspeed = ConfMan.getInt("talkspeed"); // The default talk speed is 60. This should be mapped to "Normal". @@ -78,7 +78,7 @@ void KyraEngine::readSettings() { setWalkspeed(_configWalkspeed); } -void KyraEngine::writeSettings() { +void KyraEngine_v1::writeSettings() { bool speechMute, subtitles; int talkspeed; @@ -130,14 +130,14 @@ void KyraEngine::writeSettings() { ConfMan.flushToDisk(); } -void KyraEngine::initMainButtonList() { +void KyraEngine_v1::initMainButtonList() { _haveScrollButtons = false; _buttonList = &_buttonData[0]; for (int i = 0; _buttonDataListPtr[i]; ++i) _buttonList = initButton(_buttonList, _buttonDataListPtr[i]); } -Button *KyraEngine::initButton(Button *list, Button *newButton) { +Button *KyraEngine_v1::initButton(Button *list, Button *newButton) { if (!newButton) return list; if (!list) @@ -154,7 +154,7 @@ Button *KyraEngine::initButton(Button *list, Button *newButton) { return list; } -int KyraEngine::buttonInventoryCallback(Button *caller) { +int KyraEngine_v1::buttonInventoryCallback(Button *caller) { int itemOffset = caller->specialValue - 2; uint8 inventoryItem = _currentCharacter->inventoryItems[itemOffset]; if (_itemInHand == -1) { @@ -198,7 +198,7 @@ int KyraEngine::buttonInventoryCallback(Button *caller) { return 0; } -int KyraEngine::buttonAmuletCallback(Button *caller) { +int KyraEngine_v1::buttonAmuletCallback(Button *caller) { if (!(_deathHandler & 8)) return 1; int jewel = caller->specialValue - 0x14; @@ -294,7 +294,7 @@ int KyraEngine::buttonAmuletCallback(Button *caller) { return 1; } -void KyraEngine::processButtonList(Button *list) { +void KyraEngine_v1::processButtonList(Button *list) { if (_haveScrollButtons) { if (_mouseWheel < 0) gui_scrollUp(&_scrollUpButton); @@ -367,7 +367,7 @@ void KyraEngine::processButtonList(Button *list) { } } -void KyraEngine::processButton(Button *button) { +void KyraEngine_v1::processButton(Button *button) { if (!button) return; @@ -411,7 +411,7 @@ void KyraEngine::processButton(Button *button) { (this->*callback)(button); } -void KyraEngine::processAllMenuButtons() { +void KyraEngine_v1::processAllMenuButtons() { if (!_menuButtonList) return; @@ -425,7 +425,7 @@ void KyraEngine::processAllMenuButtons() { return; } -void KyraEngine::processMenuButton(Button *button) { +void KyraEngine_v1::processMenuButton(Button *button) { if (!_displayMenu) return; @@ -449,7 +449,7 @@ void KyraEngine::processMenuButton(Button *button) { processButton(button); } -int KyraEngine::drawBoxCallback(Button *button) { +int KyraEngine_v1::drawBoxCallback(Button *button) { if (!_displayMenu) return 0; @@ -460,7 +460,7 @@ int KyraEngine::drawBoxCallback(Button *button) { return 0; } -int KyraEngine::drawShadedBoxCallback(Button *button) { +int KyraEngine_v1::drawShadedBoxCallback(Button *button) { if (!_displayMenu) return 0; @@ -471,7 +471,7 @@ int KyraEngine::drawShadedBoxCallback(Button *button) { return 0; } -void KyraEngine::setGUILabels() { +void KyraEngine_v1::setGUILabels() { int offset = 0; int offsetOptions = 0; int offsetMainMenu = 0; @@ -561,7 +561,7 @@ void KyraEngine::setGUILabels() { _onCDString = _guiStrings[21]; } -int KyraEngine::buttonMenuCallback(Button *caller) { +int KyraEngine_v1::buttonMenuCallback(Button *caller) { _displayMenu = true; assert(_guiStrings); @@ -584,9 +584,9 @@ int KyraEngine::buttonMenuCallback(Button *caller) { _screen->setPaletteIndex(0xFE, 60, 60, 0); for (int i = 0; i < 6; i++) { _menuButtonData[i].process0 = _menuButtonData[i].process1 = _menuButtonData[i].process2 = 4; - _menuButtonData[i].process0PtrCallback = &KyraEngine::drawShadedBoxCallback; - _menuButtonData[i].process1PtrCallback = &KyraEngine::drawBoxCallback; - _menuButtonData[i].process2PtrCallback = &KyraEngine::drawShadedBoxCallback; + _menuButtonData[i].process0PtrCallback = &KyraEngine_v1::drawShadedBoxCallback; + _menuButtonData[i].process1PtrCallback = &KyraEngine_v1::drawBoxCallback; + _menuButtonData[i].process2PtrCallback = &KyraEngine_v1::drawShadedBoxCallback; } _screen->savePageToDisk("SEENPAGE.TMP", 0); @@ -627,7 +627,7 @@ int KyraEngine::buttonMenuCallback(Button *caller) { return 0; } -void KyraEngine::initMenu(Menu &menu) { +void KyraEngine_v1::initMenu(Menu &menu) { _menuButtonList = 0; _screen->hideMouse(); @@ -707,14 +707,14 @@ void KyraEngine::initMenu(Menu &menu) { _scrollUpButton.x = menu.scrollUpBtnX + menu.x; _scrollUpButton.y = menu.scrollUpBtnY + menu.y; - _scrollUpButton.buttonCallback = &KyraEngine::gui_scrollUp; + _scrollUpButton.buttonCallback = &KyraEngine_v1::gui_scrollUp; _scrollUpButton.nextButton = 0; _menuButtonList = initButton(_menuButtonList, &_scrollUpButton); processMenuButton(&_scrollUpButton); _scrollDownButton.x = menu.scrollDownBtnX + menu.x; _scrollDownButton.y = menu.scrollDownBtnY + menu.y; - _scrollDownButton.buttonCallback = &KyraEngine::gui_scrollDown; + _scrollDownButton.buttonCallback = &KyraEngine_v1::gui_scrollDown; _scrollDownButton.nextButton = 0; _menuButtonList = initButton(_menuButtonList, &_scrollDownButton); processMenuButton(&_scrollDownButton); @@ -726,7 +726,7 @@ void KyraEngine::initMenu(Menu &menu) { _screen->updateScreen(); } -void KyraEngine::calcCoords(Menu &menu) { +void KyraEngine_v1::calcCoords(Menu &menu) { assert(menu.nrOfItems < 7); int widthBackup = _screen->_charWidth; @@ -798,7 +798,7 @@ void KyraEngine::calcCoords(Menu &menu) { _screen->_charWidth = widthBackup; } -void KyraEngine::gui_getInput() { +void KyraEngine_v1::gui_getInput() { Common::Event event; static uint32 lastScreenUpdate = 0; uint32 now = _system->getMillis(); @@ -841,22 +841,22 @@ void KyraEngine::gui_getInput() { _system->delayMillis(3); } -int KyraEngine::gui_resumeGame(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_resumeGame()"); +int KyraEngine_v1::gui_resumeGame(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_resumeGame()"); processMenuButton(button); _displayMenu = false; return 0; } -const char *KyraEngine::getSavegameFilename(int num) { +const char *KyraEngine_v1::getSavegameFilename(int num) { static char saveLoadSlot[12]; sprintf(saveLoadSlot, "%s.%.3d", _targetName.c_str(), num); return saveLoadSlot; } -int KyraEngine::getNextSavegameSlot() { +int KyraEngine_v1::getNextSavegameSlot() { Common::InSaveFile *in; for (int i = 1; i < 1000; i++) { @@ -869,7 +869,7 @@ int KyraEngine::getNextSavegameSlot() { return 0; } -void KyraEngine::setupSavegames(Menu &menu, int num) { +void KyraEngine_v1::setupSavegames(Menu &menu, int num) { Common::InSaveFile *in; static char savenames[5][31]; uint8 startSlot; @@ -900,8 +900,8 @@ void KyraEngine::setupSavegames(Menu &menu, int num) { } } -int KyraEngine::gui_saveGameMenu(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_saveGameMenu()"); +int KyraEngine_v1::gui_saveGameMenu(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_saveGameMenu()"); processMenuButton(button); _menu[2].item[5].enabled = true; @@ -911,7 +911,7 @@ int KyraEngine::gui_saveGameMenu(Button *button) { _menu[2].menuName = _guiStrings[8]; // Select a position to save to: _specialSavegameString = _guiStrings[9]; // [ EMPTY SLOT ] for (int i = 0; i < 5; i++) - _menu[2].item[i].callback = &KyraEngine::gui_saveGame; + _menu[2].item[i].callback = &KyraEngine_v1::gui_saveGame; _savegameOffset = 0; setupSavegames(_menu[2], 5); @@ -940,8 +940,8 @@ int KyraEngine::gui_saveGameMenu(Button *button) { return 0; } -int KyraEngine::gui_loadGameMenu(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_loadGameMenu()"); +int KyraEngine_v1::gui_loadGameMenu(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_loadGameMenu()"); if (_menuDirectlyToLoad) { _menu[2].item[5].enabled = false; } else { @@ -955,7 +955,7 @@ int KyraEngine::gui_loadGameMenu(Button *button) { _specialSavegameString = _newGameString[0]; //[ START A NEW GAME ] _menu[2].menuName = _guiStrings[7]; // Which game would you like to reload? for (int i = 0; i < 5; i++) - _menu[2].item[i].callback = &KyraEngine::gui_loadGame; + _menu[2].item[i].callback = &KyraEngine_v1::gui_loadGame; _savegameOffset = 0; setupSavegames(_menu[2], 5); @@ -987,7 +987,7 @@ int KyraEngine::gui_loadGameMenu(Button *button) { return 0; } -void KyraEngine::gui_redrawTextfield() { +void KyraEngine_v1::gui_redrawTextfield() { _screen->fillRect(38, 91, 287, 102, 250); _text->printText(_savegameName, 38, 92, 253, 0, 0); @@ -999,7 +999,7 @@ void KyraEngine::gui_redrawTextfield() { _screen->updateScreen(); } -void KyraEngine::gui_updateSavegameString() { +void KyraEngine_v1::gui_updateSavegameString() { int length; if (_keyPressed.keycode) { @@ -1026,8 +1026,8 @@ void KyraEngine::gui_updateSavegameString() { _keyPressed.reset(); } -int KyraEngine::gui_saveGame(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_saveGame()"); +int KyraEngine_v1::gui_saveGame(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_saveGame()"); processMenuButton(button); _gameToLoad = button->specialValue; @@ -1074,16 +1074,16 @@ int KyraEngine::gui_saveGame(Button *button) { return 0; } -int KyraEngine::gui_savegameConfirm(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_savegameConfirm()"); +int KyraEngine_v1::gui_savegameConfirm(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_savegameConfirm()"); processMenuButton(button); _displaySubMenu = false; return 0; } -int KyraEngine::gui_loadGame(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_loadGame()"); +int KyraEngine_v1::gui_loadGame(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_loadGame()"); processMenuButton(button); _displaySubMenu = false; _gameToLoad = button->specialValue; @@ -1091,8 +1091,8 @@ int KyraEngine::gui_loadGame(Button *button) { return 0; } -int KyraEngine::gui_cancelSubMenu(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_cancelLoadGameMenu()"); +int KyraEngine_v1::gui_cancelSubMenu(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_cancelLoadGameMenu()"); processMenuButton(button); _displaySubMenu = false; _cancelSubMenu = true; @@ -1100,8 +1100,8 @@ int KyraEngine::gui_cancelSubMenu(Button *button) { return 0; } -int KyraEngine::gui_quitPlaying(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_quitPlaying()"); +int KyraEngine_v1::gui_quitPlaying(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_quitPlaying()"); processMenuButton(button); if (gui_quitConfirm(_guiStrings[14])) { // Are you sure you want to quit playing? @@ -1114,8 +1114,8 @@ int KyraEngine::gui_quitPlaying(Button *button) { return 0; } -bool KyraEngine::gui_quitConfirm(const char *str) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_quitConfirm()"); +bool KyraEngine_v1::gui_quitConfirm(const char *str) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_quitConfirm()"); _screen->loadPageFromDisk("SEENPAGE.TMP", 0); _screen->savePageToDisk("SEENPAGE.TMP", 0); @@ -1139,8 +1139,8 @@ bool KyraEngine::gui_quitConfirm(const char *str) { return !_cancelSubMenu; } -int KyraEngine::gui_quitConfirmYes(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_quitConfirmYes()"); +int KyraEngine_v1::gui_quitConfirmYes(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_quitConfirmYes()"); processMenuButton(button); _displaySubMenu = false; _cancelSubMenu = false; @@ -1148,8 +1148,8 @@ int KyraEngine::gui_quitConfirmYes(Button *button) { return 0; } -int KyraEngine::gui_quitConfirmNo(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_quitConfirmNo()"); +int KyraEngine_v1::gui_quitConfirmNo(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_quitConfirmNo()"); processMenuButton(button); _displaySubMenu = false; _cancelSubMenu = true; @@ -1157,8 +1157,8 @@ int KyraEngine::gui_quitConfirmNo(Button *button) { return 0; } -int KyraEngine::gui_gameControlsMenu(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_gameControlsMenu()"); +int KyraEngine_v1::gui_gameControlsMenu(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_gameControlsMenu()"); readSettings(); @@ -1175,14 +1175,14 @@ int KyraEngine::gui_gameControlsMenu(Button *button) { } _menu[5].item[3].labelString = _voiceTextString; //"Voice / Text " - _menu[5].item[3].callback = &KyraEngine::gui_controlsChangeVoice; + _menu[5].item[3].callback = &KyraEngine_v1::gui_controlsChangeVoice; } else { //_menu[5].height = 136; //_menu[5].item[5].y = 110; _menu[5].item[4].enabled = 0; _menu[5].item[3].labelString = _textSpeedString; // "Text speed " - _menu[5].item[3].callback = &KyraEngine::gui_controlsChangeText; + _menu[5].item[3].callback = &KyraEngine_v1::gui_controlsChangeText; } gui_setupControls(_menu[5]); @@ -1208,8 +1208,8 @@ int KyraEngine::gui_gameControlsMenu(Button *button) { return 0; } -void KyraEngine::gui_setupControls(Menu &menu) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_setupControls()"); +void KyraEngine_v1::gui_setupControls(Menu &menu) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_setupControls()"); switch (_configMusic) { case 0: @@ -1299,8 +1299,8 @@ void KyraEngine::gui_setupControls(Menu &menu) { initMenu(menu); } -int KyraEngine::gui_controlsChangeMusic(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsChangeMusic()"); +int KyraEngine_v1::gui_controlsChangeMusic(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsChangeMusic()"); processMenuButton(button); _configMusic = ++_configMusic % (_flags.platform == Common::kPlatformFMTowns ? 3 : 2); @@ -1308,8 +1308,8 @@ int KyraEngine::gui_controlsChangeMusic(Button *button) { return 0; } -int KyraEngine::gui_controlsChangeSounds(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsChangeSounds()"); +int KyraEngine_v1::gui_controlsChangeSounds(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsChangeSounds()"); processMenuButton(button); _configSounds = !_configSounds; @@ -1317,8 +1317,8 @@ int KyraEngine::gui_controlsChangeSounds(Button *button) { return 0; } -int KyraEngine::gui_controlsChangeWalk(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsChangeWalk()"); +int KyraEngine_v1::gui_controlsChangeWalk(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsChangeWalk()"); processMenuButton(button); _configWalkspeed = ++_configWalkspeed % 5; @@ -1327,8 +1327,8 @@ int KyraEngine::gui_controlsChangeWalk(Button *button) { return 0; } -int KyraEngine::gui_controlsChangeText(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsChangeText()"); +int KyraEngine_v1::gui_controlsChangeText(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsChangeText()"); processMenuButton(button); _configTextspeed = ++_configTextspeed % 4; @@ -1336,8 +1336,8 @@ int KyraEngine::gui_controlsChangeText(Button *button) { return 0; } -int KyraEngine::gui_controlsChangeVoice(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsChangeVoice()"); +int KyraEngine_v1::gui_controlsChangeVoice(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsChangeVoice()"); processMenuButton(button); _configVoice = ++_configVoice % 3; @@ -1345,14 +1345,14 @@ int KyraEngine::gui_controlsChangeVoice(Button *button) { return 0; } -int KyraEngine::gui_controlsApply(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_controlsApply()"); +int KyraEngine_v1::gui_controlsApply(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_controlsApply()"); writeSettings(); return gui_cancelSubMenu(button); } -int KyraEngine::gui_scrollUp(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_scrollUp()"); +int KyraEngine_v1::gui_scrollUp(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_scrollUp()"); processMenuButton(button); if (_savegameOffset > 0) { @@ -1363,8 +1363,8 @@ int KyraEngine::gui_scrollUp(Button *button) { return 0; } -int KyraEngine::gui_scrollDown(Button *button) { - debugC(9, kDebugLevelGUI, "KyraEngine::gui_scrollDown()"); +int KyraEngine_v1::gui_scrollDown(Button *button) { + debugC(9, kDebugLevelGUI, "KyraEngine_v1::gui_scrollDown()"); processMenuButton(button); _savegameOffset++; @@ -1374,7 +1374,7 @@ int KyraEngine::gui_scrollDown(Button *button) { return 0; } -void KyraEngine::gui_processHighlights(Menu &menu) { +void KyraEngine_v1::gui_processHighlights(Menu &menu) { int x1, y1, x2, y2; Common::Point mouse = getMousePos(); @@ -1403,7 +1403,7 @@ void KyraEngine::gui_processHighlights(Menu &menu) { } } -void KyraEngine::gui_redrawText(Menu menu) { +void KyraEngine_v1::gui_redrawText(Menu menu) { int textX; int i = menu.highlightedItem; @@ -1422,7 +1422,7 @@ void KyraEngine::gui_redrawText(Menu menu) { _text->printText(menu.item[i].itemString, textX, textY, menu.item[i].textColor, 0, 0); } -void KyraEngine::gui_redrawHighlight(Menu menu) { +void KyraEngine_v1::gui_redrawHighlight(Menu menu) { int textX; int i = menu.highlightedItem; @@ -1441,7 +1441,7 @@ void KyraEngine::gui_redrawHighlight(Menu menu) { _text->printText(menu.item[i].itemString, textX, textY, menu.item[i].highlightColor, 0, 0); } -void KyraEngine::gui_fadePalette() { +void KyraEngine_v1::gui_fadePalette() { if (_flags.platform == Common::kPlatformAmiga) return; @@ -1461,7 +1461,7 @@ void KyraEngine::gui_fadePalette() { _screen->fadePalette(_screen->_currentPalette, 2); } -void KyraEngine::gui_restorePalette() { +void KyraEngine_v1::gui_restorePalette() { if (_flags.platform == Common::kPlatformAmiga) return; @@ -1469,172 +1469,5 @@ void KyraEngine::gui_restorePalette() { _screen->fadePalette(_screen->_currentPalette, 2); } -#pragma mark - - -// Kyra 2 and 3 main menu - -void KyraEngine::gui_updateMainMenuAnimation() { - _screen->updateScreen(); -} - -bool KyraEngine::gui_mainMenuGetInput() { - Common::Event event; - - while (_eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_QUIT: - quitGame(); - break; - case Common::EVENT_LBUTTONUP: - return true; - default: - break; - } - } - return false; -} - -int KyraEngine::gui_handleMainMenu() { - debugC(9, kDebugLevelMain, "KyraEngine::gui_handleMainMenu()"); - int command = -1; - - uint8 colorMap[16]; - memset(colorMap, 0, sizeof(colorMap)); - _screen->setTextColorMap(colorMap); - - const char * const *strings = &_mainMenuStrings[_lang << 2]; - Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT); - int charWidthBackUp = _screen->_charWidth; - - _screen->_charWidth = -2; - _screen->setScreenDim(3); - int backUpX = _screen->_curDim->sx; - int backUpY = _screen->_curDim->sy; - int backUpWidth = _screen->_curDim->w; - int backUpHeight = _screen->_curDim->h; - _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 0, 3); - - int x = _screen->_curDim->sx << 3; - int y = _screen->_curDim->sy; - int width = _screen->_curDim->w << 3; - int height = _screen->_curDim->h; - - gui_drawMainBox(x, y, width, height, 1); - gui_drawMainBox(x + 1, y + 1, width - 2, height - 2, 0); - - int selected = 0; - - gui_drawMainMenu(strings, selected); - - _screen->showMouse(); - - int fh = _screen->getFontHeight(); - int textPos = ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3; - - Common::Rect menuRect(x + 16, y + 4, x + width - 16, y + 4 + fh * 4); - - while (!_quitFlag) { - gui_updateMainMenuAnimation(); - bool mousePressed = gui_mainMenuGetInput(); - - Common::Point mouse = getMousePos(); - if (menuRect.contains(mouse)) { - int item = (mouse.y - menuRect.top) / fh; - - if (item != selected) { - gui_printString(strings[selected], textPos, menuRect.top + selected * fh, 0x80, 0, 5); - gui_printString(strings[item], textPos, menuRect.top + item * fh, 0xFF, 0, 5); - - selected = item; - } - - if (mousePressed) { - // TODO: Flash the text - command = item; - break; - } - } - _system->delayMillis(10); - } - - if (_quitFlag) - command = -1; - - _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 3, 0); - _screen->_charWidth = charWidthBackUp; - _screen->setFont(oldFont); - - return command; -} - -void KyraEngine::gui_drawMainMenu(const char * const *strings, int select) { - debugC(9, kDebugLevelMain, "KyraEngine::gui_drawMainMenu(%p)", (const void*)strings); - static const uint16 menuTable[] = { 0x01, 0x04, 0x0C, 0x04, 0x00, 0x80, 0xFF, 0x00, 0x01, 0x02, 0x03 }; - - int top = _screen->_curDim->sy; - top += menuTable[1]; - - for (int i = 0; i < menuTable[3]; ++i) { - int curY = top + i * _screen->getFontHeight(); - int color = (i == select) ? menuTable[6] : menuTable[5]; - gui_printString(strings[i], ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3, curY, color, 0, 5); - } -} - -void KyraEngine::gui_drawMainBox(int x, int y, int w, int h, int fill) { - debugC(9, kDebugLevelMain, "KyraEngine::gui_drawMainBox(%d, %d, %d, %d, %d)", x, y, w, h, fill); - static const uint8 kyra3ColorTable[] = { 0x16, 0x19, 0x1A, 0x16 }; - static const uint8 kyra2ColorTable[] = { 0x0, 0x19, 0x28, 0xc8 }; - - const uint8 *colorTable; - if (_flags.gameID == GI_KYRA3) - colorTable = kyra3ColorTable; - else - colorTable = kyra2ColorTable; - - --w; --h; - - if (fill) - _screen->fillRect(x, y, x+w, y+h, colorTable[0]); - - _screen->drawClippedLine(x, y+h, x+w, y+h, colorTable[1]); - _screen->drawClippedLine(x+w, y, x+w, y+h, colorTable[1]); - _screen->drawClippedLine(x, y, x+w, y, colorTable[2]); - _screen->drawClippedLine(x, y, x, y+h, colorTable[2]); - - _screen->setPagePixel(_screen->_curPage, x, y+h, colorTable[3]); - _screen->setPagePixel(_screen->_curPage, x+w, y, colorTable[3]); -} - -void KyraEngine::gui_printString(const char *format, int x, int y, int col1, int col2, int flags, ...) { - debugC(9, kDebugLevelMain, "KyraEngine::gui_printString('%s', %d, %d, %d, %d, %d, ...)", format, x, y, col1, col2, flags); - if (!format) - return; - - char string[512]; - va_list vaList; - va_start(vaList, flags); - vsprintf(string, format, vaList); - va_end(vaList); - - if (flags & 1) - x -= _screen->getTextWidth(string) >> 1; - - if (flags & 2) - x -= _screen->getTextWidth(string); - - if (flags & 4) { - _screen->printText(string, x - 1, y, 240, col2); - _screen->printText(string, x, y + 1, 240, col2); - } - - if (flags & 8) { - _screen->printText(string, x - 1, y, 227, col2); - _screen->printText(string, x, y + 1, 227, col2); - } - - _screen->printText(string, x, y, col1, col2); -} - } // end of namespace Kyra diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp new file mode 100644 index 0000000000..f24bf295a8 --- /dev/null +++ b/engines/kyra/gui_v2.cpp @@ -0,0 +1,195 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "kyra/kyra.h" +#include "kyra/kyra_v2.h" +#include "kyra/screen.h" + +namespace Kyra { + +void KyraEngine_v2::gui_updateMainMenuAnimation() { + _screen->updateScreen(); +} + +bool KyraEngine_v2::gui_mainMenuGetInput() { + Common::Event event; + + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_QUIT: + quitGame(); + break; + case Common::EVENT_LBUTTONUP: + return true; + default: + break; + } + } + return false; +} + +int KyraEngine_v2::gui_handleMainMenu() { + debugC(9, kDebugLevelMain, "KyraEngine_v2::gui_handleMainMenu()"); + int command = -1; + + uint8 colorMap[16]; + memset(colorMap, 0, sizeof(colorMap)); + _screen->setTextColorMap(colorMap); + + const char * const *strings = &_mainMenuStrings[_lang << 2]; + Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT); + int charWidthBackUp = _screen->_charWidth; + + _screen->_charWidth = -2; + _screen->setScreenDim(3); + int backUpX = _screen->_curDim->sx; + int backUpY = _screen->_curDim->sy; + int backUpWidth = _screen->_curDim->w; + int backUpHeight = _screen->_curDim->h; + _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 0, 3); + + int x = _screen->_curDim->sx << 3; + int y = _screen->_curDim->sy; + int width = _screen->_curDim->w << 3; + int height = _screen->_curDim->h; + + gui_drawMainBox(x, y, width, height, 1); + gui_drawMainBox(x + 1, y + 1, width - 2, height - 2, 0); + + int selected = 0; + + gui_drawMainMenu(strings, selected); + + _screen->showMouse(); + + int fh = _screen->getFontHeight(); + int textPos = ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3; + + Common::Rect menuRect(x + 16, y + 4, x + width - 16, y + 4 + fh * 4); + + while (!_quitFlag) { + gui_updateMainMenuAnimation(); + bool mousePressed = gui_mainMenuGetInput(); + + Common::Point mouse = getMousePos(); + if (menuRect.contains(mouse)) { + int item = (mouse.y - menuRect.top) / fh; + + if (item != selected) { + gui_printString(strings[selected], textPos, menuRect.top + selected * fh, 0x80, 0, 5); + gui_printString(strings[item], textPos, menuRect.top + item * fh, 0xFF, 0, 5); + + selected = item; + } + + if (mousePressed) { + // TODO: Flash the text + command = item; + break; + } + } + _system->delayMillis(10); + } + + if (_quitFlag) + command = -1; + + _screen->copyRegion(backUpX, backUpY, backUpX, backUpY, backUpWidth, backUpHeight, 3, 0); + _screen->_charWidth = charWidthBackUp; + _screen->setFont(oldFont); + + return command; +} + +void KyraEngine_v2::gui_drawMainMenu(const char * const *strings, int select) { + debugC(9, kDebugLevelMain, "KyraEngine_v2::gui_drawMainMenu(%p)", (const void*)strings); + static const uint16 menuTable[] = { 0x01, 0x04, 0x0C, 0x04, 0x00, 0x80, 0xFF, 0x00, 0x01, 0x02, 0x03 }; + + int top = _screen->_curDim->sy; + top += menuTable[1]; + + for (int i = 0; i < menuTable[3]; ++i) { + int curY = top + i * _screen->getFontHeight(); + int color = (i == select) ? menuTable[6] : menuTable[5]; + gui_printString(strings[i], ((_screen->_curDim->w >> 1) + _screen->_curDim->sx) << 3, curY, color, 0, 5); + } +} + +void KyraEngine_v2::gui_drawMainBox(int x, int y, int w, int h, int fill) { + debugC(9, kDebugLevelMain, "KyraEngine_v2::gui_drawMainBox(%d, %d, %d, %d, %d)", x, y, w, h, fill); + static const uint8 kyra3ColorTable[] = { 0x16, 0x19, 0x1A, 0x16 }; + static const uint8 kyra2ColorTable[] = { 0x0, 0x19, 0x28, 0xc8 }; + + const uint8 *colorTable; + if (_flags.gameID == GI_KYRA3) + colorTable = kyra3ColorTable; + else + colorTable = kyra2ColorTable; + + --w; --h; + + if (fill) + _screen->fillRect(x, y, x+w, y+h, colorTable[0]); + + _screen->drawClippedLine(x, y+h, x+w, y+h, colorTable[1]); + _screen->drawClippedLine(x+w, y, x+w, y+h, colorTable[1]); + _screen->drawClippedLine(x, y, x+w, y, colorTable[2]); + _screen->drawClippedLine(x, y, x, y+h, colorTable[2]); + + _screen->setPagePixel(_screen->_curPage, x, y+h, colorTable[3]); + _screen->setPagePixel(_screen->_curPage, x+w, y, colorTable[3]); +} + +void KyraEngine_v2::gui_printString(const char *format, int x, int y, int col1, int col2, int flags, ...) { + debugC(9, kDebugLevelMain, "KyraEngine_v2::gui_printString('%s', %d, %d, %d, %d, %d, ...)", format, x, y, col1, col2, flags); + if (!format) + return; + + char string[512]; + va_list vaList; + va_start(vaList, flags); + vsprintf(string, format, vaList); + va_end(vaList); + + if (flags & 1) + x -= _screen->getTextWidth(string) >> 1; + + if (flags & 2) + x -= _screen->getTextWidth(string); + + if (flags & 4) { + _screen->printText(string, x - 1, y, 240, col2); + _screen->printText(string, x, y + 1, 240, col2); + } + + if (flags & 8) { + _screen->printText(string, x - 1, y, 227, col2); + _screen->printText(string, x, y + 1, 227, col2); + } + + _screen->printText(string, x, y, col1, col2); +} + +} // end of namespace Kyra diff --git a/engines/kyra/items_v1.cpp b/engines/kyra/items_v1.cpp index 2a1a08b7de..84b76c59a6 100644 --- a/engines/kyra/items_v1.cpp +++ b/engines/kyra/items_v1.cpp @@ -23,14 +23,14 @@ * */ -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/seqplayer.h" #include "kyra/screen.h" #include "kyra/resource.h" #include "kyra/sound.h" #include "kyra/sprites.h" #include "kyra/wsamovie.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/text.h" #include "common/system.h" @@ -38,7 +38,7 @@ namespace Kyra { -int KyraEngine::findDuplicateItemShape(int shape) { +int KyraEngine_v1::findDuplicateItemShape(int shape) { static uint8 dupTable[] = { 0x48, 0x46, 0x49, 0x47, 0x4a, 0x46, 0x4b, 0x47, 0x4c, 0x46, 0x4d, 0x47, 0x5b, 0x5a, 0x5c, 0x5a, @@ -55,8 +55,8 @@ int KyraEngine::findDuplicateItemShape(int shape) { return -1; } -void KyraEngine::addToNoDropRects(int x, int y, int w, int h) { - debugC(9, kDebugLevelMain, "KyraEngine::addToNoDropRects(%d, %d, %d, %d)", x, y, w, h); +void KyraEngine_v1::addToNoDropRects(int x, int y, int w, int h) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::addToNoDropRects(%d, %d, %d, %d)", x, y, w, h); for (int rect = 0; rect < 11; ++rect) { if (_noDropRects[rect].x == -1) { _noDropRects[rect].x = x; @@ -68,13 +68,13 @@ void KyraEngine::addToNoDropRects(int x, int y, int w, int h) { } } -void KyraEngine::clearNoDropRects() { - debugC(9, kDebugLevelMain, "KyraEngine::clearNoDropRects()"); +void KyraEngine_v1::clearNoDropRects() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::clearNoDropRects()"); memset(_noDropRects, -1, sizeof(_noDropRects)); } -byte KyraEngine::findFreeItemInScene(int scene) { - debugC(9, kDebugLevelMain, "KyraEngine::findFreeItemInScene(%d)", scene); +byte KyraEngine_v1::findFreeItemInScene(int scene) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::findFreeItemInScene(%d)", scene); assert(scene < _roomTableSize); Room *room = &_roomTable[scene]; for (int i = 0; i < 12; ++i) { @@ -84,8 +84,8 @@ byte KyraEngine::findFreeItemInScene(int scene) { return 0xFF; } -byte KyraEngine::findItemAtPos(int x, int y) { - debugC(9, kDebugLevelMain, "KyraEngine::findItemAtPos(%d, %d)", x, y); +byte KyraEngine_v1::findItemAtPos(int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::findItemAtPos(%d, %d)", x, y); assert(_currentCharacter->sceneId < _roomTableSize); const uint8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable; const uint16 *xposOffset = _roomTable[_currentCharacter->sceneId].itemsXPos; @@ -120,8 +120,8 @@ byte KyraEngine::findItemAtPos(int x, int y) { return returnValue; } -void KyraEngine::placeItemInGenericMapScene(int item, int index) { - debugC(9, kDebugLevelMain, "KyraEngine::placeItemInGenericMapScene(%d, %d)", item, index); +void KyraEngine_v1::placeItemInGenericMapScene(int item, int index) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::placeItemInGenericMapScene(%d, %d)", item, index); static const uint16 itemMapSceneMinTable[] = { 0x0000, 0x0011, 0x006D, 0x0025, 0x00C7, 0x0000 }; @@ -175,32 +175,32 @@ void KyraEngine::placeItemInGenericMapScene(int item, int index) { } } -void KyraEngine::createMouseItem(int item) { - debugC(9, kDebugLevelMain, "KyraEngine::createMouseItem(%d)", item); +void KyraEngine_v1::createMouseItem(int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::createMouseItem(%d)", item); _screen->hideMouse(); setMouseItem(item); _itemInHand = item; _screen->showMouse(); } -void KyraEngine::destroyMouseItem() { - debugC(9, kDebugLevelMain, "KyraEngine::destroyMouseItem()"); +void KyraEngine_v1::destroyMouseItem() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::destroyMouseItem()"); _screen->hideMouse(); _screen->setMouseCursor(1, 1, _shapes[0]); _itemInHand = -1; _screen->showMouse(); } -void KyraEngine::setMouseItem(int item) { - debugC(9, kDebugLevelMain, "KyraEngine::setMouseItem(%d)", item); +void KyraEngine_v1::setMouseItem(int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setMouseItem(%d)", item); if (item == -1) _screen->setMouseCursor(1, 1, _shapes[6]); else _screen->setMouseCursor(8, 15, _shapes[216+item]); } -void KyraEngine::wipeDownMouseItem(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::wipeDownMouseItem(%d, %d)", xpos, ypos); +void KyraEngine_v1::wipeDownMouseItem(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::wipeDownMouseItem(%d, %d)", xpos, ypos); if (_itemInHand == -1) return; xpos -= 8; @@ -226,8 +226,8 @@ void KyraEngine::wipeDownMouseItem(int xpos, int ypos) { _screen->showMouse(); } -void KyraEngine::setupSceneItems() { - debugC(9, kDebugLevelMain, "KyraEngine::setupSceneItems()"); +void KyraEngine_v1::setupSceneItems() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setupSceneItems()"); uint16 sceneId = _currentCharacter->sceneId; assert(sceneId < _roomTableSize); Room *currentRoom = &_roomTable[sceneId]; @@ -264,8 +264,8 @@ void KyraEngine::setupSceneItems() { } } -int KyraEngine::countItemsInScene(uint16 sceneId) { - debugC(9, kDebugLevelMain, "KyraEngine::countItemsInScene(%d)", sceneId); +int KyraEngine_v1::countItemsInScene(uint16 sceneId) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::countItemsInScene(%d)", sceneId); assert(sceneId < _roomTableSize); Room *currentRoom = &_roomTable[sceneId]; @@ -279,8 +279,8 @@ int KyraEngine::countItemsInScene(uint16 sceneId) { return items; } -int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2) { - debugC(9, kDebugLevelMain, "KyraEngine::processItemDrop(%d, %d, %d, %d, %d, %d)", sceneId, item, x, y, unk1, unk2); +int KyraEngine_v1::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::processItemDrop(%d, %d, %d, %d, %d, %d)", sceneId, item, x, y, unk1, unk2); int freeItem = -1; uint8 itemIndex = findItemAtPos(x, y); if (unk1) @@ -432,8 +432,8 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un return 1; } -void KyraEngine::exchangeItemWithMouseItem(uint16 sceneId, int itemIndex) { - debugC(9, kDebugLevelMain, "KyraEngine::exchangeItemWithMouseItem(%d, %d)", sceneId, itemIndex); +void KyraEngine_v1::exchangeItemWithMouseItem(uint16 sceneId, int itemIndex) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::exchangeItemWithMouseItem(%d, %d)", sceneId, itemIndex); _screen->hideMouse(); _animator->animRemoveGameItem(itemIndex); assert(sceneId < _roomTableSize); @@ -452,8 +452,8 @@ void KyraEngine::exchangeItemWithMouseItem(uint16 sceneId, int itemIndex) { clickEventHandler2(); } -void KyraEngine::addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y) { - debugC(9, kDebugLevelMain, "KyraEngine::addItemToRoom(%d, %d, %d, %d, %d)", sceneId, item, itemIndex, x, y); +void KyraEngine_v1::addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::addItemToRoom(%d, %d, %d, %d, %d)", sceneId, item, itemIndex, x, y); assert(sceneId < _roomTableSize); Room *currentRoom = &_roomTable[sceneId]; currentRoom->itemsTable[itemIndex] = item; @@ -462,8 +462,8 @@ void KyraEngine::addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, currentRoom->needInit[itemIndex] = 1; } -int KyraEngine::checkNoDropRects(int x, int y) { - debugC(9, kDebugLevelMain, "KyraEngine::checkNoDropRects(%d, %d)", x, y); +int KyraEngine_v1::checkNoDropRects(int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::checkNoDropRects(%d, %d)", x, y); if (_lastProcessedItemHeight < 1 || _lastProcessedItemHeight > 16) _lastProcessedItemHeight = 16; if (_noDropRects[0].x == -1) @@ -492,8 +492,8 @@ int KyraEngine::checkNoDropRects(int x, int y) { return 0; } -int KyraEngine::isDropable(int x, int y) { - debugC(9, kDebugLevelMain, "KyraEngine::isDropable(%d, %d)", x, y); +int KyraEngine_v1::isDropable(int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::isDropable(%d, %d)", x, y); x -= 8; y -= 1; @@ -507,8 +507,8 @@ int KyraEngine::isDropable(int x, int y) { return 1; } -void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item) { - debugC(9, kDebugLevelMain, "KyraEngine::itemDropDown(%d, %d, %d, %d, %d, %d)", x, y, destX, destY, freeItem, item); +void KyraEngine_v1::itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::itemDropDown(%d, %d, %d, %d, %d, %d)", x, y, destX, destY, freeItem, item); assert(_currentCharacter->sceneId < _roomTableSize); Room *currentRoom = &_roomTable[_currentCharacter->sceneId]; if (x == destX && y == destY) { @@ -591,8 +591,8 @@ void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, _screen->showMouse(); } -void KyraEngine::dropItem(int unk1, int item, int x, int y, int unk2) { - debugC(9, kDebugLevelMain, "KyraEngine::dropItem(%d, %d, %d, %d, %d)", unk1, item, x, y, unk2); +void KyraEngine_v1::dropItem(int unk1, int item, int x, int y, int unk2) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::dropItem(%d, %d, %d, %d, %d)", unk1, item, x, y, unk2); if (processItemDrop(_currentCharacter->sceneId, item, x, y, unk1, unk2)) return; snd_playSoundEffect(54); @@ -603,16 +603,16 @@ void KyraEngine::dropItem(int unk1, int item, int x, int y, int unk2) { drawSentenceCommand(_noDropList[1], 6); } -void KyraEngine::itemSpecialFX(int x, int y, int item) { - debugC(9, kDebugLevelMain, "KyraEngine::itemSpecialFX(%d, %d, %d)", x, y, item); +void KyraEngine_v1::itemSpecialFX(int x, int y, int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::itemSpecialFX(%d, %d, %d)", x, y, item); if (item == 41) itemSpecialFX1(x, y, item); else itemSpecialFX2(x, y, item); } -void KyraEngine::itemSpecialFX1(int x, int y, int item) { - debugC(9, kDebugLevelMain, "KyraEngine::itemSpecialFX1(%d, %d, %d)", x, y, item); +void KyraEngine_v1::itemSpecialFX1(int x, int y, int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::itemSpecialFX1(%d, %d, %d)", x, y, item); uint8 *shape = _shapes[216+item]; x -= 8; int startY = y; @@ -632,8 +632,8 @@ void KyraEngine::itemSpecialFX1(int x, int y, int item) { _screen->showMouse(); } -void KyraEngine::itemSpecialFX2(int x, int y, int item) { - debugC(9, kDebugLevelMain, "KyraEngine::itemSpecialFX2(%d, %d, %d)", x, y, item); +void KyraEngine_v1::itemSpecialFX2(int x, int y, int item) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::itemSpecialFX2(%d, %d, %d)", x, y, item); x -= 8; y -= 15; int yAdd = (int8)(((16 - _itemTable[item].height) >> 1) & 0xFF); @@ -660,8 +660,8 @@ void KyraEngine::itemSpecialFX2(int x, int y, int item) { restoreItemRect0(x, y); } -void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { - debugC(9, kDebugLevelMain, "KyraEngine::magicOutMouseItem(%d, %d)", animIndex, itemPos); +void KyraEngine_v1::magicOutMouseItem(int animIndex, int itemPos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::magicOutMouseItem(%d, %d)", animIndex, itemPos); int videoPageBackUp = _screen->_curPage; _screen->_curPage = 0; int x = 0, y = 0; @@ -744,8 +744,8 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { _screen->_curPage = videoPageBackUp; } -void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) { - debugC(9, kDebugLevelMain, "KyraEngine::magicInMouseItem(%d, %d, %d)", animIndex, item, itemPos); +void KyraEngine_v1::magicInMouseItem(int animIndex, int item, int itemPos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::magicInMouseItem(%d, %d, %d)", animIndex, item, itemPos); int videoPageBackUp = _screen->_curPage; _screen->_curPage = 0; int x = 0, y = 0; @@ -817,8 +817,8 @@ void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) { _screen->_curPage = videoPageBackUp; } -void KyraEngine::specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops) { - debugC(9, kDebugLevelMain, "KyraEngine::specialMouseItemFX(%d, %d, %d, %d, %d, %d, %d)", shape, x, y, animIndex, tableIndex, loopStart, maxLoops); +void KyraEngine_v1::specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::specialMouseItemFX(%d, %d, %d, %d, %d, %d, %d)", shape, x, y, animIndex, tableIndex, loopStart, maxLoops); static const uint8 table1[] = { 0x23, 0x45, 0x55, 0x72, 0x84, 0xCF, 0x00, 0x00 }; @@ -840,8 +840,8 @@ void KyraEngine::specialMouseItemFX(int shape, int x, int y, int animIndex, int processSpecialMouseItemFX(shape, x, y, tableValue, loopStart, maxLoops); } -void KyraEngine::processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops) { - debugC(9, kDebugLevelMain, "KyraEngine::processSpecialMouseItemFX(%d, %d, %d, %d, %d, %d)", shape, x, y, tableValue, loopStart, maxLoops); +void KyraEngine_v1::processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::processSpecialMouseItemFX(%d, %d, %d, %d, %d, %d)", shape, x, y, tableValue, loopStart, maxLoops); uint8 shapeColorTable[16]; uint8 *shapePtr = _shapes[shape] + 10; if (_flags.useAltShapeHeader) @@ -859,8 +859,8 @@ void KyraEngine::processSpecialMouseItemFX(int shape, int x, int y, int tableVal _screen->drawShape(0, _shapes[shape], x, y, 0, 0x8000, shapeColorTable); } -void KyraEngine::updatePlayerItemsForScene() { - debugC(9, kDebugLevelMain, "KyraEngine::updatePlayerItemsForScene()"); +void KyraEngine_v1::updatePlayerItemsForScene() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updatePlayerItemsForScene()"); if (_itemInHand >= 29 && _itemInHand < 33) { ++_itemInHand; if (_itemInHand > 33) @@ -900,7 +900,7 @@ void KyraEngine::updatePlayerItemsForScene() { _screen->showMouse(); } -void KyraEngine::redrawInventory(int page) { +void KyraEngine_v1::redrawInventory(int page) { int videoPageBackUp = _screen->_curPage; _screen->_curPage = page; _screen->hideMouse(); @@ -916,26 +916,26 @@ void KyraEngine::redrawInventory(int page) { _screen->updateScreen(); } -void KyraEngine::backUpItemRect0(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::backUpItemRect0(%d, %d)", xpos, ypos); +void KyraEngine_v1::backUpItemRect0(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::backUpItemRect0(%d, %d)", xpos, ypos); _screen->rectClip(xpos, ypos, 3<<3, 24); _screen->copyRegionToBuffer(_screen->_curPage, xpos, ypos, 3<<3, 24, _itemBkgBackUp[0]); } -void KyraEngine::restoreItemRect0(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::restoreItemRect0(%d, %d)", xpos, ypos); +void KyraEngine_v1::restoreItemRect0(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::restoreItemRect0(%d, %d)", xpos, ypos); _screen->rectClip(xpos, ypos, 3<<3, 24); _screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 3<<3, 24, _itemBkgBackUp[0]); } -void KyraEngine::backUpItemRect1(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::backUpItemRect1(%d, %d)", xpos, ypos); +void KyraEngine_v1::backUpItemRect1(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::backUpItemRect1(%d, %d)", xpos, ypos); _screen->rectClip(xpos, ypos, 4<<3, 32); _screen->copyRegionToBuffer(_screen->_curPage, xpos, ypos, 4<<3, 32, _itemBkgBackUp[1]); } -void KyraEngine::restoreItemRect1(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::restoreItemRect1(%d, %d)", xpos, ypos); +void KyraEngine_v1::restoreItemRect1(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::restoreItemRect1(%d, %d)", xpos, ypos); _screen->rectClip(xpos, ypos, 4<<3, 32); _screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 4<<3, 32, _itemBkgBackUp[1]); } diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index 1664ce144f..c7e167f600 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -26,91 +26,31 @@ #include "common/stdafx.h" #include "common/config-manager.h" -#include "common/file.h" -#include "common/events.h" -#include "common/system.h" -#include "common/savefile.h" -#include "sound/mixer.h" #include "sound/mididrv.h" - -#include "gui/message.h" +#include "sound/mixer.h" #include "kyra/kyra.h" +#include "kyra/sound.h" #include "kyra/resource.h" #include "kyra/screen.h" -#include "kyra/script.h" -#include "kyra/seqplayer.h" -#include "kyra/sound.h" -#include "kyra/sprites.h" -#include "kyra/wsamovie.h" -#include "kyra/animator.h" #include "kyra/text.h" -#include "kyra/debugger.h" namespace Kyra { KyraEngine::KyraEngine(OSystem *system, const GameFlags &flags) : Engine(system) { - _flags = flags; - - _seq_Forest = _seq_KallakWriting = _seq_KyrandiaLogo = _seq_KallakMalcolm = - _seq_MalcolmTree = _seq_WestwoodLogo = _seq_Demo1 = _seq_Demo2 = _seq_Demo3 = - _seq_Demo4 = 0; - - _seq_WSATable = _seq_CPSTable = _seq_COLTable = _seq_textsTable = 0; - _seq_WSATable_Size = _seq_CPSTable_Size = _seq_COLTable_Size = _seq_textsTable_Size = 0; - - _roomFilenameTable = _characterImageTable = 0; - _roomFilenameTableSize = _characterImageTableSize = 0; - _itemList = _takenList = _placedList = _droppedList = _noDropList = 0; - _itemList_Size = _takenList_Size = _placedList_Size = _droppedList_Size = _noDropList_Size = 0; - _putDownFirst = _waitForAmulet = _blackJewel = _poisonGone = _healingTip = 0; - _putDownFirst_Size = _waitForAmulet_Size = _blackJewel_Size = _poisonGone_Size = _healingTip_Size = 0; - _thePoison = _fluteString = _wispJewelStrings = _magicJewelString = _flaskFull = _fullFlask = 0; - _thePoison_Size = _fluteString_Size = _wispJewelStrings_Size = 0; - _magicJewelString_Size = _flaskFull_Size = _fullFlask_Size = 0; - - _defaultShapeTable = 0; - _healingShapeTable = _healingShape2Table = 0; - _defaultShapeTableSize = _healingShapeTableSize = _healingShape2TableSize = 0; - _posionDeathShapeTable = _fluteAnimShapeTable = 0; - _posionDeathShapeTableSize = _fluteAnimShapeTableSize = 0; - _winterScrollTable = _winterScroll1Table = _winterScroll2Table = 0; - _winterScrollTableSize = _winterScroll1TableSize = _winterScroll2TableSize = 0; - _drinkAnimationTable = _brandonToWispTable = _magicAnimationTable = _brandonStoneTable = 0; - _drinkAnimationTableSize = _brandonToWispTableSize = _magicAnimationTableSize = _brandonStoneTableSize = 0; - memset(&_specialPalettes, 0, sizeof(_specialPalettes)); - _debugger = 0; - _sprites = 0; - _animator = 0; _screen = 0; _res = 0; _sound = 0; - _seq = 0; - _scriptInterpreter = 0; _text = 0; - _npcScriptData = 0; - _scriptMain = 0; - _scriptClickData = 0; - _scriptClick = 0; - _characterList = 0; - _movFacingTable = 0; - memset(_shapes, 0, sizeof(_shapes)); - memset(_movieObjects, 0, sizeof(_movieObjects)); - _finalA = _finalB = _finalC = 0; - _endSequenceBackUpRect = 0; - memset(_panPagesTable, 0, sizeof(_panPagesTable)); - _npcScriptData = _scriptClickData = 0; - _scrollUpButton.process0PtrShape = _scrollUpButton.process1PtrShape = _scrollUpButton.process2PtrShape = 0; - _scrollDownButton.process0PtrShape = _scrollDownButton.process1PtrShape = _scrollDownButton.process2PtrShape = 0; - memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); + _staticres = 0; + _quitFlag = false; - _currHeadShape = 0; - - _curSfxFile = _curMusicTheme = 0; - - memset(&_itemBkgBackUp, 0, sizeof(_itemBkgBackUp)); + + _skipFlag = false; + + memset(_flagsTable, 0, sizeof(_flagsTable)); // sets up all engine specific debug levels Common::addSpecialDebugLevel(kDebugLevelScriptFuncs, "ScriptFuncs", "Script function debug level"); @@ -133,18 +73,10 @@ int KyraEngine::init() { _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); - - _screen = new Screen(this, _system); - assert(_screen); - if (!_screen->init()) - error("_screen->init() failed"); - - // for now we prefer Adlib over native MIDI + + // for now we prefer Adlib over native MIDI int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB/* | MDT_PREFER_MIDI*/); - // TODO: We should play the native Kyra 2 Adlib music, but until that - // is support, we'll use the automagic MIDI -> Adlib converter. - if (_flags.platform == Common::kPlatformFMTowns) { // no sfx enabled for CD audio music atm // later on here should be a usage of MixedSoundDriver @@ -183,155 +115,12 @@ int KyraEngine::init() { _res = new Resource(this); assert(_res); - _sprites = new Sprites(this, _system); - assert(_sprites); - _seq = new SeqPlayer(this, _system); - assert(_seq); - _animator = new ScreenAnimator(this, _system); - assert(_animator); - _animator->init(5, 11, 12); - assert(*_animator); _text = new TextDisplayer(this, _screen); assert(_text); - _staticres = new StaticResource(this); assert(_staticres); if (!_staticres->init()) error("_staticres->init() failed"); - - initStaticResource(); - - if (!_sound->init()) - error("Couldn't init sound"); - - if (_flags.platform == Common::kPlatformFMTowns) - _sound->setSoundFileList(_soundFilesTowns, _soundFilesTownsCount); - else - _sound->setSoundFileList(_soundFiles, _soundFilesCount); - - _sound->setVolume(255); - _sound->loadSoundFile(0); - - setupOpcodeTable(); - setupButtonData(); - setupMenu(); - - _paletteChanged = 1; - _currentCharacter = 0; - _characterList = new Character[11]; - assert(_characterList); - memset(_characterList, 0, sizeof(Character)*11); - - for (int i = 0; i < 11; ++i) - memset(_characterList[i].inventoryItems, 0xFF, sizeof(_characterList[i].inventoryItems)); - - _characterList[0].sceneId = 5; - _characterList[0].height = 48; - _characterList[0].facing = 3; - _characterList[0].currentAnimFrame = 7; - - _scriptInterpreter = new ScriptHelper(this); - assert(_scriptInterpreter); - - _npcScriptData = new ScriptData; - memset(_npcScriptData, 0, sizeof(ScriptData)); - assert(_npcScriptData); - _npcScript = new ScriptState; - assert(_npcScript); - memset(_npcScript, 0, sizeof(ScriptState)); - - _scriptMain = new ScriptState; - assert(_scriptMain); - memset(_scriptMain, 0, sizeof(ScriptState)); - - _scriptClickData = new ScriptData; - assert(_scriptClickData); - memset(_scriptClickData, 0, sizeof(ScriptData)); - _scriptClick = new ScriptState; - assert(_scriptClick); - memset(_scriptClick, 0, sizeof(ScriptState)); - - _debugger = new Debugger(this); - assert(_debugger); - memset(_shapes, 0, sizeof(_shapes)); - - for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) - _movieObjects[i] = createWSAMovie(); - - memset(_flagsTable, 0, sizeof(_flagsTable)); - - _abortWalkFlag = false; - _abortWalkFlag2 = false; - _talkingCharNum = -1; - _charSayUnk3 = -1; - memset(_currSentenceColor, 0, 3); - _startSentencePalIndex = -1; - _fadeText = false; - - _cauldronState = 0; - _crystalState[0] = _crystalState[1] = -1; - - _brandonStatusBit = 0; - _brandonStatusBit0x02Flag = _brandonStatusBit0x20Flag = 10; - _brandonPosX = _brandonPosY = -1; - _deathHandler = 0xFF; - _poisonDeathCounter = 0; - - memset(_itemTable, 0, sizeof(_itemTable)); - memset(_exitList, 0xFFFF, sizeof(_exitList)); - _exitListPtr = 0; - _pathfinderFlag = _pathfinderFlag2 = 0; - _lastFindWayRet = 0; - _sceneChangeState = _loopFlag2 = 0; - _timerNextRun = 0; - - _movFacingTable = new int[150]; - assert(_movFacingTable); - _movFacingTable[0] = 8; - - registerDefaultSettings(); - readSettings(); - - _skipFlag = false; - - _marbleVaseItem = -1; - memset(_foyerItemTable, -1, sizeof(_foyerItemTable)); - _mouseState = _itemInHand = -1; - _handleInput = false; - - _currentRoom = 0xFFFF; - _scenePhasingFlag = 0; - _lastProcessedItem = 0; - _lastProcessedItemHeight = 16; - - _unkScreenVar1 = 1; - _unkScreenVar2 = 0; - _unkScreenVar3 = 0; - _unkAmuletVar = 0; - - _endSequenceNeedLoading = 1; - _malcolmFlag = 0; - _beadStateVar = 0; - _endSequenceSkipFlag = 0; - _unkEndSeqVar2 = 0; - _endSequenceBackUpRect = 0; - _unkEndSeqVar4 = 0; - _unkEndSeqVar5 = 0; - _lastDisplayedPanPage = 0; - memset(_panPagesTable, 0, sizeof(_panPagesTable)); - _finalA = _finalB = _finalC = 0; - memset(&_kyragemFadingState, 0, sizeof(_kyragemFadingState)); - _kyragemFadingState.gOffset = 0x13; - _kyragemFadingState.bOffset = 0x13; - - _mousePressFlag = false; - - _menuDirectlyToLoad = false; - - _lastMusicCommand = 0; - - _gameSpeed = 60; - _tickLength = (uint8)(1000.0 / _gameSpeed); _lang = 0; Common::Language lang = Common::parseLanguage(ConfMan.get("language")); @@ -363,216 +152,9 @@ int KyraEngine::init() { } KyraEngine::~KyraEngine() { - for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { - if (_movieObjects[i]) - _movieObjects[i]->close(); - delete _movieObjects[i]; - _movieObjects[i] = 0; - } - - closeFinalWsa(); - if (_scriptInterpreter) { - _scriptInterpreter->unloadScript(_npcScriptData); - _scriptInterpreter->unloadScript(_scriptClickData); - } - - Common::clearAllSpecialDebugLevels(); - - delete _debugger; - delete _sprites; - delete _animator; - delete _screen; delete _res; delete _sound; - delete _seq; - delete _scriptInterpreter; delete _text; - - delete _npcScriptData; - delete _scriptMain; - - delete _scriptClickData; - delete _scriptClick; - - delete [] _characterList; - - delete [] _movFacingTable; - - delete [] _scrollUpButton.process0PtrShape; - delete [] _scrollUpButton.process1PtrShape; - delete [] _scrollUpButton.process2PtrShape; - delete [] _scrollDownButton.process0PtrShape; - delete [] _scrollDownButton.process1PtrShape; - delete [] _scrollDownButton.process2PtrShape; - - delete [] _itemBkgBackUp[0]; - delete [] _itemBkgBackUp[1]; - - for (int i = 0; i < ARRAYSIZE(_shapes); ++i) { - if (_shapes[i] != 0) { - delete [] _shapes[i]; - for (int i2 = 0; i2 < ARRAYSIZE(_shapes); i2++) { - if (_shapes[i2] == _shapes[i] && i2 != i) { - _shapes[i2] = 0; - } - } - _shapes[i] = 0; - } - } - - for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) - delete [] _sceneAnimTable[i]; -} - -int KyraEngine::go() { - if (_res->getFileSize("6.FNT")) - _screen->loadFont(Screen::FID_6_FNT, "6.FNT"); - _screen->loadFont(Screen::FID_8_FNT, "8FAT.FNT"); - _screen->setScreenDim(0); - - _abortIntroFlag = false; - - if (_flags.isDemo) { - seq_demo(); - } else { - setGameFlag(0xF3); - setGameFlag(0xFD); - setGameFlag(0xEF); - seq_intro(); - if (_quitFlag) - return 0; - if (_skipIntroFlag && _abortIntroFlag) - resetGameFlag(0xEF); - startup(); - resetGameFlag(0xEF); - mainLoop(); - } - return 0; -} - - -void KyraEngine::startup() { - debugC(9, kDebugLevelMain, "KyraEngine::startup()"); - static const uint8 colorMap[] = { 0, 0, 0, 0, 12, 12, 12, 0, 0, 0, 0, 0 }; - _screen->setTextColorMap(colorMap); -// _screen->setFont(Screen::FID_6_FNT); - _screen->setAnimBlockPtr(3750); - memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); - loadMouseShapes(); - _currentCharacter = &_characterList[0]; - for (int i = 1; i < 5; ++i) - _animator->setCharacterDefaultFrame(i); - for (int i = 5; i <= 10; ++i) - setCharactersPositions(i); - _animator->setCharactersHeight(); - resetBrandonPoisonFlags(); - _screen->_curPage = 0; - // XXX - for (int i = 0; i < 12; ++i) { - int size = _screen->getRectSize(3, 24); - _shapes[361+i] = new byte[size]; - } - - _itemBkgBackUp[0] = new uint8[_screen->getRectSize(3, 24)]; - memset(_itemBkgBackUp[0], 0, _screen->getRectSize(3, 24)); - _itemBkgBackUp[1] = new uint8[_screen->getRectSize(4, 32)]; - memset(_itemBkgBackUp[1], 0, _screen->getRectSize(4, 32)); - - for (int i = 0; i < _roomTableSize; ++i) { - for (int item = 0; item < 12; ++item) { - _roomTable[i].itemsTable[item] = 0xFF; - _roomTable[i].itemsXPos[item] = 0xFFFF; - _roomTable[i].itemsYPos[item] = 0xFF; - _roomTable[i].needInit[item] = 0; - } - } - - loadCharacterShapes(); - loadSpecialEffectShapes(); - loadItems(); - loadButtonShapes(); - initMainButtonList(); - loadMainScreen(); - setupTimers(); - _screen->loadPalette("PALETTE.COL", _screen->_currentPalette); - - // XXX - _animator->initAnimStateList(); - setCharactersInDefaultScene(); - - if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData, &_opcodes)) - error("Could not load \"_STARTUP.EMC\" script"); - _scriptInterpreter->initScript(_scriptMain, _npcScriptData); - - if (!_scriptInterpreter->startScript(_scriptMain, 0)) - error("Could not start script function 0 of script \"_STARTUP.EMC\""); - - while (_scriptInterpreter->validScript(_scriptMain)) - _scriptInterpreter->runScript(_scriptMain); - - _scriptInterpreter->unloadScript(_npcScriptData); - - if (!_scriptInterpreter->loadScript("_NPC.EMC", _npcScriptData, &_opcodes)) - error("Could not load \"_NPC.EMC\" script"); - - snd_playTheme(1); - enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1); - - if (_abortIntroFlag && _skipIntroFlag) { - _menuDirectlyToLoad = true; - _screen->setMouseCursor(1, 1, _shapes[0]); - _screen->showMouse(); - buttonMenuCallback(0); - _menuDirectlyToLoad = false; - } else - saveGame(getSavegameFilename(0), "New game"); -} - -void KyraEngine::mainLoop() { - debugC(9, kDebugLevelMain, "KyraEngine::mainLoop()"); - - while (!_quitFlag) { - int32 frameTime = (int32)_system->getMillis(); - _skipFlag = false; - - if (_currentCharacter->sceneId == 210) { - updateKyragemFading(); - if (seq_playEnd() && _deathHandler != 8) - break; - } - - if (_deathHandler != 0xFF) { - snd_playWanderScoreViaMap(0, 1); - snd_playSoundEffect(49); - _screen->hideMouse(); - _screen->setMouseCursor(1, 1, _shapes[0]); - destroyMouseItem(); - _screen->showMouse(); - buttonMenuCallback(0); - _deathHandler = 0xFF; - } - - if ((_brandonStatusBit & 2) && _brandonStatusBit0x02Flag) - _animator->animRefreshNPC(0); - - if ((_brandonStatusBit & 0x20) && _brandonStatusBit0x20Flag) { - _animator->animRefreshNPC(0); - _brandonStatusBit0x20Flag = 0; - } - - _screen->showMouse(); - - processButtonList(_buttonList); - updateMousePointer(); - updateGameTimers(); - updateTextFade(); - - _handleInput = true; - delay((frameTime + _gameSpeed) - _system->getMillis(), true, true); - _handleInput = false; - - _sound->process(); - } } void KyraEngine::quitGame() { @@ -581,209 +163,15 @@ void KyraEngine::quitGame() { // Nothing to do here } -void KyraEngine::delayUntil(uint32 timestamp, bool updateTimers, bool update, bool isMainLoop) { - while (_system->getMillis() < timestamp && !_quitFlag) { - if (updateTimers) - updateGameTimers(); - - if (timestamp - _system->getMillis() >= 10) - delay(10, update, isMainLoop); - } -} - -void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { - Common::Event event; - char saveLoadSlot[20]; - char savegameName[14]; - - uint32 start = _system->getMillis(); - do { - while (_eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && - (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && isMainLoop) { - sprintf(saveLoadSlot, "%s.00%d", _targetName.c_str(), event.kbd.keycode - '0'); - if (event.kbd.flags == Common::KBD_CTRL) - loadGame(saveLoadSlot); - else { - sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); - saveGame(saveLoadSlot, savegameName); - } - } else if (event.kbd.flags == Common::KBD_CTRL) { - if (event.kbd.keycode == 'd') - _debugger->attach(); - else if (event.kbd.keycode == 'q') - _quitFlag = true; - } else if (event.kbd.keycode == '.') - _skipFlag = true; - else if (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_SPACE || event.kbd.keycode == Common::KEYCODE_ESCAPE) { - _abortIntroFlag = true; - _skipFlag = true; - } - - break; - case Common::EVENT_MOUSEMOVE: - _animator->_updateScreen = true; - break; - case Common::EVENT_QUIT: - quitGame(); - break; - case Common::EVENT_LBUTTONDOWN: - _mousePressFlag = true; - break; - case Common::EVENT_LBUTTONUP: - _mousePressFlag = false; - - if (_abortWalkFlag2) - _abortWalkFlag = true; - - if (_handleInput) { - _handleInput = false; - processInput(); - _handleInput = true; - } else - _skipFlag = true; - - break; - default: - break; - } - } - - if (_debugger->isAttached()) - _debugger->onFrame(); - - if (update) { - _sprites->updateSceneAnims(); - _animator->updateAllObjectShapes(); - updateTextFade(); - updateMousePointer(); - } - - if (_currentCharacter && _currentCharacter->sceneId == 210 && update) - updateKyragemFading(); - - if (_skipFlag && !_abortIntroFlag && !queryGameFlag(0xFE)) - _skipFlag = false; - - if (amount > 0 && !_skipFlag && !_quitFlag) - _system->delayMillis(10); - - if (_skipFlag) - _sound->voiceStop(); - } while (!_skipFlag && _system->getMillis() < start + amount && !_quitFlag); -} - Common::Point KyraEngine::getMousePos() const { Common::Point mouse = _eventMan->getMousePos(); + if (_flags.useHiResOverlay) { mouse.x >>= 1; mouse.y >>= 1; } - return mouse; -} - -void KyraEngine::waitForEvent() { - bool finished = false; - Common::Event event; - - while (!finished && !_quitFlag) { - while (_eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_KEYDOWN: - finished = true; - break; - case Common::EVENT_QUIT: - quitGame(); - break; - case Common::EVENT_LBUTTONDOWN: - finished = true; - _skipFlag = true; - break; - default: - break; - } - } - - if (_debugger->isAttached()) - _debugger->onFrame(); - - _system->delayMillis(10); - } -} - -void KyraEngine::delayWithTicks(int ticks) { - uint32 nextTime = _system->getMillis() + ticks * _tickLength; - - while (_system->getMillis() < nextTime) { - _sprites->updateSceneAnims(); - _animator->updateAllObjectShapes(); - - if (_currentCharacter->sceneId == 210) { - updateKyragemFading(); - seq_playEnd(); - } - - if (_skipFlag) - break; - - if (nextTime - _system->getMillis() >= 10) - delay(10); - } -} - -#pragma mark - -#pragma mark - Animation/shape specific code -#pragma mark - - -void KyraEngine::setupShapes123(const Shape *shapeTable, int endShape, int flags) { - debugC(9, kDebugLevelMain, "KyraEngine::setupShapes123(%p, %d, %d)", (const void *)shapeTable, endShape, flags); - for (int i = 123; i <= 172; ++i) - _shapes[i] = 0; - - uint8 curImage = 0xFF; - int curPageBackUp = _screen->_curPage; - _screen->_curPage = 8; // we are using page 8 here in the original page 2 was backuped and then used for this stuff - int shapeFlags = 2; - if (flags) - shapeFlags = 3; - for (int i = 123; i < 123+endShape; ++i) { - uint8 newImage = shapeTable[i-123].imageIndex; - if (newImage != curImage && newImage != 0xFF) { - assert(_characterImageTable); - _screen->loadBitmap(_characterImageTable[newImage], 8, 8, 0); - curImage = newImage; - } - _shapes[i] = _screen->encodeShape(shapeTable[i-123].x<<3, shapeTable[i-123].y, shapeTable[i-123].w<<3, shapeTable[i-123].h, shapeFlags); - assert(i-7 < _defaultShapeTableSize); - _defaultShapeTable[i-7].xOffset = shapeTable[i-123].xOffset; - _defaultShapeTable[i-7].yOffset = shapeTable[i-123].yOffset; - _defaultShapeTable[i-7].w = shapeTable[i-123].w; - _defaultShapeTable[i-7].h = shapeTable[i-123].h; - } - _screen->_curPage = curPageBackUp; -} - -void KyraEngine::freeShapes123() { - debugC(9, kDebugLevelMain, "KyraEngine::freeShapes123()"); - - for (int i = 123; i <= 172; ++i) { - delete [] _shapes[i]; - _shapes[i] = 0; - } -} - -#pragma mark - -#pragma mark - Misc stuff -#pragma mark - - -Movie *KyraEngine::createWSAMovie() { - if (_flags.platform == Common::kPlatformAmiga) - return new WSAMovieAmiga(this); - - return new WSAMovieV1(this); + return mouse; } int KyraEngine::setGameFlag(int flag) { @@ -791,7 +179,7 @@ int KyraEngine::setGameFlag(int flag) { return 1; } -int KyraEngine::queryGameFlag(int flag) { +int KyraEngine::queryGameFlag(int flag) const { return ((_flagsTable[flag >> 3] >> (flag & 7)) & 1); } @@ -800,344 +188,19 @@ int KyraEngine::resetGameFlag(int flag) { return 0; } -void KyraEngine::setBrandonPoisonFlags(int reset) { - debugC(9, kDebugLevelMain, "KyraEngine::setBrandonPoisonFlags(%d)", reset); - _brandonStatusBit |= 1; - - if (reset) - _poisonDeathCounter = 0; - - for (int i = 0; i < 0x100; ++i) - _brandonPoisonFlagsGFX[i] = i; - - _brandonPoisonFlagsGFX[0x99] = 0x34; - _brandonPoisonFlagsGFX[0x9A] = 0x35; - _brandonPoisonFlagsGFX[0x9B] = 0x37; - _brandonPoisonFlagsGFX[0x9C] = 0x38; - _brandonPoisonFlagsGFX[0x9D] = 0x2B; -} - -void KyraEngine::resetBrandonPoisonFlags() { - debugC(9, kDebugLevelMain, "KyraEngine::resetBrandonPoisonFlags()"); - _brandonStatusBit = 0; - - for (int i = 0; i < 0x100; ++i) - _brandonPoisonFlagsGFX[i] = i; -} - -#pragma mark - -#pragma mark - Input -#pragma mark - - -void KyraEngine::processInput() { - Common::Point mouse = getMousePos(); - int xpos = mouse.x; - int ypos = mouse.y; - - debugC(9, kDebugLevelMain, "KyraEngine::processInput(%d, %d)", xpos, ypos); - _abortWalkFlag2 = false; - - if (processInputHelper(xpos, ypos)) - return; - - uint8 item = findItemAtPos(xpos, ypos); - if (item == 0xFF) { - _changedScene = false; - int handled = clickEventHandler(xpos, ypos); - if (_changedScene || handled) - return; - } - - // XXX _deathHandler specific - if (ypos <= 158) { - uint16 exit = 0xFFFF; - if (xpos < 12) { - exit = _walkBlockWest; - } else if (xpos >= 308) { - exit = _walkBlockEast; - } else if (ypos >= 136) { - exit = _walkBlockSouth; - } else if (ypos < 12) { - exit = _walkBlockNorth; - } - - if (exit != 0xFFFF) { - _abortWalkFlag2 = true; - handleSceneChange(xpos, ypos, 1, 1); - _abortWalkFlag2 = false; - return; - } else { - int script = checkForNPCScriptRun(xpos, ypos); - if (script >= 0) { - runNpcScript(script); - return; - } - if (_itemInHand != -1) { - if (ypos < 155) { - if (hasClickedOnExit(xpos, ypos)) { - _abortWalkFlag2 = true; - handleSceneChange(xpos, ypos, 1, 1); - _abortWalkFlag2 = false; - return; - } - dropItem(0, _itemInHand, xpos, ypos, 1); - } - } else { - if (ypos <= 155) { - _abortWalkFlag2 = true; - handleSceneChange(xpos, ypos, 1, 1); - _abortWalkFlag2 = false; - } - } - } - } -} - -int KyraEngine::processInputHelper(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::processInputHelper(%d, %d)", xpos, ypos); - uint8 item = findItemAtPos(xpos, ypos); - if (item != 0xFF) { - if (_itemInHand == -1) { - _screen->hideMouse(); - _animator->animRemoveGameItem(item); - snd_playSoundEffect(53); - assert(_currentCharacter->sceneId < _roomTableSize); - Room *currentRoom = &_roomTable[_currentCharacter->sceneId]; - int item2 = currentRoom->itemsTable[item]; - currentRoom->itemsTable[item] = 0xFF; - setMouseItem(item2); - assert(_itemList && _takenList); - updateSentenceCommand(_itemList[item2], _takenList[0], 179); - _itemInHand = item2; - _screen->showMouse(); - clickEventHandler2(); - return 1; - } else { - exchangeItemWithMouseItem(_currentCharacter->sceneId, item); - return 1; - } - } - return 0; -} - -int KyraEngine::clickEventHandler(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::clickEventHandler(%d, %d)", xpos, ypos); - _scriptInterpreter->initScript(_scriptClick, _scriptClickData); - _scriptClick->regs[1] = xpos; - _scriptClick->regs[2] = ypos; - _scriptClick->regs[3] = 0; - _scriptClick->regs[4] = _itemInHand; - _scriptInterpreter->startScript(_scriptClick, 1); - - while (_scriptInterpreter->validScript(_scriptClick)) - _scriptInterpreter->runScript(_scriptClick); - - return _scriptClick->regs[3]; -} - -void KyraEngine::updateMousePointer(bool forceUpdate) { - int shape = 0; - - int newMouseState = 0; - int newX = 0; - int newY = 0; - Common::Point mouse = getMousePos(); - if (mouse.y <= 158) { - if (mouse.x >= 12) { - if (mouse.x >= 308) { - if (_walkBlockEast == 0xFFFF) { - newMouseState = -2; - } else { - newMouseState = -5; - shape = 3; - newX = 7; - newY = 5; - } - } else if (mouse.y >= 136) { - if (_walkBlockSouth == 0xFFFF) { - newMouseState = -2; - } else { - newMouseState = -4; - shape = 4; - newX = 5; - newY = 7; - } - } else if (mouse.y < 12) { - if (_walkBlockNorth == 0xFFFF) { - newMouseState = -2; - } else { - newMouseState = -6; - shape = 2; - newX = 5; - newY = 1; - } - } - } else { - if (_walkBlockWest == 0xFFFF) { - newMouseState = -2; - } else { - newMouseState = -3; - newX = 1; - newY = shape = 5; - } - } - } - - if (mouse.x >= _entranceMouseCursorTracks[0] && mouse.y >= _entranceMouseCursorTracks[1] - && mouse.x <= _entranceMouseCursorTracks[2] && mouse.y <= _entranceMouseCursorTracks[3]) { - switch (_entranceMouseCursorTracks[4]) { - case 0: - newMouseState = -6; - shape = 2; - newX = 5; - newY = 1; - break; - - case 2: - newMouseState = -5; - shape = 3; - newX = 7; - newY = 5; - break; - - case 4: - newMouseState = -4; - shape = 4; - newX = 5; - newY = 7; - break; - - case 6: - newMouseState = -3; - shape = 5; - newX = 1; - newY = 5; - break; - - default: - break; - } - } - - if (newMouseState == -2) { - shape = 6; - newX = 4; - newY = 4; - } - - if ((newMouseState && _mouseState != newMouseState) || (newMouseState && forceUpdate)) { - _mouseState = newMouseState; - _screen->hideMouse(); - _screen->setMouseCursor(newX, newY, _shapes[shape]); - _screen->showMouse(); - } - - if (!newMouseState) { - if (_mouseState != _itemInHand || forceUpdate) { - if (mouse.y > 158 || (mouse.x >= 12 && mouse.x < 308 && mouse.y < 136 && mouse.y >= 12) || forceUpdate) { - _mouseState = _itemInHand; - _screen->hideMouse(); - if (_itemInHand == -1) { - _screen->setMouseCursor(1, 1, _shapes[0]); - } else { - _screen->setMouseCursor(8, 15, _shapes[216+_itemInHand]); - } - _screen->showMouse(); - } - } +void KyraEngine::delayUntil(uint32 timestamp, bool updateTimers, bool update, bool isMainLoop) { + while (_system->getMillis() < timestamp && !_quitFlag) { + if (timestamp - _system->getMillis() >= 10) + delay(10, update, isMainLoop); } } -bool KyraEngine::hasClickedOnExit(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::hasClickedOnExit(%d, %d)", xpos, ypos); - if (xpos < 16 || xpos >= 304) - return true; - - if (ypos < 8) - return true; - - if (ypos < 136 || ypos > 155) - return false; - - return true; -} - -void KyraEngine::clickEventHandler2() { - debugC(9, kDebugLevelMain, "KyraEngine::clickEventHandler2()"); - - Common::Point mouse = getMousePos(); - - _scriptInterpreter->initScript(_scriptClick, _scriptClickData); - _scriptClick->regs[0] = _currentCharacter->sceneId; - _scriptClick->regs[1] = mouse.x; - _scriptClick->regs[2] = mouse.y; - _scriptClick->regs[4] = _itemInHand; - _scriptInterpreter->startScript(_scriptClick, 6); - - while (_scriptInterpreter->validScript(_scriptClick)) - _scriptInterpreter->runScript(_scriptClick); -} - -int KyraEngine::checkForNPCScriptRun(int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::checkForNPCScriptRun(%d, %d)", xpos, ypos); - int returnValue = -1; - const Character *currentChar = _currentCharacter; - int charLeft = 0, charRight = 0, charTop = 0, charBottom = 0; - - int scaleFactor = _scaleTable[currentChar->y1]; - int addX = (((scaleFactor*8)*3)>>8)>>1; - int addY = ((scaleFactor*3)<<4)>>8; - - charLeft = currentChar->x1 - addX; - charRight = currentChar->x1 + addX; - charTop = currentChar->y1 - addY; - charBottom = currentChar->y1; - - if (xpos >= charLeft && charRight >= xpos && charTop <= ypos && charBottom >= ypos) - return 0; - - if (xpos > 304 || xpos < 16) - return -1; - - for (int i = 1; i < 5; ++i) { - currentChar = &_characterList[i]; - - if (currentChar->sceneId != _currentCharacter->sceneId) - continue; - - charLeft = currentChar->x1 - 12; - charRight = currentChar->x1 + 11; - charTop = currentChar->y1 - 48; - // if (!i) { - // charBottom = currentChar->y2 - 16; - // } else { - charBottom = currentChar->y1; - // } - - if (xpos < charLeft || xpos > charRight || ypos < charTop || charBottom < ypos) - continue; - - if (returnValue != -1) { - if (currentChar->y1 >= _characterList[returnValue].y1) - returnValue = i; - } else { - returnValue = i; - } - } - - return returnValue; +void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { + _system->delayMillis(amount); } -void KyraEngine::runNpcScript(int func) { - debugC(9, kDebugLevelMain, "KyraEngine::runNpcScript(%d)", func); - _scriptInterpreter->initScript(_npcScript, _npcScriptData); - _scriptInterpreter->startScript(_npcScript, func); - _npcScript->regs[0] = _currentCharacter->sceneId; - _npcScript->regs[4] = _itemInHand; - _npcScript->regs[5] = func; - - while (_scriptInterpreter->validScript(_npcScript)) - _scriptInterpreter->runScript(_npcScript); +void KyraEngine::delayWithTicks(int ticks) { + delay(ticks * _tickLength); } } // End of namespace Kyra diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h index bb41a68e6b..7d795abd7c 100644 --- a/engines/kyra/kyra.h +++ b/engines/kyra/kyra.h @@ -33,24 +33,7 @@ namespace Kyra { -class Movie; -class Sound; -class SoundDigital; -class SeqPlayer; -class Resource; -class PAKFile; -class Screen; -class Sprites; -class ScriptHelper; -class Debugger; -class ScreenAnimator; -class TextDisplayer; -class KyraEngine; -class StaticResource; - struct Opcode; -struct ScriptState; -struct ScriptData; struct GameFlags { Common::Language lang; @@ -62,6 +45,11 @@ struct GameFlags { byte gameID; }; +struct Rect { + int x, y; + int x2, y2; +}; + enum { GI_KYRA1 = 0, GI_KYRA2 = 1, @@ -83,839 +71,80 @@ enum kDebugLevels { kDebugLevelMovie = 1 << 9 // prints debug output of movie specific funtions }; -struct Character { - uint16 sceneId; - uint8 height; - uint8 facing; - uint16 currentAnimFrame; - uint8 inventoryItems[10]; - int16 x1, y1, x2, y2; -}; - -struct Shape { - uint8 imageIndex; - int8 xOffset, yOffset; - uint8 x, y, w, h; -}; - -struct Room { - uint8 nameIndex; - uint16 northExit; - uint16 eastExit; - uint16 southExit; - uint16 westExit; - uint8 itemsTable[12]; - uint16 itemsXPos[12]; - uint8 itemsYPos[12]; - uint8 needInit[12]; -}; - -struct Rect { - int x, y; - int x2, y2; -}; - -struct Item { - uint8 unk1; - uint8 height; - uint8 unk2; - uint8 unk3; -}; - -struct SeqLoop { - const uint8 *ptr; - uint16 count; -}; - -struct SceneExits { - uint16 northXPos; - uint8 northYPos; - uint16 eastXPos; - uint8 eastYPos; - uint16 southXPos; - uint8 southYPos; - uint16 westXPos; - uint8 westYPos; -}; - -struct BeadState { - int16 x; - int16 y; - int16 width; - int16 height; - int16 dstX; - int16 dstY; - int16 width2; - int16 unk8; - int16 unk9; - int16 tableIndex; -}; - -struct Timer { - uint8 active; - int32 countdown; - uint32 nextRun; - void (KyraEngine::*func)(int timerNum); -}; - -struct Button { - Button *nextButton; - uint16 specialValue; - // uint8 unk[4]; - uint8 process0; - uint8 process1; - uint8 process2; - // uint8 unk - uint16 flags; - typedef int (KyraEngine::*ButtonCallback)(Button*); - // using 6 pointers instead of 3 as in the orignal here (safer for use with classes) - uint8 *process0PtrShape; - uint8 *process1PtrShape; - uint8 *process2PtrShape; - ButtonCallback process0PtrCallback; - ButtonCallback process1PtrCallback; - ButtonCallback process2PtrCallback; - uint16 dimTableIndex; - uint16 x; - uint16 y; - uint16 width; - uint16 height; - // uint8 unk[8]; - uint32 flags2; - ButtonCallback buttonCallback; - // uint8 unk[8]; -}; - -struct MenuItem { - bool enabled; - uint16 field_1; - uint8 field_3; - const char *itemString; - int16 x; - int16 field_9; - uint16 y; - uint16 width; - uint16 height; - uint8 textColor; - uint8 highlightColor; - int16 field_12; - uint8 field_13; - uint8 bgcolor; - uint8 color1; - uint8 color2; - int (KyraEngine::*callback)(Button*); - int16 field_1b; - const char *labelString; - uint16 labelX; - uint8 labelY; - uint8 field_24; - uint32 field_25; -}; - -struct Menu { - int16 x; - int16 y; - uint16 width; - uint16 height; - uint8 bgcolor; - uint8 color1; - uint8 color2; - const char *menuName; - uint8 textColor; - int16 field_10; - uint16 field_12; - uint16 highlightedItem; - uint8 nrOfItems; - int16 scrollUpBtnX; - int16 scrollUpBtnY; - int16 scrollDownBtnX; - int16 scrollDownBtnY; - MenuItem item[6]; -}; +class Screen; +class Resource; +class Sound; +class Movie; +class TextDisplayer; +class StaticResource; class KyraEngine : public Engine { - friend class MusicPlayer; - friend class Debugger; - friend class ScreenAnimator; public: KyraEngine(OSystem *system, const GameFlags &flags); virtual ~KyraEngine(); - + + bool quit() const { return _quitFlag; } + + uint8 game() const { return _flags.gameID; } + const GameFlags &gameFlags() const { return _flags; } + + // access to Kyra specific functionallity Resource *resource() { return _res; } - Screen *screen() { return _screen; } - ScreenAnimator *animator() { return _animator; } + virtual Screen *screen() = 0; TextDisplayer *text() { return _text; } Sound *sound() { return _sound; } StaticResource *staticres() { return _staticres; } + uint32 tickLength() const { return _tickLength; } - virtual Movie *createWSAMovie(); - - uint8 game() const { return _flags.gameID; } - const GameFlags &gameFlags() const { return _flags; } - - uint8 **shapes() { return _shapes; } - Character *currentCharacter() { return _currentCharacter; } - Character *characterList() { return _characterList; } - uint16 brandonStatus() { return _brandonStatusBit; } - - // TODO: remove me with workaround in animator.cpp l209 - uint16 getScene() { return _currentRoom; } - - bool quit() const { return _quitFlag; } - - int _paletteChanged; - Common::RandomSource _rnd; - int16 _northExitHeight; - - typedef void (KyraEngine::*IntroProc)(); - - // static data access - const char * const*seqWSATable() { return _seq_WSATable; } - const char * const*seqCPSTable() { return _seq_CPSTable; } - const char * const*seqCOLTable() { return _seq_COLTable; } - const char * const*seqTextsTable() { return _seq_textsTable; } - const uint8 * const*palTable1() { return &_specialPalettes[0]; } - const uint8 * const*palTable2() { return &_specialPalettes[29]; } - - // sequences - // -> misc - bool seq_skipSequence() const; - -protected: - // -> demo - void seq_demo(); - - // -> intro - void seq_intro(); - void seq_introLogos(); - void seq_introStory(); - void seq_introMalcolmTree(); - void seq_introKallakWriting(); - void seq_introKallakMalcolm(); - - // -> ingame animations - void seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly); - void seq_brandonHealing(); - void seq_brandonHealing2(); - void seq_poisonDeathNow(int now); - void seq_poisonDeathNowAnim(); - void seq_playFluteAnimation(); - void seq_winterScroll1(); - void seq_winterScroll2(); - void seq_makeBrandonInv(); - void seq_makeBrandonNormal(); - void seq_makeBrandonNormal2(); - void seq_makeBrandonWisp(); - void seq_dispelMagicAnimation(); - void seq_fillFlaskWithWater(int item, int type); - void seq_playDrinkPotionAnim(int item, int unk2, int flags); - void seq_brandonToStone(); - - // -> end fight - int seq_playEnd(); - void seq_playEnding(); - - int handleMalcolmFlag(); - int handleBeadState(); - void initBeadState(int x, int y, int x2, int y2, int unk1, BeadState *ptr); - int processBead(int x, int y, int &x2, int &y2, BeadState *ptr); - - // -> credits - void seq_playCredits(); - -public: - // delay - void delayUntil(uint32 timestamp, bool updateGameTimers = false, bool update = false, bool isMainLoop = false); - void delay(uint32 millis, bool update = false, bool isMainLoop = false); - void delayWithTicks(int ticks); - void waitForEvent(); - - // TODO - void quitGame(); - - void registerDefaultSettings(); - void readSettings(); - void writeSettings(); - - void snd_playTheme(int file, int track = 0); - void snd_playVoiceFile(int id); - void snd_voiceWaitForFinish(bool ingame = true); - bool snd_voiceIsPlaying(); - void snd_stopVoice(); - void snd_playSoundEffect(int track); - void snd_playWanderScoreViaMap(int command, int restart); - - bool speechEnabled(); - bool textEnabled(); + virtual Movie *createWSAMovie() = 0; - void updateGameTimers(); - void clearNextEventTickCount(); - void setTimerCountdown(uint8 timer, int32 countdown); - void setTimerDelay(uint8 timer, int32 countdown); - int16 getTimerDelay(uint8 timer); - void enableTimer(uint8 timer); - void disableTimer(uint8 timer); - - void saveGame(const char *fileName, const char *saveName); - void loadGame(const char *fileName); - - Common::Point getMousePos() const; + Common::RandomSource _rnd; + + // quit handling + virtual void quitGame(); + // game flag handling int setGameFlag(int flag); - int queryGameFlag(int flag); + int queryGameFlag(int flag) const; int resetGameFlag(int flag); -protected: - virtual int go(); - virtual int init(); - - // input - void processInput(); - int processInputHelper(int xpos, int ypos); - int clickEventHandler(int xpos, int ypos); - void clickEventHandler2(); - void updateMousePointer(bool forceUpdate = false); - bool hasClickedOnExit(int xpos, int ypos); - - // scene - // -> init - void loadSceneMsc(); - void startSceneScript(int brandonAlive); - void setupSceneItems(); - void initSceneData(int facing, int unk1, int brandonAlive); - void initSceneObjectList(int brandonAlive); - void initSceneScreen(int brandonAlive); - void setupSceneResource(int sceneId); - - // -> process - void enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive); - int handleSceneChange(int xpos, int ypos, int unk1, int frameReset); - int processSceneChange(int *table, int unk1, int frameReset); - int changeScene(int facing); - - // -> modification - void transcendScenes(int roomIndex, int roomName); - void setSceneFile(int roomIndex, int roomName); - - // -> pathfinder - int findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize); - int findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end); - int getFacingFromPointToPoint(int x, int y, int toX, int toY); - void changePosTowardsFacing(int &x, int &y, int facing); - bool lineIsPassable(int x, int y); - int getMoveTableSize(int *moveTable); - - // -> item handling - // --> misc - void addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y); - - // --> drop handling - void itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item); - int processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2); - void dropItem(int unk1, int item, int x, int y, int unk2); - - // --> dropped item handling - int countItemsInScene(uint16 sceneId); - void exchangeItemWithMouseItem(uint16 sceneId, int itemIndex); - byte findFreeItemInScene(int scene); - byte findItemAtPos(int x, int y); - - // --> drop area handling - void addToNoDropRects(int x, int y, int w, int h); - void clearNoDropRects(); - int isDropable(int x, int y); - int checkNoDropRects(int x, int y); - - // --> player items handling - void updatePlayerItemsForScene(); - - // --> item GFX handling - void backUpItemRect0(int xpos, int ypos); - void restoreItemRect0(int xpos, int ypos); - void backUpItemRect1(int xpos, int ypos); - void restoreItemRect1(int xpos, int ypos); - - // items - // -> misc - void placeItemInGenericMapScene(int item, int index); - - // -> mouse item - void createMouseItem(int item); - void destroyMouseItem(); - void setMouseItem(int item); - - // -> graphics effects - void wipeDownMouseItem(int xpos, int ypos); - void itemSpecialFX(int x, int y, int item); - void itemSpecialFX1(int x, int y, int item); - void itemSpecialFX2(int x, int y, int item); - void magicOutMouseItem(int animIndex, int itemPos); - void magicInMouseItem(int animIndex, int item, int itemPos); - void specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops); - void processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops); - - // character - // -> movement - void moveCharacterToPos(int character, int facing, int xpos, int ypos); - void setCharacterPositionWithUpdate(int character); - int setCharacterPosition(int character, int *facingTable); - void setCharacterPositionHelper(int character, int *facingTable); - int getOppositeFacingDirection(int dir); - void setCharactersPositions(int character); - - // -> brandon - void setBrandonPoisonFlags(int reset); - void resetBrandonPoisonFlags(); - - // chat - // -> process - void characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration); - void waitForChatToFinish(int vocFile, int16 chatDuration, const char *str, uint8 charNum); - - // -> initialization - int initCharacterChat(int8 charNum); - void backupChatPartnerAnimFrame(int8 charNum); - void restoreChatPartnerAnimFrame(int8 charNum); - int8 getChatPartnerNum(); - - // -> deinitialization - void endCharacterChat(int8 charNum, int16 arg_4); - - // graphics - // -> misc - int findDuplicateItemShape(int shape); - void updateKyragemFading(); - - // -> interface - void loadMainScreen(int page = 3); - void redrawInventory(int page); -public: - void drawSentenceCommand(const char *sentence, int unk1); - void updateSentenceCommand(const char *str1, const char *str2, int unk1); - void updateTextFade(); - -protected: - // -> amulet - void drawJewelPress(int jewel, int drawSpecial); - void drawJewelsFadeOutStart(); - void drawJewelsFadeOutEnd(int jewel); - - // -> shape handling - void setupShapes123(const Shape *shapeTable, int endShape, int flags); - void freeShapes123(); - - // misc (TODO) - void startup(); - void mainLoop(); - - int checkForNPCScriptRun(int xpos, int ypos); - void runNpcScript(int func); - - virtual void setupOpcodeTable() = 0; - Common::Array<const Opcode*> _opcodes; - - void loadMouseShapes(); - void loadCharacterShapes(); - void loadSpecialEffectShapes(); - void loadItems(); - void loadButtonShapes(); - void initMainButtonList(); - void setCharactersInDefaultScene(); - void setupPanPages(); - void freePanPages(); - void closeFinalWsa(); - void setTimer19(); - void setupTimers(); - void timerUpdateHeadAnims(int timerNum); - void timerSetFlags1(int timerNum); - void timerSetFlags2(int timerNum); - void timerSetFlags3(int timerNum); - void timerCheckAnimFlag1(int timerNum); - void timerCheckAnimFlag2(int timerNum); - void checkAmuletAnimFlags(); - void timerRedrawAmulet(int timerNum); - void timerFadeText(int timerNum); - void updateAnimFlag1(int timerNum); - void updateAnimFlag2(int timerNum); - void drawAmulet(); - void setTextFadeTimerCountdown(int16 countdown); - void setWalkspeed(uint8 newSpeed); + // delay functionallity + virtual void delayUntil(uint32 timestamp, bool updateGameTimers = false, bool update = false, bool isMainLoop = false); + virtual void delay(uint32 millis, bool update = false, bool isMainLoop = false); + virtual void delayWithTicks(int ticks); - int buttonInventoryCallback(Button *caller); - int buttonAmuletCallback(Button *caller); - int buttonMenuCallback(Button *caller); - int drawBoxCallback(Button *button); - int drawShadedBoxCallback(Button *button); - void calcCoords(Menu &menu); - void initMenu(Menu &menu); - void setGUILabels(); - - Button *initButton(Button *list, Button *newButton); - void processButtonList(Button *list); - void processButton(Button *button); - void processMenuButton(Button *button); - void processAllMenuButtons(); - - const char *getSavegameFilename(int num); - void setupSavegames(Menu &menu, int num); - int getNextSavegameSlot(); - - int gui_resumeGame(Button *button); - int gui_loadGameMenu(Button *button); - int gui_saveGameMenu(Button *button); - int gui_gameControlsMenu(Button *button); - int gui_quitPlaying(Button *button); - int gui_quitConfirmYes(Button *button); - int gui_quitConfirmNo(Button *button); - int gui_loadGame(Button *button); - int gui_saveGame(Button *button); - int gui_savegameConfirm(Button *button); - int gui_cancelSubMenu(Button *button); - int gui_scrollUp(Button *button); - int gui_scrollDown(Button *button); - int gui_controlsChangeMusic(Button *button); - int gui_controlsChangeSounds(Button *button); - int gui_controlsChangeWalk(Button *button); - int gui_controlsChangeText(Button *button); - int gui_controlsChangeVoice(Button *button); - int gui_controlsApply(Button *button); - - bool gui_quitConfirm(const char *str); - void gui_getInput(); - void gui_redrawText(Menu menu); - void gui_redrawHighlight(Menu menu); - void gui_processHighlights(Menu &menu); - void gui_updateSavegameString(); - void gui_redrawTextfield(); - void gui_fadePalette(); - void gui_restorePalette(); - void gui_setupControls(Menu &menu); - - // Kyra 2 and 3 main menu - - static const char *_mainMenuStrings[]; - virtual void gui_initMainMenu() {} - int gui_handleMainMenu(); - virtual void gui_updateMainMenuAnimation(); - void gui_drawMainMenu(const char * const *strings, int select); - void gui_drawMainBox(int x, int y, int w, int h, int fill); - bool gui_mainMenuGetInput(); +protected: + virtual int go() = 0; + virtual int init(); - void gui_printString(const char *string, int x, int y, int col1, int col2, int flags, ...); - - GameFlags _flags; + // quit Handling bool _quitFlag; - bool _skipFlag; - bool _skipIntroFlag; - bool _abortIntroFlag; - bool _menuDirectlyToLoad; - bool _abortWalkFlag; - bool _abortWalkFlag2; - bool _mousePressFlag; - int8 _mouseWheel; - uint8 _flagsTable[69]; - uint8 *_itemBkgBackUp[2]; - uint8 *_shapes[373]; - uint16 _gameSpeed; - uint16 _tickLength; - int _lang; - int8 _itemInHand; - int _mouseState; - bool _handleInput; - bool _changedScene; - int _unkScreenVar1, _unkScreenVar2, _unkScreenVar3; - int _beadStateVar; - int _unkAmuletVar; - - int _malcolmFlag; - int _endSequenceSkipFlag; - int _endSequenceNeedLoading; - int _unkEndSeqVar2; - uint8 *_endSequenceBackUpRect; - int _unkEndSeqVar4; - int _unkEndSeqVar5; - int _lastDisplayedPanPage; - uint8 *_panPagesTable[20]; - Movie *_finalA, *_finalB, *_finalC; - - Movie *_movieObjects[10]; - - uint16 _entranceMouseCursorTracks[8]; - uint16 _walkBlockNorth; - uint16 _walkBlockEast; - uint16 _walkBlockSouth; - uint16 _walkBlockWest; - - int32 _scaleMode; - int16 _scaleTable[145]; - - Rect _noDropRects[11]; - - int8 _birthstoneGemTable[4]; - int8 _idolGemsTable[3]; - - int8 _marbleVaseItem; - int8 _foyerItemTable[3]; - - int8 _cauldronState; - int8 _crystalState[2]; - - uint16 _brandonStatusBit; - uint8 _brandonStatusBit0x02Flag; - uint8 _brandonStatusBit0x20Flag; - uint8 _brandonPoisonFlagsGFX[256]; - uint8 _deathHandler; - int16 _brandonInvFlag; - uint8 _poisonDeathCounter; - int _brandonPosX; - int _brandonPosY; - - uint16 _currentChatPartnerBackupFrame; - uint16 _currentCharAnimFrame; - int8 *_sceneAnimTable[50]; - - Item _itemTable[145]; - int _lastProcessedItem; - int _lastProcessedItemHeight; - - int16 *_exitListPtr; - int16 _exitList[11]; - SceneExits _sceneExits; - uint16 _currentRoom; - int _scenePhasingFlag; - - int _sceneChangeState; - int _loopFlag2; - - int _pathfinderFlag; - int _pathfinderFlag2; - int _lastFindWayRet; - int *_movFacingTable; - - int8 _talkingCharNum; - int8 _charSayUnk2; - int8 _charSayUnk3; - int8 _currHeadShape; - uint8 _currSentenceColor[3]; - int8 _startSentencePalIndex; - bool _fadeText; - - uint8 _configTextspeed; - uint8 _configWalkspeed; - int _configMusic; - bool _configSounds; - uint8 _configVoice; - - int _curMusicTheme; - int _curSfxFile; - int16 _lastMusicCommand; - + // intern Resource *_res; Screen *_screen; - ScreenAnimator *_animator; Sound *_sound; - SeqPlayer *_seq; - Sprites *_sprites; TextDisplayer *_text; - ScriptHelper *_scriptInterpreter; - Debugger *_debugger; StaticResource *_staticres; - - ScriptState *_scriptMain; - - ScriptState *_npcScript; - ScriptData *_npcScriptData; - - ScriptState *_scriptClick; - ScriptData *_scriptClickData; - - Character *_characterList; - Character *_currentCharacter; - - Button *_buttonList; - Button *_menuButtonList; - bool _displayMenu; - bool _menuRestoreScreen; - bool _displaySubMenu; - bool _cancelSubMenu; - uint8 _toplevelMenu; - int _savegameOffset; - int _gameToLoad; - char _savegameName[31]; - const char *_specialSavegameString; - Common::KeyState _keyPressed; - - struct KyragemState { - uint16 nextOperation; - uint16 rOffset; - uint16 gOffset; - uint16 bOffset; - uint32 timerCount; - } _kyragemFadingState; - - // TODO: get rid of all variables having pointers to the static resources if possible - // i.e. let them directly use the _staticres functions - void initStaticResource(); - - const uint8 *_seq_Forest; - const uint8 *_seq_KallakWriting; - const uint8 *_seq_KyrandiaLogo; - const uint8 *_seq_KallakMalcolm; - const uint8 *_seq_MalcolmTree; - const uint8 *_seq_WestwoodLogo; - const uint8 *_seq_Demo1; - const uint8 *_seq_Demo2; - const uint8 *_seq_Demo3; - const uint8 *_seq_Demo4; - const uint8 *_seq_Reunion; - - const char * const*_seq_WSATable; - const char * const*_seq_CPSTable; - const char * const*_seq_COLTable; - const char * const*_seq_textsTable; - - int _seq_WSATable_Size; - int _seq_CPSTable_Size; - int _seq_COLTable_Size; - int _seq_textsTable_Size; - - const char * const*_itemList; - const char * const*_takenList; - const char * const*_placedList; - const char * const*_droppedList; - const char * const*_noDropList; - const char * const*_putDownFirst; - const char * const*_waitForAmulet; - const char * const*_blackJewel; - const char * const*_poisonGone; - const char * const*_healingTip; - const char * const*_thePoison; - const char * const*_fluteString; - const char * const*_wispJewelStrings; - const char * const*_magicJewelString; - const char * const*_flaskFull; - const char * const*_fullFlask; - const char * const*_veryClever; - const char * const*_homeString; - const char * const*_newGameString; - - const char *_voiceTextString; - const char *_textSpeedString; - const char *_onString; - const char *_offString; - const char *_onCDString; - - int _itemList_Size; - int _takenList_Size; - int _placedList_Size; - int _droppedList_Size; - int _noDropList_Size; - int _putDownFirst_Size; - int _waitForAmulet_Size; - int _blackJewel_Size; - int _poisonGone_Size; - int _healingTip_Size; - int _thePoison_Size; - int _fluteString_Size; - int _wispJewelStrings_Size; - int _magicJewelString_Size; - int _flaskFull_Size; - int _fullFlask_Size; - int _veryClever_Size; - int _homeString_Size; - int _newGameString_Size; - - const char * const*_characterImageTable; - int _characterImageTableSize; - - const char * const*_guiStrings; - int _guiStringsSize; - - const char * const*_configStrings; - int _configStringsSize; - Shape *_defaultShapeTable; - int _defaultShapeTableSize; - - const Shape *_healingShapeTable; - int _healingShapeTableSize; - const Shape *_healingShape2Table; - int _healingShape2TableSize; - - const Shape *_posionDeathShapeTable; - int _posionDeathShapeTableSize; - - const Shape *_fluteAnimShapeTable; - int _fluteAnimShapeTableSize; - - const Shape *_winterScrollTable; - int _winterScrollTableSize; - const Shape *_winterScroll1Table; - int _winterScroll1TableSize; - const Shape *_winterScroll2Table; - int _winterScroll2TableSize; - - const Shape *_drinkAnimationTable; - int _drinkAnimationTableSize; - - const Shape *_brandonToWispTable; - int _brandonToWispTableSize; - - const Shape *_magicAnimationTable; - int _magicAnimationTableSize; - - const Shape *_brandonStoneTable; - int _brandonStoneTableSize; - - Room *_roomTable; - int _roomTableSize; - const char * const*_roomFilenameTable; - int _roomFilenameTableSize; - - const uint8 *_amuleteAnim; + // game speed + bool _skipFlag; + uint16 _tickLength; - const uint8 * const*_specialPalettes; - - Timer _timers[34]; - uint32 _timerNextRun; + // detection + GameFlags _flags; + int _lang; - static const char *_soundFiles[]; - static const int _soundFilesCount; - static const char *_soundFilesTowns[]; - static const int _soundFilesTownsCount; + // opcode + virtual void setupOpcodeTable() = 0; + Common::Array<const Opcode*> _opcodes; - static const int8 _charXPosTable[]; - static const int8 _addXPosTable[]; - static const int8 _charYPosTable[]; - static const int8 _addYPosTable[]; - - // positions of the inventory - static const uint16 _itemPosX[]; - static const uint8 _itemPosY[]; + // game flags + uint8 _flagsTable[100]; // TODO: check this value - void setupButtonData(); - Button *_buttonData; - Button **_buttonDataListPtr; - static Button _menuButtonData[]; - static Button _scrollUpButton; - static Button _scrollDownButton; - - bool _haveScrollButtons; - - void setupMenu(); - Menu *_menu; - - static const uint8 _magicMouseItemStartFrame[]; - static const uint8 _magicMouseItemEndFrame[]; - static const uint8 _magicMouseItemStartFrame2[]; - static const uint8 _magicMouseItemEndFrame2[]; - - static const uint16 _amuletX[]; - static const uint16 _amuletY[]; - static const uint16 _amuletX2[]; - static const uint16 _amuletY2[]; + // input + Common::Point getMousePos() const; }; } // End of namespace Kyra diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp index 3246e0f426..404e62403a 100644 --- a/engines/kyra/kyra_v1.cpp +++ b/engines/kyra/kyra_v1.cpp @@ -25,13 +25,982 @@ #include "kyra/kyra_v1.h" +#include "common/file.h" +#include "common/events.h" +#include "common/system.h" +#include "common/savefile.h" + +#include "gui/message.h" + +#include "kyra/resource.h" +#include "kyra/screen.h" +#include "kyra/script.h" +#include "kyra/seqplayer.h" +#include "kyra/sound.h" +#include "kyra/sprites.h" +#include "kyra/wsamovie.h" +#include "kyra/animator_v1.h" +#include "kyra/text.h" +#include "kyra/debugger.h" + namespace Kyra { KyraEngine_v1::KyraEngine_v1(OSystem *system, const GameFlags &flags) : KyraEngine(system, flags) { + _flags = flags; + + _seq_Forest = _seq_KallakWriting = _seq_KyrandiaLogo = _seq_KallakMalcolm = + _seq_MalcolmTree = _seq_WestwoodLogo = _seq_Demo1 = _seq_Demo2 = _seq_Demo3 = + _seq_Demo4 = 0; + + _seq_WSATable = _seq_CPSTable = _seq_COLTable = _seq_textsTable = 0; + _seq_WSATable_Size = _seq_CPSTable_Size = _seq_COLTable_Size = _seq_textsTable_Size = 0; + + _roomFilenameTable = _characterImageTable = 0; + _roomFilenameTableSize = _characterImageTableSize = 0; + _itemList = _takenList = _placedList = _droppedList = _noDropList = 0; + _itemList_Size = _takenList_Size = _placedList_Size = _droppedList_Size = _noDropList_Size = 0; + _putDownFirst = _waitForAmulet = _blackJewel = _poisonGone = _healingTip = 0; + _putDownFirst_Size = _waitForAmulet_Size = _blackJewel_Size = _poisonGone_Size = _healingTip_Size = 0; + _thePoison = _fluteString = _wispJewelStrings = _magicJewelString = _flaskFull = _fullFlask = 0; + _thePoison_Size = _fluteString_Size = _wispJewelStrings_Size = 0; + _magicJewelString_Size = _flaskFull_Size = _fullFlask_Size = 0; + + _defaultShapeTable = 0; + _healingShapeTable = _healingShape2Table = 0; + _defaultShapeTableSize = _healingShapeTableSize = _healingShape2TableSize = 0; + _posionDeathShapeTable = _fluteAnimShapeTable = 0; + _posionDeathShapeTableSize = _fluteAnimShapeTableSize = 0; + _winterScrollTable = _winterScroll1Table = _winterScroll2Table = 0; + _winterScrollTableSize = _winterScroll1TableSize = _winterScroll2TableSize = 0; + _drinkAnimationTable = _brandonToWispTable = _magicAnimationTable = _brandonStoneTable = 0; + _drinkAnimationTableSize = _brandonToWispTableSize = _magicAnimationTableSize = _brandonStoneTableSize = 0; + memset(&_specialPalettes, 0, sizeof(_specialPalettes)); + _debugger = 0; + _sprites = 0; + _animator = 0; + _seq = 0; + _scriptInterpreter = 0; + _npcScriptData = 0; + _scriptMain = 0; + _scriptClickData = 0; + _scriptClick = 0; + _characterList = 0; + _movFacingTable = 0; + memset(_shapes, 0, sizeof(_shapes)); + memset(_movieObjects, 0, sizeof(_movieObjects)); + _finalA = _finalB = _finalC = 0; + _endSequenceBackUpRect = 0; + memset(_panPagesTable, 0, sizeof(_panPagesTable)); + _npcScriptData = _scriptClickData = 0; + _scrollUpButton.process0PtrShape = _scrollUpButton.process1PtrShape = _scrollUpButton.process2PtrShape = 0; + _scrollDownButton.process0PtrShape = _scrollDownButton.process1PtrShape = _scrollDownButton.process2PtrShape = 0; + memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); + _currHeadShape = 0; + + _curSfxFile = _curMusicTheme = 0; + + memset(&_itemBkgBackUp, 0, sizeof(_itemBkgBackUp)); } KyraEngine_v1::~KyraEngine_v1() { + for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { + if (_movieObjects[i]) + _movieObjects[i]->close(); + delete _movieObjects[i]; + _movieObjects[i] = 0; + } + + closeFinalWsa(); + if (_scriptInterpreter) { + _scriptInterpreter->unloadScript(_npcScriptData); + _scriptInterpreter->unloadScript(_scriptClickData); + } + + Common::clearAllSpecialDebugLevels(); + + delete _screen; + delete _debugger; + delete _sprites; + delete _animator; + delete _seq; + delete _scriptInterpreter; + + delete _npcScriptData; + delete _scriptMain; + + delete _scriptClickData; + delete _scriptClick; + + delete [] _characterList; + + delete [] _movFacingTable; + + delete [] _scrollUpButton.process0PtrShape; + delete [] _scrollUpButton.process1PtrShape; + delete [] _scrollUpButton.process2PtrShape; + delete [] _scrollDownButton.process0PtrShape; + delete [] _scrollDownButton.process1PtrShape; + delete [] _scrollDownButton.process2PtrShape; + + delete [] _itemBkgBackUp[0]; + delete [] _itemBkgBackUp[1]; + + for (int i = 0; i < ARRAYSIZE(_shapes); ++i) { + if (_shapes[i] != 0) { + delete [] _shapes[i]; + for (int i2 = 0; i2 < ARRAYSIZE(_shapes); i2++) { + if (_shapes[i2] == _shapes[i] && i2 != i) { + _shapes[i2] = 0; + } + } + _shapes[i] = 0; + } + } + + for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) + delete [] _sceneAnimTable[i]; +} + +int KyraEngine_v1::init() { + _screen = new Screen_v1(this, _system); + assert(_screen); + if (!_screen->init()) + error("_screen->init() failed"); + + KyraEngine::init(); + + _sprites = new Sprites(this, _system); + assert(_sprites); + _seq = new SeqPlayer(this, _system); + assert(_seq); + _animator = new ScreenAnimator(this, _system); + assert(_animator); + _animator->init(5, 11, 12); + assert(*_animator); + + initStaticResource(); + + if (!_sound->init()) + error("Couldn't init sound"); + + if (_flags.platform == Common::kPlatformFMTowns) + _sound->setSoundFileList(_soundFilesTowns, _soundFilesTownsCount); + else + _sound->setSoundFileList(_soundFiles, _soundFilesCount); + + _sound->setVolume(255); + _sound->loadSoundFile(0); + + setupOpcodeTable(); + setupButtonData(); + setupMenu(); + + _paletteChanged = 1; + _currentCharacter = 0; + _characterList = new Character[11]; + assert(_characterList); + memset(_characterList, 0, sizeof(Character)*11); + + for (int i = 0; i < 11; ++i) + memset(_characterList[i].inventoryItems, 0xFF, sizeof(_characterList[i].inventoryItems)); + + _characterList[0].sceneId = 5; + _characterList[0].height = 48; + _characterList[0].facing = 3; + _characterList[0].currentAnimFrame = 7; + + _scriptInterpreter = new ScriptHelper(this); + assert(_scriptInterpreter); + + _npcScriptData = new ScriptData; + memset(_npcScriptData, 0, sizeof(ScriptData)); + assert(_npcScriptData); + _npcScript = new ScriptState; + assert(_npcScript); + memset(_npcScript, 0, sizeof(ScriptState)); + + _scriptMain = new ScriptState; + assert(_scriptMain); + memset(_scriptMain, 0, sizeof(ScriptState)); + + _scriptClickData = new ScriptData; + assert(_scriptClickData); + memset(_scriptClickData, 0, sizeof(ScriptData)); + _scriptClick = new ScriptState; + assert(_scriptClick); + memset(_scriptClick, 0, sizeof(ScriptState)); + + _debugger = new Debugger_v1(this); + assert(_debugger); + memset(_shapes, 0, sizeof(_shapes)); + + for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) + _movieObjects[i] = createWSAMovie(); + + memset(_flagsTable, 0, sizeof(_flagsTable)); + + _abortWalkFlag = false; + _abortWalkFlag2 = false; + _talkingCharNum = -1; + _charSayUnk3 = -1; + memset(_currSentenceColor, 0, 3); + _startSentencePalIndex = -1; + _fadeText = false; + + _cauldronState = 0; + _crystalState[0] = _crystalState[1] = -1; + + _brandonStatusBit = 0; + _brandonStatusBit0x02Flag = _brandonStatusBit0x20Flag = 10; + _brandonPosX = _brandonPosY = -1; + _deathHandler = 0xFF; + _poisonDeathCounter = 0; + + memset(_itemTable, 0, sizeof(_itemTable)); + memset(_exitList, 0xFFFF, sizeof(_exitList)); + _exitListPtr = 0; + _pathfinderFlag = _pathfinderFlag2 = 0; + _lastFindWayRet = 0; + _sceneChangeState = _loopFlag2 = 0; + _timerNextRun = 0; + + _movFacingTable = new int[150]; + assert(_movFacingTable); + _movFacingTable[0] = 8; + + registerDefaultSettings(); + readSettings(); + + _skipFlag = false; + + _marbleVaseItem = -1; + memset(_foyerItemTable, -1, sizeof(_foyerItemTable)); + _mouseState = _itemInHand = -1; + _handleInput = false; + + _currentRoom = 0xFFFF; + _scenePhasingFlag = 0; + _lastProcessedItem = 0; + _lastProcessedItemHeight = 16; + + _unkScreenVar1 = 1; + _unkScreenVar2 = 0; + _unkScreenVar3 = 0; + _unkAmuletVar = 0; + + _endSequenceNeedLoading = 1; + _malcolmFlag = 0; + _beadStateVar = 0; + _endSequenceSkipFlag = 0; + _unkEndSeqVar2 = 0; + _endSequenceBackUpRect = 0; + _unkEndSeqVar4 = 0; + _unkEndSeqVar5 = 0; + _lastDisplayedPanPage = 0; + memset(_panPagesTable, 0, sizeof(_panPagesTable)); + _finalA = _finalB = _finalC = 0; + memset(&_kyragemFadingState, 0, sizeof(_kyragemFadingState)); + _kyragemFadingState.gOffset = 0x13; + _kyragemFadingState.bOffset = 0x13; + + _mousePressFlag = false; + + _menuDirectlyToLoad = false; + + _lastMusicCommand = 0; + + _gameSpeed = 60; + _tickLength = (uint8)(1000.0 / _gameSpeed); + + return 0; +} + +int KyraEngine_v1::go() { + if (_res->getFileSize("6.FNT")) + _screen->loadFont(Screen::FID_6_FNT, "6.FNT"); + _screen->loadFont(Screen::FID_8_FNT, "8FAT.FNT"); + _screen->setScreenDim(0); + + _abortIntroFlag = false; + + if (_flags.isDemo) { + seq_demo(); + } else { + setGameFlag(0xF3); + setGameFlag(0xFD); + setGameFlag(0xEF); + seq_intro(); + if (_quitFlag) + return 0; + if (_skipIntroFlag && _abortIntroFlag) + resetGameFlag(0xEF); + startup(); + resetGameFlag(0xEF); + mainLoop(); + } + return 0; +} + + +void KyraEngine_v1::startup() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::startup()"); + static const uint8 colorMap[] = { 0, 0, 0, 0, 12, 12, 12, 0, 0, 0, 0, 0 }; + _screen->setTextColorMap(colorMap); +// _screen->setFont(Screen::FID_6_FNT); + _screen->setAnimBlockPtr(3750); + memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); + loadMouseShapes(); + _currentCharacter = &_characterList[0]; + for (int i = 1; i < 5; ++i) + _animator->setCharacterDefaultFrame(i); + for (int i = 5; i <= 10; ++i) + setCharactersPositions(i); + _animator->setCharactersHeight(); + resetBrandonPoisonFlags(); + _screen->_curPage = 0; + // XXX + for (int i = 0; i < 12; ++i) { + int size = _screen->getRectSize(3, 24); + _shapes[361+i] = new byte[size]; + } + + _itemBkgBackUp[0] = new uint8[_screen->getRectSize(3, 24)]; + memset(_itemBkgBackUp[0], 0, _screen->getRectSize(3, 24)); + _itemBkgBackUp[1] = new uint8[_screen->getRectSize(4, 32)]; + memset(_itemBkgBackUp[1], 0, _screen->getRectSize(4, 32)); + + for (int i = 0; i < _roomTableSize; ++i) { + for (int item = 0; item < 12; ++item) { + _roomTable[i].itemsTable[item] = 0xFF; + _roomTable[i].itemsXPos[item] = 0xFFFF; + _roomTable[i].itemsYPos[item] = 0xFF; + _roomTable[i].needInit[item] = 0; + } + } + + loadCharacterShapes(); + loadSpecialEffectShapes(); + loadItems(); + loadButtonShapes(); + initMainButtonList(); + loadMainScreen(); + setupTimers(); + _screen->loadPalette("PALETTE.COL", _screen->_currentPalette); + + // XXX + _animator->initAnimStateList(); + setCharactersInDefaultScene(); + + if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData, &_opcodes)) + error("Could not load \"_STARTUP.EMC\" script"); + _scriptInterpreter->initScript(_scriptMain, _npcScriptData); + + if (!_scriptInterpreter->startScript(_scriptMain, 0)) + error("Could not start script function 0 of script \"_STARTUP.EMC\""); + + while (_scriptInterpreter->validScript(_scriptMain)) + _scriptInterpreter->runScript(_scriptMain); + + _scriptInterpreter->unloadScript(_npcScriptData); + + if (!_scriptInterpreter->loadScript("_NPC.EMC", _npcScriptData, &_opcodes)) + error("Could not load \"_NPC.EMC\" script"); + + snd_playTheme(1); + enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1); + + if (_abortIntroFlag && _skipIntroFlag) { + _menuDirectlyToLoad = true; + _screen->setMouseCursor(1, 1, _shapes[0]); + _screen->showMouse(); + buttonMenuCallback(0); + _menuDirectlyToLoad = false; + } else + saveGame(getSavegameFilename(0), "New game"); +} + +void KyraEngine_v1::mainLoop() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::mainLoop()"); + + while (!_quitFlag) { + int32 frameTime = (int32)_system->getMillis(); + _skipFlag = false; + + if (_currentCharacter->sceneId == 210) { + updateKyragemFading(); + if (seq_playEnd() && _deathHandler != 8) + break; + } + + if (_deathHandler != 0xFF) { + snd_playWanderScoreViaMap(0, 1); + snd_playSoundEffect(49); + _screen->hideMouse(); + _screen->setMouseCursor(1, 1, _shapes[0]); + destroyMouseItem(); + _screen->showMouse(); + buttonMenuCallback(0); + _deathHandler = 0xFF; + } + + if ((_brandonStatusBit & 2) && _brandonStatusBit0x02Flag) + _animator->animRefreshNPC(0); + + if ((_brandonStatusBit & 0x20) && _brandonStatusBit0x20Flag) { + _animator->animRefreshNPC(0); + _brandonStatusBit0x20Flag = 0; + } + + _screen->showMouse(); + + processButtonList(_buttonList); + updateMousePointer(); + updateGameTimers(); + updateTextFade(); + + _handleInput = true; + delay((frameTime + _gameSpeed) - _system->getMillis(), true, true); + _handleInput = false; + + _sound->process(); + } +} + +void KyraEngine_v1::delayUntil(uint32 timestamp, bool updateTimers, bool update, bool isMainLoop) { + while (_system->getMillis() < timestamp && !_quitFlag) { + if (updateTimers) + updateGameTimers(); + + if (timestamp - _system->getMillis() >= 10) + delay(10, update, isMainLoop); + } +} + +void KyraEngine_v1::delay(uint32 amount, bool update, bool isMainLoop) { + Common::Event event; + char saveLoadSlot[20]; + char savegameName[14]; + + uint32 start = _system->getMillis(); + do { + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && + (event.kbd.flags == Common::KBD_CTRL || event.kbd.flags == Common::KBD_ALT) && isMainLoop) { + sprintf(saveLoadSlot, "%s.00%d", _targetName.c_str(), event.kbd.keycode - '0'); + if (event.kbd.flags == Common::KBD_CTRL) + loadGame(saveLoadSlot); + else { + sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0'); + saveGame(saveLoadSlot, savegameName); + } + } else if (event.kbd.flags == Common::KBD_CTRL) { + if (event.kbd.keycode == 'd') + _debugger->attach(); + else if (event.kbd.keycode == 'q') + _quitFlag = true; + } else if (event.kbd.keycode == '.') + _skipFlag = true; + else if (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_SPACE || event.kbd.keycode == Common::KEYCODE_ESCAPE) { + _abortIntroFlag = true; + _skipFlag = true; + } + + break; + case Common::EVENT_MOUSEMOVE: + _animator->_updateScreen = true; + break; + case Common::EVENT_QUIT: + quitGame(); + break; + case Common::EVENT_LBUTTONDOWN: + _mousePressFlag = true; + break; + case Common::EVENT_LBUTTONUP: + _mousePressFlag = false; + + if (_abortWalkFlag2) + _abortWalkFlag = true; + + if (_handleInput) { + _handleInput = false; + processInput(); + _handleInput = true; + } else + _skipFlag = true; + + break; + default: + break; + } + } + + if (_debugger->isAttached()) + _debugger->onFrame(); + + if (update) { + _sprites->updateSceneAnims(); + _animator->updateAllObjectShapes(); + updateTextFade(); + updateMousePointer(); + } + + if (_currentCharacter && _currentCharacter->sceneId == 210 && update) + updateKyragemFading(); + + if (_skipFlag && !_abortIntroFlag && !queryGameFlag(0xFE)) + _skipFlag = false; + + if (amount > 0 && !_skipFlag && !_quitFlag) + _system->delayMillis(10); + + if (_skipFlag) + _sound->voiceStop(); + } while (!_skipFlag && _system->getMillis() < start + amount && !_quitFlag); +} + +void KyraEngine_v1::waitForEvent() { + bool finished = false; + Common::Event event; + + while (!finished && !_quitFlag) { + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + finished = true; + break; + case Common::EVENT_QUIT: + quitGame(); + break; + case Common::EVENT_LBUTTONDOWN: + finished = true; + _skipFlag = true; + break; + default: + break; + } + } + + if (_debugger->isAttached()) + _debugger->onFrame(); + + _system->delayMillis(10); + } +} + +void KyraEngine_v1::delayWithTicks(int ticks) { + uint32 nextTime = _system->getMillis() + ticks * _tickLength; + + while (_system->getMillis() < nextTime) { + _sprites->updateSceneAnims(); + _animator->updateAllObjectShapes(); + + if (_currentCharacter->sceneId == 210) { + updateKyragemFading(); + seq_playEnd(); + } + + if (_skipFlag) + break; + + if (nextTime - _system->getMillis() >= 10) + delay(10); + } +} + +#pragma mark - +#pragma mark - Animation/shape specific code +#pragma mark - + +void KyraEngine_v1::setupShapes123(const Shape *shapeTable, int endShape, int flags) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setupShapes123(%p, %d, %d)", (const void *)shapeTable, endShape, flags); + + for (int i = 123; i <= 172; ++i) + _shapes[i] = 0; + + uint8 curImage = 0xFF; + int curPageBackUp = _screen->_curPage; + _screen->_curPage = 8; // we are using page 8 here in the original page 2 was backuped and then used for this stuff + int shapeFlags = 2; + if (flags) + shapeFlags = 3; + for (int i = 123; i < 123+endShape; ++i) { + uint8 newImage = shapeTable[i-123].imageIndex; + if (newImage != curImage && newImage != 0xFF) { + assert(_characterImageTable); + _screen->loadBitmap(_characterImageTable[newImage], 8, 8, 0); + curImage = newImage; + } + _shapes[i] = _screen->encodeShape(shapeTable[i-123].x<<3, shapeTable[i-123].y, shapeTable[i-123].w<<3, shapeTable[i-123].h, shapeFlags); + assert(i-7 < _defaultShapeTableSize); + _defaultShapeTable[i-7].xOffset = shapeTable[i-123].xOffset; + _defaultShapeTable[i-7].yOffset = shapeTable[i-123].yOffset; + _defaultShapeTable[i-7].w = shapeTable[i-123].w; + _defaultShapeTable[i-7].h = shapeTable[i-123].h; + } + _screen->_curPage = curPageBackUp; +} + +void KyraEngine_v1::freeShapes123() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::freeShapes123()"); + + for (int i = 123; i <= 172; ++i) { + delete [] _shapes[i]; + _shapes[i] = 0; + } +} + +#pragma mark - +#pragma mark - Misc stuff +#pragma mark - + +Movie *KyraEngine_v1::createWSAMovie() { + if (_flags.platform == Common::kPlatformAmiga) + return new WSAMovieAmiga(this); + + return new WSAMovieV1(this); +} + +void KyraEngine_v1::setBrandonPoisonFlags(int reset) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setBrandonPoisonFlags(%d)", reset); + _brandonStatusBit |= 1; + + if (reset) + _poisonDeathCounter = 0; + + for (int i = 0; i < 0x100; ++i) + _brandonPoisonFlagsGFX[i] = i; + + _brandonPoisonFlagsGFX[0x99] = 0x34; + _brandonPoisonFlagsGFX[0x9A] = 0x35; + _brandonPoisonFlagsGFX[0x9B] = 0x37; + _brandonPoisonFlagsGFX[0x9C] = 0x38; + _brandonPoisonFlagsGFX[0x9D] = 0x2B; +} + +void KyraEngine_v1::resetBrandonPoisonFlags() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::resetBrandonPoisonFlags()"); + _brandonStatusBit = 0; + + for (int i = 0; i < 0x100; ++i) + _brandonPoisonFlagsGFX[i] = i; +} + +#pragma mark - +#pragma mark - Input +#pragma mark - + +void KyraEngine_v1::processInput() { + Common::Point mouse = getMousePos(); + int xpos = mouse.x; + int ypos = mouse.y; + + debugC(9, kDebugLevelMain, "KyraEngine_v1::processInput(%d, %d)", xpos, ypos); + _abortWalkFlag2 = false; + + if (processInputHelper(xpos, ypos)) + return; + + uint8 item = findItemAtPos(xpos, ypos); + if (item == 0xFF) { + _changedScene = false; + int handled = clickEventHandler(xpos, ypos); + if (_changedScene || handled) + return; + } + + // XXX _deathHandler specific + if (ypos <= 158) { + uint16 exit = 0xFFFF; + if (xpos < 12) { + exit = _walkBlockWest; + } else if (xpos >= 308) { + exit = _walkBlockEast; + } else if (ypos >= 136) { + exit = _walkBlockSouth; + } else if (ypos < 12) { + exit = _walkBlockNorth; + } + + if (exit != 0xFFFF) { + _abortWalkFlag2 = true; + handleSceneChange(xpos, ypos, 1, 1); + _abortWalkFlag2 = false; + return; + } else { + int script = checkForNPCScriptRun(xpos, ypos); + if (script >= 0) { + runNpcScript(script); + return; + } + if (_itemInHand != -1) { + if (ypos < 155) { + if (hasClickedOnExit(xpos, ypos)) { + _abortWalkFlag2 = true; + handleSceneChange(xpos, ypos, 1, 1); + _abortWalkFlag2 = false; + return; + } + dropItem(0, _itemInHand, xpos, ypos, 1); + } + } else { + if (ypos <= 155) { + _abortWalkFlag2 = true; + handleSceneChange(xpos, ypos, 1, 1); + _abortWalkFlag2 = false; + } + } + } + } +} + +int KyraEngine_v1::processInputHelper(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::processInputHelper(%d, %d)", xpos, ypos); + uint8 item = findItemAtPos(xpos, ypos); + if (item != 0xFF) { + if (_itemInHand == -1) { + _screen->hideMouse(); + _animator->animRemoveGameItem(item); + snd_playSoundEffect(53); + assert(_currentCharacter->sceneId < _roomTableSize); + Room *currentRoom = &_roomTable[_currentCharacter->sceneId]; + int item2 = currentRoom->itemsTable[item]; + currentRoom->itemsTable[item] = 0xFF; + setMouseItem(item2); + assert(_itemList && _takenList); + updateSentenceCommand(_itemList[item2], _takenList[0], 179); + _itemInHand = item2; + _screen->showMouse(); + clickEventHandler2(); + return 1; + } else { + exchangeItemWithMouseItem(_currentCharacter->sceneId, item); + return 1; + } + } + return 0; +} + +int KyraEngine_v1::clickEventHandler(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::clickEventHandler(%d, %d)", xpos, ypos); + _scriptInterpreter->initScript(_scriptClick, _scriptClickData); + _scriptClick->regs[1] = xpos; + _scriptClick->regs[2] = ypos; + _scriptClick->regs[3] = 0; + _scriptClick->regs[4] = _itemInHand; + _scriptInterpreter->startScript(_scriptClick, 1); + + while (_scriptInterpreter->validScript(_scriptClick)) + _scriptInterpreter->runScript(_scriptClick); + + return _scriptClick->regs[3]; +} + +void KyraEngine_v1::updateMousePointer(bool forceUpdate) { + int shape = 0; + + int newMouseState = 0; + int newX = 0; + int newY = 0; + Common::Point mouse = getMousePos(); + if (mouse.y <= 158) { + if (mouse.x >= 12) { + if (mouse.x >= 308) { + if (_walkBlockEast == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -5; + shape = 3; + newX = 7; + newY = 5; + } + } else if (mouse.y >= 136) { + if (_walkBlockSouth == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -4; + shape = 4; + newX = 5; + newY = 7; + } + } else if (mouse.y < 12) { + if (_walkBlockNorth == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -6; + shape = 2; + newX = 5; + newY = 1; + } + } + } else { + if (_walkBlockWest == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -3; + newX = 1; + newY = shape = 5; + } + } + } + + if (mouse.x >= _entranceMouseCursorTracks[0] && mouse.y >= _entranceMouseCursorTracks[1] + && mouse.x <= _entranceMouseCursorTracks[2] && mouse.y <= _entranceMouseCursorTracks[3]) { + switch (_entranceMouseCursorTracks[4]) { + case 0: + newMouseState = -6; + shape = 2; + newX = 5; + newY = 1; + break; + + case 2: + newMouseState = -5; + shape = 3; + newX = 7; + newY = 5; + break; + + case 4: + newMouseState = -4; + shape = 4; + newX = 5; + newY = 7; + break; + + case 6: + newMouseState = -3; + shape = 5; + newX = 1; + newY = 5; + break; + + default: + break; + } + } + + if (newMouseState == -2) { + shape = 6; + newX = 4; + newY = 4; + } + + if ((newMouseState && _mouseState != newMouseState) || (newMouseState && forceUpdate)) { + _mouseState = newMouseState; + _screen->hideMouse(); + _screen->setMouseCursor(newX, newY, _shapes[shape]); + _screen->showMouse(); + } + + if (!newMouseState) { + if (_mouseState != _itemInHand || forceUpdate) { + if (mouse.y > 158 || (mouse.x >= 12 && mouse.x < 308 && mouse.y < 136 && mouse.y >= 12) || forceUpdate) { + _mouseState = _itemInHand; + _screen->hideMouse(); + if (_itemInHand == -1) { + _screen->setMouseCursor(1, 1, _shapes[0]); + } else { + _screen->setMouseCursor(8, 15, _shapes[216+_itemInHand]); + } + _screen->showMouse(); + } + } + } +} + +bool KyraEngine_v1::hasClickedOnExit(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::hasClickedOnExit(%d, %d)", xpos, ypos); + if (xpos < 16 || xpos >= 304) + return true; + + if (ypos < 8) + return true; + + if (ypos < 136 || ypos > 155) + return false; + + return true; +} + +void KyraEngine_v1::clickEventHandler2() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::clickEventHandler2()"); + + Common::Point mouse = getMousePos(); + + _scriptInterpreter->initScript(_scriptClick, _scriptClickData); + _scriptClick->regs[0] = _currentCharacter->sceneId; + _scriptClick->regs[1] = mouse.x; + _scriptClick->regs[2] = mouse.y; + _scriptClick->regs[4] = _itemInHand; + _scriptInterpreter->startScript(_scriptClick, 6); + + while (_scriptInterpreter->validScript(_scriptClick)) + _scriptInterpreter->runScript(_scriptClick); +} + +int KyraEngine_v1::checkForNPCScriptRun(int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::checkForNPCScriptRun(%d, %d)", xpos, ypos); + int returnValue = -1; + const Character *currentChar = _currentCharacter; + int charLeft = 0, charRight = 0, charTop = 0, charBottom = 0; + + int scaleFactor = _scaleTable[currentChar->y1]; + int addX = (((scaleFactor*8)*3)>>8)>>1; + int addY = ((scaleFactor*3)<<4)>>8; + + charLeft = currentChar->x1 - addX; + charRight = currentChar->x1 + addX; + charTop = currentChar->y1 - addY; + charBottom = currentChar->y1; + + if (xpos >= charLeft && charRight >= xpos && charTop <= ypos && charBottom >= ypos) + return 0; + + if (xpos > 304 || xpos < 16) + return -1; + + for (int i = 1; i < 5; ++i) { + currentChar = &_characterList[i]; + + if (currentChar->sceneId != _currentCharacter->sceneId) + continue; + + charLeft = currentChar->x1 - 12; + charRight = currentChar->x1 + 11; + charTop = currentChar->y1 - 48; + // if (!i) { + // charBottom = currentChar->y2 - 16; + // } else { + charBottom = currentChar->y1; + // } + + if (xpos < charLeft || xpos > charRight || ypos < charTop || charBottom < ypos) + continue; + + if (returnValue != -1) { + if (currentChar->y1 >= _characterList[returnValue].y1) + returnValue = i; + } else { + returnValue = i; + } + } + + return returnValue; +} + +void KyraEngine_v1::runNpcScript(int func) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::runNpcScript(%d)", func); + _scriptInterpreter->initScript(_npcScript, _npcScriptData); + _scriptInterpreter->startScript(_npcScript, func); + _npcScript->regs[0] = _currentCharacter->sceneId; + _npcScript->regs[4] = _itemInHand; + _npcScript->regs[5] = func; + + while (_scriptInterpreter->validScript(_npcScript)) + _scriptInterpreter->runScript(_npcScript); } #define Opcode(x) OpcodeV1(this, &KyraEngine_v1::x) diff --git a/engines/kyra/kyra_v1.h b/engines/kyra/kyra_v1.h index 5afa248981..1bd8f48971 100644 --- a/engines/kyra/kyra_v1.h +++ b/engines/kyra/kyra_v1.h @@ -28,14 +28,806 @@ #include "kyra/kyra.h" #include "kyra/script.h" +#include "kyra/screen_v1.h" namespace Kyra { +class Movie; +class SoundDigital; +class SeqPlayer; +class Sprites; +class ScriptHelper; +class Debugger; +class ScreenAnimator; +class TextDisplayer; +class KyraEngine_v1; + +struct Character { + uint16 sceneId; + uint8 height; + uint8 facing; + uint16 currentAnimFrame; + uint8 inventoryItems[10]; + int16 x1, y1, x2, y2; +}; + +struct Shape { + uint8 imageIndex; + int8 xOffset, yOffset; + uint8 x, y, w, h; +}; + +struct Room { + uint8 nameIndex; + uint16 northExit; + uint16 eastExit; + uint16 southExit; + uint16 westExit; + uint8 itemsTable[12]; + uint16 itemsXPos[12]; + uint8 itemsYPos[12]; + uint8 needInit[12]; +}; + +struct Item { + uint8 unk1; + uint8 height; + uint8 unk2; + uint8 unk3; +}; + +struct SeqLoop { + const uint8 *ptr; + uint16 count; +}; + +struct SceneExits { + uint16 northXPos; + uint8 northYPos; + uint16 eastXPos; + uint8 eastYPos; + uint16 southXPos; + uint8 southYPos; + uint16 westXPos; + uint8 westYPos; +}; + +struct BeadState { + int16 x; + int16 y; + int16 width; + int16 height; + int16 dstX; + int16 dstY; + int16 width2; + int16 unk8; + int16 unk9; + int16 tableIndex; +}; + +struct Timer { + uint8 active; + int32 countdown; + uint32 nextRun; + void (KyraEngine_v1::*func)(int timerNum); +}; + +struct Button { + Button *nextButton; + uint16 specialValue; + // uint8 unk[4]; + uint8 process0; + uint8 process1; + uint8 process2; + // uint8 unk + uint16 flags; + typedef int (KyraEngine_v1::*ButtonCallback)(Button*); + // using 6 pointers instead of 3 as in the orignal here (safer for use with classes) + uint8 *process0PtrShape; + uint8 *process1PtrShape; + uint8 *process2PtrShape; + ButtonCallback process0PtrCallback; + ButtonCallback process1PtrCallback; + ButtonCallback process2PtrCallback; + uint16 dimTableIndex; + uint16 x; + uint16 y; + uint16 width; + uint16 height; + // uint8 unk[8]; + uint32 flags2; + ButtonCallback buttonCallback; + // uint8 unk[8]; +}; + +struct MenuItem { + bool enabled; + uint16 field_1; + uint8 field_3; + const char *itemString; + int16 x; + int16 field_9; + uint16 y; + uint16 width; + uint16 height; + uint8 textColor; + uint8 highlightColor; + int16 field_12; + uint8 field_13; + uint8 bgcolor; + uint8 color1; + uint8 color2; + int (KyraEngine_v1::*callback)(Button*); + int16 field_1b; + const char *labelString; + uint16 labelX; + uint8 labelY; + uint8 field_24; + uint32 field_25; +}; + +struct Menu { + int16 x; + int16 y; + uint16 width; + uint16 height; + uint8 bgcolor; + uint8 color1; + uint8 color2; + const char *menuName; + uint8 textColor; + int16 field_10; + uint16 field_12; + uint16 highlightedItem; + uint8 nrOfItems; + int16 scrollUpBtnX; + int16 scrollUpBtnY; + int16 scrollDownBtnX; + int16 scrollDownBtnY; + MenuItem item[6]; +}; + class KyraEngine_v1 : public KyraEngine { + friend class MusicPlayer; + friend class Debugger_v1; + friend class ScreenAnimator; public: KyraEngine_v1(OSystem *system, const GameFlags &flags); ~KyraEngine_v1(); + Screen *screen() { return _screen; } + ScreenAnimator *animator() { return _animator; } + virtual Movie *createWSAMovie(); + + uint8 **shapes() { return _shapes; } + Character *currentCharacter() { return _currentCharacter; } + Character *characterList() { return _characterList; } + uint16 brandonStatus() { return _brandonStatusBit; } + + // TODO: remove me with workaround in animator.cpp l209 + uint16 getScene() { return _currentRoom; } + + int _paletteChanged; + int16 _northExitHeight; + + typedef void (KyraEngine_v1::*IntroProc)(); + + // static data access + const char * const*seqWSATable() { return _seq_WSATable; } + const char * const*seqCPSTable() { return _seq_CPSTable; } + const char * const*seqCOLTable() { return _seq_COLTable; } + const char * const*seqTextsTable() { return _seq_textsTable; } + + const uint8 * const*palTable1() { return &_specialPalettes[0]; } + const uint8 * const*palTable2() { return &_specialPalettes[29]; } + +protected: + virtual int go(); + virtual int init(); + +public: + // sequences + // -> misc + bool seq_skipSequence() const; +protected: + // -> demo + void seq_demo(); + + // -> intro + void seq_intro(); + void seq_introLogos(); + void seq_introStory(); + void seq_introMalcolmTree(); + void seq_introKallakWriting(); + void seq_introKallakMalcolm(); + + // -> ingame animations + void seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly); + void seq_brandonHealing(); + void seq_brandonHealing2(); + void seq_poisonDeathNow(int now); + void seq_poisonDeathNowAnim(); + void seq_playFluteAnimation(); + void seq_winterScroll1(); + void seq_winterScroll2(); + void seq_makeBrandonInv(); + void seq_makeBrandonNormal(); + void seq_makeBrandonNormal2(); + void seq_makeBrandonWisp(); + void seq_dispelMagicAnimation(); + void seq_fillFlaskWithWater(int item, int type); + void seq_playDrinkPotionAnim(int item, int unk2, int flags); + void seq_brandonToStone(); + + // -> end fight + int seq_playEnd(); + void seq_playEnding(); + + int handleMalcolmFlag(); + int handleBeadState(); + void initBeadState(int x, int y, int x2, int y2, int unk1, BeadState *ptr); + int processBead(int x, int y, int &x2, int &y2, BeadState *ptr); + + // -> credits + void seq_playCredits(); + +public: + // delay + void delayUntil(uint32 timestamp, bool updateGameTimers = false, bool update = false, bool isMainLoop = false); + void delay(uint32 millis, bool update = false, bool isMainLoop = false); + void delayWithTicks(int ticks); + void waitForEvent(); + + // TODO + void registerDefaultSettings(); + void readSettings(); + void writeSettings(); + + void snd_playTheme(int file, int track = 0); + void snd_playVoiceFile(int id); + void snd_voiceWaitForFinish(bool ingame = true); + bool snd_voiceIsPlaying(); + void snd_stopVoice(); + void snd_playSoundEffect(int track); + void snd_playWanderScoreViaMap(int command, int restart); + + bool speechEnabled(); + bool textEnabled(); + + void updateGameTimers(); + void clearNextEventTickCount(); + void setTimerCountdown(uint8 timer, int32 countdown); + void setTimerDelay(uint8 timer, int32 countdown); + int16 getTimerDelay(uint8 timer); + void enableTimer(uint8 timer); + void disableTimer(uint8 timer); + + void saveGame(const char *fileName, const char *saveName); + void loadGame(const char *fileName); + +protected: + // input + void processInput(); + int processInputHelper(int xpos, int ypos); + int clickEventHandler(int xpos, int ypos); + void clickEventHandler2(); + void updateMousePointer(bool forceUpdate = false); + bool hasClickedOnExit(int xpos, int ypos); + + // scene + // -> init + void loadSceneMsc(); + void startSceneScript(int brandonAlive); + void setupSceneItems(); + void initSceneData(int facing, int unk1, int brandonAlive); + void initSceneObjectList(int brandonAlive); + void initSceneScreen(int brandonAlive); + void setupSceneResource(int sceneId); + + // -> process + void enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive); + int handleSceneChange(int xpos, int ypos, int unk1, int frameReset); + int processSceneChange(int *table, int unk1, int frameReset); + int changeScene(int facing); + + // -> modification + void transcendScenes(int roomIndex, int roomName); + void setSceneFile(int roomIndex, int roomName); + + // -> pathfinder + int findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize); + int findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end); + int getFacingFromPointToPoint(int x, int y, int toX, int toY); + void changePosTowardsFacing(int &x, int &y, int facing); + bool lineIsPassable(int x, int y); + int getMoveTableSize(int *moveTable); + + // -> item handling + // --> misc + void addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y); + + // --> drop handling + void itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item); + int processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2); + void dropItem(int unk1, int item, int x, int y, int unk2); + + // --> dropped item handling + int countItemsInScene(uint16 sceneId); + void exchangeItemWithMouseItem(uint16 sceneId, int itemIndex); + byte findFreeItemInScene(int scene); + byte findItemAtPos(int x, int y); + + // --> drop area handling + void addToNoDropRects(int x, int y, int w, int h); + void clearNoDropRects(); + int isDropable(int x, int y); + int checkNoDropRects(int x, int y); + + // --> player items handling + void updatePlayerItemsForScene(); + + // --> item GFX handling + void backUpItemRect0(int xpos, int ypos); + void restoreItemRect0(int xpos, int ypos); + void backUpItemRect1(int xpos, int ypos); + void restoreItemRect1(int xpos, int ypos); + + // items + // -> misc + void placeItemInGenericMapScene(int item, int index); + + // -> mouse item + void createMouseItem(int item); + void destroyMouseItem(); + void setMouseItem(int item); + + // -> graphics effects + void wipeDownMouseItem(int xpos, int ypos); + void itemSpecialFX(int x, int y, int item); + void itemSpecialFX1(int x, int y, int item); + void itemSpecialFX2(int x, int y, int item); + void magicOutMouseItem(int animIndex, int itemPos); + void magicInMouseItem(int animIndex, int item, int itemPos); + void specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops); + void processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops); + + // character + // -> movement + void moveCharacterToPos(int character, int facing, int xpos, int ypos); + void setCharacterPositionWithUpdate(int character); + int setCharacterPosition(int character, int *facingTable); + void setCharacterPositionHelper(int character, int *facingTable); + int getOppositeFacingDirection(int dir); + void setCharactersPositions(int character); + + // -> brandon + void setBrandonPoisonFlags(int reset); + void resetBrandonPoisonFlags(); + + // chat + // -> process + void characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration); + void waitForChatToFinish(int vocFile, int16 chatDuration, const char *str, uint8 charNum); + + // -> initialization + int initCharacterChat(int8 charNum); + void backupChatPartnerAnimFrame(int8 charNum); + void restoreChatPartnerAnimFrame(int8 charNum); + int8 getChatPartnerNum(); + + // -> deinitialization + void endCharacterChat(int8 charNum, int16 arg_4); + + // graphics + // -> misc + int findDuplicateItemShape(int shape); + void updateKyragemFading(); + + // -> interface + void loadMainScreen(int page = 3); + void redrawInventory(int page); +public: + void drawSentenceCommand(const char *sentence, int unk1); + void updateSentenceCommand(const char *str1, const char *str2, int unk1); + void updateTextFade(); + +protected: + // -> amulet + void drawJewelPress(int jewel, int drawSpecial); + void drawJewelsFadeOutStart(); + void drawJewelsFadeOutEnd(int jewel); + + // -> shape handling + void setupShapes123(const Shape *shapeTable, int endShape, int flags); + void freeShapes123(); + + // misc (TODO) + void startup(); + void mainLoop(); + + int checkForNPCScriptRun(int xpos, int ypos); + void runNpcScript(int func); + + void loadMouseShapes(); + void loadCharacterShapes(); + void loadSpecialEffectShapes(); + void loadItems(); + void loadButtonShapes(); + void initMainButtonList(); + void setCharactersInDefaultScene(); + void setupPanPages(); + void freePanPages(); + void closeFinalWsa(); + + void setTimer19(); + void setupTimers(); + void timerUpdateHeadAnims(int timerNum); + void timerSetFlags1(int timerNum); + void timerSetFlags2(int timerNum); + void timerSetFlags3(int timerNum); + void timerCheckAnimFlag1(int timerNum); + void timerCheckAnimFlag2(int timerNum); + void checkAmuletAnimFlags(); + void timerRedrawAmulet(int timerNum); + void timerFadeText(int timerNum); + void updateAnimFlag1(int timerNum); + void updateAnimFlag2(int timerNum); + void drawAmulet(); + void setTextFadeTimerCountdown(int16 countdown); + void setWalkspeed(uint8 newSpeed); + + int buttonInventoryCallback(Button *caller); + int buttonAmuletCallback(Button *caller); + int buttonMenuCallback(Button *caller); + int drawBoxCallback(Button *button); + int drawShadedBoxCallback(Button *button); + void calcCoords(Menu &menu); + void initMenu(Menu &menu); + void setGUILabels(); + + Button *initButton(Button *list, Button *newButton); + void processButtonList(Button *list); + void processButton(Button *button); + void processMenuButton(Button *button); + void processAllMenuButtons(); + + const char *getSavegameFilename(int num); + void setupSavegames(Menu &menu, int num); + int getNextSavegameSlot(); + + int gui_resumeGame(Button *button); + int gui_loadGameMenu(Button *button); + int gui_saveGameMenu(Button *button); + int gui_gameControlsMenu(Button *button); + int gui_quitPlaying(Button *button); + int gui_quitConfirmYes(Button *button); + int gui_quitConfirmNo(Button *button); + int gui_loadGame(Button *button); + int gui_saveGame(Button *button); + int gui_savegameConfirm(Button *button); + int gui_cancelSubMenu(Button *button); + int gui_scrollUp(Button *button); + int gui_scrollDown(Button *button); + int gui_controlsChangeMusic(Button *button); + int gui_controlsChangeSounds(Button *button); + int gui_controlsChangeWalk(Button *button); + int gui_controlsChangeText(Button *button); + int gui_controlsChangeVoice(Button *button); + int gui_controlsApply(Button *button); + + bool gui_quitConfirm(const char *str); + void gui_getInput(); + void gui_redrawText(Menu menu); + void gui_redrawHighlight(Menu menu); + void gui_processHighlights(Menu &menu); + void gui_updateSavegameString(); + void gui_redrawTextfield(); + void gui_fadePalette(); + void gui_restorePalette(); + void gui_setupControls(Menu &menu); + + bool _skipIntroFlag; + bool _abortIntroFlag; + bool _menuDirectlyToLoad; + bool _abortWalkFlag; + bool _abortWalkFlag2; + bool _mousePressFlag; + int8 _mouseWheel; + uint8 *_itemBkgBackUp[2]; + uint8 *_shapes[373]; + uint16 _gameSpeed; + int8 _itemInHand; + int _mouseState; + bool _handleInput; + bool _changedScene; + int _unkScreenVar1, _unkScreenVar2, _unkScreenVar3; + int _beadStateVar; + int _unkAmuletVar; + + int _malcolmFlag; + int _endSequenceSkipFlag; + int _endSequenceNeedLoading; + int _unkEndSeqVar2; + uint8 *_endSequenceBackUpRect; + int _unkEndSeqVar4; + int _unkEndSeqVar5; + int _lastDisplayedPanPage; + uint8 *_panPagesTable[20]; + Movie *_finalA, *_finalB, *_finalC; + + Movie *_movieObjects[10]; + + uint16 _entranceMouseCursorTracks[8]; + uint16 _walkBlockNorth; + uint16 _walkBlockEast; + uint16 _walkBlockSouth; + uint16 _walkBlockWest; + + int32 _scaleMode; + int16 _scaleTable[145]; + + Rect _noDropRects[11]; + + int8 _birthstoneGemTable[4]; + int8 _idolGemsTable[3]; + + int8 _marbleVaseItem; + int8 _foyerItemTable[3]; + + int8 _cauldronState; + int8 _crystalState[2]; + + uint16 _brandonStatusBit; + uint8 _brandonStatusBit0x02Flag; + uint8 _brandonStatusBit0x20Flag; + uint8 _brandonPoisonFlagsGFX[256]; + uint8 _deathHandler; + int16 _brandonInvFlag; + uint8 _poisonDeathCounter; + int _brandonPosX; + int _brandonPosY; + + uint16 _currentChatPartnerBackupFrame; + uint16 _currentCharAnimFrame; + + int8 *_sceneAnimTable[50]; + + Item _itemTable[145]; + int _lastProcessedItem; + int _lastProcessedItemHeight; + + int16 *_exitListPtr; + int16 _exitList[11]; + SceneExits _sceneExits; + uint16 _currentRoom; + int _scenePhasingFlag; + + int _sceneChangeState; + int _loopFlag2; + + int _pathfinderFlag; + int _pathfinderFlag2; + int _lastFindWayRet; + int *_movFacingTable; + + int8 _talkingCharNum; + int8 _charSayUnk2; + int8 _charSayUnk3; + int8 _currHeadShape; + uint8 _currSentenceColor[3]; + int8 _startSentencePalIndex; + bool _fadeText; + + uint8 _configTextspeed; + uint8 _configWalkspeed; + int _configMusic; + bool _configSounds; + uint8 _configVoice; + + int _curMusicTheme; + int _curSfxFile; + int16 _lastMusicCommand; + + ScreenAnimator *_animator; + SeqPlayer *_seq; + Sprites *_sprites; + Screen_v1 *_screen; + ScriptHelper *_scriptInterpreter; + Debugger *_debugger; + + ScriptState *_scriptMain; + + ScriptState *_npcScript; + ScriptData *_npcScriptData; + + ScriptState *_scriptClick; + ScriptData *_scriptClickData; + + Character *_characterList; + Character *_currentCharacter; + + Button *_buttonList; + Button *_menuButtonList; + bool _displayMenu; + bool _menuRestoreScreen; + bool _displaySubMenu; + bool _cancelSubMenu; + uint8 _toplevelMenu; + int _savegameOffset; + int _gameToLoad; + char _savegameName[31]; + const char *_specialSavegameString; + Common::KeyState _keyPressed; + + struct KyragemState { + uint16 nextOperation; + uint16 rOffset; + uint16 gOffset; + uint16 bOffset; + uint32 timerCount; + } _kyragemFadingState; + + // TODO: get rid of all variables having pointers to the static resources if possible + // i.e. let them directly use the _staticres functions + void initStaticResource(); + + const uint8 *_seq_Forest; + const uint8 *_seq_KallakWriting; + const uint8 *_seq_KyrandiaLogo; + const uint8 *_seq_KallakMalcolm; + const uint8 *_seq_MalcolmTree; + const uint8 *_seq_WestwoodLogo; + const uint8 *_seq_Demo1; + const uint8 *_seq_Demo2; + const uint8 *_seq_Demo3; + const uint8 *_seq_Demo4; + const uint8 *_seq_Reunion; + + const char * const*_seq_WSATable; + const char * const*_seq_CPSTable; + const char * const*_seq_COLTable; + const char * const*_seq_textsTable; + + int _seq_WSATable_Size; + int _seq_CPSTable_Size; + int _seq_COLTable_Size; + int _seq_textsTable_Size; + + const char * const*_itemList; + const char * const*_takenList; + const char * const*_placedList; + const char * const*_droppedList; + const char * const*_noDropList; + const char * const*_putDownFirst; + const char * const*_waitForAmulet; + const char * const*_blackJewel; + const char * const*_poisonGone; + const char * const*_healingTip; + const char * const*_thePoison; + const char * const*_fluteString; + const char * const*_wispJewelStrings; + const char * const*_magicJewelString; + const char * const*_flaskFull; + const char * const*_fullFlask; + const char * const*_veryClever; + const char * const*_homeString; + const char * const*_newGameString; + + const char *_voiceTextString; + const char *_textSpeedString; + const char *_onString; + const char *_offString; + const char *_onCDString; + + int _itemList_Size; + int _takenList_Size; + int _placedList_Size; + int _droppedList_Size; + int _noDropList_Size; + int _putDownFirst_Size; + int _waitForAmulet_Size; + int _blackJewel_Size; + int _poisonGone_Size; + int _healingTip_Size; + int _thePoison_Size; + int _fluteString_Size; + int _wispJewelStrings_Size; + int _magicJewelString_Size; + int _flaskFull_Size; + int _fullFlask_Size; + int _veryClever_Size; + int _homeString_Size; + int _newGameString_Size; + + const char * const*_characterImageTable; + int _characterImageTableSize; + + const char * const*_guiStrings; + int _guiStringsSize; + + const char * const*_configStrings; + int _configStringsSize; + + Shape *_defaultShapeTable; + int _defaultShapeTableSize; + + const Shape *_healingShapeTable; + int _healingShapeTableSize; + const Shape *_healingShape2Table; + int _healingShape2TableSize; + + const Shape *_posionDeathShapeTable; + int _posionDeathShapeTableSize; + + const Shape *_fluteAnimShapeTable; + int _fluteAnimShapeTableSize; + + const Shape *_winterScrollTable; + int _winterScrollTableSize; + const Shape *_winterScroll1Table; + int _winterScroll1TableSize; + const Shape *_winterScroll2Table; + int _winterScroll2TableSize; + + const Shape *_drinkAnimationTable; + int _drinkAnimationTableSize; + + const Shape *_brandonToWispTable; + int _brandonToWispTableSize; + + const Shape *_magicAnimationTable; + int _magicAnimationTableSize; + + const Shape *_brandonStoneTable; + int _brandonStoneTableSize; + + Room *_roomTable; + int _roomTableSize; + const char * const*_roomFilenameTable; + int _roomFilenameTableSize; + + const uint8 *_amuleteAnim; + + const uint8 * const*_specialPalettes; + + Timer _timers[34]; + uint32 _timerNextRun; + + static const char *_soundFiles[]; + static const int _soundFilesCount; + static const char *_soundFilesTowns[]; + static const int _soundFilesTownsCount; + + static const int8 _charXPosTable[]; + static const int8 _addXPosTable[]; + static const int8 _charYPosTable[]; + static const int8 _addYPosTable[]; + + // positions of the inventory + static const uint16 _itemPosX[]; + static const uint8 _itemPosY[]; + + void setupButtonData(); + Button *_buttonData; + Button **_buttonDataListPtr; + static Button _menuButtonData[]; + static Button _scrollUpButton; + static Button _scrollDownButton; + + bool _haveScrollButtons; + + void setupMenu(); + Menu *_menu; + + static const uint8 _magicMouseItemStartFrame[]; + static const uint8 _magicMouseItemEndFrame[]; + static const uint8 _magicMouseItemStartFrame2[]; + static const uint8 _magicMouseItemEndFrame2[]; + + static const uint16 _amuletX[]; + static const uint16 _amuletY[]; + static const uint16 _amuletX2[]; + static const uint16 _amuletY2[]; protected: typedef OpcodeImpl<KyraEngine_v1> OpcodeV1; void setupOpcodeTable(); diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 03d1f8e27e..2f52d8919d 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -41,9 +41,19 @@ KyraEngine_v2::KyraEngine_v2(OSystem *system, const GameFlags &flags) : KyraEngi KyraEngine_v2::~KyraEngine_v2() { delete [] _mouseSHPBuf; + delete _screen; +} + +Movie *KyraEngine_v2::createWSAMovie() { + return new WSAMovieV2(this); } int KyraEngine_v2::init() { + _screen = new Screen_v2(this, _system); + assert(_screen); + if (!_screen->init()) + error("_screen->init() failed"); + KyraEngine::init(); if (_res->getFileSize("6.FNT")) diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index e3dac3f0d5..df73118376 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -26,6 +26,9 @@ #ifndef KYRA_KYRA_V2_H #define KYRA_KYRA_V2_H +#include "kyra/kyra.h" +#include "kyra/screen_v2.h" + namespace Kyra { enum kSequences { @@ -82,10 +85,24 @@ class KyraEngine_v2 : public KyraEngine { public: KyraEngine_v2(OSystem *system, const GameFlags &flags); ~KyraEngine_v2(); + + virtual Screen *screen() { return _screen; } + Screen *screen_v2() { return _screen; } + + Movie *createWSAMovie(); +protected: + // Main menu code, also used for Kyra 3 + static const char *_mainMenuStrings[]; + + virtual void gui_initMainMenu() {} + int gui_handleMainMenu(); + virtual void gui_updateMainMenuAnimation(); + void gui_drawMainMenu(const char * const *strings, int select); + void gui_drawMainBox(int x, int y, int w, int h, int fill); + bool gui_mainMenuGetInput(); + + void gui_printString(const char *string, int x, int y, int col1, int col2, int flags, ...); - int go(); - -private: void setupOpcodeTable() {} void seq_playSequences(int startSeq, int endSeq = -1); @@ -111,7 +128,11 @@ private: void seq_setChatEntry(uint16 strIndex, uint16 posX, uint16 posY, int duration, uint16 unk1); void mainMenu(); + int init(); + int go(); + + Screen_v2 *_screen; ActiveWSA *_activeWSA; ActiveChat *_activeChat; diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp index f035158892..b49635ab2d 100644 --- a/engines/kyra/kyra_v3.cpp +++ b/engines/kyra/kyra_v3.cpp @@ -38,7 +38,7 @@ #include "graphics/cursorman.h" namespace Kyra { -KyraEngine_v3::KyraEngine_v3(OSystem *system, const GameFlags &flags) : KyraEngine(system, flags) { +KyraEngine_v3::KyraEngine_v3(OSystem *system, const GameFlags &flags) : KyraEngine_v2(system, flags) { _soundDigital = 0; _musicSoundChannel = -1; _menuAudioFile = "TITLE1.AUD"; @@ -87,10 +87,6 @@ KyraEngine_v3::~KyraEngine_v3() { delete [] _scenesList; } -Movie *KyraEngine_v3::createWSAMovie() { - return new WSAMovieV2(this); -} - int KyraEngine_v3::init() { KyraEngine::init(); @@ -324,7 +320,7 @@ int KyraEngine_v3::musicUpdate(int forceRestart) { #pragma mark - void KyraEngine_v3::gui_initMainMenu() { - KyraEngine::gui_initMainMenu(); + KyraEngine_v2::gui_initMainMenu(); _mainMenuFrame = 29; _mainMenuFrameAdd = 1; } diff --git a/engines/kyra/kyra_v3.h b/engines/kyra/kyra_v3.h index 5616fcbf0e..79c48b0dcb 100644 --- a/engines/kyra/kyra_v3.h +++ b/engines/kyra/kyra_v3.h @@ -26,20 +26,17 @@ #ifndef KYRA_KYRA_V3_H #define KYRA_KYRA_V3_H -#include "kyra/kyra.h" +#include "kyra/kyra_v2.h" namespace Kyra { -// maybe subclass KyraEngine_v2 later -class WSAMovieV2; +class SoundDigital; -class KyraEngine_v3 : public KyraEngine { +class KyraEngine_v3 : public KyraEngine_v2 { public: KyraEngine_v3(OSystem *system, const GameFlags &flags); ~KyraEngine_v3(); - - Movie *createWSAMovie(); - + SoundDigital *soundDigital() { return _soundDigital; } int go(); diff --git a/engines/kyra/module.mk b/engines/kyra/module.mk index 8303028b27..0ddcc1bf7f 100644 --- a/engines/kyra/module.mk +++ b/engines/kyra/module.mk @@ -1,19 +1,22 @@ MODULE := engines/kyra MODULE_OBJS := \ - animator.o \ + animator_v1.o \ debugger.o \ detection.o \ - gui.o \ - items.o \ + gui_v1.o \ + gui_v2.o \ + items_v1.o \ kyra.o \ kyra_v1.o \ kyra_v2.o \ kyra_v3.o \ resource.o \ - saveload.o \ - scene.o \ + saveload_v1.o \ + scene_v1.o \ screen.o \ + screen_v1.o \ + screen_v2.o \ script_v1.o \ script.o \ seqplayer.o \ @@ -23,10 +26,12 @@ MODULE_OBJS := \ sound_digital.o \ sound_towns.o \ sound.o \ + sound_v1.o \ sprites.o \ staticres.o \ text.o \ - timer.o \ + text_v1.o \ + timer_v1.o \ vqa.o \ wsamovie.o diff --git a/engines/kyra/saveload_v1.cpp b/engines/kyra/saveload_v1.cpp index 95693684a1..d28a0b3f8b 100644 --- a/engines/kyra/saveload_v1.cpp +++ b/engines/kyra/saveload_v1.cpp @@ -28,8 +28,8 @@ #include "common/savefile.h" #include "common/system.h" -#include "kyra/kyra.h" -#include "kyra/animator.h" +#include "kyra/kyra_v1.h" +#include "kyra/animator_v1.h" #include "kyra/screen.h" #include "kyra/resource.h" #include "kyra/sound.h" @@ -44,7 +44,7 @@ #define GF_FMTOWNS (1 << 2) namespace Kyra { -void KyraEngine::loadGame(const char *fileName) { +void KyraEngine_v1::loadGame(const char *fileName) { debugC(9, kDebugLevelMain, "loadGame('%s')", fileName); Common::InSaveFile *in; @@ -266,7 +266,7 @@ void KyraEngine::loadGame(const char *fileName) { delete in; } -void KyraEngine::saveGame(const char *fileName, const char *saveName) { +void KyraEngine_v1::saveGame(const char *fileName, const char *saveName) { debugC(9, kDebugLevelMain, "saveGame('%s', '%s')", fileName, saveName); Common::OutSaveFile *out; if (_quitFlag) return; diff --git a/engines/kyra/scene_v1.cpp b/engines/kyra/scene_v1.cpp index a92fd9ce7c..e01bb98e18 100644 --- a/engines/kyra/scene_v1.cpp +++ b/engines/kyra/scene_v1.cpp @@ -23,14 +23,14 @@ * */ -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/seqplayer.h" #include "kyra/screen.h" #include "kyra/resource.h" #include "kyra/sound.h" #include "kyra/sprites.h" #include "kyra/wsamovie.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/text.h" #include "kyra/script.h" @@ -39,8 +39,8 @@ namespace Kyra { -void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive) { - debugC(9, kDebugLevelMain, "KyraEngine::enterNewScene(%d, %d, %d, %d, %d)", sceneId, facing, unk1, unk2, brandonAlive); +void KyraEngine_v1::enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::enterNewScene(%d, %d, %d, %d, %d)", sceneId, facing, unk1, unk2, brandonAlive); int unkVar1 = 1; _screen->hideMouse(); _handleInput = false; @@ -191,8 +191,8 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int _changedScene = true; } -void KyraEngine::transcendScenes(int roomIndex, int roomName) { - debugC(9, kDebugLevelMain, "KyraEngine::transcendScenes(%d, %d)", roomIndex, roomName); +void KyraEngine_v1::transcendScenes(int roomIndex, int roomName) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::transcendScenes(%d, %d)", roomIndex, roomName); assert(roomIndex < _roomTableSize); if (_flags.isTalkie) { @@ -217,14 +217,14 @@ void KyraEngine::transcendScenes(int roomIndex, int roomName) { _unkScreenVar3 = 0; } -void KyraEngine::setSceneFile(int roomIndex, int roomName) { - debugC(9, kDebugLevelMain, "KyraEngine::setSceneFile(%d, %d)", roomIndex, roomName); +void KyraEngine_v1::setSceneFile(int roomIndex, int roomName) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setSceneFile(%d, %d)", roomIndex, roomName); assert(roomIndex < _roomTableSize); _roomTable[roomIndex].nameIndex = roomName; } -void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypos) { - debugC(9, kDebugLevelMain, "KyraEngine::moveCharacterToPos(%d, %d, %d, %d)", character, facing, xpos, ypos); +void KyraEngine_v1::moveCharacterToPos(int character, int facing, int xpos, int ypos) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::moveCharacterToPos(%d, %d, %d, %d)", character, facing, xpos, ypos); Character *ch = &_characterList[character]; ch->facing = facing; _screen->hideMouse(); @@ -278,8 +278,8 @@ void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypo _screen->showMouse(); } -void KyraEngine::setCharacterPositionWithUpdate(int character) { - debugC(9, kDebugLevelMain, "KyraEngine::setCharacterPositionWithUpdate(%d)", character); +void KyraEngine_v1::setCharacterPositionWithUpdate(int character) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setCharacterPositionWithUpdate(%d)", character); setCharacterPosition(character, 0); _sprites->updateSceneAnims(); updateGameTimers(); @@ -290,8 +290,8 @@ void KyraEngine::setCharacterPositionWithUpdate(int character) { updateKyragemFading(); } -int KyraEngine::setCharacterPosition(int character, int *facingTable) { - debugC(9, kDebugLevelMain, "KyraEngine::setCharacterPosition(%d, %p)", character, (const void *)facingTable); +int KyraEngine_v1::setCharacterPosition(int character, int *facingTable) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setCharacterPosition(%d, %p)", character, (const void *)facingTable); if (character == 0) { _currentCharacter->x1 += _charXPosTable[_currentCharacter->facing]; @@ -307,8 +307,8 @@ int KyraEngine::setCharacterPosition(int character, int *facingTable) { return 0; } -void KyraEngine::setCharacterPositionHelper(int character, int *facingTable) { - debugC(9, kDebugLevelMain, "KyraEngine::setCharacterPositionHelper(%d, %p)", character, (const void *)facingTable); +void KyraEngine_v1::setCharacterPositionHelper(int character, int *facingTable) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setCharacterPositionHelper(%d, %p)", character, (const void *)facingTable); Character *ch = &_characterList[character]; ++ch->currentAnimFrame; int facing = ch->facing; @@ -391,8 +391,8 @@ void KyraEngine::setCharacterPositionHelper(int character, int *facingTable) { _animator->animRefreshNPC(character); } -int KyraEngine::getOppositeFacingDirection(int dir) { - debugC(9, kDebugLevelMain, "KyraEngine::getOppositeFacingDirection(%d)", dir); +int KyraEngine_v1::getOppositeFacingDirection(int dir) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::getOppositeFacingDirection(%d)", dir); switch (dir) { case 0: return 2; @@ -414,7 +414,7 @@ int KyraEngine::getOppositeFacingDirection(int dir) { return 0; } -void KyraEngine::loadSceneMsc() { +void KyraEngine_v1::loadSceneMsc() { assert(_currentCharacter->sceneId < _roomTableSize); int tableId = _roomTable[_currentCharacter->sceneId].nameIndex; assert(tableId < _roomFilenameTableSize); @@ -425,8 +425,8 @@ void KyraEngine::loadSceneMsc() { _screen->loadBitmap(fileNameBuffer, 3, 5, 0); } -void KyraEngine::startSceneScript(int brandonAlive) { - debugC(9, kDebugLevelMain, "KyraEngine::startSceneScript(%d)", brandonAlive); +void KyraEngine_v1::startSceneScript(int brandonAlive) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::startSceneScript(%d)", brandonAlive); assert(_currentCharacter->sceneId < _roomTableSize); int tableId = _roomTable[_currentCharacter->sceneId].nameIndex; assert(tableId < _roomFilenameTableSize); @@ -457,8 +457,8 @@ void KyraEngine::startSceneScript(int brandonAlive) { _scriptInterpreter->runScript(_scriptClick); } -void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { - debugC(9, kDebugLevelMain, "KyraEngine::initSceneData(%d, %d, %d)", facing, unk1, brandonAlive); +void KyraEngine_v1::initSceneData(int facing, int unk1, int brandonAlive) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::initSceneData(%d, %d, %d)", facing, unk1, brandonAlive); int16 xpos2 = 0; int setFacing = 1; @@ -627,8 +627,8 @@ void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { _scriptInterpreter->runScript(_scriptClick); } -void KyraEngine::initSceneObjectList(int brandonAlive) { - debugC(9, kDebugLevelMain, "KyraEngine::initSceneObjectList(%d)", brandonAlive); +void KyraEngine_v1::initSceneObjectList(int brandonAlive) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::initSceneObjectList(%d)", brandonAlive); for (int i = 0; i < 28; ++i) _animator->actors()[i].active = 0; @@ -798,7 +798,7 @@ void KyraEngine::initSceneObjectList(int brandonAlive) { _animator->copyChangedObjectsForward(0); } -void KyraEngine::initSceneScreen(int brandonAlive) { +void KyraEngine_v1::initSceneScreen(int brandonAlive) { if (_flags.platform == Common::kPlatformAmiga) { if (_unkScreenVar1 && !queryGameFlag(0xF0)) { memset(_screen->getPalette(2), 0, 32*3); @@ -871,8 +871,8 @@ void KyraEngine::initSceneScreen(int brandonAlive) { } } -int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) { - debugC(9, kDebugLevelMain, "KyraEngine::handleSceneChange(%d, %d, %d, %d)", xpos, ypos, unk1, frameReset); +int KyraEngine_v1::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::handleSceneChange(%d, %d, %d, %d)", xpos, ypos, unk1, frameReset); if (queryGameFlag(0xEF)) unk1 = 0; @@ -931,8 +931,8 @@ int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) return processSceneChange(_movFacingTable, unk1, frameReset); } -int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { - debugC(9, kDebugLevelMain, "KyraEngine::processSceneChange(%p, %d, %d)", (const void *)table, unk1, frameReset); +int KyraEngine_v1::processSceneChange(int *table, int unk1, int frameReset) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::processSceneChange(%p, %d, %d)", (const void *)table, unk1, frameReset); if (queryGameFlag(0xEF)) unk1 = 0; @@ -1024,8 +1024,8 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { return returnValue; } -int KyraEngine::changeScene(int facing) { - debugC(9, kDebugLevelMain, "KyraEngine::changeScene(%d)", facing); +int KyraEngine_v1::changeScene(int facing) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::changeScene(%d)", facing); if (queryGameFlag(0xEF)) { if (_currentCharacter->sceneId == 5) return 0; @@ -1142,7 +1142,7 @@ int KyraEngine::changeScene(int facing) { return returnValue; } -void KyraEngine::setCharactersInDefaultScene() { +void KyraEngine_v1::setCharactersInDefaultScene() { static const uint32 defaultSceneTable[][4] = { { 0xFFFF, 0x0004, 0x0003, 0xFFFF }, { 0xFFFF, 0x0022, 0xFFFF, 0x0000 }, @@ -1165,7 +1165,7 @@ void KyraEngine::setCharactersInDefaultScene() { } } -void KyraEngine::setCharactersPositions(int character) { +void KyraEngine_v1::setCharactersPositions(int character) { static uint16 initXPosTable[] = { 0x3200, 0x0024, 0x2230, 0x2F00, 0x0020, 0x002B, 0x00CA, 0x00F0, 0x0082, 0x00A2, 0x0042 @@ -1186,8 +1186,8 @@ void KyraEngine::setCharactersPositions(int character) { #pragma mark - Pathfinder #pragma mark - -int KyraEngine::findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize) { - debugC(9, kDebugLevelMain, "KyraEngine::findWay(%d, %d, %d, %d, %p, %d)", x, y, toX, toY, (const void *)moveTable, moveTableSize); +int KyraEngine_v1::findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::findWay(%d, %d, %d, %d, %p, %d)", x, y, toX, toY, (const void *)moveTable, moveTableSize); x &= 0xFFFC; toX &= 0xFFFC; y &= 0xFFFE; toY &= 0xFFFE; x = (int16)x; y = (int16)y; toX = (int16)toX; toY = (int16)toY; @@ -1301,8 +1301,8 @@ int KyraEngine::findWay(int x, int y, int toX, int toY, int *moveTable, int move return getMoveTableSize(moveTable); } -int KyraEngine::findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end) { - debugC(9, kDebugLevelMain, "KyraEngine::findSubPath(%d, %d, %d, %d, %p, %d, %d)", x, y, toX, toY, (const void *)moveTable, start, end); +int KyraEngine_v1::findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::findSubPath(%d, %d, %d, %d, %p, %d, %d)", x, y, toX, toY, (const void *)moveTable, start, end); // only used for debug specific code //static uint16 unkTable[] = { 8, 5 }; static const int8 facingTable1[] = { 7, 0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 0 }; @@ -1370,8 +1370,8 @@ int KyraEngine::findSubPath(int x, int y, int toX, int toY, int *moveTable, int return 0x7D00; } -int KyraEngine::getFacingFromPointToPoint(int x, int y, int toX, int toY) { - debugC(9, kDebugLevelMain, "KyraEngine::getFacingFromPointToPoint(%d, %d, %d, %d)", x, y, toX, toY); +int KyraEngine_v1::getFacingFromPointToPoint(int x, int y, int toX, int toY) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::getFacingFromPointToPoint(%d, %d, %d, %d)", x, y, toX, toY); static const int facingTable[] = { 1, 0, 1, 2, 3, 4, 3, 2, 7, 0, 7, 6, 5, 4, 5, 6 }; @@ -1413,14 +1413,14 @@ int KyraEngine::getFacingFromPointToPoint(int x, int y, int toX, int toY) { return facingTable[facingEntry]; } -void KyraEngine::changePosTowardsFacing(int &x, int &y, int facing) { - debugC(9, kDebugLevelMain, "KyraEngine::changePosTowardsFacing(%d, %d, %d)", x, y, facing); +void KyraEngine_v1::changePosTowardsFacing(int &x, int &y, int facing) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::changePosTowardsFacing(%d, %d, %d)", x, y, facing); x += _addXPosTable[facing]; y += _addYPosTable[facing]; } -bool KyraEngine::lineIsPassable(int x, int y) { - debugC(9, kDebugLevelMain, "KyraEngine::lineIsPassable(%d, %d)", x, y); +bool KyraEngine_v1::lineIsPassable(int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::lineIsPassable(%d, %d)", x, y); if (queryGameFlag(0xEF)) { if (_currentCharacter->sceneId == 5) return true; @@ -1478,8 +1478,8 @@ bool KyraEngine::lineIsPassable(int x, int y) { return true; } -int KyraEngine::getMoveTableSize(int *moveTable) { - debugC(9, kDebugLevelMain, "KyraEngine::getMoveTableSize(%p)", (const void *)moveTable); +int KyraEngine_v1::getMoveTableSize(int *moveTable) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::getMoveTableSize(%p)", (const void *)moveTable); int retValue = 0; if (moveTable[0] == 8) return 0; @@ -1573,8 +1573,8 @@ int KyraEngine::getMoveTableSize(int *moveTable) { return retValue; } -void KyraEngine::setupSceneResource(int sceneId) { - debugC(9, kDebugLevelMain, "KyraEngine::setupSceneResource(%d)", sceneId); +void KyraEngine_v1::setupSceneResource(int sceneId) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setupSceneResource(%d)", sceneId); if (!_flags.isTalkie) return; diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index 641a034eab..0e01801369 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -382,19 +382,6 @@ void Screen::k2IntroFadeToGrey(int delay) { setPaletteIndex(254, 254, 254, 254); } -void Screen::fadeSpecialPalette(int palIndex, int startIndex, int size, int fadeTime) { - debugC(9, kDebugLevelScreen, "fadeSpecialPalette(%d, %d, %d, %d)", palIndex, startIndex, size, fadeTime); - assert(_vm->palTable1()[palIndex]); - assert(_currentPalette); - uint8 tempPal[768]; - memcpy(tempPal, _currentPalette, 768); - memcpy(&tempPal[startIndex*3], _vm->palTable1()[palIndex], size*3); - fadePalette(tempPal, fadeTime*18); - memcpy(&_currentPalette[startIndex*3], &tempPal[startIndex*3], size*3); - setScreenPalette(_currentPalette); - _system->updateScreen(); -} - void Screen::fadePalette(const uint8 *palData, int delay) { debugC(9, kDebugLevelScreen, "Screen::fadePalette(%p, %d)", (const void *)palData, delay); updateScreen(); diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index a60cdbd637..355407a330 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -33,7 +33,6 @@ class OSystem; namespace Kyra { class KyraEngine; -class Debugger; struct Rect; struct ScreenDim { @@ -57,7 +56,7 @@ struct Font { }; class Screen { - friend class Debugger; + friend class Debugger_v1; public: enum { @@ -94,7 +93,7 @@ public: }; Screen(KyraEngine *vm, OSystem *system); - ~Screen(); + virtual ~Screen(); bool init(); @@ -136,7 +135,6 @@ public: void k2IntroFadeToGrey(int delay=0x54); - void fadeSpecialPalette(int palIndex, int startIndex, int size, int fadeTime); void fadePalette(const uint8 *palData, int delay); void setPaletteIndex(uint8 index, uint8 red, uint8 green, uint8 blue); @@ -243,7 +241,7 @@ public: uint16 getShapeSize(const uint8 *shp); -private: +protected: uint8 *getPagePtr(int pageNum); void updateDirtyRects(); void updateDirtyRectsOvl(); diff --git a/engines/kyra/screen_v1.cpp b/engines/kyra/screen_v1.cpp new file mode 100644 index 0000000000..dc0fd798fa --- /dev/null +++ b/engines/kyra/screen_v1.cpp @@ -0,0 +1,53 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "kyra/kyra_v1.h" +#include "kyra/screen_v1.h" + +namespace Kyra { + +Screen_v1::Screen_v1(KyraEngine_v1 *vm, OSystem *system) + : Screen(vm, system) { + _vm = vm; +} + +Screen_v1::~Screen_v1() { +} + +void Screen_v1::fadeSpecialPalette(int palIndex, int startIndex, int size, int fadeTime) { + debugC(9, kDebugLevelScreen, "Screen_v1::fadeSpecialPalette(%d, %d, %d, %d)", palIndex, startIndex, size, fadeTime); + + assert(_vm->palTable1()[palIndex]); + assert(_currentPalette); + uint8 tempPal[768]; + memcpy(tempPal, _currentPalette, 768); + memcpy(&tempPal[startIndex*3], _vm->palTable1()[palIndex], size*3); + fadePalette(tempPal, fadeTime*18); + memcpy(&_currentPalette[startIndex*3], &tempPal[startIndex*3], size*3); + setScreenPalette(_currentPalette); + _system->updateScreen(); +} + +} // end of namespace Kyra diff --git a/engines/kyra/screen_v1.h b/engines/kyra/screen_v1.h new file mode 100644 index 0000000000..988e28bfbf --- /dev/null +++ b/engines/kyra/screen_v1.h @@ -0,0 +1,48 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef KYRA_SCREEN_V1_H +#define KYRA_SCREEN_V1_H + +#include "kyra/screen.h" + +namespace Kyra { + +class KyraEngine_v1; + +class Screen_v1 : public Screen { +public: + Screen_v1(KyraEngine_v1 *vm, OSystem *system); + virtual ~Screen_v1(); + + void fadeSpecialPalette(int palIndex, int startIndex, int size, int fadeTime); + +protected: + KyraEngine_v1 *_vm; +}; + +} // end of namespace Kyra + +#endif diff --git a/engines/kyra/screen_v2.cpp b/engines/kyra/screen_v2.cpp new file mode 100644 index 0000000000..3e98cdbe5b --- /dev/null +++ b/engines/kyra/screen_v2.cpp @@ -0,0 +1,41 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "common/stdafx.h" + +#include "kyra/kyra_v2.h" +#include "kyra/screen_v2.h" + +namespace Kyra { + +Screen_v2::Screen_v2(KyraEngine_v2 *vm, OSystem *system) + : Screen(vm, system) { + _vm = vm; +} + +Screen_v2::~Screen_v2() { +} + +} // end of namespace Kyra diff --git a/engines/kyra/screen_v2.h b/engines/kyra/screen_v2.h new file mode 100644 index 0000000000..e45d44d3ff --- /dev/null +++ b/engines/kyra/screen_v2.h @@ -0,0 +1,45 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef KYRA_SCREEN_V2_H +#define KYRA_SCREEN_V2_H + +#include "kyra/screen.h" + +namespace Kyra { + +class KyraEngine_v2; + +class Screen_v2 : public Screen { +public: + Screen_v2(KyraEngine_v2 *vm, OSystem *system); + virtual ~Screen_v2(); +private: + KyraEngine_v2 *_vm; +}; + +} // End of namespace Kyra + +#endif diff --git a/engines/kyra/script_v1.cpp b/engines/kyra/script_v1.cpp index 18b6c791b9..14edf5fff8 100644 --- a/engines/kyra/script_v1.cpp +++ b/engines/kyra/script_v1.cpp @@ -30,7 +30,7 @@ #include "kyra/screen.h" #include "kyra/sprites.h" #include "kyra/wsamovie.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/text.h" #include "common/system.h" diff --git a/engines/kyra/seqplayer.cpp b/engines/kyra/seqplayer.cpp index ba221bf35a..20a98c66c1 100644 --- a/engines/kyra/seqplayer.cpp +++ b/engines/kyra/seqplayer.cpp @@ -28,7 +28,6 @@ #include "engines/engine.h" -#include "kyra/kyra.h" #include "kyra/resource.h" #include "kyra/screen.h" #include "kyra/sound.h" @@ -41,7 +40,7 @@ namespace Kyra { -SeqPlayer::SeqPlayer(KyraEngine* vm, OSystem* system) { +SeqPlayer::SeqPlayer(KyraEngine_v1 *vm, OSystem *system) { _vm = vm; _system = system; diff --git a/engines/kyra/seqplayer.h b/engines/kyra/seqplayer.h index 0fba0403e4..4636a956e9 100644 --- a/engines/kyra/seqplayer.h +++ b/engines/kyra/seqplayer.h @@ -26,11 +26,13 @@ #ifndef KYRA_SEQPLAYER_H #define KYRA_SEQPLAYER_H +#include "kyra/kyra_v1.h" + namespace Kyra { class SeqPlayer { public: - SeqPlayer(KyraEngine* vm, OSystem* system); + SeqPlayer(KyraEngine_v1 *vm, OSystem *system); ~SeqPlayer(); void setCopyViewOffs(bool offs) { @@ -43,9 +45,8 @@ public: bool playSequence(const uint8 *seqData, bool skipSeq); uint8 *setPanPages(int pageNum, int shape); - protected: - KyraEngine *_vm; + KyraEngine_v1 *_vm; OSystem *_system; Screen *_screen; Sound *_sound; diff --git a/engines/kyra/sequences_v1.cpp b/engines/kyra/sequences_v1.cpp index 8900e68d93..55c294fb1c 100644 --- a/engines/kyra/sequences_v1.cpp +++ b/engines/kyra/sequences_v1.cpp @@ -25,12 +25,12 @@ #include "kyra/kyra.h" #include "kyra/seqplayer.h" -#include "kyra/screen.h" +#include "kyra/screen_v1.h" #include "kyra/resource.h" #include "kyra/sound.h" #include "kyra/sprites.h" #include "kyra/wsamovie.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "kyra/text.h" #include "common/events.h" @@ -39,8 +39,8 @@ namespace Kyra { -void KyraEngine::seq_demo() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_demo()"); +void KyraEngine_v1::seq_demo() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_demo()"); snd_playTheme(0, 2); @@ -89,18 +89,18 @@ void KyraEngine::seq_demo() { _sound->haltTrack(); } -void KyraEngine::seq_intro() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_intro()"); +void KyraEngine_v1::seq_intro() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_intro()"); if (_flags.isTalkie) _res->loadPakFile("INTRO.VRM"); static const IntroProc introProcTable[] = { - &KyraEngine::seq_introLogos, - &KyraEngine::seq_introStory, - &KyraEngine::seq_introMalcolmTree, - &KyraEngine::seq_introKallakWriting, - &KyraEngine::seq_introKallakMalcolm + &KyraEngine_v1::seq_introLogos, + &KyraEngine_v1::seq_introStory, + &KyraEngine_v1::seq_introMalcolmTree, + &KyraEngine_v1::seq_introKallakWriting, + &KyraEngine_v1::seq_introKallakMalcolm }; Common::InSaveFile *in; @@ -129,8 +129,8 @@ void KyraEngine::seq_intro() { _res->unloadPakFile("INTRO.VRM"); } -void KyraEngine::seq_introLogos() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_introLogos()"); +void KyraEngine_v1::seq_introLogos() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_introLogos()"); if (_flags.platform == Common::kPlatformFMTowns) { _screen->loadBitmap("LOGO.CPS", 3, 3, _screen->_currentPalette); @@ -231,8 +231,8 @@ void KyraEngine::seq_introLogos() { _seq->playSequence(_seq_Forest, true); } -void KyraEngine::seq_introStory() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_introStory()"); +void KyraEngine_v1::seq_introStory() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_introStory()"); _screen->clearPage(3); _screen->clearPage(0); @@ -278,15 +278,15 @@ void KyraEngine::seq_introStory() { delay(360 * _tickLength); } -void KyraEngine::seq_introMalcolmTree() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_introMalcolmTree()"); +void KyraEngine_v1::seq_introMalcolmTree() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_introMalcolmTree()"); _screen->_curPage = 0; _screen->clearPage(3); _seq->playSequence(_seq_MalcolmTree, true); } -void KyraEngine::seq_introKallakWriting() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_introKallakWriting()"); +void KyraEngine_v1::seq_introKallakWriting() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_introKallakWriting()"); _seq->makeHandShapes(); _screen->setAnimBlockPtr(5060); _screen->_charWidth = -2; @@ -294,13 +294,13 @@ void KyraEngine::seq_introKallakWriting() { _seq->playSequence(_seq_KallakWriting, true); } -void KyraEngine::seq_introKallakMalcolm() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_introKallakMalcolm()"); +void KyraEngine_v1::seq_introKallakMalcolm() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_introKallakMalcolm()"); _screen->clearPage(3); _seq->playSequence(_seq_KallakMalcolm, true); } -void KyraEngine::seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly) { +void KyraEngine_v1::seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly) { debugC(9, kDebugLevelMain, "seq_createAmuletJewel(%d, %d, %d, %d)", jewel, page, noSound, drawOnly); static const uint16 specialJewelTable[] = { 0x167, 0x162, 0x15D, 0x158, 0x153, 0xFFFF @@ -360,7 +360,7 @@ void KyraEngine::seq_createAmuletJewel(int jewel, int page, int noSound, int dra setGameFlag(0x55+jewel); } -void KyraEngine::seq_brandonHealing() { +void KyraEngine_v1::seq_brandonHealing() { debugC(9, kDebugLevelMain, "seq_brandonHealing()"); if (!(_deathHandler & 8)) return; @@ -391,7 +391,7 @@ void KyraEngine::seq_brandonHealing() { _screen->showMouse(); } -void KyraEngine::seq_brandonHealing2() { +void KyraEngine_v1::seq_brandonHealing2() { debugC(9, kDebugLevelMain, "seq_brandonHealing2()"); _screen->hideMouse(); checkAmuletAnimFlags(); @@ -415,7 +415,7 @@ void KyraEngine::seq_brandonHealing2() { characterSays(2011, _poisonGone[1], 0, -2); } -void KyraEngine::seq_poisonDeathNow(int now) { +void KyraEngine_v1::seq_poisonDeathNow(int now) { debugC(9, kDebugLevelMain, "seq_poisonDeathNow(%d)", now); if (!(_brandonStatusBit & 1)) return; @@ -436,7 +436,7 @@ void KyraEngine::seq_poisonDeathNow(int now) { } } -void KyraEngine::seq_poisonDeathNowAnim() { +void KyraEngine_v1::seq_poisonDeathNowAnim() { debugC(9, kDebugLevelMain, "seq_poisonDeathNowAnim()"); _screen->hideMouse(); checkAmuletAnimFlags(); @@ -477,7 +477,7 @@ void KyraEngine::seq_poisonDeathNowAnim() { _screen->showMouse(); } -void KyraEngine::seq_playFluteAnimation() { +void KyraEngine_v1::seq_playFluteAnimation() { debugC(9, kDebugLevelMain, "seq_playFluteAnimation()"); _screen->hideMouse(); checkAmuletAnimFlags(); @@ -531,7 +531,7 @@ void KyraEngine::seq_playFluteAnimation() { } } -void KyraEngine::seq_winterScroll1() { +void KyraEngine_v1::seq_winterScroll1() { debugC(9, kDebugLevelMain, "seq_winterScroll1()"); _screen->hideMouse(); checkAmuletAnimFlags(); @@ -612,7 +612,7 @@ void KyraEngine::seq_winterScroll1() { _screen->showMouse(); } -void KyraEngine::seq_winterScroll2() { +void KyraEngine_v1::seq_winterScroll2() { debugC(9, kDebugLevelMain, "seq_winterScroll2()"); _screen->hideMouse(); checkAmuletAnimFlags(); @@ -641,7 +641,7 @@ void KyraEngine::seq_winterScroll2() { _screen->showMouse(); } -void KyraEngine::seq_makeBrandonInv() { +void KyraEngine_v1::seq_makeBrandonInv() { debugC(9, kDebugLevelMain, "seq_makeBrandonInv()"); if (_deathHandler == 8) return; @@ -667,7 +667,7 @@ void KyraEngine::seq_makeBrandonInv() { _screen->showMouse(); } -void KyraEngine::seq_makeBrandonNormal() { +void KyraEngine_v1::seq_makeBrandonNormal() { debugC(9, kDebugLevelMain, "seq_makeBrandonNormal()"); _screen->hideMouse(); _brandonStatusBit |= 0x40; @@ -683,7 +683,7 @@ void KyraEngine::seq_makeBrandonNormal() { _screen->showMouse(); } -void KyraEngine::seq_makeBrandonNormal2() { +void KyraEngine_v1::seq_makeBrandonNormal2() { debugC(9, kDebugLevelMain, "seq_makeBrandonNormal2()"); _screen->hideMouse(); assert(_brandonToWispTable); @@ -709,7 +709,7 @@ void KyraEngine::seq_makeBrandonNormal2() { _screen->showMouse(); } -void KyraEngine::seq_makeBrandonWisp() { +void KyraEngine_v1::seq_makeBrandonWisp() { debugC(9, kDebugLevelMain, "seq_makeBrandonWisp()"); if (_deathHandler == 8) return; @@ -751,7 +751,7 @@ void KyraEngine::seq_makeBrandonWisp() { _screen->showMouse(); } -void KyraEngine::seq_dispelMagicAnimation() { +void KyraEngine_v1::seq_dispelMagicAnimation() { debugC(9, kDebugLevelMain, "seq_dispelMagicAnimation()"); if (_deathHandler == 8) return; @@ -793,7 +793,7 @@ void KyraEngine::seq_dispelMagicAnimation() { _screen->showMouse(); } -void KyraEngine::seq_fillFlaskWithWater(int item, int type) { +void KyraEngine_v1::seq_fillFlaskWithWater(int item, int type) { debugC(9, kDebugLevelMain, "seq_fillFlaskWithWater(%d, %d)", item, type); int newItem = -1; static const uint8 flaskTable1[] = { 0x46, 0x48, 0x4A, 0x4C }; @@ -826,8 +826,8 @@ void KyraEngine::seq_fillFlaskWithWater(int item, int type) { characterSays(voiceEntries[type], _fullFlask[type], 0, -2); } -void KyraEngine::seq_playDrinkPotionAnim(int item, int unk2, int flags) { - debugC(9, kDebugLevelMain, "KyraEngine::seq_playDrinkPotionAnim(%d, %d, %d)", item, unk2, flags); +void KyraEngine_v1::seq_playDrinkPotionAnim(int item, int unk2, int flags) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_playDrinkPotionAnim(%d, %d, %d)", item, unk2, flags); uint8 red, green, blue; switch (item) { @@ -918,8 +918,8 @@ void KyraEngine::seq_playDrinkPotionAnim(int item, int unk2, int flags) { _screen->showMouse(); } -int KyraEngine::seq_playEnd() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_playEnd()"); +int KyraEngine_v1::seq_playEnd() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_playEnd()"); if (_endSequenceSkipFlag) return 0; @@ -1011,8 +1011,8 @@ int KyraEngine::seq_playEnd() { return 0; } -void KyraEngine::seq_brandonToStone() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_brandonToStone()"); +void KyraEngine_v1::seq_brandonToStone() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_brandonToStone()"); _screen->hideMouse(); assert(_brandonStoneTable); setupShapes123(_brandonStoneTable, 14, 0); @@ -1027,8 +1027,8 @@ void KyraEngine::seq_brandonToStone() { _screen->showMouse(); } -void KyraEngine::seq_playEnding() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_playEnding()"); +void KyraEngine_v1::seq_playEnding() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_playEnding()"); if (_quitFlag) return; _screen->hideMouse(); @@ -1051,8 +1051,8 @@ void KyraEngine::seq_playEnding() { seq_playCredits(); } -void KyraEngine::seq_playCredits() { - debugC(9, kDebugLevelMain, "KyraEngine::seq_playCredits()"); +void KyraEngine_v1::seq_playCredits() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_playCredits()"); static const uint8 colorMap[] = { 0, 0, 0xC, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const char stringTerms[] = { 0x5, 0xd, 0x0}; static const int numStrings = 250; @@ -1208,13 +1208,13 @@ void KyraEngine::seq_playCredits() { _screen->showMouse(); } -bool KyraEngine::seq_skipSequence() const { - debugC(9, kDebugLevelMain, "KyraEngine::seq_skipSequence()"); +bool KyraEngine_v1::seq_skipSequence() const { + debugC(9, kDebugLevelMain, "KyraEngine_v1::seq_skipSequence()"); return _quitFlag || _abortIntroFlag; } -int KyraEngine::handleMalcolmFlag() { - debugC(9, kDebugLevelMain, "KyraEngine::handleMalcolmFlag()"); +int KyraEngine_v1::handleMalcolmFlag() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::handleMalcolmFlag()"); static uint16 frame = 0; static uint32 timer1 = 0; static uint32 timer2 = 0; @@ -1382,8 +1382,8 @@ int KyraEngine::handleMalcolmFlag() { return 0; } -int KyraEngine::handleBeadState() { - debugC(9, kDebugLevelMain, "KyraEngine::handleBeadState()"); +int KyraEngine_v1::handleBeadState() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::handleBeadState()"); static uint32 timer1 = 0; static uint32 timer2 = 0; static BeadState beadState1 = { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -1602,8 +1602,8 @@ int KyraEngine::handleBeadState() { return 0; } -void KyraEngine::initBeadState(int x, int y, int x2, int y2, int unk, BeadState *ptr) { - debugC(9, kDebugLevelMain, "KyraEngine::initBeadState(%d, %d, %d, %d, %d, %p)", x, y, x2, y2, unk, (const void *)ptr); +void KyraEngine_v1::initBeadState(int x, int y, int x2, int y2, int unk, BeadState *ptr) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::initBeadState(%d, %d, %d, %d, %d, %p)", x, y, x2, y2, unk, (const void *)ptr); ptr->unk9 = unk; int xDiff = x2 - x; int yDiff = y2 - y; @@ -1636,8 +1636,8 @@ void KyraEngine::initBeadState(int x, int y, int x2, int y2, int unk, BeadState ptr->unk8 = unk2; } -int KyraEngine::processBead(int x, int y, int &x2, int &y2, BeadState *ptr) { - debugC(9, kDebugLevelMain, "KyraEngine::processBead(%d, %d, %p, %p, %p)", x, y, (const void *)&x2, (const void *)&y2, (const void *)ptr); +int KyraEngine_v1::processBead(int x, int y, int &x2, int &y2, BeadState *ptr) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::processBead(%d, %d, %p, %p, %p)", x, y, (const void *)&x2, (const void *)&y2, (const void *)ptr); if (x == ptr->dstX && y == ptr->dstY) return 1; @@ -1673,8 +1673,8 @@ int KyraEngine::processBead(int x, int y, int &x2, int &y2, BeadState *ptr) { return 0; } -void KyraEngine::setupPanPages() { - debugC(9, kDebugLevelMain, "KyraEngine::setupPanPages()"); +void KyraEngine_v1::setupPanPages() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setupPanPages()"); _screen->loadBitmap("BEAD.CPS", 3, 3, 0); if (_flags.platform == Common::kPlatformMacintosh || _flags.platform == Common::kPlatformAmiga) { int pageBackUp = _screen->_curPage; @@ -1702,8 +1702,8 @@ void KyraEngine::setupPanPages() { } } -void KyraEngine::freePanPages() { - debugC(9, kDebugLevelMain, "KyraEngine::freePanPages()"); +void KyraEngine_v1::freePanPages() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::freePanPages()"); delete _endSequenceBackUpRect; _endSequenceBackUpRect = 0; for (int i = 0; i <= 19; ++i) { @@ -1712,8 +1712,8 @@ void KyraEngine::freePanPages() { } } -void KyraEngine::closeFinalWsa() { - debugC(9, kDebugLevelMain, "KyraEngine::closeFinalWsa()"); +void KyraEngine_v1::closeFinalWsa() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::closeFinalWsa()"); delete _finalA; _finalA = 0; delete _finalB; @@ -1724,7 +1724,7 @@ void KyraEngine::closeFinalWsa() { _endSequenceNeedLoading = 1; } -void KyraEngine::updateKyragemFading() { +void KyraEngine_v1::updateKyragemFading() { static const uint8 kyraGemPalette[0x28] = { 0x3F, 0x3B, 0x38, 0x34, 0x32, 0x2F, 0x2C, 0x29, 0x25, 0x22, 0x1F, 0x1C, 0x19, 0x16, 0x12, 0x0F, 0x0C, 0x0A, 0x06, 0x03, @@ -1794,8 +1794,8 @@ void KyraEngine::updateKyragemFading() { _kyragemFadingState.timerCount = _system->getMillis() + 120 * _tickLength; } -void KyraEngine::drawJewelPress(int jewel, int drawSpecial) { - debugC(9, kDebugLevelMain, "KyraEngine::drawJewelPress(%d, %d)", jewel, drawSpecial); +void KyraEngine_v1::drawJewelPress(int jewel, int drawSpecial) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::drawJewelPress(%d, %d)", jewel, drawSpecial); _screen->hideMouse(); int shape = 0; @@ -1819,8 +1819,8 @@ void KyraEngine::drawJewelPress(int jewel, int drawSpecial) { _screen->showMouse(); } -void KyraEngine::drawJewelsFadeOutStart() { - debugC(9, kDebugLevelMain, "KyraEngine::drawJewelsFadeOutStart()"); +void KyraEngine_v1::drawJewelsFadeOutStart() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::drawJewelsFadeOutStart()"); static const uint16 jewelTable1[] = { 0x164, 0x15F, 0x15A, 0x155, 0x150, 0xFFFF }; static const uint16 jewelTable2[] = { 0x163, 0x15E, 0x159, 0x154, 0x14F, 0xFFFF }; static const uint16 jewelTable3[] = { 0x166, 0x160, 0x15C, 0x157, 0x152, 0xFFFF }; @@ -1839,8 +1839,8 @@ void KyraEngine::drawJewelsFadeOutStart() { } } -void KyraEngine::drawJewelsFadeOutEnd(int jewel) { - debugC(9, kDebugLevelMain, "KyraEngine::drawJewelsFadeOutEnd(%d)", jewel); +void KyraEngine_v1::drawJewelsFadeOutEnd(int jewel) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::drawJewelsFadeOutEnd(%d)", jewel); static const uint16 jewelTable[] = { 0x153, 0x158, 0x15D, 0x162, 0x148, 0xFFFF }; int newDelay = 0; diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index 1d2ff2e512..562754b9c5 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -434,117 +434,6 @@ void SoundMidiPC::beginFadeOut() { _fadeStartTime = _vm->_system->getMillis(); } -#pragma mark - - -bool KyraEngine::speechEnabled() { - return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2); -} - -bool KyraEngine::textEnabled() { - return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2); -} - -void KyraEngine::snd_playTheme(int file, int track) { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playTheme(%d)", file); - _curSfxFile = _curMusicTheme = file; - _sound->loadSoundFile(_curMusicTheme); - _sound->playTrack(track); -} - -void KyraEngine::snd_playSoundEffect(int track) { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playSoundEffect(%d)", track); - if (_flags.platform == Common::kPlatformFMTowns && track == 49) { - snd_playWanderScoreViaMap(56, 1); - return; - } - _sound->playSoundEffect(track); -} - -void KyraEngine::snd_playWanderScoreViaMap(int command, int restart) { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playWanderScoreViaMap(%d, %d)", command, restart); - if (restart) - _lastMusicCommand = -1; - - if (_flags.platform == Common::kPlatformFMTowns) { - if (command == 1) { - _sound->beginFadeOut(); - } else if (command >= 35 && command <= 38) { - snd_playSoundEffect(command-20); - } else if (command >= 2) { - if (_lastMusicCommand != command) { - // the original does -2 here we handle this inside _sound->playTrack() - _sound->playTrack(command); - } - } else { - _sound->haltTrack(); - } - } else { - static const int8 soundTable[] = { - -1, 0, -1, 1, 0, 3, 0, 2, - 0, 4, 1, 2, 1, 3, 1, 4, - 1, 92, 1, 6, 1, 7, 2, 2, - 2, 3, 2, 4, 2, 5, 2, 6, - 2, 7, 3, 3, 3, 4, 1, 8, - 1, 9, 4, 2, 4, 3, 4, 4, - 4, 5, 4, 6, 4, 7, 4, 8, - 1, 11, 1, 12, 1, 14, 1, 13, - 4, 9, 5, 12, 6, 2, 6, 6, - 6, 7, 6, 8, 6, 9, 6, 3, - 6, 4, 6, 5, 7, 2, 7, 3, - 7, 4, 7, 5, 7, 6, 7, 7, - 7, 8, 7, 9, 8, 2, 8, 3, - 8, 4, 8, 5, 6, 11, 5, 11 - }; - //if (!_disableSound) { - // XXX - //} - assert(command*2+1 < ARRAYSIZE(soundTable)); - if (_curMusicTheme != soundTable[command*2]+1) { - if (soundTable[command*2] != -1) - snd_playTheme(soundTable[command*2]+1); - } - - if (command != 1) { - if (_lastMusicCommand != command) { - _sound->haltTrack(); - _sound->playTrack(soundTable[command*2+1]); - } - } else { - _sound->beginFadeOut(); - } - } - - _lastMusicCommand = command; -} - -void KyraEngine::snd_playVoiceFile(int id) { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playVoiceFile(%d)", id); - char vocFile[9]; - assert(id >= 0 && id < 9999); - sprintf(vocFile, "%03d", id); - _sound->voicePlay(vocFile); -} - -void KyraEngine::snd_voiceWaitForFinish(bool ingame) { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_voiceWaitForFinish(%d)", ingame); - while (_sound->voiceIsPlaying() && !_skipFlag) { - if (ingame) - delay(10, true); - else - _system->delayMillis(10); - } -} - -void KyraEngine::snd_stopVoice() { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_stopVoice()"); - _sound->voiceStop(); -} - -bool KyraEngine::snd_voiceIsPlaying() { - debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_voiceIsPlaying()"); - return _sound->voiceIsPlaying(); -} - // static res const Sound::SpeechCodecs Sound::_supportedCodes[] = { diff --git a/engines/kyra/sound_v1.cpp b/engines/kyra/sound_v1.cpp new file mode 100644 index 0000000000..3ea86189b2 --- /dev/null +++ b/engines/kyra/sound_v1.cpp @@ -0,0 +1,140 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "kyra/sound.h" +#include "kyra/kyra_v1.h" + +namespace Kyra { + +bool KyraEngine_v1::speechEnabled() { + return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2); +} + +bool KyraEngine_v1::textEnabled() { + return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2); +} + +void KyraEngine_v1::snd_playTheme(int file, int track) { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playTheme(%d)", file); + _curSfxFile = _curMusicTheme = file; + _sound->loadSoundFile(_curMusicTheme); + _sound->playTrack(track); +} + +void KyraEngine_v1::snd_playSoundEffect(int track) { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playSoundEffect(%d)", track); + if (_flags.platform == Common::kPlatformFMTowns && track == 49) { + snd_playWanderScoreViaMap(56, 1); + return; + } + _sound->playSoundEffect(track); +} + +void KyraEngine_v1::snd_playWanderScoreViaMap(int command, int restart) { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playWanderScoreViaMap(%d, %d)", command, restart); + if (restart) + _lastMusicCommand = -1; + + if (_flags.platform == Common::kPlatformFMTowns) { + if (command == 1) { + _sound->beginFadeOut(); + } else if (command >= 35 && command <= 38) { + snd_playSoundEffect(command-20); + } else if (command >= 2) { + if (_lastMusicCommand != command) { + // the original does -2 here we handle this inside _sound->playTrack() + _sound->playTrack(command); + } + } else { + _sound->haltTrack(); + } + } else { + static const int8 soundTable[] = { + -1, 0, -1, 1, 0, 3, 0, 2, + 0, 4, 1, 2, 1, 3, 1, 4, + 1, 92, 1, 6, 1, 7, 2, 2, + 2, 3, 2, 4, 2, 5, 2, 6, + 2, 7, 3, 3, 3, 4, 1, 8, + 1, 9, 4, 2, 4, 3, 4, 4, + 4, 5, 4, 6, 4, 7, 4, 8, + 1, 11, 1, 12, 1, 14, 1, 13, + 4, 9, 5, 12, 6, 2, 6, 6, + 6, 7, 6, 8, 6, 9, 6, 3, + 6, 4, 6, 5, 7, 2, 7, 3, + 7, 4, 7, 5, 7, 6, 7, 7, + 7, 8, 7, 9, 8, 2, 8, 3, + 8, 4, 8, 5, 6, 11, 5, 11 + }; + //if (!_disableSound) { + // XXX + //} + assert(command*2+1 < ARRAYSIZE(soundTable)); + if (_curMusicTheme != soundTable[command*2]+1) { + if (soundTable[command*2] != -1) + snd_playTheme(soundTable[command*2]+1); + } + + if (command != 1) { + if (_lastMusicCommand != command) { + _sound->haltTrack(); + _sound->playTrack(soundTable[command*2+1]); + } + } else { + _sound->beginFadeOut(); + } + } + + _lastMusicCommand = command; +} + +void KyraEngine_v1::snd_playVoiceFile(int id) { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playVoiceFile(%d)", id); + char vocFile[9]; + assert(id >= 0 && id < 9999); + sprintf(vocFile, "%03d", id); + _sound->voicePlay(vocFile); +} + +void KyraEngine_v1::snd_voiceWaitForFinish(bool ingame) { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_voiceWaitForFinish(%d)", ingame); + while (_sound->voiceIsPlaying() && !_skipFlag) { + if (ingame) + delay(10, true); + else + _system->delayMillis(10); + } +} + +void KyraEngine_v1::snd_stopVoice() { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_stopVoice()"); + _sound->voiceStop(); +} + +bool KyraEngine_v1::snd_voiceIsPlaying() { + debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_voiceIsPlaying()"); + return _sound->voiceIsPlaying(); +} + +} // end of namespace Kyra diff --git a/engines/kyra/sprites.cpp b/engines/kyra/sprites.cpp index 0a3f243df2..1a2c7f6146 100644 --- a/engines/kyra/sprites.cpp +++ b/engines/kyra/sprites.cpp @@ -29,14 +29,14 @@ #include "common/util.h" #include "common/system.h" #include "kyra/screen.h" -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/sprites.h" #include "kyra/resource.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" namespace Kyra { -Sprites::Sprites(KyraEngine *vm, OSystem *system) { +Sprites::Sprites(KyraEngine_v1 *vm, OSystem *system) { _vm = vm; _res = vm->resource(); _screen = vm->screen(); diff --git a/engines/kyra/sprites.h b/engines/kyra/sprites.h index 179942d519..255d878635 100644 --- a/engines/kyra/sprites.h +++ b/engines/kyra/sprites.h @@ -26,6 +26,8 @@ #ifndef KYRA_SPRITES_H #define KYRA_SPRITES_H +#include "kyra/kyra_v1.h" + namespace Kyra { #define MAX_NUM_ANIMS 11 @@ -61,10 +63,11 @@ struct Anim { bool disable; }; +class KyraEngine_v1; + class Sprites { public: - - Sprites(KyraEngine *vm, OSystem *system); + Sprites(KyraEngine_v1 *vm, OSystem *system); ~Sprites(); void updateSceneAnims(); @@ -83,7 +86,7 @@ public: protected: void freeSceneShapes(); - KyraEngine *_vm; + KyraEngine_v1 *_vm; Resource *_res; OSystem *_system; Screen *_screen; diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 247cf90705..68e5401481 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -27,6 +27,7 @@ #include "common/endian.h" #include "common/md5.h" #include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/kyra_v2.h" #include "kyra/kyra_v3.h" #include "kyra/screen.h" @@ -617,7 +618,7 @@ uint8 *StaticResource::getFile(const char *name, int &size) { #pragma mark - -void KyraEngine::initStaticResource() { +void KyraEngine_v1::initStaticResource() { int temp = 0; _seq_Forest = _staticres->loadRawData(kForestSeq, temp); _seq_KallakWriting = _staticres->loadRawData(kKallakWritingSeq, temp); @@ -708,7 +709,7 @@ void KyraEngine::initStaticResource() { } } -void KyraEngine::loadMouseShapes() { +void KyraEngine_v1::loadMouseShapes() { _screen->loadBitmap("MOUSE.CPS", 3, 3, 0); _screen->_curPage = 2; _shapes[0] = _screen->encodeShape(0, 0, 8, 10, 0); @@ -724,7 +725,7 @@ void KyraEngine::loadMouseShapes() { _screen->setShapePages(5, 3); } -void KyraEngine::loadCharacterShapes() { +void KyraEngine_v1::loadCharacterShapes() { int curImage = 0xFF; int videoPage = _screen->_curPage; _screen->_curPage = 2; @@ -745,7 +746,7 @@ void KyraEngine::loadCharacterShapes() { _screen->_curPage = videoPage; } -void KyraEngine::loadSpecialEffectShapes() { +void KyraEngine_v1::loadSpecialEffectShapes() { _screen->loadBitmap("EFFECTS.CPS", 3, 3, 0); _screen->_curPage = 2; @@ -763,7 +764,7 @@ void KyraEngine::loadSpecialEffectShapes() { _shapes[currShape] = _screen->encodeShape((currShape-201) * 16, 106, 16, 16, 1); } -void KyraEngine::loadItems() { +void KyraEngine_v1::loadItems() { int shape; _screen->loadBitmap("JEWELS3.CPS", 3, 3, 0); @@ -817,7 +818,7 @@ void KyraEngine::loadItems() { delete[] fileData; } -void KyraEngine::loadButtonShapes() { +void KyraEngine_v1::loadButtonShapes() { _screen->loadBitmap("BUTTONS2.CPS", 3, 3, 0); _screen->_curPage = 2; _scrollUpButton.process0PtrShape = _screen->encodeShape(0, 0, 24, 14, 1); @@ -829,7 +830,7 @@ void KyraEngine::loadButtonShapes() { _screen->_curPage = 0; } -void KyraEngine::loadMainScreen(int page) { +void KyraEngine_v1::loadMainScreen(int page) { _screen->clearPage(page); if (_flags.lang == Common::EN_ANY && !_flags.isTalkie && (_flags.platform == Common::kPlatformPC || _flags.platform == Common::kPlatformAmiga)) @@ -878,7 +879,7 @@ const ScreenDim Screen::_screenDimTableK3[] = { const int Screen::_screenDimTableCountK3 = ARRAYSIZE(_screenDimTableK3); -const char *KyraEngine::_soundFiles[] = { +const char *KyraEngine_v1::_soundFiles[] = { "INTRO", "KYRA1A", "KYRA1B", @@ -891,9 +892,9 @@ const char *KyraEngine::_soundFiles[] = { "KYRAMISC" }; -const int KyraEngine::_soundFilesCount = ARRAYSIZE(KyraEngine::_soundFiles); +const int KyraEngine_v1::_soundFilesCount = ARRAYSIZE(KyraEngine_v1::_soundFiles); -const char *KyraEngine::_soundFilesTowns[] = { +const char *KyraEngine_v1::_soundFilesTowns[] = { "TW_INTRO.SFX", "TW_SCEN1.SFX", "TW_SCEN2.SFX", @@ -902,49 +903,49 @@ const char *KyraEngine::_soundFilesTowns[] = { "TW_SCEN5.SFX", }; -const int KyraEngine::_soundFilesTownsCount = ARRAYSIZE(KyraEngine::_soundFilesTowns); +const int KyraEngine_v1::_soundFilesTownsCount = ARRAYSIZE(KyraEngine_v1::_soundFilesTowns); -const int8 KyraEngine::_charXPosTable[] = { +const int8 KyraEngine_v1::_charXPosTable[] = { 0, 4, 4, 4, 0, -4, -4, -4 }; -const int8 KyraEngine::_addXPosTable[] = { +const int8 KyraEngine_v1::_addXPosTable[] = { 4, 4, 0, -4, -4, -4, 0, 4 }; -const int8 KyraEngine::_charYPosTable[] = { +const int8 KyraEngine_v1::_charYPosTable[] = { -2, -2, 0, 2, 2, 2, 0, -2 }; -const int8 KyraEngine::_addYPosTable[] = { +const int8 KyraEngine_v1::_addYPosTable[] = { 0, -2, -2, -2, 0, 2, 2, 2 }; -const uint16 KyraEngine::_itemPosX[] = { +const uint16 KyraEngine_v1::_itemPosX[] = { 95, 115, 135, 155, 175, 95, 115, 135, 155, 175 }; -const uint8 KyraEngine::_itemPosY[] = { +const uint8 KyraEngine_v1::_itemPosY[] = { 160, 160, 160, 160, 160, 181, 181, 181, 181, 181 }; -void KyraEngine::setupButtonData() { +void KyraEngine_v1::setupButtonData() { static Button buttonData[] = { - { 0, 0x02, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x05D, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x01, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x009, 0xA4, 0x36, 0x1E, /*XXX,*/ 0, &KyraEngine::buttonMenuCallback/*, XXX*/ }, - { 0, 0x03, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x071, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x04, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x085, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x05, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x099, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x06, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x0AD, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x07, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x05D, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x08, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x071, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x09, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x085, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x0A, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x099, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x0B, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x0AD, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine::buttonInventoryCallback/*, XXX*/ }, - { 0, 0x15, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0FD, 0x9C, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine::buttonAmuletCallback/*, XXX*/ }, - { 0, 0x16, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0E7, 0xAA, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine::buttonAmuletCallback/*, XXX*/ }, - { 0, 0x17, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0FD, 0xB5, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine::buttonAmuletCallback/*, XXX*/ }, - { 0, 0x18, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x113, 0xAA, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine::buttonAmuletCallback/*, XXX*/ } + { 0, 0x02, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x05D, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x01, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x009, 0xA4, 0x36, 0x1E, /*XXX,*/ 0, &KyraEngine_v1::buttonMenuCallback/*, XXX*/ }, + { 0, 0x03, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x071, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x04, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x085, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x05, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x099, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x06, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x0AD, 0x9E, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x07, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x05D, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x08, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x071, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x09, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x085, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x0A, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x099, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x0B, /*XXX,*/0, 0, 0, /*XXX,*/ 0x0400, 0, 0, 0, 0, 0, 0, 0, 0x0AD, 0xB3, 0x13, 0x14, /*XXX,*/ 0, &KyraEngine_v1::buttonInventoryCallback/*, XXX*/ }, + { 0, 0x15, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0FD, 0x9C, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine_v1::buttonAmuletCallback/*, XXX*/ }, + { 0, 0x16, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0E7, 0xAA, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine_v1::buttonAmuletCallback/*, XXX*/ }, + { 0, 0x17, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x0FD, 0xB5, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine_v1::buttonAmuletCallback/*, XXX*/ }, + { 0, 0x18, /*XXX,*/1, 1, 1, /*XXX,*/ 0x0487, 0, 0, 0, 0, 0, 0, 0, 0x113, 0xAA, 0x1A, 0x12, /*XXX,*/ 0, &KyraEngine_v1::buttonAmuletCallback/*, XXX*/ } }; static Button *buttonDataListPtr[] = { @@ -969,10 +970,10 @@ void KyraEngine::setupButtonData() { _buttonDataListPtr = buttonDataListPtr; } -Button KyraEngine::_scrollUpButton = {0, 0x12, 1, 1, 1, 0x483, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x0f, 0, 0}; -Button KyraEngine::_scrollDownButton = {0, 0x13, 1, 1, 1, 0x483, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x0f, 0, 0}; +Button KyraEngine_v1::_scrollUpButton = {0, 0x12, 1, 1, 1, 0x483, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x0f, 0, 0}; +Button KyraEngine_v1::_scrollDownButton = {0, 0x13, 1, 1, 1, 0x483, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x0f, 0, 0}; -Button KyraEngine::_menuButtonData[] = { +Button KyraEngine_v1::_menuButtonData[] = { { 0, 0x0c, /*XXX,*/1, 1, 1, /*XXX,*/ 0x487, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*XXX,*/ 0, 0 /*, XXX*/ }, { 0, 0x0d, /*XXX,*/1, 1, 1, /*XXX,*/ 0x487, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*XXX,*/ 0, 0 /*, XXX*/ }, { 0, 0x0e, /*XXX,*/1, 1, 1, /*XXX,*/ 0x487, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*XXX,*/ 0, 0 /*, XXX*/ }, @@ -981,33 +982,33 @@ Button KyraEngine::_menuButtonData[] = { { 0, 0x11, /*XXX,*/1, 1, 1, /*XXX,*/ 0x487, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*XXX,*/ 0, 0 /*, XXX*/ } }; -void KyraEngine::setupMenu() { +void KyraEngine_v1::setupMenu() { static Menu menu[] = { { -1, -1, 208, 136, 248, 249, 250, 0, 251, -1, 8, 0, 5, -1, -1, -1, -1, { {1, 0, 0, 0, -1, -1, 30, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_loadGameMenu, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_loadGameMenu, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, -1, -1, 47, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_saveGameMenu, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_saveGameMenu, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, -1, -1, 64, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_gameControlsMenu, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_gameControlsMenu, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, -1, -1, 81, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_quitPlaying, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_quitPlaying, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 86, 0, 110, 92, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_resumeGame, -1, 0, 0, 0, 0, 0} + 248, 249, 250, &KyraEngine_v1::gui_resumeGame, -1, 0, 0, 0, 0, 0} } }, { -1, -1, 288, 56, 248, 249, 250, 0, 254,-1, 8, 0, 2, -1, -1, -1, -1, { {1, 0, 0, 0, 24, 0, 30, 72, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_quitConfirmYes, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_quitConfirmYes, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 192, 0, 30, 72, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_quitConfirmNo, -1, 0, 0, 0, 0, 0} + 248, 249, 250, &KyraEngine_v1::gui_quitConfirmNo, -1, 0, 0, 0, 0, 0} } }, { -1, -1, 288, 160, 248, 249, 250, 0, 251, -1, 8, 0, 6, 132, 22, 132, 124, @@ -1028,46 +1029,46 @@ void KyraEngine::setupMenu() { 248, 249, 250, 0, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 184, 0, 134, 88, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_cancelSubMenu, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_cancelSubMenu, -1, 0, 0, 0, 0, 0}, } }, { -1, -1, 288, 67, 248, 249, 250, 0, 251, -1, 8, 0, 3, -1, -1, -1, -1, { {1, 0, 0, 0, 24, 0, 44, 72, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_savegameConfirm, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_savegameConfirm, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 192, 0, 44, 72, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_cancelSubMenu, -1, 0, 0, 0, 0, 0} + 248, 249, 250, &KyraEngine_v1::gui_cancelSubMenu, -1, 0, 0, 0, 0, 0} } }, { -1, -1, 208, 76, 248, 249, 250, 0, 251, -1, 8, 0, 2, -1, -1, -1, -1, { {1, 0, 0, 0, -1, -1, 30, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_loadGameMenu, -1, 0, 0, 0, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_loadGameMenu, -1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, -1, -1, 47, 148, 15, 252, 253, 24, 0, - 248, 249, 250, &KyraEngine::gui_quitPlaying, -1, 0, 0, 0, 0, 0} + 248, 249, 250, &KyraEngine_v1::gui_quitPlaying, -1, 0, 0, 0, 0, 0} } }, { -1, -1, 208, 153, 248, 249, 250, 0, 251, -1, 8, 0, 6, -1, -1, -1, -1, { {1, 0, 0, 0, 110, 0, 30, 64, 15, 252, 253, 5, 0, - 248, 249, 250, &KyraEngine::gui_controlsChangeMusic, -1, 0, 34, 32, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_controlsChangeMusic, -1, 0, 34, 32, 0, 0}, {1, 0, 0, 0, 110, 0, 47, 64, 15, 252, 253, 5, 0, - 248, 249, 250, &KyraEngine::gui_controlsChangeSounds, -1, 0, 34, 49, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_controlsChangeSounds, -1, 0, 34, 49, 0, 0}, {1, 0, 0, 0, 110, 0, 64, 64, 15, 252, 253, 5, 0, - 248, 249, 250, &KyraEngine::gui_controlsChangeWalk, -1, 0, 34, 66, 0, 0}, + 248, 249, 250, &KyraEngine_v1::gui_controlsChangeWalk, -1, 0, 34, 66, 0, 0}, {1, 0, 0, 0, 110, 0, 81, 64, 15, 252, 253, 5, 0, 248, 249, 250, 0, -1, 0, 34, 83, 0, 0 }, {1, 0, 0, 0, 110, 0, 98, 64, 15, 252, 253, 5, 0, - 248, 249, 250, &KyraEngine::gui_controlsChangeText, -1, 0, 34, 100, 0, 0 }, + 248, 249, 250, &KyraEngine_v1::gui_controlsChangeText, -1, 0, 34, 100, 0, 0 }, {1, 0, 0, 0, 64, 0, 127, 92, 15, 252, 253, -1, 255, - 248, 249, 250, &KyraEngine::gui_controlsApply, -1, -0, 0, 0, 0, 0} + 248, 249, 250, &KyraEngine_v1::gui_controlsApply, -1, -0, 0, 0, 0, 0} } } }; @@ -1075,31 +1076,31 @@ void KyraEngine::setupMenu() { _menu = menu; } -const uint8 KyraEngine::_magicMouseItemStartFrame[] = { +const uint8 KyraEngine_v1::_magicMouseItemStartFrame[] = { 0xAD, 0xB7, 0xBE, 0x00 }; -const uint8 KyraEngine::_magicMouseItemEndFrame[] = { +const uint8 KyraEngine_v1::_magicMouseItemEndFrame[] = { 0xB1, 0xB9, 0xC2, 0x00 }; -const uint8 KyraEngine::_magicMouseItemStartFrame2[] = { +const uint8 KyraEngine_v1::_magicMouseItemStartFrame2[] = { 0xB2, 0xBA, 0xC3, 0x00 }; -const uint8 KyraEngine::_magicMouseItemEndFrame2[] = { +const uint8 KyraEngine_v1::_magicMouseItemEndFrame2[] = { 0xB6, 0xBD, 0xC8, 0x00 }; -const uint16 KyraEngine::_amuletX[] = { 231, 275, 253, 253 }; -const uint16 KyraEngine::_amuletY[] = { 170, 170, 159, 181 }; +const uint16 KyraEngine_v1::_amuletX[] = { 231, 275, 253, 253 }; +const uint16 KyraEngine_v1::_amuletY[] = { 170, 170, 159, 181 }; -const uint16 KyraEngine::_amuletX2[] = { 0x000, 0x0FD, 0x0E7, 0x0FD, 0x113, 0x000 }; -const uint16 KyraEngine::_amuletY2[] = { 0x000, 0x09F, 0x0AA, 0x0B5, 0x0AA, 0x000 }; +const uint16 KyraEngine_v1::_amuletX2[] = { 0x000, 0x0FD, 0x0E7, 0x0FD, 0x113, 0x000 }; +const uint16 KyraEngine_v1::_amuletY2[] = { 0x000, 0x09F, 0x0AA, 0x0B5, 0x0AA, 0x000 }; // Kyra 2 and 3 main menu -const char *KyraEngine::_mainMenuStrings[] = { +const char *KyraEngine_v2::_mainMenuStrings[] = { "Start a new game", "Introduction", "Load a game", diff --git a/engines/kyra/text.cpp b/engines/kyra/text.cpp index 58ce3c9d1e..e62410ca19 100644 --- a/engines/kyra/text.cpp +++ b/engines/kyra/text.cpp @@ -28,8 +28,6 @@ #include "kyra/kyra.h" #include "kyra/screen.h" #include "kyra/text.h" -#include "kyra/animator.h" -#include "kyra/sprites.h" #include "common/events.h" #include "common/system.h" @@ -37,369 +35,6 @@ namespace Kyra { -void KyraEngine::waitForChatToFinish(int vocFile, int16 chatDuration, const char *chatStr, uint8 charNum) { - debugC(9, kDebugLevelMain, "KyraEngine::waitForChatToFinish(%i, %s, %i)", chatDuration, chatStr, charNum); - bool hasUpdatedNPCs = false; - bool runLoop = true; - bool drawText = textEnabled(); - uint8 currPage; - Common::Event event; - - //while (towns_isEscKeyPressed() ) - //towns_getKey(); - - uint32 timeToEnd = strlen(chatStr) * 8 * _tickLength + _system->getMillis(); - - if (_configVoice == 0 && chatDuration != -1) { - switch (_configTextspeed) { - case 0: - chatDuration *= 2; - break; - case 2: - chatDuration /= 4; - break; - case 3: - chatDuration = -1; - break; - } - } - - if (chatDuration != -1) - chatDuration *= _tickLength; - - if (vocFile != -1) { - snd_voiceWaitForFinish(); - snd_playVoiceFile(vocFile); - } - - disableTimer(14); - disableTimer(18); - disableTimer(19); - - uint32 timeAtStart = _system->getMillis(); - uint32 loopStart; - while (runLoop) { - loopStart = _system->getMillis(); - if (_currentCharacter->sceneId == 210) - if (seq_playEnd()) - break; - - if (_system->getMillis() > timeToEnd && !hasUpdatedNPCs) { - hasUpdatedNPCs = true; - disableTimer(15); - _currHeadShape = 4; - _animator->animRefreshNPC(0); - _animator->animRefreshNPC(_talkingCharNum); - - if (_charSayUnk2 != -1) { - _animator->sprites()[_charSayUnk2].active = 0; - _sprites->_anims[_charSayUnk2].play = false; - _charSayUnk2 = -1; - } - } - - updateGameTimers(); - _sprites->updateSceneAnims(); - _animator->restoreAllObjectBackgrounds(); - _animator->preserveAnyChangedBackgrounds(); - _animator->prepDrawAllObjects(); - - if (drawText) { - currPage = _screen->_curPage; - _screen->_curPage = 2; - _text->printCharacterText(chatStr, charNum, _characterList[charNum].x1); - _animator->_updateScreen = true; - _screen->_curPage = currPage; - } - - _animator->copyChangedObjectsForward(0); - updateTextFade(); - - if ((chatDuration < (int16)(_system->getMillis() - timeAtStart)) && chatDuration != -1 && (!drawText || !snd_voiceIsPlaying())) - break; - - uint32 nextTime = loopStart + _tickLength; - - while (_system->getMillis() < nextTime) { - while (_eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_KEYDOWN: - if (event.kbd.keycode == '.') - _skipFlag = true; - break; - case Common::EVENT_QUIT: - quitGame(); - runLoop = false; - break; - case Common::EVENT_LBUTTONDOWN: - runLoop = false; - break; - default: - break; - } - } - - if (nextTime - _system->getMillis() >= 10) { - _system->delayMillis(10); - _system->updateScreen(); - } - } - - if (_skipFlag) - runLoop = false; - } - - snd_voiceWaitForFinish(); - snd_stopVoice(); - - enableTimer(14); - enableTimer(15); - enableTimer(18); - enableTimer(19); - //clearKyrandiaButtonIO(); -} - -void KyraEngine::endCharacterChat(int8 charNum, int16 convoInitialized) { - _charSayUnk3 = -1; - - if (charNum > 4 && charNum < 11) { - //TODO: weird _game_inventory stuff here - warning("STUB: endCharacterChat() for high charnums"); - } - - if (convoInitialized != 0) { - _talkingCharNum = -1; - if (_currentCharacter->currentAnimFrame != 88) - _currentCharacter->currentAnimFrame = 7; - _animator->animRefreshNPC(0); - _animator->updateAllObjectShapes(); - } -} - -void KyraEngine::restoreChatPartnerAnimFrame(int8 charNum) { - _talkingCharNum = -1; - - if (charNum > 0 && charNum < 5) { - _characterList[charNum].currentAnimFrame = _currentChatPartnerBackupFrame; - _animator->animRefreshNPC(charNum); - } - - if (_currentCharacter->currentAnimFrame != 88) - _currentCharacter->currentAnimFrame = 7; - - _animator->animRefreshNPC(0); - _animator->updateAllObjectShapes(); -} - -void KyraEngine::backupChatPartnerAnimFrame(int8 charNum) { - _talkingCharNum = 0; - - if (charNum < 5 && charNum > 0) - _currentChatPartnerBackupFrame = _characterList[charNum].currentAnimFrame; - - if (_currentCharacter->currentAnimFrame != 88) { - _currentCharacter->currentAnimFrame = 16; - if (_scaleMode != 0) - _currentCharacter->currentAnimFrame = 7; - } - - _animator->animRefreshNPC(0); - _animator->updateAllObjectShapes(); -} - -int8 KyraEngine::getChatPartnerNum() { - uint8 sceneTable[] = {0x2, 0x5, 0x2D, 0x7, 0x1B, 0x8, 0x22, 0x9, 0x30, 0x0A}; - int pos = 0; - int partner = -1; - - for (int i = 1; i < 6; i++) { - if (_currentCharacter->sceneId == sceneTable[pos]) { - partner = sceneTable[pos+1]; - break; - } - pos += 2; - } - - for (int i = 1; i < 5; i++) { - if (_characterList[i].sceneId == _currentCharacter->sceneId) { - partner = i; - break; - } - } - return partner; -} - -int KyraEngine::initCharacterChat(int8 charNum) { - int returnValue = 0; - - if (_talkingCharNum == -1) { - returnValue = 1; - _talkingCharNum = 0; - - if (_currentCharacter->currentAnimFrame != 88) { - _currentCharacter->currentAnimFrame = 16; - if (_scaleMode != 0) - _currentCharacter->currentAnimFrame = 7; - } - - _animator->animRefreshNPC(0); - _animator->updateAllObjectShapes(); - } - - _charSayUnk2 = -1; - _animator->flagAllObjectsForBkgdChange(); - _animator->restoreAllObjectBackgrounds(); - - if (charNum > 4 && charNum < 11) { - // TODO: Fill in weird _game_inventory stuff here - warning("STUB: initCharacterChat() for high charnums"); - } - - _animator->flagAllObjectsForRefresh(); - _animator->flagAllObjectsForBkgdChange(); - _animator->preserveAnyChangedBackgrounds(); - _charSayUnk3 = charNum; - - return returnValue; -} - -void KyraEngine::characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration) { - debugC(9, kDebugLevelMain, "KyraEngine::characterSays('%s', %i, %d)", chatStr, charNum, chatDuration); - uint8 startAnimFrames[] = { 0x10, 0x32, 0x56, 0x0, 0x0, 0x0 }; - - uint16 chatTicks; - int16 convoInitialized; - int8 chatPartnerNum; - - if (_currentCharacter->sceneId == 210) - return; - - convoInitialized = initCharacterChat(charNum); - chatPartnerNum = getChatPartnerNum(); - - if (chatPartnerNum >= 0 && chatPartnerNum < 5) - backupChatPartnerAnimFrame(chatPartnerNum); - - if (charNum < 5) { - _characterList[charNum].currentAnimFrame = startAnimFrames[charNum]; - _charSayUnk3 = charNum; - _talkingCharNum = charNum; - _animator->animRefreshNPC(charNum); - } - - char *processedString = _text->preprocessString(chatStr); - int lineNum = _text->buildMessageSubstrings(processedString); - - int16 yPos = _characterList[charNum].y1; - yPos -= ((_scaleTable[yPos] * _characterList[charNum].height) >> 8); - yPos -= 8; - yPos -= lineNum * 10; - - if (yPos < 11) - yPos = 11; - - if (yPos > 100) - yPos = 100; - - _text->_talkMessageY = yPos; - _text->_talkMessageH = lineNum * 10; - - if (textEnabled()) { - _animator->restoreAllObjectBackgrounds(); - - _screen->copyRegion(12, _text->_talkMessageY, 12, 136, 308, _text->_talkMessageH, 2, 2); - _screen->hideMouse(); - - _text->printCharacterText(processedString, charNum, _characterList[charNum].x1); - _screen->showMouse(); - } - - if (chatDuration == -2) - chatTicks = strlen(processedString) * 9; - else - chatTicks = chatDuration; - - if (!speechEnabled()) - vocFile = -1; - waitForChatToFinish(vocFile, chatTicks, chatStr, charNum); - - if (textEnabled()) { - _animator->restoreAllObjectBackgrounds(); - - _screen->copyRegion(12, 136, 12, _text->_talkMessageY, 308, _text->_talkMessageH, 2, 2); - _animator->preserveAllBackgrounds(); - _animator->prepDrawAllObjects(); - _screen->hideMouse(); - - _screen->copyRegion(12, _text->_talkMessageY, 12, _text->_talkMessageY, 308, _text->_talkMessageH, 2, 0); - _screen->showMouse(); - _animator->flagAllObjectsForRefresh(); - _animator->copyChangedObjectsForward(0); - } - - if (chatPartnerNum != -1 && chatPartnerNum < 5) - restoreChatPartnerAnimFrame(chatPartnerNum); - - endCharacterChat(charNum, convoInitialized); -} - -void KyraEngine::drawSentenceCommand(const char *sentence, int color) { - debugC(9, kDebugLevelMain, "KyraEngine::drawSentenceCommand('%s', %i)", sentence, color); - _screen->hideMouse(); - _screen->fillRect(8, 143, 311, 152, 12); - - if (_startSentencePalIndex != color || _fadeText != false) { - _currSentenceColor[0] = _screen->_currentPalette[765] = _screen->_currentPalette[color*3]; - _currSentenceColor[1] = _screen->_currentPalette[766] = _screen->_currentPalette[color*3+1]; - _currSentenceColor[2] = _screen->_currentPalette[767] = _screen->_currentPalette[color*3+2]; - - _screen->setScreenPalette(_screen->_currentPalette); - _startSentencePalIndex = 0; - } - - _text->printText(sentence, 8, 143, 0xFF, 12, 0); - _screen->showMouse(); - setTextFadeTimerCountdown(15); - _fadeText = false; -} - -void KyraEngine::updateSentenceCommand(const char *str1, const char *str2, int color) { - debugC(9, kDebugLevelMain, "KyraEngine::updateSentenceCommand('%s', '%s', %i)", str1, str2, color); - char sentenceCommand[500]; - strncpy(sentenceCommand, str1, 500); - if (str2) - strncat(sentenceCommand, str2, 500 - strlen(sentenceCommand)); - - drawSentenceCommand(sentenceCommand, color); - _screen->updateScreen(); -} - -void KyraEngine::updateTextFade() { - debugC(9, kDebugLevelMain, "KyraEngine::updateTextFade()"); - if (!_fadeText) - return; - - bool finished = false; - for (int i = 0; i < 3; i++) - if (_currSentenceColor[i] > 4) - _currSentenceColor[i] -= 4; - else - if (_currSentenceColor[i]) { - _currSentenceColor[i] = 0; - finished = true; - } - - _screen->_currentPalette[765] = _currSentenceColor[0]; - _screen->_currentPalette[766] = _currSentenceColor[1]; - _screen->_currentPalette[767] = _currSentenceColor[2]; - _screen->setScreenPalette(_screen->_currentPalette); - - if (finished) { - _fadeText = false; - _startSentencePalIndex = -1; - } -} - TextDisplayer::TextDisplayer(KyraEngine *vm, Screen *screen) { _screen = screen; _vm = vm; diff --git a/engines/kyra/text_v1.cpp b/engines/kyra/text_v1.cpp new file mode 100644 index 0000000000..3ca986adf8 --- /dev/null +++ b/engines/kyra/text_v1.cpp @@ -0,0 +1,397 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "kyra/kyra_v1.h" +#include "kyra/screen_v1.h" +#include "kyra/text.h" +#include "kyra/animator_v1.h" +#include "kyra/sprites.h" + +namespace Kyra { + +void KyraEngine_v1::waitForChatToFinish(int vocFile, int16 chatDuration, const char *chatStr, uint8 charNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::waitForChatToFinish(%i, %s, %i)", chatDuration, chatStr, charNum); + bool hasUpdatedNPCs = false; + bool runLoop = true; + bool drawText = textEnabled(); + uint8 currPage; + Common::Event event; + + //while (towns_isEscKeyPressed() ) + //towns_getKey(); + + uint32 timeToEnd = strlen(chatStr) * 8 * _tickLength + _system->getMillis(); + + if (_configVoice == 0 && chatDuration != -1) { + switch (_configTextspeed) { + case 0: + chatDuration *= 2; + break; + case 2: + chatDuration /= 4; + break; + case 3: + chatDuration = -1; + break; + } + } + + if (chatDuration != -1) + chatDuration *= _tickLength; + + if (vocFile != -1) { + snd_voiceWaitForFinish(); + snd_playVoiceFile(vocFile); + } + + disableTimer(14); + disableTimer(18); + disableTimer(19); + + uint32 timeAtStart = _system->getMillis(); + uint32 loopStart; + while (runLoop) { + loopStart = _system->getMillis(); + if (_currentCharacter->sceneId == 210) + if (seq_playEnd()) + break; + + if (_system->getMillis() > timeToEnd && !hasUpdatedNPCs) { + hasUpdatedNPCs = true; + disableTimer(15); + _currHeadShape = 4; + _animator->animRefreshNPC(0); + _animator->animRefreshNPC(_talkingCharNum); + + if (_charSayUnk2 != -1) { + _animator->sprites()[_charSayUnk2].active = 0; + _sprites->_anims[_charSayUnk2].play = false; + _charSayUnk2 = -1; + } + } + + updateGameTimers(); + _sprites->updateSceneAnims(); + _animator->restoreAllObjectBackgrounds(); + _animator->preserveAnyChangedBackgrounds(); + _animator->prepDrawAllObjects(); + + if (drawText) { + currPage = _screen->_curPage; + _screen->_curPage = 2; + _text->printCharacterText(chatStr, charNum, _characterList[charNum].x1); + _animator->_updateScreen = true; + _screen->_curPage = currPage; + } + + _animator->copyChangedObjectsForward(0); + updateTextFade(); + + if ((chatDuration < (int16)(_system->getMillis() - timeAtStart)) && chatDuration != -1 && (!drawText || !snd_voiceIsPlaying())) + break; + + uint32 nextTime = loopStart + _tickLength; + + while (_system->getMillis() < nextTime) { + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + if (event.kbd.keycode == '.') + _skipFlag = true; + break; + case Common::EVENT_QUIT: + quitGame(); + runLoop = false; + break; + case Common::EVENT_LBUTTONDOWN: + runLoop = false; + break; + default: + break; + } + } + + if (nextTime - _system->getMillis() >= 10) { + _system->delayMillis(10); + _system->updateScreen(); + } + } + + if (_skipFlag) + runLoop = false; + } + + snd_voiceWaitForFinish(); + snd_stopVoice(); + + enableTimer(14); + enableTimer(15); + enableTimer(18); + enableTimer(19); + //clearKyrandiaButtonIO(); +} + +void KyraEngine_v1::endCharacterChat(int8 charNum, int16 convoInitialized) { + _charSayUnk3 = -1; + + if (charNum > 4 && charNum < 11) { + //TODO: weird _game_inventory stuff here + warning("STUB: endCharacterChat() for high charnums"); + } + + if (convoInitialized != 0) { + _talkingCharNum = -1; + if (_currentCharacter->currentAnimFrame != 88) + _currentCharacter->currentAnimFrame = 7; + _animator->animRefreshNPC(0); + _animator->updateAllObjectShapes(); + } +} + +void KyraEngine_v1::restoreChatPartnerAnimFrame(int8 charNum) { + _talkingCharNum = -1; + + if (charNum > 0 && charNum < 5) { + _characterList[charNum].currentAnimFrame = _currentChatPartnerBackupFrame; + _animator->animRefreshNPC(charNum); + } + + if (_currentCharacter->currentAnimFrame != 88) + _currentCharacter->currentAnimFrame = 7; + + _animator->animRefreshNPC(0); + _animator->updateAllObjectShapes(); +} + +void KyraEngine_v1::backupChatPartnerAnimFrame(int8 charNum) { + _talkingCharNum = 0; + + if (charNum < 5 && charNum > 0) + _currentChatPartnerBackupFrame = _characterList[charNum].currentAnimFrame; + + if (_currentCharacter->currentAnimFrame != 88) { + _currentCharacter->currentAnimFrame = 16; + if (_scaleMode != 0) + _currentCharacter->currentAnimFrame = 7; + } + + _animator->animRefreshNPC(0); + _animator->updateAllObjectShapes(); +} + +int8 KyraEngine_v1::getChatPartnerNum() { + uint8 sceneTable[] = {0x2, 0x5, 0x2D, 0x7, 0x1B, 0x8, 0x22, 0x9, 0x30, 0x0A}; + int pos = 0; + int partner = -1; + + for (int i = 1; i < 6; i++) { + if (_currentCharacter->sceneId == sceneTable[pos]) { + partner = sceneTable[pos+1]; + break; + } + pos += 2; + } + + for (int i = 1; i < 5; i++) { + if (_characterList[i].sceneId == _currentCharacter->sceneId) { + partner = i; + break; + } + } + return partner; +} + +int KyraEngine_v1::initCharacterChat(int8 charNum) { + int returnValue = 0; + + if (_talkingCharNum == -1) { + returnValue = 1; + _talkingCharNum = 0; + + if (_currentCharacter->currentAnimFrame != 88) { + _currentCharacter->currentAnimFrame = 16; + if (_scaleMode != 0) + _currentCharacter->currentAnimFrame = 7; + } + + _animator->animRefreshNPC(0); + _animator->updateAllObjectShapes(); + } + + _charSayUnk2 = -1; + _animator->flagAllObjectsForBkgdChange(); + _animator->restoreAllObjectBackgrounds(); + + if (charNum > 4 && charNum < 11) { + // TODO: Fill in weird _game_inventory stuff here + warning("STUB: initCharacterChat() for high charnums"); + } + + _animator->flagAllObjectsForRefresh(); + _animator->flagAllObjectsForBkgdChange(); + _animator->preserveAnyChangedBackgrounds(); + _charSayUnk3 = charNum; + + return returnValue; +} + +void KyraEngine_v1::characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::characterSays('%s', %i, %d)", chatStr, charNum, chatDuration); + uint8 startAnimFrames[] = { 0x10, 0x32, 0x56, 0x0, 0x0, 0x0 }; + + uint16 chatTicks; + int16 convoInitialized; + int8 chatPartnerNum; + + if (_currentCharacter->sceneId == 210) + return; + + convoInitialized = initCharacterChat(charNum); + chatPartnerNum = getChatPartnerNum(); + + if (chatPartnerNum >= 0 && chatPartnerNum < 5) + backupChatPartnerAnimFrame(chatPartnerNum); + + if (charNum < 5) { + _characterList[charNum].currentAnimFrame = startAnimFrames[charNum]; + _charSayUnk3 = charNum; + _talkingCharNum = charNum; + _animator->animRefreshNPC(charNum); + } + + char *processedString = _text->preprocessString(chatStr); + int lineNum = _text->buildMessageSubstrings(processedString); + + int16 yPos = _characterList[charNum].y1; + yPos -= ((_scaleTable[yPos] * _characterList[charNum].height) >> 8); + yPos -= 8; + yPos -= lineNum * 10; + + if (yPos < 11) + yPos = 11; + + if (yPos > 100) + yPos = 100; + + _text->_talkMessageY = yPos; + _text->_talkMessageH = lineNum * 10; + + if (textEnabled()) { + _animator->restoreAllObjectBackgrounds(); + + _screen->copyRegion(12, _text->_talkMessageY, 12, 136, 308, _text->_talkMessageH, 2, 2); + _screen->hideMouse(); + + _text->printCharacterText(processedString, charNum, _characterList[charNum].x1); + _screen->showMouse(); + } + + if (chatDuration == -2) + chatTicks = strlen(processedString) * 9; + else + chatTicks = chatDuration; + + if (!speechEnabled()) + vocFile = -1; + waitForChatToFinish(vocFile, chatTicks, chatStr, charNum); + + if (textEnabled()) { + _animator->restoreAllObjectBackgrounds(); + + _screen->copyRegion(12, 136, 12, _text->_talkMessageY, 308, _text->_talkMessageH, 2, 2); + _animator->preserveAllBackgrounds(); + _animator->prepDrawAllObjects(); + _screen->hideMouse(); + + _screen->copyRegion(12, _text->_talkMessageY, 12, _text->_talkMessageY, 308, _text->_talkMessageH, 2, 0); + _screen->showMouse(); + _animator->flagAllObjectsForRefresh(); + _animator->copyChangedObjectsForward(0); + } + + if (chatPartnerNum != -1 && chatPartnerNum < 5) + restoreChatPartnerAnimFrame(chatPartnerNum); + + endCharacterChat(charNum, convoInitialized); +} + +void KyraEngine_v1::drawSentenceCommand(const char *sentence, int color) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::drawSentenceCommand('%s', %i)", sentence, color); + _screen->hideMouse(); + _screen->fillRect(8, 143, 311, 152, 12); + + if (_startSentencePalIndex != color || _fadeText != false) { + _currSentenceColor[0] = _screen->_currentPalette[765] = _screen->_currentPalette[color*3]; + _currSentenceColor[1] = _screen->_currentPalette[766] = _screen->_currentPalette[color*3+1]; + _currSentenceColor[2] = _screen->_currentPalette[767] = _screen->_currentPalette[color*3+2]; + + _screen->setScreenPalette(_screen->_currentPalette); + _startSentencePalIndex = 0; + } + + _text->printText(sentence, 8, 143, 0xFF, 12, 0); + _screen->showMouse(); + setTextFadeTimerCountdown(15); + _fadeText = false; +} + +void KyraEngine_v1::updateSentenceCommand(const char *str1, const char *str2, int color) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updateSentenceCommand('%s', '%s', %i)", str1, str2, color); + char sentenceCommand[500]; + strncpy(sentenceCommand, str1, 500); + if (str2) + strncat(sentenceCommand, str2, 500 - strlen(sentenceCommand)); + + drawSentenceCommand(sentenceCommand, color); + _screen->updateScreen(); +} + +void KyraEngine_v1::updateTextFade() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updateTextFade()"); + if (!_fadeText) + return; + + bool finished = false; + for (int i = 0; i < 3; i++) + if (_currSentenceColor[i] > 4) + _currSentenceColor[i] -= 4; + else + if (_currSentenceColor[i]) { + _currSentenceColor[i] = 0; + finished = true; + } + + _screen->_currentPalette[765] = _currSentenceColor[0]; + _screen->_currentPalette[766] = _currSentenceColor[1]; + _screen->_currentPalette[767] = _currSentenceColor[2]; + _screen->setScreenPalette(_screen->_currentPalette); + + if (finished) { + _fadeText = false; + _startSentencePalIndex = -1; + } +} + +} // end of namespace Kyra diff --git a/engines/kyra/timer_v1.cpp b/engines/kyra/timer_v1.cpp index a35b701697..0b5184fe5a 100644 --- a/engines/kyra/timer_v1.cpp +++ b/engines/kyra/timer_v1.cpp @@ -23,15 +23,15 @@ * */ -#include "kyra/kyra.h" +#include "kyra/kyra_v1.h" #include "kyra/screen.h" -#include "kyra/animator.h" +#include "kyra/animator_v1.h" #include "common/system.h" namespace Kyra { -void KyraEngine::setupTimers() { - debugC(9, kDebugLevelMain, "KyraEngine::setupTimers()"); +void KyraEngine_v1::setupTimers() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setupTimers()"); memset(_timers, 0, sizeof(_timers)); for (int i = 0; i < 34; i++) @@ -40,12 +40,12 @@ void KyraEngine::setupTimers() { _timers[0].func = _timers[1].func = _timers[2].func = _timers[3].func = _timers[4].func = 0; //Unused. _timers[5].func = _timers[6].func = _timers[7].func = _timers[8].func = _timers[9].func = 0; //_nullsub51; _timers[10].func = _timers[11].func = _timers[12].func = _timers[13].func = 0; //_nullsub50; - _timers[14].func = &KyraEngine::timerCheckAnimFlag2; //_nullsub52; - _timers[15].func = &KyraEngine::timerUpdateHeadAnims; //_nullsub48; - _timers[16].func = &KyraEngine::timerSetFlags1; //_nullsub47; + _timers[14].func = &KyraEngine_v1::timerCheckAnimFlag2; //_nullsub52; + _timers[15].func = &KyraEngine_v1::timerUpdateHeadAnims; //_nullsub48; + _timers[16].func = &KyraEngine_v1::timerSetFlags1; //_nullsub47; _timers[17].func = 0; //sub_15120; - _timers[18].func = &KyraEngine::timerCheckAnimFlag1; //_nullsub53; - _timers[19].func = &KyraEngine::timerRedrawAmulet; //_nullsub54; + _timers[18].func = &KyraEngine_v1::timerCheckAnimFlag1; //_nullsub53; + _timers[19].func = &KyraEngine_v1::timerRedrawAmulet; //_nullsub54; _timers[20].func = 0; //offset _timerDummy1 _timers[21].func = 0; //sub_1517C; _timers[22].func = 0; //offset _timerDummy2 @@ -57,9 +57,9 @@ void KyraEngine::setupTimers() { _timers[28].func = 0; //offset _timerDummy6 _timers[29].func = 0; //offset _timerDummy7, _timers[30].func = 0; //offset _timerDummy8, - _timers[31].func = &KyraEngine::timerFadeText; //sub_151F8; - _timers[32].func = &KyraEngine::updateAnimFlag1; //_nullsub61; - _timers[33].func = &KyraEngine::updateAnimFlag2; //_nullsub62; + _timers[31].func = &KyraEngine_v1::timerFadeText; //sub_151F8; + _timers[32].func = &KyraEngine_v1::updateAnimFlag1; //_nullsub61; + _timers[33].func = &KyraEngine_v1::updateAnimFlag2; //_nullsub62; _timers[0].countdown = _timers[1].countdown = _timers[2].countdown = _timers[3].countdown = _timers[4].countdown = -1; _timers[5].countdown = 5; @@ -84,8 +84,8 @@ void KyraEngine::setupTimers() { _timers[33].countdown = 3; } -void KyraEngine::updateGameTimers() { - debugC(9, kDebugLevelMain, "KyraEngine::updateGameTimers()"); +void KyraEngine_v1::updateGameTimers() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updateGameTimers()"); if (_system->getMillis() < _timerNextRun) return; @@ -106,23 +106,23 @@ void KyraEngine::updateGameTimers() { } } -void KyraEngine::clearNextEventTickCount() { - debugC(9, kDebugLevelMain, "KyraEngine::clearNextEventTickCount()"); +void KyraEngine_v1::clearNextEventTickCount() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::clearNextEventTickCount()"); _timerNextRun = 0; } -void KyraEngine::setTimerDelay(uint8 timer, int32 countdown) { - debugC(9, kDebugLevelMain, "KyraEngine::setTimerDelay(%i, %d)", timer, countdown); +void KyraEngine_v1::setTimerDelay(uint8 timer, int32 countdown) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setTimerDelay(%i, %d)", timer, countdown); _timers[timer].countdown = countdown; } -int16 KyraEngine::getTimerDelay(uint8 timer) { - debugC(9, kDebugLevelMain, "KyraEngine::getTimerDelay(%i)", timer); +int16 KyraEngine_v1::getTimerDelay(uint8 timer) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::getTimerDelay(%i)", timer); return _timers[timer].countdown; } -void KyraEngine::setTimerCountdown(uint8 timer, int32 countdown) { - debugC(9, kDebugLevelMain, "KyraEngine::setTimerCountdown(%i, %i)", timer, countdown); +void KyraEngine_v1::setTimerCountdown(uint8 timer, int32 countdown) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setTimerCountdown(%i, %i)", timer, countdown); _timers[timer].countdown = countdown; _timers[timer].nextRun = _system->getMillis() + countdown * _tickLength; @@ -131,18 +131,18 @@ void KyraEngine::setTimerCountdown(uint8 timer, int32 countdown) { _timerNextRun = nextRun; } -void KyraEngine::enableTimer(uint8 timer) { - debugC(9, kDebugLevelMain, "KyraEngine::enableTimer(%i)", timer); +void KyraEngine_v1::enableTimer(uint8 timer) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::enableTimer(%i)", timer); _timers[timer].active = 1; } -void KyraEngine::disableTimer(uint8 timer) { - debugC(9, kDebugLevelMain, "KyraEngine::disableTimer(%i)", timer); +void KyraEngine_v1::disableTimer(uint8 timer) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::disableTimer(%i)", timer); _timers[timer].active = 0; } -void KyraEngine::timerUpdateHeadAnims(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerUpdateHeadAnims(%i)", timerNum); +void KyraEngine_v1::timerUpdateHeadAnims(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerUpdateHeadAnims(%i)", timerNum); static int8 currentFrame = 0; static const int8 frameTable[] = {4, 5, 4, 5, 4, 5, 0, 1, 4, 5, 4, 4, 6, 4, 8, 1, 9, 4, -1}; @@ -160,8 +160,8 @@ void KyraEngine::timerUpdateHeadAnims(int timerNum) { _animator->animRefreshNPC(_talkingCharNum); } -void KyraEngine::timerSetFlags1(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerSetFlags(%i)", timerNum); +void KyraEngine_v1::timerSetFlags1(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerSetFlags(%i)", timerNum); if (_currentCharacter->sceneId == 0x1C) return; @@ -179,57 +179,57 @@ void KyraEngine::timerSetFlags1(int timerNum) { } } -void KyraEngine::timerFadeText(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerFadeText(%i)", timerNum); +void KyraEngine_v1::timerFadeText(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerFadeText(%i)", timerNum); _fadeText = true; } -void KyraEngine::updateAnimFlag1(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::updateAnimFlag1(%d)", timerNum); +void KyraEngine_v1::updateAnimFlag1(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updateAnimFlag1(%d)", timerNum); if (_brandonStatusBit & 2) { _brandonStatusBit0x02Flag = 1; } } -void KyraEngine::updateAnimFlag2(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::updateAnimFlag2(%d)", timerNum); +void KyraEngine_v1::updateAnimFlag2(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::updateAnimFlag2(%d)", timerNum); if (_brandonStatusBit & 0x20) { _brandonStatusBit0x20Flag = 1; } } -void KyraEngine::setTextFadeTimerCountdown(int16 countdown) { - debugC(9, kDebugLevelMain, "KyraEngine::setTextFadeTimerCountdown(%i)", countdown); +void KyraEngine_v1::setTextFadeTimerCountdown(int16 countdown) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setTextFadeTimerCountdown(%i)", countdown); //if (countdown == -1) //countdown = 32000; setTimerCountdown(31, countdown*60); } -void KyraEngine::timerSetFlags2(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerSetFlags2(%i)", timerNum); +void KyraEngine_v1::timerSetFlags2(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerSetFlags2(%i)", timerNum); if (!((uint32*)(_flagsTable+0x2D))[timerNum]) ((uint32*)(_flagsTable+0x2D))[timerNum] = 1; } -void KyraEngine::timerCheckAnimFlag1(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerCheckAnimFlag1(%i)", timerNum); +void KyraEngine_v1::timerCheckAnimFlag1(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerCheckAnimFlag1(%i)", timerNum); if (_brandonStatusBit & 0x20) { checkAmuletAnimFlags(); setTimerCountdown(18, -1); } } -void KyraEngine::timerCheckAnimFlag2(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerCheckAnimFlag1(%i)", timerNum); +void KyraEngine_v1::timerCheckAnimFlag2(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerCheckAnimFlag1(%i)", timerNum); if (_brandonStatusBit & 0x2) { checkAmuletAnimFlags(); setTimerCountdown(14, -1); } } -void KyraEngine::checkAmuletAnimFlags() { - debugC(9, kDebugLevelMain, "KyraEngine::checkSpecialAnimFlags()"); +void KyraEngine_v1::checkAmuletAnimFlags() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::checkSpecialAnimFlags()"); if (_brandonStatusBit & 2) { seq_makeBrandonNormal2(); setTimerCountdown(19, 300); @@ -241,16 +241,16 @@ void KyraEngine::checkAmuletAnimFlags() { } } -void KyraEngine::timerRedrawAmulet(int timerNum) { - debugC(9, kDebugLevelMain, "KyraEngine::timerRedrawAmulet(%i)", timerNum); +void KyraEngine_v1::timerRedrawAmulet(int timerNum) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::timerRedrawAmulet(%i)", timerNum); if (queryGameFlag(0xF1)) { drawAmulet(); setTimerCountdown(19, -1); } } -void KyraEngine::drawAmulet() { - debugC(9, kDebugLevelMain, "KyraEngine::drawAmulet()"); +void KyraEngine_v1::drawAmulet() { + debugC(9, kDebugLevelMain, "KyraEngine_v1::drawAmulet()"); static const int16 amuletTable1[] = {0x167, 0x162, 0x15D, 0x158, 0x153, 0x150, 0x155, 0x15A, 0x15F, 0x164, 0x145, -1}; static const int16 amuletTable3[] = {0x167, 0x162, 0x15D, 0x158, 0x153, 0x14F, 0x154, 0x159, 0x15E, 0x163, 0x144, -1}; static const int16 amuletTable2[] = {0x167, 0x162, 0x15D, 0x158, 0x153, 0x152, 0x157, 0x15C, 0x161, 0x166, 0x147, -1}; @@ -280,8 +280,8 @@ void KyraEngine::drawAmulet() { _screen->showMouse(); } -void KyraEngine::setWalkspeed(uint8 newSpeed) { - debugC(9, kDebugLevelMain, "KyraEngine::setWalkspeed(%i)", newSpeed); +void KyraEngine_v1::setWalkspeed(uint8 newSpeed) { + debugC(9, kDebugLevelMain, "KyraEngine_v1::setWalkspeed(%i)", newSpeed); static const uint8 speeds[] = {11, 9, 6, 5, 3}; assert(newSpeed < ARRAYSIZE(speeds)); |