/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifdef ENABLE_EOB #include "kyra/eobcommon.h" #include "kyra/screen_eob.h" #include "kyra/script_eob.h" #include "kyra/resource.h" #include "kyra/sound.h" #include "common/system.h" namespace Kyra { void EobCoreEngine::runLevelScript(int block, int flags) { _inf->run(block, flags); } void EobCoreEngine::setScriptFlag(int flag) { _inf->setFlag(flag); } void EobCoreEngine::clearScriptFlag(int flag) { _inf->clearFlag(flag); } bool EobCoreEngine::checkScriptFlag(int flag) { return _inf->checkFlag(flag); } const uint8 *EobCoreEngine::initScriptTimers(const uint8 *pos) { _scriptTimersCount = 0; while (((int16)READ_LE_UINT16(pos)) != -1) { _scriptTimers[_scriptTimersCount].func = READ_LE_UINT16(pos); pos += 2; uint16 ticks = READ_LE_UINT16(pos) * 18; _scriptTimers[_scriptTimersCount].ticks = ticks; pos += 2; _scriptTimers[_scriptTimersCount++].next = _system->getMillis() + ticks * _tickLength; } return pos; } void EobCoreEngine::updateScriptTimers() { bool timerUpdate = false; if ((_scriptTimersMode & 2) && _stepsUntilScriptCall && _stepCounter > _stepsUntilScriptCall) { _inf->run(0, 0x20); _stepCounter = 0; timerUpdate = true; } if (_scriptTimersMode & 1) { for (int i = 0; i < _scriptTimersCount; i++) { if (_scriptTimers[i].next < _system->getMillis()) { _inf->run(_scriptTimers[i].func, _flags.gameID == GI_EOB1 ? 0x20 : 0x80); _scriptTimers[i].next = _system->getMillis() + _scriptTimers[i].ticks * _tickLength; _sceneUpdateRequired = true; timerUpdate = true; } } } if (timerUpdate) updateScriptTimersExtra(); } EobInfProcessor::EobInfProcessor(EobCoreEngine *engine, Screen_Eob *screen) : _vm(engine), _screen(screen), _commandMin(engine->game() == GI_EOB1 ? -27 : -31) { #define Opcode(x) _opcodes.push_back(new InfProc(this, &EobInfProcessor::x)) #define OpcodeAlt(x) if (_vm->game() == GI_EOB1) Opcode(x##_v1); else Opcode(x##_v2); Opcode(oeob_setWallType); Opcode(oeob_toggleWallState); Opcode(oeob_openDoor); Opcode(oeob_closeDoor); Opcode(oeob_replaceMonster); Opcode(oeob_movePartyOrObject); Opcode(oeob_moveInventoryItemToBlock); OpcodeAlt(oeob_printMessage); Opcode(oeob_setFlags); Opcode(oeob_playSoundEffect); Opcode(oeob_removeFlags); Opcode(oeob_modifyCharacterHitPoints); Opcode(oeob_calcAndInflictCharacterDamage); Opcode(oeob_jump); Opcode(oeob_end); Opcode(oeob_popPosAndReturn); Opcode(oeob_pushPosAndJump); OpcodeAlt(oeob_eval); Opcode(oeob_deleteItem); Opcode(oeob_loadNewLevelOrMonsters); Opcode(oeob_increasePartyExperience); OpcodeAlt(oeob_createItem); Opcode(oeob_launchObject); Opcode(oeob_changeDirection); Opcode(oeob_identifyItems); Opcode(oeob_sequence); Opcode(oeob_delay); Opcode(oeob_drawScene); Opcode(oeob_dialogue); Opcode(oeob_specialEvent); #undef Opcode #undef OpcodeAlt _scriptData = 0; _abortScript = 0; _abortAfterSubroutine = 0; _dlgResult = 0; _preventRest = 0; _lastScriptFunc = 0; _lastScriptSub = 0; _scriptPosStack = new int8*[10]; memset(_scriptPosStack, 0, 10 * sizeof(int8*)); _scriptPosStackIndex = 0; _flagTable = new uint32[18]; memset(_flagTable, 0, 18 * sizeof(uint32)); _stack = new int16[30]; memset(_stack, 0, 30 * sizeof(int16)); _stackIndex = 0; memset(_scriptPosStack, 0, sizeof(_scriptPosStack)); _scriptPosStackIndex = 0; _activeCharacter = -1; } EobInfProcessor::~EobInfProcessor() { delete[] _scriptPosStack; delete[] _flagTable; delete[] _stack; delete[] _scriptData; for (Common::Array::const_iterator a = _opcodes.begin(); a != _opcodes.end(); ++a) delete *a; _opcodes.clear(); } void EobInfProcessor::loadData(const uint8 *data, uint32 dataSize) { delete[] _scriptData; _scriptData = new int8[dataSize]; memcpy(_scriptData, data, dataSize); } void EobInfProcessor::run(int func, int sub) { int o = _vm->_levelBlockProperties[func].assignedObjects; if (!o) return; uint16 f = _vm->_levelBlockProperties[func].flags; uint16 subFlags = ((f & 0xfff8) >> 3) | 0xe0; if (!(sub & subFlags)) return; _abortScript = 0; _abortAfterSubroutine = 0; _dlgResult = 0; _activeCharacter = -1; _lastScriptFunc = func; _lastScriptSub = sub; _vm->resetSkipFlag(true); int8 *pos = (int8*)(_scriptData + o); do { int8 cmd = *pos++; if (cmd <= _commandMin || cmd >= 0) continue; pos += (*_opcodes[-(cmd + 1)])(pos); } while (!_abortScript && !_abortAfterSubroutine); } void EobInfProcessor::setFlag(int flag) { _flagTable[17] |= flag; } void EobInfProcessor::clearFlag(int flag) { _flagTable[17] &= ~flag; } bool EobInfProcessor::checkFlag(int flag) const { return (_flagTable[17] & flag) ? true : false; } bool EobInfProcessor::preventRest() const { return _preventRest ? true : false; } void EobInfProcessor::loadState(Common::SeekableSubReadStreamEndian &in) { _preventRest = in.readByte(); for (int i = 0; i < 18; i++) _flagTable[i] = in.readUint32BE(); } void EobInfProcessor::saveState(Common::OutSaveFile *out) { out->writeByte(_preventRest); for (int i = 0; i < 18; i++) out->writeUint32BE(_flagTable[i]); } const char *EobInfProcessor::getString(uint16 index) { if (index == 0xffff) return 0; int8 *res = _scriptData + READ_LE_UINT16(_scriptData); while (index) { if(*res++) continue; index--; } return (const char*)res; } int EobInfProcessor::oeob_setWallType(int8 *data) { int8 *pos = data; uint16 block = 0; int8 dir = 0; switch (*pos++) { case -23: block = READ_LE_UINT16(pos); pos += 2; dir = *pos++; _vm->_levelBlockProperties[block].walls[dir] = *pos++; _vm->checkSceneUpdateNeed(block); break; case -19: _vm->_currentDirection = *pos++; break; case -9: block = READ_LE_UINT16(pos); pos += 2; dir = *pos++; memset(_vm->_levelBlockProperties[block].walls, dir, 4 * sizeof(uint8)); _vm->checkSceneUpdateNeed(block); break; default: break; } return pos - data; } int EobInfProcessor::oeob_toggleWallState(int8 *data) { int8 *pos = data; uint16 block = 0; int8 dir = 0; uint8 a = 0; uint8 b = 0; switch (*pos++) { case -23: block = READ_LE_UINT16(pos); pos += 2; dir = *pos++; a = (uint8)*pos++; b = (uint8)*pos++; a = (_vm->_levelBlockProperties[block].walls[dir] == a) ? b : a; _vm->_levelBlockProperties[block].walls[dir] = a; _vm->checkSceneUpdateNeed(block); break; case -22: _vm->processDoorSwitch(READ_LE_UINT16(pos), 0); pos += 2; break; case -9: block = READ_LE_UINT16(pos); pos += 2; a = (uint8)*pos++; b = (uint8)*pos++; a = (_vm->_levelBlockProperties[block].walls[dir] == a) ? b : a; memset(_vm->_levelBlockProperties[block].walls, a, 4 * sizeof(uint8)); _vm->checkSceneUpdateNeed(block); break; default: break; } return pos - data; } int EobInfProcessor::oeob_openDoor(int8 *data) { int8 *pos = data; _vm->openDoor(READ_LE_UINT16(pos)); pos += 2; return pos - data; } int EobInfProcessor::oeob_closeDoor(int8 *data) { int8 *pos = data; _vm->closeDoor(READ_LE_UINT16(pos)); pos += 2; return pos - data; } int EobInfProcessor::oeob_replaceMonster(int8 *data) { int8 *pos = data; _vm->replaceMonster(pos[1], READ_LE_UINT16(pos + 2), pos[4], pos[5], pos[6], pos[7], pos[8], pos[9], READ_LE_UINT16(pos + 10), READ_LE_UINT16(pos + 12)); pos += 14; return pos - data; } int EobInfProcessor::oeob_movePartyOrObject(int8 *data) { int8 *pos = data; int8 a = *pos++; uint16 b = 0xffff; uint16 c = 0; uint16 d = 0; if (_vm->game() == GI_EOB2 && a == -31) { b = READ_LE_UINT16(pos); pos += 2; } if (_vm->game() == GI_EOB1) { if (a != -15) { c = READ_LE_UINT16(pos); pos += 2; } d = READ_LE_UINT16(pos); pos += 2; } if (_vm->game() == GI_EOB2 && a != -31 && a != -11) { c = READ_LE_UINT16(pos); pos += 2; d = READ_LE_UINT16(pos); pos += 2; } if (a == -13) { // move monster from block c to block d for (int i = 0; i < 30; i++) { if (_vm->_monsters[i].block != c) continue; _vm->placeMonster(&_vm->_monsters[i], d, _vm->_monsters[i].pos); } } else if (a == -24) { // move party to block d int ba = _dlgResult; int bb = _lastScriptFunc; int bc = _lastScriptSub; int bd = _abortScript; int be = _activeCharacter; int bf = _scriptPosStackIndex; _vm->moveParty(d); _dlgResult = ba; _lastScriptFunc = bb; _lastScriptSub = bc; _abortScript = bd; _activeCharacter = be; if (!_abortAfterSubroutine) _scriptPosStackIndex = bf; _vm->_sceneDefaultUpdate = 0; } else if ((a == -31 && _vm->game() == GI_EOB2) || a == -11) { // move item int8 e = _vm->_currentLevel; int8 f = _vm->_currentLevel; if (_vm->game() == GI_EOB2) { e = (*pos++ == -21) ? _vm->_currentLevel : *pos++; c = READ_LE_UINT16(pos); pos += 2; f = (*pos++ == -21) ? _vm->_currentLevel : *pos++; d = READ_LE_UINT16(pos); pos += 2; } if (e == _vm->_currentLevel) { int i = _vm->countQueuedItems(_vm->_levelBlockProperties[c].drawObjects, -1, (int16)b, 0, 1); while (i) { int p = _vm->_items[i].pos; _vm->getQueuedItem((Item*)&_vm->_levelBlockProperties[c].drawObjects, 0, i); if (_vm->_currentLevel == f) { _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[d].drawObjects, d, i, p); } else { _vm->_items[i].level = f; _vm->_items[i].block = d; if (p < 8) _vm->_items[i].pos = p & 3; } i = _vm->countQueuedItems(_vm->_levelBlockProperties[c].drawObjects, -1, (int16)b, 0, 1); } for (i = 0; i < 10; i++) { if (_vm->_flyingObjects[i].enable != 1 || _vm->_flyingObjects[i].curBlock != c) continue; if (f == _vm->_currentLevel || _vm->game() == GI_EOB1) _vm->_flyingObjects[i].curBlock = d; else _vm->_flyingObjects[i].enable = 0; } } else { for (int i = 0; i < 600; i++) { if (_vm->_items[i].level != e || _vm->_items[i].block != c) continue; _vm->_items[i].level = f; _vm->_items[i].block = d; } } } _vm->_sceneUpdateRequired = true; return pos - data; } int EobInfProcessor::oeob_moveInventoryItemToBlock(int8 *data) { int8 *pos = data; int8 c = *pos++; uint16 block = READ_LE_UINT16(pos); pos += 2; int8 p = *pos++; if (c == -1) c = _vm->rollDice(1, 6, -1); while (!(_vm->_characters[c].flags & 1)) { if (++c == 5) c = 0; } if (_vm->_currentControlMode && (_vm->_updateCharNum == c)) return pos - data; int slot = _vm->rollDice(1, 27, 0); int itm = 0; int i = 0; for (; i < 27; i++) { if ((!_vm->_currentControlMode && slot > 1) || slot == 16) continue; itm = _vm->_characters[c].inventory[slot]; if (!itm) continue; if (_vm->_dscItemShapeMap[_vm->_items[itm].icon] >= 15) break; if (++slot == 27) slot = 0; } if (i < 27 && itm) { _vm->_characters[c].inventory[slot] = 0; _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[block].drawObjects, block, itm, p); } return pos - data; } int EobInfProcessor::oeob_printMessage_v1(int8 *data) { static const char colorConfig[] = "\x6\x21\x2\x21"; char col[5]; int8 *pos = data; strcpy(col, colorConfig); const char *str = (const char*) pos; pos += (strlen(str) + 1); col[1] = *pos++; col[3] = *pos++; _vm->txt()->printMessage(col); _vm->txt()->printMessage(str); col[1] = _screen->_curDim->unk8; col[3] = _screen->_curDim->unkA; _vm->txt()->printMessage(col); _vm->txt()->printMessage("\r"); return pos - data; } int EobInfProcessor::oeob_printMessage_v2(int8 *data) { int8 *pos = data; uint16 str = READ_LE_UINT16(pos); pos += 2; uint8 col = (uint8)*pos; pos += 2; int c = 0; if (_activeCharacter == -1) { c = _vm->rollDice(1, 6, -1); while (!_vm->testCharacter(c, 3)) c = (c + 1) % 6; } else { c = _activeCharacter; } _vm->txt()->printMessage(getString(str), col, _vm->_characters[c].name); _vm->txt()->printMessage("\r"); return pos - data; } int EobInfProcessor::oeob_setFlags(int8 *data) { int8 *pos = data; int8 b = 0; switch (*pos++) { case -47: _preventRest = 0; break; case -28: _dlgResult = 1; break; case -17: _flagTable[_vm->_currentLevel] |= (1 << (*pos++)); break; case -16: _flagTable[17] |= (1 << (*pos++)); break; case -13: b = *pos++; _vm->_monsters[b].flags |= (1 << (*pos++)); _vm->_monsters[b].mode = 0; break; default: break; } return pos - data; } int EobInfProcessor::oeob_playSoundEffect(int8 *data) { int8 *pos = data; uint16 block = READ_LE_UINT16(pos + 1); if (block) { _vm->snd_processEnvironmentalSoundEffect(pos[0], block); } else { _vm->snd_playSoundEffect(pos[0]); } pos += 3; return pos - data; } int EobInfProcessor::oeob_removeFlags(int8 *data) { int8 *pos = data; int8 a = *pos++; int8 b = *pos++; switch (a) { case -47: _preventRest = 1; break; case -28: _dlgResult = 0; break; case -17: _flagTable[_vm->_currentLevel] &= ~(1 << b); break; case -16: _flagTable[17] &= ~(1 << b); break; default: break; } return pos - data; } int EobInfProcessor::oeob_modifyCharacterHitPoints(int8 *data) { int8 *pos = data; int8 c = *pos++; int8 p = *pos++; if (c == -1) { for (c = 0; c < 6; c++) _vm->modifyCharacterHitpoints(c, p); } else { _vm->modifyCharacterHitpoints(c, p); } return pos - data; } int EobInfProcessor::oeob_calcAndInflictCharacterDamage(int8 *data) { int8 *pos = data; int charIndex = *pos++; int times = *pos++; int itemOrPips = *pos++; int useStrModifierOrBase = *pos++; int flg = (charIndex == -1) ? 4 : 0; int a = 5; int damageType = 1; if (_vm->game() == GI_EOB2) { flg = *pos++; a = *pos++; damageType = *pos++; } else if (!itemOrPips) { useStrModifierOrBase = times; times = 0; } if (charIndex == -1) { for (int i = 0; i < 6; i++) _vm->calcAndInflictCharacterDamage(i, times, itemOrPips, useStrModifierOrBase, flg, a, damageType); } else { _vm->calcAndInflictCharacterDamage(charIndex, times, itemOrPips, useStrModifierOrBase, flg, a, damageType); } return pos - data; } int EobInfProcessor::oeob_jump(int8 *data) { int8 *pos = data; pos = _scriptData + READ_LE_UINT16(pos); return pos - data; } int EobInfProcessor::oeob_end(int8 *data) { _abortScript = 1; _scriptPosStackIndex = 0; return 0; } int EobInfProcessor::oeob_popPosAndReturn(int8 *data) { int8 *pos = data; if (_scriptPosStackIndex) pos = _scriptPosStack[--_scriptPosStackIndex]; else _abortScript = 1; return pos - data; } int EobInfProcessor::oeob_pushPosAndJump(int8 *data) { int8 *pos = data; uint16 offs = READ_LE_UINT16(pos); pos += 2; if (_scriptPosStackIndex < 10) { _scriptPosStack[_scriptPosStackIndex++] = pos; pos = _scriptData + offs; } return pos - data; } int EobInfProcessor::oeob_eval_v1(int8 *data) { int8 *pos = data; int8 cmd = *pos++; int a = 0; int b = 0; int i = 0; EobItem *itm = &_vm->_items[_vm->_itemInHand]; Common::String tempString1; Common::String tempString2; while (cmd != -18) { switch (cmd + 38) { case 0: a = 0; for (i = 0; i < 6; i++) { if (!(_vm->_characters[i].flags & 1)) continue; if (_vm->_characters[i].effectFlags & 4) continue; a = 1; break; } _stack[_stackIndex++] = a; break; case 1: _stack[_stackIndex++] = _vm->rollDice(pos[0], pos[1], pos[2]); pos += 3; break; case 2: cmd = *pos++; b = 0; for (i = 0; i < 6; i++) { if (!(_vm->_characters[i].flags & 1)) continue; if (_vm->_classModifierFlags[_vm->_characters[i].cClass] & cmd) { b = 1; break; } } _stack[_stackIndex++] = b; break; case 3: cmd = *pos++; b = 0; for (i = 0; i < 6; i++) { if (!(_vm->_characters[i].flags & 1)) continue; if ((_vm->_characters[i].raceSex >> 1) == cmd) { b = 1; break; } } _stack[_stackIndex++] = b; break; case 6: _stack[_stackIndex++] = _lastScriptSub; break; case 13: itm = &_vm->_items[_vm->_itemInHand]; switch (*pos++) { case -31: _stack[_stackIndex++] = itm->type; break; case -11: _stack[_stackIndex++] = _vm->_itemInHand; break; default: _stack[_stackIndex++] = itm->value; break; } break; case 15: _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos + 1)].walls[pos[0]]; pos += 3; break; case 19: _stack[_stackIndex++] = _vm->_currentDirection; break; case 21: _stack[_stackIndex++] = (_flagTable[_vm->_currentLevel] & (1 << (*pos++))) ? 1 : 0; break; case 22: _stack[_stackIndex++] = (_flagTable[17] & (1 << (*pos++))) ? 1 : 0; break; case 23: _stack[_stackIndex++] = (_vm->_currentBlock == READ_LE_UINT16(pos)) ? 1 : 0; pos += 2; break; case 24: a = (int16)READ_LE_UINT16(pos); pos += 2; b = READ_LE_UINT16(pos); pos += 2; _stack[_stackIndex++] = _vm->countQueuedItems(_vm->_levelBlockProperties[b].drawObjects, a, -1, 0, 1); break; case 25: _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos)].flags ? 1 : 0; pos += 2; break; case 27: b = *pos++; i = READ_LE_UINT16(pos); pos += 2; _stack[_stackIndex++] = _vm->countQueuedItems(_vm->_levelBlockProperties[i].drawObjects, -1, b, 1, 1); break; case 29: _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos)].walls[0]; pos += 2; break; case 30: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a || b) ? 1 : 0; break; case 31: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a && b) ? 1 : 0; break; case 32: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a <= b) ? 1 : 0; break; case 33: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a < b) ? 1 : 0; break; case 34: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a >= b) ? 1 : 0; break; case 35: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a > b) ? 1 : 0; break; case 36: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a != b) ? 1 : 0; break; case 37: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a == b) ? 1 : 0; break; default: a = cmd; if (a >= 0 && a < 128) _stack[_stackIndex++] = a; break; } cmd = *pos++; } cmd = _stack[--_stackIndex]; if (cmd) pos += 2; else pos = _scriptData + READ_LE_UINT16(pos); return pos - data; } int EobInfProcessor::oeob_eval_v2(int8 *data) { int8 *pos = data; int8 cmd = *pos++; int a = 0; int b = 0; int i = 0; EobItem *itm = (_vm->_itemInHand != -1) ? &_vm->_items[_vm->_itemInHand] : 0; Common::String tempString1; Common::String tempString2; while (cmd != -18) { switch (cmd + 50) { case 0: a = 0; b = *pos++; for (i = 0; i < 6; i++) { if (!_vm->testCharacter(i, 5)) continue; if (_vm->_characters[i].portrait != b) { a = 1; _activeCharacter = i; break; } } _stack[_stackIndex++] = a; break; case 4: _stack[_stackIndex++] = (int16)READ_LE_UINT16(pos); pos += 2; break; case 9: switch (*pos++) { case -36: _stack[_stackIndex++] = _vm->_itemTypes[_vm->_items[_vm->_lastUsedItem].type].extraProperties & 0x7f; break; case -31: _stack[_stackIndex++] = _vm->_items[_vm->_lastUsedItem].type; break; case -11: _stack[_stackIndex++] = _vm->_lastUsedItem; break; case -10: _stack[_stackIndex++] = _vm->_items[_vm->_lastUsedItem].value; break; default: break; } break; case 12: a = 0; for (i = 0; i < 6; i++) { if (!(_vm->_characters[i].flags & 1)) continue; if (_vm->_characters[i].effectFlags & 0x40) continue; a = 1; break; } _stack[_stackIndex++] = a; break; case 13: _stack[_stackIndex++] = _vm->rollDice(pos[0], pos[1], pos[2]); pos += 3; break; case 14: cmd = *pos++; a = _vm->rollDice(1, 6); b = 0; for (i = 0; i < 6 && b == 0; i++) { if (++a > 5) a = 0; if (_vm->testCharacter(a, 5)) { if (_vm->_classModifierFlags[_vm->_characters[a].cClass] & cmd) { _activeCharacter = a; b = 1; } } } _stack[_stackIndex++] = b; break; case 15: cmd = *pos++; a = _vm->rollDice(1, 6); b = 0; for (i = 0; i < 6; i++) { if (++a > 5) a = 0; if (_vm->testCharacter(a, 5)) { if ((_vm->_characters[a].raceSex >> 1) == cmd) { _activeCharacter = a; b = 1; } } } _stack[_stackIndex++] = b; break; case 17: _stack[_stackIndex++] = _vm->_activeSpell; break; case 18: _stack[_stackIndex++] = _lastScriptSub; break; case 22: _stack[_stackIndex++] = _dlgResult; break; case 25: itm = &_vm->_items[_vm->_itemInHand]; switch (*pos++) { case -49: a = *pos++; tempString1 = _vm->_itemNames[itm->nameId]; tempString1.toUppercase(); tempString2 = (const char*)pos; tempString2.toUppercase(); pos += a; _stack[_stackIndex++] = tempString1.contains(tempString2) ? 1 : 0; break; case -48: a = *pos++; tempString1 = _vm->_itemNames[itm->nameUnid]; tempString1.toUppercase(); tempString2 = (const char*)pos; tempString2.toUppercase(); pos += a; _stack[_stackIndex++] = tempString1.contains(tempString2) ? 1 : 0; break; case -31: _stack[_stackIndex++] = itm->type; break; case -11: _stack[_stackIndex++] = _vm->_itemInHand; break; case -10: _stack[_stackIndex++] = itm->value; break; default: break; } break; case 26: a = 0; for (i = 0; i < 6; i++) { if (_vm->testCharacter(i, 0x0f)) a++; } _stack[_stackIndex++] = a; break; case 27: _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos + 1)].walls[pos[0]]; pos += 3; break; case 31: _stack[_stackIndex++] = _vm->_currentDirection; break; case 33: _stack[_stackIndex++] = (_flagTable[_vm->_currentLevel] & (1 << (*pos++))) ? 1 : 0; break; case 34: _stack[_stackIndex++] = (_flagTable[17] & (1 << (*pos++))) ? 1 : 0; break; case 35: if (*pos++ == -11) { a = (int16)READ_LE_UINT16(pos); pos += 2; b = (int16)READ_LE_UINT16(pos); pos += 2; _stack[_stackIndex++] = _vm->countCharactersWithSpecificItems(a, b); } else { _stack[_stackIndex++] = (_vm->_currentBlock == READ_LE_UINT16(pos)) ? 1 : 0; pos += 2; } break; case 36: a = (int16)READ_LE_UINT16(pos); pos += 2; b = READ_LE_UINT16(pos); pos += 2; _stack[_stackIndex++] = _vm->countQueuedItems(_vm->_levelBlockProperties[b].drawObjects, a, -1, 0, 0); break; case 37: if (*pos++ == -1) { _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos)].flags & 7; pos += 2; } else { do { a += _vm->countSpecificMonsters(*pos++); } while (*pos != -1); pos++; _stack[_stackIndex++] = a; } break; case 39: a = *pos++; b = *pos++; i = READ_LE_UINT16(pos); pos += 2; _stack[_stackIndex++] = _vm->countQueuedItems(_vm->_levelBlockProperties[i].drawObjects, -1, b, 1, a); break; case 41: _stack[_stackIndex++] = _vm->_levelBlockProperties[READ_LE_UINT16(pos)].walls[0]; pos += 2; break; case 42: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a || b) ? 1 : 0; break; case 43: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a && b) ? 1 : 0; break; case 44: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a <= b) ? 1 : 0; break; case 45: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a < b) ? 1 : 0; break; case 46: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a >= b) ? 1 : 0; break; case 47: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a > b) ? 1 : 0; break; case 48: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a != b) ? 1 : 0; break; case 49: a = _stack[--_stackIndex]; b = _stack[--_stackIndex]; _stack[_stackIndex++] = (a == b) ? 1 : 0; break; default: break; } cmd = *pos++; } cmd = _stack[--_stackIndex]; if (cmd) pos += 2; else pos = _scriptData + READ_LE_UINT16(pos); return pos - data; } int EobInfProcessor::oeob_deleteItem(int8 *data) { int8 *pos = data; int8 c = *pos++; if (c == -1) { _vm->deleteInventoryItem(0, -1); } else { _vm->deleteBlockItem(READ_LE_UINT16(pos), (c == -2) ? -1 : c); pos += 2; } return pos - data; } int EobInfProcessor::oeob_loadNewLevelOrMonsters(int8 *data) { int8 *pos = data; _vm->gui_updateControls(); int8 cmd = *pos++; int8 index = *pos++; int res = 0; if (cmd == -27 || _vm->game() == GI_EOB1) { cmd = _vm->game() == GI_EOB2 ? *pos++ : 0; _vm->_currentBlock = READ_LE_UINT16(pos); pos += 2; uint8 dir = (uint8)*pos++; if (dir != 0xff) _vm->_currentDirection = dir; for (int i = 0; i < 30; i++) _vm->_monsters[i].curAttackFrame = 0; for (int i = 0; i < 10; i++) { EobFlyingObject *fo = &_vm->_flyingObjects[i]; if (fo->enable == 1) { _vm->_items[fo->item].pos &= 3; run(_vm->_items[fo->item].block, 4); } fo->enable = 0; } _vm->completeDoorOperations(); _vm->generateTempData(); _vm->txt()->removePageBreakFlag(); _screen->setScreenDim(7); _vm->loadLevel(index, cmd); if (_vm->_dialogueField) _vm->restoreAfterDialogueSequence(); _vm->moveParty(_vm->_currentBlock); _abortScript = 1; _abortAfterSubroutine = 1; _vm->_sceneUpdateRequired = true; _vm->gui_drawAllCharPortraitsWithStats(); _scriptPosStackIndex = 0; } else { cmd = *pos++; _vm->releaseMonsterShapes(cmd * 18, 18); _vm->loadMonsterShapes((const char*)pos, cmd * 18, true, index * 18); pos += 13; _vm->gui_restorePlayField(); res = pos - data; } return res; } int EobInfProcessor::oeob_increasePartyExperience(int8 *data) { int8 *pos = data; if (*pos++ == -30) { _vm->increasePartyExperience((int16)READ_LE_UINT16(pos)); pos += 2; } return pos - data; } int EobInfProcessor::oeob_createItem_v1(int8 *data) { int8 *pos = data; uint16 itm = _vm->duplicateItem(READ_LE_UINT16(pos)); pos += 2; uint16 block = READ_LE_UINT16(pos); pos += 2; uint8 itmPos = *pos++; if (itm) { if (block == 0xffff && !_vm->_itemInHand) _vm->setHandItem(itm); else if (block != 0xffff ) _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[block & 0x3ff].drawObjects, block, itm, itmPos); } return pos - data; } int EobInfProcessor::oeob_createItem_v2(int8 *data) { static const uint8 _itemPos[] = { 0, 1, 2, 3, 1, 3, 0, 2, 3, 2, 1, 0, 2, 0, 3, 1 }; int8 *pos = data; uint16 itm = _vm->duplicateItem(READ_LE_UINT16(pos)); pos += 2; uint16 block = READ_LE_UINT16(pos); pos += 2; uint8 itmPos = *pos++; uint8 flg = *pos++; if (flg & 1) _vm->_items[itm].value = *pos++; if (flg & 2) _vm->_items[itm].flags = *pos++; if (flg & 4) _vm->_items[itm].icon = *pos++; if (!itm) return pos - data; if (block == 0xffff) { if (!_vm->_itemInHand) _vm->setHandItem(itm); else _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[_vm->_currentBlock & 0x3ff].drawObjects, _vm->_currentBlock, itm, _itemPos[_vm->rollDice(1, 2, -1)]); } else if (block == 0xfffe) { _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[_vm->_currentBlock & 0x3ff].drawObjects, _vm->_currentBlock, itm, _itemPos[(_vm->_currentDirection << 2) + _vm->rollDice(1, 2, -1)]); } else { _vm->setItemPosition((Item*)&_vm->_levelBlockProperties[block & 0x3ff].drawObjects, block, itm, itmPos); } return pos - data; } int EobInfProcessor::oeob_launchObject(int8 *data) { static const uint8 startPos[] = { 2, 3, 0, 2, 1, 0, 3, 1 }; int8 *pos = data; bool m = (*pos++ == -33); int i = READ_LE_UINT16(pos); pos += 2; uint16 block = READ_LE_UINT16(pos); pos += 2; int dir = *pos++; int dirOffs = *pos++; if (m) { uint8 openBookType = _vm->_openBookType; _vm->_openBookType = 0; _vm->launchMagicObject(-1, i, block, startPos[dir * 2 + dirOffs], dir); _vm->_openBookType = openBookType; } else { Item itm = _vm->duplicateItem(i); if (itm) { if (!_vm->launchObject(-1, itm, block, startPos[dir * 2 + dirOffs], dir, _vm->_items[itm].type)) _vm->_items[itm].block = -1; } } return pos - data; } int EobInfProcessor::oeob_changeDirection(int8 *data) { int8 *pos = data; int8 cmd = *pos++; int8 dir = *pos++; if (cmd == -15) { _vm->_currentDirection = (_vm->_currentDirection + dir) & 3; //_vm->_keybControlUnk = -1; _vm->_sceneUpdateRequired = true; } else if (cmd == -11) { for (int i = 0; i < 10; i++) { if (_vm->_flyingObjects[i].enable) _vm->_flyingObjects[i].direction = (_vm->_flyingObjects[i].direction + dir) & 3; } } return pos - data; } int EobInfProcessor::oeob_identifyItems(int8 *data) { int8 *pos = data; uint16 block = READ_LE_UINT16(pos); if (block == _vm->_currentBlock) { for (int i = 0; i < 6; i++) { if (!(_vm->_characters[i].flags & 1)) continue; for (int ii = 0; ii < 27; ii++) { int inv = _vm->_characters[i].inventory[ii]; if (inv) _vm->_items[inv].flags |= 0x40; } _vm->identifyQueuedItems(_vm->_characters[i].inventory[16]); } } _vm->identifyQueuedItems(_vm->_levelBlockProperties[block].drawObjects); return pos - data; } int EobInfProcessor::oeob_sequence(int8 *data) { int8 *pos = data; _vm->_npcSequenceSub = -1; _vm->txt()->setWaitButtonMode(0); _vm->gui_updateControls(); _vm->drawScene(1); int cmd = *pos++; if (_vm->game() == GI_EOB1) { if (cmd == 10) cmd = -1; else if (cmd == 9) cmd = -3; else if (cmd == 8) cmd = -2; } switch (cmd) { case -3: // eob1 outro _vm->_runFlag = false; _vm->_playFinale = true; _abortScript = 1; return 0; case -2: _vm->seq_portal(); break; case -1: _vm->_runFlag = _vm->checkPassword(); break; default: _vm->npcSequence(cmd); break; } _vm->screen()->setScreenDim(7); return pos - data; } int EobInfProcessor::oeob_delay(int8 *data) { int8 *pos = data; _vm->delay(READ_LE_UINT16(pos) * _vm->tickLength()); pos += 2; return pos - data; } int EobInfProcessor::oeob_drawScene(int8 *data) { _vm->drawScene(1); return 0; } int EobInfProcessor::oeob_dialogue(int8 *data) { int8 *pos = data; switch (*pos++) { case -45: _vm->drawSequenceBitmap((const char*)pos, pos[13], READ_LE_UINT16(pos + 14), READ_LE_UINT16(pos + 16), READ_LE_UINT16(pos + 18)); pos += 20; break; case -44: _vm->restoreAfterDialogueSequence(); break; case -43: _vm->initDialogueSequence(); break; case -42: _vm->gui_drawDialogueBox(); break; case -40: _dlgResult = _vm->runDialogue(READ_LE_UINT16(pos), READ_LE_UINT16(pos + 6) == 0xffff ? 0 : 1, getString(READ_LE_UINT16(pos + 2)), getString(READ_LE_UINT16(pos + 4)), getString(READ_LE_UINT16(pos + 6)), 0); pos += 8; break; case -8: _vm->txt()->printDialogueText(READ_LE_UINT16(pos), getString(READ_LE_UINT16(pos + 2))); pos += 4; break; default: break; } return pos - data; } int EobInfProcessor::oeob_specialEvent(int8 *data) { int8 *pos = data; uint16 cmd = READ_LE_UINT16(pos); pos += 2; uint32 endTime = 0; int i = 0; switch (cmd) { case 0: _vm->drawScene(1); _screen->_curPage = 2; _screen->copyRegion(72, 0, 0, 0, 32, 120, 2, 12, Screen::CR_NO_P_CHECK); for (; i < 4; i++) { endTime = _vm->_system->getMillis() + _vm->_tickLength; _vm->drawLightningColumn(); _screen->copyRegion(72, 0, 72, 0, 32, 120, 2, 0, Screen::CR_NO_P_CHECK); _screen->updateScreen(); _screen->copyRegion(0, 0, 72, 0, 32, 120, 12, 2, Screen::CR_NO_P_CHECK); _vm->delayUntil(endTime); } _screen->_curPage = 0; _vm->_sceneUpdateRequired = true; break; case 1: _dlgResult = _vm->charSelectDialogue(); break; case 2: _vm->characterLevelGain(_dlgResult); break; case 3: _dlgResult = _vm->resurrectionSelectDialogue(); break; case 4: if (_vm->prepareForNewPartyMember(33, 5)) _vm->initNpc(4); break; case 5: _vm->deletePartyItems(46, 5); _vm->deletePartyItems(46, 6); break; case 6: _vm->loadVcnData(0, 0); break; default: break; } return pos - data; } } // End of namespace Kyra #endif // ENABLE_EOB