From 5f46bbff728025aedc7d4d6c83b23c3a59912e96 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Fri, 16 Dec 2016 18:27:24 +0100 Subject: ADL: Add item region checks --- engines/adl/adl.cpp | 43 ++++++++++++++++--------------- engines/adl/adl_v2.cpp | 68 ++++++++++++++++++++++++-------------------------- engines/adl/adl_v2.h | 1 + engines/adl/adl_v4.cpp | 52 -------------------------------------- engines/adl/adl_v4.h | 3 --- 5 files changed, 55 insertions(+), 112 deletions(-) (limited to 'engines/adl') diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 0d96cb67af..e3cd929b6d 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -510,26 +510,25 @@ void AdlEngine::takeItem(byte noun) { Common::List::iterator item; for (item = _state.items.begin(); item != _state.items.end(); ++item) { - if (item->noun != noun || item->room != _state.room) - continue; - - if (item->state == IDI_ITEM_DOESNT_MOVE) { - printMessage(_messageIds.itemDoesntMove); - return; - } - - if (item->state == IDI_ITEM_DROPPED) { - item->room = IDI_ANY; - return; - } + if (item->noun == noun && item->room == _state.room && item->region == _state.region) { + if (item->state == IDI_ITEM_DOESNT_MOVE) { + printMessage(_messageIds.itemDoesntMove); + return; + } - Common::Array::const_iterator pic; - for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { - if (*pic == getCurRoom().curPicture) { + if (item->state == IDI_ITEM_DROPPED) { item->room = IDI_ANY; - item->state = IDI_ITEM_DROPPED; return; } + + Common::Array::const_iterator pic; + for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { + if (*pic == getCurRoom().curPicture) { + item->room = IDI_ANY; + item->state = IDI_ITEM_DROPPED; + return; + } + } } } @@ -540,12 +539,12 @@ void AdlEngine::dropItem(byte noun) { Common::List::iterator item; for (item = _state.items.begin(); item != _state.items.end(); ++item) { - if (item->noun != noun || item->room != IDI_ANY) - continue; - - item->room = _state.room; - item->state = IDI_ITEM_DROPPED; - return; + if (item->noun == noun && item->room == IDI_ANY) { + item->room = _state.room; + item->region = _state.region; + item->state = IDI_ITEM_DROPPED; + return; + } } printMessage(_messageIds.dontUnderstand); diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index b34d4c9a06..46bd6aa4d3 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -286,32 +286,34 @@ void AdlEngine_v2::showRoom() { _linesPrinted = 0; } +// TODO: Merge this into AdlEngine? void AdlEngine_v2::takeItem(byte noun) { Common::List::iterator item; for (item = _state.items.begin(); item != _state.items.end(); ++item) { - if (item->noun != noun || item->room != _state.room) - continue; - - if (item->state == IDI_ITEM_DOESNT_MOVE) { - printMessage(_messageIds.itemDoesntMove); - return; - } - - if (item->state == IDI_ITEM_DROPPED) { - item->room = IDI_ANY; - _itemRemoved = true; - return; - } + if (item->noun == noun && item->room == _state.room && item->region == _state.region) { + if (item->state == IDI_ITEM_DOESNT_MOVE) { + printMessage(_messageIds.itemDoesntMove); + return; + } - Common::Array::const_iterator pic; - for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { - if (*pic == getCurRoom().curPicture || *pic == IDI_ANY) { + if (item->state == IDI_ITEM_DROPPED) { item->room = IDI_ANY; _itemRemoved = true; - item->state = IDI_ITEM_DROPPED; return; } + + Common::Array::const_iterator pic; + for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { + if (*pic == getCurRoom().curPicture || *pic == IDI_ANY) { + if (!isInventoryFull()) { + item->room = IDI_ANY; + _itemRemoved = true; + item->state = IDI_ITEM_DROPPED; + } + return; + } + } } } @@ -323,24 +325,20 @@ void AdlEngine_v2::drawItems() { for (item = _state.items.begin(); item != _state.items.end(); ++item) { // Skip items not in this room - if (item->room != _state.room) - continue; - - if (item->isOnScreen) - continue; - - if (item->state == IDI_ITEM_DROPPED) { - // Draw dropped item if in normal view - if (getCurRoom().picture == getCurRoom().curPicture) - drawItem(*item, _itemOffsets[_itemsOnScreen++]); - } else { - // Draw fixed item if current view is in the pic list - Common::Array::const_iterator pic; - - for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { - if (*pic == _state.curPicture || *pic == IDI_ANY) { - drawItem(*item, item->position); - break; + if (item->region == _state.region && item->room == _state.room && !item->isOnScreen) { + if (item->state == IDI_ITEM_DROPPED) { + // Draw dropped item if in normal view + if (getCurRoom().picture == getCurRoom().curPicture) + drawItem(*item, _itemOffsets[_itemsOnScreen++]); + } else { + // Draw fixed item if current view is in the pic list + Common::Array::const_iterator pic; + + for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { + if (*pic == _state.curPicture || *pic == IDI_ANY) { + drawItem(*item, item->position); + break; + } } } } diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index 8f36b5cdb8..fe0c781f44 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -58,6 +58,7 @@ protected: void loadMessages(Common::ReadStream &stream, byte count); void loadPictures(Common::ReadStream &stream); void loadItemPictures(Common::ReadStream &stream, byte count); + virtual bool isInventoryFull() { return false; } void checkTextOverflow(char c); diff --git a/engines/adl/adl_v4.cpp b/engines/adl/adl_v4.cpp index 6dfee8084a..8b72923e8b 100644 --- a/engines/adl/adl_v4.cpp +++ b/engines/adl/adl_v4.cpp @@ -266,58 +266,6 @@ void AdlEngine_v4::switchRegion(byte region) { _picOnScreen = _roomOnScreen = 0; } -// TODO: Merge this into v2? -void AdlEngine_v4::takeItem(byte noun) { - Common::List::iterator item; - - for (item = _state.items.begin(); item != _state.items.end(); ++item) { - if (item->noun != noun || item->room != _state.room || item->region != _state.region) - continue; - - if (item->state == IDI_ITEM_DOESNT_MOVE) { - printMessage(_messageIds.itemDoesntMove); - return; - } - - if (item->state == IDI_ITEM_DROPPED) { - item->room = IDI_ANY; - _itemRemoved = true; - return; - } - - Common::Array::const_iterator pic; - for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) { - if (*pic == getCurRoom().curPicture || *pic == IDI_ANY) { - if (!isInventoryFull()) { - item->room = IDI_ANY; - _itemRemoved = true; - item->state = IDI_ITEM_DROPPED; - } - return; - } - } - } - - printMessage(_messageIds.itemNotHere); -} - -// TODO: Merge this into v2? -void AdlEngine_v4::dropItem(byte noun) { - Common::List::iterator item; - - for (item = _state.items.begin(); item != _state.items.end(); ++item) { - if (item->noun != noun || item->room != IDI_ANY) - continue; - - item->room = _state.room; - item->region = _state.region; - item->state = IDI_ITEM_DROPPED; - return; - } - - printMessage(_messageIds.dontUnderstand); -} - int AdlEngine_v4::o4_isItemInRoom(ScriptEnv &e) { OP_DEBUG_2("\t&& GET_ITEM_ROOM(%s) == %s", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); diff --git a/engines/adl/adl_v4.h b/engines/adl/adl_v4.h index 8516e40bd2..1bc7664d58 100644 --- a/engines/adl/adl_v4.h +++ b/engines/adl/adl_v4.h @@ -68,9 +68,6 @@ protected: void backupVars(); void restoreVars(); void switchRegion(byte region); - virtual bool isInventoryFull() { return false; } - virtual void takeItem(byte noun); - virtual void dropItem(byte noun); int o4_isItemInRoom(ScriptEnv &e); int o4_isVarGT(ScriptEnv &e); -- cgit v1.2.3