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.
This commit is contained in:
Walter van Niftrik 2016-08-21 12:27:45 +02:00
parent ff0bc115b5
commit df838f50eb
7 changed files with 37 additions and 10 deletions

View file

@ -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;

View file

@ -165,11 +165,12 @@ struct State {
Common::Array<byte> 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<Command> Commands;

View file

@ -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<byte>::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());

View file

@ -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);

View file

@ -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);

View file

@ -338,6 +338,7 @@ void HiRes1Engine::loadRoom(byte roomNr) {
}
void HiRes1Engine::showRoom() {
_state.curPicture = getCurRoom().curPicture;
clearScreen();
loadRoom(_state.room);

View file

@ -317,6 +317,8 @@ void HiRes6Engine::initGameState() {
}
void HiRes6Engine::showRoom() {
_state.curPicture = getCurRoom().curPicture;
bool redrawPic = false;
if (getVar(26) == 0xfe)