2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 The ScummVM project
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scumm.h"
|
2002-05-14 23:32:34 +00:00
|
|
|
#include "actor.h"
|
2003-05-30 19:00:33 +00:00
|
|
|
#include "bomp.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
#include "object.h"
|
|
|
|
#include "resource.h"
|
2003-01-14 10:06:56 +00:00
|
|
|
#include "usage_bits.h"
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-30 15:06:29 +00:00
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma START_PACK_STRUCTS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct BompHeader { /* Bomp header */
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint16 unk;
|
|
|
|
uint16 width, height;
|
|
|
|
} GCC_PACK old;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32 width, height;
|
|
|
|
} GCC_PACK v8;
|
|
|
|
} GCC_PACK;
|
|
|
|
} GCC_PACK;
|
|
|
|
|
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma END_PACK_STRUCTS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
bool Scumm::getClass(int obj, int cls)
|
|
|
|
{
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in getClass");
|
2002-04-03 16:20:17 +00:00
|
|
|
cls &= 0x7F;
|
2002-04-11 17:19:16 +00:00
|
|
|
checkRange(32, 1, cls, "Class %d out of range in getClass");
|
2002-04-03 16:20:17 +00:00
|
|
|
|
2002-04-04 04:38:18 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
2003-05-20 20:42:28 +00:00
|
|
|
// Translate the new (V5) object classes to the old classes
|
|
|
|
// (for those which differ).
|
|
|
|
switch (cls) {
|
|
|
|
case kObjectClassUntouchable:
|
|
|
|
cls = 24;
|
|
|
|
break;
|
|
|
|
case kObjectClassPlayer:
|
|
|
|
cls = 23;
|
|
|
|
break;
|
|
|
|
case kObjectClassXFlip:
|
|
|
|
cls = 19;
|
|
|
|
break;
|
|
|
|
case kObjectClassYFlip:
|
|
|
|
cls = 18;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-03 15:45:32 +00:00
|
|
|
}
|
2003-05-20 20:42:28 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
return (_classData[obj] & (1 << (cls - 1))) != 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::putClass(int obj, int cls, bool set)
|
|
|
|
{
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in putClass");
|
2001-10-09 14:30:12 +00:00
|
|
|
cls &= 0x7F;
|
2002-07-15 22:56:24 +00:00
|
|
|
checkRange(32, 1, cls, "Class %d out of range in putClass");
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-04 04:38:18 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
2003-05-20 20:42:28 +00:00
|
|
|
// Translate the new (V5) object classes to the old classes
|
|
|
|
// (for those which differ).
|
|
|
|
switch (cls) {
|
|
|
|
case kObjectClassUntouchable:
|
|
|
|
cls = 24;
|
|
|
|
break;
|
|
|
|
case kObjectClassPlayer:
|
|
|
|
cls = 23;
|
|
|
|
break;
|
|
|
|
case kObjectClassXFlip:
|
|
|
|
cls = 19;
|
|
|
|
break;
|
|
|
|
case kObjectClassYFlip:
|
|
|
|
cls = 18;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-03 16:20:17 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
// FIXME: It isn't enough for the Indy3 intro to make the
|
|
|
|
// little trains ignore boxes, they have to always clip as
|
|
|
|
// well. Is this yet another walkbox 0 error?
|
|
|
|
if (_gameId == GID_INDY3_256 && cls == kObjectClassIgnoreBoxes && _currentRoom == 76)
|
|
|
|
putClass(obj, kObjectClassAlwaysClip, set);
|
|
|
|
|
2002-04-11 15:22:02 +00:00
|
|
|
if (set)
|
2002-04-11 17:19:16 +00:00
|
|
|
_classData[obj] |= (1 << (cls - 1));
|
2002-04-11 15:22:02 +00:00
|
|
|
else
|
2002-04-11 17:19:16 +00:00
|
|
|
_classData[obj] &= ~(1 << (cls - 1));
|
2002-07-26 16:13:04 +00:00
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
if (1 <= obj && obj < _numActors) {
|
2002-07-26 16:13:04 +00:00
|
|
|
_actors[obj].classChanged(cls, set);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getOwner(int obj) {
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in getOwner");
|
2001-11-26 19:57:57 +00:00
|
|
|
return _objectOwnerTable[obj];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::putOwner(int obj, int owner) {
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in putOwner");
|
2001-11-26 19:57:57 +00:00
|
|
|
checkRange(0xFF, 0, owner, "Owner %d out of range in putOwner");
|
2002-07-02 21:29:24 +00:00
|
|
|
_objectOwnerTable[obj] = owner;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-06-16 14:45:23 +00:00
|
|
|
#ifndef BYPASS_COPY_PROT
|
|
|
|
#define BYPASS_COPY_PROT
|
|
|
|
#endif
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getState(int obj) {
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in getState");
|
2003-06-16 14:45:23 +00:00
|
|
|
|
|
|
|
#if defined(BYPASS_COPY_PROT)
|
|
|
|
// I knew LucasArts sold cracked copies of the original Maniac Mansion,
|
|
|
|
// at least as part of Day of the Tentacle. Apparently they also sold
|
|
|
|
// cracked versions of the enhanced version. At least in Germany.
|
|
|
|
//
|
|
|
|
// This will keep the security door open at all times. I can only
|
|
|
|
// assume that 182 and 193 each correspond to one particular side of
|
|
|
|
// the it. Fortunately it does not prevent frustrated players from
|
|
|
|
// blowing up the mansion, should they feel the urge to.
|
|
|
|
|
|
|
|
if (_gameId == GID_MANIAC && (obj == 182 || obj == 193))
|
|
|
|
_objectStateTable[obj] |= 0x08;
|
|
|
|
#endif
|
|
|
|
|
2002-07-02 21:29:24 +00:00
|
|
|
return _objectStateTable[obj];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::putState(int obj, int state) {
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in putState");
|
2001-11-26 19:57:57 +00:00
|
|
|
checkRange(0xFF, 0, state, "State %d out of range in putState");
|
2002-07-02 21:29:24 +00:00
|
|
|
_objectStateTable[obj] = state;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjectRoom(int obj) {
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, obj, "Object %d out of range in getObjectRoom");
|
2001-11-26 19:57:57 +00:00
|
|
|
return _objectRoomTable[obj];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjectIndex(int object) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2003-01-12 07:30:17 +00:00
|
|
|
if (object < 1)
|
|
|
|
return -1;
|
|
|
|
|
2003-05-22 15:27:44 +00:00
|
|
|
for (i = (_numLocalObjects-1); i > 0; i--) {
|
|
|
|
if (_objs[i].obj_nr == object)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::whereIsObject(int object) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
if (object >= _numGlobalObjects)
|
2001-11-12 20:50:36 +00:00
|
|
|
return WIO_NOT_FOUND;
|
2001-11-06 21:29:23 +00:00
|
|
|
|
2003-01-12 07:30:17 +00:00
|
|
|
if (object < 1)
|
|
|
|
return WIO_NOT_FOUND;
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_objectOwnerTable[object] != OF_OWNER_ROOM) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _maxInventoryItems; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_inventory[i] == object)
|
2001-11-12 20:50:36 +00:00
|
|
|
return WIO_INVENTORY;
|
|
|
|
return WIO_NOT_FOUND;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = (_numLocalObjects-1); i > 0; i--)
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_objs[i].obj_nr == object) {
|
|
|
|
if (_objs[i].fl_object_index)
|
2001-11-12 20:50:36 +00:00
|
|
|
return WIO_FLOBJECT;
|
|
|
|
return WIO_ROOM;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-01-11 18:52:19 +00:00
|
|
|
|
2001-11-12 20:50:36 +00:00
|
|
|
return WIO_NOT_FOUND;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjectOrActorXY(int object, int &x, int &y) {
|
2003-05-13 23:42:41 +00:00
|
|
|
if (object < _numActors) {
|
2002-07-30 11:43:30 +00:00
|
|
|
Actor *act = derefActorSafe(object, "getObjectOrActorXY");
|
|
|
|
if (!act)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return act->getActorXYPos(x, y);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
switch (whereIsObject(object)) {
|
2001-11-12 20:50:36 +00:00
|
|
|
case WIO_NOT_FOUND:
|
2001-10-09 14:30:12 +00:00
|
|
|
return -1;
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_INVENTORY:
|
2003-05-13 23:42:41 +00:00
|
|
|
if (_objectOwnerTable[object] < _numActors)
|
2002-07-16 18:51:27 +00:00
|
|
|
return derefActorSafe(_objectOwnerTable[object], "getObjectOrActorXY(2)")->getActorXYPos(x, y);
|
2002-04-07 04:29:15 +00:00
|
|
|
else
|
|
|
|
return 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-07-16 18:51:27 +00:00
|
|
|
getObjectXYPos(object, x, y);
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Return the position of an object.
|
|
|
|
* Returns X, Y and direction in angles
|
2001-11-26 19:57:57 +00:00
|
|
|
*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::getObjectXYPos(int object, int &x, int &y, int &dir) {
|
2001-10-16 10:01:48 +00:00
|
|
|
ObjectData *od = &_objs[getObjectIndex(object)];
|
|
|
|
int state;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
|
|
|
const ImageHeader *imhd;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 6) {
|
2003-01-13 15:27:06 +00:00
|
|
|
state = getState(object) - 1;
|
|
|
|
if (state < 0)
|
|
|
|
state = 0;
|
|
|
|
|
|
|
|
if (od->fl_object_index) {
|
|
|
|
ptr = getResourceAddress(rtFlObject, od->fl_object_index);
|
|
|
|
ptr = findResource(MKID('OBIM'), ptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
} else {
|
2003-01-13 15:27:06 +00:00
|
|
|
ptr = getResourceAddress(rtRoom, _roomResource);
|
|
|
|
ptr += od->OBIMoffset;
|
|
|
|
}
|
2003-05-30 00:40:58 +00:00
|
|
|
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...
|
|
|
|
warning("getObjectXYPos: Can't find object %d", object);
|
|
|
|
return;
|
|
|
|
}
|
2003-05-28 20:01:47 +00:00
|
|
|
imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), ptr);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2003-01-13 15:27:06 +00:00
|
|
|
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);
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 7) {
|
2003-01-13 15:27:06 +00:00
|
|
|
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);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x = od->walk_x;
|
2002-03-23 20:34:47 +00:00
|
|
|
y = od->walk_y;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2003-03-02 15:51:56 +00:00
|
|
|
dir = fromSimpleDir(1, od->actordir);
|
2003-02-27 10:42:12 +00:00
|
|
|
else
|
|
|
|
dir = oldDirToNewDir(od->actordir & 3);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjActToObjActDist(int a, int b) {
|
2002-07-16 18:51:27 +00:00
|
|
|
int x, y, x2, y2;
|
2001-10-09 14:30:12 +00:00
|
|
|
Actor *acta = NULL;
|
|
|
|
Actor *actb = NULL;
|
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
if (a < _numActors)
|
2001-10-09 14:30:12 +00:00
|
|
|
acta = derefActorSafe(a, "getObjActToObjActDist");
|
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
if (b < _numActors)
|
2001-10-09 14:30:12 +00:00
|
|
|
actb = derefActorSafe(b, "getObjActToObjActDist(2)");
|
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
if (acta && actb && acta->getRoom() == actb->getRoom() && acta->getRoom() && !acta->isInCurrentRoom())
|
2002-04-11 17:19:16 +00:00
|
|
|
return 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-07-16 18:51:27 +00:00
|
|
|
if (getObjectOrActorXY(a, x, y) == -1)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0xFF;
|
|
|
|
|
2002-07-16 18:51:27 +00:00
|
|
|
if (getObjectOrActorXY(b, x2, y2) == -1)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0xFF;
|
|
|
|
|
|
|
|
if (acta) {
|
2003-05-20 19:35:40 +00:00
|
|
|
AdjustBoxResult r = acta->adjustXYToBeInBox(x2, y2);
|
2002-07-16 18:51:27 +00:00
|
|
|
x2 = r.x;
|
|
|
|
y2 = r.y;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 18:51:27 +00:00
|
|
|
y = abs(y - y2);
|
|
|
|
x = abs(x - x2);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (y > x)
|
|
|
|
x = y;
|
2003-06-07 00:13:26 +00:00
|
|
|
return (_version <= 2) ? x / 8 : x;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::findObject(int x, int y) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, b;
|
2001-11-26 19:57:57 +00:00
|
|
|
byte a;
|
2003-06-07 00:13:26 +00:00
|
|
|
const int mask = (_version <= 2) ? 0x8 : 0xF;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++) {
|
2003-05-20 20:42:28 +00:00
|
|
|
if ((_objs[i].obj_nr < 1) || getClass(_objs[i].obj_nr, kObjectClassUntouchable))
|
2001-10-09 14:30:12 +00:00
|
|
|
continue;
|
2003-06-07 00:13:26 +00:00
|
|
|
if ((_version <= 2) && _objs[i].state & 0x2)
|
2003-05-19 01:27:30 +00:00
|
|
|
continue;
|
2001-10-09 14:30:12 +00:00
|
|
|
b = i;
|
|
|
|
do {
|
2001-10-16 10:01:48 +00:00
|
|
|
a = _objs[b].parentstate;
|
|
|
|
b = _objs[b].parent;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b == 0) {
|
2002-12-28 00:45:44 +00:00
|
|
|
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)
|
2002-04-11 17:19:16 +00:00
|
|
|
return _objs[i].obj_nr;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-05-10 22:12:23 +00:00
|
|
|
} while ((_objs[b].state & mask) == a);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawRoomObject(int i, int arg) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ObjectData *od;
|
2001-11-26 19:57:57 +00:00
|
|
|
byte a;
|
2003-06-07 00:13:26 +00:00
|
|
|
const int mask = (_version <= 2) ? 0x8 : 0xF;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-12-04 21:44:41 +00:00
|
|
|
od = &_objs[i];
|
2003-01-12 07:30:17 +00:00
|
|
|
if ((i < 1) || (od->obj_nr < 1) || !od->state)
|
2001-12-04 21:44:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
a = od->parentstate;
|
|
|
|
if (!od->parent) {
|
|
|
|
drawObject(i, arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
od = &_objs[od->parent];
|
2003-05-10 22:12:23 +00:00
|
|
|
} while ((od->state & mask) == a);
|
2001-12-04 21:44:41 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawRoomObjects(int arg) {
|
2001-12-04 21:44:41 +00:00
|
|
|
int i;
|
2003-06-07 00:13:26 +00:00
|
|
|
const int mask = (_version <= 2) ? 0x8 : 0xF;
|
2001-12-04 21:44:41 +00:00
|
|
|
|
|
|
|
if (_features & GF_DRAWOBJ_OTHER_ORDER) {
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++)
|
2003-01-12 07:30:17 +00:00
|
|
|
if (_objs[i].obj_nr > 0)
|
|
|
|
drawRoomObject(i, arg);
|
2001-12-04 21:44:41 +00:00
|
|
|
} else {
|
2003-01-12 08:37:59 +00:00
|
|
|
for (i = (_numLocalObjects-1); i > 0; i--)
|
2003-05-10 22:12:23 +00:00
|
|
|
if (_objs[i].obj_nr > 0 && (_objs[i].state & mask)) {
|
2003-01-12 07:30:17 +00:00
|
|
|
drawRoomObject(i, arg);
|
2003-05-10 22:12:23 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 00:03:49 +00:00
|
|
|
static const uint32 IMxx_tags[] = {
|
2001-10-09 14:30:12 +00:00
|
|
|
MKID('IM00'),
|
|
|
|
MKID('IM01'),
|
|
|
|
MKID('IM02'),
|
|
|
|
MKID('IM03'),
|
|
|
|
MKID('IM04'),
|
|
|
|
MKID('IM05'),
|
|
|
|
MKID('IM06'),
|
|
|
|
MKID('IM07'),
|
|
|
|
MKID('IM08'),
|
|
|
|
MKID('IM09'),
|
|
|
|
MKID('IM0A'),
|
|
|
|
MKID('IM0B'),
|
|
|
|
MKID('IM0C'),
|
|
|
|
MKID('IM0D'),
|
|
|
|
MKID('IM0E'),
|
|
|
|
MKID('IM0F')
|
|
|
|
};
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawObject(int obj, int arg) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ObjectData *od;
|
|
|
|
int xpos, ypos, height, width;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
int x, a, numstrip;
|
2001-10-26 17:34:50 +00:00
|
|
|
int tmp;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (_BgNeedsRedraw)
|
|
|
|
arg = 0;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
od = &_objs[obj];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-01-12 07:30:17 +00:00
|
|
|
if (od->obj_nr == 0)
|
|
|
|
return;
|
|
|
|
|
2003-01-13 15:27:06 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 0, od->obj_nr, "Object %d out of range in drawObject");
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
xpos = od->x_pos >> 3;
|
2001-10-09 14:30:12 +00:00
|
|
|
ypos = od->y_pos;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
width = od->width >> 3;
|
2003-01-12 13:58:16 +00:00
|
|
|
height = od->height &= 0xFFFFFFF8; // Mask out last 3 bits
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
if (width == 0 || xpos > _screenEndStrip || xpos + width < _screenStartStrip)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (od->fl_object_index) {
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = getResourceAddress(rtFlObject, od->fl_object_index);
|
2002-04-11 17:19:16 +00:00
|
|
|
ptr = findResource(MKID('OBIM'), ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2001-11-05 19:21:49 +00:00
|
|
|
ptr = getResourceAddress(rtRoom, _roomResource);
|
2002-12-26 20:37:49 +00:00
|
|
|
ptr = ptr + od->OBIMoffset;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-04-12 18:43:23 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
ptr += 0;
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2002-04-11 17:19:16 +00:00
|
|
|
ptr += 8;
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 8) {
|
2002-12-31 03:26:02 +00:00
|
|
|
ptr = findResource(MKID('IMAG'), ptr);
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ptr = findResource(MKID('WRAP'), ptr);
|
|
|
|
assert(ptr);
|
|
|
|
ptr = findResource(MKID('OFFS'), ptr);
|
|
|
|
assert(ptr);
|
|
|
|
// Get the address of the specified SMAP (corresponding to IMxx)
|
|
|
|
ptr += READ_LE_UINT32(ptr + 4 + 4*getState(od->obj_nr));
|
|
|
|
} else
|
2002-04-11 17:19:16 +00:00
|
|
|
ptr = findResource(IMxx_tags[getState(od->obj_nr)], ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x = 0xFFFF;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (a = numstrip = 0; a < width; a++) {
|
2001-10-26 17:34:50 +00:00
|
|
|
tmp = xpos + a;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (arg == 1 && _screenStartStrip != tmp)
|
2001-10-09 14:30:12 +00:00
|
|
|
continue;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (arg == 2 && _screenEndStrip != tmp)
|
2001-10-09 14:30:12 +00:00
|
|
|
continue;
|
2001-10-26 17:34:50 +00:00
|
|
|
if (tmp < _screenStartStrip || tmp > _screenEndStrip)
|
2001-10-09 14:30:12 +00:00
|
|
|
continue;
|
2003-01-14 10:06:56 +00:00
|
|
|
setGfxUsageBit(tmp, USAGE_BIT_DIRTY);
|
2001-10-26 17:34:50 +00:00
|
|
|
if (tmp < x)
|
|
|
|
x = tmp;
|
|
|
|
numstrip++;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (numstrip != 0) {
|
2001-11-26 19:57:57 +00:00
|
|
|
byte flags = Gdi::dbAllowMaskOr;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 1) {
|
2003-06-06 05:27:45 +00:00
|
|
|
gdi._C64ObjectMode = true;
|
2003-06-06 07:35:19 +00:00
|
|
|
gdi.decodeC64Gfx(ptr, gdi._C64ObjectMap, width * (height >> 3) * 3);
|
2003-06-06 05:27:45 +00:00
|
|
|
}
|
2003-06-06 07:35:19 +00:00
|
|
|
// Sam & Max needs this to fix object-layering problems with
|
|
|
|
// the inventory and conversation icons.
|
2003-06-07 00:13:26 +00:00
|
|
|
if ((_version >= 7 || _gameId == GID_SAMNMAX) && getClass(od->obj_nr, kObjectClassIgnoreBoxes))
|
2002-09-29 15:20:02 +00:00
|
|
|
flags |= Gdi::dbDrawMaskOnAll;
|
2003-05-10 12:59:32 +00:00
|
|
|
gdi.drawBitmap(ptr, &virtscr[0], x, ypos, width << 3, height, x - xpos, numstrip, flags);
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::clearRoomObjects() {
|
2003-01-26 10:57:01 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
for (i = 0; i < _numLocalObjects; i++) {
|
|
|
|
_objs[i].obj_nr = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// FIXME: Locking/FlObjects stuff?
|
|
|
|
for (i = 0; i < _numLocalObjects; i++) {
|
|
|
|
if (_objs[i].obj_nr < 1) // Optimise codepath
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Nuke all non-flObjects (flObjects are nuked in script.cpp)
|
|
|
|
if (_objs[i].fl_object_index == 0) {
|
|
|
|
_objs[i].obj_nr = 0;
|
|
|
|
} else {
|
|
|
|
// Nuke all unlocked flObjects
|
|
|
|
if (!(res.flags[rtFlObject][_objs[i].fl_object_index] & RF_LOCK)) {
|
|
|
|
nukeResource(rtFlObject, _objs[i].fl_object_index);
|
|
|
|
_objs[i].obj_nr = 0;
|
|
|
|
_objs[i].fl_object_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::loadRoomObjects() {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-10-09 14:30:12 +00:00
|
|
|
ObjectData *od;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
2001-10-09 14:30:12 +00:00
|
|
|
uint16 obim_id;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *room, *searchptr, *rootptr;
|
|
|
|
const ImageHeader *imhd;
|
|
|
|
const RoomHeader *roomhdr;
|
|
|
|
const CodeHeader *cdhd;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-24 15:27:27 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
room = getResourceAddress(rtRoom, _roomResource);
|
2003-05-28 20:01:47 +00:00
|
|
|
roomhdr = (const RoomHeader *)findResourceData(MKID('RMHD'), room);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-25 07:48:37 +00:00
|
|
|
_numObjectsInRoom = (byte)READ_LE_UINT32(&(roomhdr->v8.numObjects));
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 7)
|
2002-03-05 20:13:47 +00:00
|
|
|
_numObjectsInRoom = READ_LE_UINT16(&(roomhdr->v7.numObjects));
|
|
|
|
else
|
|
|
|
_numObjectsInRoom = READ_LE_UINT16(&(roomhdr->old.numObjects));
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_numObjectsInRoom == 0)
|
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_numObjectsInRoom > _numLocalObjects)
|
|
|
|
error("More than %d objects in room %d", _numLocalObjects, _roomResource);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-24 12:49:25 +00:00
|
|
|
searchptr = rootptr = getResourceAddress(rtRoomScripts, _roomResource);
|
2002-12-24 12:09:11 +00:00
|
|
|
else
|
2002-12-24 12:49:25 +00:00
|
|
|
searchptr = rootptr = room;
|
2002-12-27 14:36:28 +00:00
|
|
|
assert(searchptr);
|
2002-12-24 12:09:11 +00:00
|
|
|
|
2003-01-12 07:30:17 +00:00
|
|
|
// Load in new room objects
|
|
|
|
for (i = 0; i < _numObjectsInRoom; i++) {
|
|
|
|
od = &_objs[findLocalObjectSlot()];
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
ptr = findResource(MKID('OBCD'), searchptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Room %d missing object code block(s)", _roomResource);
|
|
|
|
|
2002-12-26 20:37:49 +00:00
|
|
|
od->OBCDoffset = ptr - rootptr;
|
2003-05-28 20:01:47 +00:00
|
|
|
cdhd = (const CodeHeader *)findResourceData(MKID('CDHD'), ptr);
|
2002-03-05 20:43:26 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7)
|
2002-03-05 20:43:26 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v7.obj_id));
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 6)
|
2002-04-11 17:19:16 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
|
2002-03-05 20:43:26 +00:00
|
|
|
else
|
2002-04-11 17:19:16 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-31 02:09:57 +00:00
|
|
|
if (_dumpScripts) {
|
2001-10-09 14:30:12 +00:00
|
|
|
char buf[32];
|
2002-04-11 17:19:16 +00:00
|
|
|
sprintf(buf, "roomobj-%d-", _roomResource);
|
2003-05-04 13:09:42 +00:00
|
|
|
ptr = findResource(MKID('VERB'), ptr, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
dumpResource(buf, od->obj_nr, ptr);
|
2002-12-31 02:09:57 +00:00
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
searchptr = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
searchptr = room;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _numObjectsInRoom; i++) {
|
2001-11-26 19:57:57 +00:00
|
|
|
ptr = findResource(MKID('OBIM'), searchptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Room %d missing image blocks(s)", _roomResource);
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), ptr);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-24 16:10:31 +00:00
|
|
|
// In V8, IMHD has no obj_id, but rather a name string. We map the name
|
|
|
|
// back to an object id using a table derived from the DOBJ resource.
|
|
|
|
obim_id = _objectIDMap[imhd->v8.name];
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 7)
|
2002-03-05 21:03:32 +00:00
|
|
|
obim_id = READ_LE_UINT16(&imhd->v7.obj_id);
|
|
|
|
else
|
|
|
|
obim_id = READ_LE_UINT16(&imhd->old.obj_id);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (j = 1; j < _numLocalObjects; j++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[j].obj_nr == obim_id)
|
2002-12-26 20:37:49 +00:00
|
|
|
_objs[j].OBIMoffset = ptr - room;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
searchptr = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++) {
|
2003-01-12 10:20:09 +00:00
|
|
|
if (_objs[i].obj_nr && !_objs[i].fl_object_index)
|
2003-01-12 07:30:17 +00:00
|
|
|
setupRoomObject(&_objs[i], room);
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-12-24 15:27:27 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-04-12 02:09:00 +00:00
|
|
|
void Scumm::loadRoomObjectsOldBundle() {
|
|
|
|
int i;
|
|
|
|
ObjectData *od;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *room, *ptr;
|
2003-04-12 02:09:00 +00:00
|
|
|
|
|
|
|
CHECK_HEAP
|
|
|
|
room = getResourceAddress(rtRoom, _roomResource);
|
|
|
|
|
|
|
|
_numObjectsInRoom = room[20];
|
|
|
|
|
|
|
|
if (_numObjectsInRoom == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_numObjectsInRoom > _numLocalObjects)
|
|
|
|
error("More than %d objects in room %d", _numLocalObjects, _roomResource);
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 2)
|
2003-04-28 18:19:48 +00:00
|
|
|
ptr = room + 28;
|
|
|
|
else
|
|
|
|
ptr = room + 29;
|
|
|
|
|
2003-04-12 02:09:00 +00:00
|
|
|
for (i = 0; i < _numObjectsInRoom; i++) {
|
|
|
|
od = &_objs[findLocalObjectSlot()];
|
|
|
|
|
|
|
|
od->OBIMoffset = READ_LE_UINT16(ptr);
|
|
|
|
od->OBCDoffset = READ_LE_UINT16(ptr + 2 * _numObjectsInRoom);
|
|
|
|
setupRoomObject(od, room);
|
|
|
|
|
|
|
|
ptr += 2;
|
2003-05-16 21:31:15 +00:00
|
|
|
|
|
|
|
if (_dumpScripts) {
|
|
|
|
char buf[32];
|
|
|
|
sprintf(buf, "roomobj-%d-", _roomResource);
|
|
|
|
dumpResource(buf, od->obj_nr, room + od->OBCDoffset);
|
|
|
|
}
|
2003-04-12 02:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_HEAP
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::loadRoomObjectsSmall() {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
|
|
|
ObjectData *od;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
uint16 obim_id;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *room, *searchptr;
|
|
|
|
const RoomHeader *roomhdr;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-26 21:50:13 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
room = getResourceAddress(rtRoom, _roomResource);
|
2003-05-28 20:01:47 +00:00
|
|
|
roomhdr = (const RoomHeader *)findResourceData(MKID('RMHD'), room);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
_numObjectsInRoom = READ_LE_UINT16(&(roomhdr->old.numObjects));
|
|
|
|
|
|
|
|
if (_numObjectsInRoom == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_numObjectsInRoom > _numLocalObjects)
|
|
|
|
error("More than %d objects in room %d", _numLocalObjects, _roomResource);
|
|
|
|
|
|
|
|
searchptr = room;
|
2003-01-12 07:30:17 +00:00
|
|
|
for (i = 0; i < _numObjectsInRoom; i++) {
|
|
|
|
od = &_objs[findLocalObjectSlot()];
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
ptr = findResourceSmall(MKID('OBCD'), searchptr);
|
|
|
|
if (ptr == NULL)
|
|
|
|
error("Room %d missing object code block(s)", _roomResource);
|
|
|
|
|
2002-12-26 20:37:49 +00:00
|
|
|
od->OBCDoffset = ptr - room;
|
2002-04-11 17:19:16 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(ptr + 6);
|
2002-12-31 02:09:57 +00:00
|
|
|
if (_dumpScripts) {
|
2002-04-11 17:19:16 +00:00
|
|
|
char buf[32];
|
|
|
|
sprintf(buf, "roomobj-%d-", _roomResource);
|
|
|
|
dumpResource(buf, od->obj_nr, ptr);
|
2002-12-31 02:09:57 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
searchptr = NULL;
|
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
searchptr = room;
|
|
|
|
for (i = 0; i < _numObjectsInRoom; i++) {
|
|
|
|
ptr = findResourceSmall(MKID('OBIM'), searchptr);
|
|
|
|
if (ptr == NULL)
|
|
|
|
error("Room %d missing image blocks(s)", _roomResource);
|
|
|
|
|
|
|
|
obim_id = READ_LE_UINT16(ptr + 6);
|
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (j = 1; j < _numLocalObjects; j++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[j].obj_nr == obim_id)
|
2002-12-26 20:37:49 +00:00
|
|
|
_objs[j].OBIMoffset = ptr - room;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
searchptr = NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++) {
|
2003-04-12 02:09:00 +00:00
|
|
|
if (_objs[i].obj_nr && !_objs[i].fl_object_index) {
|
2003-01-12 07:30:17 +00:00
|
|
|
setupRoomObject(&_objs[i], room);
|
2003-04-12 02:09:00 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
2002-12-24 15:27:27 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
void Scumm::setupRoomObject(ObjectData *od, const byte *room, const byte *searchptr) {
|
|
|
|
const CodeHeader *cdhd = NULL;
|
|
|
|
const ImageHeader *imhd = NULL;
|
2002-12-27 14:36:28 +00:00
|
|
|
|
|
|
|
assert(room);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (_features & GF_SMALL_HEADER) {
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr = room + od->OBCDoffset;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-04-12 02:09:00 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
ptr -= 2;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-04-12 02:09:00 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(ptr + 6);
|
|
|
|
|
|
|
|
od->x_pos = *(ptr + 9) << 3;
|
|
|
|
od->y_pos = ((*(ptr + 10)) & 0x7F) << 3;
|
|
|
|
|
2003-05-01 16:05:47 +00:00
|
|
|
od->parentstate = (*(ptr + 10) & 0x80) ? 1 : 0;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 2)
|
2003-05-10 22:12:23 +00:00
|
|
|
od->parentstate <<= 3;
|
2003-04-28 12:38:24 +00:00
|
|
|
|
2003-04-12 02:09:00 +00:00
|
|
|
od->width = *(ptr + 11) << 3;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
od->parent = *(ptr + 12);
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 2) {
|
2003-05-22 15:30:27 +00:00
|
|
|
od->walk_x = *(ptr + 13) * 8;
|
|
|
|
od->walk_y = (*(ptr + 14) & 0x1f) * 8;
|
2003-04-21 11:19:56 +00:00
|
|
|
od->actordir = (*(ptr + 15)) & 7;
|
|
|
|
od->height = *(ptr + 15) & 0xf8;
|
|
|
|
} else {
|
|
|
|
od->walk_x = READ_LE_UINT16(ptr + 13);
|
|
|
|
od->walk_y = READ_LE_UINT16(ptr + 15);
|
|
|
|
od->actordir = (*(ptr + 17)) & 7;
|
|
|
|
od->height = *(ptr + 17) & 0xf8;
|
|
|
|
}
|
2003-04-28 12:38:24 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
if (searchptr == NULL) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-27 14:36:28 +00:00
|
|
|
searchptr = getResourceAddress(rtRoomScripts, _roomResource);
|
|
|
|
else
|
|
|
|
searchptr = room;
|
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
cdhd = (const CodeHeader *)findResourceData(MKID('CDHD'), searchptr + od->OBCDoffset);
|
2002-12-24 12:27:35 +00:00
|
|
|
if (cdhd == NULL)
|
|
|
|
error("Room %d missing CDHD blocks(s)", _roomResource);
|
2002-12-24 04:02:21 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2002-12-24 04:02:21 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v7.obj_id));
|
|
|
|
|
|
|
|
od->parent = cdhd->v7.parent;
|
|
|
|
od->parentstate = cdhd->v7.parentstate;
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), room + od->OBIMoffset);
|
2002-12-25 07:48:37 +00:00
|
|
|
od->x_pos = (int)READ_LE_UINT32(&imhd->v8.x_pos);
|
|
|
|
od->y_pos = (int)READ_LE_UINT32(&imhd->v8.y_pos);
|
|
|
|
od->width = (uint)READ_LE_UINT32(&imhd->v8.width);
|
|
|
|
od->height = (uint)READ_LE_UINT32(&imhd->v8.height);
|
2003-03-02 15:51:56 +00:00
|
|
|
// HACK: This is done sinec an angle doesn't fit into a byte (360 > 256)
|
|
|
|
od->actordir = toSimpleDir(1, READ_LE_UINT32(&imhd->v8.actordir));
|
2002-12-24 04:02:21 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 7) {
|
2002-03-05 20:43:26 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v7.obj_id));
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-03-05 23:05:55 +00:00
|
|
|
od->parent = cdhd->v7.parent;
|
|
|
|
od->parentstate = cdhd->v7.parentstate;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), room + od->OBIMoffset);
|
2002-03-16 18:58:51 +00:00
|
|
|
od->x_pos = READ_LE_UINT16(&imhd->v7.x_pos);
|
|
|
|
od->y_pos = READ_LE_UINT16(&imhd->v7.y_pos);
|
2002-04-11 17:19:16 +00:00
|
|
|
od->width = READ_LE_UINT16(&imhd->v7.width);
|
2002-03-16 18:58:51 +00:00
|
|
|
od->height = READ_LE_UINT16(&imhd->v7.height);
|
|
|
|
od->actordir = READ_LE_UINT16(&imhd->v7.actordir);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 6) {
|
2002-12-24 04:02:21 +00:00
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
|
|
|
|
|
|
|
|
od->width = READ_LE_UINT16(&cdhd->v6.w);
|
|
|
|
od->height = READ_LE_UINT16(&cdhd->v6.h);
|
|
|
|
od->x_pos = ((int16)READ_LE_UINT16(&cdhd->v6.x));
|
|
|
|
od->y_pos = ((int16)READ_LE_UINT16(&cdhd->v6.y));
|
|
|
|
if (cdhd->v6.flags == 0x80) {
|
|
|
|
od->parentstate = 1;
|
|
|
|
} else {
|
|
|
|
od->parentstate = (cdhd->v6.flags & 0xF);
|
|
|
|
}
|
|
|
|
od->parent = cdhd->v6.parent;
|
|
|
|
od->actordir = cdhd->v6.actordir;
|
|
|
|
} else {
|
|
|
|
od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
|
|
|
|
|
|
|
|
od->width = cdhd->v5.w << 3;
|
|
|
|
od->height = cdhd->v5.h << 3;
|
|
|
|
od->x_pos = cdhd->v5.x << 3;
|
|
|
|
od->y_pos = cdhd->v5.y << 3;
|
|
|
|
if (cdhd->v5.flags == 0x80) {
|
|
|
|
od->parentstate = 1;
|
|
|
|
} else {
|
|
|
|
od->parentstate = (cdhd->v5.flags & 0xF);
|
|
|
|
}
|
|
|
|
od->parent = cdhd->v5.parent;
|
|
|
|
od->walk_x = READ_LE_UINT16(&cdhd->v5.walk_x);
|
|
|
|
od->walk_y = READ_LE_UINT16(&cdhd->v5.walk_y);
|
|
|
|
od->actordir = cdhd->v5.actordir;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2002-12-24 04:02:21 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
od->fl_object_index = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::fixObjectFlags() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2001-10-16 10:01:48 +00:00
|
|
|
ObjectData *od = &_objs[1];
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++, od++) {
|
2003-01-12 07:30:17 +00:00
|
|
|
if (od->obj_nr > 0)
|
2003-06-16 14:45:23 +00:00
|
|
|
od->state = getState(od->obj_nr);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::processDrawQue() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i, j;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _drawObjectQueNr; i++) {
|
2001-10-09 14:30:12 +00:00
|
|
|
j = _drawObjectQue[i];
|
|
|
|
if (j)
|
2002-04-11 17:19:16 +00:00
|
|
|
drawObject(j, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
_drawObjectQueNr = 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::clearOwnerOf(int obj) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
|
|
|
uint16 *a;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
stopObjectScript(obj);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (getOwner(obj) == OF_OWNER_ROOM) {
|
2001-10-09 14:30:12 +00:00
|
|
|
i = 0;
|
|
|
|
do {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[i].obj_nr == obj) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (!_objs[i].fl_object_index)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2001-11-05 19:21:49 +00:00
|
|
|
nukeResource(rtFlObject, _objs[i].fl_object_index);
|
2001-10-16 10:01:48 +00:00
|
|
|
_objs[i].obj_nr = 0;
|
|
|
|
_objs[i].fl_object_index = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-01-12 08:32:44 +00:00
|
|
|
} while (++i < _numLocalObjects);
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < _maxInventoryItems; i++) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_inventory[i] == obj) {
|
|
|
|
j = whereIsObject(obj);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (j == WIO_INVENTORY) {
|
2001-11-05 19:21:49 +00:00
|
|
|
nukeResource(rtInventory, i);
|
2001-10-09 14:30:12 +00:00
|
|
|
_inventory[i] = 0;
|
|
|
|
}
|
2001-10-26 17:34:50 +00:00
|
|
|
a = &_inventory[1];
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < _maxInventoryItems - 1; i++, a++) {
|
2001-10-26 17:34:50 +00:00
|
|
|
if (!a[0] && a[1]) {
|
|
|
|
a[0] = a[1];
|
|
|
|
a[1] = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
_baseInventoryItems[i] = _baseInventoryItems[i + 1];
|
|
|
|
_baseInventoryItems[i + 1] = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::removeObjectFromRoom(int obj) {
|
2003-01-17 15:23:27 +00:00
|
|
|
int i, j, strip;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[i].obj_nr == (uint16)obj) {
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_objs[i].width != 0) {
|
2003-03-05 11:39:27 +00:00
|
|
|
for (j = 0; j < _objs[i].width >> 3; j++) {
|
2003-01-17 15:23:27 +00:00
|
|
|
strip = (_objs[i].x_pos >> 3) + j;
|
|
|
|
|
|
|
|
// Clip value
|
|
|
|
if (strip < _screenStartStrip)
|
|
|
|
continue;
|
|
|
|
if (strip > _screenEndStrip)
|
|
|
|
break;
|
|
|
|
|
|
|
|
setGfxUsageBit(strip, USAGE_BIT_DIRTY);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
_BgNeedsRedraw = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::addObjectToDrawQue(int object) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_drawObjectQue[_drawObjectQueNr++] = object;
|
2003-05-18 21:03:57 +00:00
|
|
|
if ((unsigned int)_drawObjectQueNr > ARRAYSIZE(_drawObjectQue))
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Draw Object Que overflow");
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::clearDrawObjectQueue() {
|
2001-10-09 14:30:12 +00:00
|
|
|
_drawObjectQueNr = 0;
|
|
|
|
}
|
|
|
|
|
2003-05-31 12:17:58 +00:00
|
|
|
const byte *Scumm::getObjOrActorName(int obj) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *objptr;
|
2002-06-25 02:04:43 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
if (obj < _numActors)
|
2003-05-23 13:24:41 +00:00
|
|
|
return derefActor(obj, "getObjOrActorName")->getActorName();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 6) {
|
2003-05-28 20:01:47 +00:00
|
|
|
for (i = 0; i < _numNewNames; i++) {
|
2002-06-25 02:04:43 +00:00
|
|
|
if (_newNames[i] == obj) {
|
2003-06-14 08:58:56 +00:00
|
|
|
debug(5, "Found new name for object %d at _newNames[%d]", obj, i);
|
2002-06-25 02:04:43 +00:00
|
|
|
return getResourceAddress(rtObjectName, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
objptr = getOBCDFromObject(obj);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (objptr == NULL)
|
2003-05-21 18:09:49 +00:00
|
|
|
return NULL;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-31 11:57:18 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
byte offset = 0;
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 2)
|
2003-05-31 11:57:18 +00:00
|
|
|
offset = *(objptr + 14);
|
|
|
|
else if (_features & GF_OLD_BUNDLE)
|
|
|
|
offset = *(objptr + 16);
|
|
|
|
else
|
|
|
|
offset = READ_LE_UINT16(objptr + 18);
|
|
|
|
|
|
|
|
return (objptr + offset);
|
|
|
|
}
|
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
return findResourceData(MKID('OBNA'), objptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
uint32 Scumm::getOBCDOffs(int object) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_objectOwnerTable[object] != OF_OWNER_ROOM)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = (_numLocalObjects-1); i > 0; i--) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_objs[i].obj_nr == object) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[i].fl_object_index != 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 8;
|
2002-12-26 20:37:49 +00:00
|
|
|
return _objs[i].OBCDoffset;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *Scumm::getOBCDFromObject(int obj) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_objectOwnerTable[obj] != OF_OWNER_ROOM) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _maxInventoryItems; i++) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_inventory[i] == obj)
|
2001-11-05 19:21:49 +00:00
|
|
|
return getResourceAddress(rtInventory, i);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = (_numLocalObjects-1); i > 0; --i) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_objs[i].obj_nr == obj) {
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_objs[i].fl_object_index)
|
2002-04-11 17:19:16 +00:00
|
|
|
return getResourceAddress(rtFlObject, _objs[i].fl_object_index) + 8;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-26 20:37:49 +00:00
|
|
|
return getResourceAddress(rtRoomScripts, _roomResource) + _objs[i].OBCDoffset;
|
|
|
|
else
|
|
|
|
return getResourceAddress(rtRoom, _roomResource) + _objs[i].OBCDoffset;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::addObjectToInventory(uint obj, uint room) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i, slot;
|
2001-11-26 19:57:57 +00:00
|
|
|
uint32 size;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
|
|
|
byte *dst;
|
2001-11-26 19:57:57 +00:00
|
|
|
FindObjectInRoom foir;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
debug(1, "Adding object %d from room %d into inventory", obj, room);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-26 21:50:13 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
if (whereIsObject(obj) == WIO_FLOBJECT) {
|
2001-10-09 14:30:12 +00:00
|
|
|
i = getObjectIndex(obj);
|
2001-12-27 17:51:58 +00:00
|
|
|
ptr = getResourceAddress(rtFlObject, _objs[i].fl_object_index) + 8;
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(ptr + 4);
|
2001-11-26 19:57:57 +00:00
|
|
|
} else {
|
|
|
|
findObjectInRoom(&foir, foCodeHeader, obj, room);
|
2003-04-13 16:21:41 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
size = READ_LE_UINT16(foir.obcd);
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2002-04-11 17:19:16 +00:00
|
|
|
size = READ_LE_UINT32(foir.obcd);
|
|
|
|
else
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(foir.obcd + 4);
|
2002-12-27 19:48:30 +00:00
|
|
|
ptr = foir.obcd;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2002-12-27 19:48:30 +00:00
|
|
|
slot = getInventorySlot();
|
|
|
|
_inventory[slot] = obj;
|
2003-05-26 14:44:03 +00:00
|
|
|
dst = createResource(rtInventory, slot, size);
|
2002-12-27 19:48:30 +00:00
|
|
|
assert(dst);
|
|
|
|
memcpy(dst, ptr, size);
|
|
|
|
|
2002-12-24 04:02:21 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, uint room) {
|
2003-04-12 12:58:20 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const CodeHeader *cdhd;
|
2001-11-26 19:57:57 +00:00
|
|
|
int i, numobj;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *roomptr, *obcdptr, *obimptr, *searchptr;
|
|
|
|
const ImageHeader *imhd;
|
2002-03-05 20:43:26 +00:00
|
|
|
int id2;
|
2002-03-05 21:03:32 +00:00
|
|
|
int id3;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (findWhat & foCheckAlreadyLoaded && getObjectIndex(id) != -1) {
|
2003-04-12 12:58:20 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
|
|
|
// I am not sure if this is even needed for old games...
|
2003-05-26 14:44:03 +00:00
|
|
|
// but using RES_SIZE definitely won't work with OLD_BUNDLE, since it
|
2003-04-12 12:58:20 +00:00
|
|
|
// assumes the size is 32 bit but in old games it's 16 bit
|
|
|
|
error("findObjectInRoom foCheckAlreadyLoaded NYI for GF_OLD_BUNDLE (id = %d, room = %d)", id, room);
|
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
fo->obcd = obcdptr = getOBCDFromObject(id);
|
2003-05-28 20:01:47 +00:00
|
|
|
assert((const byte *)obcdptr > (byte *)256);
|
2002-07-16 21:03:14 +00:00
|
|
|
fo->obim = obimptr = obcdptr + RES_SIZE(obcdptr);
|
2003-05-28 20:01:47 +00:00
|
|
|
fo->cdhd = (const CodeHeader *)findResourceData(MKID('CDHD'), obcdptr);
|
|
|
|
fo->imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), obimptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
|
|
|
fo->roomptr = roomptr = getResourceAddress(rtRoom, room);
|
2002-04-19 16:26:44 +00:00
|
|
|
if (!roomptr)
|
|
|
|
error("findObjectInRoom: failed getting roomptr to %d", room);
|
|
|
|
|
2003-04-12 12:58:20 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
|
|
|
numobj = roomptr[20];
|
|
|
|
} else {
|
2003-05-28 20:01:47 +00:00
|
|
|
const RoomHeader *roomhdr = (const RoomHeader *)findResourceData(MKID('RMHD'), roomptr);
|
2003-04-12 12:58:20 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2003-04-12 12:58:20 +00:00
|
|
|
numobj = READ_LE_UINT32(&(roomhdr->v8.numObjects));
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 7)
|
2003-04-12 12:58:20 +00:00
|
|
|
numobj = READ_LE_UINT16(&(roomhdr->v7.numObjects));
|
|
|
|
else
|
|
|
|
numobj = READ_LE_UINT16(&(roomhdr->old.numObjects));
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (numobj == 0)
|
2001-11-26 19:57:57 +00:00
|
|
|
error("findObjectInRoom: No object found in room %d", room);
|
2001-11-06 21:41:56 +00:00
|
|
|
if (numobj > _numLocalObjects)
|
2002-07-07 20:25:23 +00:00
|
|
|
error("findObjectInRoom: More (%d) than %d objects in room %d", numobj, _numLocalObjects, room);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-04-12 12:58:20 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 2)
|
2003-04-28 18:19:48 +00:00
|
|
|
searchptr = roomptr + 28;
|
|
|
|
else
|
|
|
|
searchptr = roomptr + 29;
|
|
|
|
|
2003-04-12 12:58:20 +00:00
|
|
|
for (i = 0; i < numobj; i++) {
|
|
|
|
obimptr = roomptr + READ_LE_UINT16(searchptr);
|
|
|
|
obcdptr = roomptr + READ_LE_UINT16(searchptr + 2 * _numObjectsInRoom);
|
|
|
|
id2 = READ_LE_UINT16(obcdptr + 4);
|
|
|
|
|
|
|
|
if (id2 == (uint16)id) {
|
|
|
|
if (findWhat & foCodeHeader) {
|
|
|
|
fo->obcd = obcdptr;
|
2003-05-28 20:01:47 +00:00
|
|
|
fo->cdhd = (const CodeHeader *)(obcdptr + 10); // TODO - FIXME
|
2003-04-12 12:58:20 +00:00
|
|
|
}
|
|
|
|
if (findWhat & foImageHeader) {
|
|
|
|
fo->obim = obimptr;
|
2003-04-13 21:47:48 +00:00
|
|
|
fo->imhd = NULL;
|
2003-04-12 12:58:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-04-13 21:47:48 +00:00
|
|
|
searchptr += 2;
|
2003-04-12 12:58:20 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (findWhat & foCodeHeader) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2003-01-12 21:46:58 +00:00
|
|
|
searchptr = getResourceAddress(rtRoomScripts, room);
|
|
|
|
else
|
|
|
|
searchptr = roomptr;
|
2002-12-27 14:36:28 +00:00
|
|
|
assert(searchptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0;;) {
|
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
obcdptr = findResourceSmall(MKID('OBCD'), searchptr);
|
|
|
|
else
|
|
|
|
obcdptr = findResource(MKID('OBCD'), searchptr);
|
|
|
|
if (obcdptr == NULL)
|
2001-11-26 19:57:57 +00:00
|
|
|
error("findObjectInRoom: Not enough code blocks in room %d", room);
|
2003-05-28 20:01:47 +00:00
|
|
|
cdhd = (const CodeHeader *)findResourceData(MKID('CDHD'), obcdptr);
|
2002-12-25 11:59:55 +00:00
|
|
|
|
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
id2 = READ_LE_UINT16(obcdptr + 6);
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version >= 7)
|
2002-12-25 11:59:55 +00:00
|
|
|
id2 = READ_LE_UINT16(&(cdhd->v7.obj_id));
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 6)
|
2002-12-25 11:59:55 +00:00
|
|
|
id2 = READ_LE_UINT16(&(cdhd->v6.obj_id));
|
|
|
|
else
|
|
|
|
id2 = READ_LE_UINT16(&(cdhd->v5.obj_id));
|
|
|
|
|
|
|
|
if (id2 == (uint16)id) {
|
|
|
|
fo->obcd = obcdptr;
|
2003-04-12 12:58:20 +00:00
|
|
|
fo->cdhd = cdhd;
|
2002-12-25 11:59:55 +00:00
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
if (++i == numobj)
|
|
|
|
error("findObjectInRoom: Object %d not found in room %d", id, room);
|
|
|
|
searchptr = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-25 03:48:27 +00:00
|
|
|
roomptr = fo->roomptr;
|
2001-11-26 19:57:57 +00:00
|
|
|
if (findWhat & foImageHeader) {
|
|
|
|
searchptr = roomptr;
|
2002-12-27 14:36:28 +00:00
|
|
|
assert(searchptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0;;) {
|
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
obimptr = findResourceSmall(MKID('OBIM'), searchptr);
|
|
|
|
else
|
|
|
|
obimptr = findResource(MKID('OBIM'), searchptr);
|
|
|
|
if (obimptr == NULL)
|
2001-11-26 19:57:57 +00:00
|
|
|
error("findObjectInRoom: Not enough image blocks in room %d", room);
|
2003-05-28 20:01:47 +00:00
|
|
|
imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), obimptr);
|
2002-12-25 11:59:55 +00:00
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
id3 = READ_LE_UINT16(obimptr + 6);
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 8)
|
2002-12-25 11:59:55 +00:00
|
|
|
// In V8, IMHD has no obj_id, but rather a name string. We map the name
|
|
|
|
// back to an object id using a table derived from the DOBJ resource.
|
|
|
|
id3 = _objectIDMap[imhd->v8.name];
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_version == 7)
|
2002-12-25 11:59:55 +00:00
|
|
|
id3 = READ_LE_UINT16(&imhd->v7.obj_id);
|
|
|
|
else
|
|
|
|
id3 = READ_LE_UINT16(&imhd->old.obj_id);
|
|
|
|
|
|
|
|
if (id3 == (uint16)id) {
|
|
|
|
fo->obim = obimptr;
|
|
|
|
fo->imhd = imhd;
|
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
if (++i == numobj)
|
2002-07-07 20:25:23 +00:00
|
|
|
error("findObjectInRoom: Object %d image not found in room %d", id, room);
|
2001-11-26 19:57:57 +00:00
|
|
|
searchptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getInventorySlot() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i <= _maxInventoryItems; i++) {
|
|
|
|
if (_inventory[i] == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
error("Inventory full, %d max items", _maxInventoryItems);
|
2002-05-05 18:10:29 +00:00
|
|
|
return -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::SamInventoryHack(int obj) {
|
|
|
|
// FIXME: Sam and Max hack
|
2002-03-05 09:24:42 +00:00
|
|
|
int base = 6;
|
|
|
|
|
|
|
|
while (base < 80) {
|
|
|
|
int value = readArray(178, 0, base);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (value == obj)
|
|
|
|
return;
|
2002-03-05 09:24:42 +00:00
|
|
|
if (value == 0) {
|
2003-05-08 15:48:50 +00:00
|
|
|
_scummVars[179]++;
|
2002-04-11 17:19:16 +00:00
|
|
|
writeArray(178, 0, base, obj);
|
|
|
|
return;
|
2002-03-05 09:24:42 +00:00
|
|
|
}
|
|
|
|
base++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setOwnerOf(int obj, int owner) {
|
2001-10-16 10:01:48 +00:00
|
|
|
ScriptSlot *ss;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (owner == 0) {
|
2001-10-16 10:01:48 +00:00
|
|
|
clearOwnerOf(obj);
|
|
|
|
ss = &vm.slot[_currentScript];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ss->where == WIO_INVENTORY && _inventory[ss->number] == obj) {
|
2001-10-16 10:01:48 +00:00
|
|
|
putOwner(obj, 0);
|
2003-06-14 12:23:30 +00:00
|
|
|
runInventoryScript(0);
|
2001-10-16 10:01:48 +00:00
|
|
|
stopObjectCode();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-03-05 09:24:42 +00:00
|
|
|
if ((owner == 2) && (_gameId == GID_SAMNMAX))
|
|
|
|
SamInventoryHack(obj);
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
putOwner(obj, owner);
|
2003-06-14 12:23:30 +00:00
|
|
|
runInventoryScript(0);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjX(int obj) {
|
2003-05-13 23:42:41 +00:00
|
|
|
if (obj < _numActors) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (obj < 1)
|
|
|
|
return 0; /* fix for indy4's map */
|
2003-05-23 13:24:41 +00:00
|
|
|
return derefActor(obj, "getObjX")->x;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (whereIsObject(obj) == WIO_NOT_FOUND)
|
2001-10-16 10:01:48 +00:00
|
|
|
return -1;
|
2002-07-16 18:51:27 +00:00
|
|
|
int x, y;
|
|
|
|
getObjectOrActorXY(obj, x, y);
|
|
|
|
return x;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjY(int obj) {
|
2003-05-13 23:42:41 +00:00
|
|
|
if (obj < _numActors) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (obj < 1)
|
|
|
|
return 0; /* fix for indy4's map */
|
2003-05-23 13:24:41 +00:00
|
|
|
return derefActor(obj, "getObjY")->y;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (whereIsObject(obj) == WIO_NOT_FOUND)
|
2001-10-16 10:01:48 +00:00
|
|
|
return -1;
|
2002-07-16 18:51:27 +00:00
|
|
|
int x, y;
|
|
|
|
getObjectOrActorXY(obj, x, y);
|
|
|
|
return y;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjOldDir(int obj) {
|
2003-03-08 00:56:43 +00:00
|
|
|
return newDirToOldDir(getObjNewDir(obj));
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getObjNewDir(int obj) {
|
2003-03-08 00:24:23 +00:00
|
|
|
int dir;
|
2003-05-13 23:42:41 +00:00
|
|
|
if (obj < _numActors) {
|
2003-05-23 13:24:41 +00:00
|
|
|
dir = derefActor(obj, "getObjNewDir")->facing;
|
2001-12-27 17:51:58 +00:00
|
|
|
} else {
|
2003-03-08 00:24:23 +00:00
|
|
|
int x, y;
|
2002-07-16 18:51:27 +00:00
|
|
|
getObjectXYPos(obj, x, y, dir);
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
2003-03-08 00:24:23 +00:00
|
|
|
return dir;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::findInventory(int owner, int idx) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int count = 1, i, obj;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i != _maxInventoryItems; i++) {
|
2001-10-16 10:01:48 +00:00
|
|
|
obj = _inventory[i];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (obj && getOwner(obj) == owner && count++ == idx)
|
2001-10-16 10:01:48 +00:00
|
|
|
return obj;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
return 0;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getInventoryCount(int owner) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, obj;
|
2001-10-16 10:01:48 +00:00
|
|
|
int count = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i != _maxInventoryItems; i++) {
|
2001-10-16 10:01:48 +00:00
|
|
|
obj = _inventory[i];
|
|
|
|
if (obj && getOwner(obj) == owner)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setObjectState(int obj, int state, int x, int y) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
i = getObjectIndex(obj);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (i == -1) {
|
2003-05-24 16:02:07 +00:00
|
|
|
warning("setObjectState: no such object %d", obj);
|
2001-10-16 10:01:48 +00:00
|
|
|
return;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
if (x != -1) {
|
2002-04-11 17:19:16 +00:00
|
|
|
_objs[i].x_pos = x << 3;
|
|
|
|
_objs[i].y_pos = y << 3;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addObjectToDrawQue(i);
|
|
|
|
putState(obj, state);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
static int getDist(int x, int y, int x2, int y2) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int a = abs(y - y2);
|
|
|
|
int b = abs(x - x2);
|
|
|
|
if (a > b)
|
2001-10-16 10:01:48 +00:00
|
|
|
return a;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e, int f) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
|
|
|
int x, y;
|
|
|
|
int x2, y2;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
j = i = 0xFF;
|
|
|
|
|
|
|
|
if (is_obj_1) {
|
2002-07-16 18:51:27 +00:00
|
|
|
if (getObjectOrActorXY(b, x, y) == -1)
|
2001-10-16 10:01:48 +00:00
|
|
|
return -1;
|
2003-05-13 23:42:41 +00:00
|
|
|
if (b < _numActors)
|
2003-05-23 13:24:41 +00:00
|
|
|
i = derefActor(b, "unkObjProc1")->scalex;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
|
|
|
x = b;
|
|
|
|
y = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_obj_2) {
|
2002-07-16 18:51:27 +00:00
|
|
|
if (getObjectOrActorXY(e, x2, y2) == -1)
|
2001-10-16 10:01:48 +00:00
|
|
|
return -1;
|
2003-05-13 23:42:41 +00:00
|
|
|
if (e < _numActors)
|
2003-05-23 13:24:41 +00:00
|
|
|
j = derefActor(e, "unkObjProc1(2)")->scalex;
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
|
|
|
x2 = e;
|
|
|
|
y2 = f;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
return getDist(x, y, x2, y2) * 0xFF / ((i + j) >> 1);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setCursorImg(uint img, uint room, uint imgindex) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int w, h;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *dataptr, *bomp;
|
2001-11-06 20:00:47 +00:00
|
|
|
uint32 size;
|
2001-11-26 19:57:57 +00:00
|
|
|
FindObjectInRoom foir;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (room == (uint) - 1)
|
2001-11-26 19:57:57 +00:00
|
|
|
room = getObjectRoom(img);
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
findObjectInRoom(&foir, foCodeHeader | foImageHeader | foCheckAlreadyLoaded, img, room);
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2003-04-26 13:28:34 +00:00
|
|
|
setCursorHotspot(READ_LE_UINT32(&foir.imhd->v8.hotspot[0].x),
|
2002-12-24 04:02:21 +00:00
|
|
|
READ_LE_UINT32(&foir.imhd->v8.hotspot[0].y));
|
|
|
|
w = READ_LE_UINT32(&foir.imhd->v8.width) >> 3;
|
|
|
|
h = READ_LE_UINT32(&foir.imhd->v8.height) >> 3;
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 7) {
|
2003-04-26 13:28:34 +00:00
|
|
|
setCursorHotspot(READ_LE_UINT16(&foir.imhd->v7.hotspot[0].x),
|
2002-12-24 04:02:21 +00:00
|
|
|
READ_LE_UINT16(&foir.imhd->v7.hotspot[0].y));
|
|
|
|
w = READ_LE_UINT16(&foir.imhd->v7.width) >> 3;
|
|
|
|
h = READ_LE_UINT16(&foir.imhd->v7.height) >> 3;
|
|
|
|
} else {
|
2003-04-26 13:28:34 +00:00
|
|
|
setCursorHotspot(READ_LE_UINT16(&foir.imhd->old.hotspot[0].x),
|
2002-12-24 04:02:21 +00:00
|
|
|
READ_LE_UINT16(&foir.imhd->old.hotspot[0].y));
|
2002-04-11 17:19:16 +00:00
|
|
|
w = READ_LE_UINT16(&foir.cdhd->v6.w) >> 3;
|
|
|
|
h = READ_LE_UINT16(&foir.cdhd->v6.h) >> 3;
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-12-25 03:48:27 +00:00
|
|
|
// TODO - for V8 don't use IMxx_tags. Rather, we do something similiar to the V8
|
|
|
|
// code in drawBlastObject. It would be *much* nicer if we could aggregate this
|
|
|
|
// common code into some helper functions, instead of having long convuluted
|
|
|
|
// cases scattered all over the place.
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2002-12-25 03:48:27 +00:00
|
|
|
dataptr = findResource(MKID('IMAG'), foir.obim);
|
|
|
|
assert(dataptr);
|
|
|
|
dataptr = findResource(MKID('WRAP'), dataptr);
|
|
|
|
assert(dataptr);
|
|
|
|
dataptr = findResource(MKID('OFFS'), dataptr);
|
|
|
|
assert(dataptr);
|
|
|
|
dataptr += READ_LE_UINT32(dataptr + 4 + 4*imgindex);
|
|
|
|
// TODO - distinguish between SMAP and BOMP here?
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-12-25 03:48:27 +00:00
|
|
|
// HACK - adjust dataptr here until bomp code gets adjusted for V8
|
2002-12-25 12:41:41 +00:00
|
|
|
bomp = dataptr;
|
2002-12-25 03:48:27 +00:00
|
|
|
} else {
|
|
|
|
dataptr = findResource(IMxx_tags[imgindex], foir.obim);
|
|
|
|
if (dataptr == NULL)
|
|
|
|
error("setCursorImg: No such image");
|
|
|
|
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(dataptr + 4);
|
2002-12-25 03:48:27 +00:00
|
|
|
if (size > sizeof(_grabbedCursor))
|
|
|
|
error("setCursorImg: Cursor image too large");
|
|
|
|
|
|
|
|
bomp = findResource(MKID('BOMP'), dataptr);
|
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-12-25 03:48:27 +00:00
|
|
|
if (bomp != NULL)
|
2001-11-06 20:00:47 +00:00
|
|
|
useBompCursor(bomp, w, h);
|
|
|
|
else
|
|
|
|
useIm01Cursor(dataptr, w, h);
|
|
|
|
|
|
|
|
}
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::nukeFlObjects(int min, int max) {
|
2001-11-11 16:54:45 +00:00
|
|
|
ObjectData *od;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
warning("nukeFlObjects(%d,%d)", min, max);
|
|
|
|
|
2003-01-12 08:32:44 +00:00
|
|
|
for (i = (_numLocalObjects-1), od = _objs; --i >= 0; od++)
|
2002-04-11 17:19:16 +00:00
|
|
|
if (od->fl_object_index && od->obj_nr >= min && od->obj_nr <= max) {
|
2001-11-11 16:54:45 +00:00
|
|
|
nukeResource(rtFlObject, od->fl_object_index);
|
|
|
|
od->obj_nr = 0;
|
|
|
|
od->fl_object_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
void Scumm::enqueueObject(int objectNumber, int objectX, int objectY, int objectWidth,
|
2003-05-15 17:57:52 +00:00
|
|
|
int objectHeight, int scaleX, int scaleY, int image, int mode) {
|
2002-04-21 21:20:32 +00:00
|
|
|
BlastObject *eo;
|
2001-11-11 16:54:45 +00:00
|
|
|
ObjectData *od;
|
|
|
|
|
2003-05-15 17:57:52 +00:00
|
|
|
if (_blastObjectQueuePos >= (int)ARRAYSIZE(_blastObjectQueue)) {
|
2002-10-23 03:28:06 +00:00
|
|
|
warning("enqueueObject: overflow");
|
|
|
|
return;
|
|
|
|
}
|
2003-05-15 17:57:52 +00:00
|
|
|
|
|
|
|
int idx = getObjectIndex(objectNumber);
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2003-01-16 00:40:19 +00:00
|
|
|
eo = &_blastObjectQueue[_blastObjectQueuePos++];
|
2002-04-22 13:55:28 +00:00
|
|
|
eo->number = objectNumber;
|
2002-05-20 16:02:29 +00:00
|
|
|
eo->posX = objectX + (camera._cur.x & 7);
|
2003-05-10 21:49:59 +00:00
|
|
|
eo->posY = objectY + (camera._cur.y - (_screenHeight / 2));
|
2002-04-21 21:20:32 +00:00
|
|
|
if (objectWidth == 0) {
|
2003-05-15 17:57:52 +00:00
|
|
|
od = &_objs[idx];
|
2001-11-26 19:57:57 +00:00
|
|
|
eo->width = od->width;
|
2001-11-11 16:54:45 +00:00
|
|
|
} else {
|
2002-04-21 21:20:32 +00:00
|
|
|
eo->width = objectWidth;
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
2002-04-21 21:20:32 +00:00
|
|
|
if (objectHeight == 0) {
|
2003-05-15 17:57:52 +00:00
|
|
|
od = &_objs[idx];
|
2001-11-26 19:57:57 +00:00
|
|
|
eo->height = od->height;
|
2001-11-11 16:54:45 +00:00
|
|
|
} else {
|
2002-04-21 21:20:32 +00:00
|
|
|
eo->height = objectHeight;
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
2002-11-06 15:29:49 +00:00
|
|
|
eo->scaleX = scaleX;
|
|
|
|
eo->scaleY = scaleY;
|
2002-04-22 13:55:28 +00:00
|
|
|
eo->image = image;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-21 21:20:32 +00:00
|
|
|
eo->mode = mode;
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawBlastObjects() {
|
2002-04-21 21:20:32 +00:00
|
|
|
BlastObject *eo;
|
2001-11-11 16:54:45 +00:00
|
|
|
int i;
|
|
|
|
|
2003-01-16 00:40:19 +00:00
|
|
|
eo = _blastObjectQueue;
|
|
|
|
for (i = 0; i < _blastObjectQueuePos; i++, eo++) {
|
2002-04-21 21:20:32 +00:00
|
|
|
drawBlastObject(eo);
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawBlastObject(BlastObject *eo) {
|
2001-11-11 16:54:45 +00:00
|
|
|
VirtScreen *vs;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *bomp, *ptr;
|
2003-01-01 11:25:04 +00:00
|
|
|
int idx, objnum;
|
2001-11-27 17:56:04 +00:00
|
|
|
BompDrawData bdd;
|
|
|
|
|
2001-11-11 16:54:45 +00:00
|
|
|
vs = &virtscr[0];
|
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
checkRange(_numGlobalObjects - 1, 30, eo->number, "Illegal Blast object %d");
|
2002-04-22 13:55:28 +00:00
|
|
|
|
2003-01-01 11:25:04 +00:00
|
|
|
objnum = getObjectIndex(eo->number);
|
|
|
|
if (objnum == -1)
|
|
|
|
error("drawBlastObject: getObjectIndex on BlastObject %d failed", eo->number);
|
2002-04-22 13:55:28 +00:00
|
|
|
|
2003-01-01 11:25:04 +00:00
|
|
|
idx = _objs[objnum].fl_object_index;
|
2002-07-07 20:25:23 +00:00
|
|
|
if (idx) {
|
2002-04-22 13:55:28 +00:00
|
|
|
ptr = getResourceAddress(rtFlObject, idx);
|
2001-11-26 19:57:57 +00:00
|
|
|
ptr = findResource(MKID('OBIM'), ptr);
|
2001-11-11 16:54:45 +00:00
|
|
|
} else {
|
2003-01-01 11:25:04 +00:00
|
|
|
idx = objnum;
|
|
|
|
ptr = getResourceAddress(rtRoom, _roomResource) + _objs[objnum].OBIMoffset;
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
2002-07-07 20:25:23 +00:00
|
|
|
if (!ptr)
|
2002-12-27 14:36:28 +00:00
|
|
|
error("BlastObject object %d (%d) image not found", eo->number, idx);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2002-12-25 03:48:27 +00:00
|
|
|
// The OBIM contains an IMAG, which in turn contains a WRAP, which contains
|
|
|
|
// an OFFS chunk and multiple BOMP chunks. To find the right BOMP, we can
|
|
|
|
// either use the offsets in the OFFS chunk, or iterate over all BOMPs we find.
|
|
|
|
// Here we use the first method.
|
2002-12-31 03:26:02 +00:00
|
|
|
ptr = findResource(MKID('IMAG'), ptr);
|
|
|
|
assert(ptr);
|
|
|
|
ptr = findResource(MKID('WRAP'), ptr);
|
|
|
|
assert(ptr);
|
|
|
|
ptr = findResource(MKID('OFFS'), ptr);
|
|
|
|
assert(ptr);
|
|
|
|
// Get the address of the specified BOMP (we really should verify it's a BOMP and not a SMAP
|
|
|
|
bomp = ptr + READ_LE_UINT32(ptr + 4 + 4*eo->image) + 8;
|
2002-12-25 03:48:27 +00:00
|
|
|
} else {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *img = findResource(IMxx_tags[eo->image], ptr);
|
2002-12-25 03:48:27 +00:00
|
|
|
if (!img)
|
|
|
|
img = findResource(IMxx_tags[1], ptr); // Backward compatibility with samnmax blast objects
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
error("blast-object %d invalid image %d (1-x)", eo->number, eo->image);
|
|
|
|
|
|
|
|
bomp = findResourceData(MKID('BOMP'), img);
|
|
|
|
}
|
2002-04-22 13:55:28 +00:00
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
if (!bomp)
|
|
|
|
error("object %d is not a blast object", eo->number);
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2002-12-25 04:30:24 +00:00
|
|
|
//hexdump(bomp,32);
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2003-05-28 20:01:47 +00:00
|
|
|
bdd.srcwidth = READ_LE_UINT32(&((const BompHeader *)bomp)->v8.width);
|
|
|
|
bdd.srcheight = READ_LE_UINT32(&((const BompHeader *)bomp)->v8.height);
|
2002-12-25 03:48:27 +00:00
|
|
|
} else {
|
2003-05-28 20:01:47 +00:00
|
|
|
bdd.srcwidth = READ_LE_UINT16(&((const BompHeader *)bomp)->old.width);
|
|
|
|
bdd.srcheight = READ_LE_UINT16(&((const BompHeader *)bomp)->old.height);
|
2002-12-25 03:48:27 +00:00
|
|
|
}
|
|
|
|
|
2002-03-20 22:58:41 +00:00
|
|
|
bdd.out = vs->screenPtr + vs->xstart;
|
2002-04-22 16:18:20 +00:00
|
|
|
bdd.outwidth = vs->width;
|
2001-11-27 17:56:04 +00:00
|
|
|
bdd.outheight = vs->height;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2002-12-25 03:48:27 +00:00
|
|
|
bdd.dataptr = bomp + 8; // Why this? See also useBompCursor
|
|
|
|
} else {
|
|
|
|
bdd.dataptr = bomp + 10; // Why this? See also useBompCursor
|
|
|
|
}
|
2002-04-22 13:55:28 +00:00
|
|
|
bdd.x = eo->posX;
|
|
|
|
bdd.y = eo->posY;
|
2002-11-06 07:28:39 +00:00
|
|
|
bdd.scale_x = (byte)eo->scaleX;
|
|
|
|
bdd.scale_y = (byte)eo->scaleY;
|
|
|
|
|
|
|
|
|
|
|
|
if ((bdd.scale_x != 255) || (bdd.scale_y != 255)) {
|
2003-05-30 15:06:29 +00:00
|
|
|
byte bomp_scaling_x[64], bomp_scaling_y[64];
|
|
|
|
bdd.scalingXPtr = bomp_scaling_x;
|
|
|
|
bdd.scalingYPtr = bomp_scaling_y;
|
|
|
|
bdd.scaleRight = setupBompScale(bomp_scaling_x, bdd.srcwidth, bdd.scale_x);
|
|
|
|
bdd.scaleBottom = setupBompScale(bomp_scaling_y, bdd.srcheight, bdd.scale_y);
|
2002-11-06 15:29:49 +00:00
|
|
|
bdd.shadowMode = 0;
|
2003-06-01 13:09:30 +00:00
|
|
|
drawBomp(bdd, false);
|
2003-05-30 15:06:29 +00:00
|
|
|
} else {
|
2003-06-01 13:09:30 +00:00
|
|
|
bdd.scalingXPtr = NULL;
|
|
|
|
bdd.scalingYPtr = NULL;
|
|
|
|
bdd.scaleRight = 0;
|
|
|
|
bdd.scaleBottom = 0;
|
2002-11-06 15:29:49 +00:00
|
|
|
bdd.shadowMode = eo->mode;
|
2003-06-01 13:09:30 +00:00
|
|
|
drawBomp(bdd, false);
|
2002-11-06 07:28:39 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:25:23 +00:00
|
|
|
updateDirtyRect(vs->number, bdd.x, bdd.x + bdd.srcwidth, bdd.y, bdd.y + bdd.srcheight, 0);
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::removeBlastObjects() {
|
2002-04-21 21:20:32 +00:00
|
|
|
BlastObject *eo;
|
2001-11-11 16:54:45 +00:00
|
|
|
int i;
|
|
|
|
|
2003-01-16 00:40:19 +00:00
|
|
|
eo = _blastObjectQueue;
|
|
|
|
for (i = 0; i < _blastObjectQueuePos; i++, eo++) {
|
2002-04-21 21:20:32 +00:00
|
|
|
removeBlastObject(eo);
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clearEnqueue();
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::removeBlastObject(BlastObject *eo) {
|
2002-10-11 11:50:06 +00:00
|
|
|
VirtScreen *vs = &virtscr[0];
|
|
|
|
|
|
|
|
int top, bottom, left, right;
|
|
|
|
int left_strip, right_strip;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
top = eo->posY;
|
|
|
|
bottom = eo->posY + eo->height;
|
|
|
|
left = eo->posX;
|
|
|
|
right = eo->posX + eo->width;
|
|
|
|
|
|
|
|
if (bottom < 0 || right < 0 || top > vs->height || left > vs->width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (top < 0)
|
|
|
|
top = 0;
|
|
|
|
if (bottom > vs->height)
|
|
|
|
bottom = vs->height;
|
|
|
|
if (left < 0)
|
|
|
|
left = 0;
|
|
|
|
if (right > vs->width)
|
|
|
|
right = vs->width;
|
|
|
|
|
|
|
|
left_strip = left >> 3;
|
2003-05-15 17:57:52 +00:00
|
|
|
right_strip = (right - 1) >> 3;
|
2002-10-11 11:50:06 +00:00
|
|
|
|
|
|
|
if (left_strip < 0)
|
|
|
|
left_strip = 0;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
2002-11-06 17:55:44 +00:00
|
|
|
if (right_strip > 409)
|
|
|
|
right_strip = 409;
|
|
|
|
} else {
|
|
|
|
if (right_strip >= 200)
|
|
|
|
right_strip = 200;
|
|
|
|
}
|
2002-10-11 11:50:06 +00:00
|
|
|
for (i = left_strip; i <= right_strip; i++)
|
|
|
|
gdi.resetBackground(top, bottom, i);
|
|
|
|
|
2003-01-14 10:06:56 +00:00
|
|
|
updateDirtyRect(0, left, right, top, bottom, USAGE_BIT_RESTORED);
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::findLocalObjectSlot() {
|
2003-01-12 07:30:17 +00:00
|
|
|
int i;
|
|
|
|
|
2003-01-13 15:06:58 +00:00
|
|
|
for (i = 1; i < _numLocalObjects; i++) {
|
|
|
|
if (!_objs[i].obj_nr)
|
2003-01-12 07:30:17 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::findFlObjectSlot() {
|
2001-11-26 19:57:57 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < _maxFLObject; i++) {
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_baseFLObject[i] == NULL)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
error("findFlObjectSlot: Out of FLObject slots");
|
2002-05-05 18:10:29 +00:00
|
|
|
return -1;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::loadFlObject(uint object, uint room) {
|
2001-11-26 19:57:57 +00:00
|
|
|
FindObjectInRoom foir;
|
2003-01-12 07:30:17 +00:00
|
|
|
int slot, objslot;
|
2001-11-26 19:57:57 +00:00
|
|
|
ObjectData *od;
|
2003-01-12 21:46:58 +00:00
|
|
|
byte *flob;
|
2001-11-26 19:57:57 +00:00
|
|
|
uint32 obcd_size, obim_size, flob_size;
|
2003-01-12 21:53:25 +00:00
|
|
|
bool isRoomLocked, isRoomScriptsLocked;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
// Don't load an already loaded object
|
2001-11-26 19:57:57 +00:00
|
|
|
if (whereIsObject(object) != WIO_NOT_FOUND)
|
|
|
|
return;
|
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
// Locate the object in the room resource
|
2001-11-26 19:57:57 +00:00
|
|
|
findObjectInRoom(&foir, foImageHeader | foCodeHeader, object, room);
|
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
// Add an entry for the new floating object in the local object table
|
2003-01-12 07:30:17 +00:00
|
|
|
if (!(objslot = findLocalObjectSlot()))
|
2001-11-26 19:57:57 +00:00
|
|
|
error("loadFlObject: Local Object Table overflow");
|
2003-01-12 07:30:17 +00:00
|
|
|
|
|
|
|
od = &_objs[objslot];
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-12 13:06:59 +00:00
|
|
|
// Dump object script
|
|
|
|
if (_dumpScripts) {
|
|
|
|
char buf[32];
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr = foir.obcd;
|
2003-01-12 13:06:59 +00:00
|
|
|
sprintf(buf, "roomobj-%d-", room);
|
2003-05-10 18:38:59 +00:00
|
|
|
ptr = findResource(MKID('VERB'), ptr, 0);
|
2003-01-12 13:06:59 +00:00
|
|
|
dumpResource(buf, object, ptr);
|
|
|
|
}
|
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
// Setup sizes
|
2003-06-14 18:52:30 +00:00
|
|
|
obcd_size = READ_BE_UINT32(foir.obcd + 4);
|
2002-12-26 20:37:49 +00:00
|
|
|
od->OBCDoffset = 8;
|
|
|
|
od->OBIMoffset = obcd_size + 8;
|
2003-06-14 18:52:30 +00:00
|
|
|
obim_size = READ_BE_UINT32(foir.obim + 4);
|
2001-11-26 19:57:57 +00:00
|
|
|
flob_size = obcd_size + obim_size + 8;
|
|
|
|
|
2003-01-12 21:46:58 +00:00
|
|
|
// Lock room/roomScripts for the given room. They contains the OBCD/OBIM
|
|
|
|
// data, and a call to createResource might expire them, hence we lock them.
|
2003-01-18 14:16:55 +00:00
|
|
|
isRoomLocked = ((res.flags[rtRoom][room] & RF_LOCK) != 0);
|
|
|
|
isRoomScriptsLocked = ((res.flags[rtRoomScripts][room] & RF_LOCK) != 0);
|
2003-01-12 21:53:25 +00:00
|
|
|
if (!isRoomLocked)
|
|
|
|
lock(rtRoom, room);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8 && !isRoomScriptsLocked)
|
2003-01-12 21:46:58 +00:00
|
|
|
lock(rtRoomScripts, room);
|
2002-12-27 14:36:28 +00:00
|
|
|
|
|
|
|
// Allocate slot & memory for floating object
|
2001-11-26 19:57:57 +00:00
|
|
|
slot = findFlObjectSlot();
|
2003-05-26 14:44:03 +00:00
|
|
|
flob = createResource(rtFlObject, slot, flob_size);
|
2002-12-27 14:36:28 +00:00
|
|
|
assert(flob);
|
|
|
|
|
|
|
|
// Copy object code + object image to floating object
|
2002-04-11 17:19:16 +00:00
|
|
|
((uint32 *)flob)[0] = MKID('FLOB');
|
|
|
|
((uint32 *)flob)[1] = TO_BE_32(flob_size);
|
2002-12-27 14:36:28 +00:00
|
|
|
|
2003-01-12 21:46:58 +00:00
|
|
|
memcpy(flob + 8, foir.obcd, obcd_size);
|
|
|
|
memcpy(flob + 8 + obcd_size, foir.obim, obim_size);
|
|
|
|
|
|
|
|
// Unlock room/roomScripts
|
2003-01-12 21:53:25 +00:00
|
|
|
if (!isRoomLocked)
|
|
|
|
unlock(rtRoom, room);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8 && !isRoomScriptsLocked)
|
2003-01-12 21:46:58 +00:00
|
|
|
unlock(rtRoomScripts, room);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2002-12-27 14:36:28 +00:00
|
|
|
// Setup local object flags
|
|
|
|
setupRoomObject(od, flob, flob);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
|
|
|
od->fl_object_index = slot;
|
|
|
|
}
|