scummvm/engines/scumm/script_v6.cpp

3159 lines
68 KiB
C++
Raw Normal View History

/* ScummVM - Graphic Adventure Engine
*
* 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.
2001-10-16 10:01:48 +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.
2001-10-16 10:01:48 +00:00
*
* $URL$
* $Id$
2001-10-16 10:01:48 +00:00
*
*/
#include <time.h> // for ScummEngine_v6::o6_getDateTime()
#include "common/config-manager.h"
#include "common/system.h"
2003-09-11 10:32:15 +00:00
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/file.h"
#include "scumm/imuse/imuse.h"
#include "scumm/imuse_digi/dimuse.h"
#include "scumm/insane/insane.h"
2003-09-11 10:32:15 +00:00
#include "scumm/intern.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/smush/smush_player.h"
2003-09-11 10:32:15 +00:00
#include "scumm/sound.h"
#include "scumm/util.h"
2003-09-11 10:32:15 +00:00
#include "scumm/verbs.h"
#include "sound/mididrv.h"
#include "sound/mixer.h"
2001-10-16 10:01:48 +00:00
namespace Scumm {
#define OPCODE(x) _OPCODE(ScummEngine_v6, x)
void ScummEngine_v6::setupOpcodes() {
static const OpcodeEntryV6 opcodes[256] = {
/* 00 */
OPCODE(o6_pushByte),
OPCODE(o6_pushWord),
OPCODE(o6_pushByteVar),
OPCODE(o6_pushWordVar),
/* 04 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayRead),
OPCODE(o6_wordArrayRead),
/* 08 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayIndexedRead),
OPCODE(o6_wordArrayIndexedRead),
/* 0C */
OPCODE(o6_dup),
2002-12-22 19:14:53 +00:00
OPCODE(o6_not),
OPCODE(o6_eq),
OPCODE(o6_neq),
/* 10 */
OPCODE(o6_gt),
OPCODE(o6_lt),
OPCODE(o6_le),
OPCODE(o6_ge),
/* 14 */
OPCODE(o6_add),
OPCODE(o6_sub),
OPCODE(o6_mul),
OPCODE(o6_div),
/* 18 */
OPCODE(o6_land),
OPCODE(o6_lor),
OPCODE(o6_pop),
OPCODE(o6_invalid),
/* 1C */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 20 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 24 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 28 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 2C */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 30 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 34 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 38 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 3C */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* 40 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_writeByteVar),
OPCODE(o6_writeWordVar),
/* 44 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayWrite),
OPCODE(o6_wordArrayWrite),
/* 48 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayIndexedWrite),
OPCODE(o6_wordArrayIndexedWrite),
/* 4C */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteVarInc),
OPCODE(o6_wordVarInc),
/* 50 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayInc),
OPCODE(o6_wordArrayInc),
/* 54 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteVarDec),
OPCODE(o6_wordVarDec),
/* 58 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_byteArrayDec),
OPCODE(o6_wordArrayDec),
/* 5C */
OPCODE(o6_if),
OPCODE(o6_ifNot),
OPCODE(o6_startScript),
OPCODE(o6_startScriptQuick),
/* 60 */
OPCODE(o6_startObject),
OPCODE(o6_drawObject),
OPCODE(o6_drawObjectAt),
OPCODE(o6_drawBlastObject),
/* 64 */
OPCODE(o6_setBlastObjectWindow),
OPCODE(o6_stopObjectCode),
OPCODE(o6_stopObjectCode),
OPCODE(o6_endCutscene),
/* 68 */
OPCODE(o6_cutscene),
OPCODE(o6_stopMusic),
OPCODE(o6_freezeUnfreeze),
OPCODE(o6_cursorCommand),
/* 6C */
OPCODE(o6_breakHere),
OPCODE(o6_ifClassOfIs),
OPCODE(o6_setClass),
OPCODE(o6_getState),
/* 70 */
OPCODE(o6_setState),
OPCODE(o6_setOwner),
OPCODE(o6_getOwner),
OPCODE(o6_jump),
/* 74 */
OPCODE(o6_startSound),
OPCODE(o6_stopSound),
OPCODE(o6_startMusic),
OPCODE(o6_stopObjectScript),
/* 78 */
OPCODE(o6_panCameraTo),
OPCODE(o6_actorFollowCamera),
OPCODE(o6_setCameraAt),
OPCODE(o6_loadRoom),
/* 7C */
OPCODE(o6_stopScript),
OPCODE(o6_walkActorToObj),
OPCODE(o6_walkActorTo),
OPCODE(o6_putActorAtXY),
/* 80 */
OPCODE(o6_putActorAtObject),
OPCODE(o6_faceActor),
OPCODE(o6_animateActor),
OPCODE(o6_doSentence),
/* 84 */
OPCODE(o6_pickupObject),
OPCODE(o6_loadRoomWithEgo),
OPCODE(o6_invalid),
OPCODE(o6_getRandomNumber),
/* 88 */
OPCODE(o6_getRandomNumberRange),
OPCODE(o6_invalid),
OPCODE(o6_getActorMoving),
2002-12-22 19:14:53 +00:00
OPCODE(o6_isScriptRunning),
/* 8C */
OPCODE(o6_getActorRoom),
OPCODE(o6_getObjectX),
OPCODE(o6_getObjectY),
OPCODE(o6_getObjectOldDir),
/* 90 */
OPCODE(o6_getActorWalkBox),
OPCODE(o6_getActorCostume),
OPCODE(o6_findInventory),
OPCODE(o6_getInventoryCount),
/* 94 */
OPCODE(o6_getVerbFromXY),
OPCODE(o6_beginOverride),
OPCODE(o6_endOverride),
OPCODE(o6_setObjectName),
/* 98 */
OPCODE(o6_isSoundRunning),
OPCODE(o6_setBoxFlags),
OPCODE(o6_createBoxMatrix),
OPCODE(o6_resourceRoutines),
/* 9C */
OPCODE(o6_roomOps),
2002-12-23 15:46:53 +00:00
OPCODE(o6_actorOps),
OPCODE(o6_verbOps),
OPCODE(o6_getActorFromXY),
/* A0 */
OPCODE(o6_findObject),
OPCODE(o6_pseudoRoom),
OPCODE(o6_getActorElevation),
OPCODE(o6_getVerbEntrypoint),
/* A4 */
OPCODE(o6_arrayOps),
OPCODE(o6_saveRestoreVerbs),
OPCODE(o6_drawBox),
OPCODE(o6_pop),
/* A8 */
OPCODE(o6_getActorWidth),
OPCODE(o6_wait),
OPCODE(o6_getActorScaleX),
OPCODE(o6_getActorAnimCounter),
/* AC */
OPCODE(o6_soundKludge),
OPCODE(o6_isAnyOf),
OPCODE(o6_systemOps),
OPCODE(o6_isActorInBox),
/* B0 */
OPCODE(o6_delay),
OPCODE(o6_delaySeconds),
OPCODE(o6_delayMinutes),
OPCODE(o6_stopSentence),
/* B4 */
OPCODE(o6_printLine),
2005-06-13 07:09:12 +00:00
OPCODE(o6_printText),
OPCODE(o6_printDebug),
OPCODE(o6_printSystem),
/* B8 */
OPCODE(o6_printActor),
OPCODE(o6_printEgo),
OPCODE(o6_talkActor),
OPCODE(o6_talkEgo),
/* BC */
OPCODE(o6_dimArray),
OPCODE(o6_dummy),
OPCODE(o6_startObjectQuick),
OPCODE(o6_startScriptQuick2),
/* C0 */
OPCODE(o6_dim2dimArray),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* C4 */
OPCODE(o6_abs),
OPCODE(o6_distObjectObject),
OPCODE(o6_distObjectPt),
OPCODE(o6_distPtPt),
/* C8 */
OPCODE(o6_kernelGetFunctions),
OPCODE(o6_kernelSetFunctions),
OPCODE(o6_delayFrames),
OPCODE(o6_pickOneOf),
/* CC */
OPCODE(o6_pickOneOfDefault),
OPCODE(o6_stampObject),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* D0 */
OPCODE(o6_getDateTime),
OPCODE(o6_stopTalking),
OPCODE(o6_getAnimateVariable),
OPCODE(o6_invalid),
/* D4 */
OPCODE(o6_shuffle),
OPCODE(o6_jumpToScript),
OPCODE(o6_band),
OPCODE(o6_bor),
/* D8 */
OPCODE(o6_isRoomScriptRunning),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* DC */
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_findAllObjects),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* E0 */
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_getPixel),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
2003-02-17 21:42:33 +00:00
OPCODE(o6_pickVarRandom),
/* E4 */
2004-02-16 05:53:17 +00:00
OPCODE(o6_setBoxSet),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* E8 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* EC */
OPCODE(o6_getActorLayer),
OPCODE(o6_getObjectNewDir),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* F0 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
/* F4 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* F8 */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
2004-02-07 02:52:27 +00:00
OPCODE(o6_invalid),
OPCODE(o6_invalid),
/* FC */
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
OPCODE(o6_invalid),
};
_opcodesV6 = opcodes;
2001-10-16 10:01:48 +00:00
}
2002-12-22 19:14:53 +00:00
void ScummEngine_v6::executeOpcode(byte i) {
2002-12-22 19:14:53 +00:00
OpcodeProcV6 op = _opcodesV6[i].proc;
(this->*op) ();
}
const char *ScummEngine_v6::getOpcodeDesc(byte i) {
2002-12-22 19:14:53 +00:00
return _opcodesV6[i].desc;
}
int ScummEngine_v6::popRoomAndObj(int *room) {
int obj;
if (_game.version >= 7) {
obj = pop();
*room = getObjectRoom(obj);
} else {
*room = pop();
obj = pop();
}
return obj;
}
byte *ScummEngine_v6::defineArray(int array, int type, int dim2, int dim1) {
int id;
int size;
ArrayHeader *ah;
assert(0 <= type && type <= 5);
if (_game.heversion >= 61) {
2004-08-01 02:03:07 +00:00
if (type == kBitArray || type == kNibbleArray)
type = kByteArray;
} else {
2004-08-01 02:03:07 +00:00
// NOTE: The following code turns all arrays except string arrays into
// integer arrays. There seems to be no reason for this, and it wastes
// space. However, we can't just remove this either, as that would
// break savegame compatibility. So do not touch this unless you are
// also adding code which updates old savegames, too. And of course
2004-08-01 02:03:07 +00:00
// readArray() and writeArray() would have to be updated, too...
if (type != kStringArray)
type = kIntArray;
}
nukeArray(array);
id = findFreeArrayId();
if (_game.version == 8) {
if (array & 0x40000000) {
}
if (array & 0x80000000) {
error("Can't define bit variable as array pointer");
}
size = (type == kIntArray) ? 4 : 1;
} else {
if (array & 0x4000) {
}
if (array & 0x8000) {
error("Can't define bit variable as array pointer");
}
size = (type == kIntArray) ? 2 : 1;
}
writeVar(array, id);
size *= dim2 + 1;
size *= dim1 + 1;
ah = (ArrayHeader *)_res->createResource(rtString, id, size + sizeof(ArrayHeader));
ah->type = TO_LE_16(type);
ah->dim1 = TO_LE_16(dim1 + 1);
ah->dim2 = TO_LE_16(dim2 + 1);
return ah->data;
}
void ScummEngine_v6::nukeArray(int a) {
int data;
data = readVar(a);
if (_game.heversion >= 80)
data &= ~0x33539000;
if (data)
_res->nukeResource(rtString, data);
if (_game.heversion >= 60)
_arraySlot[data] = 0;
writeVar(a, 0);
}
int ScummEngine_v6::findFreeArrayId() {
byte **addr = _res->address[rtString];
int i;
for (i = 1; i < _numArray; i++) {
if (!addr[i])
return i;
}
error("Out of array pointers, %d max", _numArray);
return -1;
}
#define SWAP16(x) x = SWAP_BYTES_16(x)
ScummEngine_v6::ArrayHeader *ScummEngine_v6::getArray(int array) {
ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, readVar(array));
if (!ah)
return 0;
// Workaround for a long standing bug where we saved array headers in native
// endianness, instead of a fixed endianness. We now always store the
// dimensions in little endian byte order. But to stay compatible with older
// savegames, we try to detect savegames which were created on a big endian
// system and convert them to the proper little endian format on the fly.
if ((FROM_LE_16(ah->dim1) & 0xF000) || (FROM_LE_16(ah->dim2) & 0xF000) || (FROM_LE_16(ah->type) & 0xFF00)) {
SWAP16(ah->dim1);
SWAP16(ah->dim2);
SWAP16(ah->type);
}
return ah;
}
int ScummEngine_v6::readArray(int array, int idx, int base) {
ArrayHeader *ah = getArray(array);
2001-10-16 10:01:48 +00:00
if (ah == NULL || ah->data == NULL)
error("readArray: invalid array %d (%d)", array, readVar(array));
// WORKAROUND bug #645711. This is clearly a script bug, as this script
// excerpt shows nicely:
// ...
// [03A7] (5D) if (isAnyOf(array-447[localvar13][localvar14],[0,4])) {
// [03BD] (5D) if ((localvar13 != -1) && (localvar14 != -1)) {
// [03CF] (B6) printDebug.begin()
// ...
// So it checks for invalid array indices only *after* using them to access
// the array. Ouch.
if (_game.id == GID_FT && array == 447 && _currentRoom == 95 && vm.slot[_currentScript].number == 2010 && idx == -1 && base == -1) {
return 0;
}
const int offset = base + idx * FROM_LE_16(ah->dim1);
2001-10-16 10:01:48 +00:00
if (offset < 0 || offset >= FROM_LE_16(ah->dim1) * FROM_LE_16(ah->dim2)) {
error("readArray: array %d out of bounds: [%d,%d] exceeds [%d,%d]",
array, base, idx, FROM_LE_16(ah->dim1), FROM_LE_16(ah->dim2));
}
2001-10-16 10:01:48 +00:00
int val;
2004-08-01 02:03:07 +00:00
if (FROM_LE_16(ah->type) != kIntArray) {
val = ah->data[offset];
} else if (_game.version == 8) {
val = (int32)READ_LE_UINT32(ah->data + offset * 4);
2001-10-16 10:01:48 +00:00
} else {
val = (int16)READ_LE_UINT16(ah->data + offset * 2);
2001-10-16 10:01:48 +00:00
}
return val;
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::writeArray(int array, int idx, int base, int value) {
ArrayHeader *ah = getArray(array);
if (!ah)
return;
2001-10-16 10:01:48 +00:00
const int offset = base + idx * FROM_LE_16(ah->dim1);
if (offset < 0 || offset >= FROM_LE_16(ah->dim1) * FROM_LE_16(ah->dim2)) {
error("writeArray: array %d out of bounds: [%d,%d] exceeds [%d,%d]",
array, base, idx, FROM_LE_16(ah->dim1), FROM_LE_16(ah->dim2));
}
2001-10-16 10:01:48 +00:00
2004-08-01 02:03:07 +00:00
if (FROM_LE_16(ah->type) != kIntArray) {
ah->data[offset] = value;
} else if (_game.version == 8) {
WRITE_LE_UINT32(ah->data + offset * 4, value);
2001-10-16 10:01:48 +00:00
} else {
WRITE_LE_UINT16(ah->data + offset * 2, value);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::readArrayFromIndexFile() {
int num;
int a, b, c;
while ((num = _fileHandle->readUint16LE()) != 0) {
a = _fileHandle->readUint16LE();
b = _fileHandle->readUint16LE();
c = _fileHandle->readUint16LE();
2004-08-28 14:48:51 +00:00
if (c == kBitArray)
defineArray(num, kBitArray, a, b);
else
defineArray(num, kIntArray, a, b);
}
}
int ScummEngine_v6::getStackList(int *args, uint maxnum) {
2001-10-16 10:01:48 +00:00
uint num, i;
for (i = 0; i < maxnum; i++)
2001-10-16 10:01:48 +00:00
args[i] = 0;
num = pop();
if (num > maxnum)
error("Too many items %d in stack list, max %d", num, maxnum);
i = num;
2004-03-15 21:48:54 +00:00
while (i--) {
2001-10-16 10:01:48 +00:00
args[i] = pop();
}
return num;
}
void ScummEngine_v6::o6_pushByte() {
2001-10-16 10:01:48 +00:00
push(fetchScriptByte());
}
void ScummEngine_v6::o6_pushWord() {
push(fetchScriptWordSigned());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_pushByteVar() {
2004-08-23 14:11:53 +00:00
push(readVar(fetchScriptByte()));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_pushWordVar() {
2001-10-16 10:01:48 +00:00
push(readVar(fetchScriptWord()));
}
void ScummEngine_v6::o6_invalid() {
error("Invalid opcode '%x' at %lx", _opcode, (long)(_scriptPointer - _scriptOrgPointer));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_byteArrayRead() {
2001-10-16 10:01:48 +00:00
int base = pop();
push(readArray(fetchScriptByte(), 0, base));
}
void ScummEngine_v6::o6_wordArrayRead() {
2001-10-16 10:01:48 +00:00
int base = pop();
push(readArray(fetchScriptWord(), 0, base));
}
void ScummEngine_v6::o6_byteArrayIndexedRead() {
2001-10-16 10:01:48 +00:00
int base = pop();
int idx = pop();
push(readArray(fetchScriptByte(), idx, base));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_wordArrayIndexedRead() {
2001-10-16 10:01:48 +00:00
int base = pop();
int idx = pop();
push(readArray(fetchScriptWord(), idx, base));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_dup() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(a);
push(a);
}
void ScummEngine_v6::o6_not() {
push(pop() == 0);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_eq() {
push(pop() == pop());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_neq() {
push(pop() != pop());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_gt() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() > a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_lt() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() < a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_le() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() <= a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_ge() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() >= a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_add() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() + a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_sub() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() - a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_mul() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() * a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_div() {
2001-10-16 10:01:48 +00:00
int a = pop();
if (a == 0)
error("division by zero");
push(pop() / a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_land() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() && a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_lor() {
2001-10-16 10:01:48 +00:00
int a = pop();
push(pop() || a);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_bor() {
int a = pop();
push(pop() | a);
}
void ScummEngine_v6::o6_band() {
int a = pop();
push(pop() & a);
}
void ScummEngine_v6::o6_pop() {
2001-10-16 10:01:48 +00:00
pop();
}
void ScummEngine_v6::o6_writeByteVar() {
2001-10-16 10:01:48 +00:00
writeVar(fetchScriptByte(), pop());
}
void ScummEngine_v6::o6_writeWordVar() {
2001-10-16 10:01:48 +00:00
writeVar(fetchScriptWord(), pop());
}
void ScummEngine_v6::o6_byteArrayWrite() {
2001-10-16 10:01:48 +00:00
int a = pop();
writeArray(fetchScriptByte(), 0, pop(), a);
}
void ScummEngine_v6::o6_wordArrayWrite() {
2001-10-16 10:01:48 +00:00
int a = pop();
writeArray(fetchScriptWord(), 0, pop(), a);
}
void ScummEngine_v6::o6_byteArrayIndexedWrite() {
2001-10-16 10:01:48 +00:00
int val = pop();
int base = pop();
writeArray(fetchScriptByte(), pop(), base, val);
}
void ScummEngine_v6::o6_wordArrayIndexedWrite() {
2001-10-16 10:01:48 +00:00
int val = pop();
int base = pop();
writeArray(fetchScriptWord(), pop(), base, val);
}
void ScummEngine_v6::o6_byteVarInc() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptByte();
writeVar(var, readVar(var) + 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_wordVarInc() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptWord();
writeVar(var, readVar(var) + 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_byteArrayInc() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptByte();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) + 1);
}
void ScummEngine_v6::o6_wordArrayInc() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptWord();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) + 1);
}
void ScummEngine_v6::o6_byteVarDec() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptByte();
writeVar(var, readVar(var) - 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_wordVarDec() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptWord();
writeVar(var, readVar(var) - 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_byteArrayDec() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptByte();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) - 1);
}
void ScummEngine_v6::o6_wordArrayDec() {
2001-10-16 10:01:48 +00:00
int var = fetchScriptWord();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) - 1);
}
void ScummEngine_v6::o6_if() {
2001-10-16 10:01:48 +00:00
if (pop())
o6_jump();
2001-10-16 10:01:48 +00:00
else
fetchScriptWord();
}
void ScummEngine_v6::o6_ifNot() {
2001-10-16 10:01:48 +00:00
if (!pop())
o6_jump();
2001-10-16 10:01:48 +00:00
else
fetchScriptWord();
}
void ScummEngine_v6::o6_jump() {
int offset = fetchScriptWordSigned();
_scriptPointer += offset;
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_startScript() {
2004-12-19 09:27:08 +00:00
int args[25];
int script, flags;
2001-10-16 10:01:48 +00:00
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
script = pop();
flags = pop();
2004-08-08 11:43:54 +00:00
// WORKAROUND bug #556558: At Dino Bungee National Memorial, the buttons for
// the Wally and Rex dinosaurs will always restart their speech, instead of
// stopping and starting their speech. This was a script bug in the original
2004-08-08 11:43:54 +00:00
// game.
if (_game.id == GID_SAMNMAX && _roomResource == 59 &&
vm.slot[_currentScript].number == 201 && script == 48) {
o6_breakHere();
}
// WORKAROUND bug #903223: In Puerto Pollo, if you have Guybrush examine
// the church clock, he'll read out the current time. Nice touch, only that
// it sounds crap in the german version (and maybe others, too). It seems
// the original engine of the german version played just a simple fixed
// text in this spot, for the above reason. Since the data files are
// unchanged, it must have been an engine hack job. No idea how they did
// it exactly, but this here is how we do it :-)
if (_game.id == GID_CMI && script == 204 &&
_currentRoom == 15 && vm.slot[_currentScript].number == 421 &&
_language == Common::DE_DEU) {
_actorToPrintStrFor = 1;
_string[0].loadDefault();
actorTalk((const byte *)"/VDSO325/Whoa! Look at the time. Gotta scoot.");
return;
}
2003-05-19 15:40:34 +00:00
runScript(script, (flags & 1) != 0, (flags & 2) != 0, args);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_jumpToScript() {
2004-12-19 09:27:08 +00:00
int args[25];
int script, flags;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
script = pop();
flags = pop();
stopObjectCode();
2003-05-19 15:40:34 +00:00
runScript(script, (flags & 1) != 0, (flags & 2) != 0, args);
}
void ScummEngine_v6::o6_startScriptQuick() {
2004-12-19 09:27:08 +00:00
int args[25];
2001-10-16 10:01:48 +00:00
int script;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
script = pop();
runScript(script, 0, 0, args);
}
void ScummEngine_v6::o6_startScriptQuick2() {
2004-12-19 09:27:08 +00:00
int args[25];
int script;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
script = pop();
runScript(script, 0, 1, args);
}
void ScummEngine_v6::o6_startObject() {
2004-12-19 09:27:08 +00:00
int args[25];
int script, entryp;
2001-10-16 10:01:48 +00:00
int flags;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
entryp = pop();
script = pop();
flags = pop();
runObjectScript(script, entryp, (flags & 1) != 0, (flags & 2) != 0, args);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_startObjectQuick() {
2004-12-19 09:27:08 +00:00
int args[25];
int script, entryp;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
entryp = pop();
script = pop();
runObjectScript(script, entryp, 0, 1, args);
}
void ScummEngine_v6::o6_drawObject() {
2004-01-11 21:48:31 +00:00
int state = pop();
int obj = pop();
// This is based on disassembly
2004-01-11 21:48:31 +00:00
if (state == 0)
state = 1;
2004-01-11 21:48:31 +00:00
setObjectState(obj, state, -1, -1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_drawObjectAt() {
2001-10-16 10:01:48 +00:00
int y = pop();
int x = pop();
int obj = pop();
setObjectState(obj, 1, x, y);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopObjectCode() {
2001-10-16 10:01:48 +00:00
stopObjectCode();
}
void ScummEngine_v6::o6_endCutscene() {
2001-10-16 10:01:48 +00:00
endCutscene();
}
void ScummEngine_v6::o6_cutscene() {
2004-12-19 09:27:08 +00:00
int args[25];
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
beginCutscene(args);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopMusic() {
2002-08-14 20:43:56 +00:00
_sound->stopAllSounds();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_freezeUnfreeze() {
2001-10-16 10:01:48 +00:00
int a = pop();
2001-10-16 10:01:48 +00:00
if (a)
freezeScripts(a);
else
unfreezeScripts();
}
void ScummEngine_v6::o6_cursorCommand() {
int a, i;
int args[16];
byte subOp = fetchScriptByte();
2001-10-16 10:01:48 +00:00
switch (subOp) {
case 0x90: // SO_CURSOR_ON Turn cursor on
2002-12-04 22:31:36 +00:00
_cursor.state = 1;
2001-10-16 10:01:48 +00:00
verbMouseOver(0);
break;
case 0x91: // SO_CURSOR_OFF Turn cursor off
2002-12-04 22:31:36 +00:00
_cursor.state = 0;
2001-10-16 10:01:48 +00:00
verbMouseOver(0);
break;
case 0x92: // SO_USERPUT_ON
2001-10-16 10:01:48 +00:00
_userPut = 1;
break;
case 0x93: // SO_USERPUT_OFF
2001-10-16 10:01:48 +00:00
_userPut = 0;
break;
case 0x94: // SO_CURSOR_SOFT_ON Turn soft cursor on
2002-12-04 22:31:36 +00:00
_cursor.state++;
if (_cursor.state > 1)
2001-10-16 10:01:48 +00:00
error("Cursor state greater than 1 in script");
verbMouseOver(0);
break;
case 0x95: // SO_CURSOR_SOFT_OFF Turn soft cursor off
2002-12-04 22:31:36 +00:00
_cursor.state--;
2001-10-16 10:01:48 +00:00
verbMouseOver(0);
break;
case 0x96: // SO_USERPUT_SOFT_ON
2001-10-16 10:01:48 +00:00
_userPut++;
break;
case 0x97: // SO_USERPUT_SOFT_OFF
2001-10-16 10:01:48 +00:00
_userPut--;
break;
case 0x99: // SO_CURSOR_IMAGE Set cursor image
{
2005-04-16 10:26:49 +00:00
int room, obj;
if (_game.heversion >= 70) {
2005-04-16 10:26:49 +00:00
obj = pop();
room = getObjectRoom(obj);
} else {
obj = popRoomAndObj(&room);
}
2004-08-22 23:38:00 +00:00
setCursorFromImg(obj, room, 1);
break;
}
case 0x9A: // SO_CURSOR_HOTSPOT Set cursor hotspot
2001-10-16 10:01:48 +00:00
a = pop();
setCursorHotspot(pop(), a);
updateCursor();
2001-10-16 10:01:48 +00:00
break;
case 0x9C: // SO_CHARSET_SET
2001-10-16 10:01:48 +00:00
initCharset(pop());
break;
case 0x9D: // SO_CHARSET_COLOR
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
for (i = 0; i < 16; i++)
_charsetColorMap[i] = _charsetData[_string[1]._default.charset][i] = (unsigned char)args[i];
2001-10-16 10:01:48 +00:00
break;
case 0xD6: // SO_CURSOR_TRANSPARENT Set cursor transparent color
2004-08-22 23:38:00 +00:00
setCursorTransparency(pop());
2001-10-16 10:01:48 +00:00
break;
default:
error("o6_cursorCommand: default case %x", subOp);
2001-10-16 10:01:48 +00:00
}
VAR(VAR_CURSORSTATE) = _cursor.state;
VAR(VAR_USERPUT) = _userPut;
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_breakHere() {
2001-10-16 10:01:48 +00:00
updateScriptPtr();
_currentScript = 0xFF;
}
void ScummEngine_v6::o6_ifClassOfIs() {
int args[16];
int num, obj, cls;
2001-10-16 10:01:48 +00:00
bool b;
int cond = 1;
2003-05-18 21:03:57 +00:00
num = getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
obj = pop();
if (_game.heversion >= 80 && num == 0) {
push(_classData[obj]);
return;
}
while (--num >= 0) {
2001-10-16 10:01:48 +00:00
cls = args[num];
b = getClass(obj, cls);
if ((cls & 0x80 && !b) || (!(cls & 0x80) && b))
2001-10-16 10:01:48 +00:00
cond = 0;
}
push(cond);
}
void ScummEngine_v6::o6_setClass() {
int args[16];
int num, obj, cls;
2001-10-16 10:01:48 +00:00
2003-05-18 21:03:57 +00:00
num = getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
obj = pop();
while (--num >= 0) {
2001-10-16 10:01:48 +00:00
cls = args[num];
if (cls == 0)
2001-10-16 10:01:48 +00:00
_classData[num] = 0;
else if (cls & 0x80)
2001-10-16 10:01:48 +00:00
putClass(obj, cls, 1);
else
putClass(obj, cls, 0);
}
}
void ScummEngine_v6::o6_getState() {
2001-10-16 10:01:48 +00:00
push(getState(pop()));
}
void ScummEngine_v6::o6_setState() {
2001-10-16 10:01:48 +00:00
int state = pop();
int obj = pop();
putState(obj, state);
markObjectRectAsDirty(obj);
if (_bgNeedsRedraw)
2001-10-16 10:01:48 +00:00
clearDrawObjectQueue();
}
void ScummEngine_v6::o6_setOwner() {
2001-10-16 10:01:48 +00:00
int owner = pop();
int obj = pop();
setOwnerOf(obj, owner);
}
void ScummEngine_v6::o6_getOwner() {
2001-10-16 10:01:48 +00:00
push(getOwner(pop()));
}
void ScummEngine_v6::o6_startSound() {
int offset = 0;
// In Fatty Bear's Birthday Surprise the piano uses offsets 1 - 23 to
// indicate which note to play, but only when using the standard piano
2005-09-02 11:24:16 +00:00
// sound. See also o60_soundOps()
if (_game.heversion >= 60 && (_game.id != GID_PUTTDEMO))
offset = pop();
#ifdef ENABLE_SCUMM_7_8
if (_game.version >= 7)
2004-07-14 08:16:40 +00:00
_imuseDigital->startSfx(pop(), 64);
else
#endif
2004-07-14 08:16:40 +00:00
_sound->addSoundToQueue(pop(), offset);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopSound() {
2002-08-14 20:43:56 +00:00
_sound->stopSound(pop());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_startMusic() {
if (_game.version >= 7)
error("o6_startMusic() It shouldn't be called here for imuse digital");
_sound->addSoundToQueue(pop());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopObjectScript() {
2001-10-16 10:01:48 +00:00
stopObjectScript(pop());
}
void ScummEngine_v6::o6_panCameraTo() {
if (_game.version >= 7) {
int y = pop();
int x = pop();
panCameraTo(x, y);
} else {
panCameraTo(pop(), 0);
}
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_actorFollowCamera() {
if (_game.version >= 7)
setCameraFollows(derefActor(pop(), "actorFollowCamera"));
else
actorFollowCamera(pop());
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_setCameraAt() {
if (_game.version >= 7) {
int x, y;
camera._follows = 0;
VAR(VAR_CAMERA_FOLLOWED_ACTOR) = 0;
y = pop();
x = pop();
setCameraAt(x, y);
} else {
setCameraAtEx(pop());
}
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_loadRoom() {
2002-12-23 15:46:53 +00:00
int room = pop();
2001-10-16 10:01:48 +00:00
startScene(room, 0, 0);
if (_game.heversion >= 61) {
setCameraAt(camera._cur.x, 0);
}
2005-08-06 14:34:40 +00:00
_fullRedraw = true;
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopScript() {
2001-10-16 10:01:48 +00:00
int script = pop();
if (script == 0)
2001-10-16 10:01:48 +00:00
stopObjectCode();
else
stopScript(script);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_walkActorToObj() {
int act, obj, dist;
2001-10-16 10:01:48 +00:00
Actor *a, *a2;
2003-06-11 21:45:47 +00:00
int x, y;
2001-10-16 10:01:48 +00:00
dist = pop();
obj = pop();
act = pop();
a = derefActor(act, "o6_walkActorToObj");
2001-10-16 10:01:48 +00:00
if (obj >= _numActors) {
int wio = whereIsObject(obj);
if (wio != WIO_FLOBJECT && wio != WIO_ROOM)
2001-10-16 10:01:48 +00:00
return;
2003-06-11 21:45:47 +00:00
int dir;
getObjectXYPos(obj, x, y, dir);
a->startWalkActor(x, y, dir);
2001-10-16 10:01:48 +00:00
} else {
a2 = derefActorSafe(obj, "o6_walkActorToObj(2)");
if (_game.id == GID_SAMNMAX && a2 == 0) {
2006-01-17 18:57:26 +00:00
// WORKAROUND bug #742676 SAM: Fish Farm. Note quite sure why it
// happens, whether it's normal or due to a bug in the ScummVM code.
debug(0, "o6_walkActorToObj: invalid actor %d", obj);
return;
}
2002-08-04 13:03:33 +00:00
if (!a->isInCurrentRoom() || !a2->isInCurrentRoom())
return;
if (dist == 0) {
dist = a2->_scalex * a2->_width / 0xFF;
2003-06-11 21:45:47 +00:00
dist += dist / 2;
2001-10-16 10:01:48 +00:00
}
x = a2->getPos().x;
y = a2->getPos().y;
if (x < a->getPos().x)
2001-10-16 10:01:48 +00:00
x += dist;
else
x -= dist;
2003-06-11 21:45:47 +00:00
a->startWalkActor(x, y, -1);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_walkActorTo() {
int x, y;
2001-10-16 10:01:48 +00:00
y = pop();
x = pop();
Actor *a = derefActor(pop(), "o6_walkActorTo");
2002-12-30 02:06:18 +00:00
a->startWalkActor(x, y, -1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_putActorAtXY() {
int room, x, y, act;
2001-10-16 10:01:48 +00:00
Actor *a;
room = pop();
y = pop();
x = pop();
act = pop();
a = derefActor(act, "o6_putActorAtXY");
2003-01-05 22:16:09 +00:00
if (room == 0xFF || room == 0x7FFFFFFF) {
room = a->_room;
2001-10-16 10:01:48 +00:00
} else {
if (a->_visible && _currentRoom != room && getTalkingActor() == a->_number) {
stopTalk();
2001-10-16 10:01:48 +00:00
}
if (room != 0)
a->_room = room;
2001-10-16 10:01:48 +00:00
}
a->putActor(x, y, room);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_putActorAtObject() {
int room, obj, x, y;
2001-10-16 10:01:48 +00:00
Actor *a;
2005-04-16 10:26:49 +00:00
obj = popRoomAndObj(&room);
2001-10-16 10:01:48 +00:00
a = derefActor(pop(), "o6_putActorAtObject");
if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj, x, y);
2001-10-16 10:01:48 +00:00
} else {
x = 160;
2001-10-16 10:01:48 +00:00
y = 120;
}
if (room == 0xFF)
room = a->_room;
a->putActor(x, y, room);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_faceActor() {
int obj = pop();
Actor *a = derefActor(pop(), "o6_faceActor");
a->faceToObject(obj);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_animateActor() {
2001-10-16 10:01:48 +00:00
int anim = pop();
int act = pop();
if (_game.id == GID_TENTACLE && _roomResource == 57 &&
vm.slot[_currentScript].number == 19 && act == 593) {
2006-01-17 18:57:26 +00:00
// WORKAROUND bug #743363: This very odd case (animateActor(593,250))
// occurs in DOTT, in the cutscene after George cuts down the "cherry
// tree" and the tree Laverne is trapped in vanishes...
// Not sure if this means animateActor somehow also must work for objects
// (593 is the time machine in room 57), or if this is simply a script bug.
act = 6;
}
if (_game.id == GID_SAMNMAX && _roomResource == 35 &&
2005-09-02 10:49:21 +00:00
vm.slot[_currentScript].number == 202 && act == 4 && anim == 14) {
// WORKAROUND bug #1223621 (Animation glitch at World of Fish).
// Before starting animation 14 of the fisherman, make sure he isn't
// talking anymore. This appears to be a bug in the original game as well.
if (getTalkingActor() == 4) {
stopTalk();
}
}
Actor *a = derefActor(act, "o6_animateActor");
a->animateActor(anim);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_doSentence() {
int verb, objectA, objectB, dummy = 0;
2001-10-16 10:01:48 +00:00
objectB = pop();
if (_game.version < 8)
2003-05-24 16:45:49 +00:00
dummy = pop(); // dummy pop (in Sam&Max, seems to be always 0 or 130)
objectA = pop();
verb = pop();
2001-10-16 10:01:48 +00:00
doSentence(verb, objectA, objectB);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_pickupObject() {
2001-10-16 10:01:48 +00:00
int obj, room;
int i;
2001-10-16 10:01:48 +00:00
obj = popRoomAndObj(&room);
if (room == 0)
room = _roomResource;
for (i = 0; i < _numInventory; i++) {
if (_inventory[i] == (uint16)obj) {
putOwner(obj, VAR(VAR_EGO));
runInventoryScript(obj);
return;
}
}
2001-10-16 10:01:48 +00:00
addObjectToInventory(obj, room);
putOwner(obj, VAR(VAR_EGO));
putClass(obj, kObjectClassUntouchable, 1);
2001-10-16 10:01:48 +00:00
putState(obj, 1);
markObjectRectAsDirty(obj);
2001-10-16 10:01:48 +00:00
clearDrawObjectQueue();
2006-01-17 18:57:26 +00:00
runInventoryScript(obj);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_loadRoomWithEgo() {
2001-10-16 10:01:48 +00:00
Actor *a;
2002-08-15 20:12:15 +00:00
int obj, room, x, y;
2001-10-16 10:01:48 +00:00
y = pop();
x = pop();
2005-04-16 10:26:49 +00:00
obj = popRoomAndObj(&room);
a = derefActor(VAR(VAR_EGO), "o6_loadRoomWithEgo");
a->putActor(0, 0, room);
2001-10-26 17:34:50 +00:00
_egoPositioned = false;
VAR(VAR_WALKTO_OBJ) = obj;
startScene(a->_room, a, obj);
VAR(VAR_WALKTO_OBJ) = 0;
2001-10-16 10:01:48 +00:00
if (_game.version == 6) {
camera._cur.x = camera._dest.x = a->getPos().x;
setCameraFollows(a, (_game.heversion >= 60));
}
2002-08-15 20:12:15 +00:00
2005-08-06 14:34:40 +00:00
_fullRedraw = true;
2002-08-15 20:12:15 +00:00
if (x != -1 && x != 0x7FFFFFFF) {
a->startWalkActor(x, y, -1);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_getRandomNumber() {
2001-10-16 10:01:48 +00:00
int rnd;
rnd = _rnd.getRandomNumber(pop());
if (VAR_RANDOM_NR != 0xFF)
VAR(VAR_RANDOM_NR) = rnd;
2001-10-16 10:01:48 +00:00
push(rnd);
}
void ScummEngine_v6::o6_getRandomNumberRange() {
2001-10-16 10:01:48 +00:00
int max = pop();
int min = pop();
int rnd = _rnd.getRandomNumberRng(min, max);
if (VAR_RANDOM_NR != 0xFF)
VAR(VAR_RANDOM_NR) = rnd;
2001-10-16 10:01:48 +00:00
push(rnd);
}
void ScummEngine_v6::o6_isScriptRunning() {
push(isScriptRunning(pop()));
}
void ScummEngine_v6::o6_isRoomScriptRunning() {
push(isRoomScriptRunning(pop()));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_getActorMoving() {
Actor *a = derefActor(pop(), "o6_getActorMoving");
push(a->_moving);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorRoom() {
int act = pop();
if (act == 0) {
// This case occurs at the very least in COMI. That's because in COMI's script 28,
// there is a check which looks as follows:
// if (((VAR_TALK_ACTOR != 0) && (VAR_HAVE_MSG == 1)) &&
// (getActorRoom(VAR_TALK_ACTOR) == VAR_ROOM))
// Due to the way this is represented in bytecode, the engine cannot
2004-01-15 20:37:26 +00:00
// short circuit. Hence, even though this would be perfectly fine code
// in C/C++, here it can (and does) lead to getActorRoom(0) being
// invoked. We silently ignore this.
push(0);
return;
}
if (act == 255) {
// This case also occurs in COMI...
push(0);
return;
}
Actor *a = derefActor(act, "o6_getActorRoom");
push(a->_room);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_getActorWalkBox() {
Actor *a = derefActor(pop(), "o6_getActorWalkBox");
push(a->_ignoreBoxes ? 0 : a->_walkbox);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorCostume() {
Actor *a = derefActor(pop(), "o6_getActorCostume");
push(a->_costume);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorElevation() {
Actor *a = derefActor(pop(), "o6_getActorElevation");
push(a->getElevation());
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorWidth() {
Actor *a = derefActor(pop(), "o6_getActorWidth");
push(a->_width);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorScaleX() {
Actor *a = derefActor(pop(), "o6_getActorScaleX");
push(a->_scalex);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorAnimCounter() {
Actor *a = derefActor(pop(), "o6_getActorAnimCounter");
push(a->_cost.animCounter);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getAnimateVariable() {
2002-12-30 02:06:18 +00:00
int var = pop();
Actor *a = derefActor(pop(), "o6_getAnimateVariable");
push(a->getAnimVar(var));
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_isActorInBox() {
2002-12-30 02:06:18 +00:00
int box = pop();
Actor *a = derefActor(pop(), "o6_isActorInBox");
push(checkXYInBoxBounds(box, a->getPos().x, a->getPos().y));
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getActorLayer() {
Actor *a = derefActor(pop(), "getActorLayer");
push(a->_layer);
2002-12-30 02:06:18 +00:00
}
void ScummEngine_v6::o6_getObjectX() {
2001-10-16 10:01:48 +00:00
push(getObjX(pop()));
}
void ScummEngine_v6::o6_getObjectY() {
2001-10-16 10:01:48 +00:00
push(getObjY(pop()));
}
void ScummEngine_v6::o6_getObjectOldDir() {
push(getObjOldDir(pop()));
}
void ScummEngine_v6::o6_getObjectNewDir() {
push(getObjNewDir(pop()));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_findInventory() {
int idx = pop();
2001-10-16 10:01:48 +00:00
int owner = pop();
push(findInventory(owner, idx));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_getInventoryCount() {
2001-10-16 10:01:48 +00:00
push(getInventoryCount(pop()));
}
void ScummEngine_v6::o6_getVerbFromXY() {
2001-10-16 10:01:48 +00:00
int y = pop();
int x = pop();
int over = findVerbAtPos(x, y);
2001-10-16 10:01:48 +00:00
if (over)
over = _verbs[over].verbid;
push(over);
}
void ScummEngine_v6::o6_beginOverride() {
2001-10-16 10:01:48 +00:00
beginOverride();
}
void ScummEngine_v6::o6_endOverride() {
2001-10-16 10:01:48 +00:00
endOverride();
}
void ScummEngine_v6::o6_setObjectName() {
2001-10-16 10:01:48 +00:00
int obj = pop();
setObjectName(obj);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_isSoundRunning() {
2001-10-16 10:01:48 +00:00
int snd = pop();
2001-10-16 10:01:48 +00:00
if (snd)
2002-08-14 20:43:56 +00:00
snd = _sound->isSoundRunning(snd);
2001-10-16 10:01:48 +00:00
push(snd);
}
void ScummEngine_v6::o6_setBoxFlags() {
int table[65];
int num, value;
2001-10-16 10:01:48 +00:00
value = pop();
2003-05-18 21:03:57 +00:00
num = getStackList(table, ARRAYSIZE(table));
2001-10-16 10:01:48 +00:00
while (--num >= 0) {
2001-10-16 10:01:48 +00:00
setBoxFlags(table[num], value);
}
}
void ScummEngine_v6::o6_createBoxMatrix() {
2001-10-16 10:01:48 +00:00
createBoxMatrix();
if ((_game.id == GID_DIG) || (_game.id == GID_CMI))
2004-07-07 00:11:11 +00:00
putActors();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_resourceRoutines() {
int resid;
2001-10-16 10:01:48 +00:00
byte subOp = fetchScriptByte();
switch (subOp) {
case 100: // SO_LOAD_SCRIPT
resid = pop();
if (_game.version >= 7)
if (resid >= _numGlobalScripts)
break;
ensureResourceLoaded(rtScript, resid);
2001-10-16 10:01:48 +00:00
break;
case 101: // SO_LOAD_SOUND
resid = pop();
ensureResourceLoaded(rtSound, resid);
2001-10-16 10:01:48 +00:00
break;
case 102: // SO_LOAD_COSTUME
resid = pop();
ensureResourceLoaded(rtCostume, resid);
2001-10-16 10:01:48 +00:00
break;
case 103: // SO_LOAD_ROOM
resid = pop();
ensureResourceLoaded(rtRoom, resid);
2001-10-16 10:01:48 +00:00
break;
case 104: // SO_NUKE_SCRIPT
resid = pop();
if (_game.version >= 7)
if (resid >= _numGlobalScripts)
break;
_res->setResourceCounter(rtScript, resid, 0x7F);
2001-10-16 10:01:48 +00:00
break;
case 105: // SO_NUKE_SOUND
resid = pop();
_res->setResourceCounter(rtSound, resid, 0x7F);
2001-10-16 10:01:48 +00:00
break;
case 106: // SO_NUKE_COSTUME
resid = pop();
_res->setResourceCounter(rtCostume, resid, 0x7F);
2001-10-16 10:01:48 +00:00
break;
case 107: // SO_NUKE_ROOM
resid = pop();
_res->setResourceCounter(rtRoom, resid, 0x7F);
2001-10-16 10:01:48 +00:00
break;
case 108: // SO_LOCK_SCRIPT
resid = pop();
if (resid >= _numGlobalScripts)
2001-10-16 10:01:48 +00:00
break;
_res->lock(rtScript, resid);
2001-10-16 10:01:48 +00:00
break;
case 109: // SO_LOCK_SOUND
resid = pop();
_res->lock(rtSound, resid);
2001-10-16 10:01:48 +00:00
break;
case 110: // SO_LOCK_COSTUME
resid = pop();
_res->lock(rtCostume, resid);
2001-10-16 10:01:48 +00:00
break;
case 111: // SO_LOCK_ROOM
resid = pop();
if (resid > 0x7F)
resid = _resourceMapper[resid & 0x7F];
_res->lock(rtRoom, resid);
2001-10-16 10:01:48 +00:00
break;
case 112: // SO_UNLOCK_SCRIPT
resid = pop();
if (resid >= _numGlobalScripts)
2001-10-16 10:01:48 +00:00
break;
_res->unlock(rtScript, resid);
2001-10-16 10:01:48 +00:00
break;
case 113: // SO_UNLOCK_SOUND
resid = pop();
_res->unlock(rtSound, resid);
2001-10-16 10:01:48 +00:00
break;
case 114: // SO_UNLOCK_COSTUME
resid = pop();
_res->unlock(rtCostume, resid);
2001-10-16 10:01:48 +00:00
break;
case 115: // SO_UNLOCK_ROOM
resid = pop();
if (resid > 0x7F)
resid = _resourceMapper[resid & 0x7F];
_res->unlock(rtRoom, resid);
2001-10-16 10:01:48 +00:00
break;
case 116: // SO_CLEAR_HEAP
2001-10-16 10:01:48 +00:00
/* this is actually a scumm message */
error("clear heap not working yet");
break;
case 117: // SO_LOAD_CHARSET
resid = pop();
loadCharset(resid);
2001-10-16 10:01:48 +00:00
break;
case 118: // SO_NUKE_CHARSET
resid = pop();
nukeCharset(resid);
2001-10-16 10:01:48 +00:00
break;
case 119: // SO_LOAD_OBJECT
{
int room, obj = popRoomAndObj(&room);
loadFlObject(obj, room);
break;
}
2001-10-16 10:01:48 +00:00
default:
error("o6_resourceRoutines: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_roomOps() {
int a, b, c, d, e;
2001-10-16 10:01:48 +00:00
byte subOp = fetchScriptByte();
switch (subOp) {
case 172: // SO_ROOM_SCROLL
2001-10-16 10:01:48 +00:00
b = pop();
a = pop();
if (a < (_screenWidth / 2))
a = (_screenWidth / 2);
if (b < (_screenWidth / 2))
b = (_screenWidth / 2);
if (a > _roomWidth - (_screenWidth / 2))
a = _roomWidth - (_screenWidth / 2);
if (b > _roomWidth - (_screenWidth / 2))
b = _roomWidth - (_screenWidth / 2);
VAR(VAR_CAMERA_MIN_X) = a;
VAR(VAR_CAMERA_MAX_X) = b;
2001-10-16 10:01:48 +00:00
break;
case 174: // SO_ROOM_SCREEN
2001-10-16 10:01:48 +00:00
b = pop();
a = pop();
2004-01-04 14:49:14 +00:00
initScreens(a, b);
2001-10-16 10:01:48 +00:00
break;
case 175: // SO_ROOM_PALETTE
2001-10-16 10:01:48 +00:00
d = pop();
c = pop();
b = pop();
a = pop();
setPalColor(d, a, b, c);
break;
case 176: // SO_ROOM_SHAKE_ON
2001-10-16 10:01:48 +00:00
setShake(1);
break;
case 177: // SO_ROOM_SHAKE_OFF
2001-10-16 10:01:48 +00:00
setShake(0);
break;
case 179: // SO_ROOM_INTENSITY
2001-10-16 10:01:48 +00:00
c = pop();
b = pop();
a = pop();
darkenPalette(a, a, a, b, c);
2001-10-16 10:01:48 +00:00
break;
case 180: // SO_ROOM_SAVEGAME
_saveTemporaryState = true;
2001-10-26 17:34:50 +00:00
_saveLoadSlot = pop();
2001-10-16 10:01:48 +00:00
_saveLoadFlag = pop();
if (_game.id == GID_TENTACLE)
_saveSound = (_saveLoadSlot != 0);
2001-10-16 10:01:48 +00:00
break;
case 181: // SO_ROOM_FADE
2001-10-16 10:01:48 +00:00
a = pop();
if (a) {
_switchRoomEffect = (byte)(a & 0xFF);
_switchRoomEffect2 = (byte)(a >> 8);
2001-10-16 10:01:48 +00:00
} else {
fadeIn(_newEffect);
2001-10-16 10:01:48 +00:00
}
break;
case 182: // SO_RGB_ROOM_INTENSITY
2001-10-16 10:01:48 +00:00
e = pop();
d = pop();
c = pop();
b = pop();
a = pop();
darkenPalette(a, b, c, d, e);
2001-10-16 10:01:48 +00:00
break;
case 183: // SO_ROOM_SHADOW
2001-10-16 10:01:48 +00:00
e = pop();
d = pop();
c = pop();
b = pop();
a = pop();
setShadowPalette(a, b, c, d, e, 0, 256);
2001-10-16 10:01:48 +00:00
break;
case 184: // SO_SAVE_STRING
2001-10-16 10:01:48 +00:00
error("save string not implemented");
break;
case 185: // SO_LOAD_STRING
2001-10-16 10:01:48 +00:00
error("load string not implemented");
break;
case 186: // SO_ROOM_TRANSFORM
2001-10-16 10:01:48 +00:00
d = pop();
c = pop();
b = pop();
a = pop();
palManipulateInit(a, b, c, d);
2001-10-16 10:01:48 +00:00
break;
case 187: // SO_CYCLE_SPEED
2001-10-16 10:01:48 +00:00
b = pop();
a = pop();
assertRange(1, a, 16, "o6_roomOps: 187: color cycle");
_colorCycle[a - 1].delay = (b != 0) ? 0x4000 / (b * 0x4C) : 0;
2001-10-16 10:01:48 +00:00
break;
case 213: // SO_ROOM_NEW_PALETTE
a = pop();
// This opcode is used when turning off noir mode in Sam & Max,
// but since our implementation of this feature doesn't change
// the original palette there's no need to reload it. Doing it
// this way, we avoid some graphics glitches that the original
// interpreter had.
if (_game.id == GID_SAMNMAX && vm.slot[_currentScript].number == 64)
setDirtyColors(0, 255);
else
2006-11-04 22:59:56 +00:00
setCurrentPalette(a);
2001-10-16 10:01:48 +00:00
break;
default:
error("o6_roomOps: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_actorOps() {
2001-10-16 10:01:48 +00:00
Actor *a;
int i, j, k;
int args[8];
2001-10-16 10:01:48 +00:00
byte subOp = fetchScriptByte();
if (subOp == 197) {
2001-10-16 10:01:48 +00:00
_curActor = pop();
return;
}
2002-12-23 15:46:53 +00:00
a = derefActorSafe(_curActor, "o6_actorOps");
if (!a)
return;
2001-10-16 10:01:48 +00:00
switch (subOp) {
case 76: // SO_COSTUME
a->setActorCostume(pop());
2001-10-16 10:01:48 +00:00
break;
case 77: // SO_STEP_DIST
2001-10-16 10:01:48 +00:00
j = pop();
i = pop();
a->setActorWalkSpeed(i, j);
2001-10-16 10:01:48 +00:00
break;
case 78: // SO_SOUND
2003-05-18 21:03:57 +00:00
k = getStackList(args, ARRAYSIZE(args));
for (i = 0; i < k; i++)
a->_sound[i] = args[i];
2001-10-16 10:01:48 +00:00
break;
case 79: // SO_WALK_ANIMATION
a->_walkFrame = pop();
2001-10-16 10:01:48 +00:00
break;
case 80: // SO_TALK_ANIMATION
a->_talkStopFrame = pop();
a->_talkStartFrame = pop();
2001-10-16 10:01:48 +00:00
break;
case 81: // SO_STAND_ANIMATION
a->_standFrame = pop();
2001-10-16 10:01:48 +00:00
break;
case 82: // SO_ANIMATION
2004-02-06 16:19:43 +00:00
// dummy case in scumm6
2001-10-16 10:01:48 +00:00
pop();
pop();
pop();
break;
case 83: // SO_DEFAULT
a->initActor(0);
2001-10-16 10:01:48 +00:00
break;
case 84: // SO_ELEVATION
a->setElevation(pop());
2001-10-16 10:01:48 +00:00
break;
case 85: // SO_ANIMATION_DEFAULT
a->_initFrame = 1;
a->_walkFrame = 2;
a->_standFrame = 3;
a->_talkStartFrame = 4;
a->_talkStopFrame = 5;
2001-10-16 10:01:48 +00:00
break;
case 86: // SO_PALETTE
2001-10-16 10:01:48 +00:00
j = pop();
i = pop();
assertRange(0, i, 255, "o6_actorOps: palette slot");
2004-02-07 02:52:27 +00:00
a->setPalette(i, j);
2001-10-16 10:01:48 +00:00
break;
case 87: // SO_TALK_COLOR
a->_talkColor = pop();
2001-10-16 10:01:48 +00:00
break;
case 88: // SO_ACTOR_NAME
loadPtrToResource(rtActorName, a->_number, NULL);
2001-10-16 10:01:48 +00:00
break;
case 89: // SO_INIT_ANIMATION
a->_initFrame = pop();
2001-10-16 10:01:48 +00:00
break;
case 91: // SO_ACTOR_WIDTH
a->_width = pop();
2001-10-16 10:01:48 +00:00
break;
case 92: // SO_SCALE
2004-01-05 16:30:00 +00:00
i = pop();
a->setScale(i, i);
2001-10-16 10:01:48 +00:00
break;
case 93: // SO_NEVER_ZCLIP
a->_forceClip = 0;
2001-10-16 10:01:48 +00:00
break;
case 225: // SO_ALWAYS_ZCLIP
case 94: // SO_ALWAYS_ZCLIP
a->_forceClip = pop();
2001-10-16 10:01:48 +00:00
break;
case 95: // SO_IGNORE_BOXES
a->_ignoreBoxes = 1;
a->_forceClip = (_game.version >= 7) ? 100 : 0;
if (a->isInCurrentRoom())
a->putActor();
2001-10-16 10:01:48 +00:00
break;
case 96: // SO_FOLLOW_BOXES
a->_ignoreBoxes = 0;
a->_forceClip = (_game.version >= 7) ? 100 : 0;
2003-05-20 23:05:34 +00:00
if (a->isInCurrentRoom())
a->putActor();
2003-05-20 23:05:34 +00:00
break;
case 97: // SO_ANIMATION_SPEED
a->setAnimSpeed(pop());
2001-10-16 10:01:48 +00:00
break;
case 98: // SO_SHADOW
a->_shadowMode = pop();
2001-10-16 10:01:48 +00:00
break;
case 99: // SO_TEXT_OFFSET
a->_talkPosY = pop();
a->_talkPosX = pop();
2001-10-16 10:01:48 +00:00
break;
case 198: // SO_ACTOR_VARIABLE
i = pop();
a->setAnimVar(pop(), i);
break;
case 215: // SO_ACTOR_IGNORE_TURNS_ON
a->_ignoreTurns = true;
break;
case 216: // SO_ACTOR_IGNORE_TURNS_OFF
a->_ignoreTurns = false;
2001-10-16 10:01:48 +00:00
break;
case 217: // SO_ACTOR_NEW
a->initActor(2);
break;
case 227: // SO_ACTOR_DEPTH
a->_layer = pop();
break;
case 228: // SO_ACTOR_WALK_SCRIPT
a->_walkScript = pop();
break;
case 229: // SO_ACTOR_STOP
a->stopActorMoving();
a->startAnimActor(a->_standFrame);
break;
case 230: /* set direction */
a->_moving &= ~MF_TURN;
a->setDirection(pop());
break;
case 231: /* turn to direction */
a->turnToDirection(pop());
break;
case 233: // SO_ACTOR_WALK_PAUSE
a->_moving |= MF_FROZEN;
break;
case 234: // SO_ACTOR_WALK_RESUME
a->_moving &= ~MF_FROZEN;
break;
case 235: // SO_ACTOR_TALK_SCRIPT
a->_talkScript = pop();
break;
2001-10-16 10:01:48 +00:00
default:
error("o6_actorOps: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_verbOps() {
int slot, a, b;
2001-10-16 10:01:48 +00:00
VerbSlot *vs;
byte subOp = fetchScriptByte();
if (subOp == 196) {
2001-10-16 10:01:48 +00:00
_curVerb = pop();
_curVerbSlot = getVerbSlot(_curVerb, 0);
assertRange(0, _curVerbSlot, _numVerbs - 1, "new verb slot");
2001-10-16 10:01:48 +00:00
return;
}
vs = &_verbs[_curVerbSlot];
slot = _curVerbSlot;
switch (subOp) {
case 124: // SO_VERB_IMAGE
2001-10-16 10:01:48 +00:00
a = pop();
if (_curVerbSlot) {
setVerbObject(_roomResource, a, slot);
2002-11-29 18:27:35 +00:00
vs->type = kImageVerbType;
if (_game.heversion >= 61)
vs->imgindex = a;
2001-10-16 10:01:48 +00:00
}
break;
case 125: // SO_VERB_NAME
loadPtrToResource(rtVerb, slot, NULL);
2002-11-29 18:27:35 +00:00
vs->type = kTextVerbType;
2001-10-16 10:01:48 +00:00
vs->imgindex = 0;
break;
case 126: // SO_VERB_COLOR
2001-10-16 10:01:48 +00:00
vs->color = pop();
break;
case 127: // SO_VERB_HICOLOR
2001-10-16 10:01:48 +00:00
vs->hicolor = pop();
break;
case 128: // SO_VERB_AT
vs->curRect.top = pop();
vs->curRect.left = pop();
2001-10-16 10:01:48 +00:00
break;
case 129: // SO_VERB_ON
2001-10-16 10:01:48 +00:00
vs->curmode = 1;
break;
case 130: // SO_VERB_OFF
2001-10-16 10:01:48 +00:00
vs->curmode = 0;
break;
case 131: // SO_VERB_DELETE
if (_game.heversion >= 60) {
slot = getVerbSlot(pop(), 0);
}
2001-10-16 10:01:48 +00:00
killVerb(slot);
break;
case 132: // SO_VERB_NEW
2001-10-16 10:01:48 +00:00
slot = getVerbSlot(_curVerb, 0);
if (slot == 0) {
for (slot = 1; slot < _numVerbs; slot++) {
if (_verbs[slot].verbid == 0)
2001-10-16 10:01:48 +00:00
break;
}
if (slot == _numVerbs)
2001-10-16 10:01:48 +00:00
error("Too many verbs");
_curVerbSlot = slot;
}
vs = &_verbs[slot];
vs->verbid = _curVerb;
vs->color = 2;
vs->hicolor = 0;
vs->dimcolor = 8;
2002-11-29 18:27:35 +00:00
vs->type = kTextVerbType;
vs->charset_nr = _string[0]._default.charset;
2001-10-16 10:01:48 +00:00
vs->curmode = 0;
vs->saveid = 0;
vs->key = 0;
vs->center = 0;
vs->imgindex = 0;
break;
case 133: // SO_VERB_DIMCOLOR
2001-10-16 10:01:48 +00:00
vs->dimcolor = pop();
break;
case 134: // SO_VERB_DIM
2001-10-16 10:01:48 +00:00
vs->curmode = 2;
break;
case 135: // SO_VERB_KEY
2001-10-16 10:01:48 +00:00
vs->key = pop();
break;
case 136: // SO_VERB_CENTER
2001-10-16 10:01:48 +00:00
vs->center = 1;
break;
case 137: // SO_VERB_NAME_STR
2001-10-16 10:01:48 +00:00
a = pop();
if (a == 0) {
loadPtrToResource(rtVerb, slot, (const byte *)"");
2001-10-16 10:01:48 +00:00
} else {
loadPtrToResource(rtVerb, slot, getStringAddress(a));
2001-10-16 10:01:48 +00:00
}
2002-11-29 18:27:35 +00:00
vs->type = kTextVerbType;
2001-10-16 10:01:48 +00:00
vs->imgindex = 0;
break;
case 139: // SO_VERB_IMAGE_IN_ROOM
2001-10-16 10:01:48 +00:00
b = pop();
a = pop();
2001-10-16 10:01:48 +00:00
if (slot && a != vs->imgindex) {
setVerbObject(b, a, slot);
2002-11-29 18:27:35 +00:00
vs->type = kImageVerbType;
2001-10-16 10:01:48 +00:00
vs->imgindex = a;
}
break;
case 140: // SO_VERB_BAKCOLOR
2001-10-16 10:01:48 +00:00
vs->bkcolor = pop();
break;
case 255:
drawVerb(slot, 0);
verbMouseOver(0);
break;
default:
error("o6_verbops: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_getActorFromXY() {
2001-10-16 10:01:48 +00:00
int y = pop();
int x = pop();
int r = getActorFromPos(x, y);
push(r);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_findObject() {
2001-10-16 10:01:48 +00:00
int y = pop();
int x = pop();
int r = findObject(x, y);
2001-10-16 10:01:48 +00:00
push(r);
}
void ScummEngine_v6::o6_pseudoRoom() {
int list[100];
int num, a, value;
2001-10-16 10:01:48 +00:00
2003-05-18 21:03:57 +00:00
num = getStackList(list, ARRAYSIZE(list));
2001-10-16 10:01:48 +00:00
value = pop();
while (--num >= 0) {
2001-10-16 10:01:48 +00:00
a = list[num];
if (a > 0x7F)
_resourceMapper[a & 0x7F] = value;
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_getVerbEntrypoint() {
2001-10-16 10:01:48 +00:00
int e = pop();
int v = pop();
push(getVerbEntrypoint(v, e));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_arrayOps() {
byte subOp = fetchScriptByte();
int array = fetchScriptWord();
int b, c, d, len;
byte *data;
int list[128];
2001-10-16 10:01:48 +00:00
switch (subOp) {
case 205: // SO_ASSIGN_STRING
b = pop();
len = resStrLen(_scriptPointer);
data = defineArray(array, kStringArray, 0, len + 1);
copyScriptString(data + b);
2001-10-16 10:01:48 +00:00
break;
case 208: // SO_ASSIGN_INT_LIST
2001-10-16 10:01:48 +00:00
b = pop();
c = pop();
d = readVar(array);
if (d == 0) {
defineArray(array, kIntArray, 0, b + c);
2001-10-16 10:01:48 +00:00
}
while (c--) {
writeArray(array, 0, b + c, pop());
2001-10-16 10:01:48 +00:00
}
break;
case 212: // SO_ASSIGN_2DIM_LIST
2001-10-16 10:01:48 +00:00
b = pop();
2003-05-18 21:03:57 +00:00
len = getStackList(list, ARRAYSIZE(list));
d = readVar(array);
if (d == 0)
2001-10-16 10:01:48 +00:00
error("Must DIM a two dimensional array before assigning");
c = pop();
while (--len >= 0) {
writeArray(array, c, b + len, list[len]);
2001-10-16 10:01:48 +00:00
}
break;
default:
error("o6_arrayOps: default case %d (array %d)", subOp, array);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_saveRestoreVerbs() {
int a, b, c;
int slot, slot2;
2001-10-16 10:01:48 +00:00
c = pop();
b = pop();
a = pop();
byte subOp = fetchScriptByte();
if (_game.version == 8) {
subOp = (subOp - 141) + 0xB4;
}
switch (subOp) {
case 141: // SO_SAVE_VERBS
while (a <= b) {
slot = getVerbSlot(a, 0);
if (slot && _verbs[slot].saveid == 0) {
2001-10-16 10:01:48 +00:00
_verbs[slot].saveid = c;
drawVerb(slot, 0);
verbMouseOver(0);
}
a++;
}
break;
case 142: // SO_RESTORE_VERBS
while (a <= b) {
2001-10-16 10:01:48 +00:00
slot = getVerbSlot(a, c);
if (slot) {
slot2 = getVerbSlot(a, 0);
2001-10-16 10:01:48 +00:00
if (slot2)
killVerb(slot2);
slot = getVerbSlot(a, c);
2001-10-16 10:01:48 +00:00
_verbs[slot].saveid = 0;
drawVerb(slot, 0);
verbMouseOver(0);
}
a++;
}
break;
case 143: // SO_DELETE_VERBS
while (a <= b) {
slot = getVerbSlot(a, c);
2001-10-16 10:01:48 +00:00
if (slot)
killVerb(slot);
a++;
}
break;
default:
error("o6_saveRestoreVerbs: default case");
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_drawBox() {
int x, y, x2, y2, color;
2001-10-16 10:01:48 +00:00
color = pop();
y2 = pop();
x2 = pop();
y = pop();
x = pop();
drawBox(x, y, x2, y2, color);
}
void ScummEngine_v6::o6_wait() {
int actnum;
int offs = -2;
Actor *a;
byte subOp = fetchScriptByte();
switch (subOp) {
case 168: // SO_WAIT_FOR_ACTOR Wait for actor
offs = fetchScriptWordSigned();
actnum = pop();
a = derefActor(actnum, "o6_wait:168");
if (_game.version >= 7) {
if (a->isInCurrentRoom() && a->_moving)
break;
} else {
if (a->_moving)
break;
}
return;
case 169: // SO_WAIT_FOR_MESSAGE Wait for message
if (VAR(VAR_HAVE_MSG))
2001-10-16 10:01:48 +00:00
break;
return;
case 170: // SO_WAIT_FOR_CAMERA Wait for camera
if (_game.version >= 7) {
if (camera._dest != camera._cur)
break;
} else {
if (camera._cur.x / 8 != camera._dest.x / 8)
break;
}
2001-10-16 10:01:48 +00:00
return;
case 171: // SO_WAIT_FOR_SENTENCE
if (_sentenceNum) {
if (_sentence[_sentenceNum - 1].freezeCount && !isScriptInUse(VAR(VAR_SENTENCE_SCRIPT)))
2001-10-16 10:01:48 +00:00
return;
break;
}
if (!isScriptInUse(VAR(VAR_SENTENCE_SCRIPT)))
2001-10-16 10:01:48 +00:00
return;
break;
case 226: // SO_WAIT_FOR_ANIMATION
offs = fetchScriptWordSigned();
actnum = pop();
a = derefActor(actnum, "o6_wait:226");
if (a->isInCurrentRoom() && a->_needRedraw)
2003-05-31 21:25:14 +00:00
break;
return;
case 232: // SO_WAIT_FOR_TURN
// WORKAROUND for bug #744441: An angle will often be received as the
2006-02-27 23:32:59 +00:00
// actor number due to script bugs in The Dig. In all cases where this
// occurs, _curActor is set just before it, so we can use it instead.
//
// For now, if the value passed in is divisible by 45, assume it is an
// angle, and use _curActor as the actor to wait for.
offs = fetchScriptWordSigned();
actnum = pop();
if (actnum % 45 == 0) {
actnum = _curActor;
}
a = derefActor(actnum, "o6_wait:232b");
if (a->isInCurrentRoom() && a->_moving & MF_TURN)
2003-05-31 21:25:14 +00:00
break;
return;
2001-10-16 10:01:48 +00:00
default:
error("o6_wait: default case 0x%x", subOp);
2001-10-16 10:01:48 +00:00
}
_scriptPointer += offs;
o6_breakHere();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_soundKludge() {
int list[16];
2003-05-18 21:03:57 +00:00
int num = getStackList(list, ARRAYSIZE(list));
_sound->soundKludge(list, num);
// WORKAROUND for bug #1398195: The room-11-2016 script contains a
// slight bug causing it to busy-wait for a sound to finish. Even under
// the best of circumstances, this will cause the game to hang briefly.
// On platforms where threading is cooperative, it will cause the game
// to hang indefinitely. We identify the buggy part of the script by
// looking for a soundKludge() opcode immediately followed by a jump.
if (_game.id == GID_CMI && _roomResource == 11 && vm.slot[_currentScript].number == 2016 && *_scriptPointer == 0x66) {
debug(3, "Working around script bug in room-11-2016");
o6_breakHere();
}
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_isAnyOf() {
int list[100];
2001-10-16 10:01:48 +00:00
int num;
int32 val;
2001-10-16 10:01:48 +00:00
2003-05-18 21:03:57 +00:00
num = getStackList(list, ARRAYSIZE(list));
2001-10-16 10:01:48 +00:00
val = pop();
while (--num >= 0) {
2001-10-16 10:01:48 +00:00
if (list[num] == val) {
push(1);
return;
}
}
2005-03-07 06:37:56 +00:00
2001-10-16 10:01:48 +00:00
push(0);
}
void ScummEngine_v6::o6_systemOps() {
byte subOp = fetchScriptByte();
switch (subOp) {
case 158: // SO_RESTART
restart();
break;
case 159: // SO_PAUSE
pauseGame();
2001-10-16 10:01:48 +00:00
break;
case 160: // SO_QUIT
shutDown();
2001-10-16 10:01:48 +00:00
break;
default:
error("o6_systemOps invalid case %d", subOp);
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_delay() {
2001-10-16 10:01:48 +00:00
uint32 delay = (uint16)pop();
vm.slot[_currentScript].delay = delay;
2003-09-11 10:32:15 +00:00
vm.slot[_currentScript].status = ssPaused;
o6_breakHere();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_delaySeconds() {
uint32 delay = (uint32)pop();
delay = delay * 60;
2001-10-16 10:01:48 +00:00
vm.slot[_currentScript].delay = delay;
2003-09-11 10:32:15 +00:00
vm.slot[_currentScript].status = ssPaused;
o6_breakHere();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_delayMinutes() {
2001-10-16 10:01:48 +00:00
uint32 delay = (uint16)pop() * 3600;
vm.slot[_currentScript].delay = delay;
2003-09-11 10:32:15 +00:00
vm.slot[_currentScript].status = ssPaused;
o6_breakHere();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_stopSentence() {
_sentenceNum = 0;
stopScript(VAR(VAR_SENTENCE_SCRIPT));
2001-10-16 10:01:48 +00:00
clearClickedStatus();
}
void ScummEngine_v6::o6_printLine() {
2001-10-16 10:01:48 +00:00
_actorToPrintStrFor = 0xFF;
2002-12-23 15:46:53 +00:00
decodeParseString(0, 0);
2001-10-16 10:01:48 +00:00
}
2005-06-13 07:09:12 +00:00
void ScummEngine_v6::o6_printText() {
2002-12-23 15:46:53 +00:00
decodeParseString(1, 0);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_printDebug() {
2002-12-23 15:46:53 +00:00
decodeParseString(2, 0);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_printSystem() {
2002-12-23 15:46:53 +00:00
decodeParseString(3, 0);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_printActor() {
2002-12-23 15:46:53 +00:00
decodeParseString(0, 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_printEgo() {
push(VAR(VAR_EGO));
decodeParseString(0, 1);
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_talkActor() {
int offset = _scriptPointer - _scriptOrgPointer;
// WORKAROUNDfor bug #896489: see below for detailed description
if (_forcedWaitForMessage) {
if (VAR(VAR_HAVE_MSG)) {
_scriptPointer--;
o6_breakHere();
return;
}
_forcedWaitForMessage = false;
_scriptPointer += resStrLen(_scriptPointer) + 1;
return;
}
2001-10-16 10:01:48 +00:00
_actorToPrintStrFor = pop();
2003-06-01 00:45:08 +00:00
_string[0].loadDefault();
actorTalk(_scriptPointer);
// WORKAROUND for bug #896489: "DIG: Missing subtitles when talking to Brink"
// Original script does not have wait.waitForMessage() after several messages:
//
// [011A] (5D) if (getActorCostume(VAR_EGO) == 1) {
// [0126] (BA) talkActor("/STOP.008/Low out.",3)
// [013D] (A9) wait.waitForMessage()
// [013F] (5D) } else if (var227 == 0) {
// [014C] (BA) talkActor("/STOP.009/Never mind.",3)
// [0166] (73) } else {
//
// Here we simulate that opcode.
if (_game.id == GID_DIG && vm.slot[_currentScript].number == 88) {
if (offset == 0x158 || offset == 0x214 || offset == 0x231 || offset == 0x278) {
_forcedWaitForMessage = true;
_scriptPointer--;
return;
}
}
_scriptPointer += resStrLen(_scriptPointer) + 1;
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_talkEgo() {
push(VAR(VAR_EGO));
o6_talkActor();
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_dimArray() {
2001-10-16 10:01:48 +00:00
int data;
byte subOp = fetchScriptByte();
switch (subOp) {
case 199: // SO_INT_ARRAY
data = kIntArray;
2001-10-16 10:01:48 +00:00
break;
case 200: // SO_BIT_ARRAY
data = kBitArray;
2001-10-16 10:01:48 +00:00
break;
case 201: // SO_NIBBLE_ARRAY
data = kNibbleArray;
2001-10-16 10:01:48 +00:00
break;
case 202: // SO_BYTE_ARRAY
data = kByteArray;
2001-10-16 10:01:48 +00:00
break;
case 203: // SO_STRING_ARRAY
data = kStringArray;
2001-10-16 10:01:48 +00:00
break;
case 204: // SO_UNDIM_ARRAY
2001-10-16 10:01:48 +00:00
nukeArray(fetchScriptWord());
return;
default:
error("o6_dimArray: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
defineArray(fetchScriptWord(), data, 0, pop());
}
void ScummEngine_v6::o6_dummy() {
if (_game.heversion >= 60) {
stopObjectCode();
}
}
void ScummEngine_v6::o6_dim2dimArray() {
int a, b, data;
byte subOp = fetchScriptByte();
switch (subOp) {
case 199: // SO_INT_ARRAY
data = kIntArray;
2001-10-16 10:01:48 +00:00
break;
case 200: // SO_BIT_ARRAY
data = kBitArray;
2001-10-16 10:01:48 +00:00
break;
case 201: // SO_NIBBLE_ARRAY
data = kNibbleArray;
2001-10-16 10:01:48 +00:00
break;
case 202: // SO_BYTE_ARRAY
data = kByteArray;
2001-10-16 10:01:48 +00:00
break;
case 203: // SO_STRING_ARRAY
data = kStringArray;
2001-10-16 10:01:48 +00:00
break;
default:
error("o6_dim2dimArray: default case %d", subOp);
2001-10-16 10:01:48 +00:00
}
b = pop();
a = pop();
defineArray(fetchScriptWord(), data, a, b);
}
void ScummEngine_v6::o6_abs() {
int a = pop();
push(ABS(a));
2001-10-16 10:01:48 +00:00
}
void ScummEngine_v6::o6_distObjectObject() {
int a, b;
2001-10-16 10:01:48 +00:00
b = pop();
a = pop();
push(getDistanceBetween(true, a, 0, true, b, 0));
}
void ScummEngine_v6::o6_distObjectPt() {
int a, b, c;
2001-10-16 10:01:48 +00:00
c = pop();
b = pop();
a = pop();
push(getDistanceBetween(true, a, 0, false, b, c));
}
void ScummEngine_v6::o6_distPtPt() {
int a, b, c, d;
2001-10-16 10:01:48 +00:00
d = pop();
c = pop();
b = pop();
a = pop();
push(getDistanceBetween(false, a, b, false, c, d));
}
void ScummEngine_v6::o6_drawBlastObject() {
int args[16];
int a, b, c, d, e;
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
e = pop();
d = pop();
c = pop();
b = pop();
a = pop();
enqueueObject(a, b, c, d, e, 0xFF, 0xFF, 1, 0);
}
2002-12-23 15:46:53 +00:00
// Set BOMP processing window
void ScummEngine_v6::o6_setBlastObjectWindow() {
pop();
pop();
pop();
pop();
2002-12-23 15:46:53 +00:00
// None of the scripts of The Dig and Full Throttle use this opcode.
// Sam & Max only uses it at the beginning of the highway subgame. In
// the original interpreter pop'ed arguments are just ignored and the
// clipping blastObject window is defined with (0, 0, 320, 200)...
// which matches the screen dimensions and thus, doesn't require
// another clipping operation.
// So, we just handle this as no-op opcode.
2002-12-23 15:46:53 +00:00
}
#ifdef ENABLE_SCUMM_7_8
void ScummEngine_v7::o6_kernelSetFunctions() {
int args[30];
2003-05-24 17:04:54 +00:00
int num;
Actor *a;
2003-05-24 17:04:54 +00:00
num = getStackList(args, ARRAYSIZE(args));
switch (args[0]) {
case 4:
grabCursor(args[1], args[2], args[3], args[4]);
break;
case 6: {
if (_smushFrameRate == 0)
_smushFrameRate = 14;
// SMUSH movie playback
if (args[1] == 0) {
2006-11-13 20:20:01 +00:00
const char *videoname = (const char *)getStringAddressVar(VAR_VIDEONAME);
assert(videoname);
if (strcmp(videoname, "sq3.san") == 0)
_smushFrameRate = 14;
2003-03-06 17:58:13 +00:00
// Correct incorrect smush filename in Macintosh FT demo
if ((_game.id == GID_FT) && (_game.features & GF_DEMO) && (_game.platform == Common::kPlatformMacintosh) &&
2006-11-13 20:20:01 +00:00
(strcmp(videoname, "jumpgorge.san") == 0))
_splayer->play("jumpgorg.san", _smushFrameRate);
else
2006-11-13 20:20:01 +00:00
_splayer->play(videoname, _smushFrameRate);
if (_game.id == GID_DIG) {
_disableFadeInEffect = true;
}
} else if (_game.id == GID_FT) {
const int insaneVarNum = ((_game.features & GF_DEMO) && (_game.platform == Common::kPlatformPC))
? 232 : 233;
_insane->setSmushParams(_smushFrameRate);
_insane->runScene(insaneVarNum);
2003-03-06 17:58:13 +00:00
}
}
break;
case 12:
setCursorFromImg(args[1], (uint) - 1, args[2]);
break;
case 13:
derefActor(args[1], "o6_kernelSetFunctions:13")->remapActorPalette(args[2], args[3], args[4], -1);
break;
case 14:
derefActor(args[1], "o6_kernelSetFunctions:14")->remapActorPalette(args[2], args[3], args[4], args[5]);
break;
case 15:
_smushFrameRate = args[1];
break;
case 16:
case 17:
enqueueText(getStringAddressVar(VAR_STRING2DRAW), args[3], args[4], args[2], args[1], (args[0] == 16));
break;
case 20:
// it's used for turn on/off 'RadioChatter' effect for voice in the dig, but i's not needed
break;
case 107:
a = derefActor(args[1], "o6_kernelSetFunctions: 107");
a->setScale((unsigned char)args[2], -1);
break;
case 108:
setShadowPalette(args[1], args[2], args[3], args[4], args[5], args[6]);
break;
case 109:
setShadowPalette(0, args[1], args[2], args[3], args[4], args[5]);
break;
case 114:
error("o6_kernelSetFunctions: stub114()");
break;
case 117:
freezeScripts(2);
break;
case 118:
enqueueObject(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], 3);
break;
case 119:
enqueueObject(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], 0);
break;
case 124:
_saveSound = args[1];
break;
case 215:
ConfMan.setBool("subtitles", args[1] != 0);
break;
default:
error("o6_kernelSetFunctions: default case %d (param count %d)", args[0], num);
break;
}
}
#endif
void ScummEngine_v6::o6_kernelSetFunctions() {
int args[30];
int num;
Actor *a;
num = getStackList(args, ARRAYSIZE(args));
switch (args[0]) {
case 3:
// Dummy case
break;
case 4:
grabCursor(args[1], args[2], args[3], args[4]);
break;
case 5:
fadeOut(args[1]);
break;
case 6:
_fullRedraw = true;
redrawBGAreas();
setActorRedrawFlags();
processActors();
fadeIn(args[1]);
break;
case 8:
startManiac();
break;
case 9:
killAllScriptsExceptCurrent();
break;
case 104: /* samnmax */
nukeFlObjects(args[2], args[3]);
break;
case 107: /* set actor scale */
a = derefActor(args[1], "o6_kernelSetFunctions: 107");
a->setScale((unsigned char)args[2], -1);
break;
case 108: /* create proc_special_palette */
case 109:
// Case 108 and 109 share the same function
if (num != 6)
error("o6_kernelSetFunctions sub op %d: expected 6 params but got %d", args[0], num);
setShadowPalette(args[3], args[4], args[5], args[1], args[2], 0, 256);
break;
case 110:
clearCharsetMask();
break;
case 111:
a = derefActor(args[1], "o6_kernelSetFunctions: 111");
a->_shadowMode = args[2] + args[3];
break;
case 112: /* palette shift? */
setShadowPalette(args[3], args[4], args[5], args[1], args[2], args[6], args[7]);
break;
case 114:
// Sam & Max film noir mode
if (_game.id == GID_SAMNMAX) {
// At this point ScummVM will already have set
// variable 0x8000 to indicate that the game is
// in film noir mode. All we have to do here is
// to mark the palette as "dirty", because
// updatePalette() will desaturate the colors
// as they are uploaded to the backend.
//
// This actually works better than the original
// interpreter, where actors would sometimes
// still be drawn in color.
setDirtyColors(0, 255);
} else
error("stub o6_kernelSetFunctions_114()");
break;
case 117:
// Sam & Max uses this opcode in script-43, right
// before a screensaver is selected.
//
// Sam & Max uses variable 132 to specify the number of
// minutes of inactivity (no mouse movements) before
// starting the screensaver, so setting it to 0 will
// help in debugging.
freezeScripts(0x80);
break;
case 119:
enqueueObject(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], 0);
break;
case 120:
swapPalColors(args[1], args[2]);
break;
case 122:
VAR(VAR_SOUNDRESULT) =
(short)_imuse->doCommand (num - 1, &args[1]);
break;
case 123:
copyPalColor(args[2], args[1]);
break;
case 124:
_saveSound = args[1];
break;
default:
error("o6_kernelSetFunctions: default case %d (param count %d)", args[0], num);
break;
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_kernelGetFunctions() {
int args[30];
int i;
int slot;
Actor *a;
VirtScreen *vs = &_virtscr[kMainVirtScreen];
2003-05-18 21:03:57 +00:00
getStackList(args, ARRAYSIZE(args));
switch (args[0]) {
case 113:
// WORKAROUND for bug #899249: The scripts used for screen savers
// in Sam & Max use hard coded values for the maximum height and width.
// This causes problems in rooms (ie. Credits) where their values are
// lower, so we set result to zero if out of bounds.
if (args[1] >= 0 && args[1] <= vs->w && args[2] >= 0 && args[2] <= vs->h) {
byte pixel = *vs->getPixels(args[1], args[2]);
push(pixel);
} else {
push(0);
}
break;
case 115:
push(getSpecialBox(args[1], args[2]));
break;
case 116:
push(checkXYInBoxBounds(args[3], args[1], args[2]));
break;
case 206:
2004-09-21 13:54:30 +00:00
push(remapPaletteColor(args[1], args[2], args[3], -1));
break;
case 207:
i = getObjectIndex(args[1]);
assert(i);
push(_objs[i].x_pos);
break;
case 208:
i = getObjectIndex(args[1]);
assert(i);
push(_objs[i].y_pos);
break;
case 209:
i = getObjectIndex(args[1]);
assert(i);
push(_objs[i].width);
break;
case 210:
i = getObjectIndex(args[1]);
assert(i);
push(_objs[i].height);
break;
case 211:
/*
13 = thrust
336 = thrust
328 = thrust
27 = abort
97 = left
331 = left
115 = right
333 = right
*/
push(getKeyState(args[1]));
break;
case 212:
a = derefActor(args[1], "o6_kernelGetFunctions:212");
// This is used by walk scripts
push(a->_frame);
break;
case 213:
slot = getVerbSlot(args[1], 0);
push(_verbs[slot].curRect.left);
break;
case 214:
slot = getVerbSlot(args[1], 0);
push(_verbs[slot].curRect.top);
break;
case 215:
if ((_extraBoxFlags[args[1]] & 0x00FF) == 0x00C0) {
push(_extraBoxFlags[args[1]]);
} else {
2002-12-30 00:40:25 +00:00
push(getBoxFlags(args[1]));
}
break;
default:
error("o6_kernelGetFunctions: default case %d", args[0]);
}
2001-10-16 10:01:48 +00:00
}
int ScummEngine::getKeyState(int key) {
2004-10-22 10:25:56 +00:00
switch (key) {
case 0x147: // Home
// FIXME: There seems to be a mistake in the code here ("insert" vs. "home")
return (_keyDownMap[Common::KEYCODE_KP7] ||
_keyDownMap[Common::KEYCODE_INSERT]) ? 1 : 0;
case 0x148: // Up
return (_keyDownMap[Common::KEYCODE_KP8] ||
_keyDownMap[Common::KEYCODE_UP] ||
_keyDownMap[Common::KEYCODE_8]) ? 1 : 0;
case 0x149: // PgUp
return (_keyDownMap[Common::KEYCODE_KP9] ||
_keyDownMap[Common::KEYCODE_PAGEUP]) ? 1 : 0;
case 0x14B: // Left
return (_keyDownMap[Common::KEYCODE_KP4] ||
_keyDownMap[Common::KEYCODE_LEFT] ||
_keyDownMap[Common::KEYCODE_4]) ? 1 : 0;
case 0x14D: // Right
return (_keyDownMap[Common::KEYCODE_KP6] ||
_keyDownMap[Common::KEYCODE_RIGHT] ||
_keyDownMap[Common::KEYCODE_6]) ? 1 : 0;
case 0x14F: // End
return (_keyDownMap[Common::KEYCODE_KP1] ||
_keyDownMap[Common::KEYCODE_END]) ? 1 : 0;
case 0x150: // Down
return (_keyDownMap[Common::KEYCODE_KP2] ||
_keyDownMap[Common::KEYCODE_DOWN] ||
_keyDownMap[Common::KEYCODE_2]) ? 1 : 0;
case 0x151: // PgDn
return (_keyDownMap[Common::KEYCODE_KP3] ||
_keyDownMap[Common::KEYCODE_PAGEDOWN]) ? 1 : 0;
default:
return (_keyDownMap[key]) ? 1 : 0;
}
}
void ScummEngine_v6::o6_delayFrames() {
2001-10-16 10:01:48 +00:00
ScriptSlot *ss = &vm.slot[_currentScript];
if (ss->delayFrameCount == 0) {
2002-08-25 11:35:13 +00:00
ss->delayFrameCount = pop();
2001-10-16 10:01:48 +00:00
} else {
2002-08-25 11:35:13 +00:00
ss->delayFrameCount--;
2001-10-16 10:01:48 +00:00
}
2002-08-25 11:35:13 +00:00
if (ss->delayFrameCount) {
2001-10-16 10:01:48 +00:00
_scriptPointer--;
o6_breakHere();
2001-10-16 10:01:48 +00:00
}
}
void ScummEngine_v6::o6_pickOneOf() {
int args[100];
int i, num;
2001-10-16 10:01:48 +00:00
2003-05-18 21:03:57 +00:00
num = getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
i = pop();
if (i < 0 || i > num)
error("o6_pickOneOf: %d out of range (0, %d)", i, num - 1);
2001-10-16 10:01:48 +00:00
push(args[i]);
}
void ScummEngine_v6::o6_pickOneOfDefault() {
int args[100];
int i, num, def;
2001-10-16 10:01:48 +00:00
def = pop();
2003-05-18 21:03:57 +00:00
num = getStackList(args, ARRAYSIZE(args));
2001-10-16 10:01:48 +00:00
i = pop();
if (i < 0 || i >= num)
2001-10-16 10:01:48 +00:00
i = def;
else
i = args[i];
push(i);
}
void ScummEngine_v6::o6_stampObject() {
int object, x, y, state;
2004-02-14 16:59:28 +00:00
state = pop();
y = pop();
x = pop();
object = pop();
if (_game.version >= 7 && object < 30) {
if (state == 0)
state = 255;
Actor *a = derefActor(object, "o6_stampObject");
a->_scalex = state;
a->_scaley = state;
a->putActor(x, y, _currentRoom);
a->_drawToBackBuf = true;
a->drawActorCostume();
a->_drawToBackBuf = false;
a->drawActorCostume();
return;
}
if (state == 0)
state = 1;
int objnum = getObjectIndex(object);
if (objnum == -1)
return;
if (x != -1) {
_objs[objnum].x_pos = x * 8;
_objs[objnum].y_pos = y * 8;
}
putState(object, state);
drawObject(objnum, 0);
}
void ScummEngine_v6::o6_stopTalking() {
stopTalk();
}
void ScummEngine_v6::o6_findAllObjects() {
int room = pop();
int i = 1;
if (room != _currentRoom)
error("o6_findAllObjects: current room is not %d", room);
writeVar(0, 0);
defineArray(0, kIntArray, 0, _numLocalObjects + 1);
2003-02-17 10:40:02 +00:00
writeArray(0, 0, 0, _numLocalObjects);
while (i < _numLocalObjects) {
writeArray(0, 0, i, _objs[i].obj_nr);
i++;
}
push(readVar(0));
}
void ScummEngine_v6::shuffleArray(int num, int minIdx, int maxIdx) {
int range = maxIdx - minIdx;
int count = range * 2;
// Shuffle the array 'num'
while (count--) {
// Determine two random elements...
int rand1 = _rnd.getRandomNumber(range) + minIdx;
int rand2 = _rnd.getRandomNumber(range) + minIdx;
// ...and swap them
int val1 = readArray(num, 0, rand1);
int val2 = readArray(num, 0, rand2);
writeArray(num, 0, rand1, val2);
2003-03-07 21:54:45 +00:00
writeArray(num, 0, rand2, val1);
}
}
void ScummEngine_v6::o6_shuffle() {
int b = pop();
int a = pop();
shuffleArray(fetchScriptWord(), a, b);
}
void ScummEngine_v6::o6_pickVarRandom() {
int num;
int args[100];
2004-09-16 13:51:03 +00:00
int dim1;
2003-02-17 21:42:33 +00:00
2003-05-18 21:03:57 +00:00
num = getStackList(args, ARRAYSIZE(args));
int value = fetchScriptWord();
if (readVar(value) == 0) {
2004-09-16 14:31:16 +00:00
defineArray(value, kIntArray, 0, num);
if (num > 0) {
int16 counter = 0;
do {
writeArray(value, 0, counter + 1, args[counter]);
} while (++counter < num);
}
2004-09-16 14:31:16 +00:00
shuffleArray(value, 1, num);
writeArray(value, 0, 0, 2);
push(readArray(value, 0, 1));
return;
}
num = readArray(value, 0, 0);
ArrayHeader *ah = getArray(value);
2004-09-16 13:51:03 +00:00
dim1 = FROM_LE_16(ah->dim1) - 1;
if (dim1 < num) {
2004-09-16 12:54:32 +00:00
int16 var_2 = readArray(value, 0, num - 1);
2004-09-16 13:51:03 +00:00
shuffleArray(value, 1, dim1);
if (readArray(value, 0, 1) == var_2) {
num = 2;
} else {
num = 1;
}
}
2003-02-17 21:42:33 +00:00
writeArray(value, 0, 0, num + 1);
push(readArray(value, 0, num));
2003-02-17 21:42:33 +00:00
}
void ScummEngine_v6::o6_getDateTime() {
struct tm t;
_system->getTimeAndDate(t);
VAR(VAR_TIMEDATE_YEAR) = t.tm_year;
VAR(VAR_TIMEDATE_MONTH) = t.tm_mon;
VAR(VAR_TIMEDATE_DAY) = t.tm_mday;
VAR(VAR_TIMEDATE_HOUR) = t.tm_hour;
VAR(VAR_TIMEDATE_MINUTE) = t.tm_min;
if (_game.version == 8)
VAR(VAR_TIMEDATE_SECOND) = t.tm_sec;
}
void ScummEngine_v6::o6_getPixel() {
int x, y;
if (_game.heversion == 61) {
x = pop();
y = pop();
} else {
y = pop();
x = pop();
}
VirtScreen *vs = findVirtScreen(y);
if (vs == NULL || x > _screenWidth - 1 || x < 0) {
push(-1);
return;
}
byte pixel = *vs->getPixels(x, y - vs->topline);
push(pixel);
}
2004-02-16 05:53:17 +00:00
void ScummEngine_v6::o6_setBoxSet() {
int arg = pop() - 1;
const byte *room = getResourceAddress(rtRoom, _roomResource);
2004-02-14 17:01:28 +00:00
const byte *boxd = NULL, *boxm = NULL;
int32 dboxSize, mboxSize;
int i;
ResourceIterator boxds(room, false);
for (i = 0; i < arg; i++)
boxd = boxds.findNext(MKID_BE('BOXD'));
if (!boxd)
2004-02-16 05:53:17 +00:00
error("ScummEngine_v6::o6_setBoxSet: Can't find dboxes for set %d", arg);
dboxSize = READ_BE_UINT32(boxd + 4) - 8;
byte *matrix = _res->createResource(rtMatrix, 2, dboxSize);
assert(matrix);
memcpy(matrix, boxd + 8, dboxSize);
ResourceIterator boxms(room, false);
for (i = 0; i < arg; i++)
boxm = boxms.findNext(MKID_BE('BOXM'));
if (!boxm)
2004-02-16 05:53:17 +00:00
error("ScummEngine_v6::o6_setBoxSet: Can't find mboxes for set %d", arg);
mboxSize = READ_BE_UINT32(boxm + 4) - 8;
matrix = _res->createResource(rtMatrix, 1, mboxSize);
assert(matrix);
memcpy(matrix, boxm + 8, mboxSize);
if (_game.version == 7)
putActors();
}
2003-05-17 01:57:54 +00:00
void ScummEngine_v6::decodeParseString(int m, int n) {
byte b = fetchScriptByte();
switch (b) {
case 65: // SO_AT
_string[m].ypos = pop();
_string[m].xpos = pop();
_string[m].overhead = false;
2001-10-16 10:01:48 +00:00
break;
case 66: // SO_COLOR
_string[m].color = pop();
2001-10-16 10:01:48 +00:00
break;
case 67: // SO_CLIPPED
_string[m].right = pop();
2001-10-16 10:01:48 +00:00
break;
case 69: // SO_CENTER
_string[m].center = true;
_string[m].overhead = false;
2001-10-16 10:01:48 +00:00
break;
case 71: // SO_LEFT
_string[m].center = false;
_string[m].overhead = false;
2001-10-16 10:01:48 +00:00
break;
case 72: // SO_OVERHEAD
_string[m].overhead = true;
_string[m].no_talk_anim = false;
2001-10-16 10:01:48 +00:00
break;
case 74: // SO_MUMBLE
_string[m].no_talk_anim = true;
2001-10-16 10:01:48 +00:00
break;
case 75: // SO_TEXTSTRING
printString(m, _scriptPointer);
_scriptPointer += resStrLen(_scriptPointer) + 1;
break;
2001-10-16 10:01:48 +00:00
case 0xFE:
_string[m].loadDefault();
2001-10-16 10:01:48 +00:00
if (n)
_actorToPrintStrFor = pop();
break;
2001-10-16 10:01:48 +00:00
case 0xFF:
_string[m].saveDefault();
break;
2001-10-16 10:01:48 +00:00
default:
error("decodeParseString: default case 0x%x", b);
2001-10-16 10:01:48 +00:00
}
}
} // End of namespace Scumm