From 2af4fc103499236cf79c7cfafeaaa622ea63e7cd Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 18 Mar 2008 15:50:43 +0000 Subject: - Implemented opcodes: -> 21: o2_backUpScreen -> 22: o2_restoreScreen -> 28: o2_addItemToInventory -> 50: o2_wipeDownMouseItem -> 67: o2_loadPalette384 -> 68: o2_setPalette384 -> 165: o2_disableTimer -> 166: o2_enableTimer -> 167: o2_setTimerCountdown - renamed some timer functions svn-id: r31182 --- engines/kyra/animator_v2.cpp | 2 +- engines/kyra/gui_v2.cpp | 8 ++++ engines/kyra/kyra_v2.cpp | 1 - engines/kyra/kyra_v2.h | 17 ++++++-- engines/kyra/resource.cpp | 4 -- engines/kyra/script_v2.cpp | 101 +++++++++++++++++++++++++++++++++++++++---- engines/kyra/timer_v2.cpp | 18 ++++---- 7 files changed, 123 insertions(+), 28 deletions(-) (limited to 'engines') diff --git a/engines/kyra/animator_v2.cpp b/engines/kyra/animator_v2.cpp index 22b01c7198..bda6be7ac3 100644 --- a/engines/kyra/animator_v2.cpp +++ b/engines/kyra/animator_v2.cpp @@ -196,7 +196,7 @@ void KyraEngine_v2::refreshAnimObjectsIfNeed() { void KyraEngine_v2::updateItemAnimations() { bool nextFrame = false; - if (_itemAnimData[0].itemIndex == -1 || _holdItemAnims) + if (_itemAnimData[0].itemIndex == -1 || _inventorySaved) return; ItemAnimData *s = &_itemAnimData[_nextAnimItem++]; diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp index 75603d623e..6cfdf67290 100644 --- a/engines/kyra/gui_v2.cpp +++ b/engines/kyra/gui_v2.cpp @@ -650,6 +650,14 @@ int KyraEngine_v2::getInventoryItemSlot(uint16 item) { return -1; } +int KyraEngine_v2::findFreeVisibleInventorySlot() { + for (int i = 0; i < 10; ++i) { + if (_mainCharacter.inventory[i] == 0xFFFF) + return i; + } + return -1; +} + void KyraEngine_v2::removeItemFromInventory(int slot) { _mainCharacter.inventory[slot] = 0xFFFF; if (slot < 10) { diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 3c4aa30c0e..01c9c21a7b 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -97,7 +97,6 @@ KyraEngine_v2::KyraEngine_v2(OSystem *system, const GameFlags &flags) : KyraEngi memset(&_invWsa, 0, sizeof(_invWsa)); _itemAnimTable = 0; _nextAnimItem = 0; - _holdItemAnims = false; _colorCodeFlag1 = 0; _colorCodeFlag2 = -1; diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index 1f227c4f4d..70b8902c40 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -593,6 +593,7 @@ protected: void clearInventorySlot(int slot, int page); void redrawInventory(int page); void scrollInventoryWheel(); + int findFreeVisibleInventorySlot(); struct ItemAnimData { int16 itemIndex; @@ -603,7 +604,6 @@ protected: } _itemAnimData[15]; int _nextAnimItem; - bool _holdItemAnims; // gui void loadButtonShapes(); @@ -908,11 +908,11 @@ protected: void snd_playSoundEffect(int track); // timer - void timerFunc2(int); + void timerFadeOutMessage(int); void timerCauldronAnimation(int); void timerFunc4(int); void timerFunc5(int); - void timerFunc6(int); + void timerBurnZanthia(int); void setTimer1DelaySecs(int secs); @@ -967,12 +967,15 @@ protected: int o2_showChapterMessage(ScriptState *script); int o2_restoreTalkTextMessageBkgd(ScriptState *script); int o2_wsaClose(ScriptState *script); - int o2_meanWhileScene(ScriptState *script); + int o2_meanWhileScene(ScriptState *script); + int o2_backUpScreen(ScriptState *script); + int o2_restoreScreen(ScriptState *script); int o2_displayWsaFrame(ScriptState *script); int o2_displayWsaSequentialFramesLooping(ScriptState *script); int o2_wsaOpen(ScriptState *script); int o2_displayWsaSequentialFrames(ScriptState *script); int o2_displayWsaSequence(ScriptState *script); + int o2_addItemToInventory(ScriptState *script); int o2_drawShape(ScriptState *script); int o2_addItemToCurScene(ScriptState *script); int o2_checkForItem(ScriptState *script); @@ -990,6 +993,7 @@ protected: int o2_addSpecialExit(ScriptState *script); int o2_setMousePos(ScriptState *script); int o2_showMouse(ScriptState *script); + int o2_wipeDownMouseItem(ScriptState *script); //int o2_playSoundEffect(ScriptState *script); int o2_delaySecs(ScriptState *script); int o2_delay(ScriptState *script); @@ -1000,6 +1004,8 @@ protected: int o2_drawSceneShapeOnPage(ScriptState *script); int o2_disableAnimObject(ScriptState *script); int o2_enableAnimObject(ScriptState *script); + int o2_loadPalette384(ScriptState *script); + int o2_setPalette384(ScriptState *script); int o2_restoreBackBuffer(ScriptState *script); int o2_backUpInventoryGfx(ScriptState *script); int o2_disableSceneAnim(ScriptState *script); @@ -1065,6 +1071,9 @@ protected: int o2_customChatFinish(ScriptState *script); int o2_setupSceneAnimation(ScriptState *script); int o2_stopSceneAnimation(ScriptState *script); + int o2_disableTimer(ScriptState *script); + int o2_enableTimer(ScriptState *script); + int o2_setTimerCountdown(ScriptState *script); int o2_processPaletteIndex(ScriptState *script); int o2_getBoolFromStack(ScriptState *script); int o2_setVocHigh(ScriptState *script); diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index 0f48dcdd07..11c48e04ed 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -347,10 +347,6 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) { if (!stream) return false; - if (maxSize < stream->size()) { - delete stream; - return false; - } memset(buf, 0, maxSize); stream->read(buf, stream->size()); delete stream; diff --git a/engines/kyra/script_v2.cpp b/engines/kyra/script_v2.cpp index 6c339fdb16..f29dedfb0f 100644 --- a/engines/kyra/script_v2.cpp +++ b/engines/kyra/script_v2.cpp @@ -27,6 +27,7 @@ #include "kyra/text_v2.h" #include "kyra/wsamovie.h" #include "kyra/sound.h" +#include "kyra/timer.h" #include "common/endian.h" @@ -196,6 +197,18 @@ int KyraEngine_v2::o2_meanWhileScene(ScriptState *script) { return 0; } +int KyraEngine_v2::o2_backUpScreen(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_backUpScreen(%p) (%d)", (const void *)script, stackPos(0)); + _screen->copyRegionToBuffer(stackPos(0), 0, 0, 320, 144, _screenBuffer); + return 0; +} + +int KyraEngine_v2::o2_restoreScreen(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_restoreScreen(%p) (%d)", (const void *)script, stackPos(0)); + _screen->copyBlockToPage(stackPos(0), 0, 0, 320, 144, _screenBuffer); + return 0; +} + int KyraEngine_v2::o2_displayWsaFrame(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_displayWsaFrame(%p) (%d, %d, %d, %d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7), stackPos(8)); @@ -355,6 +368,17 @@ int KyraEngine_v2::o2_displayWsaSequence(ScriptState *script) { return 0; } +int KyraEngine_v2::o2_addItemToInventory(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_addItemToInventory(%p) (%d, -, %d)", (const void *)script, stackPos(0), stackPos(2)); + int slot = findFreeVisibleInventorySlot(); + if (slot != -1) { + _mainCharacter.inventory[slot] = stackPos(0); + if (stackPos(2)) + redrawInventory(0); + } + return slot; +} + int KyraEngine_v2::o2_drawShape(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_drawShape(%p) (%d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); @@ -519,6 +543,33 @@ int KyraEngine_v2::o2_showMouse(ScriptState *script) { return 0; } +int KyraEngine_v2::o2_wipeDownMouseItem(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_wipeDownMouseItem(%p) (-, %d, %d)", (const void *)script, stackPos(1), stackPos(2)); + _screen->hideMouse(); + const int x = stackPos(1) - 8; + const int y = stackPos(2) - 15; + + if (_itemInHand >= 0) { + backUpGfxRect32x32(x, y); + uint8 *shape = getShapePtr(_itemInHand+64); + for (int curY = y, height = 16; height > 0; height -= 2, curY += 2) { + restoreGfxRect32x32(x, y); + _screen->setNewShapeHeight(shape, height); + uint32 waitTime = _system->getMillis() + _tickLength; + _screen->drawShape(0, shape, x, curY, 0, 0); + _screen->updateScreen(); + delayUntil(waitTime); + } + restoreGfxRect32x32(x, y); + _screen->resetShapeHeight(shape); + } + + _screen->showMouse(); + removeHandItem(); + + return 0; +} + int KyraEngine_v2::o2_delaySecs(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_delaySecs(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); delay(stackPos(0) * 1000, true); @@ -602,6 +653,20 @@ int KyraEngine_v2::o2_enableAnimObject(ScriptState *script) { return 0; } +int KyraEngine_v2::o2_loadPalette384(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_loadPalette384(%p) ('%s')", (const void *)script, stackPosString(0)); + memcpy(_screen->getPalette(1), _screen->getPalette(0), 768); + _res->loadFileToBuf(stackPosString(0), _screen->getPalette(1), 384); + return 0; +} + +int KyraEngine_v2::o2_setPalette384(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_setPalette384(%p) ()", (const void *)script); + memcpy(_screen->getPalette(0), _screen->getPalette(1), 384); + _screen->setScreenPalette(_screen->getPalette(0)); + return 0; +} + int KyraEngine_v2::o2_restoreBackBuffer(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_restoreBackBuffer(%p) (%d)", (const void *)script, stackPos(0)); int disable = stackPos(0); @@ -1348,6 +1413,24 @@ int KyraEngine_v2::o2_stopSceneAnimation(ScriptState *script) { return 0; } +int KyraEngine_v2::o2_disableTimer(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_disableTimer(%p) (%d)", (const void *)script, stackPos(0)); + _timer->disable(stackPos(0)); + return 0; +} + +int KyraEngine_v2::o2_enableTimer(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_enableTimer(%p) (%d)", (const void *)script, stackPos(0)); + _timer->enable(stackPos(0)); + return 0; +} + +int KyraEngine_v2::o2_setTimerCountdown(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_setTimerCountdown(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); + _timer->setCountdown(stackPos(0), stackPos(1)); + return 0; +} + int KyraEngine_v2::o2_processPaletteIndex(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_processPaletteIndex(%p) (%d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5)); uint8 *palette = _screen->getPalette(0); @@ -1492,8 +1575,8 @@ void KyraEngine_v2::setupOpcodeTable() { OpcodeUnImpl(), // 0x14 Opcode(o2_wsaClose), - OpcodeUnImpl(), - OpcodeUnImpl(), + Opcode(o2_backUpScreen), + Opcode(o2_restoreScreen), Opcode(o2_displayWsaFrame), // 0x18 Opcode(o2_displayWsaSequentialFramesLooping), @@ -1501,7 +1584,7 @@ void KyraEngine_v2::setupOpcodeTable() { Opcode(o2_displayWsaSequentialFrames), Opcode(o2_displayWsaSequence), // 0x1c - OpcodeUnImpl(), + Opcode(o2_addItemToInventory), Opcode(o2_drawShape), Opcode(o2_addItemToCurScene), OpcodeUnImpl(), @@ -1528,7 +1611,7 @@ void KyraEngine_v2::setupOpcodeTable() { // 0x30 Opcode(o2_showMouse), OpcodeUnImpl(), - OpcodeUnImpl(), + Opcode(o2_wipeDownMouseItem), OpcodeUnImpl(), // 0x34 OpcodeUnImpl(), @@ -1549,9 +1632,9 @@ void KyraEngine_v2::setupOpcodeTable() { Opcode(o2_disableAnimObject), Opcode(o2_enableAnimObject), Opcode(o2_dummy), - OpcodeUnImpl(), + Opcode(o2_loadPalette384), // 0x44 - OpcodeUnImpl(), + Opcode(o2_setPalette384), Opcode(o2_restoreBackBuffer), Opcode(o2_backUpInventoryGfx), Opcode(o2_disableSceneAnim), @@ -1661,9 +1744,9 @@ void KyraEngine_v2::setupOpcodeTable() { Opcode(o2_setupSceneAnimation), Opcode(o2_stopSceneAnimation), // 0x9c - OpcodeUnImpl(), - OpcodeUnImpl(), - OpcodeUnImpl(), + Opcode(o2_disableTimer), + Opcode(o2_enableTimer), + Opcode(o2_setTimerCountdown), Opcode(o2_processPaletteIndex), // 0xa0 OpcodeUnImpl(), diff --git a/engines/kyra/timer_v2.cpp b/engines/kyra/timer_v2.cpp index 7a0fe5b03f..b9b2819e1d 100644 --- a/engines/kyra/timer_v2.cpp +++ b/engines/kyra/timer_v2.cpp @@ -34,15 +34,15 @@ void KyraEngine_v2::setupTimers() { debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::setupTimers()"); _timer->addTimer(0, 0, 5, 1); - _timer->addTimer(1, TimerV2(timerFunc2), -1, 1); + _timer->addTimer(1, TimerV2(timerFadeOutMessage), -1, 1); _timer->addTimer(2, TimerV2(timerCauldronAnimation), 1, 1); _timer->addTimer(3, TimerV2(timerFunc4), 1, 0); _timer->addTimer(4, TimerV2(timerFunc5), 1, 0); - _timer->addTimer(5, TimerV2(timerFunc6), 1, 0); + _timer->addTimer(5, TimerV2(timerBurnZanthia), 1, 0); } -void KyraEngine_v2::timerFunc2(int arg) { - debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::timerFunc2(%d)", arg); +void KyraEngine_v2::timerFadeOutMessage(int arg) { + debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::timerFadeOutMessage(%d)", arg); if (_shownMessage) _msgUnk1 = 1; } @@ -78,16 +78,16 @@ void KyraEngine_v2::timerFunc5(int arg) { updateSceneAnim(4, i); delay(6); } - //_unk1 = 4; + _deathHandler = 4; } -void KyraEngine_v2::timerFunc6(int arg) { - debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::timerFunc6(%d)", arg); +void KyraEngine_v2::timerBurnZanthia(int arg) { + debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::timerBurnZanthia(%d)", arg); _timer->disable(5); - _screen->hideMouse(); + //_screen->hideMouse(); snd_playSoundEffect(0x2D); runTemporaryScript("_ZANBURN.EMC", 0, 1, 1, 0); - //_unk1 = 7; + _deathHandler = 7; snd_playWanderScoreViaMap(0x53, 1); } -- cgit v1.2.3