diff options
-rw-r--r-- | kyra/kyra.cpp | 355 | ||||
-rw-r--r-- | kyra/kyra.h | 20 | ||||
-rw-r--r-- | kyra/screen.cpp | 57 | ||||
-rw-r--r-- | kyra/screen.h | 3 | ||||
-rw-r--r-- | kyra/script_v1.cpp | 234 | ||||
-rw-r--r-- | kyra/sprites.cpp | 23 | ||||
-rw-r--r-- | kyra/sprites.h | 3 | ||||
-rw-r--r-- | kyra/staticres.cpp | 2 | ||||
-rw-r--r-- | kyra/wsamovie.cpp | 3 |
9 files changed, 556 insertions, 144 deletions
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index 2f864f9ec2..feee9bb32b 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -337,6 +337,10 @@ int KyraEngine::init(GameDetector &detector) { _movFacingTable[0] = 8; _configTalkspeed = 1; + + _marbleVaseItem = -1; + _mouseState = _itemInHand = -1; + _handleInput = false; return 0; } @@ -490,10 +494,6 @@ void KyraEngine::delay(uint32 amount) { case OSystem::EVENT_KEYDOWN: if (event.kbd.keycode == 'q' || event.kbd.keycode == 27) { _quitFlag = true; - } else { - ++_currentRoom; - if (_currentRoom > ARRAYSIZE(_shapes)) - _currentRoom = 3; } break; case OSystem::EVENT_MOUSEMOVE: @@ -503,6 +503,15 @@ void KyraEngine::delay(uint32 amount) { case OSystem::EVENT_QUIT: quitGame(); break; + case OSystem::EVENT_LBUTTONDOWN: + if (_handleInput) { + _mouseX = event.mouse.x; + _mouseY = event.mouse.y; + _handleInput = false; + processInput(_mouseX, _mouseY); + _handleInput = true; + } + break; default: break; } @@ -526,9 +535,15 @@ void KyraEngine::mainLoop() { while (!_quitFlag) { int32 frameTime = (int32)_system->getMillis(); + updateMousePointer(); updateGameTimers(); + _sprites->updateSceneAnims(); + updateAllObjectShapes(); + // XXX call processPalette + _handleInput = true; delay((frameTime + _gameSpeed) - _system->getMillis()); + _handleInput = false; } } @@ -1223,28 +1238,37 @@ void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypo disableTimer(19); disableTimer(14); disableTimer(18); + uint32 nextFrame = 0; switch (facing) { case 0: while (ypos < ch->y1) { + nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); setCharacterPositionWithUpdate(character); + while (_system->getMillis() < nextFrame) { updateGameTimers(); } } break; case 2: while (ch->x1 < xpos) { + nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); setCharacterPositionWithUpdate(character); + while (_system->getMillis() < nextFrame) { updateGameTimers(); } } break; case 4: while (ypos > ch->y1) { + nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); setCharacterPositionWithUpdate(character); + while (_system->getMillis() < nextFrame) { updateGameTimers(); } } break; case 6: while (ch->x1 > xpos) { + nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); setCharacterPositionWithUpdate(character); + while (_system->getMillis() < nextFrame) { updateGameTimers(); } } break; @@ -1659,8 +1683,7 @@ void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { moveCharacterToPos(0, facing, xpos2, ypos2); } - // XXX _mousePointerFlag - _scriptClick->variables[4] = -1; + _scriptClick->variables[4] = _itemInHand; _scriptClick->variables[7] = brandonAlive; _scriptInterpreter->startScript(_scriptClick, 3); while (_scriptInterpreter->validScript(_scriptClick)) { @@ -2513,6 +2536,58 @@ void KyraEngine::placeItemInGenericMapScene(int item, int index) { } } +void KyraEngine::createMouseItem(int item) { + debug(9, "createMouseItem(%d)", item); + _screen->hideMouse(); + setMouseItem(item); + _itemInHand = item; + _screen->showMouse(); +} + +void KyraEngine::destroyMouseItem() { + debug(9, "destroyMouseItem()"); + _screen->hideMouse(); + _screen->setMouseCursor(1, 1, _shapes[4]); + _itemInHand = -1; + _screen->showMouse(); +} + +void KyraEngine::setMouseItem(int item) { + debug(9, "setMouseItem(%d)", item); + if (item == -1) { + _screen->setMouseCursor(1, 1, _shapes[10]); + } else { + _screen->setMouseCursor(8, 15, _shapes[220+item]); + } +} + +void KyraEngine::wipeDownMouseItem(int xpos, int ypos) { + debug(9, "wipeDownMouseItem(%d, %d)", xpos, ypos); + if (_itemInHand == -1) + return; + xpos -= 8; + ypos -= 15; + _screen->hideMouse(); + backUpRect1(xpos, ypos); + int y = ypos; + int height = 16; + + while (height >= 0) { + restoreRect1(xpos, ypos); + _screen->setNewShapeHeight(_shapes[220+_itemInHand], height); + _screen->drawShape(0, _shapes[220+_itemInHand], xpos, y, 0, 0); + _screen->updateScreen(); + y += 2; + height -= 2; + // XXX + waitTicks(1); + } + restoreRect1(xpos, ypos); + _screen->resetShapeHeight(_shapes[220+_itemInHand]); + destroyMouseItem(); + _screen->showMouse(); +} + #pragma mark - #pragma mark - Animation specific code #pragma mark - @@ -2634,14 +2709,13 @@ void KyraEngine::prepDrawAllObjects() { int xpos = curObject->x1; int ypos = curObject->y1; - int temp = 0; - if (curObject->flags & 0x800) { - temp = 7; - } else if (!curObject->unk1) { - temp = 0; + int drawLayer = 0; + if (!(curObject->flags & 0x800)) { + drawLayer = 7; + } else if (curObject->unk1) { + drawLayer = 0; } else { - // XXX temp = sub_13368(curObject->drawY) - temp = 0; + drawLayer = _sprites->getDrawLayer(curObject->drawY); } // talking head functionallity @@ -2714,7 +2788,7 @@ void KyraEngine::prepDrawAllObjects() { tempFlags = 1; } tempFlags |= 0x900 | flagUnk1 | 0x4000; - _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 4, _unkBrandonPoisonFlags, 1, 0/*XXX*/, temp, _brandonScaleX, _brandonScaleY); + _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 4, _unkBrandonPoisonFlags, 1, 0/*XXX*/, drawLayer, _brandonScaleX, _brandonScaleY); } else { if (!(flagUnk2 & 0x4000)) { tempFlags = 0; @@ -2724,7 +2798,7 @@ void KyraEngine::prepDrawAllObjects() { tempFlags |= 0x900 | flagUnk1; } - _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 4, _unkBrandonPoisonFlags, 1, temp, _brandonScaleX, _brandonScaleY); + _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 4, _unkBrandonPoisonFlags, 1, drawLayer, _brandonScaleX, _brandonScaleY); } } } else { @@ -2733,7 +2807,7 @@ void KyraEngine::prepDrawAllObjects() { if (curObject->flags & 1) { tempFlags = 1; } - _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 0x800, temp); + _screen->drawShape(drawPage, _shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 0x800, drawLayer); } } } @@ -2756,30 +2830,30 @@ void KyraEngine::prepDrawAllObjects() { if (!_scaleMode) { if (flagUnk3 & 0x100) { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x100, (uint8*)_unkBrandonPoisonFlags, 1, temp); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x100, (uint8*)_unkBrandonPoisonFlags, 1, drawLayer); } else if (flagUnk3 & 0x4000) { // XXX int hackVar = 0; - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4000, hackVar, 0); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4000, hackVar, drawLayer); } else { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1, temp); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1, drawLayer); } } else { if (flagUnk3 & 0x100) { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x104, (uint8*)_unkBrandonPoisonFlags, 1, temp, _brandonScaleX, _brandonScaleY); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x104, (uint8*)_unkBrandonPoisonFlags, 1, drawLayer, _brandonScaleX, _brandonScaleY); } else if (flagUnk3 & 0x4000) { // XXX int hackVar = 0; - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4004, 0, temp, hackVar, _brandonScaleX, _brandonScaleY); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4004, 0, drawLayer, hackVar, _brandonScaleX, _brandonScaleY); } else { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4, temp, _brandonScaleX, _brandonScaleY); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4, drawLayer, _brandonScaleX, _brandonScaleY); } } } else { if (curObject->index >= 16 && curObject->index <= 27) { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | 4, temp, (int)_scaleTable[curObject->drawY], (int)_scaleTable[curObject->drawY]); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | 4, drawLayer, (int)_scaleTable[curObject->drawY], (int)_scaleTable[curObject->drawY]); } else { - _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags, temp); + _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags, drawLayer); } } } @@ -2976,6 +3050,16 @@ int8 KyraEngine::fetchAnimHeight(const uint8 *shape, int8 mult) { return ((int8)*(shape+2)) * mult; } +void KyraEngine::backUpRect1(int xpos, int ypos) { + debug(9, "backUpRect1(%d, %d)", xpos, ypos); + _screen->copyRegionToBuffer(_screen->_curPage, xpos, ypos, 4<<3, 32, _shapes[1]); +} + +void KyraEngine::restoreRect1(int xpos, int ypos) { + debug(9, "restoreRect1(%d, %d)", xpos, ypos); + _screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 4<<3, 32, _shapes[1]); +} + #pragma mark - #pragma mark - Pathfinder #pragma mark - @@ -3272,6 +3356,7 @@ bool KyraEngine::lineIsPassable(int x, int y) { } int KyraEngine::getMoveTableSize(int *moveTable) { + debug(9, "getMoveTableSize(0x%X)", moveTable); int retValue = 0; if (moveTable[0] == 8) return 0; @@ -3295,7 +3380,7 @@ int KyraEngine::getMoveTableSize(int *moveTable) { int *curPosition = &moveTable[1]; while (*curPosition != 8) { - if (*curPosition == facingTable[*oldPosition]) { + if (*oldPosition == facingTable[*curPosition]) { retValue -= 2; *oldPosition = 9; *curPosition = 9; @@ -3307,7 +3392,7 @@ int KyraEngine::getMoveTableSize(int *moveTable) { } if (tempPosition == moveTable && *tempPosition == 9) { - while (*tempPosition == 8 || *tempPosition != 9) { + while (*tempPosition != 8 && *tempPosition == 9) { ++tempPosition; } if (*tempPosition == 8) { @@ -3315,14 +3400,17 @@ int KyraEngine::getMoveTableSize(int *moveTable) { } } - while (*curPosition == 8 || *curPosition != 9) { + oldPosition = tempPosition; + curPosition = oldPosition+1; + while (*curPosition != 8 && *curPosition == 9) { ++curPosition; } + continue; } - if (unkTable[*curPosition+(*oldPosition*8)] != -1) { + if (unkTable[*curPosition+((*oldPosition)*8)] != -1) { --retValue; - *oldPosition = unkTable[*curPosition+(*oldPosition*8)]; + *oldPosition = unkTable[*curPosition+((*oldPosition)*8)]; *curPosition = 9; if (tempPosition != oldPosition) { @@ -3427,6 +3515,7 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { _loopFlag2 = 0; bool running = true; int returnValue = 0; + uint32 nextFrame; while (running) { // XXX bool forceContinue = false; @@ -3455,6 +3544,7 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { if (unk1) { // XXX + _sceneChangeState = 1; } if (forceContinue || !running) { @@ -3467,19 +3557,25 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { } else { temp = setCharacterPosition(0, table); } - if (!temp) + if (!temp) { continue; + } + ++table; - _sprites->updateSceneAnims(); - waitTicks(10); - // XXX updateMousePointer - updateGameTimers(); - updateAllObjectShapes(); - // XXX processPalette - if (_currentCharacter->sceneId == 210) { - // XXX updateKyragemFading - // XXX playEnd - // XXX + nextFrame = getTimerDelay(5) * _tickLength + _system->getMillis(); + while (_system->getMillis() < nextFrame) { + _sprites->updateSceneAnims(); + updateMousePointer(); + updateGameTimers(); + updateAllObjectShapes(); + // XXX processPalette + if (_currentCharacter->sceneId == 210) { + // XXX updateKyragemFading + // XXX playEnd + // XXX + } + if ((nextFrame - _system->getMillis()) >= 10) + delay(10); } } @@ -3664,7 +3760,17 @@ void KyraEngine::setupTimers() { _timers[31].countdown = -1; _timers[32].countdown = 9; _timers[33].countdown = 3; +} +void KyraEngine::setTimer19() { + debug(9, "KyraEngine::setTimer19()"); + if (_brandonStatusBit & 2) { + // XXX call sub_3F9C + setTimerCountdown(19, 300); + } else if (_brandonStatusBit & 0x20) { + // XXX call sub_4110 + setTimerCountdown(19, 300); + } } void KyraEngine::updateGameTimers() { @@ -3833,4 +3939,173 @@ void KyraEngine::drawAmulet() { _screen->showMouse(); } +#pragma mark - +#pragma mark - Input +#pragma mark - + +void KyraEngine::processInput(int xpos, int ypos) { + debug(9, "processInput(%d, %d)", xpos, ypos); + if (processInputHelper(xpos, ypos)) { + return; + } + uint8 item = findItemAtPos(xpos, ypos); + if (item == 0xFF) { + if (clickEventHandler(xpos, ypos)) + 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) { + handleSceneChange(xpos, ypos, 1, 1); + return; + } + } + + +} + +int KyraEngine::processInputHelper(int xpos, int ypos) { + debug(9, "processInputHelper(%d, %d)", xpos, ypos); + return 0; +} + +int KyraEngine::clickEventHandler(int xpos, int ypos) { + debug(9, "clickEventHandler(%d, %d)", xpos, ypos); + _scriptInterpreter->initScript(_scriptClick, _scriptClickData); + _scriptClick->variables[1] = xpos; + _scriptClick->variables[2] = ypos; + _scriptClick->variables[3] = 0; + _scriptClick->variables[4] = _itemInHand; + _scriptInterpreter->startScript(_scriptClick, 1); + + while (_scriptInterpreter->validScript(_scriptClick)) { + _scriptInterpreter->runScript(_scriptClick); + } + return _scriptClick->variables[3]; +} + +void KyraEngine::updateMousePointer() { + int shape = 0; + + int newMouseState = 0; + int newX = 0; // si + int newY = 0; // bx + if (_mouseY <= 158) { + if (_mouseX >= 12) { + if (_mouseX >= 308) { + if (_walkBlockEast == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -5; + shape = 3; + newX = 7; + newY = 5; + } + } else if (_mouseY >= 136) { + if (_walkBlockSouth == 0xFFFF) { + newMouseState = -2; + } else { + newMouseState = -4; + shape = 4; + newX = 5; + newY = 7; + } + } else if (_mouseY < 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 (_mouseX >= _entranceMouseCursorTracks[0] && _mouseY >= _entranceMouseCursorTracks[1] + && _mouseX <= _entranceMouseCursorTracks[2] && _mouseY <= _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) { + _mouseState = newMouseState; + _screen->hideMouse(); + _screen->setMouseCursor(newX, newY, _shapes[4+shape]); + _screen->showMouse(); + } + + if (!newMouseState) { + if (_mouseState != _itemInHand) { + if (_mouseY > 158 || (_mouseX >= 12 && _mouseX < 308 && _mouseY < 136 && _mouseY >= 12)) { + _mouseState = _itemInHand; + _screen->hideMouse(); + if (_itemInHand == -1) { + _screen->setMouseCursor(1, 1, _shapes[4]); + } else { + _screen->setMouseCursor(8, 15, _shapes[220+_itemInHand]); + } + _screen->showMouse(); + } + } + } +} + } // End of namespace Kyra diff --git a/kyra/kyra.h b/kyra/kyra.h index 738f13330c..ba1c69e323 100644 --- a/kyra/kyra.h +++ b/kyra/kyra.h @@ -285,7 +285,7 @@ public: int cmd_getCharacterX(ScriptState *script); int cmd_getCharacterY(ScriptState *script); int cmd_changeCharactersFacing(ScriptState *script); - int cmd_CopyWSARegion(ScriptState *script); + int cmd_copyWSARegion(ScriptState *script); int cmd_printText(ScriptState *script); int cmd_random(ScriptState *script); int cmd_loadSoundFile(ScriptState *script); @@ -449,6 +449,17 @@ protected: int handleSceneChange(int xpos, int ypos, int unk1, int frameReset); int processSceneChange(int *table, int unk1, int frameReset); int changeScene(int facing); + void createMouseItem(int item); + void destroyMouseItem(); + void setMouseItem(int item); + void wipeDownMouseItem(int xpos, int ypos); + void backUpRect1(int xpos, int ypos); + void restoreRect1(int xpos, int ypos); + + void processInput(int xpos, int ypos); + int processInputHelper(int xpos, int ypos); + int clickEventHandler(int xpos, int ypos); + void updateMousePointer(); AnimObject *objectRemoveQueue(AnimObject *queue, AnimObject *rem); AnimObject *objectAddHead(AnimObject *queue, AnimObject *head); @@ -496,6 +507,7 @@ protected: void resetBrandonPosionFlags(); void initAnimStateList(); + void setTimer19(); void setupTimers(); void timerUpdateHeadAnims(int timerNum); void timerSetFlags1(int timerNum); @@ -523,7 +535,9 @@ protected: uint16 _tickLength; uint32 _features; int _mouseX, _mouseY; - bool _needMouseUpdate; + int _itemInHand; + int _mouseState; + bool _handleInput; WSAMovieV1 *_wsaObjects[10]; uint16 _entranceMouseCursorTracks[8]; @@ -540,7 +554,7 @@ protected: uint16 _birthstoneGemTable[4]; uint8 _idolGemsTable[3]; - uint16 _marbleVaseItem; + int16 _marbleVaseItem; uint16 _brandonStatusBit; uint8 _unkBrandonPoisonFlags[256]; // this seem not to be posion flags, it is used for drawing once diff --git a/kyra/screen.cpp b/kyra/screen.cpp index 4ed0db1a83..e28f178712 100644 --- a/kyra/screen.cpp +++ b/kyra/screen.cpp @@ -62,6 +62,7 @@ Screen::Screen(KyraEngine *vm, OSystem *system) _decodeShapeBufferSize = 0; _animBlockPtr = NULL; _animBlockSize = 0; + _mouseLockCount = 0; } Screen::~Screen() { @@ -580,7 +581,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 *table = 0; int tableLoopCount = 0; - int var_30 = 0; + int drawLayer = 0; uint8 *table2 = 0; uint8 *table3 = 0; uint8 *table4 = 0; @@ -609,7 +610,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int drawShapeVar5 = va_arg(args, int); } if (flags & 0x800) { - var_30 = va_arg(args, int); + drawLayer = va_arg(args, int); } int scale_w, scale_h; if (flags & DSF_SCALE) { @@ -740,7 +741,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int } uint8 *dst = getPagePtr(pageNum) + y * SCREEN_W + x; - uint8 *dstStart = getPagePtr(pageNum) + y * SCREEN_W + x; + uint8 *dstStart = getPagePtr(pageNum); int scaleYTable[SCREEN_H]; assert(y1 >= 0 && y2 < SCREEN_H); @@ -834,7 +835,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } } break; @@ -844,7 +845,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } else { for (int i = 0; i < tableLoopCount; ++i) { @@ -858,7 +859,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); drawShapeVar4 = pixel; } else { @@ -878,7 +879,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } else { color = *dst; @@ -893,7 +894,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } else { color = table2[color]; @@ -905,7 +906,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } else { color = table2[color]; @@ -920,7 +921,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); drawShapeVar4 = pixel; } else { @@ -1035,7 +1036,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (var_30 < pixel) { + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } uint8 newColor = table3[color]; @@ -1584,16 +1585,15 @@ int Screen::getRectSize(int x, int y) { void Screen::hideMouse() { debug(9, "hideMouse()"); - // if mouseDisabled - // return + ++_mouseLockCount; _system->showMouse(false); } void Screen::showMouse() { debug(9, "showMouse()"); - // if mouseDisabled - // return - _system->showMouse(true); + if (--_mouseLockCount == 0) { + _system->showMouse(true); + } } void Screen::setShapePages(int page1, int page2) { @@ -1616,10 +1616,11 @@ void Screen::setMouseCursor(int x, int y, byte *shape) { int mouseWidth = (READ_LE_UINT16(shape + 3)) + 2; uint8 *cursor = (uint8 *)malloc(mouseHeight * mouseWidth); - fillRect(0, 0, mouseWidth, mouseHeight, 0, 3); - drawShape(3, shape, 0, 0, 0, 0); + fillRect(0, 0, mouseWidth, mouseHeight, 0, 8); + drawShape(8, shape, 0, 0, 0, 0); - copyRegionToBuffer(3, 0, 0, mouseWidth, mouseHeight, cursor); + _system->showMouse(false); + copyRegionToBuffer(8, 0, 0, mouseWidth, mouseHeight, cursor); _system->setMouseCursor(cursor, mouseWidth, mouseHeight, 0, 0, 0); _system->showMouse(true); free(cursor); @@ -1674,4 +1675,22 @@ byte Screen::getShapeFlag1(int x, int y) { return 0; } +int Screen::setNewShapeHeight(uint8 *shape, int height) { + debug(9, "setNewShapeHeight(0x%X, %d)", shape, height); + if (_vm->features() & GF_TALKIE) + shape += 2; + int oldHeight = shape[2]; + shape[2] = height; + return oldHeight; +} + +int Screen::resetShapeHeight(uint8 *shape) { + debug(9, "setNewShapeHeight(0x%X)", shape); + if (_vm->features() & GF_TALKIE) + shape += 2; + int oldHeight = shape[2]; + shape[2] = shape[5]; + return oldHeight; +} + } // End of namespace Kyra diff --git a/kyra/screen.h b/kyra/screen.h index 1933382fa7..576e7d636c 100644 --- a/kyra/screen.h +++ b/kyra/screen.h @@ -127,6 +127,8 @@ public: uint8 *getPalette(int num); byte getShapeFlag1(int x, int y); + int setNewShapeHeight(uint8 *shape, int height); + int resetShapeHeight(uint8 *shape); int _charWidth; int _charOffset; @@ -152,6 +154,7 @@ private: int _decodeShapeBufferSize; uint8 *_animBlockPtr; int _animBlockSize; + int _mouseLockCount; OSystem *_system; KyraEngine *_vm; diff --git a/kyra/script_v1.cpp b/kyra/script_v1.cpp index 65c41eb850..682158e068 100644 --- a/kyra/script_v1.cpp +++ b/kyra/script_v1.cpp @@ -133,9 +133,9 @@ void ScriptHelper::c1_negate() { switch (_parameter) { case 0: if (!value) { - _curScript->stack[_curScript->sp] = 0; - } else { _curScript->stack[_curScript->sp] = 1; + } else { + _curScript->stack[_curScript->sp] = 0; } break; @@ -304,7 +304,7 @@ int KyraEngine::cmd_magicInMouseItem(ScriptState *script) { } int KyraEngine::cmd_characterSays(ScriptState *script) { - debug(9, "cmd_characterSays(0x%X)", script); + debug(3, "cmd_characterSays(0x%X) ('%s', %d, %d)", script, stackPosString(0), stackPos(1), stackPos(2)); // Japanese version? /*const char *str1 = "âuâëâôââôüAé?é¢ùêé¢é+é®üH"; const char *str2 = "âuâëâôâ\\âôüAé?é¢ùêé¢é+é®üH"; @@ -323,23 +323,23 @@ int KyraEngine::cmd_pauseTicks(ScriptState *script) { } int KyraEngine::cmd_drawSceneAnimShape(ScriptState *script) { - debug(9, "cmd_drawSceneAnimShape(0x%X)", script); + debug(3, "cmd_drawSceneAnimShape(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); _screen->drawShape(stackPos(4), _sprites->_sceneShapes[stackPos(0)], stackPos(1), stackPos(2), 0, stackPos(3)); return 0; } int KyraEngine::cmd_queryGameFlag(ScriptState *script) { - debug(9, "cmd_queryGameFlag(0x%X)", script); + debug(3, "cmd_queryGameFlag(0x%X) (0x%X)", script, stackPos(0)); return queryGameFlag(stackPos(0)); } int KyraEngine::cmd_setGameFlag(ScriptState *script) { - debug(9, "cmd_setGameFlag(0x%X)", script); + debug(3, "cmd_setGameFlag(0x%X) (0x%X)", script, stackPos(0)); return setGameFlag(stackPos(0)); } int KyraEngine::cmd_resetGameFlag(ScriptState *script) { - debug(9, "cmd_resetGameFlag(0x%X)", script); + debug(3, "cmd_resetGameFlag(0x%X) (0x%X)", script, stackPos(0)); return resetGameFlag(stackPos(0)); } @@ -349,7 +349,7 @@ int KyraEngine::cmd_runNPCScript(ScriptState *script) { } int KyraEngine::cmd_setSpecialExitList(ScriptState *script) { - debug(9, "cmd_setSpecialExitList(0x%X)", script); + debug(3, "cmd_setSpecialExitList(0x%X) (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7), stackPos(8), stackPos(9)); for (int i = 0; i < 10; ++i) { _exitList[i] = stackPos(i); @@ -360,19 +360,19 @@ int KyraEngine::cmd_setSpecialExitList(ScriptState *script) { } int KyraEngine::cmd_blockInWalkableRegion(ScriptState *script) { - debug(9, "cmd_blockInWalkableRegion(0x%X)", script); + debug(3, "cmd_blockInWalkableRegion(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); blockInRegion(stackPos(0), stackPos(1), stackPos(2)-stackPos(0)+1, stackPos(3)-stackPos(1)+1); return 0; } int KyraEngine::cmd_blockOutWalkableRegion(ScriptState *script) { - debug(9, "cmd_blockOutWalkableRegion(0x%X)", script); + debug(9, "cmd_blockOutWalkableRegion(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); blockOutRegion(stackPos(0), stackPos(1), stackPos(2)-stackPos(0)+1, stackPos(3)-stackPos(1)+1); return 0; } int KyraEngine::cmd_walkPlayerToPoint(ScriptState *script) { - debug(9, "cmd_walkPlayerToPoint(0x%X)", script); + debug(3, "cmd_walkPlayerToPoint(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); if (!stackPos(2)) { disableTimer(19); @@ -395,7 +395,7 @@ int KyraEngine::cmd_walkPlayerToPoint(ScriptState *script) { } int KyraEngine::cmd_dropItemInScene(ScriptState *script) { - debug(9, "cmd_dropItemInScene(0x%X)", script); + debug(3, "cmd_dropItemInScene(0x%X) (%d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2)); int item = stackPos(0); int xpos = stackPos(1); int ypos = stackPos(2); @@ -422,12 +422,26 @@ int KyraEngine::cmd_dropItemInScene(ScriptState *script) { } int KyraEngine::cmd_drawAnimShapeIntoScene(ScriptState *script) { - warning("STUB: cmd_drawAnimShapeIntoScene"); + debug(3, "cmd_drawAnimShapeIntoScene(0x%X) (%d, %d, %d, %d)", stackPos(0), stackPos(1), stackPos(2), stackPos(3)); + _screen->hideMouse(); + restoreAllObjectBackgrounds(); + int shape = stackPos(0); + int xpos = stackPos(1); + int ypos = stackPos(2); + int flags = (stackPos(3) != 0) ? 1 : 0; + _screen->drawShape(2, _sprites->_sceneShapes[shape], xpos, ypos, 0, flags); + _screen->drawShape(0, _sprites->_sceneShapes[shape], xpos, ypos, 0, flags); + flagAllObjectsForBkgdChange(); + preserveAnyChangedBackgrounds(); + flagAllObjectsForRefresh(); + updateAllObjectShapes(); + _screen->showMouse(); return 0; } int KyraEngine::cmd_createMouseItem(ScriptState *script) { - warning("STUB: cmd_createMouseItem"); + debug(3, "cmd_createMouseItem(0x%X) (%d)", stackPos(0)); + createMouseItem(stackPos(0)); return 0; } @@ -437,13 +451,13 @@ int KyraEngine::cmd_savePageToDisk(ScriptState *script) { } int KyraEngine::cmd_sceneAnimOn(ScriptState *script) { - debug(9, "cmd_sceneAnimOn(0x%X)", script); + debug(3, "cmd_sceneAnimOn(0x%X) (%d)", script, stackPos(0)); _sprites->_anims[stackPos(0)].play = true; return 0; } int KyraEngine::cmd_sceneAnimOff(ScriptState *script) { - debug(9, "cmd_sceneAnimOff(0x%X)", script); + debug(3, "cmd_sceneAnimOff(0x%X) (%d)", script, stackPos(0)); _sprites->_anims[stackPos(0)].play = false; return 0; } @@ -454,12 +468,16 @@ int KyraEngine::cmd_getElapsedSeconds(ScriptState *script) { } int KyraEngine::cmd_mouseIsPointer(ScriptState *script) { - warning("STUB: cmd_mouseIsPointer"); + debug(3, "cmd_mouseIsPointer(0x%X) ()", script); + if (_itemInHand == -1) { + return 1; + } return 0; } int KyraEngine::cmd_destroyMouseItem(ScriptState *script) { - warning("STUB: cmd_destroyMouseItem"); + debug(3, "cmd_destroyMouseItem(0x%X) ()", script); + destroyMouseItem(); return 0; } @@ -509,7 +527,7 @@ int KyraEngine::cmd_sceneToDirection(ScriptState *script) { } int KyraEngine::cmd_setBirthstoneGem(ScriptState *script) { - debug(9, "cmd_setBirthstoneGem(0x%X)", script); + debug(3, "cmd_setBirthstoneGem(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); int index = stackPos(0); if (index < 4 && index >= 0) { _birthstoneGemTable[index] = stackPos(1); @@ -519,7 +537,7 @@ int KyraEngine::cmd_setBirthstoneGem(ScriptState *script) { } int KyraEngine::cmd_placeItemInGenericMapScene(ScriptState *script) { - debug(9, "cmd_placeItemInGenericMapScene(0x%X)", script); + debug(3, "cmd_placeItemInGenericMapScene(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); placeItemInGenericMapScene(stackPos(0), stackPos(1)); return 0; } @@ -530,7 +548,7 @@ int KyraEngine::cmd_setBrandonStatusBit(ScriptState *script) { } int KyraEngine::cmd_pauseSeconds(ScriptState *script) { - debug(9, "cmd_pauseSeconds(0x%X)", script); + debug(3, "cmd_pauseSeconds(0x%X) (%d)", script, stackPos(0)); delay(stackPos(0)*1000); return 0; } @@ -551,13 +569,14 @@ int KyraEngine::cmd_magicOutMouseItem(ScriptState *script) { } int KyraEngine::cmd_internalAnimOn(ScriptState *script) { - debug(9, "cmd_internalAnimOn(0x%X)", script); + debug(3, "cmd_internalAnimOn(0x%X) (%d)", script, stackPos(0)); _sprites->_animObjects[stackPos(0)].active = 1; return 0; } int KyraEngine::cmd_forceBrandonToNormal(ScriptState *script) { - warning("STUB: cmd_forceBrandonToNormal"); + debug(3, "cmd_forceBrandonToNormal(0x%X) ()", script); + setTimer19(); return 0; } @@ -572,26 +591,19 @@ int KyraEngine::cmd_setScaleMode(ScriptState *script) { } int KyraEngine::cmd_openWSAFile(ScriptState *script) { - debug(9, "cmd_openWSAFile(0x%X)", script); + debug(3, "cmd_openWSAFile(0x%X) ('%s', %d)", script, stackPosString(0), stackPos(1)); char *filename = stackPosString(0); int wsaIndex = stackPos(1); - // stackPos(2) is NOT used whyever - int offscreenDecode = 0; - if (!stackPos(3)) { - offscreenDecode = 1; - } else { - offscreenDecode = 0; - } - _wsaObjects[wsaIndex] = wsa_open(filename, offscreenDecode, 0); + _wsaObjects[wsaIndex] = wsa_open(filename, 1, 0); assert(_wsaObjects[wsaIndex]); return 0; } int KyraEngine::cmd_closeWSAFile(ScriptState *script) { - debug(9, "cmd_closeWSAFile(0x%X)", script); + debug(3, "cmd_closeWSAFile(0x%X) (%d)", script, stackPos(0)); int wsaIndex = stackPos(0); if (_wsaObjects[wsaIndex]) { @@ -603,7 +615,7 @@ int KyraEngine::cmd_closeWSAFile(ScriptState *script) { } int KyraEngine::cmd_runWSAFromBeginningToEnd(ScriptState *script) { - debug(9, "cmd_runWSAFromBeginningToEnd(0x%X)", script); + debug(3, "cmd_runWSAFromBeginningToEnd(0x%X) (%d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); _screen->hideMouse(); @@ -620,13 +632,13 @@ int KyraEngine::cmd_runWSAFromBeginningToEnd(ScriptState *script) { wsa_play(_wsaObjects[wsaIndex], wsaFrame++, xpos, ypos, 0); if (wsaFrame >= wsa_getNumFrames(_wsaObjects[wsaIndex])) running = false; - + waitTicks(waitTime); - _screen->updateScreen(); if (worldUpdate) { + _sprites->updateSceneAnims(); updateAllObjectShapes(); - // XXX } + _screen->updateScreen(); } _screen->showMouse(); @@ -635,18 +647,30 @@ int KyraEngine::cmd_runWSAFromBeginningToEnd(ScriptState *script) { } int KyraEngine::cmd_displayWSAFrame(ScriptState *script) { - warning("STUB: cmd_displayWSAFrame"); + debug(3, "cmd_displayWSAFrame(0x%X) (%d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); + int frame = stackPos(0); + int xpos = stackPos(1); + int ypos = stackPos(2); + int waitTime = stackPos(3); + int wsaIndex = stackPos(4); + _screen->hideMouse(); + wsa_play(_wsaObjects[wsaIndex], frame, xpos, ypos, 0); + waitTicks(waitTime); + _sprites->updateSceneAnims(); + updateAllObjectShapes(); + _screen->updateScreen(); + _screen->showMouse(); return 0; } int KyraEngine::cmd_enterNewScene(ScriptState *script) { - debug(9, "cmd_enterNewScene(0x%X)", script); + debug(3, "cmd_enterNewScene(0x%X) (%d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); enterNewScene(stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); return 0; } int KyraEngine::cmd_setSpecialEnterXAndY(ScriptState *script) { - debug(9, "cmd_setSpecialEnterXAndY(0x%X)", script); + debug(3, "cmd_setSpecialEnterXAndY(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); _brandonPosX = stackPos(0); _brandonPosY = stackPos(1); if (_brandonPosX + 1 == 0 && _brandonPosY + 1 == 0) @@ -660,7 +684,7 @@ int KyraEngine::cmd_runWSAFrames(ScriptState *script) { } int KyraEngine::cmd_popBrandonIntoScene(ScriptState *script) { - debug(9, "cmd_popBrandonIntoScene(0x%X)", script); + debug(3, "cmd_popBrandonIntoScene(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); int changeScaleMode = stackPos(3); int xpos = stackPos(0) & 0xFFFC; int ypos = stackPos(1) & 0xFFFE; @@ -710,7 +734,7 @@ int KyraEngine::cmd_popBrandonIntoScene(ScriptState *script) { } int KyraEngine::cmd_restoreAllObjectBackgrounds(ScriptState *script) { - debug(9, "cmd_restoreAllObjectBackgrounds(0x%X)", script); + debug(3, "cmd_restoreAllObjectBackgrounds(0x%X) ()", script); restoreAllObjectBackgrounds(); return 0; } @@ -726,39 +750,41 @@ int KyraEngine::cmd_loadPageFromDisk(ScriptState *script) { } int KyraEngine::cmd_customPrintTalkString(ScriptState *script) { - warning("STUB: cmd_customPrintTalkString"); + debug(3, "cmd_customPrintTalkString(0x%X) ('%s', %d, %d, %d)", script, stackPosString(0), stackPos(1), stackPos(2), stackPos(3) & 0xFF); + printTalkTextMessage(stackPosString(0), stackPos(1), stackPos(2), stackPos(3) & 0xFF, 0, 2); return 0; } int KyraEngine::cmd_restoreCustomPrintBackground(ScriptState *script) { - warning("STUB: cmd_restoreCustomPrintBackground"); + debug(3, "cmd_restoreCustomPrintBackground(0x%X) ()", script); + restoreTalkTextMessageBkgd(2, 0); return 0; } int KyraEngine::cmd_hideMouse(ScriptState *script) { - debug(9, "cmd_hideMouse(0x%X)", script); + debug(3, "cmd_hideMouse(0x%X) ()", script); _screen->hideMouse(); return 0; } int KyraEngine::cmd_showMouse(ScriptState *script) { - debug(9, "cmd_showMouse(0x%X)", script); + debug(3, "cmd_showMouse(0x%X) ()", script); _screen->showMouse(); return 0; } int KyraEngine::cmd_getCharacterX(ScriptState *script) { - debug(9, "cmd_getCharacterX(0x%X)", script); + debug(3, "cmd_getCharacterX(0x%X) (%d)", script, stackPos(0)); return _characterList[stackPos(0)].x1; } int KyraEngine::cmd_getCharacterY(ScriptState *script) { - debug(9, "cmd_getCharacterY(0x%X)", script); + debug(3, "cmd_getCharacterY(0x%X) (%d)", script, stackPos(0)); return _characterList[stackPos(0)].y1; } int KyraEngine::cmd_changeCharactersFacing(ScriptState *script) { - debug(9, "cmd_changeCharactersFacing(0x%X)", script); + debug(3, "cmd_changeCharactersFacing(0x%X) (%d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2)); int character = stackPos(0); int facing = stackPos(1); int newAnimFrame = stackPos(2); @@ -776,8 +802,15 @@ int KyraEngine::cmd_changeCharactersFacing(ScriptState *script) { return 0; } -int KyraEngine::cmd_CopyWSARegion(ScriptState *script) { - warning("STUB: cmd_CopyWSARegion"); +int KyraEngine::cmd_copyWSARegion(ScriptState *script) { + debug(3, "cmd_copyWSARegion(0x%X) (%d, %d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5)); + int xpos = stackPos(0); + int ypos = stackPos(1); + int width = stackPos(2); + int height = stackPos(3); + int srcPage = stackPos(4); + int dstPage = stackPos(5); + _screen->copyRegion(xpos, ypos, xpos, ypos, width, height, srcPage, dstPage, 0); return 0; } @@ -787,7 +820,7 @@ int KyraEngine::cmd_printText(ScriptState *script) { } int KyraEngine::cmd_random(ScriptState *script) { - debug(9, "cmd_random(0x%X)", script); + debug(3, "cmd_random(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); assert(stackPos(0) < stackPos(1)); return _rnd.getRandomNumberRng(stackPos(0), stackPos(1)); } @@ -803,12 +836,50 @@ int KyraEngine::cmd_displayWSAFrameOnHidPage(ScriptState *script) { } int KyraEngine::cmd_displayWSASequentialFrames(ScriptState *script) { - warning("STUB: cmd_displayWSASequentialFrames"); + debug(3, "cmd_displayWSASequentialFrames(0x%X) (%d, %d, %d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5), stackPos(6)); + int startFrame = stackPos(0); + int endFrame = stackPos(1); + int xpos = stackPos(2); + int ypos = stackPos(3); + int waitTime = stackPos(4); + int wsaIndex = stackPos(5); + int maxTime = stackPos(6); + if (maxTime - 1 <= 0) + maxTime = 1; + + int curTime = 0; + _screen->hideMouse(); + while (curTime < maxTime) { + if (endFrame >= startFrame) { + int frame = startFrame; + while (endFrame >= frame) { + wsa_play(_wsaObjects[wsaIndex], frame, xpos, ypos, 0); + // XXX + waitTicks(waitTime); + _sprites->updateSceneAnims(); + updateAllObjectShapes(); + ++frame; + } + } else { + int frame = endFrame; + while (startFrame <= frame) { + wsa_play(_wsaObjects[wsaIndex], frame, xpos, ypos, 0); + // XXX + waitTicks(waitTime); + _sprites->updateSceneAnims(); + updateAllObjectShapes(); + --frame; + } + } + ++curTime; + } + _screen->showMouse(); + return 0; } int KyraEngine::cmd_drawCharacterStanding(ScriptState *script) { - debug(9, "cmd_drawCharacterStanding(0x%X)", script); + debug(3, "cmd_drawCharacterStanding(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); int character = stackPos(0); int animFrame = stackPos(1); int newFacing = stackPos(2); @@ -825,7 +896,7 @@ int KyraEngine::cmd_drawCharacterStanding(ScriptState *script) { } int KyraEngine::cmd_internalAnimOff(ScriptState *script) { - debug(9, "cmd_internalAnimOff(0x%X)", script); + debug(3, "cmd_internalAnimOff(0x%X) (%d)", script, stackPos(0)); _sprites->_animObjects[stackPos(0)].active = 0; return 0; } @@ -851,7 +922,7 @@ int KyraEngine::cmd_refreshSceneAnimator(ScriptState *script) { } int KyraEngine::cmd_placeItemInOffScene(ScriptState *script) { - debug(9, "cmd_placeItemInOffScene(0x%X)", script); + debug(3, "cmd_placeItemInOffScene(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); int item = stackPos(0); int xpos = stackPos(1); int ypos = stackPos(2); @@ -870,12 +941,16 @@ int KyraEngine::cmd_placeItemInOffScene(ScriptState *script) { } int KyraEngine::cmd_wipeDownMouseItem(ScriptState *script) { - warning("STUB: cmd_wipeDownMouseItem"); + debug(3, "cmd_wipeDownMouseItem(0x%X) (%d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2)); + _screen->hideMouse(); + wipeDownMouseItem(stackPos(1), stackPos(2)); + destroyMouseItem(); + _screen->showMouse(); return 0; } int KyraEngine::cmd_placeCharacterInOtherScene(ScriptState *script) { - debug(9, "cmd_placeCharacterInOtherScene(0x%X)", script); + debug(3, "cmd_placeCharacterInOtherScene(0x%X) (%d, %d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5)); int id = stackPos(0); int sceneId = stackPos(1); int xpos = stackPos(2) & 0xFFFC; @@ -927,7 +1002,7 @@ int KyraEngine::cmd_setCharactersLocation(ScriptState *script) { } int KyraEngine::cmd_walkCharacterToPoint(ScriptState *script) { - debug(9, "cmd_walkCharacterToPoint(0x%X)", script); + debug(3, "cmd_walkCharacterToPoint(0x%X) (%d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2)); int character = stackPos(0); int toX = stackPos(1); int toY = stackPos(2); @@ -992,18 +1067,18 @@ int KyraEngine::cmd_walkCharacterToPoint(ScriptState *script) { continue; } - nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); setCharacterPosition(character, 0); ++curPos; + nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis(); while (_system->getMillis() < nextFrame) { _sprites->updateSceneAnims(); - // XXX updateMouseCursor(); + updateMousePointer(); updateGameTimers(); updateAllObjectShapes(); // XXX processPalette(); if ((nextFrame - _system->getMillis()) >= 10) - _system->delayMillis(10); + delay(10); } } return 0; @@ -1035,7 +1110,7 @@ int KyraEngine::cmd_preserveAllObjectBackgrounds(ScriptState *script) { } int KyraEngine::cmd_updateSceneAnimations(ScriptState *script) { - debug(9, "cmd_updateSceneAnimations(0x%X)", script); + debug(3, "cmd_updateSceneAnimations(0x%X) (%d)", script, stackPos(0)); if (stackPos(0)) { _sprites->updateSceneAnims(); updateAllObjectShapes(); @@ -1044,7 +1119,7 @@ int KyraEngine::cmd_updateSceneAnimations(ScriptState *script) { } int KyraEngine::cmd_sceneAnimationActive(ScriptState *script) { - debug(9, "cmd_sceneAnimationActive(0x%X)", script); + debug(3, "cmd_sceneAnimationActive(0x%X) (%d)", script, stackPos(0)); return _sprites->_anims[stackPos(0)].play; } @@ -1054,8 +1129,8 @@ int KyraEngine::cmd_setCharactersMovementDelay(ScriptState *script) { } int KyraEngine::cmd_getCharactersFacing(ScriptState *script) { - warning("STUB: cmd_getCharactersFacing"); - return 0; + debug(9, "cmd_getCharactersFacing(0x%X) (%d)", script, stackPos(0)); + return _characterList[stackPos(0)].facing; } int KyraEngine::cmd_bkgdScrollSceneAndMasksRight(ScriptState *script) { @@ -1119,12 +1194,12 @@ int KyraEngine::cmd_setSceneFile(ScriptState *script) { } int KyraEngine::cmd_getItemInMarbleVase(ScriptState *script) { - warning("STUB: cmd_getItemInMarbleVase"); - return 0; + debug(3, "cmd_getItemInMarbleVase(0x%X) ()", script); + return _marbleVaseItem; } int KyraEngine::cmd_setItemInMarbleVase(ScriptState *script) { - debug(9, "cmd_setItemInMarbleVase(0x%X)", script); + debug(3, "cmd_setItemInMarbleVase(0x%X) (%d)", script, stackPos(0)); _marbleVaseItem = stackPos(0); return 0; } @@ -1150,7 +1225,7 @@ int KyraEngine::cmd_createAmuletJewel(ScriptState *script) { } int KyraEngine::cmd_setSceneAnimCurrXY(ScriptState *script) { - debug(9, "cmd_setSceneAnimCurrXY(0x%X)", script); + debug(3, "cmd_setSceneAnimCurrXY(0x%X) (%d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2)); _sprites->_anims[stackPos(0)].x = stackPos(1); _sprites->_anims[stackPos(0)].y = stackPos(2); return 0; @@ -1197,7 +1272,7 @@ int KyraEngine::cmd_getIdolGem(ScriptState *script) { } int KyraEngine::cmd_setIdolGem(ScriptState *script) { - debug(9, "cmd_setIdolGem(0x%X)", script); + debug(3, "cmd_setIdolGem(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); _idolGemsTable[stackPos(0)] = stackPos(1); return 0; } @@ -1213,22 +1288,25 @@ int KyraEngine::cmd_restoreBrandonsMovementDelay(ScriptState *script) { } int KyraEngine::cmd_setMousePos(ScriptState *script) { - warning("STUB: cmd_setMousePos"); + debug(3, "cmd_setMousePos(0x%X) (%d, %d)", script, stackPos(0), stackPos(1)); + _system->warpMouse(stackPos(0), stackPos(1)); + _mouseX = stackPos(0); + _mouseY = stackPos(1); return 0; } int KyraEngine::cmd_getMouseState(ScriptState *script) { - warning("STUB: cmd_getMouseState"); - return 0; + debug(3, "cmd_getMouseState(0x%X) ()", script); + return _mouseState; } int KyraEngine::cmd_setEntranceMouseCursorTrack(ScriptState *script) { - debug(9, "cmd_setEntranceMouseCursorTrack(0x%X)", script); + debug(3, "cmd_setEntranceMouseCursorTrack(0x%X) (%d, %d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4)); _entranceMouseCursorTracks[0] = stackPos(0); _entranceMouseCursorTracks[1] = stackPos(1); _entranceMouseCursorTracks[2] = stackPos(0) + stackPos(2) - 1; _entranceMouseCursorTracks[3] = stackPos(1) + stackPos(3) - 1; - _entranceMouseCursorTracks[4] = stackPos(3); + _entranceMouseCursorTracks[4] = stackPos(4); return 0; } @@ -1329,7 +1407,7 @@ int KyraEngine::cmd_setFoyerItem(ScriptState *script) { } int KyraEngine::cmd_setNoItemDropRegion(ScriptState *script) { - debug(9, "cmd_setNoItemDropRegion(0x%X)", script); + debug(3, "cmd_setNoItemDropRegion(0x%X) (%d, %d, %d, %d)", script, stackPos(0), stackPos(1), stackPos(2), stackPos(3)); addToNoDropRects(stackPos(0), stackPos(1), stackPos(2), stackPos(3)); return 0; } @@ -1385,7 +1463,7 @@ int KyraEngine::cmd_fillRect(ScriptState *script) { } int KyraEngine::cmd_dummy(ScriptState *script) { - debug(9, "cmd_dummy(0x%X)", script); + debug(3, "cmd_dummy(0x%X) ()", script); return 0; } diff --git a/kyra/sprites.cpp b/kyra/sprites.cpp index be5b54ec25..046727d4f3 100644 --- a/kyra/sprites.cpp +++ b/kyra/sprites.cpp @@ -37,10 +37,10 @@ Sprites::Sprites(KyraEngine *engine, OSystem *system) { _system = system; _dat = 0; memset(_anims, 0, sizeof(_anims)); - memset( _sceneShapes, 0, sizeof(_sceneShapes)); + memset(_sceneShapes, 0, sizeof(_sceneShapes)); _animDelay = 16; _spriteDefStart = 0; - + memset(_drawLayerTable, 0, sizeof(_drawLayerTable)); } Sprites::~Sprites() { @@ -400,6 +400,7 @@ void Sprites::loadDAT(const char *filename, SceneExits &exits) { assert(fileSize > 0x6D); + memcpy(_drawLayerTable, (_dat + 0x0D), 8); _engine->_northExitHeight = READ_LE_UINT16(_dat + 0x15); if (_engine->_northExitHeight & 1) _engine->_northExitHeight += 1; @@ -541,4 +542,22 @@ void Sprites::refreshSceneAnimObject(uint8 animNum, uint8 shapeNum, uint16 x, ui _animObjects[animNum].y1 = y; } +int Sprites::getDrawLayer(int y) { + debug(9, "getDrawLayer(%d)", y); + uint8 returnValue = 0; + for (int i = 0; i < ARRAYSIZE(_drawLayerTable); ++i) { + uint8 temp = _drawLayerTable[i]; + if (temp) { + if (temp <= y) { + returnValue = i; + } + } + } + if (returnValue <= 0) { + returnValue = 1; + } else if (returnValue >= 7) { + returnValue = 6; + } + return returnValue; +} } // end of namespace Kyra diff --git a/kyra/sprites.h b/kyra/sprites.h index 8f4102e7eb..e559cdad5c 100644 --- a/kyra/sprites.h +++ b/kyra/sprites.h @@ -71,6 +71,8 @@ public: uint8 *_sceneShapes[50]; void refreshSceneAnimObject(uint8 animNum, uint8 shapeNum, uint16 x, uint16 y, bool flipX, bool unkFlag); + + int getDrawLayer(int y); protected: void freeSceneShapes(); @@ -83,6 +85,7 @@ protected: Common::RandomSource _rnd; uint8 _animDelay; uint8 *_spriteDefStart; + uint8 _drawLayerTable[8]; }; } // End of namespace Kyra diff --git a/kyra/staticres.cpp b/kyra/staticres.cpp index f52edc5ae5..c9c857f7e9 100644 --- a/kyra/staticres.cpp +++ b/kyra/staticres.cpp @@ -433,7 +433,7 @@ KyraEngine::OpcodeProc KyraEngine::_opcodeTable[] = { Opcode(cmd_getCharacterX), Opcode(cmd_getCharacterY), Opcode(cmd_changeCharactersFacing), - Opcode(cmd_CopyWSARegion), + Opcode(cmd_copyWSARegion), // 0x3c Opcode(cmd_printText), Opcode(cmd_random), diff --git a/kyra/wsamovie.cpp b/kyra/wsamovie.cpp index b3fa637df9..00ba6cec6c 100644 --- a/kyra/wsamovie.cpp +++ b/kyra/wsamovie.cpp @@ -124,7 +124,8 @@ uint16 KyraEngine::wsa_getNumFrames(WSAMovieV1 *wsa) const { void KyraEngine::wsa_play(WSAMovieV1 *wsa, int frameNum, int x, int y, int pageNum) { debug(9, "KyraEngine::wsa_play(0x%X, %d, %d, %d, %d)", wsa, frameNum, x, y, pageNum); - assert(frameNum <= wsa->numFrames); + if (frameNum > wsa->numFrames) + return; uint8 *dst; if (wsa->flags & WF_OFFSCREEN_DECODE) { |