diff options
Diffstat (limited to 'engines/toltecs')
-rw-r--r-- | engines/toltecs/console.cpp | 79 | ||||
-rw-r--r-- | engines/toltecs/console.h | 45 | ||||
-rw-r--r-- | engines/toltecs/detection.cpp | 57 | ||||
-rw-r--r-- | engines/toltecs/menu.cpp | 200 | ||||
-rw-r--r-- | engines/toltecs/menu.h | 6 | ||||
-rw-r--r-- | engines/toltecs/microtiles.cpp | 4 | ||||
-rw-r--r-- | engines/toltecs/module.mk | 1 | ||||
-rw-r--r-- | engines/toltecs/movie.cpp | 38 | ||||
-rw-r--r-- | engines/toltecs/movie.h | 4 | ||||
-rw-r--r-- | engines/toltecs/palette.cpp | 68 | ||||
-rw-r--r-- | engines/toltecs/palette.h | 2 | ||||
-rw-r--r-- | engines/toltecs/resource.cpp | 11 | ||||
-rw-r--r-- | engines/toltecs/resource.h | 2 | ||||
-rw-r--r-- | engines/toltecs/screen.cpp | 56 | ||||
-rw-r--r-- | engines/toltecs/screen.h | 4 | ||||
-rw-r--r-- | engines/toltecs/script.cpp | 145 | ||||
-rw-r--r-- | engines/toltecs/script.h | 1 | ||||
-rw-r--r-- | engines/toltecs/sound.cpp | 9 | ||||
-rw-r--r-- | engines/toltecs/toltecs.cpp | 37 | ||||
-rw-r--r-- | engines/toltecs/toltecs.h | 2 |
20 files changed, 463 insertions, 308 deletions
diff --git a/engines/toltecs/console.cpp b/engines/toltecs/console.cpp new file mode 100644 index 0000000000..f3394909ed --- /dev/null +++ b/engines/toltecs/console.cpp @@ -0,0 +1,79 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "gui/debugger.h" + +#include "toltecs/console.h" +//#include "toltecs/palette.h" +#include "toltecs/resource.h" +//#include "toltecs/sound.h" +#include "toltecs/toltecs.h" + +namespace Toltecs { + +Console::Console(ToltecsEngine *vm) : GUI::Debugger(), _vm(vm) { + DCmd_Register("room", WRAP_METHOD(Console, Cmd_Room)); + DCmd_Register("dump", WRAP_METHOD(Console, Cmd_Dump)); +} + +Console::~Console() { +} + +bool Console::Cmd_Room(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Current room number is %d\n", _vm->_sceneResIndex); +#if 0 + DebugPrintf("Calling this command with the room number changes the room\n"); + DebugPrintf("WARNING: It's a bad idea to warp to rooms with this, as the room object scripts are not loaded\n"); +#endif + return true; +#if 0 + } else { + int roomNum = atoi(argv[1]); + + // sfClearPaletteFragments + _vm->_palette->clearFragments(); + + // sfLoadScene + _vm->_sound->stopAll(); + _vm->_res->purgeCache(); + _vm->loadScene(roomNum); +#endif + } + + return false; +} + +bool Console::Cmd_Dump(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Usage: dump <resource number>\n"); + return true; + } + + int resNum = atoi(argv[1]); + _vm->_arc->dump(resNum); + DebugPrintf("Resource %d has been dumped to disk\n", resNum); + + return true; +} + +} // End of namespace Toltecs diff --git a/engines/toltecs/console.h b/engines/toltecs/console.h new file mode 100644 index 0000000000..bcdfd0cf04 --- /dev/null +++ b/engines/toltecs/console.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. + * + */ + +#ifndef TOLTECS_CONSOLE_H +#define TOLTECS_CONSOLE_H + +#include "gui/debugger.h" + +namespace Toltecs { + +class ToltecsEngine; + +class Console : public GUI::Debugger { +public: + Console(ToltecsEngine *vm); + virtual ~Console(void); + +private: + ToltecsEngine *_vm; + + bool Cmd_Dump(int argc, const char **argv); + bool Cmd_Room(int argc, const char **argv); +}; + +} // End of namespace Toltecs +#endif diff --git a/engines/toltecs/detection.cpp b/engines/toltecs/detection.cpp index c1a57638c2..788f813762 100644 --- a/engines/toltecs/detection.cpp +++ b/engines/toltecs/detection.cpp @@ -24,6 +24,8 @@ #include "base/plugins.h" #include "engines/advancedDetector.h" + +#include "common/translation.h" #include "common/savefile.h" #include "common/str-array.h" #include "common/system.h" @@ -97,19 +99,6 @@ static const ToltecsGameDescription gameDescriptions[] = { }, { - // 3 Skulls of the Toltecs German Demo version - { - "toltecs", - 0, - AD_ENTRY1s("WESTERN", "1c85e82712d24f1d5c1ea2a66ddd75c2", 47730038), - Common::DE_DEU, - Common::kPlatformPC, - ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) - }, - }, - - { // 3 Skulls of the Toltecs French version { "toltecs", @@ -149,11 +138,44 @@ static const ToltecsGameDescription gameDescriptions[] = { }, }, + { + // 3 Skulls of the Toltecs English Demo version + { + "toltecs", + 0, + AD_ENTRY1s("WESTERN", "53a0abd1c0bc5cad8ba18f0e56877705", 46241833), + Common::EN_ANY, + Common::kPlatformPC, + ADGF_DEMO, + GUIO1(GUIO_NONE) + }, + }, + + { + // 3 Skulls of the Toltecs German Demo version + { + "toltecs", + 0, + AD_ENTRY1s("WESTERN", "1c85e82712d24f1d5c1ea2a66ddd75c2", 47730038), + Common::DE_DEU, + Common::kPlatformPC, + ADGF_DEMO, + GUIO1(GUIO_NONE) + }, + }, + { AD_TABLE_END_MARKER } }; } // End of namespace Toltecs +static const ExtraGuiOption toltecsExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + class ToltecsMetaEngine : public AdvancedMetaEngine { public: ToltecsMetaEngine() : AdvancedMetaEngine(Toltecs::gameDescriptions, sizeof(Toltecs::ToltecsGameDescription), toltecsGames) { @@ -170,6 +192,7 @@ public: virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; void removeSaveState(const char *target, int slot) const; @@ -202,6 +225,12 @@ bool ToltecsMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG return gd != 0; } +const ExtraGuiOptions ToltecsMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(toltecsExtraGuiOption); + return options; +} + SaveStateList ToltecsMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Toltecs::ToltecsEngine::SaveHeader header; @@ -295,7 +324,7 @@ SaveStateDescriptor ToltecsMetaEngine::querySaveMetaInfos(const char *target, in } return SaveStateDescriptor(); -} // End of namespace Toltecs +} // End of namespace Toltecs #if PLUGIN_ENABLED_DYNAMIC(TOLTECS) REGISTER_PLUGIN_DYNAMIC(TOLTECS, PLUGIN_TYPE_ENGINE, ToltecsMetaEngine); diff --git a/engines/toltecs/menu.cpp b/engines/toltecs/menu.cpp index 6e23ff988f..b52d7dad82 100644 --- a/engines/toltecs/menu.cpp +++ b/engines/toltecs/menu.cpp @@ -22,9 +22,12 @@ */ #include "audio/mixer.h" -#include "common/savefile.h" +#include "common/savefile.h" #include "common/config-manager.h" +#include "common/translation.h" + +#include "gui/saveload.h" #include "toltecs/toltecs.h" #include "toltecs/menu.h" @@ -41,9 +44,6 @@ MenuSystem::~MenuSystem() { } int MenuSystem::run(MenuID menuId) { - - //debug("MenuSystem::run()"); - _background = new Graphics::Surface(); _background->create(640, 400, Graphics::PixelFormat::createFormatCLUT8()); @@ -62,13 +62,12 @@ int MenuSystem::run(MenuID menuId) { _needRedraw = false; - // TODO: buildColorTransTable2 _vm->_palette->buildColorTransTable(0, 16, 7); _vm->_screen->_renderQueue->clear(); // Draw the menu background and frame _vm->_screen->blastSprite(0x140 + _vm->_cameraX, 0x175 + _vm->_cameraY, 0, 1, 0x4000); - shadeRect(60, 39, 520, 246, 30, 94); + shadeRect(60, 39, 520, 247, 225, 229); memcpy(_background->pixels, _vm->_screen->_frontScreen, 640 * 400); @@ -91,7 +90,6 @@ int MenuSystem::run(MenuID menuId) { } void MenuSystem::update() { - if (_currMenuID != _newMenuID) { _currMenuID = _newMenuID; //debug("_currMenuID = %d", _currMenuID); @@ -103,16 +101,13 @@ void MenuSystem::update() { if (_needRedraw) { //_vm->_system->copyRectToScreen(_vm->_screen->_frontScreen + 39 * 640 + 60, 640, 60, 39, 520, 247); _vm->_system->copyRectToScreen(_vm->_screen->_frontScreen, 640, 0, _top, 640, 400 - _top); - //debug("redraw"); _needRedraw = false; } _vm->_system->delayMillis(5); - } void MenuSystem::handleEvents() { - Common::Event event; Common::EventManager *eventMan = _vm->_system->getEventManager(); while (eventMan->pollEvent(event)) { @@ -126,18 +121,18 @@ void MenuSystem::handleEvents() { case Common::EVENT_MOUSEMOVE: handleMouseMove(event.mouse.x, event.mouse.y); break; - case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_LBUTTONUP: handleMouseClick(event.mouse.x, event.mouse.y); break; default: break; } } - } void MenuSystem::addClickTextItem(ItemID id, int x, int y, int w, uint fontNum, const char *caption, byte defaultColor, byte activeColor) { Item item; + item.enabled = true; item.id = id; item.defaultColor = defaultColor; item.activeColor = activeColor; @@ -202,7 +197,7 @@ void MenuSystem::handleKeyDown(const Common::KeyState& kbd) { ItemID MenuSystem::findItemAt(int x, int y) { for (Common::Array<Item>::iterator iter = _items.begin(); iter != _items.end(); iter++) { - if ((*iter).rect.contains(x, y - _top)) + if ((*iter).enabled && (*iter).rect.contains(x, y - _top)) return (*iter).id; } return kItemIdNone; @@ -220,6 +215,8 @@ void MenuSystem::setItemCaption(Item *item, const char *caption) { Font font(_vm->_res->load(_vm->_screen->getFontResIndex(item->fontNum))->data); int width = font.getTextWidth((const byte*)caption); int height = font.getHeight(); + if (width & 1) + width++; item->rect = Common::Rect(item->x, item->y - height, item->x + width, item->y); if (item->w) { item->rect.translate(item->w - width / 2, 0); @@ -236,59 +233,87 @@ void MenuSystem::initMenu(MenuID menuID) { switch (menuID) { case kMenuIdMain: - drawString(0, 74, 320, 1, 229, _vm->getSysString(kStrWhatCanIDoForYou)); - addClickTextItem(kItemIdLoad, 0, 115, 320, 0, _vm->getSysString(kStrLoad), 229, 255); - addClickTextItem(kItemIdSave, 0, 135, 320, 0, _vm->getSysString(kStrSave), 229, 255); - addClickTextItem(kItemIdToggleText, 0, 165, 320, 0, _vm->getSysString(_vm->_cfgText ? kStrTextOn : kStrTextOff), 229, 255); - addClickTextItem(kItemIdToggleVoices, 0, 185, 320, 0, _vm->getSysString(_vm->_cfgVoices ? kStrVoicesOn : kStrVoicesOff), 229, 255); - addClickTextItem(kItemIdVolumesMenu, 0, 215, 320, 0, _vm->getSysString(kStrVolume), 229, 255); - addClickTextItem(kItemIdPlay, 0, 245, 320, 0, _vm->getSysString(kStrPlay), 229, 255); - addClickTextItem(kItemIdQuit, 0, 275, 320, 0, _vm->getSysString(kStrQuit), 229, 255); + drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrWhatCanIDoForYou)); + addClickTextItem(kItemIdLoad, 0, 116, 320, 0, _vm->getSysString(kStrLoad), 253, 255); + addClickTextItem(kItemIdSave, 0, 136, 320, 0, _vm->getSysString(kStrSave), 253, 255); + addClickTextItem(kItemIdToggleText, 0, 166, 320, 0, _vm->getSysString(_vm->_cfgText ? kStrTextOn : kStrTextOff), 253, 255); + addClickTextItem(kItemIdToggleVoices, 0, 186, 320, 0, _vm->getSysString(_vm->_cfgVoices ? kStrVoicesOn : kStrVoicesOff), 253, 255); + addClickTextItem(kItemIdVolumesMenu, 0, 216, 320, 0, _vm->getSysString(kStrVolume), 253, 255); + addClickTextItem(kItemIdPlay, 0, 246, 320, 0, _vm->getSysString(kStrPlay), 253, 255); + addClickTextItem(kItemIdQuit, 0, 276, 320, 0, _vm->getSysString(kStrQuit), 253, 255); break; case kMenuIdLoad: - drawString(0, 74, 320, 1, 229, _vm->getSysString(kStrLoadGame)); - addClickTextItem(kItemIdSavegameUp, 0, 155, 545, 1, "^", 255, 253); - addClickTextItem(kItemIdSavegameDown, 0, 195, 545, 1, "\\", 255, 253); - addClickTextItem(kItemIdCancel, 0, 275, 320, 0, _vm->getSysString(kStrCancel), 255, 253); - for (int i = 1; i <= 7; i++) { - Common::String saveDesc = Common::String::format("SAVEGAME %d", i); - addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 115 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234); + if (ConfMan.getBool("originalsaveload")) { + shadeRect(80, 92, 440, 141, 226, 225); + drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrLoadGame)); + addClickTextItem(kItemIdSavegameUp, 0, 156, 545, 1, "^", 253, 255); + addClickTextItem(kItemIdSavegameDown, 0, 196, 545, 1, "\\", 253, 255); + addClickTextItem(kItemIdCancel, 0, 276, 320, 0, _vm->getSysString(kStrCancel), 253, 255); + for (int i = 1; i <= 7; i++) { + Common::String saveDesc = Common::String::format("SAVEGAME %d", i); + addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 116 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234); + } + loadSavegamesList(); + setSavegameCaptions(true); + } else { + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); + int slot = dialog->runModalWithCurrentTarget(); + delete dialog; + + if (slot >= 0) + _vm->requestLoadgame(slot); + + _running = false; } - loadSavegamesList(); - setSavegameCaptions(); break; case kMenuIdSave: - drawString(0, 74, 320, 1, 229, _vm->getSysString(kStrSaveGame)); - addClickTextItem(kItemIdSavegameUp, 0, 155, 545, 1, "^", 255, 253); - addClickTextItem(kItemIdSavegameDown, 0, 195, 545, 1, "\\", 255, 253); - addClickTextItem(kItemIdCancel, 0, 275, 320, 0, _vm->getSysString(kStrCancel), 255, 253); - for (int i = 1; i <= 7; i++) { - Common::String saveDesc = Common::String::format("SAVEGAME %d", i); - addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 115 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234); + if (ConfMan.getBool("originalsaveload")) { + shadeRect(80, 92, 440, 141, 226, 225); + drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrSaveGame)); + addClickTextItem(kItemIdSavegameUp, 0, 156, 545, 1, "^", 253, 255); + addClickTextItem(kItemIdSavegameDown, 0, 196, 545, 1, "\\", 253, 255); + addClickTextItem(kItemIdCancel, 0, 276, 320, 0, _vm->getSysString(kStrCancel), 253, 255); + for (int i = 1; i <= 7; i++) { + Common::String saveDesc = Common::String::format("SAVEGAME %d", i); + addClickTextItem((ItemID)(kItemIdSavegame1 + i - 1), 0, 116 + 20 * (i - 1), 300, 0, saveDesc.c_str(), 231, 234); + } + newSlotNum = loadSavegamesList() + 1; + _savegames.push_back(SavegameItem(newSlotNum, Common::String::format("GAME %04d", _savegames.size()))); + setSavegameCaptions(true); + } else { + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); + int slot = dialog->runModalWithCurrentTarget(); + Common::String desc = dialog->getResultString(); + if (desc.empty()) { + // Create our own description for the saved game, the user didn't enter one + desc = dialog->createDefaultSaveDescription(slot); + } + + if (slot >= 0) + _vm->requestSavegame(slot, desc); + + _running = false; } - newSlotNum = loadSavegamesList() + 1; - _savegames.push_back(SavegameItem(newSlotNum, Common::String::format("GAME %03d", _savegames.size() + 1))); - setSavegameCaptions(); break; case kMenuIdVolumes: - drawString(0, 74, 320, 1, 229, _vm->getSysString(kStrAdjustVolume)); - drawString(0, 130, 200, 0, 246, _vm->getSysString(kStrMaster)); - drawString(0, 155, 200, 0, 244, _vm->getSysString(kStrVoices)); - drawString(0, 180, 200, 0, 244, _vm->getSysString(kStrMusic)); - drawString(0, 205, 200, 0, 244, _vm->getSysString(kStrSoundFx)); - drawString(0, 230, 200, 0, 244, _vm->getSysString(kStrBackground)); - addClickTextItem(kItemIdDone, 0, 275, 200, 0, _vm->getSysString(kStrDone), 229, 253); - addClickTextItem(kItemIdCancel, 0, 275, 440, 0, _vm->getSysString(kStrCancel), 229, 253); - addClickTextItem(kItemIdMasterDown, 0, 130 + 25 * 0, 348, 1, "[", 229, 253); - addClickTextItem(kItemIdVoicesDown, 0, 130 + 25 * 1, 348, 1, "[", 229, 253); - addClickTextItem(kItemIdMusicDown, 0, 130 + 25 * 2, 348, 1, "[", 229, 253); - addClickTextItem(kItemIdSoundFXDown, 0, 130 + 25 * 3, 348, 1, "[", 229, 253); - addClickTextItem(kItemIdBackgroundDown, 0, 130 + 25 * 4, 348, 1, "[", 229, 253); - addClickTextItem(kItemIdMasterUp, 0, 130 + 25 * 0, 372, 1, "]", 229, 253); - addClickTextItem(kItemIdVoicesUp, 0, 130 + 25 * 1, 372, 1, "]", 229, 253); - addClickTextItem(kItemIdMusicUp, 0, 130 + 25 * 2, 372, 1, "]", 229, 253); - addClickTextItem(kItemIdSoundFXUp, 0, 130 + 25 * 3, 372, 1, "]", 229, 253); - addClickTextItem(kItemIdBackgroundUp, 0, 130 + 25 * 4, 372, 1, "]", 229, 253); + drawString(0, 75, 320, 1, 229, _vm->getSysString(kStrAdjustVolume)); + drawString(0, 131, 200, 0, 246, _vm->getSysString(kStrMaster)); + drawString(0, 156, 200, 0, 244, _vm->getSysString(kStrVoices)); + drawString(0, 181, 200, 0, 244, _vm->getSysString(kStrMusic)); + drawString(0, 206, 200, 0, 244, _vm->getSysString(kStrSoundFx)); + drawString(0, 231, 200, 0, 244, _vm->getSysString(kStrBackground)); + addClickTextItem(kItemIdDone, 0, 276, 200, 0, _vm->getSysString(kStrDone), 253, 255); + addClickTextItem(kItemIdCancel, 0, 276, 440, 0, _vm->getSysString(kStrCancel), 253, 255); + addClickTextItem(kItemIdMasterDown, 0, 131 + 25 * 0, 348, 1, "[", 243, 246); + addClickTextItem(kItemIdVoicesDown, 0, 131 + 25 * 1, 348, 1, "[", 243, 246); + addClickTextItem(kItemIdMusicDown, 0, 131 + 25 * 2, 348, 1, "[", 243, 246); + addClickTextItem(kItemIdSoundFXDown, 0, 131 + 25 * 3, 348, 1, "[", 243, 246); + addClickTextItem(kItemIdBackgroundDown, 0, 131 + 25 * 4, 348, 1, "[", 243, 246); + addClickTextItem(kItemIdMasterUp, 0, 131 + 25 * 0, 372, 1, "]", 243, 246); + addClickTextItem(kItemIdVoicesUp, 0, 131 + 25 * 1, 372, 1, "]", 243, 246); + addClickTextItem(kItemIdMusicUp, 0, 131 + 25 * 2, 372, 1, "]", 243, 246); + addClickTextItem(kItemIdSoundFXUp, 0, 131 + 25 * 3, 372, 1, "]", 243, 246); + addClickTextItem(kItemIdBackgroundUp, 0, 131 + 25 * 4, 372, 1, "]", 243, 246); drawVolumeBar(kItemIdMaster); drawVolumeBar(kItemIdVoices); drawVolumeBar(kItemIdMusic); @@ -300,9 +325,36 @@ void MenuSystem::initMenu(MenuID menuID) { } for (Common::Array<Item>::iterator iter = _items.begin(); iter != _items.end(); iter++) { - drawItem((*iter).id, false); + if ((*iter).enabled) + drawItem((*iter).id, false); } + // Check if the mouse is already over an item + _currItemID = kItemIdNone; + Common::Point mousePos = _vm->_system->getEventManager()->getMousePos(); + handleMouseMove(mousePos.x, mousePos.y); +} + +void MenuSystem::enableItem(ItemID id) { + Item *item = getItem(id); + if (item) { + item->enabled = true; + drawItem(id, false); + _currItemID = kItemIdNone; + Common::Point mousePos = _vm->_system->getEventManager()->getMousePos(); + handleMouseMove(mousePos.x, mousePos.y); + } +} + +void MenuSystem::disableItem(ItemID id) { + Item *item = getItem(id); + if (item) { + item->enabled = false; + restoreRect(item->rect.left, item->rect.top, item->rect.width(), item->rect.height()); + if (_currItemID == id) { + _currItemID = kItemIdNone; + } + } } void MenuSystem::enterItem(ItemID id) { @@ -433,14 +485,16 @@ void MenuSystem::drawString(int16 x, int16 y, int w, uint fontNum, byte color, c fontNum = _vm->_screen->getFontResIndex(fontNum); Font font(_vm->_res->load(fontNum)->data); if (w) { - x = x + w - font.getTextWidth((const byte*)text) / 2; + int width = font.getTextWidth((const byte*)text); + if (width & 1) + width++; + x = x + w - width / 2; } _vm->_screen->drawString(x, y - font.getHeight(), color, fontNum, (const byte*)text, -1, NULL, true); _needRedraw = true; } int MenuSystem::loadSavegamesList() { - int maxSlotNum = -1; _savegameListTopIndex = 0; @@ -483,17 +537,32 @@ MenuSystem::SavegameItem *MenuSystem::getSavegameItemByID(ItemID id) { return NULL; } -void MenuSystem::setSavegameCaptions() { - uint index = _savegameListTopIndex; +void MenuSystem::setSavegameCaptions(bool scrollToBottom) { + int size = _savegames.size(); + if (scrollToBottom && size > 0) { + while (_savegameListTopIndex + 7 <= size) + _savegameListTopIndex += 6; + } + int index = _savegameListTopIndex; for (int i = 1; i <= 7; i++) - setItemCaption(getItem((ItemID)(kItemIdSavegame1 + i - 1)), index < _savegames.size() ? _savegames[index++]._description.c_str() : ""); + setItemCaption(getItem((ItemID)(kItemIdSavegame1 + i - 1)), index < size ? _savegames[index++]._description.c_str() : ""); + if (_savegameListTopIndex == 0) { + disableItem(kItemIdSavegameUp); + } else { + enableItem(kItemIdSavegameUp); + } + if (_savegameListTopIndex + 7 > size) { + disableItem(kItemIdSavegameDown); + } else { + enableItem(kItemIdSavegameDown); + } } void MenuSystem::scrollSavegames(int delta) { int newPos = CLIP<int>(_savegameListTopIndex + delta, 0, _savegames.size() - 1); _savegameListTopIndex = newPos; restoreRect(80, 92, 440, 140); - setSavegameCaptions(); + setSavegameCaptions(false); for (int i = 1; i <= 7; i++) drawItem((ItemID)(kItemIdSavegame1 + i - 1), false); } @@ -574,7 +643,6 @@ void MenuSystem::drawVolumeBar(ItemID itemID) { text[volume] = 0; drawString(0, y, w, 0, 246, text); - } void MenuSystem::changeVolumeBar(ItemID itemID, int delta) { diff --git a/engines/toltecs/menu.h b/engines/toltecs/menu.h index a72205c2e5..a5eca7c8ff 100644 --- a/engines/toltecs/menu.h +++ b/engines/toltecs/menu.h @@ -84,6 +84,7 @@ public: protected: struct Item { + bool enabled; Common::Rect rect; ItemID id; Common::String caption; @@ -130,6 +131,9 @@ protected: void initMenu(MenuID menuID); + void enableItem(ItemID id); + void disableItem(ItemID id); + void enterItem(ItemID id); void leaveItem(ItemID id); void clickItem(ItemID id); @@ -141,7 +145,7 @@ protected: SavegameItem *getSavegameItemByID(ItemID id); int loadSavegamesList(); - void setSavegameCaptions(); + void setSavegameCaptions(bool scrollToBottom); void scrollSavegames(int delta); void clickSavegameItem(ItemID id); void setCfgText(bool value, bool active); diff --git a/engines/toltecs/microtiles.cpp b/engines/toltecs/microtiles.cpp index 60e65bdaf3..9181480351 100644 --- a/engines/toltecs/microtiles.cpp +++ b/engines/toltecs/microtiles.cpp @@ -119,8 +119,6 @@ Common::Rect * MicroTileArray::getRectangles(int *num_rects, int min_x, int min_ for (y = 0; y < _tilesH; ++y) { for (x = 0; x < _tilesW; ++x) { - - int start; int finish = 0; BoundingBox boundingBox; @@ -141,8 +139,6 @@ Common::Rect * MicroTileArray::getRectangles(int *num_rects, int min_x, int min_ // FIXME: Why is the following code in an #if block? #if 1 - start = i; - if (TileX1(boundingBox) == TileSize - 1 && x != _tilesW - 1) { // check if the tile continues while (!finish) { ++x; diff --git a/engines/toltecs/module.mk b/engines/toltecs/module.mk index aa4a6f376b..0de1eef733 100644 --- a/engines/toltecs/module.mk +++ b/engines/toltecs/module.mk @@ -2,6 +2,7 @@ MODULE := engines/toltecs MODULE_OBJS = \ animation.o \ + console.o \ detection.o \ menu.o \ microtiles.o \ diff --git a/engines/toltecs/movie.cpp b/engines/toltecs/movie.cpp index 35accb5d93..8bc00511e9 100644 --- a/engines/toltecs/movie.cpp +++ b/engines/toltecs/movie.cpp @@ -45,14 +45,13 @@ enum ChunkTypes { kChunkStopSubtitles = 8 }; -MoviePlayer::MoviePlayer(ToltecsEngine *vm) : _vm(vm) { +MoviePlayer::MoviePlayer(ToltecsEngine *vm) : _vm(vm), _isPlaying(false) { } MoviePlayer::~MoviePlayer() { } void MoviePlayer::playMovie(uint resIndex) { - const uint32 subtitleSlot = kMaxScriptSlots - 1; int16 savedSceneWidth = _vm->_sceneWidth; int16 savedSceneHeight = _vm->_sceneHeight; @@ -62,6 +61,7 @@ void MoviePlayer::playMovie(uint resIndex) { int16 savedGuiHeight = _vm->_guiHeight; byte moviePalette[768]; + _isPlaying = true; _vm->_isSaveAllowed = false; memset(moviePalette, 0, sizeof(moviePalette)); @@ -99,15 +99,16 @@ void MoviePlayer::playMovie(uint resIndex) { byte *chunkBuffer = NULL; uint32 chunkBufferSize = 0; uint32 frame = 0; + bool abortMovie = false; - while (_chunkCount--) { + while (_chunkCount-- && !abortMovie) { byte chunkType = _vm->_arc->readByte(); uint32 chunkSize = _vm->_arc->readUint32LE(); debug(0, "chunkType = %d; chunkSize = %d", chunkType, chunkSize); // Skip audio chunks - we've already queued them in - // fetchAudioChunks() above + // fetchAudioChunks() if (chunkType == kChunkAudio) { _vm->_arc->skip(chunkSize); } else { @@ -136,7 +137,8 @@ void MoviePlayer::playMovie(uint resIndex) { if (_vm->_screen->_shakeActive && _vm->_screen->updateShakeScreen()) { _vm->_screen->_fullRefresh = true; } - _vm->updateInput(); + if (!handleInput()) + abortMovie = true; _vm->drawScreen(); // Note: drawScreen() calls delayMillis() } @@ -153,10 +155,11 @@ void MoviePlayer::playMovie(uint resIndex) { // Already processed break; case kChunkShowSubtitle: - if (_vm->_cfgText) { - memcpy(_vm->_script->getSlotData(subtitleSlot), chunkBuffer, chunkSize); - _vm->_screen->updateTalkText(subtitleSlot, 0); - } + memcpy(_vm->_script->getSlotData(subtitleSlot), chunkBuffer, chunkSize); + // The last character of the subtitle determines if it should + // always be displayed or not. If it's 0xFF, it should always be + // displayed, otherwise, if it's 0xFE, it can be toggled. + _vm->_screen->updateTalkText(subtitleSlot, 0, (chunkBuffer[chunkSize - 1] == 0xFF)); break; case kChunkShakeScreen: // start/stop shakescreen effect if (chunkBuffer[0] == 0xFF) @@ -180,7 +183,7 @@ void MoviePlayer::playMovie(uint resIndex) { } if (!handleInput()) - break; + abortMovie = true; } delete[] chunkBuffer; @@ -200,10 +203,10 @@ void MoviePlayer::playMovie(uint resIndex) { _vm->_guiHeight = savedGuiHeight; _vm->_isSaveAllowed = true; + _isPlaying = false; } void MoviePlayer::fetchAudioChunks() { - uint32 startOfs = _vm->_arc->pos(); uint32 chunkCount = _chunkCount; uint prefetchChunkCount = 0; @@ -214,7 +217,7 @@ void MoviePlayer::fetchAudioChunks() { while (chunkCount-- && prefetchChunkCount < _framesPerSoundChunk / 2) { byte chunkType = _vm->_arc->readByte(); uint32 chunkSize = _vm->_arc->readUint32LE(); - if (chunkType == 4) { + if (chunkType == kChunkAudio) { byte *chunkBuffer = (byte *)malloc(chunkSize); _vm->_arc->read(chunkBuffer, chunkSize); _audioStream->queueBuffer(chunkBuffer, chunkSize, DisposeAfterUse::YES, Audio::FLAG_UNSIGNED); @@ -229,7 +232,6 @@ void MoviePlayer::fetchAudioChunks() { _lastPrefetchOfs = _vm->_arc->pos(); _vm->_arc->seek(startOfs, SEEK_SET); - } void MoviePlayer::unpackPalette(byte *source, byte *dest, int elemCount, int elemSize) { @@ -249,10 +251,12 @@ void MoviePlayer::unpackPalette(byte *source, byte *dest, int elemCount, int ele } void MoviePlayer::unpackRle(byte *source, byte *dest) { - int size = 256000; + int size = 256000; // 640x400 + //int packedSize = 0; while (size > 0) { byte a = *source++; byte b = *source++; + //packedSize += 2; if (a == 0) { dest += b; size -= b; @@ -262,6 +266,7 @@ void MoviePlayer::unpackRle(byte *source, byte *dest) { size -= a; } } + //debug("Packed RLE size: %d", packedSize); } bool MoviePlayer::handleInput() { @@ -272,12 +277,15 @@ bool MoviePlayer::handleInput() { case Common::EVENT_KEYDOWN: if (event.kbd.keycode == Common::KEYCODE_ESCAPE) return false; + if (event.kbd.keycode == Common::KEYCODE_F10) { + // TODO: The original would bring up a stripped down + // main menu dialog, without the save/restore options. + } break; case Common::EVENT_LBUTTONDOWN: case Common::EVENT_RBUTTONDOWN: return false; case Common::EVENT_QUIT: - _vm->quitGame(); return false; default: break; diff --git a/engines/toltecs/movie.h b/engines/toltecs/movie.h index 8fa48975d7..c1ed6d7ba0 100644 --- a/engines/toltecs/movie.h +++ b/engines/toltecs/movie.h @@ -37,11 +37,15 @@ public: void playMovie(uint resIndex); + bool isPlaying() { return _isPlaying; } + protected: ToltecsEngine *_vm; Audio::QueuingAudioStream *_audioStream; Audio::SoundHandle _audioStreamHandle; + bool _isPlaying; + uint32 _chunkCount, _frameCount, _lastPrefetchOfs; uint32 _soundChunkFramesLeft, _framesPerSoundChunk; diff --git a/engines/toltecs/palette.cpp b/engines/toltecs/palette.cpp index 74683c6d7a..b93bb8b510 100644 --- a/engines/toltecs/palette.cpp +++ b/engines/toltecs/palette.cpp @@ -32,6 +32,8 @@ namespace Toltecs { Palette::Palette(ToltecsEngine *vm) : _vm(vm) { clearFragments(); + memset(_mainPalette, 0, sizeof(_mainPalette)); + memset(_animPalette, 0, sizeof(_animPalette)); memset(_colorTransTable, 0, sizeof(_colorTransTable)); } @@ -138,52 +140,48 @@ void Palette::clearFragments() { _fragments.clear(); } +byte Palette::getMatchingColor(byte r, byte g, byte b) { + int bestIndex = 0; + uint16 bestMatch = 0xFFFF; + + for (int j = 0; j < 256; j++) { + byte distance = ABS(_mainPalette[j * 3 + 0] - r) + ABS(_mainPalette[j * 3 + 1] - g) + ABS(_mainPalette[j * 3 + 2] - b); + byte maxColor = MAX(_mainPalette[j * 3 + 0], MAX(_mainPalette[j * 3 + 1], _mainPalette[j * 3 + 2])); + uint16 match = (distance << 8) | maxColor; + if (match < bestMatch) { + bestMatch = match; + bestIndex = j; + } + } + + return bestIndex; +} + void Palette::buildColorTransTable(byte limit, int8 deltaValue, byte mask) { byte r = 0, g = 0, b = 0; mask &= 7; - for (int i = 0; i < 256; i++) { - - if (deltaValue < 0) { - // TODO (probably unused) - warning("Palette::buildColorTransTable(%d, %d, %02X) not yet implemented!", limit, deltaValue, mask); - } else { - r = _mainPalette[i * 3 + 0]; - g = _mainPalette[i * 3 + 1]; - b = _mainPalette[i * 3 + 2]; - if (MAX(r, MAX(b, g)) >= limit) { - if ((mask & 1) && r >= deltaValue) - r -= deltaValue; - if ((mask & 2) && g >= deltaValue) - g -= deltaValue; - if ((mask & 4) && b >= deltaValue) - b -= deltaValue; - } - } + if (deltaValue < 0) // unused + error("buildColorTransTable called with a negative delta value(limit %d, delta %d, mask %02X)", limit, deltaValue, mask); - int bestIndex = 0; - uint16 bestMatch = 0xFFFF; - - for (int j = 0; j < 256; j++) { - byte distance = ABS(_mainPalette[j * 3 + 0] - r) + ABS(_mainPalette[j * 3 + 1] - g) + ABS(_mainPalette[j * 3 + 2] - b); - byte maxColor = MAX(_mainPalette[j * 3 + 0], MAX(_mainPalette[j * 3 + 1], _mainPalette[j * 3 + 2])); - uint16 match = (distance << 8) | maxColor; - if (match < bestMatch) { - bestMatch = match; - bestIndex = j; - } + for (int i = 0; i < 256; i++) { + r = _mainPalette[i * 3 + 0]; + g = _mainPalette[i * 3 + 1]; + b = _mainPalette[i * 3 + 2]; + if (MAX(r, MAX(b, g)) >= limit) { + if ((mask & 1) && r >= deltaValue) + r -= deltaValue; + if ((mask & 2) && g >= deltaValue) + g -= deltaValue; + if ((mask & 4) && b >= deltaValue) + b -= deltaValue; } - _colorTransTable[i] = bestIndex; - + _colorTransTable[i] = getMatchingColor(r, g, b); } } -void Palette::buildColorTransTable2(byte limit, int8 deltaValue, byte mask) { - // TODO -} - void Palette::saveState(Common::WriteStream *out) { // Save currently active palette byte palette[768]; diff --git a/engines/toltecs/palette.h b/engines/toltecs/palette.h index 570f51777e..4777a82699 100644 --- a/engines/toltecs/palette.h +++ b/engines/toltecs/palette.h @@ -50,8 +50,8 @@ public: uint16 findFragment(int16 id); void clearFragments(); + byte getMatchingColor(byte r, byte g, byte b); void buildColorTransTable(byte limit, int8 deltaValue, byte mask); - void buildColorTransTable2(byte limit, int8 deltaValue, byte mask); byte getColorTransPixel(byte pixel) const { return _colorTransTable[pixel]; } byte *getMainPalette() { return _mainPalette; } diff --git a/engines/toltecs/resource.cpp b/engines/toltecs/resource.cpp index 0b9f7c8fcd..d66075004b 100644 --- a/engines/toltecs/resource.cpp +++ b/engines/toltecs/resource.cpp @@ -61,16 +61,11 @@ uint32 ArchiveReader::getResourceSize(uint resIndex) { return _offsets[resIndex + 1] - _offsets[resIndex]; } -void ArchiveReader::dump(uint resIndex, const char *prefix) { +void ArchiveReader::dump(uint resIndex) { int32 resourceSize = getResourceSize(resIndex); byte *data = new byte[resourceSize]; - Common::String fn; - - if (prefix) - fn = Common::String::format("%s_%04X.0", prefix, resIndex); - else - fn = Common::String::format("%04X.0", resIndex); + Common::String fn = Common::String::format("toltecs_res.%03d", resIndex); openResource(resIndex); read(data, resourceSize); @@ -112,11 +107,13 @@ Resource *ResourceCache::load(uint resIndex) { } else { debug(1, "ResourceCache::load(%d) From disk", resIndex); + int32 curPos = _vm->_arc->pos(); Resource *resItem = new Resource(); resItem->size = _vm->_arc->openResource(resIndex); resItem->data = new byte[resItem->size]; _vm->_arc->read(resItem->data, resItem->size); _vm->_arc->closeResource(); + _vm->_arc->seek(curPos); _cache[resIndex] = resItem; diff --git a/engines/toltecs/resource.h b/engines/toltecs/resource.h index 3fed2e11ca..3d45d9fb1b 100644 --- a/engines/toltecs/resource.h +++ b/engines/toltecs/resource.h @@ -50,7 +50,7 @@ public: // Returns the size of the resource uint32 getResourceSize(uint resIndex); - void dump(uint resIndex, const char *prefix = NULL); + void dump(uint resIndex); protected: uint32 *_offsets; diff --git a/engines/toltecs/screen.cpp b/engines/toltecs/screen.cpp index c8d6740b02..be91130c0a 100644 --- a/engines/toltecs/screen.cpp +++ b/engines/toltecs/screen.cpp @@ -33,7 +33,6 @@ namespace Toltecs { Screen::Screen(ToltecsEngine *vm) : _vm(vm) { - _frontScreen = new byte[268800]; _backScreen = new byte[870400]; @@ -68,16 +67,13 @@ Screen::Screen(ToltecsEngine *vm) : _vm(vm) { _renderQueue = new RenderQueue(_vm); _fullRefresh = false; _guiRefresh = false; - } Screen::~Screen() { - delete[] _frontScreen; delete[] _backScreen; delete _renderQueue; - } void Screen::unpackRle(byte *source, byte *dest, uint16 width, uint16 height) { @@ -120,7 +116,6 @@ void Screen::loadMouseCursor(uint resIndex) { } void Screen::drawGuiImage(int16 x, int16 y, uint resIndex) { - byte *imageData = _vm->_res->load(resIndex)->data; int16 headerSize = READ_LE_UINT16(imageData); int16 width = imageData[2]; @@ -153,7 +148,6 @@ void Screen::drawGuiImage(int16 x, int16 y, uint resIndex) { } _guiRefresh = true; - } void Screen::startShakeScreen(int16 shakeCounter) { @@ -185,7 +179,6 @@ bool Screen::updateShakeScreen() { } void Screen::addStaticSprite(byte *spriteItem) { - DrawRequest drawRequest; memset(&drawRequest, 0, sizeof(drawRequest)); @@ -200,11 +193,9 @@ void Screen::addStaticSprite(byte *spriteItem) { debug(0, "Screen::addStaticSprite() x = %d; y = %d; baseColor = %d; resIndex = %d; flags = %04X", drawRequest.x, drawRequest.y, drawRequest.baseColor, drawRequest.resIndex, drawRequest.flags); addDrawRequest(drawRequest); - } void Screen::addAnimatedSprite(int16 x, int16 y, int16 fragmentId, byte *data, int16 *spriteArray, bool loop, int mode) { - //debug(0, "Screen::addAnimatedSprite(%d, %d, %d)", x, y, fragmentId); DrawRequest drawRequest; @@ -257,9 +248,7 @@ void Screen::addAnimatedSprite(int16 x, int16 y, int16 fragmentId, byte *data, i WRITE_LE_UINT16(spriteItem + 0, loopNum); WRITE_LE_UINT16(spriteItem + 4, frameNum); - } - } void Screen::clearSprites() { @@ -267,7 +256,6 @@ void Screen::clearSprites() { } void Screen::blastSprite(int16 x, int16 y, int16 fragmentId, int16 resIndex, uint16 flags) { - DrawRequest drawRequest; SpriteDrawItem sprite; @@ -283,11 +271,9 @@ void Screen::blastSprite(int16 x, int16 y, int16 fragmentId, int16 resIndex, uin sprite.y -= _vm->_cameraY; drawSprite(sprite); } - } void Screen::updateVerbLine(int16 slotIndex, int16 slotOffset) { - debug(0, "Screen::updateVerbLine() _verbLineNum = %d; _verbLineX = %d; _verbLineY = %d; _verbLineWidth = %d; _verbLineCount = %d", _verbLineNum, _verbLineX, _verbLineY, _verbLineWidth, _verbLineCount); @@ -339,7 +325,7 @@ void Screen::updateVerbLine(int16 slotIndex, int16 slotOffset) { wrapState.len1 -= len; wrapState.len2 = len + 1; - drawGuiText(_verbLineX - 1 - (wrapState.width / 2), y, 0xF9, 0xFF, _fontResIndexArray[0], wrapState); + drawGuiText(_verbLineX - 1 - (wrapState.width / 2), y - 1, 0xF9, 0xFF, _fontResIndexArray[0], wrapState); wrapState.destString = wrapState.textBuffer; wrapState.width = 0; @@ -354,14 +340,12 @@ void Screen::updateVerbLine(int16 slotIndex, int16 slotOffset) { wrapState.len1 -= len; wrapState.len2 = len; - drawGuiText(_verbLineX - 1 - (wrapState.width / 2), y, 0xF9, 0xFF, _fontResIndexArray[0], wrapState); + drawGuiText(_verbLineX - 1 - (wrapState.width / 2), y - 1, 0xF9, 0xFF, _fontResIndexArray[0], wrapState); _guiRefresh = true; - } -void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { - +void Screen::updateTalkText(int16 slotIndex, int16 slotOffset, bool alwaysDisplayed) { int16 x, y, maxWidth, width, length; byte durationModifier = 1; byte *textData = _vm->_script->getSlotData(slotIndex) + slotOffset; @@ -370,6 +354,7 @@ void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { item->fontNum = 0; item->color = _talkTextFontColor; + item->alwaysDisplayed = alwaysDisplayed; x = CLIP<int16>(_talkTextX - _vm->_cameraX, 120, _talkTextMaxWidth); y = CLIP<int16>(_talkTextY - _vm->_cameraY, 4, _vm->_cameraHeight - 16); @@ -455,11 +440,9 @@ void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) { textDurationMultiplier += 100; } item->duration = 4 * textDurationMultiplier * durationModifier; - } void Screen::addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 width, TalkTextItem *item) { - if (width > 0) { TextRect *textRect = &item->lines[item->lineCount]; width = width + 1 - font.getSpacing(); @@ -472,7 +455,6 @@ void Screen::addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 } y += font.getHeight() - 1; - } void Screen::addTalkTextItemsToRenderQueue() { @@ -488,7 +470,7 @@ void Screen::addTalkTextItemsToRenderQueue() { if (item->duration < 0) item->duration = 0; - if (!_vm->_cfgText) + if (!_vm->_cfgText && !item->alwaysDisplayed) return; for (byte j = 0; j < item->lineCount; j++) { @@ -499,6 +481,15 @@ void Screen::addTalkTextItemsToRenderQueue() { } } +bool Screen::isTalkTextActive(int16 slotIndex) { + for (int16 i = 0; i <= _talkTextItemNum; i++) { + if (_talkTextItems[i].slotIndex == slotIndex && _talkTextItems[i].duration > 0) + return true; + } + + return false; +} + int16 Screen::getTalkTextDuration() { return _talkTextItems[_talkTextItemNum].duration; } @@ -524,7 +515,6 @@ void Screen::registerFont(uint fontIndex, uint resIndex) { } void Screen::drawGuiTextMulti(byte *textData) { - int16 x = 0, y = 0; // Really strange stuff. @@ -554,12 +544,11 @@ void Screen::drawGuiTextMulti(byte *textData) { wrapState.width = 0; wrapState.len1 = 0; wrapState.len2 = wrapGuiText(_fontResIndexArray[1], 640, wrapState); - drawGuiText(x - wrapState.width / 2, y, _fontColor1, _fontColor2, _fontResIndexArray[1], wrapState); + drawGuiText(x - wrapState.width / 2, y - 1, _fontColor1, _fontColor2, _fontResIndexArray[1], wrapState); } } while (*wrapState.sourceString != 0xFF); _guiRefresh = true; - } int16 Screen::wrapGuiText(uint fontResIndex, int maxWidth, GuiTextWrapState &wrapState) { @@ -582,7 +571,6 @@ int16 Screen::wrapGuiText(uint fontResIndex, int maxWidth, GuiTextWrapState &wra } return len; - } void Screen::drawGuiText(int16 x, int16 y, byte fontColor1, byte fontColor2, uint fontResIndex, GuiTextWrapState &wrapState) { @@ -593,11 +581,9 @@ void Screen::drawGuiText(int16 x, int16 y, byte fontColor1, byte fontColor2, uin x = drawString(x + 1, y + _vm->_cameraHeight, fontColor1, fontResIndex, wrapState.textBuffer, wrapState.len1, &ywobble, false); x = drawString(x, y + _vm->_cameraHeight, fontColor2, fontResIndex, wrapState.textBuffer + wrapState.len1, wrapState.len2, &ywobble, false); - } int16 Screen::drawString(int16 x, int16 y, byte color, uint fontResIndex, const byte *text, int len, int16 *ywobble, bool outline) { - //debug(0, "Screen::drawString(%d, %d, %d, %d)", x, y, color, fontResIndex); Font font(_vm->_res->load(fontResIndex)->data); @@ -614,7 +600,7 @@ int16 Screen::drawString(int16 x, int16 y, byte color, uint fontResIndex, const if (ch <= 0x20) { x += font.getWidth(); } else { - drawChar(font, _frontScreen, x, y - yadd, ch, color, outline); + drawChar(font, _frontScreen, x, y + yadd, ch, color, outline); x += font.getCharWidth(ch) + font.getSpacing() - 1; yadd = -yadd; } @@ -624,11 +610,9 @@ int16 Screen::drawString(int16 x, int16 y, byte color, uint fontResIndex, const *ywobble = yadd; return x; - } void Screen::drawChar(const Font &font, byte *dest, int16 x, int16 y, byte ch, byte color, bool outline) { - int16 charWidth, charHeight; byte *charData; @@ -657,11 +641,9 @@ void Screen::drawChar(const Font &font, byte *dest, int16 x, int16 y, byte ch, b } dest += 640 - charWidth; } - } void Screen::drawSurface(int16 x, int16 y, Graphics::Surface *surface) { - int16 skipX = 0; int16 width = surface->w; int16 height = surface->h; @@ -706,11 +688,9 @@ void Screen::drawSurface(int16 x, int16 y, Graphics::Surface *surface) { frontScreen += 640 - width; surfacePixels += surface->w - width - skipX; } - } void Screen::saveState(Common::WriteStream *out) { - // Save verb line out->writeUint16LE(_verbLineNum); out->writeUint16LE(_verbLineX); @@ -757,11 +737,9 @@ void Screen::saveState(Common::WriteStream *out) { out->writeUint32LE(_fontResIndexArray[i]); out->writeByte(_fontColor1); out->writeByte(_fontColor2); - } void Screen::loadState(Common::ReadStream *in) { - // Load verb line _verbLineNum = in->readUint16LE(); _verbLineX = in->readUint16LE(); @@ -786,6 +764,7 @@ void Screen::loadState(Common::ReadStream *in) { _talkTextItems[i].fontNum = in->readUint16LE(); _talkTextItems[i].color = in->readByte(); _talkTextItems[i].lineCount = in->readByte(); + _talkTextItems[i].alwaysDisplayed = false; for (int j = 0; j < _talkTextItems[i].lineCount; j++) { _talkTextItems[i].lines[j].x = in->readUint16LE(); _talkTextItems[i].lines[j].y = in->readUint16LE(); @@ -809,7 +788,6 @@ void Screen::loadState(Common::ReadStream *in) { _fontResIndexArray[i] = in->readUint32LE(); _fontColor1 = in->readByte(); _fontColor2 = in->readByte(); - } } // End of namespace Toltecs diff --git a/engines/toltecs/screen.h b/engines/toltecs/screen.h index 788cde50c6..ee565e1882 100644 --- a/engines/toltecs/screen.h +++ b/engines/toltecs/screen.h @@ -136,6 +136,7 @@ struct TalkTextItem { byte color; byte lineCount; TextRect lines[15]; + bool alwaysDisplayed; }; struct GuiTextWrapState { @@ -177,10 +178,11 @@ public: void updateVerbLine(int16 slotIndex, int16 slotOffset); // Talk text - void updateTalkText(int16 slotIndex, int16 slotOffset); + void updateTalkText(int16 slotIndex, int16 slotOffset, bool alwaysDisplayed); void addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 width, TalkTextItem *item); void addTalkTextItemsToRenderQueue(); int16 getTalkTextDuration(); + bool isTalkTextActive(int16 slotIndex); void finishTalkTextItems(); void keepTalkTextItemsAlive(); diff --git a/engines/toltecs/script.cpp b/engines/toltecs/script.cpp index 5e8617bc43..9ea95a2cd1 100644 --- a/engines/toltecs/script.cpp +++ b/engines/toltecs/script.cpp @@ -40,6 +40,22 @@ namespace Toltecs { +static const VarType varTypes[] = { + vtByte, vtWord, vtWord, vtByte, vtWord, // 0 - 4 + vtWord, vtWord, vtWord, vtWord, vtWord, // 5 - 9 + vtWord, vtWord, vtByte, vtWord, vtWord, // 10 - 14 + vtWord, vtWord, vtWord, vtWord, vtWord, // 15 - 19 + vtWord, vtWord // 20 - 21 +}; + +static const char *varNames[] = { + "mouseDisabled", "mouseY", "mouseX", "mouseButton", "verbLineY", // 0 - 4 + "verbLineX", "verbLineWidth", "verbLineCount", "verbLineNum", "talkTextItemNum", // 5 - 9 + "talkTextY", "talkTextX", "talkTextFontColor", "cameraY", "cameraX", // 10 - 14 + "walkSpeedY", "walkSpeedX", "flag01", "sceneResIndex", "guiHeight", // 15 - 19 + "sceneHeight", "sceneWidth" // 20 - 21 +}; + ScriptInterpreter::ScriptInterpreter(ToltecsEngine *vm) : _vm(vm) { _stack = new byte[kScriptStackSize]; @@ -154,7 +170,6 @@ void ScriptInterpreter::setupScriptFunctions() { } void ScriptInterpreter::loadScript(uint resIndex, uint slotIndex) { - delete[] _slots[slotIndex].data; _slots[slotIndex].resIndex = resIndex; @@ -162,7 +177,6 @@ void ScriptInterpreter::loadScript(uint resIndex, uint slotIndex) { _slots[slotIndex].size = scriptResource->size; _slots[slotIndex].data = new byte[_slots[slotIndex].size]; memcpy(_slots[slotIndex].data, scriptResource->data, _slots[slotIndex].size); - } void ScriptInterpreter::setMainScript(uint slotIndex) { @@ -228,10 +242,9 @@ int16 ScriptInterpreter::readInt16() { } void ScriptInterpreter::execOpcode(byte opcode) { - int16 ofs; - debug(1, "opcode = %d", opcode); + debug(2, "opcode = %d", opcode); switch (opcode) { case 0: @@ -239,35 +252,32 @@ void ScriptInterpreter::execOpcode(byte opcode) { // ok _subCode = _code; byte length = readByte(); - debug(1, "length = %d", length); + if (length == 0) { + warning("Possible script bug detected - opcode length is 0 when calling script function"); + return; + } + debug(2, "length = %d", length); uint16 index = readInt16(); - debug(1, "callScriptFunction %d", index); execScriptFunction(index); _code += length - 2; break; } case 1: - // ok _regs.reg0 = readInt16(); break; case 2: - // ok _regs.reg1 = readInt16(); break; case 3: - // ok _regs.reg3 = readInt16(); break; case 4: - // ok _regs.reg5 = _regs.reg0; break; case 5: - // ok _regs.reg3 = _regs.reg0; break; case 6: - // ok _regs.reg1 = _regs.reg0; break; case 7: @@ -468,72 +478,14 @@ void ScriptInterpreter::execOpcode(byte opcode) { } void ScriptInterpreter::execScriptFunction(uint16 index) { - debug(4, "execScriptFunction(%d)", index); if (index >= _scriptFuncs.size()) error("ScriptInterpreter::execScriptFunction() Invalid script function index %d", index); - debug(4, "%s", _scriptFuncNames[index]); + debug(1, "execScriptFunction %s (%d)", _scriptFuncNames[index], index); (*_scriptFuncs[index])(); } -VarType ScriptInterpreter::getGameVarType(uint variable) { - switch (variable) { - case 0: return vtByte; - case 1: return vtWord; - case 2: return vtWord; - case 3: return vtByte; - case 4: return vtWord; - case 5: return vtWord; - case 6: return vtWord; - case 7: return vtWord; - case 8: return vtWord; - case 9: return vtWord; - case 10: return vtWord; - case 11: return vtWord; - case 12: return vtByte; - case 13: return vtWord; - case 14: return vtWord; - case 15: return vtWord; - case 16: return vtWord; - case 17: return vtWord; - case 18: return vtWord; - case 19: return vtWord; - case 20: return vtWord; - case 21: return vtWord; - default: - error("Invalid game variable"); - } -} - -const char *getVarName(uint variable) { - switch (variable) { - case 0: return "mouseDisabled"; - case 1: return "mouseY"; - case 2: return "mouseX"; - case 3: return "mouseButton"; - case 4: return "verbLineY"; - case 5: return "verbLineX"; - case 6: return "verbLineWidth"; - case 7: return "verbLineCount"; - case 8: return "verbLineNum"; - case 9: return "talkTextItemNum"; - case 10: return "talkTextY"; - case 11: return "talkTextX"; - case 12: return "talkTextFontColor"; - case 13: return "cameraY"; - case 14: return "cameraX"; - case 15: return "walkSpeedY"; - case 16: return "walkSpeedX"; - case 17: return "flag01"; - case 18: return "sceneResIndex"; - case 19: return "guiHeight"; - case 20: return "sceneHeight"; - case 21: return "sceneWidth"; - } - return "(invalid)"; -} - int16 ScriptInterpreter::getGameVar(uint variable) { - debug(0, "ScriptInterpreter::getGameVar(%d{%s})", variable, getVarName(variable)); + debug(2, "ScriptInterpreter::getGameVar(%d{%s})", variable, varNames[variable]); switch (variable) { case 0: return _vm->_mouseDisabled; @@ -559,13 +511,13 @@ int16 ScriptInterpreter::getGameVar(uint variable) { case 20: return _vm->_sceneHeight; case 21: return _vm->_sceneWidth; default: - warning("Getting unimplemented game variable %s (%d)", getVarName(variable), variable); + warning("Getting unimplemented game variable %s (%d)", varNames[variable], variable); return 0; } } void ScriptInterpreter::setGameVar(uint variable, int16 value) { - debug(0, "ScriptInterpreter::setGameVar(%d{%s}, %d)", variable, getVarName(variable), value); + debug(2, "ScriptInterpreter::setGameVar(%d{%s}, %d)", variable, varNames[variable], value); switch (variable) { case 0: @@ -632,10 +584,9 @@ void ScriptInterpreter::setGameVar(uint variable, int16 value) { case 1: case 2: default: - warning("Setting unimplemented game variable %s (%d) to %d", getVarName(variable), variable, value); + warning("Setting unimplemented game variable %s (%d) to %d", varNames[variable], variable, value); break; } - } byte ScriptInterpreter::arg8(int16 offset) { @@ -657,32 +608,31 @@ int16 ScriptInterpreter::popInt16() { } void ScriptInterpreter::localWrite8(int16 offset, byte value) { - //debug(1, "localWrite8(%d, %d)", offset, value); + //debug(2, "localWrite8(%d, %d)", offset, value); _localData[offset] = value; } byte ScriptInterpreter::localRead8(int16 offset) { - //debug(1, "localRead8(%d) -> %d", offset, _localData[offset]); + //debug(2, "localRead8(%d) -> %d", offset, _localData[offset]); return _localData[offset]; } void ScriptInterpreter::localWrite16(int16 offset, int16 value) { - //debug(1, "localWrite16(%d, %d)", offset, value); + //debug(2, "localWrite16(%d, %d)", offset, value); WRITE_LE_UINT16(&_localData[offset], value); } int16 ScriptInterpreter::localRead16(int16 offset) { - //debug(1, "localRead16(%d) -> %d", offset, (int16)READ_LE_UINT16(&_localData[offset])); + //debug(2, "localRead16(%d) -> %d", offset, (int16)READ_LE_UINT16(&_localData[offset])); return (int16)READ_LE_UINT16(&_localData[offset]); } byte *ScriptInterpreter::localPtr(int16 offset) { - //debug(1, "localPtr(%d)", offset); + //debug(2, "localPtr(%d)", offset); return &_localData[offset]; } void ScriptInterpreter::saveState(Common::WriteStream *out) { - // Save registers out->writeUint16LE(_regs.reg0); out->writeUint16LE(_regs.reg1); @@ -708,11 +658,9 @@ void ScriptInterpreter::saveState(Common::WriteStream *out) { // Save IP out->writeUint16LE((int16)(_code - getSlotData(_regs.reg4))); - } void ScriptInterpreter::loadState(Common::ReadStream *in) { - // Load registers _regs.reg0 = in->readUint16LE(); _regs.reg1 = in->readUint16LE(); @@ -741,7 +689,6 @@ void ScriptInterpreter::loadState(Common::ReadStream *in) { // Load IP _code = getSlotData(_regs.reg4) + in->readUint16LE(); - } void ScriptInterpreter::sfNop() { @@ -755,7 +702,9 @@ void ScriptInterpreter::sfGetGameVar() { void ScriptInterpreter::sfSetGameVar() { int16 varIndex = arg16(3); - VarType varType = getGameVarType(varIndex); + assert(varIndex <= 21); + + VarType varType = varTypes[varIndex]; int16 value = 0; if (varType == vtByte) value = arg8(5); @@ -810,8 +759,7 @@ void ScriptInterpreter::sfSetDeltaAnimPalette() { } void ScriptInterpreter::sfSetUnkPaletteEffect() { - // TODO - debug("ScriptInterpreter::sfSetUnkPaletteEffect"); + error("ScriptInterpreter::sfSetUnkPaletteEffect called"); // unused } void ScriptInterpreter::sfBuildColorTransTable() { @@ -992,7 +940,8 @@ void ScriptInterpreter::sfStopShakeScreen() { void ScriptInterpreter::sfStartSequence() { int16 sequenceResIndex = arg16(3); - //debug("ScriptInterpreter::sfStartSequence(%d)", sequenceResIndex); + debug(1, "ScriptInterpreter::sfStartSequence(%d)", sequenceResIndex); + if (sequenceResIndex >= 0) { //_vm->_arc->dump(sequenceResIndex, "music"); // DEBUG: Dump music so we know what's in there @@ -1001,7 +950,6 @@ void ScriptInterpreter::sfStartSequence() { } void ScriptInterpreter::sfEndSequence() { - //debug("ScriptInterpreter::sfEndSequence"); _vm->_music->stopSequence(); } @@ -1029,9 +977,8 @@ void ScriptInterpreter::sfHandleInput() { if (_vm->_rightButtonDown) { keyCode = 1; } else { - /* Convert keyboard scancode to IBM PC scancode - Only scancodes known to be used (so far) are converted - */ + // Convert keyboard scancode to IBM PC scancode. + // Only scancodes known to be used (so far) are converted. switch (_vm->_keyState.keycode) { case Common::KEYCODE_ESCAPE: keyCode = 1; @@ -1050,11 +997,13 @@ void ScriptInterpreter::sfRunOptionsScreen() { _vm->showMenu(kMenuIdMain); } -/* NOTE: The opcodes sfPrecacheSprites, sfPrecacheSounds1, sfPrecacheSounds2 and - sfDeletePrecachedFiles were used by the original engine to handle precaching - of data so the game doesn't stall while playing (due to the slow speed of - CD-Drives back then). This is not needed in ScummVM since all supported - systems are fast enough to load data in-game. */ +/** + * NOTE: The opcodes sfPrecacheSprites, sfPrecacheSounds1, sfPrecacheSounds2 and + * sfDeletePrecachedFiles were used by the original engine to handle precaching + * of data so the game doesn't stall while playing (due to the slow speed of + * CD-Drives back then). This is not needed in ScummVM since all supported + * systems are fast enough to load data in-game. + */ void ScriptInterpreter::sfPrecacheSprites() { // See note above diff --git a/engines/toltecs/script.h b/engines/toltecs/script.h index 89dca4598f..4c880dfef5 100644 --- a/engines/toltecs/script.h +++ b/engines/toltecs/script.h @@ -49,7 +49,6 @@ public: byte *getSlotData(int slotIndex) const { return _slots[slotIndex].data; } - VarType getGameVarType(uint variable); int16 getGameVar(uint variable); void setGameVar(uint variable, int16 value); diff --git a/engines/toltecs/sound.cpp b/engines/toltecs/sound.cpp index 4b281392e5..8afc0e7890 100644 --- a/engines/toltecs/sound.cpp +++ b/engines/toltecs/sound.cpp @@ -103,8 +103,7 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa } } } else { - - if (type == -3) { + if (type == kChannelTypeSpeech) { // Stop speech and play new sound stopSpeech(); } @@ -137,10 +136,8 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa _vm->_mixer->playStream(soundType, &channels[freeChannel].handle, stream, -1, volume, panning); - } - - } - + } // if (freeChannel >= 0) + } // resIndex } void Sound::updateSpeech() { diff --git a/engines/toltecs/toltecs.cpp b/engines/toltecs/toltecs.cpp index 9f3a10a03b..1a399dacc0 100644 --- a/engines/toltecs/toltecs.cpp +++ b/engines/toltecs/toltecs.cpp @@ -39,6 +39,7 @@ #include "toltecs/toltecs.h" #include "toltecs/animation.h" +#include "toltecs/console.h" #include "toltecs/menu.h" #include "toltecs/movie.h" #include "toltecs/music.h" @@ -62,6 +63,9 @@ struct GameSettings { }; ToltecsEngine::ToltecsEngine(OSystem *syst, const ToltecsGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { + // Assign default values to the config manager, in case settings are missing + ConfMan.registerDefault("originalsaveload", "false"); + _rnd = new Common::RandomSource("toltecs"); } @@ -123,6 +127,7 @@ Common::Error ToltecsEngine::run() { _menuSystem = new MenuSystem(this); _sound = new Sound(this); + _console = new Console(this); _cfgText = ConfMan.getBool("subtitles"); _cfgVoices = !ConfMan.getBool("speech_mute"); @@ -176,6 +181,7 @@ Common::Error ToltecsEngine::run() { _music->stopSequence(); _sound->stopAll(); + delete _console; delete _arc; delete _res; delete _screen; @@ -215,7 +221,6 @@ void ToltecsEngine::requestLoadgame(int slotNum) { } void ToltecsEngine::loadScene(uint resIndex) { - Resource *sceneResource = _res->load(resIndex); byte *scene = sceneResource->data; @@ -250,13 +255,10 @@ void ToltecsEngine::loadScene(uint resIndex) { _screen->_fullRefresh = true; _screen->_renderQueue->clear(); - } void ToltecsEngine::updateScreen() { - _sound->updateSpeech(); - _screen->updateShakeScreen(); // TODO: Set quit flag @@ -289,7 +291,6 @@ void ToltecsEngine::updateScreen() { _counter02 = (currUpdateTime - prevUpdateTime) / 13; } while (_counter02 == 0); prevUpdateTime = currUpdateTime; - } void ToltecsEngine::drawScreen() { @@ -310,6 +311,7 @@ void ToltecsEngine::drawScreen() { _screen->_guiRefresh = false; } + _console->onFrame(); _system->updateScreen(); _system->delayMillis(10); @@ -317,7 +319,6 @@ void ToltecsEngine::drawScreen() { } void ToltecsEngine::updateInput() { - Common::Event event; Common::EventManager *eventMan = _system->getEventManager(); while (eventMan->pollEvent(event)) { @@ -327,6 +328,9 @@ void ToltecsEngine::updateInput() { //debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode); + if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) + _console->attach(); + switch (event.kbd.keycode) { case Common::KEYCODE_F5: showMenu(kMenuIdSave); @@ -350,9 +354,6 @@ void ToltecsEngine::updateInput() { case Common::EVENT_KEYUP: _keyState.reset(); break; - case Common::EVENT_QUIT: - quitGame(); - break; case Common::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; _mouseY = event.mouse.y; @@ -408,9 +409,7 @@ void ToltecsEngine::updateInput() { _mouseWaitForRelease = false; _mouseButton = 0; } - } - } void ToltecsEngine::setGuiHeight(int16 guiHeight) { @@ -478,7 +477,6 @@ void ToltecsEngine::scrollCameraRight(int16 delta) { } void ToltecsEngine::updateCamera() { - if (_cameraX != _newCameraX) { _cameraX = _newCameraX; _screen->_fullRefresh = true; @@ -492,13 +490,16 @@ void ToltecsEngine::updateCamera() { } //debug(0, "ToltecsEngine::updateCamera() _cameraX = %d; _cameraY = %d", _cameraX, _cameraY); - } void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) { - byte *scanData = _script->getSlotData(slotIndex) + slotOffset; + // If there's another talk text at the requested slot and it's still + // active, don't overwrite it. Fixes bug #3600166. + if (_screen->isTalkTextActive(slotIndex)) + return; + while (*scanData < 0xF0) { if (*scanData == 0x19) { scanData++; @@ -518,19 +519,18 @@ void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) { debug(0, "ToltecsEngine::talk() playSound(resIndex: %d)", resIndex); _sound->playSpeech(resIndex); } + if (_doText) { - _screen->updateTalkText(slotIndex, slotOffset); + _screen->updateTalkText(slotIndex, slotOffset, false); } else { _screen->keepTalkTextItemsAlive(); } } else { - _screen->updateTalkText(slotIndex, slotOffset); + _screen->updateTalkText(slotIndex, slotOffset, true); } - } void ToltecsEngine::walk(byte *walkData) { - int16 xdelta, ydelta, v8, v10, v11; int16 xstep, ystep; ScriptWalk walkInfo; @@ -613,7 +613,6 @@ void ToltecsEngine::walk(byte *walkData) { WRITE_LE_UINT16(walkData + 14, walkInfo.xerror); WRITE_LE_UINT16(walkData + 16, walkInfo.mulValue); WRITE_LE_UINT16(walkData + 18, walkInfo.scaling); - } int16 ToltecsEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 index, int16 itemSize, diff --git a/engines/toltecs/toltecs.h b/engines/toltecs/toltecs.h index b95a4f77cb..0be2d2a646 100644 --- a/engines/toltecs/toltecs.h +++ b/engines/toltecs/toltecs.h @@ -42,6 +42,7 @@ struct ToltecsGameDescription; class AnimationPlayer; class ArchiveReader; +class Console; class Input; class MenuSystem; class MoviePlayer; @@ -144,6 +145,7 @@ public: AnimationPlayer *_anim; ArchiveReader *_arc; + Console *_console; Input *_input; MenuSystem *_menuSystem; MoviePlayer *_moviePlayer; |