int KyraEngine_HoF::cauldronClearButton(Button *button) { if (!queryGameFlag(2)) { updateCharFacing(); objectChat(getTableString(0xF0, _cCodeBuffer, 1), 0, 0x83, 0xF0); return 0; } if (queryGameFlag(0xE4)) { snd_playSoundEffect(0x0D); return 0; } _screen->hideMouse(); displayInvWsaLastFrame(); snd_playSoundEffect(0x25); loadInvWsa("PULL.WSA", 1, 6, 0, -1, -1, 1); loadInvWsa("CAULD00.WSA", 1, 7, 0, 0xD4, 0x0F, 1); showMessage(0, 0xCF); setCauldronState(0, 0); clearCauldronTable(); snd_playSoundEffect(0x57); loadInvWsa("CAULDFIL.WSA", 1, 7, 0, -1, -1, 1); _screen->showMouse(); return 0; }
void KyraEngine_MR::scoreIncrease(int count, const char *str) { int drawOld = 1; _screen->hideMouse(); showMessage(str, 0xFF, 0xF0); const int x = getScoreX(str); for (int i = 0; i < count; ++i) { int oldScore = _score; int newScore = ++_score; if (newScore > _scoreMax) { _score = _scoreMax; break; } drawScoreCounting(oldScore, newScore, drawOld, x); if (_inventoryState) drawScore(0, 215, 191); _screen->updateScreen(); delay(20, true); snd_playSoundEffect(0x0E, 0xC8); drawOld = 0; } _screen->showMouse(); }
int KyraEngine_LoK::processInputHelper(int xpos, int ypos) { uint8 item = findItemAtPos(xpos, ypos); if (item != 0xFF) { if (_itemInHand == kItemNone) { _screen->hideMouse(); _animator->animRemoveGameItem(item); snd_playSoundEffect(53); assert(_currentCharacter->sceneId < _roomTableSize); Room *currentRoom = &_roomTable[_currentCharacter->sceneId]; int item2 = currentRoom->itemsTable[item]; currentRoom->itemsTable[item] = kItemNone; setMouseItem(item2); assert(_itemList && _takenList); updateSentenceCommand(_itemList[getItemListIndex(item2)], _takenList[0], 179); _itemInHand = item2; _screen->showMouse(); clickEventHandler2(); return 1; } else { exchangeItemWithMouseItem(_currentCharacter->sceneId, item); return 1; } } return 0; }
void KyraEngine_HoF::scrollInventoryWheel() { WSAMovie_v2 movie(this); movie.open("INVWHEEL.WSA", 0, 0); int frames = movie.opened() ? movie.frames() : 6; memcpy(_screenBuffer, _screen->getCPagePtr(2), 64000); uint8 overlay[0x100]; _screen->generateOverlay(_screen->getPalette(0), overlay, 0, 50); _screen->copyRegion(0x46, 0x90, 0x46, 0x79, 0x71, 0x17, 0, 2, Screen::CR_NO_P_CHECK); snd_playSoundEffect(0x25); bool breakFlag = false; for (int i = 0; i <= 6 && !breakFlag; ++i) { if (movie.opened()) { movie.displayFrame(i % frames, 0, 0, 0, 0, 0, 0); _screen->updateScreen(); } uint32 endTime = _system->getMillis() + _tickLength; int y = (i * 981) >> 8; if (y >= 23 || i == 6) { y = 23; breakFlag = true; } _screen->applyOverlay(0x46, 0x79, 0x71, 0x17, 2, overlay); _screen->copyRegion(0x46, y+0x79, 0x46, 0x90, 0x71, 0x2E, 2, 0, Screen::CR_NO_P_CHECK); _screen->updateScreen(); delayUntil(endTime); } _screen->copyBlockToPage(2, 0, 0, 320, 200, _screenBuffer); movie.close(); }
void KyraEngine_LoK::snd_playWanderScoreViaMap(int command, int restart) { if (restart) _lastMusicCommand = -1; if (_flags.platform == Common::kPlatformFMTowns) { if (command >= 35 && command <= 38) { snd_playSoundEffect(command - 20); } else if (command >= 2) { if (_lastMusicCommand != command) // the original does -2 here we handle this inside _sound->playTrack() _sound->playTrack(command); } else { _sound->beginFadeOut(); } _lastMusicCommand = command; } else if (_flags.platform == Common::kPlatformPC98) { if (command == 1) { _sound->beginFadeOut(); } else if ((command >= 2 && command < 53) || command == 55) { if (_lastMusicCommand != command) _sound->playTrack(command); } else { _sound->haltTrack(); } _lastMusicCommand = command; } else { KyraEngine_v1::snd_playWanderScoreViaMap(command, restart); } }
void EoBCoreEngine::useWand(int charIndex, int weaponSlot) { int v = _items[_characters[charIndex].inventory[weaponSlot]].value; if (!v) { _txt->printMessage(_wandStrings[0]); return; } if (v != 5) useMagicScroll(charIndex, _wandTypes[v], weaponSlot); else if (_flags.gameID == GI_EOB2) useMagicScroll(charIndex, 64, weaponSlot); else { uint16 bl1 = calcNewBlockPosition(_currentBlock, _currentDirection); uint16 bl2 = calcNewBlockPosition(bl1, _currentDirection); snd_playSoundEffect(98); sparkEffectOffensive(); if ((_wllWallFlags[_levelBlockProperties[bl2].walls[_currentDirection ^ 2]] & 4) && !(_levelBlockProperties[bl2].flags & 7) && (_levelBlockProperties[bl1].flags & 7)) { for (int i = 0; i < 30; i++) { if (_monsters[i].block != bl1) continue; placeMonster(&_monsters[i], bl2, -1); _sceneUpdateRequired = true; } } else { _txt->printMessage(_wandStrings[1]); } } }
bool KyraEngine_HoF::checkInventoryItemExchange(Item handItem, int slot) { bool removeItem = false; Item newItem = kItemNone; Item invItem = _mainCharacter.inventory[slot]; for (const uint16 *table = _itemMagicTable; *table != 0xFFFF; table += 4) { if (table[0] != handItem || table[1] != (uint16)invItem) continue; if (table[3] == 0xFFFF) continue; removeItem = (table[3] == 1); newItem = (Item)table[2]; snd_playSoundEffect(0x68); _mainCharacter.inventory[slot] = newItem; clearInventorySlot(slot, 0); drawInventoryShape(0, newItem, slot); if (removeItem) removeHandItem(); if (_lang != 1) updateCommandLineEx(newItem+54, 0x2E, 0xD6); return true; } return false; }
void KyraEngine_LoK::mainLoop() { // Initialize debugger since how it should be fully usable _debugger->initialize(); _eventList.clear(); while (!shouldQuit()) { int32 frameTime = (int32)_system->getMillis(); if (_currentCharacter->sceneId == 210) { updateKyragemFading(); if (seq_playEnd() && _deathHandler != 8) break; } if (_deathHandler != -1) { snd_playWanderScoreViaMap(0, 1); snd_playSoundEffect(49); _screen->hideMouse(); _screen->setMouseCursor(1, 1, _shapes[0]); removeHandItem(); _screen->showMouse(); _gui->buttonMenuCallback(0); _deathHandler = -1; } if ((_brandonStatusBit & 2) && _brandonStatusBit0x02Flag) _animator->animRefreshNPC(0); if ((_brandonStatusBit & 0x20) && _brandonStatusBit0x20Flag) { _animator->animRefreshNPC(0); _brandonStatusBit0x20Flag = 0; } // FIXME: Why is this here? _screen->showMouse(); int inputFlag = checkInput(_buttonList, _currentCharacter->sceneId != 210); removeInputTop(); updateMousePointer(); _timer->update(); _sound->process(); updateTextFade(); if (inputFlag == 198 || inputFlag == 199) processInput(_mouseX, _mouseY); if (skipFlag()) resetSkipFlag(); delay((frameTime + _gameSpeed) - _system->getMillis(), true, true); } }
void KyraEngine_MR::showGoodConscience() { if (_goodConscienceShown) return; _goodConscienceShown = true; ++_goodConscienceAnim; _goodConscienceAnim %= 5; setNextIdleAnimTimer(); _goodConsciencePosition = (_mainCharacter.x1 <= 160); if (_badConscienceShown) _goodConsciencePosition = !_badConsciencePosition; int anim = _goodConscienceAnim + (_goodConsciencePosition ? 0 : 5); TalkObject &talkObject = _talkObjectList[87]; if (_goodConsciencePosition) talkObject.x = 290; else talkObject.x = 30; talkObject.y = 30; static const char *const animFilenames[] = { "STUFL00.WSA", "STUFL02.WSA", "STUFL04.WSA", "STUFL03.WSA", "STUFL01.WSA", "STUFR00.WSA", "STUFR02.WSA", "STUFR04.WSA", "STUFR03.WSA", "STUFR01.WSA" }; setupSceneAnimObject(0x0F, 9, 0, 187, -1, -1, -1, -1, 0, 0, 0, -1, animFilenames[anim]); for (uint i = 0; i <= _goodConscienceFrameTable[_goodConscienceAnim]; ++i) { if (i == 10) snd_playSoundEffect(0x7F, 0xC8); updateSceneAnim(0x0F, i); delay(2*_tickLength, true); } if (_mainCharacter.animFrame < 50 || _mainCharacter.animFrame > 87) return; if (_mainCharacter.y1 == -1 || (_mainCharacter.x1 != -1 && _mainCharacter.animFrame == 87) || _mainCharacter.animFrame == 87) { _mainCharacter.animFrame = 87; } else { if (_goodConsciencePosition) _mainCharacter.facing = 3; else _mainCharacter.facing = 5; _mainCharacter.animFrame = _characterFrameTable[_mainCharacter.facing]; } updateCharacterAnim(0); refreshAnimObjectsIfNeed(); }
void DarkMoonEngine::runNpcDialogue(int npcIndex) { if (npcIndex == 0) { snd_playSoundEffect(57); if (npcJoinDialogue(0, 1, 3, 2)) setScriptFlags(0x40); } else if (npcIndex == 1) { snd_playSoundEffect(53); gui_drawDialogueBox(); _txt->printDialogueText(4, 0); int r = runDialogue(-1, 2, _npcStrings[0][0], _npcStrings[0][1]) - 1; if (r == 0) { snd_stopSound(); delay(3 * _tickLength); snd_playSoundEffect(91); npcJoinDialogue(1, 5, 6, 7); } else if (r == 1) { setScriptFlags(0x20); } } else if (npcIndex == 2) { snd_playSoundEffect(55); gui_drawDialogueBox(); _txt->printDialogueText(8, 0); int r = runDialogue(-1, 2, _npcStrings[1][0], _npcStrings[1][1]) - 1; if (r == 0) { if (rollDice(1, 2, -1)) _txt->printDialogueText(9, _okStrings[0]); else npcJoinDialogue(2, 102, 103, 104); setScriptFlags(8); } else if (r == 1) { _currentDirection = 0; } } }
void KyraEngine_MR::playStudioSFX(const char *str) { if (!_configStudio) return; if (_rnd.getRandomNumberRng(1, 2) != 2) return; const int strSize = strlen(str) - 1; if (str[strSize] != '?' && str[strSize] != '!') return; snd_playSoundEffect(_curStudioSFX++, 128); if (_curStudioSFX > 291) _curStudioSFX = 283; }
void KyraEngine_MR::hideBadConscience() { if (!_badConscienceShown) return; _badConscienceShown = false; for (int frame = _badConscienceFrameTable[_badConscienceAnim+8]; frame >= 0; --frame) { if (frame == 15) snd_playSoundEffect(0x31, 0xC8); updateSceneAnim(0x0E, frame); delay(1*_tickLength, true); } updateSceneAnim(0x0E, -1); update(); removeSceneAnimObject(0x0E, 1); setNextIdleAnimTimer(); }
void KyraEngine_MR::eelScript() { if (_chatText) return; _screen->hideMouse(); if (_inventoryState) hideInventory(); removeHandItem(); objectChat((const char *)getTableEntry(_cCodeFile, 35), 0, 204, 35); objectChat((const char *)getTableEntry(_cCodeFile, 40), 0, 204, 40); setGameFlag(0xD1); snd_playSoundEffect(0x2A, 0xC8); setGameFlag(0x171); switch (_characterShapeFile-1) { case 0: runAnimationScript("EELS01.EMC", 0, 0, 1, 1); break; case 1: runAnimationScript("EELS02.EMC", 0, 0, 1, 1); break; case 2: runAnimationScript("EELS03.EMC", 0, 0, 1, 1); break; case 3: runAnimationScript("EELS04.EMC", 0, 0, 1, 1); break; default: resetGameFlag(0x171); runAnimationScript("EELS00.EMC", 0, 0, 1, 1); } changeChapter(2, 29, 0, 4); _screen->showMouse(); }
bool KyraRpgEngine::snd_processEnvironmentalSoundEffect(int soundId, int block) { if (!_sound->sfxEnabled() || shouldQuit()) return false; if (_environmentSfx) snd_playSoundEffect(_environmentSfx, _environmentSfxVol); int dist = 0; if (block) { dist = getBlockDistance(_currentBlock, block); if (dist > _envSfxDistThreshold) { _environmentSfx = 0; return false; } } _environmentSfx = soundId; _environmentSfxVol = (15 - ((block || (_flags.gameID == GI_LOL && dist < 2)) ? dist : 0)) << 4; return true; }
void LoLEngine::takeCredits(int credits, int redraw) { if (redraw) snd_playSoundEffect(101, -1); if (credits > _credits) credits = _credits; int t = credits / 30; if (!t) t = 1; int cnt = 0; while (credits && _credits > 0) { if (t > credits) t = credits; if (_credits - t < 60 && t > 0) { cnt = 0; do { if (--_credits < 60) { int d = _stashSetupData[_credits % 12] - _credits / 12; if (d < 0) d += 5; _moneyColumnHeight[d]--; } } while (++cnt < t); } else if (_credits - t >= 60) { _credits -= t; } if (redraw) { gui_drawMoneyBox(6); if (credits) delay(_tickLength, 1); } credits -= t; } }
void KyraEngine_HoF::bookLoop() { Button bookButtons[5]; GUI_V2_BUTTON(bookButtons[0], 0x24, 0, 0, 1, 1, 1, 0x4487, 0, 0x82, 0xBE, 0x0A, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0); bookButtons[0].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookPrevPage); GUI_V2_BUTTON(bookButtons[1], 0x25, 0, 0, 1, 1, 1, 0x4487, 0, 0xB1, 0xBE, 0x0A, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0); bookButtons[1].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookNextPage); GUI_V2_BUTTON(bookButtons[2], 0x26, 0, 0, 1, 1, 1, 0x4487, 0, 0x8F, 0xBE, 0x21, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0); bookButtons[2].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookClose); GUI_V2_BUTTON(bookButtons[3], 0x27, 0, 0, 1, 1, 1, 0x4487, 0, 0x08, 0x08, 0x90, 0xB4, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0); bookButtons[3].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookPrevPage); GUI_V2_BUTTON(bookButtons[4], 0x28, 0, 0, 1, 1, 1, 0x4487, 0, 0xAA, 0x08, 0x8E, 0xB4, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0); bookButtons[4].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookNextPage); Button *buttonList = 0; for (uint i = 0; i < ARRAYSIZE(bookButtons); ++i) buttonList = _gui->addButtonToList(buttonList, &bookButtons[i]); showBookPage(); _bookShown = true; while (_bookShown && !shouldQuit()) { checkInput(buttonList); removeInputTop(); if (_bookCurPage != _bookNewPage) { _bookCurPage = _bookNewPage; _screen->clearPage(2); loadBookBkgd(); showBookPage(); snd_playSoundEffect(0x64); _screen->copyRegion(0, 0, 0, 0, 0x140, 0xC8, 2, 0, Screen::CR_NO_P_CHECK); _screen->updateScreen(); } _system->delayMillis(10); } _screen->clearPage(2); }
void KyraEngine_MR::handleInput(int x, int y) { if (_inventoryState) return; setNextIdleAnimTimer(); if (_unk5) { _unk5 = 0; return; } if (!_screen->isMouseVisible()) return; if (_savedMouseState == -3) { snd_playSoundEffect(0x0D, 0x80); return; } setNextIdleAnimTimer(); int skip = 0; if (checkCharCollision(x, y) && _savedMouseState >= -1 && runSceneScript2()) { return; } else if (_itemInHand != 27 && pickUpItem(x, y, 1)) { return; } else if (checkItemCollision(x, y) == -1) { resetGameFlag(1); skip = runSceneScript1(x, y); if (queryGameFlag(1)) { resetGameFlag(1); return; } else if (_unk5) { _unk5 = 0; return; } } if (_deathHandler >= 0) skip = 1; if (skip) return; if (checkCharCollision(x, y)) { if (runSceneScript2()) return; } else if (_itemInHand >= 0 && _savedMouseState >= 0) { if (_itemInHand == 27) { makeCharFacingMouse(); } else if (y <= 187) { if (_itemInHand == 43) removeHandItem(); else dropItem(0, _itemInHand, x, y, 1); } return; } else if (_savedMouseState == -3) { return; } else { if (y > 187 && _savedMouseState > -4) return; if (_unk5) { _unk5 = 0; return; } } inputSceneChange(x, y, 1, 1); }
void KyraEngine_MR::showBadConscience() { if (_badConscienceShown) return; _badConscienceShown = true; _badConscienceAnim = _rnd.getRandomNumberRng(0, 2); if (_currentChapter == 2) _badConscienceAnim = 5; else if (_currentChapter == 3) _badConscienceAnim = 3; else if (_currentChapter == 4 && _rnd.getRandomNumberRng(1, 100) <= 25) _badConscienceAnim = 6; else if (_currentChapter == 5 && _rnd.getRandomNumberRng(1, 100) <= 25) _badConscienceAnim = 7; if (_characterShapeFile == 9) _badConscienceAnim = 4; _badConsciencePosition = (_mainCharacter.x1 <= 160); if (_goodConscienceShown) _badConsciencePosition = !_goodConsciencePosition; int anim = _badConscienceAnim + (_badConsciencePosition ? 0 : 8); TalkObject &talkObject = _talkObjectList[1]; if (_badConsciencePosition) talkObject.x = 290; else talkObject.x = 30; talkObject.y = 30; static const char *const animFilenames[] = { "GUNFL00.WSA", "GUNFL01.WSA", "GUNFL02.WSA", "GUNFL03.WSA", "GUNFL04.WSA", "GUNFL05.WSA", "GUNFL06.WSA", "GUNFL07.WSA", "GUNFR00.WSA", "GUNFR01.WSA", "GUNFR02.WSA", "GUNFR03.WSA", "GUNFR04.WSA", "GUNFR05.WSA", "GUNFR06.WSA", "GUNFR07.WSA" }; setupSceneAnimObject(0x0E, 9, 0, 187, -1, -1, -1, -1, 0, 0, 0, -1, animFilenames[anim]); for (uint i = 0; i <= _badConscienceFrameTable[_badConscienceAnim]; ++i) { if (i == 8) snd_playSoundEffect(0x1B, 0xC8); updateSceneAnim(0x0E, i); delay(3*_tickLength, true); } if (_mainCharacter.animFrame < 50 || _mainCharacter.animFrame > 87) return; if (_mainCharacter.y1 == -1 || (_mainCharacter.x1 != -1 && _mainCharacter.animFrame == 87) || _mainCharacter.animFrame == 87) { _mainCharacter.animFrame = 87; } else { if (_badConsciencePosition) _mainCharacter.facing = 3; else _mainCharacter.facing = 5; _mainCharacter.animFrame = _characterFrameTable[_mainCharacter.facing]; } updateCharacterAnim(0); refreshAnimObjectsIfNeed(); }
void EoBCoreEngine::startSpell(int spell) { EoBSpell *s = &_spells[spell]; EoBCharacter *c = &_characters[_activeSpellCharId]; snd_playSoundEffect(s->sound); if (s->flags & 0xA0) sparkEffectDefensive(_activeSpellCharId); else if (s->flags & 0x40) sparkEffectDefensive(-1); else if (s->flags & 0x1000) sparkEffectOffensive(); if (s->flags & 0x20) { _txt->printMessage(c->name); _txt->printMessage(_flags.gameID == GI_EOB1 ? _magicStrings3[1] : _magicStrings1[5]); } if ((s->flags & 0x30) && (s->effectFlags & c->effectFlags)) { if (_flags.gameID == GI_EOB2) printWarning(Common::String::format(_magicStrings7[0], c->name, s->name).c_str()); } else if ((s->flags & 0x50) && (s->effectFlags & _partyEffectFlags)) { if (_flags.gameID == GI_EOB1 && s->effectFlags == 0x400) // EOB 1 only warns in case of a bless spell printWarning(_magicStrings8[1]); else printWarning(Common::String::format(_magicStrings7[1], s->name).c_str()); } else { if (s->flags & 8) setSpellEventTimer(spell, s->timingPara[0], s->timingPara[1], s->timingPara[2], s->timingPara[3]); _returnAfterSpellCallback = false; if (s->startCallback) (this->*s->startCallback)(); if (_returnAfterSpellCallback) return; if (s->flags & 1) c->effectFlags |= s->effectFlags; if (s->flags & 4) _partyEffectFlags |= s->effectFlags; if (s->flags & 0x200) { for (int i = 0; i < 6; i++) { if (!testCharacter(i, 1)) continue; if (!testCharacter(i, 2) && !(s->flags & 0x800)) continue; _characters[i].effectFlags |= s->effectFlags; } } if (s->flags & 2) recalcArmorClass(_activeSpellCharId); if (s->flags & 0x20A0) gui_drawCharPortraitWithStats(_activeSpellCharId); if (s->flags & 0x40) gui_drawAllCharPortraitsWithStats(); } if (_castScrollSlot) { gui_updateSlotAfterScrollUse(); } else { _characters[_openBookChar].disabledSlots |= 4; setCharEventTimer(_openBookChar, 72, 11, 1); gui_toggleButtons(); gui_drawSpellbook(); } if (_flags.gameID == GI_EOB2) { //_castSpellWd1 = spell; runLevelScript(_currentBlock, 0x800); //_castSpellWd1 = 0; } }
int KyraEngine_MR::o3_playSoundEffect(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_playSoundEffect(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); snd_playSoundEffect(stackPos(0), stackPos(1)); return 0; }
Common::Error KyraEngine_MR::loadGameState(int slot) { const char *fileName = getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *saveFile = openSaveForReading(fileName, header); if (!saveFile) { showMessageFromCCode(17, 0xB3, 0); snd_playSoundEffect(0x0D, 0xC8); return Common::kUnknownError; } if (header.originalSave) warning("Trying to load savegame from original interpreter, while this is possible, it is not officially supported"); if (_inventoryState) { updateCharacterAnim(0); restorePage3(); drawAnimObjects(); _inventoryState = true; refreshAnimObjects(0); hideInventory(); } _deathHandler = -1; if (!_unkSceneScreenFlag1) _lastMusicCommand = -1; int curShapes = _characterShapeFile; Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, DisposeAfterUse::YES); _screen->hideMouse(); if (!header.originalSave) { _timer->loadDataFromFile(in, header.version); uint32 flagsSize = in.readUint32BE(); assert(flagsSize <= sizeof(_flagsTable)); in.read(_flagsTable, flagsSize); } _lastMusicCommand = in.readSint16(); _currentChapter = in.readByte(); _characterShapeFile = in.readByte(); if (header.version >= 12 || header.originalSave) _album.curPage = in.readByte(); if (header.originalSave) in.readByte(); _score = in.readSint16(); _scoreMax = in.readSint16(); _malcolmsMood = in.readByte(); if (header.originalSave) in.seek(8, SEEK_CUR); for (int i = 0; i < 30; ++i) in.read(_conversationState[i], 30); if (!header.originalSave) { in.read(_newSceneDlgState, 40); } else { for (int i = 0; i < 40; ++i) _newSceneDlgState[i] = in.readUint16(); } for (int i = 0; i < 100; ++i) _hiddenItems[i] = in.readSint16(); if (header.originalSave) in.read(_flagsTable, 69); in.read(_scoreFlagTable, 26); _mainCharacter.sceneId = in.readUint16(); _mainCharacter.dlgIndex = in.readSint16(); _mainCharacter.height = in.readByte(); _mainCharacter.facing = in.readByte(); _mainCharacter.animFrame = in.readUint16(); if (!header.originalSave) { _mainCharacter.walkspeed = in.readByte(); } else { in.seek(2, SEEK_CUR); _mainCharacter.walkspeed = in.readUint32(); } for (int i = 0; i < 10; ++i) _mainCharacter.inventory[i] = in.readUint16(); _mainCharacter.x1 = in.readSint16(); _mainCharacter.y1 = in.readSint16(); _mainCharacter.x2 = in.readSint16(); _mainCharacter.y2 = in.readSint16(); _mainCharacter.x3 = in.readSint16(); _mainCharacter.y3 = in.readSint16(); for (int i = 0; i < 50; ++i) { _itemList[i].id = in.readSint16(); _itemList[i].sceneId = in.readUint16(); _itemList[i].x = in.readSint16(); _itemList[i].y = in.readSint16(); if (header.version <= 9 || header.originalSave) in.readUint16(); } for (int i = 0; i < 88; ++i) { in.read(_talkObjectList[i].filename, 13); _talkObjectList[i].sceneAnim = in.readByte(); _talkObjectList[i].sceneScript = in.readByte(); _talkObjectList[i].x = in.readSint16(); _talkObjectList[i].y = in.readSint16(); _talkObjectList[i].color = in.readByte(); if (header.version >= 13 || header.originalSave) _talkObjectList[i].sceneId = in.readByte(); } for (int i = 0; i < 98; ++i) { if (!header.originalSave) { in.read(_sceneList[i].filename1, 10); } else { in.read(_sceneList[i].filename1, 9); _sceneList[i].filename1[9] = 0; } if (!header.originalSave) { in.read(_sceneList[i].filename2, 10); } else { in.read(_sceneList[i].filename2, 9); _sceneList[i].filename2[9] = 0; } _sceneList[i].exit1 = in.readUint16(); _sceneList[i].exit2 = in.readUint16(); _sceneList[i].exit3 = in.readUint16(); _sceneList[i].exit4 = in.readUint16(); _sceneList[i].flags = in.readByte(); _sceneList[i].sound = in.readByte(); } _itemInHand = in.readSint16(); if (header.originalSave) { uint32 currentTime = _system->getMillis(); for (int i = 0; i < 6; ++i) _timer->setDelay(i, in.readSint32LE()); for (int i = 0; i < 6; ++i) { if (in.readUint16LE()) _timer->enable(i); else _timer->disable(i); } for (int i = 0; i < 6; ++i) _timer->setNextRun(i, currentTime + (in.readUint32LE() * _tickLength)); _timer->resetNextRun(); } _sceneExit1 = in.readUint16(); _sceneExit2 = in.readUint16(); _sceneExit3 = in.readUint16(); _sceneExit4 = in.readUint16(); if (saveFile->err() || saveFile->eos()) { warning("Load failed ('%s', '%s').", fileName, header.description.c_str()); return Common::kUnknownError; } else { debugC(1, kDebugLevelMain, "Loaded savegame '%s.'", header.description.c_str()); } _loadingState = true; updateCharacterAnim(0); _loadingState = false; if (curShapes != _characterShapeFile) loadCharacterShapes(_characterShapeFile); _mainCharX = _mainCharacter.x2 = _mainCharacter.x1; _mainCharY = _mainCharacter.y2 = _mainCharacter.y1; _mainCharacter.facing = 4; _badConscienceShown = false; _badConsciencePosition = false; _goodConscienceShown = false; _goodConsciencePosition = false; enterNewScene(_mainCharacter.sceneId, _mainCharacter.facing, 0, 0, 1); setHandItem(_itemInHand); if (_lastMusicCommand >= 0 && !_unkSceneScreenFlag1) snd_playWanderScoreViaMap(_lastMusicCommand, 1); else if (_lastMusicCommand == -1) snd_playWanderScoreViaMap(28, 1); while (!_screen->isMouseVisible()) _screen->showMouse(); setCommandLineRestoreTimer(7); _shownMessage = " "; _restoreCommandLine = false; // We didn't explicitly set the walk speed, but it's saved as part of // the _timers array, so we need to re-sync it with _configWalkspeed. setWalkspeed(_configWalkspeed); return Common::kNoError; }
void EoBCoreEngine::usePotion(int charIndex, int weaponSlot) { EoBCharacter *c = &_characters[charIndex]; int val = deleteInventoryItem(charIndex, weaponSlot); snd_playSoundEffect(10); if (_flags.gameID == GI_EOB1) val--; switch (val) { case 0: sparkEffectDefensive(charIndex); c->strengthCur = 22; c->strengthExtCur = 0; setCharEventTimer(charIndex, 546 * rollDice(1, 4, 4), 7, 1); break; case 1: sparkEffectDefensive(charIndex); modifyCharacterHitpoints(charIndex, rollDice(2, 4, 2)); break; case 2: sparkEffectDefensive(charIndex); modifyCharacterHitpoints(charIndex, rollDice(3, 8, 3)); break; case 3: statusAttack(charIndex, 2, _potionStrings[0], 0, 1, 8, 1); c->effectFlags &= ~0x2000; if (c->flags & 2) return; break; case 4: sparkEffectDefensive(charIndex); c->food = 100; if (_currentControlMode) gui_drawCharPortraitWithStats(charIndex); break; case 5: sparkEffectDefensive(charIndex); c->effectFlags |= 0x10000; setCharEventTimer(charIndex, 546 * rollDice(1, 4, 4), 12, 1); snd_playSoundEffect(100); gui_drawCharPortraitWithStats(charIndex); break; case 6: sparkEffectDefensive(charIndex); c->effectFlags |= 0x40; gui_drawCharPortraitWithStats(charIndex); break; case 7: sparkEffectDefensive(charIndex); neutralizePoison(charIndex); break; default: break; } _txt->printMessage(_potionStrings[1], -1, c->name, _potionEffectStrings[val]); }
void DarkMoonEngine::useHorn(int charIndex, int weaponSlot) { int v = _items[_characters[charIndex].inventory[weaponSlot]].value - 1; _txt->printMessage(_hornStrings[v]); snd_playSoundEffect(_hornSounds[v]); }
int KyraEngine_HoF::cauldronButton(Button *button) { if (!queryGameFlag(2)) { objectChat(getTableString(0xF0, _cCodeBuffer, 1), 0, 0x83, 0xF0); return 0; } if (!_screen->isMouseVisible() || _mouseState < -1) return 0; if (queryGameFlag(0xE4)) { snd_playSoundEffect(0x0D); return 0; } updateCharFacing(); for (int i = 0; _cauldronProtectedItems[i] != -1; ++i) { if (_itemInHand == _cauldronProtectedItems[i]) { objectChat(getTableString(0xF1, _cCodeBuffer, 1), 0, 0x83, 0xF1); return 0; } } if (_itemInHand == -1) { listItemsInCauldron(); return 0; } for (int i = 0; _cauldronBowlTable[i] != -1; i += 2) { if (_itemInHand == _cauldronBowlTable[i]) { addFrontCauldronTable(_itemInHand); setHandItem(_cauldronBowlTable[i+1]); if (!updateCauldron()) { _cauldronState = 0; cauldronRndPaletteFade(); } return 0; } } if (_itemInHand == 18) { const int16 *magicTable = (_mainCharacter.sceneId == 77) ? _cauldronMagicTableScene77 : _cauldronMagicTable; while (magicTable[0] != -1) { if (_cauldronState == magicTable[0]) { setHandItem(magicTable[1]); snd_playSoundEffect(0x6C); ++_cauldronUseCount; if (_cauldronStateTable[_cauldronState] <= _cauldronUseCount && _cauldronUseCount) { showMessage(0, 0xCF); setCauldronState(0, true); clearCauldronTable(); } return 0; } magicTable += 2; } } else if (_itemInHand >= 0) { int item = _itemInHand; cauldronItemAnim(item); addFrontCauldronTable(item); if (!updateCauldron()) { _cauldronState = 0; cauldronRndPaletteFade(); } } return 0; }
Common::Error KyraEngine_HoF::loadGameState(int slot) { const char *fileName = getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *saveFile = openSaveForReading(fileName, header); if (!saveFile) { showMessageFromCCode(0x35, 0x84, 0); snd_playSoundEffect(0x0D); return Common::kUnknownError; } if (header.originalSave) warning("Trying to load savegame from original interpreter, while this is possible, it is not officially supported"); bool setFlag1EE = (queryGameFlag(0x1EE) != 0); _deathHandler = -1; if (!_unkSceneScreenFlag1) { _sound->beginFadeOut(); _system->delayMillis(5 * _tickLength); _lastMusicCommand = -1; } int loadedZTable = _characterShapeFile; Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, DisposeAfterUse::YES); _screen->hideMouse(); if (!header.originalSave) { _timer->loadDataFromFile(in, header.version); uint32 flagsSize = in.readUint32BE(); assert(flagsSize <= sizeof(_flagsTable)); in.read(_flagsTable, flagsSize); } // usually we have to save the flag set by opcode 10 here //word_2AB05 = in.readUint16(); if (header.originalSave) in.readUint16(); _lastMusicCommand = in.readSint16(); _newChapterFile = in.readByte(); _characterShapeFile = in.readByte(); _cauldronState = in.readByte(); _colorCodeFlag1 = in.readByte(); _colorCodeFlag2 = in.readByte(); _bookCurPage = in.readByte(); _bookMaxPage = in.readByte(); for (int i = 0; i < 7; ++i) _presetColorCode[i] = in.readByte(); for (int i = 0; i < 7; ++i) _inputColorCode[i] = in.readByte(); for (int i = 0; i < 25; ++i) _cauldronTable[i] = in.readSint16(); for (int i = 0; i < 20; ++i) _hiddenItems[i] = in.readSint16(); if (header.originalSave) { assert(sizeof(_flagsTable) >= 0x41); in.read(_flagsTable, 0x41); } for (int i = 0; i < 19; ++i) in.read(_conversationState[i], 14); if (!header.originalSave) { in.read(_newSceneDlgState, 32); } else { for (int i = 0; i < 31; ++i) _newSceneDlgState[i] = in.readUint16(); } _cauldronUseCount = in.readSint16(); if (header.originalSave) in.seek(6, SEEK_CUR); _mainCharacter.sceneId = in.readUint16(); _mainCharacter.dlgIndex = in.readSint16(); _mainCharacter.height = in.readByte(); _mainCharacter.facing = in.readByte(); _mainCharacter.animFrame = in.readUint16(); if (header.version <= 10 || header.originalSave) in.seek(3, SEEK_CUR); for (int i = 0; i < 20; ++i) _mainCharacter.inventory[i] = in.readUint16(); _mainCharacter.x1 = in.readSint16(); _mainCharacter.y1 = in.readSint16(); _mainCharacter.x2 = in.readSint16(); _mainCharacter.y2 = in.readSint16(); for (int i = 0; i < 30; ++i) { _itemList[i].id = in.readSint16(); _itemList[i].sceneId = in.readUint16(); _itemList[i].x = in.readSint16(); _itemList[i].y = in.readByte(); if (header.version <= 9 || header.originalSave) in.readUint16(); } for (int i = 0; i < 72; ++i) { in.read(_talkObjectList[i].filename, 13); _talkObjectList[i].scriptId = in.readByte(); _talkObjectList[i].x = in.readSint16(); _talkObjectList[i].y = in.readSint16(); _talkObjectList[i].color = in.readByte(); } for (int i = 0; i < 86; ++i) { if (!header.originalSave) { in.read(_sceneList[i].filename1, 10); } else { in.read(_sceneList[i].filename1, 9); _sceneList[i].filename1[9] = 0; } _sceneList[i].exit1 = in.readUint16(); _sceneList[i].exit2 = in.readUint16(); _sceneList[i].exit3 = in.readUint16(); _sceneList[i].exit4 = in.readUint16(); _sceneList[i].flags = in.readByte(); _sceneList[i].sound = in.readByte(); } _itemInHand = in.readSint16(); if (header.originalSave) { uint32 currentTime = _system->getMillis(); for (int i = 0; i < 6; ++i) _timer->setDelay(i, in.readSint32LE()); for (int i = 0; i < 6; ++i) { if (in.readUint16LE()) _timer->enable(i); else _timer->disable(i); } for (int i = 0; i < 6; ++i) _timer->setNextRun(i, currentTime + (in.readUint32LE() * _tickLength)); _timer->resetNextRun(); } _sceneExit1 = in.readUint16(); _sceneExit2 = in.readUint16(); _sceneExit3 = in.readUint16(); _sceneExit4 = in.readUint16(); if (saveFile->err() || saveFile->eos()) { warning("Load failed ('%s', '%s').", fileName, header.description.c_str()); return Common::kUnknownError; } else { debugC(1, kDebugLevelMain, "Loaded savegame '%s.'", header.description.c_str()); } if (loadedZTable != _characterShapeFile) loadCharacterShapes(_characterShapeFile); _screen->loadBitmap("_PLAYFLD.CPS", 3, 3, 0); if (!queryGameFlag(1)) _screen->copyRegion(0xCE, 0x90, 0xCE, 0x90, 0x2C, 0x2C, 2, 0, Screen::CR_NO_P_CHECK); if (!queryGameFlag(2)) _screen->copyRegion(0xFA, 0x90, 0xFA, 0x90, 0x46, 0x2C, 2, 0, Screen::CR_NO_P_CHECK); _screen->loadBitmap("_PLAYALL.CPS", 3, 3, 0); if (queryGameFlag(1)) _screen->copyRegion(0xCE, 0x90, 0xCE, 0x90, 0x2C, 0x2C, 2, 0, Screen::CR_NO_P_CHECK); if (queryGameFlag(2)) _screen->copyRegion(0xFA, 0x90, 0xFA, 0x90, 0x46, 0x2C, 2, 0, Screen::CR_NO_P_CHECK); redrawInventory(0); int cauldronUseCount = _cauldronUseCount; setCauldronState(_cauldronState, 0); _cauldronUseCount = cauldronUseCount; _mainCharX = _mainCharacter.x2 = _mainCharacter.x1; _mainCharY = _mainCharacter.y2 = _mainCharacter.y1; _mainCharacter.facing = 4; enterNewScene(_mainCharacter.sceneId, _mainCharacter.facing, 0, 0, 1); setDelayedCursorUpdate(); if (_lastMusicCommand >= 0 && !_unkSceneScreenFlag1) snd_playWanderScoreViaMap(_lastMusicCommand, 1); while (!_screen->isMouseVisible()) _screen->showMouse(); setTimer1DelaySecs(7); _shownMessage = " "; _fadeMessagePalette = false; if (setFlag1EE) setGameFlag(0x1EE); // We didn't explicitly set the walk speed, but it's saved as part of // the _timers array, so we need to re-sync it with _configWalkspeed. setWalkspeed(_configWalkspeed); return Common::kNoError; }
int KyraEngine_HoF::bookButton(Button *button) { if (!queryGameFlag(1)) { objectChat(getTableString(0xEB, _cCodeBuffer, 1), 0, 0x83, 0xEB); return 0; } if (!_screen->isMouseVisible()) return 0; if (queryGameFlag(0xE5)) { snd_playSoundEffect(0x0D); return 0; } if (_itemInHand == 72) { if (!queryGameFlag(0xE2)) { _bookMaxPage += 2; removeHandItem(); snd_playSoundEffect(0x6C); setGameFlag(0xE2); } if (!queryGameFlag(0x18A) && queryGameFlag(0x170)) { _bookMaxPage += 2; removeHandItem(); snd_playSoundEffect(0x6C); setGameFlag(0x18A); } return 0; } if (_mouseState != -1) { snd_playSoundEffect(0x0D); return 0; } _screen->hideMouse(); showMessage(0, 0xCF); displayInvWsaLastFrame(); _bookNewPage = _bookCurPage; if (_screenBuffer) { memcpy(_screenBuffer, _screen->getCPagePtr(0), 64000); } _screen->copyPalette(2, 0); _screen->fadeToBlack(7, &_updateFunctor); _screen->loadPalette("_BOOK.COL", _screen->getPalette(0)); loadBookBkgd(); showBookPage(); _screen->copyRegion(0, 0, 0, 0, 0x140, 0xC8, 2, 0, Screen::CR_NO_P_CHECK); _screen->updateScreen(); int oldItemInHand = _itemInHand; removeHandItem(); _screen->fadePalette(_screen->getPalette(0), 7); _screen->showMouse(); bookLoop(); _screen->fadeToBlack(7); _screen->hideMouse(); setHandItem(oldItemInHand); updateMouse(); restorePage3(); if (_screenBuffer) { _screen->copyBlockToPage(0, 0, 0, 320, 200, _screenBuffer); } setHandItem(_itemInHand); _screen->copyPalette(0, 2); _screen->fadePalette(_screen->getPalette(0), 7, &_updateFunctor); _screen->showMouse(); if (!queryGameFlag(4) && !queryGameFlag(0xB8)) { objectChat(getTableString(0xEC, _cCodeBuffer, 1), 0, 0x83, 0xEC); objectChat(getTableString(0xED, _cCodeBuffer, 1), 0, 0x83, 0xED); objectChat(getTableString(0xEE, _cCodeBuffer, 1), 0, 0x83, 0xEE); objectChat(getTableString(0xEF, _cCodeBuffer, 1), 0, 0x83, 0xEF); setGameFlag(4); } return 0; }
void KyraEngine_HoF::handleInput(int x, int y) { setNextIdleAnimTimer(); if (_unk5) { _unk5 = 0; return; } if (!_screen->isMouseVisible()) return; if (_savedMouseState == -2) { snd_playSoundEffect(13); return; } setNextIdleAnimTimer(); if (x <= 6 || x >= 312 || y <= 6 || y >= 135) { bool exitOk = false; assert(_savedMouseState + 6 >= 0); switch (_savedMouseState + 6) { case 0: if (_sceneExit1 != 0xFFFF) exitOk = true; break; case 1: if (_sceneExit2 != 0xFFFF) exitOk = true; break; case 2: if (_sceneExit3 != 0xFFFF) exitOk = true; break; case 3: if (_sceneExit4 != 0xFFFF) exitOk = true; break; default: break; } if (exitOk) { inputSceneChange(x, y, 1, 1); return; } } if (checkCharCollision(x, y) && _savedMouseState >= -1) { runSceneScript2(); return; } else if (pickUpItem(x, y)) { return; } else { int skipHandling = 0; if (checkItemCollision(x, y) == -1) { resetGameFlag(0x1EF); skipHandling = handleInputUnkSub(x, y) ? 1 : 0; if (queryGameFlag(0x1EF)) { resetGameFlag(0x1EF); return; } if (_unk5) { _unk5 = 0; return; } } if (_deathHandler > -1) skipHandling = 1; if (skipHandling) return; if (checkCharCollision(x, y)) { runSceneScript2(); return; } if (_itemInHand >= 0) { if (y > 136) return; dropItem(0, _itemInHand, x, y, 1); } else { if (_savedMouseState == -2 || y > 135) return; if (!_unk5) { inputSceneChange(x, y, 1, 1); return; } _unk5 = 0; } } }