/** * Return the position of an object. * Returns X, Y and direction in angles */ void ScummEngine::getObjectXYPos(int object, int &x, int &y, int &dir) { int idx = getObjectIndex(object); assert(idx >= 0); ObjectData &od = _objs[idx]; int state; const byte *ptr; const ImageHeader *imhd; if (_game.version >= 6) { state = getState(object) - 1; if (state < 0) state = 0; ptr = getOBIMFromObjectData(od); if (!ptr) { // FIXME: We used to assert here, but it seems that in the nexus // in The Dig, this can happen, at least with old savegames, and // it's safe to continue... debug(0, "getObjectXYPos: Can't find object %d", object); return; } imhd = (const ImageHeader *)findResourceData(MKTAG('I','M','H','D'), ptr); assert(imhd); if (_game.version == 8) { switch (FROM_LE_32(imhd->v8.version)) { case 800: x = od.x_pos + (int32)READ_LE_UINT32((const byte *)imhd + 8 * state + 0x44); y = od.y_pos + (int32)READ_LE_UINT32((const byte *)imhd + 8 * state + 0x48); break; case 801: x = od.x_pos + (int32)READ_LE_UINT32(&imhd->v8.hotspot[state].x); y = od.y_pos + (int32)READ_LE_UINT32(&imhd->v8.hotspot[state].y); break; default: error("Unsupported image header version %d", FROM_LE_32(imhd->v8.version)); } } else if (_game.version == 7) { x = od.x_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].x); y = od.y_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].y); } else { x = od.x_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].x); y = od.y_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].y); } } else if (_game.version <= 2) { x = od.walk_x; y = od.walk_y; // Adjust x, y when no actor direction is set, but only perform this // adjustment for V0 games (e.g. MM C64), otherwise certain scenes in // newer games are affected as well (e.g. the interior of the Shuttle // Bus scene in Zak V2, where no actor is present). Refer to bug #3526089. if (!od.actordir && _game.version == 0) { 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 {
/** * Return the position of an object. * Returns X, Y and direction in angles */ void ScummEngine::getObjectXYPos(int object, int &x, int &y, int &dir) { int idx = (_v0ObjectIndex) ? object : getObjectIndex(object); assert(idx >= 0); ObjectData &od = _objs[idx]; int state; const byte *ptr; const ImageHeader *imhd; if (_game.version >= 6) { state = getState(object) - 1; if (state < 0) state = 0; ptr = getOBIMFromObjectData(od); if (!ptr) { // FIXME: We used to assert here, but it seems that in the nexus // in The Dig, this can happen, at least with old savegames, and // it's safe to continue... debug(0, "getObjectXYPos: Can't find object %d", object); return; } imhd = (const ImageHeader *)findResourceData(MKTAG('I','M','H','D'), ptr); assert(imhd); if (_game.version == 8) { switch (FROM_LE_32(imhd->v8.version)) { case 800: x = od.x_pos + (int32)READ_LE_UINT32((const byte *)imhd + 8 * state + 0x44); y = od.y_pos + (int32)READ_LE_UINT32((const byte *)imhd + 8 * state + 0x48); break; case 801: x = od.x_pos + (int32)READ_LE_UINT32(&imhd->v8.hotspot[state].x); y = od.y_pos + (int32)READ_LE_UINT32(&imhd->v8.hotspot[state].y); break; default: error("Unsupported image header version %d", FROM_LE_32(imhd->v8.version)); } } else if (_game.version == 7) { x = od.x_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].x); y = od.y_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].y); } else { x = od.x_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].x); 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; } else {