From df838f50ebdc4005dc07df263cead32a4c398d4e Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 21 Aug 2016 12:27:45 +0200 Subject: [PATCH] ADL: Add "current picture" variable to state This mimics the behavior of the original engine. Note that for hires2, this patch adds some glitches that are also present in the original, and removes some glitches that are not. --- engines/adl/adl.cpp | 7 ++++++- engines/adl/adl.h | 3 ++- engines/adl/adl_v2.cpp | 28 ++++++++++++++++++++++------ engines/adl/adl_v2.h | 2 ++ engines/adl/adl_v3.cpp | 4 ++-- engines/adl/hires1.cpp | 1 + engines/adl/hires6.cpp | 2 ++ 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 83181c9847e..19595606e12 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -661,6 +661,11 @@ Common::Error AdlEngine::loadGameState(int slot) { _state.rooms[i].isFirstTime = inFile->readByte(); } + // NOTE: _state.curPicture is part of the save state in the original engine. We + // reconstruct it instead. This is believed to be safe for at least hires 0-2, but + // this may need to be re-evaluated for later games. + _state.curPicture = _state.rooms[_state.room].curPicture; + size = inFile->readUint32BE(); if (size != _state.items.size()) error("Item count mismatch (expected %i; found %i)", _state.items.size(), size); @@ -951,7 +956,7 @@ int AdlEngine::o1_isVarEQ(ScriptEnv &e) { int AdlEngine::o1_isCurPicEQ(ScriptEnv &e) { OP_DEBUG_1("\t&& GET_CURPIC() == %d", e.arg(1)); - if (getCurRoom().curPicture == e.arg(1)) + if (_state.curPicture == e.arg(1)) return 1; return -1; diff --git a/engines/adl/adl.h b/engines/adl/adl.h index c9d77fcc629..89cdabe3845 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -165,11 +165,12 @@ struct State { Common::Array vars; byte room; + byte curPicture; uint16 moves; bool isDark; Time time; - State() : room(1), moves(1), isDark(false) { } + State() : room(1), curPicture(0), moves(1), isDark(false) { } }; typedef Common::List Commands; diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index 4fdf796701a..e18f3339f8e 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -79,9 +79,9 @@ void AdlEngine_v2::setupOpcodeTables() { Opcode(o1_listInv); Opcode(o2_moveItem); Opcode(o1_setRoom); - Opcode(o1_setCurPic); + Opcode(o2_setCurPic); // 0x08 - Opcode(o1_setPic); + Opcode(o2_setPic); Opcode(o1_printMsg); Opcode(o1_setLight); Opcode(o1_setDark); @@ -250,6 +250,8 @@ void AdlEngine_v2::loadRoom(byte roomNr) { void AdlEngine_v2::showRoom() { bool redrawPic = false; + _state.curPicture = getCurRoom().curPicture; + if (_state.room != _roomOnScreen) { loadRoom(_state.room); clearScreen(); @@ -257,15 +259,15 @@ void AdlEngine_v2::showRoom() { if (!_state.isDark) redrawPic = true; } else { - if (getCurRoom().curPicture != _picOnScreen || _itemRemoved) + if (_state.curPicture != _picOnScreen || _itemRemoved) redrawPic = true; } if (redrawPic) { _roomOnScreen = _state.room; - _picOnScreen = getCurRoom().curPicture; + _picOnScreen = _state.curPicture; - drawPic(getCurRoom().curPicture); + drawPic(_state.curPicture); _itemRemoved = false; _itemsOnScreen = 0; @@ -336,7 +338,7 @@ void AdlEngine_v2::drawItems() { Common::Array::const_iterator pic; for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { - if (*pic == getCurRoom().curPicture || *pic == IDI_ANY) { + if (*pic == _state.curPicture || *pic == IDI_ANY) { drawItem(*item, item->position); break; } @@ -425,6 +427,20 @@ int AdlEngine_v2::o2_moveItem(ScriptEnv &e) { return 2; } +int AdlEngine_v2::o2_setCurPic(ScriptEnv &e) { + OP_DEBUG_1("\tSET_CURPIC(%d)", e.arg(1)); + + getCurRoom().curPicture = _state.curPicture = e.arg(1); + return 1; +} + +int AdlEngine_v2::o2_setPic(ScriptEnv &e) { + OP_DEBUG_1("\tSET_PIC(%d)", e.arg(1)); + + getCurRoom().picture = getCurRoom().curPicture = _state.curPicture = e.arg(1); + return 1; +} + int AdlEngine_v2::o2_moveAllItems(ScriptEnv &e) { OP_DEBUG_2("\tMOVE_ALL_ITEMS(%s, %s)", itemRoomStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index f18972b74bb..4a473e9b1f8 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -64,6 +64,8 @@ protected: int o2_isCarryingSomething(ScriptEnv &e); int o2_moveItem(ScriptEnv &e); + int o2_setCurPic(ScriptEnv &e); + int o2_setPic(ScriptEnv &e); int o2_moveAllItems(ScriptEnv &e); int o2_save(ScriptEnv &e); int o2_restore(ScriptEnv &e); diff --git a/engines/adl/adl_v3.cpp b/engines/adl/adl_v3.cpp index 623db661bce..005478c3765 100644 --- a/engines/adl/adl_v3.cpp +++ b/engines/adl/adl_v3.cpp @@ -110,9 +110,9 @@ void AdlEngine_v3::setupOpcodeTables() { Opcode(o1_listInv); Opcode(o3_moveItem); Opcode(o1_setRoom); - Opcode(o1_setCurPic); + Opcode(o2_setCurPic); // 0x08 - Opcode(o1_setPic); + Opcode(o2_setPic); Opcode(o1_printMsg); Opcode(o3_dummy); Opcode(o3_setTextMode); diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp index 096d8ef496b..26565c03c38 100644 --- a/engines/adl/hires1.cpp +++ b/engines/adl/hires1.cpp @@ -338,6 +338,7 @@ void HiRes1Engine::loadRoom(byte roomNr) { } void HiRes1Engine::showRoom() { + _state.curPicture = getCurRoom().curPicture; clearScreen(); loadRoom(_state.room); diff --git a/engines/adl/hires6.cpp b/engines/adl/hires6.cpp index 465538fe263..e9df7b513aa 100644 --- a/engines/adl/hires6.cpp +++ b/engines/adl/hires6.cpp @@ -317,6 +317,8 @@ void HiRes6Engine::initGameState() { } void HiRes6Engine::showRoom() { + _state.curPicture = getCurRoom().curPicture; + bool redrawPic = false; if (getVar(26) == 0xfe)