void KyraEngine_MR::runLoop() { _eventList.clear(); _runFlag = true; while (_runFlag && !shouldQuit()) { if (_deathHandler >= 0) { removeHandItem(); delay(5); _drawNoShapeFlag = 0; _gui->optionsButton(0); _deathHandler = -1; if (!_runFlag || shouldQuit()) break; } if (_system->getMillis() >= _nextIdleAnim) showIdleAnim(); int inputFlag = checkInput(_mainButtonList, true); removeInputTop(); update(); _timer->update(); if (inputFlag == 198 || inputFlag == 199) { _savedMouseState = _mouseState; Common::Point mouse = getMousePos(); handleInput(mouse.x, mouse.y); } _system->delayMillis(10); } }
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); } }
int KyraEngine_v2::o2_delay(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_delay(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); if (stackPos(1)) { uint32 maxWaitTime = _system->getMillis() + stackPos(0) * _tickLength; while (_system->getMillis() < maxWaitTime) { int inputFlag = checkInput(0); removeInputTop(); if (inputFlag == 198 || inputFlag == 199) return 1; if (_chatText) updateWithText(); else update(); _system->delayMillis(10); } } else { delay(stackPos(0) * _tickLength, true); } return 0; }
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); }
int KyraEngine_v2::o2_waitForConfirmationClick(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_waitForConfirmationClick(%p) (%d)", (const void *)script, stackPos(0)); resetSkipFlag(); uint32 maxWaitTime = _system->getMillis() + stackPos(0) * _tickLength; while (_system->getMillis() < maxWaitTime) { int inputFlag = checkInput(0); removeInputTop(); if (inputFlag == 198 || inputFlag == 199) { _sceneScriptState.regs[1] = _mouseX; _sceneScriptState.regs[2] = _mouseY; return 0; } update(); _system->delayMillis(10); } _sceneScriptState.regs[1] = _mouseX; _sceneScriptState.regs[2] = _mouseY; return 1; }
int KyraEngine_MR::o3_daggerWarning(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_daggerWarning(%p) ()", (const void *)script); int selection = 1; _screen->hideMouse(); _screen->copyRegionToBuffer(1, 0, 0, 320, 200, _screenBuffer); int curPageBackUp = _screen->_curPage; _screen->_curPage = 2; _screen->drawFilledBox(0, 0, 0x13F, 0xC7, 0xB4, 0xB3, 0xB6); _screen->drawFilledBox(0xF, 0xAA, 0x68, 0xBA, 0xB4, 0xB3, 0xB6); _screen->drawFilledBox(0x73, 0xAA, 0xCC, 0xBA, 0xB4, 0xB3, 0xB6); _screen->drawFilledBox(0xD6, 0xAA, 0x12F, 0xBA, 0xB4, 0xB3, 0xB6); int y = 15; for (int i = 100; i <= 107; ++i) { const char *str = (const char *)getTableEntry(_cCodeFile, i); int x = _text->getCenterStringX(str, 0, 0x13F); _text->printText(str, x, y, 0xFF, 0xF0, 0x00); y += 10; } y += 15; for (int i = 110; i <= 113; ++i) { const char *str = (const char *)getTableEntry(_cCodeFile, i); int x = _text->getCenterStringX(str, 0, 0x13F); _text->printText(str, x, y, 0xFF, 0xF0, 0x00); y += 10; } const char *str = 0; int x = 0; str = (const char *)getTableEntry(_cCodeFile, 120); x = _text->getCenterStringX(str, 0xF, 0x68); _text->printText(str, x, 174, 0xFF, 0xF0, 0x00); str = (const char *)getTableEntry(_cCodeFile, 121); x = _text->getCenterStringX(str, 0x73, 0xCC); _text->printText(str, x, 174, 0xFF, 0xF0, 0x00); str = (const char *)getTableEntry(_cCodeFile, 122); x = _text->getCenterStringX(str, 0xD6, 0x12F); _text->printText(str, x, 174, 0xFF, 0xF0, 0x00); _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0); _screen->updateScreen(); _screen->_curPage = curPageBackUp; _screen->showMouse(); while (!shouldQuit()) { int keys = checkInput(0); removeInputTop(); if (keys == 198 || keys == 199) { if (_mouseX >= 15 && _mouseX <= 104 && _mouseY >= 170 && _mouseY <= 186) { selection = 1; break; } else if (_mouseX >= 115 && _mouseX <= 204 && _mouseY >= 170 && _mouseY <= 186) { selection = 2; break; } else if (_mouseX >= 214 && _mouseX <= 303 && _mouseY >= 170 && _mouseY <= 186) { selection = 3; break; } } delay(10); } restorePage3(); _screen->copyBlockToPage(1, 0, 0, 320, 200, _screenBuffer); return selection; }
uint16 KyraRpgEngine::processDialogue() { int df = _dialogueHighlightedButton; int res = 0; for (int i = 0; i < _dialogueNumButtons; i++) { int x = _dialogueButtonPosX[i]; int y = ((_flags.lang == Common::JA_JPN && _flags.use16ColorMode) ? ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) & ~7) - 1 : (_dialogueButtonYoffs + _dialogueButtonPosY[i])); Common::Point p = getMousePos(); if (posWithinRect(p.x, p.y, x, y, x + _dialogueButtonWidth, y + guiSettings()->buttons.height)) { _dialogueHighlightedButton = i; break; } } if (_dialogueNumButtons == 0) { int e = checkInput(0, false) & 0xFF; removeInputTop(); if (e) { gui_notifyButtonListChanged(); if (e == _keyMap[Common::KEYCODE_SPACE] || e == _keyMap[Common::KEYCODE_RETURN]) { snd_stopSpeech(true); } } if (snd_updateCharacterSpeech() != 2) { res = 1; if (!shouldQuit()) { removeInputTop(); gui_notifyButtonListChanged(); } } } else { int e = checkInput(0, false, 0) & 0xFF; removeInputTop(); if (e) gui_notifyButtonListChanged(); if ((_flags.gameID == GI_LOL && (e == 200 || e == 202)) || (_flags.gameID != GI_LOL && (e == 199 || e == 201))) { for (int i = 0; i < _dialogueNumButtons; i++) { int x = _dialogueButtonPosX[i]; int y = (gameFlags().use16ColorMode ? ((_dialogueButtonYoffs + _dialogueButtonPosY[i]) & ~7) - 1 : (_dialogueButtonYoffs + _dialogueButtonPosY[i])); Common::Point p = getMousePos(); if (posWithinRect(p.x, p.y, x, y, x + _dialogueButtonWidth, y + guiSettings()->buttons.height)) { _dialogueHighlightedButton = i; res = _dialogueHighlightedButton + 1; break; } } } else if (e == _keyMap[Common::KEYCODE_SPACE] || e == _keyMap[Common::KEYCODE_RETURN]) { snd_stopSpeech(true); res = _dialogueHighlightedButton + 1; } else if (e == _keyMap[Common::KEYCODE_LEFT] || e == _keyMap[Common::KEYCODE_DOWN]) { if (_dialogueNumButtons > 1 && _dialogueHighlightedButton > 0) _dialogueHighlightedButton--; } else if (e == _keyMap[Common::KEYCODE_RIGHT] || e == _keyMap[Common::KEYCODE_UP]) { if (_dialogueNumButtons > 1 && _dialogueHighlightedButton < (_dialogueNumButtons - 1)) _dialogueHighlightedButton++; } } if (df != _dialogueHighlightedButton) drawDialogueButtons(); screen()->updateScreen(); if (res == 0) return 0; stopPortraitSpeechAnim(); if (game() == GI_LOL) { if (!textEnabled() && _currentControlMode) { screen()->setScreenDim(5); const ScreenDim *d = screen()->getScreenDim(5); screen()->fillRect(d->sx, d->sy + d->h - 9, d->sx + d->w - 1, d->sy + d->h - 1, d->unkA); } else { const ScreenDim *d = screen()->_curDim; if (gameFlags().use16ColorMode) screen()->fillRect(d->sx, d->sy, d->sx + d->w - 3, d->sy + d->h - 2, d->unkA); else screen()->fillRect(d->sx, d->sy, d->sx + d->w - 2, d->sy + d->h - 1, d->unkA); txt()->clearDim(4); txt()->resetDimTextPositions(4); } } return res; }
void KyraEngine_HoF::runLoop() { _screen->updateScreen(); _runFlag = true; while (!shouldQuit() && _runFlag) { if (_deathHandler >= 0) { removeHandItem(); delay(5); _drawNoShapeFlag = 0; _gui->optionsButton(0); _deathHandler = -1; if (!_runFlag || shouldQuit()) break; } if (_system->getMillis() > _nextIdleAnim) showIdleAnim(); if (queryGameFlag(0x159)) { dinoRide(); resetGameFlag(0x159); } if (queryGameFlag(0x124) && !queryGameFlag(0x125)) { _mainCharacter.animFrame = 32; enterNewScene(39, -1, 0, 0, 0); } if (queryGameFlag(0xD8)) { resetGameFlag(0xD8); if (_mainCharacter.sceneId == 34) { if (queryGameFlag(0xD1)) { initTalkObject(28); npcChatSequence(getTableString(0xFA, _cCodeBuffer, 1), 28, 0x83, 0xFA); deinitTalkObject(28); enterNewScene(35, 4, 0, 0, 0); } else if (queryGameFlag(0xD0)) { initTalkObject(29); npcChatSequence(getTableString(0xFB, _cCodeBuffer, 1), 29, 0x83, 0xFB); deinitTalkObject(29); enterNewScene(33, 6, 0, 0, 0); } } } int inputFlag = checkInput(_buttonList, true); removeInputTop(); update(); if (inputFlag == 198 || inputFlag == 199) { _savedMouseState = _mouseState; handleInput(_mouseX, _mouseY); } //if (queryGameFlag(0x1EE) && inputFlag) // sub_13B19(inputFlag); _system->delayMillis(10); } }
Common::Error EoBCoreEngine::loadGameState(int slot) { // Special slot id -1 for EOB1 party transfer const char *fileName = (slot == -1) ? _savegameFilename.c_str() : getSavegameFilename(slot); SaveHeader header; Common::InSaveFile *saveFile = openSaveForReading(fileName, header, (slot != -1)); if (!saveFile) return Common::Error(Common::kReadingFailed); Common::SeekableSubReadStreamEndian in(saveFile, saveFile->pos(), saveFile->size(), !header.originalSave, DisposeAfterUse::YES); _loading = true; if (slot != -1) _screen->fadeToBlack(10); for (int i = 0; i < 6; i++) { EoBCharacter *c = &_characters[i]; c->id = in.readByte(); c->flags = in.readByte(); in.read(c->name, 11); c->strengthCur = in.readSByte(); c->strengthMax = in.readSByte(); c->strengthExtCur = in.readSByte(); c->strengthExtMax = in.readSByte(); c->intelligenceCur = in.readSByte(); c->intelligenceMax = in.readSByte(); c->wisdomCur = in.readSByte(); c->wisdomMax = in.readSByte(); c->dexterityCur = in.readSByte(); c->dexterityMax = in.readSByte(); c->constitutionCur = in.readSByte(); c->constitutionMax = in.readSByte(); c->charismaCur = in.readSByte(); c->charismaMax = in.readSByte(); c->hitPointsCur = in.readSint16BE(); c->hitPointsMax = in.readSint16BE(); c->armorClass = in.readSByte(); c->disabledSlots = in.readByte(); c->raceSex = in.readByte(); c->cClass = in.readByte(); c->alignment = in.readByte(); c->portrait = in.readSByte(); if (slot == -1 && c->portrait < 0) c->portrait = -c->portrait + 43; c->food = in.readByte(); in.read(c->level, 3); for (int ii = 0; ii < 3; ii++) c->experience[ii] = in.readUint32BE(); delete[] c->faceShape; c->faceShape = 0; in.read(c->mageSpells, 80); in.read(c->clericSpells, 80); c->mageSpellsAvailableFlags = in.readUint32BE(); for (int ii = 0; ii < 27; ii++) c->inventory[ii] = in.readSint16BE(); uint32 ct = _system->getMillis(); for (int ii = 0; ii < 10; ii++) { c->timers[ii] = in.readUint32BE(); if (c->timers[ii]) c->timers[ii] += ct; } in.read(c->events, 10); in.read(c->effectsRemainder, 4); c->effectFlags = in.readUint32BE(); c->damageTaken = in.readByte(); in.read(c->slotStatus, 5); } setupCharacterTimers(); _screen->loadShapeSetBitmap("CHARGENA", 3, 3); for (int i = 0; i < 6; i++) { EoBCharacter *c = &_characters[i]; if (!c->flags || c->portrait < 0) continue; c->faceShape = _screen->encodeShape((c->portrait % 10) << 2, (c->portrait / 10) << 5, 4, 32, true); } _screen->loadShapeSetBitmap(_flags.gameID == GI_EOB2 ? "OUTPORTS" : "OUTTAKE", 3, 3); for (int i = 0; i < 6; i++) { EoBCharacter *c = &_characters[i]; if (!c->flags || c->portrait >= 0) continue; c->faceShape = _screen->encodeShape((-(c->portrait + 1)) << 2, _flags.gameID == GI_EOB2 ? 0 : 160, 4, 32, true); } _screen->_curPage = 0; if (slot == -1) { // Skip all settings which aren't necessary for party transfer. // Jump directly to the items list. in.skip(108); } else { _currentLevel = in.readByte(); _currentSub = in.readSByte(); _currentBlock = in.readUint16BE(); _currentDirection = in.readUint16BE(); _itemInHand = in.readSint16BE(); _hasTempDataFlags = in.readUint32BE(); _partyEffectFlags = in.readUint32BE(); _updateFlags = in.readUint16BE(); _compassDirection = in.readUint16BE(); _currentControlMode = in.readUint16BE(); _updateCharNum = in.readUint16BE(); _openBookSpellLevel = in.readSByte(); _openBookSpellSelectedItem = in.readSByte(); _openBookSpellListOffset = in.readSByte(); _openBookChar = in.readByte(); _openBookType = in.readByte(); _openBookCharBackup = in.readByte(); _openBookTypeBackup = in.readByte(); _activeSpellCharId = in.readByte(); _activeSpellCharacterPos = in.readByte(); _activeSpell = in.readByte(); _returnAfterSpellCallback = in.readByte() ? true : false; _inf->loadState(in); } for (int i = 0; i < 600; i++) { EoBItem *t = &_items[i]; t->nameUnid = in.readByte(); t->nameId = in.readByte(); t->flags = in.readByte(); t->icon = in.readSByte(); t->type = in.readSByte(); t->pos = in.readSByte(); t->block = in.readSint16BE(); t->next = in.readSint16BE(); t->prev = in.readSint16BE(); t->level = in.readByte(); t->value = in.readSByte(); } // No more data needed for party transfer if (slot == -1) { _loading = false; return Common::kNoError; } for (int i = 51; i < 65; i++) { EoBItemType *t = &_itemTypes[i]; t->invFlags = in.readUint16BE(); t->handFlags = in.readUint16BE(); t->armorClass = in.readSByte(); t->allowedClasses = in.readSByte(); t->requiredHands = in.readSByte(); t->dmgNumDiceS = in.readSByte(); t->dmgNumPipsS = in.readSByte(); t->dmgIncS = in.readSByte(); t->dmgNumDiceL = in.readSByte(); t->dmgNumPipsL = in.readSByte(); t->dmgIncL = in.readSByte(); t->unk1 = in.readByte(); t->extraProperties = in.readUint16BE(); } for (int i = 0; i < 18; i++) { if (!(_hasTempDataFlags & (1 << i))) continue; if (_lvlTempData[i]) { delete[] _lvlTempData[i]->wallsXorData; delete[] _lvlTempData[i]->flags; releaseMonsterTempData(_lvlTempData[i]); releaseFlyingObjectTempData(_lvlTempData[i]); releaseWallOfForceTempData(_lvlTempData[i]); delete _lvlTempData[i]; } _lvlTempData[i] = new LevelTempData; LevelTempData *l = _lvlTempData[i]; l->wallsXorData = new uint8[4096]; l->flags = new uint16[1024]; EoBMonsterInPlay *lm = new EoBMonsterInPlay[30]; l->monsters = lm; EoBFlyingObject *lf = new EoBFlyingObject[_numFlyingObjects]; l->flyingObjects = lf; WallOfForce *lw = new WallOfForce[5]; l->wallsOfForce = lw; in.read(l->wallsXorData, 4096); for (int ii = 0; ii < 1024; ii++) l->flags[ii] = in.readByte(); for (int ii = 0; ii < 30; ii++) { EoBMonsterInPlay *m = &lm[ii]; m->type = in.readByte(); m->unit = in.readByte(); m->block = in.readUint16BE(); m->pos = in.readByte(); m->dir = in.readSByte(); m->animStep = in.readByte(); m->shpIndex = in.readByte(); m->mode = in.readSByte(); m->f_9 = in.readSByte(); m->curAttackFrame = in.readSByte(); m->spellStatusLeft = in.readSByte(); m->hitPointsMax = in.readSint16BE(); m->hitPointsCur = in.readSint16BE(); m->dest = in.readUint16BE(); m->randItem = in.readUint16BE(); m->fixedItem = in.readUint16BE(); m->flags = in.readByte(); m->idleAnimState = in.readByte(); m->curRemoteWeapon = in.readByte(); m->numRemoteAttacks = in.readByte(); m->palette = in.readSByte(); m->directionChanged = in.readByte(); m->stepsTillRemoteAttack = in.readByte(); m->sub = in.readByte(); } for (int ii = 0; ii < _numFlyingObjects; ii++) { EoBFlyingObject *m = &lf[ii]; m->enable = in.readByte(); m->objectType = in.readByte(); m->attackerId = in.readSint16BE(); m->item = in.readSint16BE(); m->curBlock = in.readUint16BE(); m->u2 = in.readUint16BE(); m->u1 = in.readByte(); m->direction = in.readByte(); m->distance = in.readByte(); m->callBackIndex = in.readSByte(); m->curPos = in.readByte(); m->flags = in.readByte(); m->unused = in.readByte(); } for (int ii = 0; ii < 5; ii++) { WallOfForce *w = &lw[ii]; w->block = in.readUint16BE(); w->duration = in.readUint32BE(); } } loadLevel(_currentLevel, _currentSub); _sceneUpdateRequired = true; _screen->setFont(Screen::FID_6_FNT); for (int i = 0; i < 6; i++) { for (int ii = 0; ii < 10; ii++) { if (_characters[i].events[ii] == -57) spellCallback_start_trueSeeing(); } } _screen->setCurPage(0); gui_drawPlayField(false); if (_currentControlMode) _screen->copyRegion(176, 0, 0, 0, 144, 168, 0, 5, Screen::CR_NO_P_CHECK); _screen->setCurPage(0); gui_drawAllCharPortraitsWithStats(); drawScene(1); if (_updateFlags) { _updateFlags = 0; useMagicBookOrSymbol(_openBookChar, _openBookType); } _screen->copyRegion(0, 120, 0, 0, 176, 24, 0, 12, Screen::CR_NO_P_CHECK); gui_toggleButtons(); setHandItem(_itemInHand); while (!_screen->isMouseVisible()) _screen->showMouse(); _loading = false; _screen->fadeFromBlack(20); removeInputTop(); return Common::kNoError; }