diff options
author | Johannes Schickel | 2007-04-15 16:41:20 +0000 |
---|---|---|
committer | Johannes Schickel | 2007-04-15 16:41:20 +0000 |
commit | 21b2c7bceb5947e1eaa79890fe24f59def54aef9 (patch) | |
tree | d13d67e0c2c2db33651a51eb24679bac867a09d8 /engines/kyra | |
parent | e962db5b6d6856a31e52f7e3c4038a0f8f47e25d (diff) | |
download | scummvm-rg350-21b2c7bceb5947e1eaa79890fe24f59def54aef9.tar.gz scummvm-rg350-21b2c7bceb5947e1eaa79890fe24f59def54aef9.tar.bz2 scummvm-rg350-21b2c7bceb5947e1eaa79890fe24f59def54aef9.zip |
Formatting/Cleanup.
svn-id: r26511
Diffstat (limited to 'engines/kyra')
33 files changed, 962 insertions, 1089 deletions
diff --git a/engines/kyra/animator.cpp b/engines/kyra/animator.cpp index 322009bc8c..443287438d 100644 --- a/engines/kyra/animator.cpp +++ b/engines/kyra/animator.cpp @@ -196,19 +196,16 @@ void ScreenAnimator::preserveOrRestoreBackground(AnimObject *obj, bool restore) int temp; temp = x + width; - if (temp >= 39) { + if (temp >= 39) x = 39 - width; - } temp = y + height; - if (temp >= 136) { + if (temp >= 136) y = 136 - height; - } - if (restore) { + if (restore) _screen->copyBlockToPage(_screen->_curPage, x << 3, y, width << 3, height, obj->background); - } else { + else _screen->copyRegionToBuffer(_screen->_curPage, x << 3, y, width << 3, height, obj->background); - } } void ScreenAnimator::prepDrawAllObjects() { @@ -229,13 +226,12 @@ void ScreenAnimator::prepDrawAllObjects() { int ypos = curObject->y1; int drawLayer = 0; - if (!(curObject->flags & 0x800)) { + if (!(curObject->flags & 0x800)) drawLayer = 7; - } else if (curObject->disable) { + else if (curObject->disable) drawLayer = 0; - } else { + else drawLayer = _vm->_sprites->getDrawLayer(curObject->drawY); - } // talking head functionallity if (_vm->_talkingCharNum != -1 && (_vm->_currentCharacter->currentAnimFrame != 88 || curObject->index != 0)) { @@ -253,18 +249,16 @@ void ScreenAnimator::prepDrawAllObjects() { shapesIndex = baseAnimFrameTable2[curObject->index]; int temp2 = 0; if (curObject->index == 2) { - if (_vm->_characterList[2].sceneId == 77 || _vm->_characterList[2].sceneId == 86) { + if (_vm->_characterList[2].sceneId == 77 || _vm->_characterList[2].sceneId == 86) temp2 = 1; - } else { + else temp2 = 0; - } } else { temp2 = 1; } - if (!temp2) { + if (!temp2) shapesIndex = -1; - } } xpos = curObject->x1; @@ -282,16 +276,14 @@ void ScreenAnimator::prepDrawAllObjects() { xpos += tempX; ypos += tempY; - if (_vm->_scaleMode && _brandonScaleX != 256) { + if (_vm->_scaleMode && _brandonScaleX != 256) ++xpos; - } if (curObject->index == 0 && shapesIndex != -1) { if (!(_vm->_brandonStatusBit & 2)) { flagUnk3 = 0x100; - if ((flagUnk1 & 0x200) || (flagUnk2 & 0x4000)) { + if ((flagUnk1 & 0x200) || (flagUnk2 & 0x4000)) flagUnk3 = 0; - } int tempFlags = 0; if (flagUnk3 & 0x100) { @@ -315,9 +307,8 @@ void ScreenAnimator::prepDrawAllObjects() { } else { if (shapesIndex != -1) { int tempFlags = 0; - if (curObject->flags & 1) { + if (curObject->flags & 1) tempFlags = 1; - } _screen->drawShape(drawPage, _vm->_shapes[4+shapesIndex], xpos, ypos, 2, tempFlags | 0x800, drawLayer); } } @@ -331,37 +322,32 @@ void ScreenAnimator::prepDrawAllObjects() { if (curObject->index == 0) { flagUnk3 = 0x100; - if (flagUnk1 & 0x200 || flagUnk2 & 0x4000) { + if (flagUnk1 & 0x200 || flagUnk2 & 0x4000) flagUnk3 = 0; - } - if (_vm->_brandonStatusBit & 2) { + if (_vm->_brandonStatusBit & 2) curObject->flags &= 0xFFFFFFFE; - } if (!_vm->_scaleMode) { - if (flagUnk3 & 0x100) { + if (flagUnk3 & 0x100) _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x100, (uint8*)_vm->_brandonPoisonFlagsGFX, int(1), drawLayer); - } else if (flagUnk2 & 0x4000) { + else if (flagUnk2 & 0x4000) _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4000, int(_vm->_brandonInvFlag), drawLayer); - } else { + else _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1, drawLayer); - } } else { - if (flagUnk3 & 0x100) { + if (flagUnk3 & 0x100) _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x104, (uint8*)_vm->_brandonPoisonFlagsGFX, int(1), drawLayer, _brandonScaleX, _brandonScaleY); - } else if (flagUnk2 & 0x4000) { + else if (flagUnk2 & 0x4000) _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4004, int(_vm->_brandonInvFlag), drawLayer, _brandonScaleX, _brandonScaleY); - } else { + else _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | flagUnk1 | 0x4, drawLayer, _brandonScaleX, _brandonScaleY); - } } } else { - if (curObject->index >= 16 && curObject->index <= 27) { + if (curObject->index >= 16 && curObject->index <= 27) _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags | 4, drawLayer, (int)_vm->_scaleTable[curObject->drawY], (int)_vm->_scaleTable[curObject->drawY]); - } else { + else _screen->drawShape(drawPage, curObject->sceneAnimPtr, xpos, ypos, 2, curObject->flags, drawLayer); - } } } curObject = curObject->nextAnimObject; @@ -380,25 +366,21 @@ void ScreenAnimator::copyChangedObjectsForward(int refreshFlag) { width = curObject->width + (curObject->width2>>3) + 2; height = curObject->height + curObject->height2*2; - if (xpos < 1) { + if (xpos < 1) xpos = 1; - } else if (xpos > 39) { + else if (xpos > 39) continue; - } - if (xpos + width > 39) { + if (xpos + width > 39) width = 39 - xpos; - } - if (ypos < 8) { + if (ypos < 8) ypos = 8; - } else if (ypos > 136) { + else if (ypos > 136) continue; - } - if (ypos + height > 136) { + if (ypos + height > 136) height = 136 - ypos; - } _screen->copyRegion(xpos << 3, ypos, xpos << 3, ypos, width << 3, height, 2, 0, Screen::CR_CLIPPED); curObject->refreshFlag = 0; @@ -475,11 +457,12 @@ void ScreenAnimator::animAddNPC(int character) { animObj->sceneAnimPtr = _vm->_shapes[4+ch->currentAnimFrame]; animObj->x1 = animObj->x2 = ch->x1 + _vm->_defaultShapeTable[ch->currentAnimFrame-7].xOffset; animObj->y1 = animObj->y2 = ch->y1 + _vm->_defaultShapeTable[ch->currentAnimFrame-7].yOffset; - if (ch->facing >= 1 && ch->facing <= 3) { + + if (ch->facing >= 1 && ch->facing <= 3) animObj->flags |= 1; - } else if (ch->facing >= 5 && ch->facing <= 7) { + else if (ch->facing >= 5 && ch->facing <= 7) animObj->flags &= 0xFFFFFFFE; - } + _objectQueue = objectQueue(_objectQueue, animObj); preserveAnyChangedBackgrounds(); animObj->refreshFlag = 1; @@ -507,16 +490,14 @@ AnimObject *ScreenAnimator::objectRemoveQueue(AnimObject *queue, AnimObject *rem if (!cur->nextAnimObject) { if (cur == rem) { - if (!prev) { + if (!prev) return 0; - } else { + else prev->nextAnimObject = 0; - } } } else { - if (cur == rem) { + if (cur == rem) prev->nextAnimObject = rem->nextAnimObject; - } } return queue; @@ -556,31 +537,28 @@ AnimObject *ScreenAnimator::objectQueue(AnimObject *queue, AnimObject *add) { void ScreenAnimator::addObjectToQueue(AnimObject *object) { debugC(9, kDebugLevelAnimator, "ScreenAnimator::addObjectToQueue(%p)", (const void *)object); - if (!_objectQueue) { + if (!_objectQueue) _objectQueue = objectAddHead(0, object); - } else { + else _objectQueue = objectQueue(_objectQueue, object); - } } void ScreenAnimator::refreshObject(AnimObject *object) { debugC(9, kDebugLevelAnimator, "ScreenAnimator::refreshObject(%p)", (const void *)object); _objectQueue = objectRemoveQueue(_objectQueue, object); - if (_objectQueue) { + if (_objectQueue) _objectQueue = objectQueue(_objectQueue, object); - } else { + else _objectQueue = objectAddHead(0, object); - } } void ScreenAnimator::makeBrandonFaceMouse() { debugC(9, kDebugLevelAnimator, "ScreenAnimator::makeBrandonFaceMouse()"); Common::Point mouse = _vm->getMousePos(); - if (mouse.x >= _vm->_currentCharacter->x1) { + if (mouse.x >= _vm->_currentCharacter->x1) _vm->_currentCharacter->facing = 3; - } else { + else _vm->_currentCharacter->facing = 5; - } animRefreshNPC(0); updateAllObjectShapes(); } @@ -625,11 +603,10 @@ void ScreenAnimator::animRefreshNPC(int character) { animObj->refreshFlag = 1; animObj->bkgdChangeFlag = 1; int facing = ch->facing; - if (facing >= 1 && facing <= 3) { + if (facing >= 1 && facing <= 3) animObj->flags |= 1; - } else if (facing >= 5 && facing <= 7) { + else if (facing >= 5 && facing <= 7) animObj->flags &= 0xFFFFFFFE; - } animObj->drawY = ch->y1; animObj->sceneAnimPtr = _vm->shapes()[4+ch->currentAnimFrame]; @@ -645,9 +622,11 @@ void ScreenAnimator::animRefreshNPC(int character) { animObj->sceneAnimPtr = _vm->shapes()[4+_brandonDrawFrame]; if (_vm->_brandonStatusBit0x02Flag) { ++_brandonDrawFrame; - if (_brandonDrawFrame >= 122) + // TODO: check this + if (_brandonDrawFrame >= 122) { _brandonDrawFrame = 113; _vm->_brandonStatusBit0x02Flag = 0; + } } } } @@ -695,9 +674,9 @@ void ScreenAnimator::setCharactersHeight() { 44, 42, 47, 38, 35, 40 }; - for (int i = 0; i < 11; ++i) { + for (int i = 0; i < 11; ++i) _vm->characterList()[i].height = initHeightTable[i]; - } } } // end of namespace Kyra + diff --git a/engines/kyra/animator.h b/engines/kyra/animator.h index 2473cc6636..09a4ec9303 100644 --- a/engines/kyra/animator.h +++ b/engines/kyra/animator.h @@ -124,3 +124,4 @@ protected: } // end of namespace Kyra #endif + diff --git a/engines/kyra/debugger.cpp b/engines/kyra/debugger.cpp index 30ec201f27..48f1787ceb 100644 --- a/engines/kyra/debugger.cpp +++ b/engines/kyra/debugger.cpp @@ -119,8 +119,9 @@ bool Debugger::cmd_toggleFlag(int argc, const char **argv) { else _vm->setGameFlag(flag); DebugPrintf("Flag %i is now %i\n", flag, _vm->queryGameFlag(flag)); - } else + } else { DebugPrintf("Syntax: toggleflag <flag>\n"); + } return true; } @@ -129,8 +130,9 @@ bool Debugger::cmd_queryFlag(int argc, const char **argv) { if (argc > 1) { uint flag = atoi(argv[1]); DebugPrintf("Flag %i is %i\n", flag, _vm->queryGameFlag(flag)); - } else + } else { DebugPrintf("Syntax: queryflag <flag>\n"); + } return true; } @@ -148,8 +150,9 @@ bool Debugger::cmd_setTimerCountdown(int argc, const char **argv) { uint countdown = atoi(argv[2]); _vm->setTimerCountdown(timer, countdown); DebugPrintf("Timer %i now has countdown %i\n", timer, _vm->_timers[timer].countdown); - } else + } else { DebugPrintf("Syntax: settimercountdown <timer> <countdown>\n"); + } return true; } @@ -166,9 +169,11 @@ bool Debugger::cmd_giveItem(int argc, const char **argv) { _vm->setMouseItem(item); _vm->_itemInHand = item; - } else + } else { DebugPrintf("Syntax: give <itemid>\n"); + } return true; } } // End of namespace Kyra + diff --git a/engines/kyra/debugger.h b/engines/kyra/debugger.h index 91f90ee3ef..7e1e613433 100644 --- a/engines/kyra/debugger.h +++ b/engines/kyra/debugger.h @@ -53,3 +53,4 @@ protected: } // End of namespace Kyra #endif + diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index c9b8b045c2..0cb7f873be 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -130,9 +130,8 @@ void KyraEngine::writeSettings() { void KyraEngine::initMainButtonList() { _haveScrollButtons = false; _buttonList = &_buttonData[0]; - for (int i = 0; _buttonDataListPtr[i]; ++i) { + for (int i = 0; _buttonDataListPtr[i]; ++i) _buttonList = initButton(_buttonList, _buttonDataListPtr[i]); - } } Button *KyraEngine::initButton(Button *list, Button *newButton) { @@ -141,12 +140,13 @@ Button *KyraEngine::initButton(Button *list, Button *newButton) { if (!list) return newButton; Button *cur = list; + while (true) { - if (!cur->nextButton) { + if (!cur->nextButton) break; - } cur = cur->nextButton; } + cur->nextButton = newButton; return list; } @@ -231,9 +231,8 @@ int KyraEngine::buttonAmuletCallback(Button *caller) { _scriptClick->variables[6] = jewel; _scriptInterpreter->startScript(_scriptClick, 4); - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } if (_scriptClick->variables[3]) return 1; @@ -376,43 +375,37 @@ void KyraEngine::processButton(Button *button) { int flags = (button->flags2 & 5); if (flags == 1) { processType = button->process2; - if (processType == 1) { + if (processType == 1) shape = button->process2PtrShape; - } else if (processType == 4) { + else if (processType == 4) callback = button->process2PtrCallback; - } } else if (flags == 4 || flags == 5) { processType = button->process1; - if (processType == 1) { + if (processType == 1) shape = button->process1PtrShape; - } else if (processType == 4) { + else if (processType == 4) callback = button->process1PtrCallback; - } } else { processType = button->process0; - if (processType == 1) { + if (processType == 1) shape = button->process0PtrShape; - } else if (processType == 4) { + else if (processType == 4) callback = button->process0PtrCallback; - } } int x = button->x; int y = button->y; assert(button->dimTableIndex < _screen->_screenDimTableCount); - if (x < 0) { + if (x < 0) x += _screen->_screenDimTable[button->dimTableIndex].w << 3; - } - if (y < 0) { + if (y < 0) y += _screen->_screenDimTable[button->dimTableIndex].h; - } - if (processType == 1 && shape) { + if (processType == 1 && shape) _screen->drawShape(_screen->_curPage, shape, x, y, button->dimTableIndex, 0x10); - } else if (processType == 4 && callback) { + else if (processType == 4 && callback) (this->*callback)(button); - } } void KyraEngine::processAllMenuButtons() { @@ -421,9 +414,8 @@ void KyraEngine::processAllMenuButtons() { Button *cur = _menuButtonList; while (true) { - if (!cur->nextButton) { + if (!cur->nextButton) break; - } processMenuButton(cur); cur = cur->nextButton; } @@ -434,7 +426,7 @@ void KyraEngine::processMenuButton(Button *button) { if (!_displayMenu) return; - if ( !button || (button->flags & 8)) + if (!button || (button->flags & 8)) return; if (button->flags2 & 1) @@ -466,7 +458,6 @@ int KyraEngine::drawBoxCallback(Button *button) { } int KyraEngine::drawShadedBoxCallback(Button *button) { - if (!_displayMenu) return 0; @@ -487,13 +478,12 @@ void KyraEngine::setGUILabels() { int menuLabelGarbageOffset = 0; if (_flags.isTalkie) { - if (_flags.lang == Common::EN_ANY) { + if (_flags.lang == Common::EN_ANY) offset = 52; - } else if (_flags.lang == Common::DE_DEU) { + else if (_flags.lang == Common::DE_DEU) offset = 30; - } else if (_flags.lang == Common::FR_FRA) { + else if (_flags.lang == Common::FR_FRA) offset = 6; - } offsetOn = offsetMainMenu = offsetOptions = offset; walkspeedGarbageOffset = 48; } else if (_flags.lang == Common::ES_ESP) { @@ -558,10 +548,10 @@ void KyraEngine::setGUILabels() { // Main Menu _menu[5].item[5].itemString = &_guiStrings[19 + offsetMainMenu][menuLabelGarbageOffset]; - if (_flags.isTalkie) { + if (_flags.isTalkie) // Text & Voice _voiceTextString = _guiStrings[28 + offset]; - } + _textSpeedString = _guiStrings[25 + offsetOptions]; _onString = _guiStrings[20 + offsetOn]; _offString = _guiStrings[21 + offset]; @@ -607,9 +597,9 @@ int KyraEngine::buttonMenuCallback(Button *caller) { _mousePressFlag = false; _toplevelMenu = 0; - if (_menuDirectlyToLoad) + if (_menuDirectlyToLoad) { gui_loadGameMenu(0); - else { + } else { if (!caller) _toplevelMenu = 4; @@ -627,9 +617,9 @@ int KyraEngine::buttonMenuCallback(Button *caller) { gui_restorePalette(); _screen->loadPageFromDisk("SEENPAGE.TMP", 0); _animator->_updateScreen = true; - } - else + } else { _screen->deletePageFromDisk(0); + } return 0; } @@ -663,7 +653,6 @@ void KyraEngine::initMenu(Menu &menu) { if (!menu.item[i].enabled) continue; - x1 = menu.x + menu.item[i].x; y1 = menu.y + menu.item[i].y; @@ -726,8 +715,9 @@ void KyraEngine::initMenu(Menu &menu) { _scrollDownButton.nextButton = 0; _menuButtonList = initButton(_menuButtonList, &_scrollDownButton); processMenuButton(&_scrollDownButton); - } else + } else { _haveScrollButtons = false; + } _screen->showMouse(); _screen->updateScreen(); @@ -867,11 +857,10 @@ int KyraEngine::getNextSavegameSlot() { Common::InSaveFile *in; for (int i = 1; i < 1000; i++) { - if ((in = _saveFileMan->openForLoading(getSavegameFilename(i)))) { + if ((in = _saveFileMan->openForLoading(getSavegameFilename(i)))) delete in; - } else { + else return i; - } } warning("Didn't save: Ran out of savegame filenames"); return 0; @@ -888,8 +877,9 @@ void KyraEngine::setupSavegames(Menu &menu, int num) { menu.item[0].enabled = 1; menu.item[0].field_1b = 0; startSlot = 1; - } else + } else { startSlot = 0; + } for (int i = startSlot; i < num; i++) { if ((in = _saveFileMan->openForLoading(getSavegameFilename(i + _savegameOffset)))) { @@ -949,9 +939,9 @@ int KyraEngine::gui_saveGameMenu(Button *button) { int KyraEngine::gui_loadGameMenu(Button *button) { debugC(9, kDebugLevelGUI, "KyraEngine::gui_loadGameMenu()"); - if (_menuDirectlyToLoad) + if (_menuDirectlyToLoad) { _menu[2].item[5].enabled = false; - else { + } else { processMenuButton(button); _menu[2].item[5].enabled = true; } @@ -1109,9 +1099,9 @@ int KyraEngine::gui_quitPlaying(Button *button) { debugC(9, kDebugLevelGUI, "KyraEngine::gui_quitPlaying()"); processMenuButton(button); - if (gui_quitConfirm(_guiStrings[14])) // Are you sure you want to quit playing? + if (gui_quitConfirm(_guiStrings[14])) { // Are you sure you want to quit playing? quitGame(); - else { + } else { initMenu(_menu[_toplevelMenu]); processAllMenuButtons(); } @@ -1455,9 +1445,8 @@ void KyraEngine::gui_fadePalette() { memcpy(_screen->getPalette(2), _screen->_currentPalette, 768); - for (int i = 0; i < 768; i++) { - _screen->_currentPalette[i] /= 2; - } + for (int i = 0; i < 768; i++) + _screen->_currentPalette[i] >>= 1; while (menuPalIndexes[index] != -1) { memcpy(&_screen->_currentPalette[menuPalIndexes[index]*3], &_screen->getPalette(2)[menuPalIndexes[index]*3], 3); @@ -1600,9 +1589,8 @@ void KyraEngine::gui_drawMainBox(int x, int y, int w, int h, int fill) { --w; --h; - if (fill) { + if (fill) _screen->fillRect(x, y, x+w, y+h, colorTable[0]); - } _screen->drawClippedLine(x, y+h, x+w, y+h, colorTable[1]); _screen->drawClippedLine(x+w, y, x+w, y+h, colorTable[1]); @@ -1624,13 +1612,11 @@ void KyraEngine::gui_printString(const char *format, int x, int y, int col1, int vsprintf(string, format, vaList); va_end(vaList); - if (flags & 1) { + if (flags & 1) x -= _screen->getTextWidth(string) >> 1; - } - if (flags & 2) { + if (flags & 2) x -= _screen->getTextWidth(string); - } if (flags & 4) { _screen->printText(string, x - 1, y, 240, col2); diff --git a/engines/kyra/items.cpp b/engines/kyra/items.cpp index 21d263446c..ee011affb3 100644 --- a/engines/kyra/items.cpp +++ b/engines/kyra/items.cpp @@ -148,9 +148,8 @@ void KyraEngine::placeItemInGenericMapScene(int item, int index) { break; case 51: - if (room != 46) { + if (room != 46) placeItem = true; - } break; default: @@ -159,11 +158,10 @@ void KyraEngine::placeItemInGenericMapScene(int item, int index) { if (placeItem) { Room *roomPtr = &_roomTable[room]; - if (roomPtr->northExit == 0xFFFF && roomPtr->eastExit == 0xFFFF && roomPtr->southExit == 0xFFFF && roomPtr->westExit == 0xFFFF) { + if (roomPtr->northExit == 0xFFFF && roomPtr->eastExit == 0xFFFF && roomPtr->southExit == 0xFFFF && roomPtr->westExit == 0xFFFF) placeItem = false; - } else if (_currentCharacter->sceneId == room) { + else if (_currentCharacter->sceneId == room) placeItem = false; - } } if (placeItem) { @@ -192,11 +190,10 @@ void KyraEngine::destroyMouseItem() { void KyraEngine::setMouseItem(int item) { debugC(9, kDebugLevelMain, "KyraEngine::setMouseItem(%d)", item); - if (item == -1) { + if (item == -1) _screen->setMouseCursor(1, 1, _shapes[10]); - } else { + else _screen->setMouseCursor(8, 15, _shapes[220+item]); - } } void KyraEngine::wipeDownMouseItem(int xpos, int ypos) { @@ -233,9 +230,8 @@ void KyraEngine::setupSceneItems() { Room *currentRoom = &_roomTable[sceneId]; for (int i = 0; i < 12; ++i) { uint8 item = currentRoom->itemsTable[i]; - if (item == 0xFF || !currentRoom->needInit[i]) { + if (item == 0xFF || !currentRoom->needInit[i]) continue; - } int xpos = 0; int ypos = 0; @@ -256,9 +252,8 @@ void KyraEngine::setupSceneItems() { if (!stop) { xpos = currentRoom->itemsXPos[i] = _rnd.getRandomNumberRng(24, 296); ypos = currentRoom->itemsYPos[i] = _rnd.getRandomNumberRng(_northExitHeight & 0xFF, 130); - if (countItemsInScene(sceneId) >= 12) { + if (countItemsInScene(sceneId) >= 12) break; - } } else { currentRoom->needInit[i] = 0; } @@ -274,9 +269,8 @@ int KyraEngine::countItemsInScene(uint16 sceneId) { int items = 0; for (int i = 0; i < 12; ++i) { - if (currentRoom->itemsTable[i] != 0xFF) { + if (currentRoom->itemsTable[i] != 0xFF) ++items; - } } return items; @@ -286,9 +280,8 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un debugC(9, kDebugLevelMain, "KyraEngine::processItemDrop(%d, %d, %d, %d, %d, %d)", sceneId, item, x, y, unk1, unk2); int freeItem = -1; uint8 itemIndex = findItemAtPos(x, y); - if (unk1) { + if (unk1) itemIndex = 0xFF; - } if (itemIndex != 0xFF) { exchangeItemWithMouseItem(sceneId, itemIndex); @@ -309,9 +302,8 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un freeItem = _lastProcessedItem; } - if (freeItem == -1) { + if (freeItem == -1) return 0; - } if (sceneId != _currentCharacter->sceneId) { addItemToRoom(sceneId, item, freeItem, x, y); @@ -337,21 +329,18 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un bool running2 = true; if (_screen->getDrawLayer(xpos, ypos) > 1) { - if (((_northExitHeight >> 8) & 0xFF) != ypos) { + if (((_northExitHeight >> 8) & 0xFF) != ypos) running2 = false; - } } if (_screen->getDrawLayer2(xpos, ypos, itemHeight) > 1) { - if (((_northExitHeight >> 8) & 0xFF) != ypos) { + if (((_northExitHeight >> 8) & 0xFF) != ypos) running2 = false; - } } if (!isDropable(xpos, ypos)) { - if (((_northExitHeight >> 8) & 0xFF) != ypos) { + if (((_northExitHeight >> 8) & 0xFF) != ypos) running2 = false; - } } int xpos2 = xpos; @@ -384,14 +373,12 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un continue; xpos2 -= 2; - if (xpos2 < 16) { + if (xpos2 < 16) xpos2 = 16; - } xpos3 += 2; - if (xpos3 > 304) { + if (xpos3 > 304) xpos3 = 304; - } if (xpos2 > 16) continue; @@ -405,23 +392,20 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un running = 0; destY -= _rnd.getRandomNumberRng(0, 3); - if ((_northExitHeight & 0xFF) < destY) { + if ((_northExitHeight & 0xFF) < destY) continue; - } destY = (_northExitHeight & 0xFF) + 1; continue; } ypos += 2; - if (((_northExitHeight >> 8) & 0xFF) >= ypos) { + if (((_northExitHeight >> 8) & 0xFF) >= ypos) continue; - } ypos = (_northExitHeight >> 8) & 0xFF; } - if (destX == -1 || destY == -1) { + if (destX == -1 || destY == -1) return 0; - } if (unk1 == 3) { currentRoom->itemsXPos[freeItem] = destX; @@ -429,13 +413,11 @@ int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int un return 1; } - if (unk1 == 2) { + if (unk1 == 2) itemSpecialFX(x, y, item); - } - if (unk1 == 0) { + if (unk1 == 0) destroyMouseItem(); - } itemDropDown(x, y, destX, destY, freeItem, item); @@ -479,17 +461,14 @@ void KyraEngine::addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int KyraEngine::checkNoDropRects(int x, int y) { debugC(9, kDebugLevelMain, "KyraEngine::checkNoDropRects(%d, %d)", x, y); - if (_lastProcessedItemHeight < 1 || _lastProcessedItemHeight > 16) { + if (_lastProcessedItemHeight < 1 || _lastProcessedItemHeight > 16) _lastProcessedItemHeight = 16; - } - if (_noDropRects[0].x == -1) { + if (_noDropRects[0].x == -1) return 0; - } for (int i = 0; i < 11; ++i) { - if (_noDropRects[i].x == -1) { + if (_noDropRects[i].x == -1) break; - } int xpos = _noDropRects[i].x; int ypos = _noDropRects[i].y; @@ -515,14 +494,12 @@ int KyraEngine::isDropable(int x, int y) { x -= 8; y -= 1; - if (checkNoDropRects(x, y)) { + if (checkNoDropRects(x, y)) return 0; - } for (int xpos = x; xpos < x + 16; ++xpos) { - if (_screen->getShapeFlag1(xpos, y) == 0) { + if (_screen->getShapeFlag1(xpos, y) == 0) return 0; - } } return 1; } @@ -551,9 +528,8 @@ void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, while (tempY < destY) { _screen->restoreRect0(drawX, tempY - 16); tempY += addY; - if (tempY > destY) { + if (tempY > destY) tempY = destY; - } ++addY; drawY = tempY - 16; _screen->backUpRect0(drawX, drawY); @@ -565,9 +541,8 @@ void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, bool skip = false; if (x == destX) { - if (destY - y <= 16) { + if (destY - y <= 16) skip = true; - } } if (!skip) { @@ -579,9 +554,8 @@ void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, xDiff /= addY; int startAddY = addY; addY >>= 1; - if (destY - y <= 8) { + if (destY - y <= 8) addY >>= 1; - } addY = -addY; int unkX = x << 4; while (--startAddY) { @@ -590,9 +564,8 @@ void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, _screen->restoreRect0(drawX, drawY); tempY += addY; unkX += xDiff; - if (tempY > destY) { + if (tempY > destY) tempY = destY; - } ++addY; drawX = (unkX >> 4) - 8; drawY = tempY - 16; @@ -620,22 +593,19 @@ void KyraEngine::dropItem(int unk1, int item, int x, int y, int unk2) { if (processItemDrop(_currentCharacter->sceneId, item, x, y, unk1, unk2)) return; snd_playSoundEffect(54); - if (12 == countItemsInScene(_currentCharacter->sceneId)) { - assert(_noDropList); + assert(_noDropList); + if (12 == countItemsInScene(_currentCharacter->sceneId)) drawSentenceCommand(_noDropList[0], 6); - } else { - assert(_noDropList); + else drawSentenceCommand(_noDropList[1], 6); - } } void KyraEngine::itemSpecialFX(int x, int y, int item) { debugC(9, kDebugLevelMain, "KyraEngine::itemSpecialFX(%d, %d, %d)", x, y, item); - if (item == 41) { + if (item == 41) itemSpecialFX1(x, y, item); - } else { + else itemSpecialFX2(x, y, item); - } } void KyraEngine::itemSpecialFX1(int x, int y, int item) { @@ -665,9 +635,8 @@ void KyraEngine::itemSpecialFX2(int x, int y, int item) { y -= 15; int yAdd = (int8)(((16 - _itemTable[item].height) >> 1) & 0xFF); _screen->backUpRect0(x, y); - if (item >= 80 && item <= 89) { + if (item >= 80 && item <= 89) snd_playSoundEffect(55); - } for (int i = 201; i <= 205; ++i) { _screen->restoreRect0(x, y); @@ -702,9 +671,8 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { y = _itemPosY[itemPos] - 3; } - if (_itemInHand == -1 && itemPos == -1) { + if (_itemInHand == -1 && itemPos == -1) return; - } int tableIndex = 0, loopStart = 0, maxLoops = 0; if (animIndex == 0) { @@ -723,11 +691,10 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { tableIndex = -1; } - if (animIndex == 2) { + if (animIndex == 2) snd_playSoundEffect(0x5E); - } else { + else snd_playSoundEffect(0x37); - } _screen->hideMouse(); _screen->backUpRect1(x, y); @@ -735,11 +702,10 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { _screen->restoreRect1(x, y); uint32 nextTime = _system->getMillis() + 4 * _tickLength; _screen->drawShape(0, _shapes[220+_itemInHand], x + 4, y + 3, 0, 0); - if (tableIndex == -1) { + if (tableIndex == -1) _screen->drawShape(0, _shapes[4+shape], x, y, 0, 0); - } else { + else specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops); - } _screen->updateScreen(); delayUntil(nextTime); } @@ -754,11 +720,10 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) { _screen->restoreRect1(x, y); uint32 nextTime = _system->getMillis() + 4 * _tickLength; _screen->drawShape(0, _shapes[220+_itemInHand], x + 4, y + 3, 0, 0); - if (tableIndex == -1) { + if (tableIndex == -1) _screen->drawShape(0, _shapes[4+shape], x, y, 0, 0); - } else { + else specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops); - } _screen->updateScreen(); delayUntil(nextTime); } @@ -809,20 +774,18 @@ void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) { _screen->hideMouse(); _screen->backUpRect1(x, y); - if (animIndex == 2) { + if (animIndex == 2) snd_playSoundEffect(0x5E); - } else { + else snd_playSoundEffect(0x37); - } for (int shape = _magicMouseItemStartFrame[animIndex]; shape <= _magicMouseItemEndFrame[animIndex]; ++shape) { _screen->restoreRect1(x, y); uint32 nextTime = _system->getMillis() + 4 * _tickLength; - if (tableIndex == -1) { + if (tableIndex == -1) _screen->drawShape(0, _shapes[4+shape], x, y, 0, 0); - } else { + else specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops); - } _screen->updateScreen(); delayUntil(nextTime); } @@ -830,11 +793,10 @@ void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) { for (int shape = _magicMouseItemStartFrame2[animIndex]; shape <= _magicMouseItemEndFrame2[animIndex]; ++shape) { _screen->restoreRect1(x, y); uint32 nextTime = _system->getMillis() + 4 * _tickLength; - if (tableIndex == -1) { + if (tableIndex == -1) _screen->drawShape(0, _shapes[4+shape], x, y, 0, 0); - } else { + else specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops); - } _screen->updateScreen(); delayUntil(nextTime); } @@ -864,15 +826,14 @@ void KyraEngine::specialMouseItemFX(int shape, int x, int y, int animIndex, int 0x7C, 0xD0, 0x74, 0x84, 0x87, 0x00, 0x00, 0x00 }; int tableValue = 0; - if (animIndex == 0) { + if (animIndex == 0) tableValue = table1[tableIndex]; - } else if (animIndex == 1) { + else if (animIndex == 1) tableValue = table2[tableIndex]; - } else if (animIndex == 2) { + else if (animIndex == 2) tableValue = table3[tableIndex]; - } else { + else return; - } processSpecialMouseItemFX(shape, x, y, tableValue, loopStart, maxLoops); } @@ -882,14 +843,14 @@ void KyraEngine::processSpecialMouseItemFX(int shape, int x, int y, int tableVal uint8 *shapePtr = _shapes[4+shape] + 10; if (_flags.useAltShapeHeader) shapePtr += 2; - for (int i = 0; i < 16; ++i) { + + for (int i = 0; i < 16; ++i) shapeColorTable[i] = shapePtr[i]; - } + for (int i = loopStart; i < loopStart + maxLoops; ++i) { for (int i2 = 0; i2 < 16; ++i2) { - if (shapePtr[i2] == i) { + if (shapePtr[i2] == i) shapeColorTable[i2] = (i + tableValue) - loopStart; - } } } _screen->drawShape(0, _shapes[4+shape], x, y, 0, 0x8000, shapeColorTable); @@ -924,16 +885,14 @@ void KyraEngine::updatePlayerItemsForScene() { _screen->showMouse(); } - if (_itemInHand == 33) { + if (_itemInHand == 33) magicOutMouseItem(2, -1); - } _screen->hideMouse(); for (int i = 0; i < 10; ++i) { uint8 item = _currentCharacter->inventoryItems[i]; - if (item == 33) { + if (item == 33) magicOutMouseItem(2, i); - } } _screen->showMouse(); } @@ -955,3 +914,4 @@ void KyraEngine::redrawInventory(int page) { } } // end of namespace Kyra + diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index 8092f405ef..f364711066 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -130,9 +130,8 @@ KyraEngine_v1::KyraEngine_v1(OSystem *system, const GameFlags &flags) int KyraEngine::init() { // Setup mixer - if (!_mixer->isReady()) { + if (!_mixer->isReady()) warning("Sound initialization failed."); - } _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); @@ -161,9 +160,8 @@ int KyraEngine::init() { MidiDriver *driver = MidiDriver::createMidi(midiDriver); assert(driver); - if (native_mt32) { + if (native_mt32) driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); - } SoundMidiPC *soundMidiPc = new SoundMidiPC(this, _mixer, driver); _sound = soundMidiPc; @@ -221,10 +219,11 @@ int KyraEngine::init() { _currentCharacter = 0; _characterList = new Character[11]; assert(_characterList); - for (int i = 0; i < 11; ++i) { - memset(&_characterList[i], 0, sizeof(Character)); + memset(_characterList, 0, sizeof(Character)*11); + + for (int i = 0; i < 11; ++i) memset(_characterList[i].inventoryItems, 0xFF, sizeof(_characterList[i].inventoryItems)); - } + _characterList[0].sceneId = 5; _characterList[0].height = 48; _characterList[0].facing = 3; @@ -255,9 +254,8 @@ int KyraEngine::init() { assert(_debugger); memset(_shapes, 0, sizeof(_shapes)); - for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { + for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) _movieObjects[i] = createWSAMovie(); - } memset(_flagsTable, 0, sizeof(_flagsTable)); @@ -417,9 +415,9 @@ KyraEngine::~KyraEngine() { _shapes[i] = 0; } } - for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) { + + for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) delete [] _sceneAnimTable[i]; - } } KyraEngine_v1::~KyraEngine_v1() { @@ -427,10 +425,8 @@ KyraEngine_v1::~KyraEngine_v1() { } int KyraEngine::go() { - - if (_res->getFileSize("6.FNT")) { + if (_res->getFileSize("6.FNT")) _screen->loadFont(Screen::FID_6_FNT, "6.FNT"); - } _screen->loadFont(Screen::FID_8_FNT, "8FAT.FNT"); _screen->setScreenDim(0); @@ -484,6 +480,7 @@ void KyraEngine::startup() { memset(_shapes[2], 0, _screen->getRectSize(8, 69)); _shapes[3] = new uint8[_screen->getRectSize(8, 69)]; memset(_shapes[3], 0, _screen->getRectSize(8, 69)); + for (int i = 0; i < _roomTableSize; ++i) { for (int item = 0; item < 12; ++item) { _roomTable[i].itemsTable[item] = 0xFF; @@ -492,6 +489,7 @@ void KyraEngine::startup() { _roomTable[i].needInit[item] = 0; } } + loadCharacterShapes(); loadSpecialEffectShapes(); loadItems(); @@ -542,10 +540,8 @@ void KyraEngine::mainLoop() { if (_currentCharacter->sceneId == 210) { updateKyragemFading(); - if (seq_playEnd()) { - if (_deathHandler != 8) - break; - } + if (seq_playEnd() && _deathHandler != 8) + break; } if (_deathHandler != 0xFF) { @@ -559,15 +555,12 @@ void KyraEngine::mainLoop() { _deathHandler = 0xFF; } - if (_brandonStatusBit & 2) { - if (_brandonStatusBit0x02Flag) - _animator->animRefreshNPC(0); - } - if (_brandonStatusBit & 0x20) { - if (_brandonStatusBit0x20Flag) { - _animator->animRefreshNPC(0); - _brandonStatusBit0x20Flag = 0; - } + if ((_brandonStatusBit & 2) && _brandonStatusBit0x02Flag) + _animator->animRefreshNPC(0); + + if ((_brandonStatusBit & 0x20) && _brandonStatusBit0x20Flag) { + _animator->animRefreshNPC(0); + _brandonStatusBit0x20Flag = 0; } _screen->showMouse(); @@ -595,6 +588,7 @@ void KyraEngine::delayUntil(uint32 timestamp, bool updateTimers, bool update, bo while (_system->getMillis() < timestamp && !_quitFlag) { if (updateTimers) updateGameTimers(); + if (timestamp - _system->getMillis() >= 10) delay(10, update, isMainLoop); } @@ -659,6 +653,7 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { break; } } + if (_debugger->isAttached()) _debugger->onFrame(); @@ -669,22 +664,18 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { updateMousePointer(); } - if (_currentCharacter && _currentCharacter->sceneId == 210 && update) { + if (_currentCharacter && _currentCharacter->sceneId == 210 && update) updateKyragemFading(); - } if (_skipFlag && !_abortIntroFlag && !queryGameFlag(0xFE)) _skipFlag = false; - if (amount > 0 && !_skipFlag && !_quitFlag) { + if (amount > 0 && !_skipFlag && !_quitFlag) _system->delayMillis(10); - } - if (_skipFlag) { + if (_skipFlag) _sound->voiceStop(); - } } while (!_skipFlag && _system->getMillis() < start + amount && !_quitFlag); - } Common::Point KyraEngine::getMousePos() const { @@ -699,6 +690,7 @@ Common::Point KyraEngine::getMousePos() const { void KyraEngine::waitForEvent() { bool finished = false; Common::Event event; + while (!finished && !_quitFlag) { while (_eventMan->pollEvent(event)) { switch (event.type) { @@ -726,15 +718,19 @@ void KyraEngine::waitForEvent() { void KyraEngine::delayWithTicks(int ticks) { uint32 nextTime = _system->getMillis() + ticks * _tickLength; + while (_system->getMillis() < nextTime) { _sprites->updateSceneAnims(); _animator->updateAllObjectShapes(); + if (_currentCharacter->sceneId == 210) { updateKyragemFading(); seq_playEnd(); } + if (_skipFlag) break; + if (nextTime - _system->getMillis() >= 10) delay(10); } @@ -746,9 +742,10 @@ void KyraEngine::delayWithTicks(int ticks) { void KyraEngine::setupShapes123(const Shape *shapeTable, int endShape, int flags) { debugC(9, kDebugLevelMain, "KyraEngine::setupShapes123(%p, %d, %d)", (const void *)shapeTable, endShape, flags); - for (int i = 123; i <= 172; ++i) { - _shapes[4+i] = NULL; - } + + for (int i = 123; i <= 172; ++i) + _shapes[4+i] = 0; + uint8 curImage = 0xFF; int curPageBackUp = _screen->_curPage; _screen->_curPage = 8; // we are using page 8 here in the original page 2 was backuped and then used for this stuff @@ -774,9 +771,10 @@ void KyraEngine::setupShapes123(const Shape *shapeTable, int endShape, int flags void KyraEngine::freeShapes123() { debugC(9, kDebugLevelMain, "KyraEngine::freeShapes123()"); + for (int i = 123; i <= 172; ++i) { delete [] _shapes[4+i]; - _shapes[4+i] = NULL; + _shapes[4+i] = 0; } } @@ -787,6 +785,7 @@ void KyraEngine::freeShapes123() { Movie *KyraEngine::createWSAMovie() { if (_flags.platform == Common::kPlatformAmiga) return new WSAMovieAmiga(this); + return new WSAMovieV1(this); } @@ -807,11 +806,13 @@ int KyraEngine::resetGameFlag(int flag) { void KyraEngine::setBrandonPoisonFlags(int reset) { debugC(9, kDebugLevelMain, "KyraEngine::setBrandonPoisonFlags(%d)", reset); _brandonStatusBit |= 1; + if (reset) _poisonDeathCounter = 0; - for (int i = 0; i < 0x100; ++i) { + + for (int i = 0; i < 0x100; ++i) _brandonPoisonFlagsGFX[i] = i; - } + _brandonPoisonFlagsGFX[0x99] = 0x34; _brandonPoisonFlagsGFX[0x9A] = 0x35; _brandonPoisonFlagsGFX[0x9B] = 0x37; @@ -822,9 +823,9 @@ void KyraEngine::setBrandonPoisonFlags(int reset) { void KyraEngine::resetBrandonPoisonFlags() { debugC(9, kDebugLevelMain, "KyraEngine::resetBrandonPoisonFlags()"); _brandonStatusBit = 0; - for (int i = 0; i < 0x100; ++i) { + + for (int i = 0; i < 0x100; ++i) _brandonPoisonFlagsGFX[i] = i; - } } #pragma mark - @@ -839,9 +840,9 @@ void KyraEngine::processInput() { debugC(9, kDebugLevelMain, "KyraEngine::processInput(%d, %d)", xpos, ypos); _abortWalkFlag2 = false; - if (processInputHelper(xpos, ypos)) { + if (processInputHelper(xpos, ypos)) return; - } + uint8 item = findItemAtPos(xpos, ypos); if (item == 0xFF) { _changedScene = false; @@ -931,9 +932,8 @@ int KyraEngine::clickEventHandler(int xpos, int ypos) { _scriptClick->variables[4] = _itemInHand; _scriptInterpreter->startScript(_scriptClick, 1); - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } return _scriptClick->variables[3]; } @@ -1053,14 +1053,15 @@ void KyraEngine::updateMousePointer(bool forceUpdate) { bool KyraEngine::hasClickedOnExit(int xpos, int ypos) { debugC(9, kDebugLevelMain, "KyraEngine::hasClickedOnExit(%d, %d)", xpos, ypos); - if (xpos < 16 || xpos >= 304) { + if (xpos < 16 || xpos >= 304) return true; - } + if (ypos < 8) return true; - if (ypos < 136 || ypos > 155) { + + if (ypos < 136 || ypos > 155) return false; - } + return true; } @@ -1076,9 +1077,8 @@ void KyraEngine::clickEventHandler2() { _scriptClick->variables[4] = _itemInHand; _scriptInterpreter->startScript(_scriptClick, 6); - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } } int KyraEngine::checkForNPCScriptRun(int xpos, int ypos) { @@ -1096,13 +1096,11 @@ int KyraEngine::checkForNPCScriptRun(int xpos, int ypos) { charTop = currentChar->y1 - addY; charBottom = currentChar->y1; - if (xpos >= charLeft && charRight >= xpos && charTop <= ypos && charBottom >= ypos) { + if (xpos >= charLeft && charRight >= xpos && charTop <= ypos && charBottom >= ypos) return 0; - } - if (xpos > 304 || xpos < 16) { + if (xpos > 304 || xpos < 16) return -1; - } for (int i = 1; i < 5; ++i) { currentChar = &_characterList[i]; @@ -1119,14 +1117,12 @@ int KyraEngine::checkForNPCScriptRun(int xpos, int ypos) { charBottom = currentChar->y1; // } - if (xpos < charLeft || xpos > charRight || ypos < charTop || charBottom < ypos) { + if (xpos < charLeft || xpos > charRight || ypos < charTop || charBottom < ypos) continue; - } if (returnValue != -1) { - if (currentChar->y1 >= _characterList[returnValue].y1) { + if (currentChar->y1 >= _characterList[returnValue].y1) returnValue = i; - } } else { returnValue = i; } @@ -1143,19 +1139,20 @@ void KyraEngine::runNpcScript(int func) { _npcScript->variables[4] = _itemInHand; _npcScript->variables[5] = func; - while (_scriptInterpreter->validScript(_npcScript)) { + while (_scriptInterpreter->validScript(_npcScript)) _scriptInterpreter->runScript(_npcScript); - } } int KyraEngine::runOpcode(ScriptState *script, uint8 opcode) { debugC(9, kDebugLevelMain | kDebugLevelScript, "KyraEngine::runOpcode(%p, %d)", (void *)script, opcode); + assert(script); assert(opcode < _opcodeTableSize); + if (_opcodeTable[opcode] == &KyraEngine::o1_dummy) warning("calling unimplemented opcode(0x%.02X)", opcode); - int val = (this->*_opcodeTable[opcode])(script); - assert(script); - return val; + + return (this->*_opcodeTable[opcode])(script); } } // End of namespace Kyra + diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h index d5fb11e44d..fa4ff7ef7d 100644 --- a/engines/kyra/kyra.h +++ b/engines/kyra/kyra.h @@ -20,8 +20,8 @@ * */ -#ifndef KYRA_H -#define KYRA_H +#ifndef KYRA_KYRA_H +#define KYRA_KYRA_H #include "engines/engine.h" #include "common/rect.h" @@ -264,6 +264,7 @@ public: typedef void (KyraEngine::*IntroProc)(); typedef int (KyraEngine::*OpcodeProc)(ScriptState *script); + // static data access const char * const*seqWSATable() { return _seq_WSATable; } const char * const*seqCPSTable() { return _seq_CPSTable; } const char * const*seqCOLTable() { return _seq_COLTable; } @@ -272,9 +273,60 @@ public: const uint8 * const*palTable1() { return &_specialPalettes[0]; } const uint8 * const*palTable2() { return &_specialPalettes[29]; } + // sequences + // -> misc bool seq_skipSequence() const; + +private: + // -> demo + void seq_demo(); + + // -> intro + void seq_intro(); + void seq_introLogos(); + void seq_introStory(); + void seq_introMalcolmTree(); + void seq_introKallakWriting(); + void seq_introKallakMalcolm(); + + // -> ingame animations + void seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly); + void seq_brandonHealing(); + void seq_brandonHealing2(); + void seq_poisonDeathNow(int now); + void seq_poisonDeathNowAnim(); + void seq_playFluteAnimation(); + void seq_winterScroll1(); + void seq_winterScroll2(); + void seq_makeBrandonInv(); + void seq_makeBrandonNormal(); + void seq_makeBrandonNormal2(); + void seq_makeBrandonWisp(); + void seq_dispelMagicAnimation(); + void seq_fillFlaskWithWater(int item, int type); + void seq_playDrinkPotionAnim(int item, int unk2, int flags); + void seq_brandonToStone(); + + // -> end fight + int seq_playEnd(); + void seq_playEnding(); + + int handleMalcolmFlag(); + int handleBeadState(); + void initBeadState(int x, int y, int x2, int y2, int unk1, BeadState *ptr); + int processBead(int x, int y, int &x2, int &y2, BeadState *ptr); + + // -> credits + void seq_playCredits(); + +public: + // delay void delayUntil(uint32 timestamp, bool updateGameTimers = false, bool update = false, bool isMainLoop = false); void delay(uint32 millis, bool update = false, bool isMainLoop = false); + void delayWithTicks(int ticks); + void waitForEvent(); + + // TODO void quitGame(); void registerDefaultSettings(); @@ -292,10 +344,6 @@ public: bool speechEnabled(); bool textEnabled(); - void drawSentenceCommand(const char *sentence, int unk1); - void updateSentenceCommand(const char *str1, const char *str2, int unk1); - void updateTextFade(); - void updateGameTimers(); void clearNextEventTickCount(); void setTimerCountdown(uint8 timer, int32 countdown); @@ -304,8 +352,6 @@ public: void enableTimer(uint8 timer); void disableTimer(uint8 timer); - void delayWithTicks(int ticks); - void saveGame(const char *fileName, const char *saveName); void loadGame(const char *fileName); @@ -317,6 +363,7 @@ public: virtual int runOpcode(ScriptState *script, uint8 opcode); protected: + // Opcodes int o1_magicInMouseItem(ScriptState *script); int o1_characterSays(ScriptState *script); int o1_pauseTicks(ScriptState *script); @@ -476,77 +523,80 @@ protected: int o1_vocLoad(ScriptState *script); protected: - virtual int go(); virtual int init(); - void startup(); - void mainLoop(); - int initCharacterChat(int8 charNum); - int8 getChatPartnerNum(); - void backupChatPartnerAnimFrame(int8 charNum); - void restoreChatPartnerAnimFrame(int8 charNum); - void endCharacterChat(int8 charNum, int16 arg_4); - void waitForChatToFinish(int vocFile, int16 chatDuration, const char *str, uint8 charNum); - void characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration); + // input + void processInput(); + int processInputHelper(int xpos, int ypos); + int clickEventHandler(int xpos, int ypos); + void clickEventHandler2(); + void updateMousePointer(bool forceUpdate = false); + bool hasClickedOnExit(int xpos, int ypos); - void setCharactersPositions(int character); - - void setupSceneResource(int sceneId); - - void enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive); - void transcendScenes(int roomIndex, int roomName); - void setSceneFile(int roomIndex, int roomName); - void moveCharacterToPos(int character, int facing, int xpos, int ypos); - void setCharacterPositionWithUpdate(int character); - int setCharacterPosition(int character, int *facingTable); - void setCharacterPositionHelper(int character, int *facingTable); - int getOppositeFacingDirection(int dir); + // scene + // -> init void loadSceneMsc(); void startSceneScript(int brandonAlive); void setupSceneItems(); void initSceneData(int facing, int unk1, int brandonAlive); - void clearNoDropRects(); - void addToNoDropRects(int x, int y, int w, int h); - byte findFreeItemInScene(int scene); - byte findItemAtPos(int x, int y); - void placeItemInGenericMapScene(int item, int index); void initSceneObjectList(int brandonAlive); void initSceneScreen(int brandonAlive); - int findDuplicateItemShape(int shape); + void setupSceneResource(int sceneId); + + // -> process + void enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive); + int handleSceneChange(int xpos, int ypos, int unk1, int frameReset); + int processSceneChange(int *table, int unk1, int frameReset); + int changeScene(int facing); + + // -> modification + void transcendScenes(int roomIndex, int roomName); + void setSceneFile(int roomIndex, int roomName); + + // -> pathfinder int findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize); int findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end); int getFacingFromPointToPoint(int x, int y, int toX, int toY); void changePosTowardsFacing(int &x, int &y, int facing); bool lineIsPassable(int x, int y); int getMoveTableSize(int *moveTable); - 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 setBrandonPoisonFlags(int reset); - void resetBrandonPoisonFlags(); - void processInput(); - int processInputHelper(int xpos, int ypos); - int clickEventHandler(int xpos, int ypos); - void clickEventHandler2(); - void updateMousePointer(bool forceUpdate = false); - bool hasClickedOnExit(int xpos, int ypos); - int checkForNPCScriptRun(int xpos, int ypos); - void runNpcScript(int func); - - int countItemsInScene(uint16 sceneId); - int processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2); - void exchangeItemWithMouseItem(uint16 sceneId, int itemIndex); + // -> item handling + // --> misc void addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y); - int checkNoDropRects(int x, int y); - int isDropable(int x, int y); + + // --> drop handling void itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item); + int processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2); void dropItem(int unk1, int item, int x, int y, int unk2); + + // --> dropped item handling + int countItemsInScene(uint16 sceneId); + void exchangeItemWithMouseItem(uint16 sceneId, int itemIndex); + byte findFreeItemInScene(int scene); + byte findItemAtPos(int x, int y); + + // --> drop area handling + void addToNoDropRects(int x, int y, int w, int h); + void clearNoDropRects(); + int isDropable(int x, int y); + int checkNoDropRects(int x, int y); + + // --> player items handling: + void updatePlayerItemsForScene(); + + // items + // -> misc + void placeItemInGenericMapScene(int item, int index); + + // -> mouse item + void createMouseItem(int item); + void destroyMouseItem(); + void setMouseItem(int item); + + // -> graphics effects + void wipeDownMouseItem(int xpos, int ypos); void itemSpecialFX(int x, int y, int item); void itemSpecialFX1(int x, int y, int item); void itemSpecialFX2(int x, int y, int item); @@ -554,63 +604,78 @@ protected: void magicInMouseItem(int animIndex, int item, int itemPos); void specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops); void processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops); - void updatePlayerItemsForScene(); + + // character + // -> movement + void moveCharacterToPos(int character, int facing, int xpos, int ypos); + void setCharacterPositionWithUpdate(int character); + int setCharacterPosition(int character, int *facingTable); + void setCharacterPositionHelper(int character, int *facingTable); + int getOppositeFacingDirection(int dir); + void setCharactersPositions(int character); + + // -> brandon + void setBrandonPoisonFlags(int reset); + void resetBrandonPoisonFlags(); + + // chat + // -> process + void characterSays(int vocFile, const char *chatStr, int8 charNum, int8 chatDuration); + void waitForChatToFinish(int vocFile, int16 chatDuration, const char *str, uint8 charNum); + + // -> initialization + int initCharacterChat(int8 charNum); + void backupChatPartnerAnimFrame(int8 charNum); + void restoreChatPartnerAnimFrame(int8 charNum); + int8 getChatPartnerNum(); + + // -> deinitialization + void endCharacterChat(int8 charNum, int16 arg_4); + + // graphics + // -> misc + int findDuplicateItemShape(int shape); + void updateKyragemFading(); + + // -> interface + void loadMainScreen(int page = 3); void redrawInventory(int page); - +public: + void drawSentenceCommand(const char *sentence, int unk1); + void updateSentenceCommand(const char *str1, const char *str2, int unk1); + void updateTextFade(); + +protected: + // -> amulet void drawJewelPress(int jewel, int drawSpecial); void drawJewelsFadeOutStart(); void drawJewelsFadeOutEnd(int jewel); + + // -> shape handling void setupShapes123(const Shape *shapeTable, int endShape, int flags); void freeShapes123(); - void seq_demo(); - void seq_intro(); - void seq_introLogos(); - void seq_introStory(); - void seq_introMalcolmTree(); - void seq_introKallakWriting(); - void seq_introKallakMalcolm(); - void seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly); - void seq_brandonHealing(); - void seq_brandonHealing2(); - void seq_poisonDeathNow(int now); - void seq_poisonDeathNowAnim(); - void seq_playFluteAnimation(); - void seq_winterScroll1(); - void seq_winterScroll2(); - void seq_makeBrandonInv(); - void seq_makeBrandonNormal(); - void seq_makeBrandonNormal2(); - void seq_makeBrandonWisp(); - void seq_dispelMagicAnimation(); - void seq_fillFlaskWithWater(int item, int type); - void seq_playDrinkPotionAnim(int item, int unk2, int flags); - int seq_playEnd(); - void seq_brandonToStone(); - void seq_playEnding(); - void seq_playCredits(); - void updateKyragemFading(); + // misc (TODO) + void startup(); + void mainLoop(); + + int checkForNPCScriptRun(int xpos, int ypos); + void runNpcScript(int func); void setupOpcodeTable(); const OpcodeProc *_opcodeTable; int _opcodeTableSize; - void waitForEvent(); void loadMouseShapes(); void loadCharacterShapes(); void loadSpecialEffectShapes(); void loadItems(); void loadButtonShapes(); void initMainButtonList(); - void loadMainScreen(int page = 3); void setCharactersInDefaultScene(); void setupPanPages(); void freePanPages(); void closeFinalWsa(); - int handleMalcolmFlag(); - int handleBeadState(); - void initBeadState(int x, int y, int x2, int y2, int unk1, BeadState *ptr); - int processBead(int x, int y, int &x2, int &y2, BeadState *ptr); void setTimer19(); void setupTimers(); @@ -702,7 +767,7 @@ protected: bool _mousePressFlag; int8 _mouseWheel; uint8 _flagsTable[69]; - uint8 *_shapes[377]; + uint8 *_shapes[377]; // TODO: the first 4 entries seem to be screen backup rects, move them in the future out of the shape data uint16 _gameSpeed; uint16 _tickLength; int _lang; @@ -1013,3 +1078,4 @@ public: } // End of namespace Kyra #endif + diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 9593817013..4f72b1378c 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -43,20 +43,17 @@ KyraEngine_v2::~KyraEngine_v2() { int KyraEngine_v2::init() { KyraEngine::init(); - if (_res->getFileSize("6.FNT")) { + if (_res->getFileSize("6.FNT")) _screen->loadFont(Screen::FID_6_FNT, "6.FNT"); - } - if (_res->getFileSize("8FAT.FNT")) { + if (_res->getFileSize("8FAT.FNT")) _screen->loadFont(Screen::FID_8_FNT, "8FAT.FNT"); - } _screen->loadFont(Screen::FID_GOLDFONT_FNT, "GOLDFONT.FNT"); _screen->setAnimBlockPtr(3500); _screen->setScreenDim(0); assert(_introStringsSize == 21); - for (int i = 0; i < 21; i++) { + for (int i = 0; i < 21; i++) _introStringsDuration[i] = strlen(_introStrings[i]) * 8; - } // No mouse display in demo if (_flags.isDemo) @@ -127,3 +124,4 @@ void KyraEngine_v2::mainMenu() { } } // end of namespace Kyra + diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index be3ef8f241..18da31c4a7 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -121,3 +121,4 @@ private: } // end of namespace Kyra #endif + diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp index 3c0bd0f140..2301697d61 100644 --- a/engines/kyra/kyra_v3.cpp +++ b/engines/kyra/kyra_v3.cpp @@ -117,9 +117,8 @@ int KyraEngine_v3::init() { _mouseSHPBuf = _res->fileData("MOUSE.SHP", 0); assert(_mouseSHPBuf); - for (int i = 0; i <= 6; ++i) { + for (int i = 0; i <= 6; ++i) _gameShapes[i] = _screen->getPtrToShape(_mouseSHPBuf, i); - } initItems(); @@ -244,11 +243,10 @@ void KyraEngine_v3::playMenuAudioFile() { Common::File *handle = new Common::File(); uint32 temp = 0; _res->getFileHandle(_menuAudioFile, &temp, *handle); - if (handle->isOpen()) { + if (handle->isOpen()) _musicSoundChannel = _soundDigital->playSound(handle, true); - } else { + else delete handle; - } } void KyraEngine_v3::playMusicTrack(int track, int force) { @@ -256,11 +254,10 @@ void KyraEngine_v3::playMusicTrack(int track, int force) { // XXX byte_2C87C compare - if (_musicSoundChannel != -1 && !_soundDigital->isPlaying(_musicSoundChannel)) { + if (_musicSoundChannel != -1 && !_soundDigital->isPlaying(_musicSoundChannel)) force = 1; - } else if (_musicSoundChannel == -1) { + else if (_musicSoundChannel == -1) force = 1; - } if (track == _curMusicTrack && !force) return; @@ -273,11 +270,10 @@ void KyraEngine_v3::playMusicTrack(int track, int force) { Common::File *handle = new Common::File(); uint32 temp = 0; _res->getFileHandle(_soundList[track], &temp, *handle); - if (handle->isOpen()) { + if (handle->isOpen()) _musicSoundChannel = _soundDigital->playSound(handle); - } else { + else delete handle; - } } _musicSoundChannel = track; @@ -559,18 +555,16 @@ uint8 *KyraEngine_v3::allocTableSpace(uint8 *buf, int size, int id) { *(uint32*)(buf2 + 16) = unkValue1 + size; memcpy(_tableBuffer1 + entries * 14 + 12, _tableBuffer1 + unk1 * 14 + 12, 14); } else { - if (usedEntry > unk1) { + if (usedEntry > unk1) memcpy(buf2 + 12, _tableBuffer1 + unk1 * 14 + 12, 14); - } int temp = *(uint16*)(_tableBuffer1 + 2) - 1; *(uint16*)(_tableBuffer1 + 2) = temp; temp = *(uint16*)(_tableBuffer1 + 4) - 1; *(uint16*)(_tableBuffer1 + 4) = temp; } - for (int i = unk1; i > ok; --i) { + for (int i = unk1; i > ok; --i) memcpy(_tableBuffer1 + i * 14 + 12, _tableBuffer1 + (i-1) * 14 + 12, 14); - } buf2 = _tableBuffer1 + ok * 14; @@ -613,9 +607,8 @@ uint8 *KyraEngine_v3::findIdInTable(uint8 *buf, int id) { uint32 idVal = id; uint8 *ptr = (uint8*)bsearch(&idVal, _tableBuffer1 + 12, *(uint16*)(_tableBuffer1), 14, &tableIdCompare); - if (!ptr) { + if (!ptr) return 0; - } return _tableBuffer2 + *(uint32*)(ptr + 4); } @@ -633,15 +626,13 @@ void KyraEngine_v3::initItems() { _screen->loadBitmap("ITEMS.CSH", 3, 3, 0); - for (int i = 248; i <= 319; ++i) { + for (int i = 248; i <= 319; ++i) addShapeToTable(_screen->getCPagePtr(3), i, i-248); - } _screen->loadBitmap("ITEMS2.CSH", 3, 3, 0); - for (int i = 320; i <= 397; ++i) { + for (int i = 320; i <= 397; ++i) addShapeToTable(_screen->getCPagePtr(3), i, i-320); - } uint32 size = 0; uint8 *itemsDat = _res->fileData("_ITEMS.DAT", &size); @@ -703,3 +694,4 @@ bool KyraEngine_v3::loadLanguageFile(const char *file, uint8 *&buffer) { } } // end of namespace Kyra + diff --git a/engines/kyra/kyra_v3.h b/engines/kyra/kyra_v3.h index 7f3f476c15..13cc91211b 100644 --- a/engines/kyra/kyra_v3.h +++ b/engines/kyra/kyra_v3.h @@ -144,3 +144,4 @@ private: } // end of namespace Kyra #endif + diff --git a/engines/kyra/plugin.cpp b/engines/kyra/plugin.cpp index 905b0f8911..48515dd6ae 100644 --- a/engines/kyra/plugin.cpp +++ b/engines/kyra/plugin.cpp @@ -141,17 +141,15 @@ PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) { flags.platform = gd->desc.platform; Common::Platform platform = Common::parsePlatform(ConfMan.get("platform")); - if (platform != Common::kPlatformUnknown) { + if (platform != Common::kPlatformUnknown) flags.platform = platform; - } if (flags.lang == Common::UNK_LANG) { Common::Language lang = Common::parseLanguage(ConfMan.get("language")); - if (lang != Common::UNK_LANG) { + if (lang != Common::UNK_LANG) flags.lang = lang; - } else { + else flags.lang = Common::EN_ANY; - } } if (!scumm_stricmp("kyra1", gameid)) { @@ -167,3 +165,4 @@ PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) { } REGISTER_PLUGIN(KYRA, "Legend of Kyrandia Engine", "The Legend of Kyrandia (C) Westwood Studios"); + diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index 193ce839c1..2d6d54da34 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -81,9 +81,8 @@ Resource::Resource(KyraEngine *vm) { } Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); - for (;start != _pakfiles.end(); ++start) { + for (;start != _pakfiles.end(); ++start) (*start)->protect(); - } } else { for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { Common::String filename = file->name(); @@ -94,9 +93,8 @@ Resource::Resource(KyraEngine *vm) { continue; if (filename.hasSuffix("PAK") || filename.hasSuffix("APK")) { - if (!loadPakFile(file->name())) { + if (!loadPakFile(file->name())) error("couldn't open pakfile '%s'", file->name().c_str()); - } } } @@ -534,3 +532,4 @@ uint32 INSFile::getFileSize(uint hash) { } } // end of namespace Kyra + diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h index 27e3917c3f..08dbe727e3 100644 --- a/engines/kyra/resource.h +++ b/engines/kyra/resource.h @@ -303,3 +303,4 @@ private: } // end of namespace Kyra #endif + diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp index f401148613..c857bcc765 100644 --- a/engines/kyra/saveload.cpp +++ b/engines/kyra/saveload.cpp @@ -126,19 +126,15 @@ void KyraEngine::loadGame(const char *fileName) { _marbleVaseItem = in->readSint16BE(); _itemInHand = in->readByte(); - for (int i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) _birthstoneGemTable[i] = in->readByte(); - } - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 3; ++i) _idolGemsTable[i] = in->readByte(); - } - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 3; ++i) _foyerItemTable[i] = in->readByte(); - } _cauldronState = in->readByte(); - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) _crystalState[i] = in->readByte(); - } _brandonStatusBit = in->readUint16BE(); _brandonStatusBit0x02Flag = in->readByte(); @@ -207,7 +203,6 @@ void KyraEngine::loadGame(const char *fileName) { if (version >= 7) { _curSfxFile = in->readByte(); - // In the first version there this entry was introduced, // it wasn't made sure that _curSfxFile was initialized // so if it's out of bounds we just set it to 0. @@ -225,9 +220,8 @@ void KyraEngine::loadGame(const char *fileName) { _screen->loadBitmap("AMULET3.CPS", 10, 10, 0); if (!queryGameFlag(0xF1)) { for (int i = 0x55; i <= 0x5A; ++i) { - if (queryGameFlag(i)) { + if (queryGameFlag(i)) seq_createAmuletJewel(i-0x55, 10, 1, 1); - } } } _screen->copyRegion(0, 0, 0, 0, 320, 200, 10, 8); @@ -308,19 +302,15 @@ void KyraEngine::saveGame(const char *fileName, const char *saveName) { out->writeSint16BE(_marbleVaseItem); out->writeByte(_itemInHand); - for (int i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) out->writeByte(_birthstoneGemTable[i]); - } - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 3; ++i) out->writeByte(_idolGemsTable[i]); - } - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 3; ++i) out->writeByte(_foyerItemTable[i]); - } out->writeByte(_cauldronState); - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) out->writeByte(_crystalState[i]); - } out->writeUint16BE(_brandonStatusBit); out->writeByte(_brandonStatusBit0x02Flag); @@ -333,11 +323,10 @@ void KyraEngine::saveGame(const char *fileName, const char *saveName) { for (int i = 0; i < 32; i++) { out->writeByte(_timers[i].active); out->writeSint32BE(_timers[i].countdown); - if (_system->getMillis() >= _timers[i].nextRun) { + if (_system->getMillis() >= _timers[i].nextRun) out->writeUint32BE(0); - } else { + else out->writeUint32BE(_timers[i].nextRun - _system->getMillis()); - } } out->writeUint32BE(sizeof(_flagsTable)); @@ -371,3 +360,4 @@ void KyraEngine::saveGame(const char *fileName, const char *saveName) { delete out; } } // end of namespace Kyra + diff --git a/engines/kyra/scene.cpp b/engines/kyra/scene.cpp index 0d47625bc1..f72f0cf231 100644 --- a/engines/kyra/scene.cpp +++ b/engines/kyra/scene.cpp @@ -43,24 +43,23 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int _handleInput = false; _abortWalkFlag = false; _abortWalkFlag2 = false; - // just used for fm towns version, it should only load the sfx music file there + if (_flags.platform == Common::kPlatformFMTowns) { int newSfxFile = -1; - if (_currentCharacter->sceneId == 7 && sceneId == 24) { + if (_currentCharacter->sceneId == 7 && sceneId == 24) newSfxFile = 2; - } else if (_currentCharacter->sceneId == 25 && sceneId == 109) { + else if (_currentCharacter->sceneId == 25 && sceneId == 109) newSfxFile = 3; - } else if (_currentCharacter->sceneId == 120 && sceneId == 37) { + else if (_currentCharacter->sceneId == 120 && sceneId == 37) newSfxFile = 4; - } else if (_currentCharacter->sceneId == 52 && sceneId == 199) { + else if (_currentCharacter->sceneId == 52 && sceneId == 199) newSfxFile = 5; - } else if (_currentCharacter->sceneId == 37 && sceneId == 120) { + else if (_currentCharacter->sceneId == 37 && sceneId == 120) newSfxFile = 3; - } else if (_currentCharacter->sceneId == 109 && sceneId == 25) { + else if (_currentCharacter->sceneId == 109 && sceneId == 25) newSfxFile = 2; - } else if (_currentCharacter->sceneId == 24 && sceneId == 7) { + else if (_currentCharacter->sceneId == 24 && sceneId == 7) newSfxFile = 1; - } if (newSfxFile != -1) { _curSfxFile = newSfxFile; @@ -128,16 +127,14 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int moveCharacterToPos(0, facing, xpos, ypos); } - for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) { + for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) _movieObjects[i]->close(); - } if (!brandonAlive) { _scriptInterpreter->initScript(_scriptClick, _scriptClickData); _scriptInterpreter->startScript(_scriptClick, 5); - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } } memset(_entranceMouseCursorTracks, 0xFFFF, sizeof(uint16)*4); @@ -166,22 +163,17 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int _walkBlockSouth = currentRoom->southExit; _walkBlockWest = currentRoom->westExit; - if (_walkBlockNorth == 0xFFFF) { + if (_walkBlockNorth == 0xFFFF) _screen->blockOutRegion(0, 0, 320, (_northExitHeight & 0xFF)+3); - } - if (_walkBlockEast == 0xFFFF) { + if (_walkBlockEast == 0xFFFF) _screen->blockOutRegion(312, 0, 8, 139); - } - if (_walkBlockSouth == 0xFFFF) { + if (_walkBlockSouth == 0xFFFF) _screen->blockOutRegion(0, 135, 320, 8); - } - if (_walkBlockWest == 0xFFFF) { + if (_walkBlockWest == 0xFFFF) _screen->blockOutRegion(0, 0, 8, 139); - } - if (!brandonAlive) { + if (!brandonAlive) updatePlayerItemsForScene(); - } startSceneScript(brandonAlive); setupSceneItems(); @@ -190,9 +182,8 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int _loopFlag2 = 0; _screen->showMouse(); - if (!brandonAlive) { + if (!brandonAlive) seq_poisonDeathNow(0); - } updateMousePointer(true); _changedScene = true; } @@ -200,6 +191,7 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int void KyraEngine::transcendScenes(int roomIndex, int roomName) { debugC(9, kDebugLevelMain, "KyraEngine::transcendScenes(%d, %d)", roomIndex, roomName); assert(roomIndex < _roomTableSize); + if (_flags.isTalkie) { char file[32]; assert(roomIndex < _roomTableSize); @@ -209,6 +201,7 @@ void KyraEngine::transcendScenes(int roomIndex, int roomName) { strcat(file, ".VRM"); _res->unloadPakFile(file); } + _roomTable[roomIndex].nameIndex = roomName; _unkScreenVar2 = 1; _unkScreenVar3 = 1; @@ -238,6 +231,7 @@ void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypo disableTimer(14); disableTimer(18); uint32 nextFrame = 0; + switch (facing) { case 0: while (ypos < ch->y1) { @@ -274,6 +268,7 @@ void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypo default: break; } + enableTimer(19); enableTimer(14); enableTimer(18); @@ -288,13 +283,13 @@ void KyraEngine::setCharacterPositionWithUpdate(int character) { _animator->updateAllObjectShapes(); updateTextFade(); - if (_currentCharacter->sceneId == 210) { + if (_currentCharacter->sceneId == 210) updateKyragemFading(); - } } int KyraEngine::setCharacterPosition(int character, int *facingTable) { debugC(9, kDebugLevelMain, "KyraEngine::setCharacterPosition(%d, %p)", character, (const void *)facingTable); + if (character == 0) { _currentCharacter->x1 += _charXPosTable[_currentCharacter->facing]; _currentCharacter->y1 += _charYPosTable[_currentCharacter->facing]; @@ -303,9 +298,8 @@ int KyraEngine::setCharacterPosition(int character, int *facingTable) { } else { _characterList[character].x1 += _charXPosTable[_characterList[character].facing]; _characterList[character].y1 += _charYPosTable[_characterList[character].facing]; - if (_characterList[character].sceneId == _currentCharacter->sceneId) { + if (_characterList[character].sceneId == _currentCharacter->sceneId) setCharacterPositionHelper(character, 0); - } } return 0; } @@ -335,24 +329,21 @@ void KyraEngine::setCharacterPositionHelper(int character, int *facingTable) { if (facing - 1 != 0) { if (facing != 4) { if (facing == 3 || facing == 5) { - if (facingIsFour[character] > 2) { + if (facingIsFour[character] > 2) facing = 4; - } resetTables = true; } } else { ++facingIsFour[character]; } } else { - if (facingIsZero[character] > 2) { + if (facingIsZero[character] > 2) facing = 0; - } resetTables = true; } } else { - if (facingIsZero[character] > 2) { + if (facingIsZero[character] > 2) facing = 0; - } resetTables = true; } @@ -373,35 +364,26 @@ void KyraEngine::setCharacterPositionHelper(int character, int *facingTable) { }; if (facing == 0) { - if (maxAnimationFrame[36+character] > ch->currentAnimFrame) { + if (maxAnimationFrame[36+character] > ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[36+character]; - } - if (maxAnimationFrame[30+character] < ch->currentAnimFrame) { + if (maxAnimationFrame[30+character] < ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[36+character]; - } } else if (facing == 4) { - if (maxAnimationFrame[18+character] > ch->currentAnimFrame) { + if (maxAnimationFrame[18+character] > ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[18+character]; - } - if (maxAnimationFrame[12+character] < ch->currentAnimFrame) { + if (maxAnimationFrame[12+character] < ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[18+character]; - } } else { - if (maxAnimationFrame[18+character] < ch->currentAnimFrame) { + if (maxAnimationFrame[18+character] < ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[30+character]; - } - if (maxAnimationFrame[character] == ch->currentAnimFrame) { + if (maxAnimationFrame[character] == ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[6+character]; - } - if (maxAnimationFrame[character] < ch->currentAnimFrame) { + if (maxAnimationFrame[character] < ch->currentAnimFrame) ch->currentAnimFrame = maxAnimationFrame[6+character]+2; - } } - if (character == 0) { - if (_brandonStatusBit & 0x10) - ch->currentAnimFrame = 88; - } + if (character == 0 && (_brandonStatusBit & 0x10)) + ch->currentAnimFrame = 88; _animator->animRefreshNPC(character); } @@ -455,9 +437,8 @@ void KyraEngine::startSceneScript(int brandonAlive) { _exitListPtr = 0; _scaleMode = 1; - for (int i = 0; i < 145; ++i) { + for (int i = 0; i < 145; ++i) _scaleTable[i] = 256; - } clearNoDropRects(); _scriptInterpreter->initScript(_scriptClick, _scriptClickData); @@ -469,9 +450,8 @@ void KyraEngine::startSceneScript(int brandonAlive) { _scriptClick->variables[0] = _currentCharacter->sceneId; _scriptClick->variables[7] = brandonAlive; - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } } void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { @@ -512,26 +492,20 @@ void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { break; } - if ((uint8)(_northExitHeight & 0xFF) + 2 >= ypos) { + if ((uint8)(_northExitHeight & 0xFF) + 2 >= ypos) ypos = (_northExitHeight & 0xFF) + 4; - } - if (xpos >= 308) { + if (xpos >= 308) xpos = 304; - } - if ((uint8)(_northExitHeight >> 8) - 2 <= ypos) { + if ((uint8)(_northExitHeight >> 8) - 2 <= ypos) ypos = (_northExitHeight >> 8) - 4; - } - if (xpos <= 12) { + if (xpos <= 12) xpos = 16; - } } - if (_brandonPosX > -1) { + if (_brandonPosX > -1) xpos = _brandonPosX; - } - if (_brandonPosY > -1) { + if (_brandonPosY > -1) ypos = _brandonPosY; - } int16 ypos2 = 0; if (_brandonPosX > -1 && _brandonPosY > -1) { @@ -640,23 +614,20 @@ void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) { initSceneObjectList(brandonAlive); - if (unk1 && brandonAlive == 0) { + if (unk1 && brandonAlive == 0) moveCharacterToPos(0, facing, xpos2, ypos2); - } _scriptClick->variables[4] = _itemInHand; _scriptClick->variables[7] = brandonAlive; _scriptInterpreter->startScript(_scriptClick, 3); - while (_scriptInterpreter->validScript(_scriptClick)) { + while (_scriptInterpreter->validScript(_scriptClick)) _scriptInterpreter->runScript(_scriptClick); - } } void KyraEngine::initSceneObjectList(int brandonAlive) { debugC(9, kDebugLevelMain, "KyraEngine::initSceneObjectList(%d)", brandonAlive); - for (int i = 0; i < 28; ++i) { + for (int i = 0; i < 28; ++i) _animator->actors()[i].active = 0; - } int startAnimFrame = 0; @@ -668,6 +639,7 @@ void KyraEngine::initSceneObjectList(int brandonAlive) { startAnimFrame = _currentCharacter->currentAnimFrame-7; int xOffset = _defaultShapeTable[startAnimFrame].xOffset; int yOffset = _defaultShapeTable[startAnimFrame].yOffset; + if (_scaleMode) { curAnimState->x1 = _currentCharacter->x1; curAnimState->y1 = _currentCharacter->y1; @@ -681,6 +653,7 @@ void KyraEngine::initSceneObjectList(int brandonAlive) { curAnimState->x1 = _currentCharacter->x1 + xOffset; curAnimState->y1 = _currentCharacter->y1 + yOffset; } + curAnimState->x2 = curAnimState->x1; curAnimState->y2 = curAnimState->y1; curAnimState->refreshFlag = 1; @@ -727,11 +700,10 @@ void KyraEngine::initSceneObjectList(int brandonAlive) { curAnimState->refreshFlag = 1; curAnimState->bkgdChangeFlag = 1; - if (ch->facing >= 1 && ch->facing <= 3) { + if (ch->facing >= 1 && ch->facing <= 3) curAnimState->flags |= 1; - } else if (ch->facing >= 5 && ch->facing <= 7) { + else if (ch->facing >= 5 && ch->facing <= 7) curAnimState->flags &= 0xFFFFFFFE; - } _animator->addObjectToQueue(curAnimState); @@ -827,9 +799,8 @@ void KyraEngine::initSceneScreen(int brandonAlive) { if (_flags.platform == Common::kPlatformAmiga) { if (_unkScreenVar1 && !queryGameFlag(0xF0)) { memset(_screen->getPalette(2), 0, 32*3); - if (_currentCharacter->sceneId != 117 || !queryGameFlag(0xB3)) { + if (_currentCharacter->sceneId != 117 || !queryGameFlag(0xB3)) _screen->setScreenPalette(_screen->getPalette(2)); - } } if (_unkScreenVar2 == 1) @@ -838,13 +809,11 @@ void KyraEngine::initSceneScreen(int brandonAlive) { _screen->copyRegion(8, 8, 8, 8, 304, 128, 2, 0); if (_unkScreenVar1 && !queryGameFlag(0xA0)) { - if (_currentCharacter->sceneId == 45 && _paletteChanged) { + if (_currentCharacter->sceneId == 45 && _paletteChanged) memcpy(_screen->getPalette(0) + 12*3, _screen->getPalette(4) + 12*3, 2); - } - if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245 && (_brandonStatusBit & 1)) { + if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245 && (_brandonStatusBit & 1)) memcpy(_screen->getPalette(0), _screen->getPalette(0) + 320*3, 64); - } _screen->setScreenPalette(_screen->getPalette(0)); } @@ -859,11 +828,10 @@ void KyraEngine::initSceneScreen(int brandonAlive) { _screen->setScreenPalette(_screen->getPalette(0)); } - if (_unkScreenVar2 == 1) { + if (_unkScreenVar2 == 1) _screen->shuffleScreen(8, 8, 304, 128, 2, 0, _unkScreenVar3, false); - } else { + else _screen->copyRegion(8, 8, 8, 8, 304, 128, 2, 0); - } if (_unkScreenVar1 && _paletteChanged) { if (!queryGameFlag(0xA0)) { @@ -902,11 +870,12 @@ void KyraEngine::initSceneScreen(int brandonAlive) { int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) { debugC(9, kDebugLevelMain, "KyraEngine::handleSceneChange(%d, %d, %d, %d)", xpos, ypos, unk1, frameReset); - if (queryGameFlag(0xEF)) { + if (queryGameFlag(0xEF)) unk1 = 0; - } + int sceneId = _currentCharacter->sceneId; _pathfinderFlag = 0; + if (xpos < 12) { if (_roomTable[sceneId].westExit != 0xFFFF) { xpos = 12; @@ -938,31 +907,32 @@ int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) int temp = xpos - _currentCharacter->x1; if (ABS(temp) < 4) { temp = ypos - _currentCharacter->y1; - if (ABS(temp) < 2) { + if (ABS(temp) < 2) return 0; - } } int x = (int16)(_currentCharacter->x1 & 0xFFFC); int y = (int16)(_currentCharacter->y1 & 0xFFFE); xpos = (int16)(xpos & 0xFFFC); ypos = (int16)(ypos & 0xFFFE); + int ret = findWay(x, y, xpos, ypos, _movFacingTable, 150); _pathfinderFlag = 0; - if (ret >= _lastFindWayRet) { + + if (ret >= _lastFindWayRet) _lastFindWayRet = ret; - } - if (ret == 0x7D00 || ret == 0) { + + if (ret == 0x7D00 || ret == 0) return 0; - } + return processSceneChange(_movFacingTable, unk1, frameReset); } int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { debugC(9, kDebugLevelMain, "KyraEngine::processSceneChange(%p, %d, %d)", (const void *)table, unk1, frameReset); - if (queryGameFlag(0xEF)) { + if (queryGameFlag(0xEF)) unk1 = 0; - } + int *tableStart = table; _sceneChangeState = 0; _loopFlag2 = 0; @@ -1013,23 +983,22 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { } } - if (forceContinue || !running) { + if (forceContinue || !running) continue; - } int temp = 0; - if (table == tableStart || table[1] == 8) { + if (table == tableStart || table[1] == 8) temp = setCharacterPosition(0, 0); - } else { + else temp = setCharacterPosition(0, table); - } - if (temp) { + + if (temp) ++table; - } nextFrame = getTimerDelay(5) * _tickLength + _system->getMillis(); while (_system->getMillis() < nextFrame) { updateGameTimers(); + if (_currentCharacter->sceneId == 210) { updateKyragemFading(); if (seq_playEnd() || _beadStateVar == 4 || _beadStateVar == 5) { @@ -1038,14 +1007,15 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { break; } } + if ((nextFrame - _system->getMillis()) >= 10) delay(10, true); } } - if (frameReset && !(_brandonStatusBit & 2)) { + if (frameReset && !(_brandonStatusBit & 2)) _currentCharacter->currentAnimFrame = 7; - } + _animator->animRefreshNPC(0); _animator->updateAllObjectShapes(); return returnValue; @@ -1054,9 +1024,8 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) { int KyraEngine::changeScene(int facing) { debugC(9, kDebugLevelMain, "KyraEngine::changeScene(%d)", facing); if (queryGameFlag(0xEF)) { - if (_currentCharacter->sceneId == 5) { + if (_currentCharacter->sceneId == 5) return 0; - } } int xpos = _charXPosTable[facing] + _currentCharacter->x1; @@ -1069,7 +1038,7 @@ int KyraEngine::changeScene(int facing) { if (_exitListPtr) { int16 *ptr = _exitListPtr; - // this loop should be only entered on time, seems to be some hack in the original + // this loop should be only entered one time, seems to be some hack in the original while (true) { if (*ptr == -1) break; @@ -1078,12 +1047,14 @@ int KyraEngine::changeScene(int facing) { ptr += 10; break; } + _brandonPosX = ptr[6]; _brandonPosY = ptr[7]; uint16 sceneId = ptr[5]; facing = ptr[4]; int unk1 = ptr[8]; int unk2 = ptr[9]; + if (sceneId == 0xFFFF) { switch (facing) { case 0: @@ -1179,12 +1150,14 @@ void KyraEngine::setCharactersInDefaultScene() { for (int i = 1; i < 5; ++i) { Character *cur = &_characterList[i]; //cur->field_20 = 0; + const uint32 *curTable = defaultSceneTable[i-1]; cur->sceneId = curTable[0]; - if (cur->sceneId == _currentCharacter->sceneId) { + + if (cur->sceneId == _currentCharacter->sceneId) //++cur->field_20; cur->sceneId = curTable[1/*cur->field_20*/]; - } + //cur->field_23 = curTable[cur->field_20+1]; } } @@ -1199,6 +1172,7 @@ void KyraEngine::setCharactersPositions(int character) { 0x67, 0x67, 0x60, 0x5A, 0x71, 0x76 }; + assert(character < ARRAYSIZE(initXPosTable)); Character *edit = &_characterList[character]; edit->x1 = edit->x2 = initXPosTable[character]; @@ -1291,9 +1265,8 @@ int KyraEngine::findWay(int x, int y, int toX, int toY, int *moveTable, int move } } - if (temp != 0x7D00 || tempValue != 0x7D00) { + if (temp != 0x7D00 || tempValue != 0x7D00) break; - } } if (temp < tempValue) { @@ -1315,10 +1288,10 @@ int KyraEngine::findWay(int x, int y, int toX, int toY, int *moveTable, int move } x = curX; y = curY; - if (curX == toX && curY == toY) { + if (curX == toX && curY == toY) break; - } } + delete [] pathTable1; delete [] pathTable2; moveTable[lastUsedEntry] = 8; @@ -1351,9 +1324,8 @@ int KyraEngine::findSubPath(int x, int y, int toX, int toY, int *moveTable, int while (true) { changePosTowardsFacing(xpos1, ypos1, facingTable1[start*8 + newFacing2]); if (!lineIsPassable(xpos1, ypos1)) { - if (facingTable1[start*8 + newFacing2] == newFacing) { + if (facingTable1[start*8 + newFacing2] == newFacing) return 0x7D00; - } newFacing2 = facingTable1[start*8 + newFacing2]; xpos1 = x; ypos1 = y; @@ -1378,19 +1350,20 @@ int KyraEngine::findSubPath(int x, int y, int toX, int toY, int *moveTable, int } } } + moveTable[position++] = newFacing; x = xpos1; y = ypos1; - if (x == toX && y == toY) { + + if (x == toX && y == toY) return position; - } - if (xpos1 == xpos2 && ypos1 == ypos2) { + if (xpos1 == xpos2 && ypos1 == ypos2) break; - } newFacing = facingTable3[start*8 + newFacing]; } + return 0x7D00; } @@ -1432,6 +1405,7 @@ int KyraEngine::getFacingFromPointToPoint(int x, int y, int toX, int toY) { } else { facingEntry <<= 1; } + assert(facingEntry < ARRAYSIZE(facingTable)); return facingTable[facingEntry]; } @@ -1471,13 +1445,11 @@ bool KyraEngine::lineIsPassable(int x, int y) { return true; } - if (y > 137) { + if (y > 137) return false; - } - if (y < 0) { + if (y < 0) y = 0; - } int ypos = 8; if (_scaleMode) { @@ -1541,19 +1513,19 @@ int KyraEngine::getMoveTableSize(int *moveTable) { } if (tempPosition == moveTable && *tempPosition == 9) { - while (*tempPosition != 8 && *tempPosition == 9) { + while (*tempPosition != 8 && *tempPosition == 9) ++tempPosition; - } - if (*tempPosition == 8) { + + if (*tempPosition == 8) return 0; - } } oldPosition = tempPosition; curPosition = oldPosition+1; - while (*curPosition != 8 && *curPosition == 9) { + + while (*curPosition != 8 && *curPosition == 9) ++curPosition; - } + continue; } @@ -1566,20 +1538,19 @@ int KyraEngine::getMoveTableSize(int *moveTable) { curPosition = oldPosition; oldPosition = tempPosition; while (true) { - if (tempPosition == moveTable) { + if (tempPosition == moveTable) break; - } + --tempPosition; - if (*tempPosition != 9) { + if (*tempPosition != 9) break; - } + } } else { while (true) { ++curPosition; - if (*curPosition != 9) { + if (*curPosition != 9) break; - } } } continue; @@ -1588,11 +1559,11 @@ int KyraEngine::getMoveTableSize(int *moveTable) { tempPosition = oldPosition; oldPosition = curPosition; ++retValue; + while (true) { ++curPosition; - if (*curPosition != 9) { + if (*curPosition != 9) break; - } } } @@ -1614,9 +1585,11 @@ void KyraEngine::setupSceneResource(int sceneId) { strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".VRM"); _res->unloadPakFile(file); + strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".PAK"); - _res->unloadPakFile(file); + _res->unloadPakFile(file); + strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".APK"); _res->unloadPakFile(file); @@ -1632,10 +1605,12 @@ void KyraEngine::setupSceneResource(int sceneId) { strcat(file, ".VRM"); if (Common::File::exists(file)) _res->loadPakFile(file); + strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".PAK"); if (Common::File::exists(file)) _res->loadPakFile(file); + strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".APK"); if (Common::File::exists(file)) @@ -1643,3 +1618,4 @@ void KyraEngine::setupSceneResource(int sceneId) { } } // end of namespace Kyra + diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index ef3e7badfa..1b67ed04b3 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -37,17 +37,19 @@ Screen::Screen(KyraEngine *vm, OSystem *system) } Screen::~Screen() { - for (int i = 0; i < SCREEN_OVLS_NUM; ++i) { + for (int i = 0; i < SCREEN_OVLS_NUM; ++i) delete [] _sjisOverlayPtrs[i]; - } + for (int pageNum = 0; pageNum < SCREEN_PAGE_NUM; pageNum += 2) { delete [] _pagePtrs[pageNum]; _pagePtrs[pageNum] = _pagePtrs[pageNum + 1] = 0; } + for (int f = 0; f < ARRAYSIZE(_fonts); ++f) { delete[] _fonts[f].fontData; _fonts[f].fontData = NULL; } + delete [] _sjisFontData; delete [] _sjisTempPage; delete [] _currentPalette; @@ -56,9 +58,8 @@ Screen::~Screen() { delete [] _animBlockPtr; if (_vm->gameFlags().platform != Common::kPlatformAmiga) { - for (int i = 0; i < ARRAYSIZE(_palettes); ++i) { + for (int i = 0; i < ARRAYSIZE(_palettes); ++i) delete [] _palettes[i]; - } } delete [] _bitBlitRects; @@ -135,9 +136,8 @@ bool Screen::init() { assert(_currentPalette); memset(_currentPalette, 0, 1248); - for (int i = 0; i < 6; ++i) { + for (int i = 0; i < 6; ++i) _palettes[i] = _currentPalette + (i+1)*96; - } } else { _currentPalette = new uint8[768]; assert(_currentPalette); @@ -154,9 +154,8 @@ bool Screen::init() { _charWidth = 0; _charOffset = 0; memset(_fonts, 0, sizeof(_fonts)); - for (int i = 0; i < ARRAYSIZE(_textColorsMap); ++i) { + for (int i = 0; i < ARRAYSIZE(_textColorsMap); ++i) _textColorsMap[i] = i; - } _decodeShapeBuffer = NULL; _decodeShapeBufferSize = 0; _animBlockPtr = NULL; @@ -372,17 +371,18 @@ void Screen::fadePalette(const uint8 *palData, int delay) { maxDiff = diff; } } + int16 delayInc = delay << 8; - if (maxDiff != 0) { + if (maxDiff != 0) delayInc /= maxDiff; - } + delay = delayInc; for (diff = 1; diff <= maxDiff; ++diff) { - if (delayInc >= 512) { + if (delayInc >= 512) break; - } delayInc += delay; } + int delayAcc = 0; while (!_vm->quit()) { delayAcc += delayInc; @@ -394,22 +394,23 @@ void Screen::fadePalette(const uint8 *palData, int delay) { needRefresh = true; if (c1 > c2) { c2 += diff; - if (c1 < c2) { + if (c1 < c2) c2 = c1; - } } + if (c1 < c2) { c2 -= diff; - if (c1 > c2) { + if (c1 > c2) c2 = c1; - } } + fadePal[i] = (uint8)c2; } } - if (!needRefresh) { + + if (!needRefresh) break; - } + setScreenPalette(fadePal); _system->updateScreen(); //_system->delayMillis((delayAcc >> 8) * 1000 / 60); @@ -511,9 +512,8 @@ void Screen::copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPag if (flags & CR_X_FLIPPED) { while (h--) { for (int i = 0; i < w; ++i) { - if (src[i] || (flags & CR_NO_P_CHECK)) { + if (src[i] || (flags & CR_NO_P_CHECK)) dst[w-i] = src[i]; - } } src += SCREEN_W; dst += SCREEN_W; @@ -521,9 +521,8 @@ void Screen::copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPag } else { while (h--) { for (int i = 0; i < w; ++i) { - if (src[i] || (flags & CR_NO_P_CHECK)) { + if (src[i] || (flags & CR_NO_P_CHECK)) dst[i] = src[i]; - } } src += SCREEN_W; dst += SCREEN_W; @@ -535,9 +534,9 @@ void Screen::copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 * debugC(9, kDebugLevelScreen, "Screen::copyRegionToBuffer(%d, %d, %d, %d, %d)", pageNum, x, y, w, h); assert(x >= 0 && x < Screen::SCREEN_W && y >= 0 && y < Screen::SCREEN_H && dest); uint8 *pagePtr = getPagePtr(pageNum); - for (int i = y; i < y + h; i++) { + + for (int i = y; i < y + h; i++) memcpy(dest + (i - y) * w, pagePtr + i * SCREEN_W + x, w); - } } void Screen::copyPage(uint8 srcPage, uint8 dstPage) { @@ -570,22 +569,22 @@ void Screen::copyBlockToPage(int pageNum, int x, int y, int w, int h, const uint void Screen::copyFromCurPageBlock(int x, int y, int w, int h, const uint8 *src) { debugC(9, kDebugLevelScreen, "Screen::copyFromCurPageBlock(%d, %d, %d, %d, %p)", x, y, w, h, (const void *)src); - if (x < 0) { + if (x < 0) x = 0; - } else if (x >= 40) { + else if (x >= 40) return; - } - if (x + w > 40) { + + if (x + w > 40) w = 40 - x; - } - if (y < 0) { + + if (y < 0) y = 0; - } else if (y >= 200) { + else if (y >= 200) return; - } - if (y + h > 200) { + + if (y + h > 200) h = 200 - y; - } + uint8 *dst = getPagePtr(_curPage) + y * SCREEN_W + x * 8; if (_curPage == 0 || _curPage == 1) @@ -603,22 +602,22 @@ void Screen::copyFromCurPageBlock(int x, int y, int w, int h, const uint8 *src) void Screen::copyCurPageBlock(int x, int y, int w, int h, uint8 *dst) { debugC(9, kDebugLevelScreen, "Screen::copyCurPageBlock(%d, %d, %d, %d, %p)", x, y, w, h, (const void *)dst); assert(dst); - if (x < 0) { + if (x < 0) x = 0; - } else if (x >= 40) { + else if (x >= 40) return; - } - if (x + w > 40) { + + if (x + w > 40) w = 40 - x; - } - if (y < 0) { + + if (y < 0) y = 0; - } else if (y >= 200) { + else if (y >= 200) return; - } - if (y + h > 200) { + + if (y + h > 200) h = 200 - y; - } + const uint8 *src = getPagePtr(_curPage) + y * SCREEN_W + x * 8; while (h--) { memcpy(dst, src, w*8); @@ -632,9 +631,9 @@ void Screen::shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPag assert(sx >= 0 && w <= SCREEN_W); int x; uint16 x_offs[SCREEN_W]; - for (x = 0; x < SCREEN_W; ++x) { + for (x = 0; x < SCREEN_W; ++x) x_offs[x] = x; - } + for (x = 0; x < w; ++x) { int i = _vm->_rnd.getRandomNumber(w - 1); SWAP(x_offs[x], x_offs[i]); @@ -643,9 +642,9 @@ void Screen::shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPag assert(sy >= 0 && h <= SCREEN_H); int y; uint8 y_offs[SCREEN_H]; - for (y = 0; y < SCREEN_H; ++y) { + for (y = 0; y < SCREEN_H; ++y) y_offs[y] = y; - } + for (y = 0; y < h; ++y) { int i = _vm->_rnd.getRandomNumber(h - 1); SWAP(y_offs[y], y_offs[i]); @@ -660,22 +659,20 @@ void Screen::shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPag int i = sx + x_offs[x]; int j = sy + y_offs[y_cur]; ++y_cur; - if (y_cur >= h) { + if (y_cur >= h) y_cur = 0; - } + uint8 color = getPagePixel(srcPage, i, j); - if (!transparent || color != 0) { + if (!transparent || color != 0) setPagePixel(dstPage, i, j, color); - } } // forcing full update for now _forceFullUpdate = true; updateScreen(); now = (int32)_system->getMillis(); wait = ticks * _vm->tickLength() - (now - start); - if (wait > 0) { + if (wait > 0) _vm->delay(wait); - } } copyOverlayRegion(sx, sy, sx, sy, w, h, srcPage, dstPage); @@ -689,9 +686,9 @@ void Screen::shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPag void Screen::fillRect(int x1, int y1, int x2, int y2, uint8 color, int pageNum) { debugC(9, kDebugLevelScreen, "Screen::fillRect(%d, %d, %d, %d, %d, %d)", x1, y1, x2, y2, color, pageNum); assert(x2 < SCREEN_W && y2 < SCREEN_H); - if (pageNum == -1) { + if (pageNum == -1) pageNum = _curPage; - } + uint8 *dst = getPagePtr(pageNum) + y1 * SCREEN_W + x1; if (pageNum == 0 || pageNum == 1) @@ -805,9 +802,7 @@ void Screen::setTextColorMap(const uint8 *cmap) { void Screen::setTextColor(const uint8 *cmap, int a, int b) { debugC(9, kDebugLevelScreen, "Screen::setTextColor(%p, %d, %d)", (const void *)cmap, a, b); - for (int i = a; i <= b; ++i) { - _textColorsMap[i] = *cmap++; - } + memcpy(&_textColorsMap[a], cmap, b-a+1); } bool Screen::loadFont(FontId fontId, const char *filename) { @@ -922,17 +917,16 @@ void Screen::printText(const char *str, int x, int y, uint8 color1, uint8 color2 const uint8 charHeightFnt = *(fnt->fontData + fnt->charSizeOffset + 4); uint8 charHeight = 0; - if (x < 0) { + if (x < 0) x = 0; - } else if (x >= SCREEN_W) { + else if (x >= SCREEN_W) return; - } + int x_start = x; - if (y < 0) { + if (y < 0) y = 0; - } else if (y >= SCREEN_H) { + else if (y >= SCREEN_H) return; - } while (1) { uint c = *str++; @@ -970,18 +964,19 @@ void Screen::drawCharANSI(uint8 c, int x, int y) { debugC(9, kDebugLevelScreen, "Screen::drawChar('%c', %d, %d)", c, x, y); Font *fnt = &_fonts[_currentFont]; uint8 *dst = getPagePtr(_curPage) + y * SCREEN_W + x; + uint16 bitmapOffset = READ_LE_UINT16(fnt->fontData + fnt->charBitmapOffset + c * 2); - if (bitmapOffset == 0) { + if (bitmapOffset == 0) return; - } + uint8 charWidth = *(fnt->fontData + fnt->charWidthTableOffset + c); - if (charWidth + x > SCREEN_W) { + if (charWidth + x > SCREEN_W) return; - } + uint8 charH0 = *(fnt->fontData + fnt->charSizeOffset + 4); - if (charH0 + y > SCREEN_H) { + if (charH0 + y > SCREEN_H) return; - } + uint8 charH1 = *(fnt->fontData + fnt->charHeightTableOffset + c * 2); uint8 charH2 = *(fnt->fontData + fnt->charHeightTableOffset + c * 2 + 1); charH0 -= charH1 + charH2; @@ -992,9 +987,8 @@ void Screen::drawCharANSI(uint8 c, int x, int y) { while (charH1--) { uint8 col = _textColorsMap[0]; for (int i = 0; i < charWidth; ++i) { - if (col != 0) { + if (col != 0) *dst = col; - } ++dst; } dst += pitch; @@ -1021,9 +1015,8 @@ void Screen::drawCharANSI(uint8 c, int x, int y) { while (charH0--) { uint8 col = _textColorsMap[0]; for (int i = 0; i < charWidth; ++i) { - if (col != 0) { + if (col != 0) *dst = col; - } ++dst; } dst += pitch; @@ -1067,19 +1060,21 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 *table3 = 0; uint8 *table4 = 0; - if (flags & 0x8000) { + if (flags & 0x8000) table2 = va_arg(args, uint8*); - } + if (flags & 0x100) { table = va_arg(args, uint8*); tableLoopCount = va_arg(args, int); if (!tableLoopCount) flags &= 0xFFFFFEFF; } + if (flags & 0x1000) { table3 = va_arg(args, uint8*); table4 = va_arg(args, uint8*); } + if (flags & 0x200) { drawShapeVar1 += 1; drawShapeVar1 &= 7; @@ -1087,12 +1082,15 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int drawShapeVar4 = 0; drawShapeVar5 = 256; } + if (flags & 0x4000) { drawShapeVar5 = va_arg(args, int); } + if (flags & 0x800) { drawLayer = va_arg(args, int); } + int scale_w, scale_h; if (flags & DSF_SCALE) { scale_w = va_arg(args, int); @@ -1105,9 +1103,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int int ppc = (flags >> 8) & 0x3F; const uint8 *src = shapeData; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) src += 2; - } + uint16 shapeFlags = READ_LE_UINT16(src); src += 2; int shapeHeight = *src++; @@ -1132,9 +1130,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int src += 3; uint16 frameSize = READ_LE_UINT16(src); src += 2; - if ((shapeFlags & 1) || (flags & 0x400)) { + if ((shapeFlags & 1) || (flags & 0x400)) src += 0x10; - } + if (!(shapeFlags & 2)) { decodeFrame4(src, _animBlockPtr, frameSize); src = _animBlockPtr; @@ -1146,6 +1144,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int _decodeShapeBuffer = new uint8[shapeSize]; _decodeShapeBufferSize = shapeSize; } + if (!_decodeShapeBuffer) { _decodeShapeBufferSize = 0; va_end(args); @@ -1156,9 +1155,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int // only used if shapeFlag & 1 is NOT zero const uint8 *colorTable = shapeData + 10; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) colorTable += 2; - } for (int j = 0; j < shapeHeight; ++j) { uint8 *dsbNextLine = decodedShapeFrame + shapeWidth; @@ -1168,9 +1166,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int if (code != 0) { // this is guessed if (shapeFlags & 1) { - if (code < 16) { + if (code < 16) *decodedShapeFrame++ = colorTable[code]; - } } else { *decodedShapeFrame++ = code; } @@ -1196,35 +1193,31 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int int x1, x2; if (x >= 0) { x1 = 0; - if (x + scaledShapeWidth < sx2) { + if (x + scaledShapeWidth < sx2) x2 = scaledShapeWidth; - } else { + else x2 = sx2 - x; - } } else { x2 = scaledShapeWidth; x1 = -x; x = 0; - if (x2 > sx2) { + if (x2 > sx2) x2 = sx2; - } } int y1, y2; if (y >= 0) { y1 = 0; - if (y + scaledShapeHeight < sy2) { + if (y + scaledShapeHeight < sy2) y2 = scaledShapeHeight; - } else { + else y2 = sy2 - y; - } } else { y2 = scaledShapeHeight; y1 = -y; y = 0; - if (y2 > sy2) { + if (y2 > sy2) y2 = sy2; - } } uint8 *dst = getPagePtr(pageNum) + y * SCREEN_W + x; @@ -1235,34 +1228,31 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int int scaleYTable[SCREEN_H]; assert(y1 >= 0 && y2 < SCREEN_H); - for (y = y1; y < y2; ++y) { + for (y = y1; y < y2; ++y) scaleYTable[y] = (y << 8) / scale_h; - } + int scaleXTable[SCREEN_W]; assert(x1 >= 0 && x2 < SCREEN_W); - for (x = x1; x < x2; ++x) { + for (x = x1; x < x2; ++x) scaleXTable[x] = (x << 8) / scale_w; - } const uint8 *shapeBuffer = _decodeShapeBuffer; - if (flags & DSF_Y_FLIPPED) { + if (flags & DSF_Y_FLIPPED) shapeBuffer += shapeWidth * (shapeHeight - 1); - } - if (flags & DSF_X_FLIPPED) { + if (flags & DSF_X_FLIPPED) shapeBuffer += shapeWidth - 1; - } for (y = y1; y < y2; ++y) { uint8 *dstNextLine = dst + SCREEN_W; int j = scaleYTable[y]; - if (flags & DSF_Y_FLIPPED) { + if (flags & DSF_Y_FLIPPED) j = -j; - } + for (x = x1; x < x2; ++x) { int xpos = scaleXTable[x]; - if (flags & DSF_X_FLIPPED) { + if (flags & DSF_X_FLIPPED) xpos = -xpos; - } + uint8 color = shapeBuffer[j * shapeWidth + xpos]; if (color != 0) { switch (ppc) { @@ -1271,9 +1261,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int break; case 1: - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } break; case 2: { @@ -1292,9 +1281,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int case 7: case 3: color = *dst; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } break; case 4: @@ -1303,9 +1291,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int case 5: color = table2[color]; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } break; case 6: { @@ -1327,9 +1314,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (drawLayer < pixel) { + if (drawLayer < pixel) color = *(_shapePages[1] + offset); - } } break; @@ -1338,12 +1324,12 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; + if (drawLayer < pixel) { color = *(_shapePages[1] + offset); } else { - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } } } break; @@ -1378,9 +1364,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int color = *(_shapePages[1] + offset); } else { color = *dst; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } } } break; @@ -1407,9 +1392,8 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int color = *(_shapePages[1] + offset); } else { color = table2[color]; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } } } break; @@ -1447,9 +1431,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int break; case 17: { - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } + uint8 newColor = table3[color]; if (!(newColor & 0x80)) { color = *dst; @@ -1479,9 +1463,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int case 23: case 19: { color = *dst; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } + uint8 newColor = table3[color]; if (!(newColor & 0x80)) { color = *dst; @@ -1502,9 +1486,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int case 21: { color = table2[color]; - for (int i = 0; i < tableLoopCount; ++i) { + for (int i = 0; i < tableLoopCount; ++i) color = table[color]; - } + uint8 newColor = table3[color]; if (!(newColor & 0x80)) { color = *dst; @@ -1542,9 +1526,9 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int uint8 pixel = *(_shapePages[0] + offset); pixel &= 0x7F; pixel &= 0x87; - if (drawLayer < pixel) { + if (drawLayer < pixel) color = *(_shapePages[1] + offset); - } + uint8 newColor = table3[color]; if (!(newColor & 0x80)) { color = *dst; @@ -1593,44 +1577,41 @@ uint Screen::decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize) { uint8 *dstEnd = dst + dstSize; while (1) { int count = dstEnd - dst; - if (count == 0) { + if (count == 0) break; - } + uint8 code = *src++; if (!(code & 0x80)) { // 8th bit isn't set int len = MIN(count, (code >> 4) + 3); //upper half of code is the length int offs = ((code & 0xF) << 8) | *src++; //lower half of code as byte 2 of offset. const uint8 *dstOffs = dst - offs; - while (len--) { + while (len--) *dst++ = *dstOffs++; - } } else if (code & 0x40) { // 7th bit is set int len = (code & 0x3F) + 3; if (code == 0xFE) { len = READ_LE_UINT16(src); src += 2; - if (len > count) { + if (len > count) len = count; - } + memset(dst, *src++, len); dst += len; } else { - if (code == 0xFF) { + if (code == 0xFF) len = READ_LE_UINT16(src); src += 2; - } + int offs = READ_LE_UINT16(src); src += 2; - if (len > count) { + if (len > count) len = count; - } + const uint8 *dstOffs = dstOrig + offs; - while (len--) { + while (len--) *dst++ = *dstOffs++; - } } } else if (code != 0x80) { // not just the 8th bit set. //Copy some bytes from source to dest. int len = MIN(count, code & 0x3F); - while (len--) { + while (len--) *dst++ = *src++; - } } else { break; } @@ -1784,6 +1765,7 @@ void Screen::convertAmigaMsc(uint8 *data) { if (flagTable[x&7] & data[y*40+(x>>3)+i*5760]) layer = i; } + if (layer) dst[y*320+x] |= (layer+1); } @@ -1801,11 +1783,11 @@ void Screen::wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitc uint8 len = *src++; code = *src++; while (len--) { - if (noXor) { + if (noXor) *dst++ = code; - } else { + else *dst++ ^= code; - } + if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1833,11 +1815,11 @@ void Screen::wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitc uint16 len = subcode - 0x4000; code = *src++; while (len--) { - if (noXor) { + if (noXor) *dst++ = code; - } else { + else *dst++ ^= code; - } + if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1846,11 +1828,11 @@ void Screen::wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitc } } else { while (subcode--) { - if (noXor) { + if (noXor) *dst++ = *src++; - } else { + else *dst++ ^= *src++; - } + if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1872,11 +1854,11 @@ void Screen::wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitc } } else { while (code--) { - if (noXor) { + if (noXor) *dst++ = *src++; - } else { + else *dst++ ^= *src++; - } + if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1934,11 +1916,11 @@ uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) { } int16 shapeSize2 = shapeSize; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) shapeSize += 12; - } else { + else shapeSize += 10; - } + if (flags & 1) shapeSize += 16; @@ -1950,8 +1932,10 @@ uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) { assert(newShape); byte *dst = newShape; + if (_vm->gameFlags().useAltShapeHeader) dst += 2; + WRITE_LE_UINT16(dst, (flags & 3)); dst += 2; *dst = h; dst += 1; WRITE_LE_UINT16(dst, w); dst += 2; @@ -2018,20 +2002,19 @@ uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) { if (!(flags & 2)) { if (shapeSize > _animBlockSize) { dst = newShape; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) dst += 2; - } + flags = READ_LE_UINT16(dst); flags |= 2; WRITE_LE_UINT16(dst, flags); } else { src = newShape; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) src += 2; - } - if (flags & 1) { + if (flags & 1) src += 16; - } + src += 10; uint8 *shapePtrBackUp = src; dst = _animBlockPtr; @@ -2058,16 +2041,14 @@ uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) { } dst = newShape; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) dst += 2; - } WRITE_LE_UINT16((dst + 6), shapeSize); if (flags & 1) { dst = newShape + 10; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) dst += 2; - } src = &table[0x100]; memcpy(dst, src, sizeof(uint8)*16); } @@ -2208,17 +2189,15 @@ int16 Screen::encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size_to) { } int Screen::getRectSize(int x, int y) { - if (x < 1) { + if (x < 1) x = 1; - } else if (x > 40) { + else if (x > 40) x = 40; - } - if (y < 1) { + if (y < 1) y = 1; - } else if (y > 200) { + else if (y > 200) y = 200; - } return ((x*y) << 3); } @@ -2232,13 +2211,11 @@ void Screen::hideMouse() { void Screen::showMouse() { debugC(9, kDebugLevelScreen, "Screen::showMouse()"); - if (_mouseLockCount == 1) { + if (_mouseLockCount == 1) CursorMan.showMouse(true); - } if (_mouseLockCount > 0) _mouseLockCount--; - } void Screen::setShapePages(int page1, int page2) { @@ -2324,9 +2301,8 @@ void Screen::copyScreenToRect(int x, int y, int w, int h, uint8 *ptr) { uint8 *Screen::getPalette(int num) { debugC(9, kDebugLevelScreen, "Screen::getPalette(%d)", num); assert(num >= 0 && num < (_vm->gameFlags().platform == Common::kPlatformAmiga ? 6 : 4)); - if (num == 0) { + if (num == 0) return _currentPalette; - } return _palettes[num-1]; } @@ -2354,6 +2330,7 @@ int Screen::setNewShapeHeight(uint8 *shape, int height) { debugC(9, kDebugLevelScreen, "Screen::setNewShapeHeight(%p, %d)", (const void *)shape, height); if (_vm->gameFlags().useAltShapeHeader) shape += 2; + int oldHeight = shape[2]; shape[2] = height; return oldHeight; @@ -2363,6 +2340,7 @@ int Screen::resetShapeHeight(uint8 *shape) { debugC(9, kDebugLevelScreen, "Screen::setNewShapeHeight(%p)", (const void *)shape); if (_vm->gameFlags().useAltShapeHeader) shape += 2; + int oldHeight = shape[2]; shape[2] = shape[5]; return oldHeight; @@ -2370,9 +2348,9 @@ int Screen::resetShapeHeight(uint8 *shape) { void Screen::addBitBlitRect(int x, int y, int w, int h) { debugC(9, kDebugLevelScreen, "Screen::addBitBlitRects(%d, %d, %d, %d)", x, y, w, h); - if (_bitBlitNum >= BITBLIT_RECTS) { + if (_bitBlitNum >= BITBLIT_RECTS) error("too many bit blit rects"); - } + _bitBlitRects[_bitBlitNum].x = x; _bitBlitRects[_bitBlitNum].y = y; _bitBlitRects[_bitBlitNum].x2 = w; @@ -2419,9 +2397,8 @@ void Screen::blockInRegion(int x, int y, int width, int height) { byte *toPtr = _shapePages[0] + (y * 320 + x); for (int i = 0; i < height; ++i) { byte *backUpTo = toPtr; - for (int i2 = 0; i2 < width; ++i2) { + for (int i2 = 0; i2 < width; ++i2) *toPtr++ &= 0x7F; - } toPtr = (backUpTo + 320); } } @@ -2432,24 +2409,22 @@ void Screen::blockOutRegion(int x, int y, int width, int height) { byte *toPtr = _shapePages[0] + (y * 320 + x); for (int i = 0; i < height; ++i) { byte *backUpTo = toPtr; - for (int i2 = 0; i2 < width; ++i2) { + for (int i2 = 0; i2 < width; ++i2) *toPtr++ |= 0x80; - } toPtr = (backUpTo + 320); } } void Screen::rectClip(int &x, int &y, int w, int h) { - if (x < 0) { + if (x < 0) x = 0; - } else if (x + w >= 320) { + else if (x + w >= 320) x = 320 - w; - } - if (y < 0) { + + if (y < 0) y = 0; - } else if (y + h >= 200) { + else if (y + h >= 200) y = 200 - h; - } } void Screen::backUpRect0(int xpos, int ypos) { @@ -2481,14 +2456,15 @@ int Screen::getDrawLayer(int x, int y) { int xpos = x - 8; int ypos = y - 1; int layer = 1; + for (int curX = xpos; curX < xpos + 16; ++curX) { int tempLayer = getShapeFlag2(curX, ypos); - if (layer < tempLayer) { + + if (layer < tempLayer) layer = tempLayer; - } - if (layer >= 7) { + + if (layer >= 7) return 7; - } } return layer; } @@ -2502,13 +2478,12 @@ int Screen::getDrawLayer2(int x, int y, int height) { for (int useX = xpos; useX < xpos + 16; ++useX) { for (int useY = ypos - height; useY < ypos; ++useY) { int tempLayer = getShapeFlag2(useX, useY); - if (tempLayer > layer) { + + if (tempLayer > layer) layer = tempLayer; - } - if (tempLayer >= 7) { + if (tempLayer >= 7) return 7; - } } } return layer; @@ -2527,6 +2502,7 @@ void Screen::copyBackgroundBlock(int x, int page, int flag) { ++x; if (x == 19) x = 17; + uint8 *ptr1 = _unkPtr1; uint8 *ptr2 = _unkPtr2; int oldVideoPage = _curPage; @@ -2540,9 +2516,9 @@ void Screen::copyBackgroundBlock(int x, int page, int flag) { copyRegionToBuffer(_curPage, tempX<<3, 8, 8, height, ptr1); copyBlockToPage(_curPage, tempX<<3, 8, 8, height, ptr2); int newXPos = curX + x; - if (newXPos > 37) { + if (newXPos > 37) newXPos = newXPos % 38; - } + tempX = newXPos + 1; copyRegionToBuffer(_curPage, tempX<<3, 8, 8, height, ptr2); copyBlockToPage(_curPage, tempX<<3, 8, 8, height, ptr1); @@ -2714,12 +2690,15 @@ void Screen::addDirtyRect(int x, int y, int w, int h) { w += x; x = 0; } + if (x + w >= 320) w = 320 - x; + if (y < 0) { h += y; y = 0; } + if (y + h >= 200) h = 200 - y; @@ -3053,3 +3032,4 @@ void Screen::drawCharSJIS(uint16 c, int x, int y) { } } // End of namespace Kyra + diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index dab44f2b1a..f0b1d0e52b 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -322,3 +322,4 @@ private: } // End of namespace Kyra #endif + diff --git a/engines/kyra/script_v1.cpp b/engines/kyra/script_v1.cpp index 38ea303cb3..987d05db21 100644 --- a/engines/kyra/script_v1.cpp +++ b/engines/kyra/script_v1.cpp @@ -113,9 +113,8 @@ int KyraEngine::o1_runNPCScript(ScriptState *script) { int KyraEngine::o1_setSpecialExitList(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_setSpecialExitList(%p) (%d, %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), stackPos(9)); - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < 10; ++i) _exitList[i] = stackPos(i); - } _exitListPtr = _exitList; return 0; @@ -178,11 +177,10 @@ int KyraEngine::o1_dropItemInScene(ScriptState *script) { _animator->animAddGameItem(freeItem, sceneId); _animator->updateAllObjectShapes(); } else { - if (item == 43) { + if (item == 43) placeItemInGenericMapScene(item, 0); - } else { + else placeItemInGenericMapScene(item, 1); - } } return 0; } @@ -236,9 +234,8 @@ int KyraEngine::o1_getElapsedSeconds(ScriptState *script) { int KyraEngine::o1_mouseIsPointer(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_mouseIsPointer(%p) ()", (const void *)script); - if (_itemInHand == -1) { + if (_itemInHand == -1) return 1; - } return 0; } @@ -419,17 +416,14 @@ int KyraEngine::o1_setScaleMode(ScriptState *script) { int setValue1 = stackPos(1); int start2 = stackPos(2); int setValue2 = stackPos(3); - for (int i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) _scaleTable[i] = setValue1; - } int temp = setValue2 - setValue1; int temp2 = start2 - len; - for (int i = len, offset = 0; i < start2; ++i, ++offset) { + for (int i = len, offset = 0; i < start2; ++i, ++offset) _scaleTable[i] = (offset * temp) / temp2 + setValue1; - } - for (int i = start2; i < 145; ++i) { + for (int i = start2; i < 145; ++i) _scaleTable[i] = setValue2; - } _scaleMode = 1; return _scaleMode; } @@ -450,9 +444,8 @@ int KyraEngine::o1_closeWSAFile(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_closeWSAFile(%p) (%d)", (const void *)script, stackPos(0)); int wsaIndex = stackPos(0); - if (_movieObjects[wsaIndex]) { + if (_movieObjects[wsaIndex]) _movieObjects[wsaIndex]->close(); - } return 0; } @@ -603,9 +596,8 @@ int KyraEngine::o1_popBrandonIntoScene(ScriptState *script) { } int scaleModeBackup = _scaleMode; - if (changeScaleMode) { + if (changeScaleMode) _scaleMode = 1; - } _animator->animRefreshNPC(0); _animator->preserveAllBackgrounds(); @@ -701,9 +693,8 @@ int KyraEngine::o1_changeCharactersFacing(ScriptState *script) { int newAnimFrame = stackPos(2); _animator->restoreAllObjectBackgrounds(); - if (newAnimFrame != -1) { + if (newAnimFrame != -1) _characterList[character].currentAnimFrame = newAnimFrame; - } _characterList[character].facing = facing; _animator->animRefreshNPC(character); _animator->preserveAllBackgrounds(); @@ -795,7 +786,7 @@ int KyraEngine::o1_displayWSASequentialFrames(ScriptState *script) { // Workaround for bug #1498221 "KYRA1: Glitches when meeting Zanthia" // the original didn'to do a forced screen update after displaying a wsa frame // while we have to do it, which make brandon disappear for a short moment, - // which shouldn't happen. So we're not updating the screen for this special + // what shouldn't happen. So we're not updating the screen for this special // case too. if (startFrame == 18 && endFrame == 18 && _currentRoom == 45) { _movieObjects[wsaIndex]->displayFrame(18); @@ -841,6 +832,7 @@ int KyraEngine::o1_displayWSASequentialFrames(ScriptState *script) { --frame; } } + if (_skipFlag) break; else @@ -858,13 +850,11 @@ int KyraEngine::o1_drawCharacterStanding(ScriptState *script) { int newFacing = stackPos(2); int updateShapes = stackPos(3); _characterList[character].currentAnimFrame = animFrame; - if (newFacing != -1) { + if (newFacing != -1) _characterList[character].facing = newFacing; - } _animator->animRefreshNPC(character); - if (updateShapes) { + if (updateShapes) _animator->updateAllObjectShapes(); - } return 0; } @@ -1026,12 +1016,12 @@ int KyraEngine::o1_walkCharacterToPoint(ScriptState *script) { uint32 nextFrame; int findWayReturn = findWay(_characterList[character].x1, _characterList[character].y1, toX, toY, _movFacingTable, 150); _pathfinderFlag2 = 0; - if (_lastFindWayRet < findWayReturn) { + + if (_lastFindWayRet < findWayReturn) _lastFindWayRet = findWayReturn; - } - if (findWayReturn == 0x7D00 || findWayReturn == 0) { + if (findWayReturn == 0x7D00 || findWayReturn == 0) return 0; - } + int *curPos = _movFacingTable; bool running = true; while (running) { @@ -1079,9 +1069,8 @@ int KyraEngine::o1_walkCharacterToPoint(ScriptState *script) { break; } - if (forceContinue || !running) { + if (forceContinue || !running) continue; - } setCharacterPosition(character, 0); ++curPos; @@ -1106,13 +1095,12 @@ int KyraEngine::o1_specialEventDisplayBrynnsNote(ScriptState *script) { _screen->savePageToDisk("HIDPAGE.TMP", 2); _screen->savePageToDisk("SEENPAGE.TMP", 0); if (_flags.isTalkie) { - if (_flags.lang == Common::EN_ANY) { + if (_flags.lang == Common::EN_ANY) _screen->loadBitmap("NOTEENG.CPS", 3, 3, 0); - } else if (_flags.lang == Common::FR_FRA) { + else if (_flags.lang == Common::FR_FRA) _screen->loadBitmap("NOTEFRE.CPS", 3, 3, 0); - } else if (_flags.lang == Common::DE_DEU) { + else if (_flags.lang == Common::DE_DEU) _screen->loadBitmap("NOTEGER.CPS", 3, 3, 0); - } } else { _screen->loadBitmap("NOTE.CPS", 3, 3, 0); } @@ -1146,7 +1134,7 @@ int KyraEngine::o1_fatPrint(ScriptState *script) { // Workround for bug #1582672 ("KYRA1: Text crippled and drawn wrong") // I'm not sure how the original handels this, since it seems to call // printText also, maybe it fails somewhere inside... - // TODO: fix the reason for this workaround ;-) + // TODO: fix the reason for this workaround if (_currentRoom == 117) return 0; _text->printText(stackPosString(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5)); @@ -1203,15 +1191,16 @@ int KyraEngine::o1_dispelMagicAnimation(ScriptState *script) { int KyraEngine::o1_findBrightestFireberry(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_findBrightestFireberry(%p) ()", (const void *)script); - if (_currentCharacter->sceneId >= 187 && _currentCharacter->sceneId <= 198) { + if (_currentCharacter->sceneId >= 187 && _currentCharacter->sceneId <= 198) return 29; - } + if (_currentCharacter->sceneId == 133 || _currentCharacter->sceneId == 137 || - _currentCharacter->sceneId == 165 || _currentCharacter->sceneId == 173) { + _currentCharacter->sceneId == 165 || _currentCharacter->sceneId == 173) return 29; - } + if (_itemInHand == 28) return 28; + int brightestFireberry = 107; if (_itemInHand >= 29 && _itemInHand <= 33) brightestFireberry = _itemInHand; @@ -1309,18 +1298,14 @@ int KyraEngine::o1_makeAmuletAppear(ScriptState *script) { nextTime = _system->getMillis() + 5 * _tickLength; uint8 code = _amuleteAnim[i]; - if (code == 3 || code == 7) { + if (code == 3 || code == 7) snd_playSoundEffect(0x71); - } - if (code == 5) { + if (code == 5) snd_playSoundEffect(0x72); - } - if (code == 14) { + if (code == 14) snd_playSoundEffect(0x73); - } - amulet.displayFrame(code); _animator->_updateScreen = true; @@ -1345,8 +1330,10 @@ int KyraEngine::o1_drawItemShapeIntoScene(ScriptState *script) { int y = stackPos(2); int flags = stackPos(3); int onlyHidPage = stackPos(4); + if (flags) flags = 1; + if (onlyHidPage) { _screen->drawShape(2, _shapes[220+item], x, y, 0, flags); } else { @@ -1471,17 +1458,15 @@ int KyraEngine::o1_getCharactersMovementDelay(ScriptState *script) { int KyraEngine::o1_getBirthstoneGem(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_getBirthstoneGem(%p) (%d)", (const void *)script, stackPos(0)); - if (stackPos(0) < 4) { + if (stackPos(0) < 4) return _birthstoneGemTable[stackPos(0)]; - } return 0; } int KyraEngine::o1_queryBrandonStatusBit(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_queryBrandonStatusBit(%p) (%d)", (const void *)script, stackPos(0)); - if (_brandonStatusBit & stackPos(0)) { + if (_brandonStatusBit & stackPos(0)) return 1; - } return 0; } @@ -1493,11 +1478,10 @@ int KyraEngine::o1_playFluteAnimation(ScriptState *script) { int KyraEngine::o1_playWinterScrollSequence(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_playWinterScrollSequence(%p) (%d)", (const void *)script, stackPos(0)); - if (!stackPos(0)) { + if (!stackPos(0)) seq_winterScroll2(); - } else { + else seq_winterScroll1(); - } return 0; } @@ -1620,21 +1604,19 @@ int KyraEngine::o1_setCauldronState(ScriptState *script) { int KyraEngine::o1_queryCrystalState(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_queryCrystalState(%p) (%d)", (const void *)script, stackPos(0)); - if (!stackPos(0)) { + if (!stackPos(0)) return _crystalState[0]; - } else if (stackPos(0) == 1) { + else if (stackPos(0) == 1) return _crystalState[1]; - } return -1; } int KyraEngine::o1_setCrystalState(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_setCrystalState(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); - if (!stackPos(0)) { + if (!stackPos(0)) _crystalState[0] = stackPos(1); - } else if (stackPos(0) == 1) { + else if (stackPos(0) == 1) _crystalState[1] = stackPos(1); - } return stackPos(1); } @@ -1649,11 +1631,12 @@ int KyraEngine::o1_shrinkBrandonDown(ScriptState *script) { checkAmuletAnimFlags(); int scaleValue = _scaleTable[_currentCharacter->y1]; int scale = 0; - if (_scaleMode) { + + if (_scaleMode) scale = scaleValue; - } else { + else scale = 256; - } + int scaleModeBackUp = _scaleMode; _scaleMode = 1; int scaleEnd = scale >> 1; @@ -1672,11 +1655,11 @@ int KyraEngine::o1_growBrandonUp(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "o1_growBrandonUp(%p) ()", (const void *)script); int scaleValue = _scaleTable[_currentCharacter->y1]; int scale = 0; - if (_scaleMode) { + if (_scaleMode) scale = scaleValue; - } else { + else scale = 256; - } + int scaleModeBackUp = _scaleMode; _scaleMode = 1; for (int curScale = scale >> 1; curScale <= scale; ++curScale) { @@ -1831,3 +1814,4 @@ int KyraEngine::o1_dummy(ScriptState *script) { } } // end of namespace Kyra + diff --git a/engines/kyra/seqplayer.cpp b/engines/kyra/seqplayer.cpp index cf5eb9cb90..591eb29f9b 100644 --- a/engines/kyra/seqplayer.cpp +++ b/engines/kyra/seqplayer.cpp @@ -74,11 +74,11 @@ uint8 *SeqPlayer::setPanPages(int pageNum, int shape) { uint16 numShapes = READ_LE_UINT16(data); if (shape < numShapes) { uint32 offs = 0; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) offs = READ_LE_UINT32(data + 2 + shape * 4); - } else { + else offs = READ_LE_UINT16(data + 2 + shape * 2); - } + if (offs != 0) { data += offs; uint16 sz = READ_LE_UINT16(data + 6); @@ -139,9 +139,8 @@ void SeqPlayer::s1_wsaOpen() { void SeqPlayer::s1_wsaClose() { uint8 wsaObj = *_seqData++; assert(wsaObj < ARRAYSIZE(_seqMovies)); - if (_seqMovies[wsaObj].movie) { + if (_seqMovies[wsaObj].movie) _seqMovies[wsaObj].movie->close(); - } } void SeqPlayer::s1_wsaPlayFrame() { @@ -207,23 +206,21 @@ void SeqPlayer::s1_shuffleScreen() { void SeqPlayer::s1_copyView() { int y = 128; - if (!_copyViewOffs) { + if (!_copyViewOffs) y -= 8; - } - if (_specialBuffer && !_copyViewOffs) { + + if (_specialBuffer && !_copyViewOffs) _screen->copyToPage0(16, y, 3, _specialBuffer); - } else { + else _screen->copyRegion(0, 16, 0, 16, 320, y, 2, 0); - } } void SeqPlayer::s1_loopInit() { uint8 seqLoop = *_seqData++; - if (seqLoop < ARRAYSIZE(_seqLoopTable)) { + if (seqLoop < ARRAYSIZE(_seqLoopTable)) _seqLoopTable[seqLoop].ptr = _seqData; - } else { + else _seqQuitFlag = true; - } } void SeqPlayer::s1_loopInc() { @@ -250,13 +247,13 @@ void SeqPlayer::s1_loadPalette() { uint8 colNum = *_seqData++; if (_vm->gameFlags().platform == Common::kPlatformAmiga) { - if (!colNum) { + if (!colNum) memcpy(_screen->_currentPalette, _screen->_currentPalette + 576, 3*32); - } else if (colNum == 3) { + else if (colNum == 3) memcpy(_screen->_currentPalette, _screen->_currentPalette + 672, 3*32); - } else if (colNum == 4) { + else if (colNum == 4) memcpy(_screen->_currentPalette, _screen->_currentPalette + 288, 3*32); - } + _screen->setScreenPalette(_screen->_currentPalette); } else { uint32 fileSize; @@ -304,31 +301,28 @@ void SeqPlayer::s1_printTalkText() { uint8 fillColor = *_seqData++; int b; if (_seqTalkTextPrinted && !_seqTalkTextRestored) { - if (_seqWsaCurDecodePage != 0 && !_specialBuffer) { + if (_seqWsaCurDecodePage != 0 && !_specialBuffer) b = 2; - } else { + else b = 0; - } _vm->text()->restoreTalkTextMessageBkgd(2, b); } _seqTalkTextPrinted = true; _seqTalkTextRestored = false; - if (_seqWsaCurDecodePage != 0 && !_specialBuffer) { + if (_seqWsaCurDecodePage != 0 && !_specialBuffer) b = 2; - } else { + else b = 0; - } _vm->text()->printTalkTextMessage(_vm->seqTextsTable()[txt], x, y, fillColor, b, 2); } void SeqPlayer::s1_restoreTalkText() { if (_seqTalkTextPrinted && !_seqTalkTextRestored) { int b; - if (_seqWsaCurDecodePage != 0 && !_specialBuffer) { + if (_seqWsaCurDecodePage != 0 && !_specialBuffer) b = 2; - } else { + else b = 0; - } _vm->text()->restoreTalkTextMessageBkgd(2, b); _seqTalkTextRestored = true; } @@ -358,12 +352,11 @@ void SeqPlayer::s1_copyRegion() { void SeqPlayer::s1_copyRegionSpecial() { static const uint8 colorMap[] = { 0, 0, 0, 0, 0, 12, 12, 0, 0, 0, 0, 0 }; const char *copyStr = 0; - if (!_vm->gameFlags().isTalkie) { + if (!_vm->gameFlags().isTalkie) copyStr = "Copyright (c) 1992 Westwood Studios"; - } else { + else copyStr = "Copyright (c) 1992,1993 Westwood Studios"; - } - + uint8 so = *_seqData++; switch (so) { case 0: @@ -625,9 +618,9 @@ bool SeqPlayer::playSequence(const uint8 *seqData, bool skipSeq) { if (skipSeq && _vm->seq_skipSequence()) { while (1) { uint8 code = *_seqData; - if (commands[code].proc == &SeqPlayer::s1_endOfScript || commands[code].proc == &SeqPlayer::s1_break) { + if (commands[code].proc == &SeqPlayer::s1_endOfScript || commands[code].proc == &SeqPlayer::s1_break) break; - } + _seqData += commands[code].len; } skipSeq = false; @@ -644,11 +637,11 @@ bool SeqPlayer::playSequence(const uint8 *seqData, bool skipSeq) { _screen->printText(charStr, _seqDisplayedTextX, 180, 0xF, 0xC); _seqDisplayedTextX += _screen->getCharWidth(charStr[0]); ++_seqDisplayedChar; - if (_vm->seqTextsTable()[_seqDisplayedText][_seqDisplayedChar] == '\0') { + + if (_vm->seqTextsTable()[_seqDisplayedText][_seqDisplayedChar] == '\0') _seqDisplayedTextTimer = 0xFFFFFFFF; - } else { + else _seqDisplayedTextTimer = _system->getMillis() + 1000 / ((_vm->gameFlags().lang == Common::FR_FRA) ? 120 : 60); - } } } @@ -670,3 +663,4 @@ bool SeqPlayer::playSequence(const uint8 *seqData, bool skipSeq) { } // End of namespace Kyra + diff --git a/engines/kyra/seqplayer.h b/engines/kyra/seqplayer.h index 1032d0126e..9f2b846297 100644 --- a/engines/kyra/seqplayer.h +++ b/engines/kyra/seqplayer.h @@ -121,3 +121,4 @@ protected: } // End of namespace Kyra #endif + diff --git a/engines/kyra/sequences_v1.cpp b/engines/kyra/sequences_v1.cpp index 771949b852..da5cf3ccaf 100644 --- a/engines/kyra/sequences_v1.cpp +++ b/engines/kyra/sequences_v1.cpp @@ -89,9 +89,8 @@ void KyraEngine::seq_demo() { void KyraEngine::seq_intro() { debugC(9, kDebugLevelMain, "KyraEngine::seq_intro()"); - if (_flags.isTalkie) { + if (_flags.isTalkie) _res->loadPakFile("INTRO.VRM"); - } static const IntroProc introProcTable[] = { &KyraEngine::seq_introLogos, @@ -113,17 +112,18 @@ void KyraEngine::seq_intro() { if (_flags.platform != Common::kPlatformFMTowns) snd_playTheme(0, 2); _text->setTalkCoords(144); - for (int i = 0; i < ARRAYSIZE(introProcTable) && !seq_skipSequence(); ++i) { + + for (int i = 0; i < ARRAYSIZE(introProcTable) && !seq_skipSequence(); ++i) (this->*introProcTable[i])(); - } + _text->setTalkCoords(136); delay(30 * _tickLength); _seq->setCopyViewOffs(false); _sound->haltTrack(); _sound->voiceStop(); - if (_flags.isTalkie) { + + if (_flags.isTalkie) _res->unloadPakFile("INTRO.VRM"); - } } void KyraEngine::seq_introLogos() { @@ -232,23 +232,23 @@ void KyraEngine::seq_introStory() { debugC(9, kDebugLevelMain, "KyraEngine::seq_introStory()"); _screen->clearPage(3); _screen->clearPage(0); - if (_flags.isTalkie) { + + if (_flags.isTalkie) return; - } else if (_flags.lang == Common::EN_ANY && (_flags.platform == Common::kPlatformPC || _flags.platform == Common::kPlatformAmiga)) { + else if (_flags.lang == Common::EN_ANY && (_flags.platform == Common::kPlatformPC || _flags.platform == Common::kPlatformAmiga)) _screen->loadBitmap("TEXT.CPS", 3, 3, _screen->_currentPalette); - } else if (_flags.lang == Common::EN_ANY || _flags.lang == Common::JA_JPN) { + else if (_flags.lang == Common::EN_ANY || _flags.lang == Common::JA_JPN) _screen->loadBitmap("TEXT_ENG.CPS", 3, 3, _screen->_currentPalette); - } else if (_flags.lang == Common::DE_DEU) { + else if (_flags.lang == Common::DE_DEU) _screen->loadBitmap("TEXT_GER.CPS", 3, 3, _screen->_currentPalette); - } else if (_flags.lang == Common::FR_FRA) { + else if (_flags.lang == Common::FR_FRA) _screen->loadBitmap("TEXT_FRE.CPS", 3, 3, _screen->_currentPalette); - } else if (_flags.lang == Common::ES_ESP) { + else if (_flags.lang == Common::ES_ESP) _screen->loadBitmap("TEXT_SPA.CPS", 3, 3, _screen->_currentPalette); - } else if (_flags.lang == Common::IT_ITA) { + else if (_flags.lang == Common::IT_ITA) _screen->loadBitmap("TEXT_ITA.CPS", 3, 3, _screen->_currentPalette); - } else { + else warning("no story graphics file found"); - } _screen->setScreenPalette(_screen->_currentPalette); _screen->copyRegion(0, 0, 0, 0, 320, 200, 3, 0); @@ -691,11 +691,12 @@ void KyraEngine::seq_makeBrandonNormal2() { _animator->setBrandonAnimSeqSize(4, 48); _currentCharacter->currentAnimFrame = 7; _animator->animRefreshNPC(0); - if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) { + + if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) _screen->fadeSpecialPalette(31, 234, 13, 4); - } else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) { + else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) _screen->fadeSpecialPalette(14, 228, 15, 4); - } + freeShapes123(); _screen->showMouse(); } @@ -721,21 +722,23 @@ void KyraEngine::seq_makeBrandonWisp() { delayWithTicks(8); } _brandonStatusBit |= 2; - if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) { + + if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) setTimerCountdown(14, 18000); - } else { + else setTimerCountdown(14, 7200); - } + _animator->_brandonDrawFrame = 113; _brandonStatusBit0x02Flag = 1; _currentCharacter->currentAnimFrame = 113; _animator->animRefreshNPC(0); _animator->updateAllObjectShapes(); - if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) { + + if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) _screen->fadeSpecialPalette(30, 234, 13, 4); - } else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) { + else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) _screen->fadeSpecialPalette(14, 228, 15, 4); - } + freeShapes123(); _screen->showMouse(); } @@ -909,12 +912,12 @@ void KyraEngine::seq_playDrinkPotionAnim(int item, int unk2, int flags) { int KyraEngine::seq_playEnd() { debugC(9, kDebugLevelMain, "KyraEngine::seq_playEnd()"); - if (_endSequenceSkipFlag) { + if (_endSequenceSkipFlag) return 0; - } - if (_deathHandler == 8) { + + if (_deathHandler == 8) return 0; - } + _screen->_curPage = 2; if (_endSequenceNeedLoading) { snd_playWanderScoreViaMap(50, 1); @@ -959,9 +962,8 @@ int KyraEngine::seq_playEnd() { return 1; } else { _endSequenceSkipFlag = 1; - if (_text->printed()) { + if (_text->printed()) _text->restoreTalkTextMessageBkgd(2, 0); - } _screen->_curPage = 0; _screen->hideMouse(); _screen->fadeSpecialPalette(32, 228, 20, 60); @@ -979,11 +981,10 @@ int KyraEngine::seq_playEnd() { snd_playSoundEffect(0x40); for (int i = 0; i < 22; ++i) { delayUntil(nextTime); - if (i == 4) { + if (i == 4) snd_playSoundEffect(0x3E); - } else if (i == 20) { + else if (i == 20) snd_playSoundEffect(0x0E); - } nextTime = _system->getMillis() + 8 * _tickLength; _finalA->displayFrame(i); _screen->updateScreen(); @@ -1452,10 +1453,13 @@ int KyraEngine::handleBeadState() { beadState1.y = y; } } + _screen->copyCurPageBlock(x >> 3, y, beadState1.width, beadState1.height, _endSequenceBackUpRect); _screen->drawShape(2, _panPagesTable[_lastDisplayedPanPage++], x, y, 0, 0); + if (_lastDisplayedPanPage > 17) _lastDisplayedPanPage = 0; + _screen->addBitBlitRect(x, y, beadState1.width2, beadState1.height); } break; @@ -1465,19 +1469,21 @@ int KyraEngine::handleBeadState() { timer1 = _system->getMillis() + 4 * _tickLength; _screen->copyFromCurPageBlock(beadState1.x >> 3, beadState1.y, beadState1.width, beadState1.height, _endSequenceBackUpRect); _screen->addBitBlitRect(beadState1.x, beadState1.y, beadState1.width2, beadState1.height); + beadState1.x = beadState1.dstX + table1[beadState1.tableIndex]; beadState1.y = beadState1.dstY + table2[beadState1.tableIndex]; _screen->copyCurPageBlock(beadState1.x >> 3, beadState1.y, beadState1.width, beadState1.height, _endSequenceBackUpRect); + _screen->drawShape(2, _panPagesTable[_lastDisplayedPanPage++], beadState1.x, beadState1.y, 0, 0); - if (_lastDisplayedPanPage >= 17) { + if (_lastDisplayedPanPage >= 17) _lastDisplayedPanPage = 0; - } + _screen->addBitBlitRect(beadState1.x, beadState1.y, beadState1.width2, beadState1.height); + ++beadState1.tableIndex; - if (beadState1.tableIndex > 24) { + if (beadState1.tableIndex > 24) beadState1.tableIndex = 0; _unkEndSeqVar4 = 1; - } if (_system->getMillis() > timer2 && _malcolmFlag == 7 && !_unkAmuletVar && !_text->printed()) { snd_playSoundEffect(0x0B); if (_currentCharacter->x1 > 233 && _currentCharacter->x1 < 305 && _currentCharacter->y1 > 85 && _currentCharacter->y1 < 105 && @@ -1491,9 +1497,9 @@ int KyraEngine::handleBeadState() { beadState1.unk9 = _currentCharacter->y1 - 30; } - if (_text->printed()) { + if (_text->printed()) _text->restoreTalkTextMessageBkgd(2, 0); - } + initBeadState(beadState1.x, beadState1.y, beadState1.unk8, beadState1.unk9, 12, &beadState2); _lastDisplayedPanPage = 18; } @@ -1569,9 +1575,8 @@ int KyraEngine::handleBeadState() { beadState1.y = y; _screen->copyCurPageBlock(beadState1.x >> 3, beadState1.y, beadState1.width, beadState1.height, _endSequenceBackUpRect); _screen->drawShape(2, _panPagesTable[_lastDisplayedPanPage++], x, y, 0, 0); - if (_lastDisplayedPanPage > 17) { + if (_lastDisplayedPanPage > 17) _lastDisplayedPanPage = 0; - } _screen->addBitBlitRect(beadState1.x, beadState1.y, beadState1.width2, beadState1.height); } } @@ -1595,21 +1600,20 @@ void KyraEngine::initBeadState(int x, int y, int x2, int y2, int unk, BeadState int xDiff = x2 - x; int yDiff = y2 - y; int unk1 = 0, unk2 = 0; - if (xDiff > 0) { + if (xDiff > 0) unk1 = 1; - } else if (xDiff == 0) { + else if (xDiff == 0) unk1 = 0; - } else { + else unk1 = -1; - } - if (yDiff > 0) { + + if (yDiff > 0) unk2 = 1; - } else if (yDiff == 0) { + else if (yDiff == 0) unk2 = 0; - } else { + else unk2 = -1; - } xDiff = ABS(xDiff); yDiff = ABS(yDiff); @@ -1626,9 +1630,8 @@ void KyraEngine::initBeadState(int x, int y, int x2, int y2, int unk, BeadState int KyraEngine::processBead(int x, int y, int &x2, int &y2, BeadState *ptr) { debugC(9, kDebugLevelMain, "KyraEngine::processBead(%d, %d, %p, %p, %p)", x, y, (const void *)&x2, (const void *)&y2, (const void *)ptr); - if (x == ptr->dstX && y == ptr->dstY) { + if (x == ptr->dstX && y == ptr->dstY) return 1; - } int xPos = x, yPos = y; if (ptr->width >= ptr->height) { @@ -1652,13 +1655,11 @@ int KyraEngine::processBead(int x, int y, int &x2, int &y2, BeadState *ptr) { } int temp = ABS(x - ptr->dstX); - if (ptr->unk9 > temp) { + if (ptr->unk9 > temp) xPos = ptr->dstX; - } temp = ABS(y - ptr->dstY); - if (ptr->unk9 > temp) { + if (ptr->unk9 > temp) yPos = ptr->dstY; - } x2 = xPos; y2 = yPos; return 0; @@ -1789,20 +1790,22 @@ void KyraEngine::drawJewelPress(int jewel, int drawSpecial) { debugC(9, kDebugLevelMain, "KyraEngine::drawJewelPress(%d, %d)", jewel, drawSpecial); _screen->hideMouse(); int shape = 0; - if (drawSpecial) { + + if (drawSpecial) shape = 0x14E; - } else { + else shape = jewel + 0x149; - } + snd_playSoundEffect(0x45); _screen->drawShape(0, _shapes[4+shape], _amuletX2[jewel], _amuletY2[jewel], 0, 0); _screen->updateScreen(); delayWithTicks(2); - if (drawSpecial) { + + if (drawSpecial) shape = 0x148; - } else { + else shape = jewel + 0x143; - } + _screen->drawShape(0, _shapes[4+shape], _amuletX2[jewel], _amuletY2[jewel], 0, 0); _screen->updateScreen(); _screen->showMouse(); @@ -1815,18 +1818,14 @@ void KyraEngine::drawJewelsFadeOutStart() { static const uint16 jewelTable3[] = { 0x166, 0x160, 0x15C, 0x157, 0x152, 0xFFFF }; static const uint16 jewelTable4[] = { 0x165, 0x161, 0x15B, 0x156, 0x151, 0xFFFF }; for (int i = 0; jewelTable1[i] != 0xFFFF; ++i) { - if (queryGameFlag(0x57)) { + if (queryGameFlag(0x57)) _screen->drawShape(0, _shapes[4+jewelTable1[i]], _amuletX2[2], _amuletY2[2], 0, 0); - } - if (queryGameFlag(0x59)) { + if (queryGameFlag(0x59)) _screen->drawShape(0, _shapes[4+jewelTable3[i]], _amuletX2[4], _amuletY2[4], 0, 0); - } - if (queryGameFlag(0x56)) { + if (queryGameFlag(0x56)) _screen->drawShape(0, _shapes[4+jewelTable2[i]], _amuletX2[1], _amuletY2[1], 0, 0); - } - if (queryGameFlag(0x58)) { + if (queryGameFlag(0x58)) _screen->drawShape(0, _shapes[4+jewelTable4[i]], _amuletX2[3], _amuletY2[3], 0, 0); - } _screen->updateScreen(); delayWithTicks(3); } @@ -1836,36 +1835,34 @@ void KyraEngine::drawJewelsFadeOutEnd(int jewel) { debugC(9, kDebugLevelMain, "KyraEngine::drawJewelsFadeOutEnd(%d)", jewel); static const uint16 jewelTable[] = { 0x153, 0x158, 0x15D, 0x162, 0x148, 0xFFFF }; int newDelay = 0; + switch (jewel - 1) { case 2: - if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) { + if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) newDelay = 18900; - } else { + else newDelay = 8100; - } break; default: newDelay = 3600; break; } + setGameFlag(0xF1); setTimerCountdown(19, newDelay); _screen->hideMouse(); for (int i = 0; jewelTable[i] != 0xFFFF; ++i) { uint16 shape = jewelTable[i]; - if (queryGameFlag(0x57)) { + if (queryGameFlag(0x57)) _screen->drawShape(0, _shapes[4+shape], _amuletX2[2], _amuletY2[2], 0, 0); - } - if (queryGameFlag(0x59)) { + if (queryGameFlag(0x59)) _screen->drawShape(0, _shapes[4+shape], _amuletX2[4], _amuletY2[4], 0, 0); - } - if (queryGameFlag(0x56)) { + if (queryGameFlag(0x56)) _screen->drawShape(0, _shapes[4+shape], _amuletX2[1], _amuletY2[1], 0, 0); - } - if (queryGameFlag(0x58)) { + if (queryGameFlag(0x58)) _screen->drawShape(0, _shapes[4+shape], _amuletX2[3], _amuletY2[3], 0, 0); - } + _screen->updateScreen(); delayWithTicks(3); } @@ -1873,3 +1870,4 @@ void KyraEngine::drawJewelsFadeOutEnd(int jewel) { } } // end of namespace Kyra + diff --git a/engines/kyra/sequences_v2.cpp b/engines/kyra/sequences_v2.cpp index 710c773bfb..d5ea1da655 100644 --- a/engines/kyra/sequences_v2.cpp +++ b/engines/kyra/sequences_v2.cpp @@ -111,9 +111,9 @@ void KyraEngine_v2::seq_playSequences(int startSeq, int endSeq) { _screen->updateScreen(); uint32 currTime = _system->getMillis(); - if (seqDelay <= currTime && mayEndLoop) + if (seqDelay <= currTime && mayEndLoop) { break; - else { + } else { uint32 loopTime = currTime - startTime; delay(loopTime < _tickLength ? loopTime : _tickLength); } @@ -307,9 +307,9 @@ void KyraEngine_v2::seq_introOverviewOver1(int currentFrame) { void KyraEngine_v2::seq_introOverviewForest(int currentFrame) { debugC(9, kDebugLevelMain, "KyraEngine_v2::seq_introOverviewForest(%i)", currentFrame); - if (currentFrame == 11) + if (currentFrame == 11) { seq_waitForChatsToFinish(); - else if(currentFrame == 12) { + } else if(currentFrame == 12) { delay(25); seq_playIntroChat(2); } @@ -327,9 +327,9 @@ void KyraEngine_v2::seq_introOverviewDragon(int currentFrame) { int KyraEngine_v2::seq_introTitle(int seqNum) { debugC(9, kDebugLevelMain, "KyraEngine_v2::seq_introtitle(%i)", seqNum); - if (seqNum == 1) + if (seqNum == 1) { _sound->playTrack(3); - else if (seqNum == 25) { + } else if (seqNum == 25) { // XXX: handle menu return 200; } @@ -481,3 +481,4 @@ void KyraEngine_v2::seq_unloadWSA(int wsaNum) { } } // end of namespace Kyra + diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index d2e3a64d2d..3b7234709f 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -107,15 +107,13 @@ SoundMidiPC::SoundMidiPC(KyraEngine *vm, Audio::Mixer *mixer, MidiDriver *driver memset(_channel, 0, sizeof(MidiChannel*) * 32); memset(_channelVolume, 50, sizeof(uint8) * 16); _channelVolume[10] = 100; - for (int i = 0; i < 16; ++i) { + for (int i = 0; i < 16; ++i) _virChannel[i] = i; - } _volume = 0; int ret = open(); - if (ret != MERR_ALREADY_OPEN && ret != 0) { + if (ret != MERR_ALREADY_OPEN && ret != 0) error("couldn't open midi driver"); - } } SoundMidiPC::~SoundMidiPC() { @@ -371,9 +369,9 @@ void SoundMidiPC::onTimer(void *refCon) { music->send(0x80 | j | i << 8); } } - for (int i = 0; i < 16; ++i) { + + for (int i = 0; i < 16; ++i) music->send(0x007BB0 | i); - } } if (music->_isPlaying) { @@ -472,8 +470,9 @@ void KyraEngine::snd_playWanderScoreViaMap(int command, int restart) { // the original does -2 here we handle this inside _sound->playTrack() _sound->playTrack(command); } - } else + } else { _sound->haltTrack(); + } } else { static const int8 soundTable[] = { -1, 0, -1, 1, 0, 3, 0, 2, @@ -496,9 +495,8 @@ void KyraEngine::snd_playWanderScoreViaMap(int command, int restart) { //} assert(command*2+1 < ARRAYSIZE(soundTable)); if (_curMusicTheme != soundTable[command*2]+1) { - if (soundTable[command*2] != -1) { + if (soundTable[command*2] != -1) snd_playTheme(soundTable[command*2]+1); - } } if (command != 1) { @@ -525,11 +523,10 @@ void KyraEngine::snd_playVoiceFile(int id) { void KyraEngine::snd_voiceWaitForFinish(bool ingame) { debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_voiceWaitForFinish(%d)", ingame); while (_sound->voiceIsPlaying() && !_skipFlag) { - if (ingame) { + if (ingame) delay(10, true); - } else { + else _system->delayMillis(10); - } } } @@ -559,3 +556,4 @@ const Sound::SpeechCodecs Sound::_supportedCodes[] = { }; } // end of namespace Kyra + diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp index 48f6761ab8..765a20a558 100644 --- a/engines/kyra/sound_adlib.cpp +++ b/engines/kyra/sound_adlib.cpp @@ -558,9 +558,8 @@ int AdlibDriver::snd_unkOpcode3(va_list &list) { Channel &channel = _channels[_curChannel]; channel.priority = 0; channel.dataptr = 0; - if (value != 9) { + if (value != 9) noteOff(channel); - } ++value; } @@ -720,9 +719,8 @@ void AdlibDriver::executePrograms() { if ((_syncJumpMask & (1 << _curChannel)) == 0) continue; - if (_channels[_curChannel].dataptr && !_channels[_curChannel].lock) { + if (_channels[_curChannel].dataptr && !_channels[_curChannel].lock) forceUnlock = false; - } } if (forceUnlock) { @@ -735,20 +733,17 @@ void AdlibDriver::executePrograms() { for (_curChannel = 9; _curChannel >= 0; --_curChannel) { int result = 1; - if (!_channels[_curChannel].dataptr) { + if (!_channels[_curChannel].dataptr) continue; - } - if (_channels[_curChannel].lock && (_syncJumpMask & (1 << _curChannel))) { + if (_channels[_curChannel].lock && (_syncJumpMask & (1 << _curChannel))) continue; - } - + Channel &channel = _channels[_curChannel]; _curRegOffset = _regOffset[_curChannel]; - if (channel.tempoReset) { + if (channel.tempoReset) channel.tempo = _tempo; - } uint8 backup = channel.position; channel.position += channel.tempo; @@ -936,9 +931,8 @@ void AdlibDriver::setupDuration(uint8 duration, Channel &channel) { channel.duration = duration + (getRandomNr() & channel.durationRandomness); return; } - if (channel.fractionalSpacing) { + if (channel.fractionalSpacing) channel.spacing2 = (duration >> 3) * channel.fractionalSpacing; - } channel.duration = duration; } @@ -1228,9 +1222,8 @@ void AdlibDriver::secondaryEffect1(Channel &channel) { uint8 temp = channel.unk18; channel.unk18 += channel.unk19; if (channel.unk18 < temp) { - if (--channel.unk21 < 0) { + if (--channel.unk21 < 0) channel.unk21 = channel.unk20; - } writeOPL(channel.unk22 + _curRegOffset, _soundData[channel.offset + channel.unk21]); } } @@ -1336,9 +1329,8 @@ int AdlibDriver::update_setBaseOctave(uint8 *&dataptr, Channel &channel, uint8 v int AdlibDriver::update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 value) { channel.priority = 0; - if (_curChannel != 9) { + if (_curChannel != 9) noteOff(channel); - } dataptr = 0; return 2; } @@ -1388,9 +1380,8 @@ int AdlibDriver::update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, u uint8 *ptr = getProgram(value); uint8 chan = *ptr; - if (!_channels[chan].dataptr) { + if (!_channels[chan].dataptr) return 0; - } dataptr -= 2; return 2; @@ -1454,9 +1445,8 @@ int AdlibDriver::updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value } } - if (!(value & _unkValue4)) { + if (!(value & _unkValue4)) ++_unkValue5; - } dataptr -= 2; channel.duration = 1; @@ -2225,7 +2215,7 @@ SoundAdlibPC::SoundAdlibPC(KyraEngine *vm, Audio::Mixer *mixer) if (_v2) { // TODO: Figure out if Kyra 2 uses sound triggers at all. - _soundTriggers = NULL; + _soundTriggers = 0; _numSoundTriggers = 0; } else { _soundTriggers = _kyra1SoundTriggers; @@ -2250,9 +2240,8 @@ void SoundAdlibPC::process() { if (trigger < _numSoundTriggers) { int soundId = _soundTriggers[trigger]; - if (soundId) { + if (soundId) playTrack(soundId); - } } else { warning("Unknown sound trigger %d", trigger); // TODO: At this point, we really want to clear the trigger... @@ -2408,3 +2397,4 @@ void SoundAdlibPC::unk2() { } } // end of namespace Kyra + diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp index 74d6cc00a9..e046335131 100644 --- a/engines/kyra/sound_digital.cpp +++ b/engines/kyra/sound_digital.cpp @@ -321,9 +321,8 @@ SoundDigital::SoundDigital(KyraEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixe } SoundDigital::~SoundDigital() { - for (int i = 0; i < SOUND_STREAMS; ++i) { + for (int i = 0; i < SOUND_STREAMS; ++i) stopSound(i); - } } bool SoundDigital::init() { @@ -383,9 +382,9 @@ void SoundDigital::stopSound(int channel) { } void SoundDigital::beginFadeOut(int channel) { - if (isPlaying(channel)) { + if (isPlaying(channel)) _sounds[channel].stream->beginFadeOut(); - } } } // end of namespace Kyra + diff --git a/engines/kyra/sound_towns.cpp b/engines/kyra/sound_towns.cpp index bfc4655277..539017b20b 100644 --- a/engines/kyra/sound_towns.cpp +++ b/engines/kyra/sound_towns.cpp @@ -318,7 +318,7 @@ void MidiChannel_EuD_WAVE::controlChange(byte control, byte value) { // pan position break; case 0x79: - // Reset controller + // Reset controller for (uint8 i = 0; i < 8; i++) { if (_voice->_snd[i]) delete _voice->_snd[i]; @@ -1300,3 +1300,4 @@ const uint8 SoundTowns::_sfxBTTable[256] = { }; } // end of namespace Kyra + diff --git a/engines/kyra/sprites.cpp b/engines/kyra/sprites.cpp index a8825751ac..18620471db 100644 --- a/engines/kyra/sprites.cpp +++ b/engines/kyra/sprites.cpp @@ -463,9 +463,8 @@ void Sprites::loadDat(const char *filename, SceneExits &exits) { case 0xFF84: data += 2; _spriteDefStart = data; - while (READ_LE_UINT16(data) != 0xFF85) { + while (READ_LE_UINT16(data) != 0xFF85) data += 2; - } data += 2; break; case 0xFF86: @@ -575,16 +574,17 @@ int Sprites::getDrawLayer(int y) { for (int i = 0; i < ARRAYSIZE(_drawLayerTable); ++i) { uint8 temp = _drawLayerTable[i]; if (temp) { - if (temp <= y) { + if (temp <= y) returnValue = i; - } } } - if (returnValue <= 0) { + + if (returnValue <= 0) returnValue = 1; - } else if (returnValue >= 7) { + else if (returnValue >= 7) returnValue = 6; - } + return returnValue; } } // end of namespace Kyra + diff --git a/engines/kyra/sprites.h b/engines/kyra/sprites.h index 965e2888dc..8f6db3fd64 100644 --- a/engines/kyra/sprites.h +++ b/engines/kyra/sprites.h @@ -93,3 +93,4 @@ protected: } // End of namespace Kyra #endif + diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 88c972ea46..1de0a7573f 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -237,22 +237,18 @@ bool StaticResource::init() { delete [] temp; temp = 0; - if (version != RESFILE_VERSION) { + if (version != RESFILE_VERSION) error("invalid KYRA.DAT file version (%d, required %d)", version, RESFILE_VERSION); - } - if (gameID != _vm->game()) { + if (gameID != _vm->game()) error("invalid game id (%d)", gameID); - } uint32 gameFeatures = createFeatures(_vm->gameFlags()); - if ((featuresValue & GAME_FLAGS) != gameFeatures) { + if ((featuresValue & GAME_FLAGS) != gameFeatures) error("your data file has a different game flags (0x%.08X has the data and your version has 0x%.08X)", (featuresValue & GAME_FLAGS), gameFeatures); - } // load all tables for now - if (!prefetchId(-1)) { + if (!prefetchId(-1)) error("couldn't load all needed resources from 'KYRA.DAT'"); - } return true; } @@ -285,21 +281,18 @@ const uint8 * const*StaticResource::loadPaletteTable(int id, int &entries) { bool StaticResource::prefetchId(int id) { if (id == -1) { - for (int i = 0; _filenameTable[i].filename; ++i) { + for (int i = 0; _filenameTable[i].filename; ++i) prefetchId(_filenameTable[i].id); - } return true; } const void *ptr = 0; int type = -1, size = -1; - if (checkResList(id, type, ptr, size)) { + if (checkResList(id, type, ptr, size)) return true; - } - if (checkForBuiltin(id, type, size)) { + if (checkForBuiltin(id, type, size)) return true; - } const FilenameTable *filename = searchFile(id); if (!filename) @@ -311,9 +304,8 @@ bool StaticResource::prefetchId(int id) { ResData data; data.id = id; data.type = filetype->type; - if (!(this->*(filetype->load))(filename->filename, data.data, data.size)) { + if (!(this->*(filetype->load))(filename->filename, data.data, data.size)) return false; - } _resList.push_back(data); return true; @@ -376,9 +368,8 @@ const StaticResource::FileType *StaticResource::getFiletype(int type) { return 0; for (int i = 0; _fileLoader[i].load; ++i) { - if (_fileLoader[i].type == type) { + if (_fileLoader[i].type == type) return &_fileLoader[i]; - } } return 0; @@ -416,9 +407,8 @@ const void *StaticResource::getData(int id, int requesttype, int &size) { bool StaticResource::loadLanguageTable(const char *filename, void *&ptr, int &size) { char file[64]; for (int i = 0; languages[i].ext; ++i) { - if (languages[i].flags != createLanguage(_vm->gameFlags())) { + if (languages[i].flags != createLanguage(_vm->gameFlags())) continue; - } strcpy(file, filename); strcat(file, languages[i].ext); @@ -576,9 +566,8 @@ void StaticResource::freeRawData(void *&ptr, int &size) { void StaticResource::freeStringTable(void *&ptr, int &size) { char **data = (char**)ptr; - while (size--) { + while (size--) delete [] data[size]; - } ptr = 0; size = 0; } @@ -599,9 +588,8 @@ void StaticResource::freeRoomTable(void *&ptr, int &size) { void StaticResource::freePaletteTable(void *&ptr, int &size) { uint8 **data = (uint8**)ptr; - while (size--) { + while (size--) delete [] data[size]; - } ptr = 0; size = 0; } @@ -609,15 +597,14 @@ void StaticResource::freePaletteTable(void *&ptr, int &size) { uint8 *StaticResource::getFile(const char *name, int &size) { char buffer[64]; const char *ext = ""; - if (_vm->gameFlags().isTalkie) { + if (_vm->gameFlags().isTalkie) ext = ".CD"; - } else if (_vm->gameFlags().isDemo) { + else if (_vm->gameFlags().isDemo) ext = ".DEM"; - } else if (_vm->gameFlags().platform == Common::kPlatformFMTowns) { + else if (_vm->gameFlags().platform == Common::kPlatformFMTowns) ext = ".TNS"; - } else if (_vm->gameFlags().platform == Common::kPlatformAmiga) { + else if (_vm->gameFlags().platform == Common::kPlatformAmiga) ext = ".AMG"; - } snprintf(buffer, 64, "%s%s", name, ext); uint32 tempSize = 0; uint8 *data = _vm->resource()->fileData(buffer, &tempSize); @@ -1471,3 +1458,4 @@ const char *KyraEngine_v3::_languageExtension[] = { const int KyraEngine_v3::_languageExtensionSize = ARRAYSIZE(KyraEngine_v3::_languageExtension); } // End of namespace Kyra + diff --git a/engines/kyra/wsamovie.cpp b/engines/kyra/wsamovie.cpp index c682f4dc57..40023f169c 100644 --- a/engines/kyra/wsamovie.cpp +++ b/engines/kyra/wsamovie.cpp @@ -50,17 +50,15 @@ int WSAMovieV1::open(const char *filename, int offscreenDecode, uint8 *palBuf) { _deltaBufferSize = READ_LE_UINT16(wsaData); wsaData += 2; _offscreenBuffer = NULL; _flags = 0; - if (_vm->gameFlags().useAltShapeHeader) { + if (_vm->gameFlags().useAltShapeHeader) flags = READ_LE_UINT16(wsaData); wsaData += 2; - } uint32 offsPal = 0; if (flags & 1) { offsPal = 0x300; _flags |= WF_HAS_PALETTE; - if (palBuf) { + if (palBuf) memcpy(palBuf, wsaData + (_numFrames + 2) * 4, 0x300); - } } if (offscreenDecode) { @@ -107,9 +105,8 @@ int WSAMovieV1::open(const char *filename, int offscreenDecode, uint8 *palBuf) { memcpy(_frameData, wsaData, frameDataSize); // decode first frame - if (firstFrame) { + if (firstFrame) Screen::decodeFrame4(_frameData, _deltaBuffer, _deltaBufferSize); - } delete [] p; _opened = true; @@ -134,19 +131,17 @@ void WSAMovieV1::displayFrame(int frameNum) { return; uint8 *dst; - if (_flags & WF_OFFSCREEN_DECODE) { + if (_flags & WF_OFFSCREEN_DECODE) dst = _offscreenBuffer; - } else { + else dst = _vm->screen()->getPageRect(_drawPage, _x, _y, _width, _height); - } if (_currentFrame == _numFrames) { if (!(_flags & WF_NO_FIRST_FRAME)) { - if (_flags & WF_OFFSCREEN_DECODE) { + if (_flags & WF_OFFSCREEN_DECODE) Screen::decodeFrameDelta(dst, _deltaBuffer); - } else { + else Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, (_flags & WF_XOR) == 0); - } } _currentFrame = 0; } @@ -157,11 +152,10 @@ void WSAMovieV1::displayFrame(int frameNum) { int frameCount; if (_currentFrame < frameNum) { frameCount = _numFrames - frameNum + _currentFrame; - if (diffCount > frameCount) { + if (diffCount > frameCount) frameStep = -1; - } else { + else frameCount = diffCount; - } } else { frameCount = _numFrames - _currentFrame + frameNum; if (frameCount >= diffCount) { @@ -176,16 +170,14 @@ void WSAMovieV1::displayFrame(int frameNum) { while (frameCount--) { cf += frameStep; processFrame(cf, dst); - if (cf == _numFrames) { + if (cf == _numFrames) cf = 0; - } } } else { uint16 cf = _currentFrame; while (frameCount--) { - if (cf == 0) { + if (cf == 0) cf = _numFrames; - } processFrame(cf, dst); cf += frameStep; } @@ -193,9 +185,8 @@ void WSAMovieV1::displayFrame(int frameNum) { // display _currentFrame = frameNum; - if (_flags & WF_OFFSCREEN_DECODE) { + if (_flags & WF_OFFSCREEN_DECODE) _vm->screen()->copyBlockToPage(_drawPage, _x, _y, _width, _height, _offscreenBuffer); - } } void WSAMovieV1::processFrame(int frameNum, uint8 *dst) { @@ -205,11 +196,10 @@ void WSAMovieV1::processFrame(int frameNum, uint8 *dst) { assert(frameNum <= _numFrames); const uint8 *src = _frameData + _frameOffsTable[frameNum]; Screen::decodeFrame4(src, _deltaBuffer, _deltaBufferSize); - if (_flags & WF_OFFSCREEN_DECODE) { + if (_flags & WF_OFFSCREEN_DECODE) Screen::decodeFrameDelta(dst, _deltaBuffer); - } else { + else Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, false); - } } #pragma mark - @@ -256,9 +246,8 @@ void WSAMovieAmiga::displayFrame(int frameNum) { const uint8 *src = _buffer; int size = _width * _height; - for (int i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) *dst++ ^= *src++; - } dst = _buffer; } else { @@ -274,11 +263,10 @@ void WSAMovieAmiga::displayFrame(int frameNum) { int frameCount; if (_currentFrame < frameNum) { frameCount = _numFrames - frameNum + _currentFrame; - if (diffCount > frameCount) { + if (diffCount > frameCount) frameStep = -1; - } else { + else frameCount = diffCount; - } } else { frameCount = _numFrames - _currentFrame + frameNum; if (frameCount >= diffCount) { @@ -293,16 +281,14 @@ void WSAMovieAmiga::displayFrame(int frameNum) { while (frameCount--) { cf += frameStep; processFrame(cf, dst); - if (cf == _numFrames) { + if (cf == _numFrames) cf = 0; - } } } else { uint16 cf = _currentFrame; while (frameCount--) { - if (cf == 0) { + if (cf == 0) cf = _numFrames; - } processFrame(cf, dst); cf += frameStep; } @@ -310,9 +296,8 @@ void WSAMovieAmiga::displayFrame(int frameNum) { // display _currentFrame = frameNum; - if (_flags & WF_OFFSCREEN_DECODE) { + if (_flags & WF_OFFSCREEN_DECODE) _vm->screen()->copyBlockToPage(_drawPage, _x, _y, _width, _height, _offscreenBuffer); - } } void WSAMovieAmiga::processFrame(int frameNum, uint8 *dst) { @@ -340,9 +325,8 @@ void WSAMovieAmiga::processFrame(int frameNum, uint8 *dst) { } for (int y = 0; y < _height; ++y) { - for (int x = 0; x < _width; ++x) { + for (int x = 0; x < _width; ++x) *dst++ ^= *src++; - } dst += dstPitch - _width; } } @@ -378,9 +362,8 @@ int WSAMovieV2::open(const char *filename, int unk1, uint8 *palBuf) { if (flags & 1) { offsPal = 0x300; _flags |= WF_HAS_PALETTE; - if (palBuf) { + if (palBuf) memcpy(palBuf, wsaData + 8 + ((_numFrames << 2) & 0xFFFF), 0x300); - } } if (flags & 2) @@ -430,3 +413,4 @@ int WSAMovieV2::open(const char *filename, int unk1, uint8 *palBuf) { } } // end of namespace Kyra + diff --git a/engines/kyra/wsamovie.h b/engines/kyra/wsamovie.h index e9b84a0bbb..3e35fcb47d 100644 --- a/engines/kyra/wsamovie.h +++ b/engines/kyra/wsamovie.h @@ -128,3 +128,4 @@ protected: } // end of namespace Kyra #endif + |