From 0f711c4a2e6d03d481cbb7d396e3e494b2351b38 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 3 Nov 2011 01:32:27 +0000 Subject: SCUMM: Fix warnings --- engines/scumm/object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index ae4bbc45a6..da238dc517 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -1842,7 +1842,7 @@ void ScummEngine::loadFlObject(uint object, uint room) { if (_dumpScripts) { char buf[32]; const byte *ptr = foir.obcd; - sprintf(buf, "roomobj-%d-", room); + sprintf(buf, "roomobj-%u-", room); ptr = findResource(MKTAG('V','E','R','B'), ptr); dumpResource(buf, object, ptr); } -- cgit v1.2.3 From a79f224c23f1b0fa4d9850a032e0adc0d72619f7 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Tue, 3 Jan 2012 22:10:50 +0100 Subject: SCUMM: changed handling of _activeInventory/_activeActor to _activeObject(2)/_activeObject(2)Type Note: the transition is not completed yet. The code compiles but is probably not runnable as not every occurrence of _activeInventory has been properly replaced. The usage of _v0ObjectIndex and _v0ObjectInInventory should be revised too and both variables should be replaced by another mechanism (maybe by using a single variable "obj = (type << 8) | id"). - moved v0 only vars _activeInventory, _activeObject, _activeVerb from ScummEngine_v2 to ScummEngine_v0 - removed _activeActor, _activeInvExecute, _activeObject2Inv and _activeInventory. They are handled by _activeObject/_activeObjectType and _activeObject2/_activeObject2Type now. - removed _activeObject(2)Index as they only bloat the code without any benefit (?) - merge prep-name tables from ScummEngine_v2::drawPreposition() and ScummEngine_v0::drawSentenceWord() by introducing ScummEngine_v2::drawPreposition() - rename ObjectData.flags -> obj_type (quick-fix only, needs review! Maybe obj_nr and obj_type can be merged into one var: obj_nr = (obj_type << 8) | obj_nr) - o_unknown2 is negation of o_ifActiveObject (o_ifNotEqualActiveObject2) - renamed o_ifActiveObject -> o_ifEqualActiveObject2 as it acts only on _activeObject2 - renamed ScummEngine_v0::drawSentenceWord() -> ScummEngine_v0::getObjectName() --- engines/scumm/object.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index da238dc517..a9e2a76345 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -316,7 +316,7 @@ int ScummEngine::getObjectIndex(int object) const { for (i = (_numLocalObjects-1); i > 0; i--) { if (_game.version == 0 ) - if( _objs[i].flags != _v0ObjectFlag ) + if( _objs[i].obj_type != _v0ObjectFlag ) continue; if (_objs[i].obj_nr == object) @@ -492,14 +492,6 @@ int ScummEngine::getObjActToObjActDist(int a, int b) { return getDist(x, y, x2, y2); } -int ScummEngine_v0::findObjectIndex(int x, int y) { - int objIdx; - _v0ObjectIndex = true; - objIdx = findObject(x, y); - _v0ObjectIndex = false; - return objIdx; -} - int ScummEngine::findObject(int x, int y) { int i, b; byte a; @@ -510,7 +502,7 @@ int ScummEngine::findObject(int x, int y) { continue; if (_game.version == 0) { - if (_objs[i].flags == 0 && _objs[i].state & kObjectStateUntouchable) + if (_objs[i].obj_type == 0 && _objs[i].state & kObjectStateUntouchable) continue; } else { if (_game.version <= 2 && _objs[i].state & kObjectStateUntouchable) @@ -532,7 +524,7 @@ int ScummEngine::findObject(int x, int y) { _objs[i].y_pos <= y && _objs[i].height + _objs[i].y_pos > y) { // MMC64: Set the object search flag if (_game.version == 0) - _v0ObjectFlag = _objs[i].flags; + _v0ObjectFlag = _objs[i].obj_type; if (_game.version == 0 && _v0ObjectIndex) return i; else @@ -844,7 +836,7 @@ void ScummEngine_v3old::resetRoomObjects() { char buf[32]; sprintf(buf, "roomobj-%d-", _roomResource); if (_game.version == 0) - sprintf(buf + 11, "%d-", od->flags); + sprintf(buf + 11, "%d-", od->obj_type); dumpResource(buf, od->obj_nr, room + od->OBCDoffset); } @@ -912,7 +904,7 @@ void ScummEngine_v0::resetRoomObject(ObjectData *od, const byte *room, const byt ptr -= 2; od->obj_nr = *(ptr + 6); - od->flags = *(ptr + 7); + od->obj_type = *(ptr + 7); od->x_pos = *(ptr + 8) * 8; od->y_pos = ((*(ptr + 9)) & 0x7F) * 8; @@ -1072,8 +1064,8 @@ void ScummEngine::updateObjectStates() { int i; ObjectData *od = &_objs[1]; for (i = 1; i < _numLocalObjects; i++, od++) { - // V0 MM, Room objects with Flag == 1 are objects with 'no-state' (room specific objects, non-pickup) - if (_game.version == 0 && od->flags == 1) + // V0 MM, objects with type == 1 are room objects (room specific objects, non-pickup) + if (_game.version == 0 && od->obj_type == 1) continue; if (od->obj_nr > 0) -- cgit v1.2.3 From 1c32000a004cc184a8744e2467035a4c7ba2f3a5 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sat, 7 Jan 2012 16:08:55 +0100 Subject: SCUMM: start handling object type and id correctly in mm c64 - removed complicated and unnecessary _v0ObjectIndex, _v0ObjectInInventory, _v0ObjectFlag vars - started to merge object id and type into one object value (type<<8|id) - verb preposition ids do not dependent on language -> remove from VerbSettings Note: - objects with type=0 are foreground objects. They have a state, an owner and a bg overlay image. - objects with type=1 are bg objects. They do not have a state or owner and are already contained in the bg image. The do not have an entry in objectState/OwnerTable --- engines/scumm/object.cpp | 74 +++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index a9e2a76345..53dc0151d9 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -178,10 +178,7 @@ void ScummEngine::clearOwnerOf(int obj) { // Alternatively, scan the inventory to see if the object is in there... for (i = 0; i < _numInventory; i++) { if (_inventory[i] == obj) { - if (_game.version == 0) - assert(WIO_INVENTORY == whereIsObjectInventory(obj)); - else - assert(WIO_INVENTORY == whereIsObject(obj)); + assert(WIO_INVENTORY == whereIsObject(obj)); // Found the object! Nuke it from the inventory. _res->nukeResource(rtInventory, i); @@ -310,52 +307,50 @@ int ScummEngine::getObjectRoom(int obj) const { int ScummEngine::getObjectIndex(int object) const { int i; + int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); - if (object < 1) + if (nr < 1) return -1; for (i = (_numLocalObjects-1); i > 0; i--) { - if (_game.version == 0 ) - if( _objs[i].obj_type != _v0ObjectFlag ) - continue; + if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) + continue; - if (_objs[i].obj_nr == object) + if (_objs[i].obj_nr == nr) return i; } return -1; } -int ScummEngine::whereIsObjectInventory(int object) { - int res = 0; - _v0ObjectInInventory = true; - res = whereIsObject(object); - _v0ObjectInInventory = false; - - return res; -} - int ScummEngine::whereIsObject(int object) const { int i; - if (object >= _numGlobalObjects) + // Note: in MMC64 bg objects are greater _numGlobalObjects + if (_game.version != 0 && object >= _numGlobalObjects) return WIO_NOT_FOUND; if (object < 1) return WIO_NOT_FOUND; - if ((_objectOwnerTable[object] != OF_OWNER_ROOM && _game.version != 0) || _v0ObjectInInventory) { + if ((_game.version != 0 || OBJECT_V0_TYPE(object) == 0) && + _objectOwnerTable[object] != OF_OWNER_ROOM) + { for (i = 0; i < _numInventory; i++) if (_inventory[i] == object) return WIO_INVENTORY; return WIO_NOT_FOUND; } - for (i = (_numLocalObjects-1); i > 0; i--) - if ((_objs[i].obj_nr == object && !_v0ObjectIndex) || (_v0ObjectIndex && i == object)) { + for (i = (_numLocalObjects-1); i > 0; i--) { + int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); + if (_objs[i].obj_nr == nr) { + if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) + continue; if (_objs[i].fl_object_index) return WIO_FLOBJECT; return WIO_ROOM; } + } return WIO_NOT_FOUND; } @@ -396,7 +391,7 @@ int ScummEngine::getObjectOrActorXY(int object, int &x, int &y) { * Returns X, Y and direction in angles */ void ScummEngine::getObjectXYPos(int object, int &x, int &y, int &dir) { - int idx = (_v0ObjectIndex) ? object : getObjectIndex(object); + int idx = getObjectIndex(object); assert(idx >= 0); ObjectData &od = _objs[idx]; int state; @@ -497,6 +492,7 @@ int ScummEngine::findObject(int x, int y) { byte a; const int mask = (_game.version <= 2) ? kObjectState_08 : 0xF; + // FIXME(TOBIAS): <= _numLocalObjects? for (i = 1; i < _numLocalObjects; i++) { if ((_objs[i].obj_nr < 1) || getClass(_objs[i].obj_nr, kObjectClassUntouchable)) continue; @@ -522,11 +518,8 @@ int ScummEngine::findObject(int x, int y) { #endif if (_objs[i].x_pos <= x && _objs[i].width + _objs[i].x_pos > x && _objs[i].y_pos <= y && _objs[i].height + _objs[i].y_pos > y) { - // MMC64: Set the object search flag if (_game.version == 0) - _v0ObjectFlag = _objs[i].obj_type; - if (_game.version == 0 && _v0ObjectIndex) - return i; + return OBJECT_V0(_objs[i].obj_nr, _objs[i].obj_type); else return _objs[i].obj_nr; } @@ -1165,7 +1158,7 @@ const byte *ScummEngine::getObjOrActorName(int obj) { } } - objptr = getOBCDFromObject(obj); + objptr = getOBCDFromObject(obj, true); if (objptr == NULL) return NULL; @@ -1218,15 +1211,14 @@ void ScummEngine::setObjectName(int obj) { uint32 ScummEngine::getOBCDOffs(int object) const { int i; - if ((_objectOwnerTable[object] != OF_OWNER_ROOM && (_game.version != 0)) || _v0ObjectInInventory) + if ((_game.version != 0 || OBJECT_V0_TYPE(object) == 0) && + _objectOwnerTable[object] != OF_OWNER_ROOM) return 0; - // V0 MM Return by Index - if (_v0ObjectIndex) - return _objs[object].OBCDoffset; - for (i = (_numLocalObjects-1); i > 0; i--) { if (_objs[i].obj_nr == object) { + if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) + continue; if (_objs[i].fl_object_index != 0) return 8; return _objs[i].OBCDoffset; @@ -1235,21 +1227,25 @@ uint32 ScummEngine::getOBCDOffs(int object) const { return 0; } -byte *ScummEngine::getOBCDFromObject(int obj) { - bool useInventory = _v0ObjectInInventory; +byte *ScummEngine::getOBCDFromObject(int obj, bool v0CheckInventory) { int i; byte *ptr; - _v0ObjectInInventory = false; - - if ((_objectOwnerTable[obj] != OF_OWNER_ROOM && (_game.version != 0)) || useInventory) { + if ((_game.version != 0 || OBJECT_V0_TYPE(obj) == 0) && + _objectOwnerTable[obj] != OF_OWNER_ROOM) + { + if (_game.version == 0 && !v0CheckInventory) + return 0; for (i = 0; i < _numInventory; i++) { if (_inventory[i] == obj) return getResourceAddress(rtInventory, i); } } else { for (i = (_numLocalObjects-1); i > 0; --i) { - if ((_objs[i].obj_nr == obj && !_v0ObjectIndex) || (_v0ObjectIndex && i == obj)) { + int nr = (_game.version != 0) ? obj : OBJECT_V0_NR(obj); + if (_objs[i].obj_nr == nr) { + if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(obj)) + continue; if (_objs[i].fl_object_index) { assert(_objs[i].OBCDoffset == 8); ptr = getResourceAddress(rtFlObject, _objs[i].fl_object_index); -- cgit v1.2.3 From de0b5f76749add219a6b667d5d2d69fb8a86d959 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sun, 8 Jan 2012 23:51:13 +0100 Subject: SCUMM: use command stack and SentenceTab in mm c64 - MM C64 uses command stack (SentenceTab, doSentence()) now - _cmdObject... added for current SentenceTab. The _active... variables are only used to build a sentence in the inventory but never by a script. -> many routines are not needed anymore and are removed --- engines/scumm/object.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 53dc0151d9..49f1777c86 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -434,8 +434,15 @@ void ScummEngine::getObjectXYPos(int object, int &x, int &y, int &dir) { y = od.y_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].y); } } else if (_game.version <= 2) { - x = od.walk_x >> V12_X_SHIFT; - y = od.walk_y >> V12_Y_SHIFT; + if (od.actordir) { + x = od.walk_x; + y = od.walk_y; + } else { + x = od.x_pos + od.width/2; + y = od.y_pos + od.height/2; + } + x = x >> V12_X_SHIFT; + y = y >> V12_Y_SHIFT; } else { x = od.walk_x; y = od.walk_y; -- cgit v1.2.3 From c16ef940a1f25846623903d6ce744374228ff104 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 9 Jan 2012 20:04:38 +0100 Subject: SCUMM: make START-button in mm c64 kid selection screen work again --- engines/scumm/object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 49f1777c86..670b2cb79c 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -1223,7 +1223,7 @@ uint32 ScummEngine::getOBCDOffs(int object) const { return 0; for (i = (_numLocalObjects-1); i > 0; i--) { - if (_objs[i].obj_nr == object) { + if (_objs[i].obj_nr == OBJECT_V0_NR(object)) { if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) continue; if (_objs[i].fl_object_index != 0) -- cgit v1.2.3 From df07d2db297b263142a0505d880e57b17e681a97 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Tue, 10 Jan 2012 22:11:11 +0100 Subject: SCUMM: fix a regression in v0 Found by segra. --- engines/scumm/object.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 670b2cb79c..26597864fd 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -1223,7 +1223,8 @@ uint32 ScummEngine::getOBCDOffs(int object) const { return 0; for (i = (_numLocalObjects-1); i > 0; i--) { - if (_objs[i].obj_nr == OBJECT_V0_NR(object)) { + int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); + if (_objs[i].obj_nr == nr) { if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) continue; if (_objs[i].fl_object_index != 0) -- cgit v1.2.3 From 621017ce65f3c5b346c3b17bd4e6700af13215c6 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Wed, 11 Jan 2012 22:57:46 +0100 Subject: SCUMM: remove some NOTEs/TODOs - o5_breakHere() seems to be still needed. For example edna does not manage to walk up the ladder if this is not enabled. - numLocalObjects seems to be big enough so that < instead of <= can be used. The original interpreter only uses the local ids 0 .. 44 whereas scummvm has _numLocalObjects set to 200. --- engines/scumm/object.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 26597864fd..86d9065385 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -499,7 +499,6 @@ int ScummEngine::findObject(int x, int y) { byte a; const int mask = (_game.version <= 2) ? kObjectState_08 : 0xF; - // FIXME(TOBIAS): <= _numLocalObjects? for (i = 1; i < _numLocalObjects; i++) { if ((_objs[i].obj_nr < 1) || getClass(_objs[i].obj_nr, kObjectClassUntouchable)) continue; -- cgit v1.2.3 From f2309998ffbcb33a96edac7f2959abc534717827 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sun, 15 Jan 2012 20:11:30 +0100 Subject: SCUMM: fix debugger for v0 --- engines/scumm/object.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 86d9065385..d3ed086892 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -1150,6 +1150,17 @@ void ScummEngine::markObjectRectAsDirty(int obj) { } } +const byte *ScummEngine::getActorName(int id) { + if (_game.version == 0) { + if (id > 0 && id < _numActors) + return derefActor(id, "getActorName")->getActorName(); + else + return NULL; + } else { + return getObjOrActorName(id); + } +} + const byte *ScummEngine::getObjOrActorName(int obj) { byte *objptr; int i; -- cgit v1.2.3 From c138ef67099cd14bedd4e0e79080e31e2b41eddd Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sun, 15 Jan 2012 21:43:21 +0100 Subject: SCUMM: merge _activeObjectNr/_activeObjectType and _cmdObjectNr/_cmdObjectType --- engines/scumm/object.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index d3ed086892..f7a01fd4cc 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -1150,23 +1150,15 @@ void ScummEngine::markObjectRectAsDirty(int obj) { } } -const byte *ScummEngine::getActorName(int id) { - if (_game.version == 0) { - if (id > 0 && id < _numActors) - return derefActor(id, "getActorName")->getActorName(); - else - return NULL; - } else { - return getObjOrActorName(id); - } -} - const byte *ScummEngine::getObjOrActorName(int obj) { byte *objptr; int i; - if (obj < _numActors && _game.version >= 1) - return derefActor(obj, "getObjOrActorName")->getActorName(); + if ((_game.version == 0 && OBJECT_V0_TYPE(obj) == kObjectV0TypeActor) || + (_game.version != 0 && obj < _numActors)) { + int actorNr = (_game.version != 0 ? obj : OBJECT_V0_NR(obj)); + return derefActor(actorNr, "getObjOrActorName")->getActorName(); + } for (i = 0; i < _numNewNames; i++) { if (_newNames[i] == obj) { -- cgit v1.2.3 From 347035385e3608c3107db7b9cba0673ce9e03a22 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 16 Jan 2012 22:32:46 +0100 Subject: SCUMM: merge object v0 id and type into one object var --- engines/scumm/object.cpp | 55 +++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index f7a01fd4cc..bf871d7fa5 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -203,6 +203,9 @@ void ScummEngine::clearOwnerOf(int obj) { } bool ScummEngine::getClass(int obj, int cls) const { + if (_game.version == 0) + return false; + assertRange(0, obj, _numGlobalObjects - 1, "object"); cls &= 0x7F; assertRange(1, cls, 32, "class"); @@ -230,6 +233,9 @@ bool ScummEngine::getClass(int obj, int cls) const { } void ScummEngine::putClass(int obj, int cls, bool set) { + if (_game.version == 0) + return; + assertRange(0, obj, _numGlobalObjects - 1, "object"); cls &= 0x7F; assertRange(1, cls, 32, "class"); @@ -307,16 +313,12 @@ int ScummEngine::getObjectRoom(int obj) const { int ScummEngine::getObjectIndex(int object) const { int i; - int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); - if (nr < 1) + if (object < 1) return -1; for (i = (_numLocalObjects-1); i > 0; i--) { - if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) - continue; - - if (_objs[i].obj_nr == nr) + if (_objs[i].obj_nr == object) return i; } return -1; @@ -342,10 +344,7 @@ int ScummEngine::whereIsObject(int object) const { } for (i = (_numLocalObjects-1); i > 0; i--) { - int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); - if (_objs[i].obj_nr == nr) { - if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) - continue; + if (_objs[i].obj_nr == object) { if (_objs[i].fl_object_index) return WIO_FLOBJECT; return WIO_ROOM; @@ -503,11 +502,9 @@ int ScummEngine::findObject(int x, int y) { if ((_objs[i].obj_nr < 1) || getClass(_objs[i].obj_nr, kObjectClassUntouchable)) continue; - if (_game.version == 0) { - if (_objs[i].obj_type == 0 && _objs[i].state & kObjectStateUntouchable) - continue; - } else { - if (_game.version <= 2 && _objs[i].state & kObjectStateUntouchable) + if ((_game.version == 0 && OBJECT_V0_TYPE(_objs[i].obj_nr) == kObjectV0TypeFG) || + (_game.version > 0 && _game.version <= 2)) { + if (_objs[i].state & kObjectStateUntouchable) continue; } @@ -523,12 +520,8 @@ int ScummEngine::findObject(int x, int y) { } #endif if (_objs[i].x_pos <= x && _objs[i].width + _objs[i].x_pos > x && - _objs[i].y_pos <= y && _objs[i].height + _objs[i].y_pos > y) { - if (_game.version == 0) - return OBJECT_V0(_objs[i].obj_nr, _objs[i].obj_type); - else - return _objs[i].obj_nr; - } + _objs[i].y_pos <= y && _objs[i].height + _objs[i].y_pos > y) + return _objs[i].obj_nr; break; } } while ((_objs[b].state & mask) == a); @@ -834,9 +827,6 @@ void ScummEngine_v3old::resetRoomObjects() { if (_dumpScripts) { char buf[32]; sprintf(buf, "roomobj-%d-", _roomResource); - if (_game.version == 0) - sprintf(buf + 11, "%d-", od->obj_type); - dumpResource(buf, od->obj_nr, room + od->OBCDoffset); } } @@ -902,8 +892,7 @@ void ScummEngine_v0::resetRoomObject(ObjectData *od, const byte *room, const byt const byte *ptr = room + od->OBCDoffset; ptr -= 2; - od->obj_nr = *(ptr + 6); - od->obj_type = *(ptr + 7); + od->obj_nr = OBJECT_V0(*(ptr + 6), *(ptr + 7)); od->x_pos = *(ptr + 8) * 8; od->y_pos = ((*(ptr + 9)) & 0x7F) * 8; @@ -1064,7 +1053,7 @@ void ScummEngine::updateObjectStates() { ObjectData *od = &_objs[1]; for (i = 1; i < _numLocalObjects; i++, od++) { // V0 MM, objects with type == 1 are room objects (room specific objects, non-pickup) - if (_game.version == 0 && od->obj_type == 1) + if (_game.version == 0 && OBJECT_V0_TYPE(od->obj_nr) == kObjectV0TypeBG) continue; if (od->obj_nr > 0) @@ -1156,7 +1145,7 @@ const byte *ScummEngine::getObjOrActorName(int obj) { if ((_game.version == 0 && OBJECT_V0_TYPE(obj) == kObjectV0TypeActor) || (_game.version != 0 && obj < _numActors)) { - int actorNr = (_game.version != 0 ? obj : OBJECT_V0_NR(obj)); + int actorNr = (_game.version != 0 ? obj : OBJECT_V0_ID(obj)); return derefActor(actorNr, "getObjOrActorName")->getActorName(); } @@ -1225,10 +1214,7 @@ uint32 ScummEngine::getOBCDOffs(int object) const { return 0; for (i = (_numLocalObjects-1); i > 0; i--) { - int nr = (_game.version != 0) ? object : OBJECT_V0_NR(object); - if (_objs[i].obj_nr == nr) { - if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(object)) - continue; + if (_objs[i].obj_nr == object) { if (_objs[i].fl_object_index != 0) return 8; return _objs[i].OBCDoffset; @@ -1252,10 +1238,7 @@ byte *ScummEngine::getOBCDFromObject(int obj, bool v0CheckInventory) { } } else { for (i = (_numLocalObjects-1); i > 0; --i) { - int nr = (_game.version != 0) ? obj : OBJECT_V0_NR(obj); - if (_objs[i].obj_nr == nr) { - if (_game.version == 0 && _objs[i].obj_type != OBJECT_V0_TYPE(obj)) - continue; + if (_objs[i].obj_nr == obj) { if (_objs[i].fl_object_index) { assert(_objs[i].OBCDoffset == 8); ptr = getResourceAddress(rtFlObject, _objs[i].fl_object_index); -- cgit v1.2.3 From 96f8fc6ca9889d30db11b854c95ffd65bb88034d Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sun, 22 Jan 2012 22:58:10 +0100 Subject: SCUMM: Fix actor ID handling in v0 Some object functions allow actor IDs and object IDs as parameters. They are easily distinguishable in engines > 0 as actor IDs are < _numActors and object IDs are bigger. In v0 this is not the case as there are objects with IDs like 3 and 5 (e.g. the hamster). So object ID handling was unified for v0 and the other engines by introducing objIsActor(), objToActor() and ActorToObj(). --- engines/scumm/object.cpp | 67 +++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 23 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index bf871d7fa5..4ef8707714 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -357,8 +357,8 @@ int ScummEngine::whereIsObject(int object) const { int ScummEngine::getObjectOrActorXY(int object, int &x, int &y) { Actor *act; - if (object < _numActors) { - act = derefActorSafe(object, "getObjectOrActorXY"); + if (objIsActor(object)) { + act = derefActorSafe(objToActor(object), "getObjectOrActorXY"); if (act && act->isInCurrentRoom()) { x = act->getRealPos().x; y = act->getRealPos().y; @@ -371,7 +371,7 @@ int ScummEngine::getObjectOrActorXY(int object, int &x, int &y) { case WIO_NOT_FOUND: return -1; case WIO_INVENTORY: - if (_objectOwnerTable[object] < _numActors) { + if (objIsActor(_objectOwnerTable[object])) { act = derefActor(_objectOwnerTable[object], "getObjectOrActorXY(2)"); if (act && act->isInCurrentRoom()) { x = act->getRealPos().x; @@ -463,11 +463,11 @@ int ScummEngine::getObjActToObjActDist(int a, int b) { Actor *acta = NULL; Actor *actb = NULL; - if (a < _numActors) - acta = derefActorSafe(a, "getObjActToObjActDist"); + if (objIsActor(a)) + acta = derefActorSafe(objToActor(a), "getObjActToObjActDist"); - if (b < _numActors) - actb = derefActorSafe(b, "getObjActToObjActDist(2)"); + if (objIsActor(b)) + actb = derefActorSafe(objToActor(b), "getObjActToObjActDist(2)"); if (acta && actb && acta->getRoom() == actb->getRoom() && acta->getRoom() && !acta->isInCurrentRoom()) return 0; @@ -1143,11 +1143,8 @@ const byte *ScummEngine::getObjOrActorName(int obj) { byte *objptr; int i; - if ((_game.version == 0 && OBJECT_V0_TYPE(obj) == kObjectV0TypeActor) || - (_game.version != 0 && obj < _numActors)) { - int actorNr = (_game.version != 0 ? obj : OBJECT_V0_ID(obj)); - return derefActor(actorNr, "getObjOrActorName")->getActorName(); - } + if (objIsActor(obj)) + return derefActor(objToActor(obj), "getObjOrActorName")->getActorName(); for (i = 0; i < _numNewNames; i++) { if (_newNames[i] == obj) { @@ -1183,7 +1180,7 @@ const byte *ScummEngine::getObjOrActorName(int obj) { void ScummEngine::setObjectName(int obj) { int i; - if (obj < _numActors && _game.version != 0) + if (objIsActor(obj)) error("Can't set actor %d name with new-name-of", obj); for (i = 0; i < _numNewNames; i++) { @@ -1491,11 +1488,34 @@ void ScummEngine::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, } } +bool ScummEngine::objIsActor(int obj) { + // object IDs < _numActors are used in v0 for objects too (e.g. hamster) + if (_game.version == 0) + return OBJECT_V0_TYPE(obj) == kObjectV0TypeActor; + else + return obj < _numActors; +} + +int ScummEngine::objToActor(int obj) { + if (_game.version == 0) + return OBJECT_V0_ID(obj); + else + return obj; +} + +int ScummEngine::actorToObj(int actor) { + if (_game.version == 0) + return OBJECT_V0(actor, kObjectV0TypeActor); + else + return actor; +} + int ScummEngine::getObjX(int obj) { - if (obj < _numActors) { - if (obj < 1) - return 0; /* fix for indy4's map */ - return derefActor(obj, "getObjX")->getRealPos().x; + if (obj < 1) + return 0; /* fix for indy4's map */ + + if (objIsActor(obj)) { + return derefActor(objToActor(obj), "getObjX")->getRealPos().x; } else { if (whereIsObject(obj) == WIO_NOT_FOUND) return -1; @@ -1506,10 +1526,11 @@ int ScummEngine::getObjX(int obj) { } int ScummEngine::getObjY(int obj) { - if (obj < _numActors) { - if (obj < 1) - return 0; /* fix for indy4's map */ - return derefActor(obj, "getObjY")->getRealPos().y; + if (obj < 1) + return 0; /* fix for indy4's map */ + + if (objIsActor(obj)) { + return derefActor(objToActor(obj), "getObjY")->getRealPos().y; } else { if (whereIsObject(obj) == WIO_NOT_FOUND) return -1; @@ -1525,8 +1546,8 @@ int ScummEngine::getObjOldDir(int obj) { int ScummEngine::getObjNewDir(int obj) { int dir; - if (obj < _numActors) { - dir = derefActor(obj, "getObjNewDir")->getFacing(); + if (objIsActor(obj)) { + dir = derefActor(objToActor(obj), "getObjNewDir")->getFacing(); } else { int x, y; getObjectXYPos(obj, x, y, dir); -- cgit v1.2.3 From 9dd6105ce62210509207dc61607543b7bcf5639d Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Sat, 4 Feb 2012 18:34:08 +0100 Subject: SCUMM: replace "c64" with "v0" when it applies to both C64 and AppleII v0 versions In addition some routines (e.g. the gfx ones) that are even used in v1. --- engines/scumm/object.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index 4ef8707714..e38552c8f3 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -327,7 +327,7 @@ int ScummEngine::getObjectIndex(int object) const { int ScummEngine::whereIsObject(int object) const { int i; - // Note: in MMC64 bg objects are greater _numGlobalObjects + // Note: in MM v0 bg objects are greater _numGlobalObjects if (_game.version != 0 && object >= _numGlobalObjects) return WIO_NOT_FOUND; @@ -808,7 +808,7 @@ void ScummEngine_v3old::resetRoomObjects() { else ptr = room + 29; - // Default pointer of objects without image, in C64 verison of Maniac Mansion + // Default pointer of objects without image, in v0 version of Maniac Mansion int defaultPtr = READ_LE_UINT16(ptr + 2 * _numObjectsInRoom); for (i = 0; i < _numObjectsInRoom; i++) { -- cgit v1.2.3 From 4922055063b0a72069ffdbbe9e95c5b11f47bd71 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Fri, 10 Feb 2012 22:58:59 +0100 Subject: SCUMM: cleanup and separation of objIsActor()/objToActor()/actorToObj() for v0 and other engines --- engines/scumm/object.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'engines/scumm/object.cpp') diff --git a/engines/scumm/object.cpp b/engines/scumm/object.cpp index e38552c8f3..399cd91324 100644 --- a/engines/scumm/object.cpp +++ b/engines/scumm/object.cpp @@ -437,8 +437,8 @@ void ScummEngine::getObjectXYPos(int object, int &x, int &y, int &dir) { x = od.walk_x; y = od.walk_y; } else { - x = od.x_pos + od.width/2; - y = od.y_pos + od.height/2; + x = od.x_pos + od.width / 2; + y = od.y_pos + od.height / 2; } x = x >> V12_X_SHIFT; y = y >> V12_Y_SHIFT; @@ -1488,26 +1488,29 @@ void ScummEngine::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, } } -bool ScummEngine::objIsActor(int obj) { +bool ScummEngine_v0::objIsActor(int obj) { // object IDs < _numActors are used in v0 for objects too (e.g. hamster) - if (_game.version == 0) - return OBJECT_V0_TYPE(obj) == kObjectV0TypeActor; - else - return obj < _numActors; + return OBJECT_V0_TYPE(obj) == kObjectV0TypeActor; +} + +int ScummEngine_v0::objToActor(int obj) { + return OBJECT_V0_ID(obj); +} + +int ScummEngine_v0::actorToObj(int actor) { + return OBJECT_V0(actor, kObjectV0TypeActor); +} + +bool ScummEngine::objIsActor(int obj) { + return obj < _numActors; } int ScummEngine::objToActor(int obj) { - if (_game.version == 0) - return OBJECT_V0_ID(obj); - else - return obj; + return obj; } int ScummEngine::actorToObj(int actor) { - if (_game.version == 0) - return OBJECT_V0(actor, kObjectV0TypeActor); - else - return actor; + return actor; } int ScummEngine::getObjX(int obj) { -- cgit v1.2.3