2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-02-22 22:40:53 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-02-22 22:40:53 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/memstream.h"
|
2006-02-25 01:18:01 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
#include "cine/cine.h"
|
2006-02-25 01:18:01 +00:00
|
|
|
#include "cine/object.h"
|
|
|
|
#include "cine/part.h"
|
|
|
|
#include "cine/various.h"
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-02-25 00:26:14 +00:00
|
|
|
namespace Cine {
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/** Resets all elements in the object table. */
|
2008-08-09 20:50:10 +00:00
|
|
|
void resetObjectTable() {
|
2010-08-09 11:38:01 +00:00
|
|
|
for (Common::Array<ObjectStruct>::iterator it = g_cine->_objectTable.begin(); it != g_cine->_objectTable.end(); ++it) {
|
2008-08-09 20:50:10 +00:00
|
|
|
it->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
void loadObject(char *pObjectName) {
|
2011-01-09 22:54:04 +00:00
|
|
|
debug(5, "loadObject(\"%s\")", pObjectName);
|
2006-02-23 09:12:21 +00:00
|
|
|
uint16 numEntry;
|
|
|
|
uint16 entrySize;
|
|
|
|
uint16 i;
|
2007-05-29 21:06:07 +00:00
|
|
|
byte *ptr, *dataPtr;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
|
|
|
checkDataDisk(-1);
|
|
|
|
|
2007-05-29 21:06:07 +00:00
|
|
|
ptr = dataPtr = readBundleFile(findFileInBundle(pObjectName));
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-03-16 20:29:07 +00:00
|
|
|
setMouseCursor(MOUSE_CURSOR_DISK);
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-02-27 21:25:59 +00:00
|
|
|
numEntry = READ_BE_UINT16(ptr); ptr += 2;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-02-27 21:25:59 +00:00
|
|
|
entrySize = READ_BE_UINT16(ptr); ptr += 2;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-03-23 03:17:47 +00:00
|
|
|
assert(numEntry <= NUM_MAX_OBJECT);
|
2006-02-22 22:40:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numEntry; i++) {
|
2011-01-09 22:54:04 +00:00
|
|
|
if (g_cine->_objectTable[i].costume != -2 && g_cine->_objectTable[i].costume != -3) { // flag is keep ?
|
2006-04-05 20:11:00 +00:00
|
|
|
Common::MemoryReadStream readS(ptr, entrySize);
|
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[i].x = readS.readSint16BE();
|
|
|
|
g_cine->_objectTable[i].y = readS.readSint16BE();
|
|
|
|
g_cine->_objectTable[i].mask = readS.readUint16BE();
|
|
|
|
g_cine->_objectTable[i].frame = readS.readSint16BE();
|
|
|
|
g_cine->_objectTable[i].costume = readS.readSint16BE();
|
|
|
|
readS.read(g_cine->_objectTable[i].name, 20);
|
|
|
|
g_cine->_objectTable[i].part = readS.readUint16BE();
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
2006-04-05 20:11:00 +00:00
|
|
|
ptr += entrySize;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(pObjectName, "INTRO.OBJ")) {
|
|
|
|
for (i = 0; i < 10; i++) {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[i].costume = 0;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-29 21:06:07 +00:00
|
|
|
|
|
|
|
free(dataPtr);
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* Remove overlay sprite from the list
|
|
|
|
* @param objIdx Remove overlay associated with this object
|
|
|
|
* @param param Remove overlay of this type
|
2008-04-21 20:51:17 +00:00
|
|
|
*/
|
|
|
|
int removeOverlay(uint16 objIdx, uint16 param) {
|
|
|
|
Common::List<overlay>::iterator it;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) {
|
2008-04-21 20:51:17 +00:00
|
|
|
if (it->objIdx == objIdx && it->type == param) {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_overlayList.erase(it);
|
2008-04-21 20:51:17 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 07:16:14 +00:00
|
|
|
return 0;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* Add new overlay sprite to the list
|
|
|
|
* @param objIdx Associate the overlay with this object
|
|
|
|
* @param type Type of new overlay
|
|
|
|
* @todo Why are x, y, width and color left uninitialized?
|
2008-04-21 20:51:17 +00:00
|
|
|
*/
|
2008-06-26 23:30:45 +00:00
|
|
|
void addOverlay(uint16 objIdx, uint16 type) {
|
2008-04-21 20:51:17 +00:00
|
|
|
Common::List<overlay>::iterator it;
|
|
|
|
overlay tmp;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) {
|
2008-06-26 23:30:45 +00:00
|
|
|
// This is done for both Future Wars and Operation Stealth
|
2010-08-09 11:38:01 +00:00
|
|
|
if (g_cine->_objectTable[it->objIdx].mask >= g_cine->_objectTable[objIdx].mask) {
|
2008-04-21 20:51:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-26 23:30:45 +00:00
|
|
|
|
|
|
|
// There are additional checks in Operation Stealth's implementation
|
|
|
|
if (g_cine->getGameType() == Cine::GType_OS && (it->type == 2 || it->type == 3)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In Operation Stealth's implementation we might bail out early
|
2010-08-09 11:38:01 +00:00
|
|
|
if (g_cine->getGameType() == Cine::GType_OS && it != g_cine->_overlayList.end() && it->objIdx == objIdx && it->type == type) {
|
2008-06-26 23:30:45 +00:00
|
|
|
return;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2008-04-21 20:51:17 +00:00
|
|
|
tmp.objIdx = objIdx;
|
2008-06-26 23:30:45 +00:00
|
|
|
tmp.type = type;
|
2008-07-01 10:33:25 +00:00
|
|
|
tmp.x = 0;
|
|
|
|
tmp.y = 0;
|
|
|
|
tmp.width = 0;
|
|
|
|
tmp.color = 0;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_overlayList.insert(it, tmp);
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* Add new background mask overlay
|
|
|
|
* @param objIdx Associate the overlay with this object
|
|
|
|
* @param param source background index
|
2008-04-21 20:51:17 +00:00
|
|
|
*/
|
2008-06-24 20:44:37 +00:00
|
|
|
void addGfxElement(int16 objIdx, int16 param, int16 type) {
|
2008-04-21 20:51:17 +00:00
|
|
|
Common::List<overlay>::iterator it;
|
|
|
|
overlay tmp;
|
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) {
|
|
|
|
if (g_cine->_objectTable[it->objIdx].mask >= g_cine->_objectTable[objIdx].mask || it->type == 2 || it->type == 3) {
|
2008-04-21 20:51:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
if (it != g_cine->_overlayList.end() && it->objIdx == objIdx && it->type == type && it->x == param) {
|
2008-04-21 20:51:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2008-04-21 20:51:17 +00:00
|
|
|
tmp.objIdx = objIdx;
|
2008-06-24 20:44:37 +00:00
|
|
|
tmp.type = type;
|
2008-04-21 20:51:17 +00:00
|
|
|
tmp.x = param;
|
|
|
|
tmp.y = 0;
|
|
|
|
tmp.width = 0;
|
|
|
|
tmp.color = 0;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_overlayList.insert(it, tmp);
|
2008-04-21 20:51:17 +00:00
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* Remove background mask overlay
|
|
|
|
* @param objIdx Remove overlay associated with this object
|
|
|
|
* @param param Remove overlay using this background
|
|
|
|
* @todo Check that it works
|
2008-04-21 20:51:17 +00:00
|
|
|
*/
|
2008-06-24 20:44:37 +00:00
|
|
|
void removeGfxElement(int16 objIdx, int16 param, int16 type) {
|
2008-04-21 20:51:17 +00:00
|
|
|
Common::List<overlay>::iterator it;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-08-09 11:38:01 +00:00
|
|
|
for (it = g_cine->_overlayList.begin(); it != g_cine->_overlayList.end(); ++it) {
|
2008-06-24 20:44:37 +00:00
|
|
|
if (it->objIdx == objIdx && it->type == type && it->x == param) {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_overlayList.erase(it);
|
2008-04-21 20:51:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 03:45:52 +00:00
|
|
|
void setupObject(byte objIdx, uint16 param1, uint16 param2, uint16 param3, uint16 param4) {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].x = param1;
|
|
|
|
g_cine->_objectTable[objIdx].y = param2;
|
|
|
|
g_cine->_objectTable[objIdx].mask = param3;
|
|
|
|
g_cine->_objectTable[objIdx].frame = param4;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2008-06-30 03:33:08 +00:00
|
|
|
if (g_cine->getGameType() == Cine::GType_OS) {
|
|
|
|
resetGfxEntityEntry(objIdx);
|
|
|
|
} else { // Future Wars
|
|
|
|
if (removeOverlay(objIdx, 0)) {
|
|
|
|
addOverlay(objIdx, 0);
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 03:45:52 +00:00
|
|
|
void subObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
|
2007-12-08 02:24:12 +00:00
|
|
|
addObjectParam(objIdx, paramIdx, -newValue);
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 03:45:52 +00:00
|
|
|
void addObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
|
2007-12-08 02:24:12 +00:00
|
|
|
int16 currentValue = getObjectParam(objIdx, paramIdx);
|
|
|
|
modifyObjectParam(objIdx, paramIdx, currentValue + newValue);
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 03:45:52 +00:00
|
|
|
void modifyObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
|
2008-05-29 22:07:25 +00:00
|
|
|
// Operation Stealth checks object index range, Future Wars doesn't.
|
|
|
|
if (g_cine->getGameType() == Cine::GType_OS && objIdx >= NUM_MAX_OBJECT)
|
|
|
|
return;
|
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
switch (paramIdx) {
|
2008-05-29 12:22:14 +00:00
|
|
|
case 1:
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].x = newValue;
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2008-05-29 12:22:14 +00:00
|
|
|
case 2:
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].y = newValue;
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2008-05-29 12:22:14 +00:00
|
|
|
case 3:
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].mask = newValue;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2008-06-30 03:33:08 +00:00
|
|
|
if (g_cine->getGameType() == Cine::GType_OS) { // Operation Stealth specific
|
|
|
|
resetGfxEntityEntry(objIdx);
|
|
|
|
} else { // Future Wars specific
|
|
|
|
if (removeOverlay(objIdx, 0)) {
|
|
|
|
addOverlay(objIdx, 0);
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2008-05-29 12:22:14 +00:00
|
|
|
case 4:
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].frame = newValue;
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2008-05-29 12:22:14 +00:00
|
|
|
case 5:
|
|
|
|
// TODO: Test if this really breaks the newspaper machine on the airport in Operation Stealth.
|
|
|
|
if (g_cine->getGameType() == Cine::GType_FW && newValue == -1) {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].costume = g_cine->_globalVars[0];
|
2006-04-08 07:16:14 +00:00
|
|
|
} else {
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].costume = newValue;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2008-05-29 12:22:14 +00:00
|
|
|
case 6:
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable[objIdx].part = newValue;
|
2006-04-08 07:16:14 +00:00
|
|
|
break;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-25 15:09:24 +00:00
|
|
|
/**
|
|
|
|
* Check if at least one of the range B's endpoints is inside range A,
|
|
|
|
* not counting the starting and ending points of range A.
|
|
|
|
* Used at least by Operation Stealth's opcode 0x8D i.e. 141.
|
|
|
|
*/
|
|
|
|
bool compareRanges(uint16 aStart, uint16 aEnd, uint16 bStart, uint16 bEnd) {
|
|
|
|
return (bStart > aStart && bStart < aEnd) || (bEnd > aStart && bEnd < aEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 compareObjectParamRanges(uint16 objIdx1, uint16 xAdd1, uint16 yAdd1, uint16 maskAdd1, uint16 objIdx2, uint16 xAdd2, uint16 yAdd2, uint16 maskAdd2) {
|
|
|
|
assert(objIdx1 < NUM_MAX_OBJECT && objIdx2 < NUM_MAX_OBJECT);
|
2010-08-09 11:38:01 +00:00
|
|
|
const ObjectStruct &obj1 = g_cine->_objectTable[objIdx1];
|
|
|
|
const ObjectStruct &obj2 = g_cine->_objectTable[objIdx2];
|
2008-06-25 15:09:24 +00:00
|
|
|
|
|
|
|
if (compareRanges(obj1.x, obj1.x + xAdd1, obj2.x, obj2.x + xAdd2) &&
|
|
|
|
compareRanges(obj1.y, obj1.y + yAdd1, obj2.y, obj2.y + yAdd2) &&
|
|
|
|
compareRanges(obj1.mask, obj1.mask + maskAdd1, obj2.mask, obj2.mask + maskAdd2)) {
|
|
|
|
return kCmpEQ;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-07 20:24:40 +00:00
|
|
|
uint16 compareObjectParam(byte objIdx, byte type, int16 value) {
|
|
|
|
uint16 compareResult = 0;
|
2007-12-08 02:24:12 +00:00
|
|
|
int16 objectParam = getObjectParam(objIdx, type);
|
|
|
|
|
|
|
|
if (objectParam > value) {
|
|
|
|
compareResult |= kCmpGT;
|
|
|
|
} else if (objectParam < value) {
|
|
|
|
compareResult |= kCmpLT;
|
|
|
|
} else {
|
|
|
|
compareResult |= kCmpEQ;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 07:16:14 +00:00
|
|
|
return compareResult;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* @bug In Operation Stealth, if you try to go downstairs to the sea in the
|
2008-05-24 22:11:41 +00:00
|
|
|
* location between bank and hotel, getObjectParam is called with paramIdx 16
|
|
|
|
* and crashes
|
|
|
|
*/
|
2006-02-23 09:12:21 +00:00
|
|
|
int16 getObjectParam(uint16 objIdx, uint16 paramIdx) {
|
2006-03-23 03:17:47 +00:00
|
|
|
assert(objIdx <= NUM_MAX_OBJECT);
|
2006-02-22 22:40:53 +00:00
|
|
|
|
|
|
|
paramIdx--;
|
|
|
|
|
2006-03-23 03:17:47 +00:00
|
|
|
assert(paramIdx <= 5);
|
2006-02-22 22:40:53 +00:00
|
|
|
|
|
|
|
switch (paramIdx) {
|
|
|
|
case 0:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].x;
|
2006-02-22 22:40:53 +00:00
|
|
|
case 1:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].y;
|
2006-02-22 22:40:53 +00:00
|
|
|
case 2:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].mask;
|
2006-02-22 22:40:53 +00:00
|
|
|
case 3:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].frame;
|
2006-02-22 22:40:53 +00:00
|
|
|
case 4:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].costume;
|
2006-02-22 22:40:53 +00:00
|
|
|
case 5:
|
2010-08-09 11:38:01 +00:00
|
|
|
return g_cine->_objectTable[objIdx].part;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-25 00:26:14 +00:00
|
|
|
|
|
|
|
} // End of namespace Cine
|