scummvm/scumm/script_v2.cpp

1218 lines
26 KiB
C++
Raw Normal View History

/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include "stdafx.h"
#include "scumm.h"
#include "actor.h"
#include "charset.h"
#include "intern.h"
#include "sound.h"
#include "verbs.h"
#define OPCODE(x) { &Scumm_v2::x, #x }
void Scumm_v2::setupOpcodes() {
static const OpcodeEntryV2 opcodes[256] = {
/* 00 */
OPCODE(o5_stopObjectCode),
OPCODE(o2_putActor),
2003-04-27 09:39:52 +00:00
OPCODE(o5_startMusic),
OPCODE(o5_getActorRoom),
/* 04 */
OPCODE(o5_isGreaterEqual),
OPCODE(o2_drawObject),
2003-04-27 11:38:38 +00:00
OPCODE(o5_getActorElevation),
OPCODE(o2_setState08),
/* 08 */
OPCODE(o5_isNotEqual),
2003-04-27 09:39:52 +00:00
OPCODE(o5_faceActor),
OPCODE(o2_assignVarWordIndirect),
OPCODE(o2_setObjY),
/* 0C */
2003-04-21 14:09:16 +00:00
OPCODE(o2_resourceRoutines),
2003-04-27 09:39:52 +00:00
OPCODE(o5_walkActorToActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_putActorAtObject),
OPCODE(o2_ifNotState08),
/* 10 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_getObjectOwner),
2003-04-26 16:37:35 +00:00
OPCODE(o2_animateActor),
OPCODE(o2_panCameraTo),
2003-04-20 16:59:52 +00:00
OPCODE(o2_actorSet),
/* 14 */
OPCODE(o5_print),
2003-04-26 16:37:35 +00:00
OPCODE(o2_actorFromPos),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getRandomNr),
OPCODE(o2_setState04),
/* 18 */
OPCODE(o5_jumpRelative),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
2003-04-27 09:39:52 +00:00
OPCODE(o5_move),
OPCODE(o2_setBitVar),
/* 1C */
2003-04-27 09:39:52 +00:00
OPCODE(o5_startSound),
OPCODE(o2_ifClassOfIs),
2003-04-26 16:37:35 +00:00
OPCODE(o2_walkActorTo),
OPCODE(o2_ifState02),
/* 20 */
OPCODE(o5_stopMusic),
OPCODE(o2_putActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_saveLoadGame),
OPCODE(o2_getActorY),
/* 24 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_loadRoomWithEgo),
OPCODE(o2_drawObject),
OPCODE(o5_setVarRange),
OPCODE(o2_ifNotState04),
/* 28 */
OPCODE(o5_equalZero),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setOwnerOf),
OPCODE(o2_addIndirect),
OPCODE(o5_delayVariable),
/* 2C */
OPCODE(o2_assignVarByte),
OPCODE(o5_putActorInRoom),
OPCODE(o2_delay),
2003-04-26 16:37:35 +00:00
OPCODE(o2_ifNotState04),
/* 30 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_matrixOps),
OPCODE(o2_getBitVar),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setCameraAt),
OPCODE(o2_roomOps),
/* 34 */
OPCODE(o5_getDist),
OPCODE(o2_findObject),
2003-04-26 16:37:35 +00:00
OPCODE(o2_walkActorToObject),
OPCODE(o2_setState01),
/* 38 */
OPCODE(o5_lessOrEqual),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
OPCODE(o5_subtract),
OPCODE(o2_waitForActor),
/* 3C */
2003-04-27 09:39:52 +00:00
OPCODE(o5_stopSound),
2003-04-27 11:38:38 +00:00
OPCODE(o2_setActorElevation),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifNotState01),
/* 40 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_cutscene),
OPCODE(o2_putActor),
OPCODE(o2_startScript),
2003-04-26 16:37:35 +00:00
OPCODE(o2_getActorX),
/* 44 */
OPCODE(o5_isLess),
OPCODE(o2_drawObject),
OPCODE(o5_increment),
OPCODE(o2_setState08),
/* 48 */
OPCODE(o5_isEqual),
2003-04-27 09:39:52 +00:00
OPCODE(o5_faceActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_chainScript),
OPCODE(o2_setObjY),
/* 4C */
OPCODE(o2_waitForSentence),
2003-04-27 09:39:52 +00:00
OPCODE(o5_walkActorToActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_putActorAtObject),
OPCODE(o2_ifState08),
/* 50 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_pickupObject),
OPCODE(o2_animateActor),
OPCODE(o5_actorFollowCamera),
2003-04-20 17:07:25 +00:00
OPCODE(o2_actorSet),
/* 54 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_setObjectName),
OPCODE(o2_actorFromPos),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getActorMoving),
OPCODE(o2_setState02),
/* 58 */
OPCODE(beginOverride),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
OPCODE(o5_add),
OPCODE(o2_setBitVar),
/* 5C */
OPCODE(o2_dummy),
OPCODE(o2_ifClassOfIs),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifNotState02),
/* 60 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_cursorCommand),
2003-04-26 16:37:35 +00:00
OPCODE(o2_putActor),
OPCODE(o5_stopScript),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getActorFacing),
/* 64 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_loadRoomWithEgo),
OPCODE(o2_drawObject),
2003-04-30 11:15:11 +00:00
OPCODE(o5_getClosestObjActor),
OPCODE(o2_clearState04),
/* 68 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_isScriptRunning),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setOwnerOf),
OPCODE(o2_subIndirect),
OPCODE(o2_dummy),
/* 6C */
OPCODE(o2_getObjY),
OPCODE(o5_putActorInRoom),
OPCODE(o2_dummy),
OPCODE(o2_ifState04),
/* 70 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_lights),
OPCODE(o5_getActorCostume),
OPCODE(o5_loadRoom),
2003-04-26 16:37:35 +00:00
OPCODE(o2_roomOps),
/* 74 */
OPCODE(o5_getDist),
OPCODE(o2_findObject),
2003-04-26 16:37:35 +00:00
OPCODE(o2_walkActorToObject),
OPCODE(o2_clearState01),
/* 78 */
OPCODE(o5_isGreater),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
2003-04-21 14:09:16 +00:00
OPCODE(o2_verbOps),
2003-04-26 20:03:38 +00:00
OPCODE(o2_getActorWalkBox),
/* 7C */
2003-04-27 09:39:52 +00:00
OPCODE(o5_isSoundRunning),
2003-04-27 11:38:38 +00:00
OPCODE(o2_setActorElevation),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifNotState01),
/* 80 */
OPCODE(o5_breakHere),
OPCODE(o2_putActor),
2003-04-27 09:39:52 +00:00
OPCODE(o5_startMusic),
OPCODE(o5_getActorRoom),
/* 84 */
OPCODE(o5_isGreaterEqual),
OPCODE(o2_drawObject),
2003-04-27 11:38:38 +00:00
OPCODE(o5_getActorElevation),
OPCODE(o2_setState08),
/* 88 */
OPCODE(o5_isNotEqual),
2003-04-27 09:39:52 +00:00
OPCODE(o5_faceActor),
OPCODE(o2_assignVarWordIndirect),
OPCODE(o2_setObjY),
/* 8C */
2003-04-21 14:09:16 +00:00
OPCODE(o2_resourceRoutines),
2003-04-27 09:39:52 +00:00
OPCODE(o5_walkActorToActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_putActorAtObject),
OPCODE(o2_ifNotState08),
/* 90 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_getObjectOwner),
2003-04-26 16:37:35 +00:00
OPCODE(o2_animateActor),
OPCODE(o2_panCameraTo),
2003-04-20 17:07:25 +00:00
OPCODE(o2_actorSet),
/* 94 */
OPCODE(o5_print),
2003-04-26 16:37:35 +00:00
OPCODE(o2_actorFromPos),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getRandomNr),
OPCODE(o2_setState02),
/* 98 */
OPCODE(o2_restart),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
2003-05-04 17:39:25 +00:00
OPCODE(o5_move),
OPCODE(o2_setBitVar),
/* 9C */
2003-04-27 09:39:52 +00:00
OPCODE(o5_startSound),
OPCODE(o2_ifClassOfIs),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifState02),
/* A0 */
OPCODE(o5_stopObjectCode),
OPCODE(o2_putActor),
2003-04-26 20:03:38 +00:00
OPCODE(o2_saveLoadGame),
2003-04-26 16:37:35 +00:00
OPCODE(o2_getActorY),
/* A4 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_loadRoomWithEgo),
OPCODE(o2_drawObject),
OPCODE(o5_setVarRange),
OPCODE(o2_setState04),
/* A8 */
OPCODE(o5_notEqualZero),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setOwnerOf),
OPCODE(o2_addIndirect),
OPCODE(o2_dummy),
/* AC */
2003-04-27 07:13:03 +00:00
OPCODE(o2_drawSentence),
OPCODE(o5_putActorInRoom),
2003-05-04 17:39:25 +00:00
OPCODE(o2_waitForMessage),
OPCODE(o2_ifNotState04),
/* B0 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_matrixOps),
OPCODE(o2_getBitVar),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setCameraAt),
OPCODE(o2_roomOps),
/* B4 */
OPCODE(o5_getDist),
OPCODE(o2_findObject),
2003-04-26 16:37:35 +00:00
OPCODE(o2_walkActorToObject),
OPCODE(o2_setState02),
/* B8 */
OPCODE(o5_lessOrEqual),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
OPCODE(o5_subtract),
OPCODE(o2_waitForActor),
/* BC */
2003-04-27 09:39:52 +00:00
OPCODE(o5_stopSound),
2003-04-27 11:38:38 +00:00
OPCODE(o2_setActorElevation),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifNotState01),
/* C0 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_endCutscene),
OPCODE(o2_putActor),
OPCODE(o2_startScript),
2003-04-26 16:37:35 +00:00
OPCODE(o2_getActorX),
/* C4 */
OPCODE(o5_isLess),
OPCODE(o2_drawObject),
OPCODE(o5_decrement),
OPCODE(o2_clearState08),
/* C8 */
OPCODE(o5_isEqual),
2003-04-27 09:39:52 +00:00
OPCODE(o5_faceActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_chainScript),
OPCODE(o2_setObjY),
/* CC */
OPCODE(o5_pseudoRoom),
2003-04-27 09:39:52 +00:00
OPCODE(o5_walkActorToActor),
2003-04-26 16:37:35 +00:00
OPCODE(o2_putActorAtObject),
OPCODE(o2_ifState08),
/* D0 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_pickupObject),
OPCODE(o2_animateActor),
OPCODE(o5_actorFollowCamera),
2003-04-20 17:07:25 +00:00
OPCODE(o2_actorSet),
/* D4 */
2003-04-26 16:37:35 +00:00
OPCODE(o2_setObjectName),
OPCODE(o2_actorFromPos),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getActorMoving),
OPCODE(o2_setState02),
/* D8 */
OPCODE(o5_printEgo),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
OPCODE(o5_add),
2003-04-27 07:13:03 +00:00
OPCODE(o2_setBitVar),
/* DC */
OPCODE(o2_dummy),
OPCODE(o2_ifClassOfIs),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifNotState02),
/* E0 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_cursorCommand),
OPCODE(o2_putActor),
OPCODE(o5_stopScript),
2003-04-27 09:39:52 +00:00
OPCODE(o5_getActorFacing),
/* E4 */
2003-04-26 20:03:38 +00:00
OPCODE(o2_loadRoomWithEgo),
OPCODE(o2_drawObject),
2003-04-30 11:15:11 +00:00
OPCODE(o5_getClosestObjActor),
OPCODE(o2_clearState04),
/* E8 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_isScriptRunning),
2003-04-26 16:37:35 +00:00
OPCODE(o2_setOwnerOf),
OPCODE(o2_subIndirect),
OPCODE(o2_dummy),
/* EC */
OPCODE(o2_getObjY),
OPCODE(o5_putActorInRoom),
OPCODE(o2_dummy),
OPCODE(o2_ifState04),
/* F0 */
2003-04-27 09:39:52 +00:00
OPCODE(o5_lights),
OPCODE(o5_getActorCostume),
OPCODE(o5_loadRoom),
2003-04-26 16:37:35 +00:00
OPCODE(o2_roomOps),
/* F4 */
OPCODE(o5_getDist),
OPCODE(o2_findObject),
2003-04-26 16:37:35 +00:00
OPCODE(o2_walkActorToObject),
OPCODE(o2_clearState01),
/* F8 */
OPCODE(o5_isGreater),
2003-04-26 16:37:35 +00:00
OPCODE(o2_doSentence),
2003-04-21 14:09:16 +00:00
OPCODE(o2_verbOps),
2003-04-26 20:03:38 +00:00
OPCODE(o2_getActorWalkBox),
/* FC */
2003-04-27 09:39:52 +00:00
OPCODE(o5_isSoundRunning),
2003-04-27 11:38:38 +00:00
OPCODE(o2_setActorElevation),
OPCODE(o2_walkActorTo),
OPCODE(o2_ifState01)
};
_opcodesV2 = opcodes;
}
#define SENTENCE_SCRIPT 2
void Scumm_v2::executeOpcode(byte i) {
OpcodeProcV2 op = _opcodesV2[i].proc;
(this->*op) ();
}
const char *Scumm_v2::getOpcodeDesc(byte i) {
return _opcodesV2[i].desc;
}
int Scumm_v2::getVar() {
return readVar(fetchScriptByte());
}
2003-05-04 02:10:49 +00:00
void Scumm_v2::decodeParseString() {
byte buffer[256]; // FIXME
byte *ptr = buffer;
byte c;
bool insertSpace = false;
2003-05-04 02:10:49 +00:00
while ((c = fetchScriptByte())) {
insertSpace = (c & 0x80) != 0;
c &= 0x7f;
if (c < 8) {
2003-05-04 02:10:49 +00:00
// Special codes as seen in CHARSET_1 etc. My guess is that they
// have a similar function as the corresponding embedded stuff in modern
// games. Hence for now we convert them to the modern format.
// This might allow us to reuse the existing code.
*ptr++ = 0xFF;
*ptr++ = c;
if (c > 3) {
*ptr++ = 0;
*ptr++ = fetchScriptByte();
}
} else
*ptr++ = c;
if (insertSpace)
*ptr++ = ' ';
2003-05-04 02:10:49 +00:00
}
*ptr = 0;
printf("TODO: Scumm_v2::decodeParseString(\"%s\") from %d\n", buffer, vm.slot[_currentScript].number);
2003-05-14 13:30:52 +00:00
2003-05-14 13:32:43 +00:00
// For now, always use textSlot 0. Not sure if there are any situations where we might
// need to us another one?
int textSlot = 0;
2003-05-14 13:30:52 +00:00
_string[textSlot].xpos = 0;
_string[textSlot].ypos = 0;
_string[textSlot].right = 320;
_string[textSlot].center = false;
_string[textSlot].overhead = false;
_string[textSlot].color = 9; // light blue
2003-05-14 13:30:52 +00:00
_messagePtr = buffer;
switch (textSlot) {
case 0:
actorTalk();
break;
case 1:
drawString(1);
break;
case 2:
unkMessage1();
break;
case 3:
unkMessage2();
break;
}
2003-05-04 02:10:49 +00:00
}
int Scumm_v2::readVar(uint var) {
if (var >= 14 && var <= 16)
var = _scummVars[var];
2003-05-04 02:10:49 +00:00
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)");
debug(6, "readvar(%d) = %d", var, _scummVars[var]);
return _scummVars[var];
2003-05-04 02:10:49 +00:00
}
void Scumm_v2::getResultPosIndirect() {
_resultVarNumber = _scummVars[fetchScriptByte()];
}
void Scumm_v2::getResultPos() {
_resultVarNumber = fetchScriptByte();
}
void Scumm_v2::setStateCommon(byte type) {
int obj = getVarOrDirectWord(0x80);
putState(obj, getState(obj) | type);
}
void Scumm_v2::clearStateCommon(byte type) {
int obj = getVarOrDirectWord(0x80);
putState(obj, getState(obj) & ~type);
}
void Scumm_v2::o2_setState08() {
int obj = getVarOrDirectWord(0x80);
putState(obj, getState(obj) | 0x08);
removeObjectFromRoom(obj);
clearDrawObjectQueue();
}
void Scumm_v2::o2_clearState08() {
int obj = getVarOrDirectWord(0x80);
putState(obj, getState(obj) & ~0x08);
removeObjectFromRoom(obj);
clearDrawObjectQueue();
}
void Scumm_v2::o2_setState04() {
setStateCommon(0x04);
}
void Scumm_v2::o2_clearState04() {
clearStateCommon(0x04);
}
void Scumm_v2::o2_setState02() {
setStateCommon(0x02);
}
void Scumm_v2::o2_clearState02() {
clearStateCommon(0x02);
}
void Scumm_v2::o2_setState01() {
setStateCommon(0x01);
}
void Scumm_v2::o2_clearState01() {
clearStateCommon(0x01);
}
void Scumm_v2::o2_assignVarWordIndirect() {
getResultPosIndirect();
2003-05-04 17:39:25 +00:00
setResult(getVarOrDirectWord(0x80));
}
void Scumm_v2::o2_assignVarByte() {
getResultPos();
setResult(fetchScriptByte());
}
void Scumm_v2::o2_setObjY() {
int obj = getVarOrDirectWord(0x80);
int y = fetchScriptByte();
if (whereIsObject(obj) != WIO_NOT_FOUND) {
ObjectData *od = &_objs[getObjectIndex(obj)];
2003-04-21 12:59:57 +00:00
od->walk_y = (y << 5) | (od->walk_y & 0x1F);
}
}
void Scumm_v2::o2_getObjY() {
int obj = getVarOrDirectWord(0x80);
2003-04-21 12:59:57 +00:00
getResultPos();
if (whereIsObject(obj) != WIO_NOT_FOUND) {
ObjectData *od = &_objs[getObjectIndex(obj)];
2003-04-30 11:15:11 +00:00
setResult(od->walk_y >> 5);
} else {
2003-04-30 11:15:11 +00:00
setResult(0xFF);
}
}
void Scumm_v2::o2_setBitVar() {
2003-05-09 00:57:10 +00:00
byte var = fetchScriptWord();
byte a = getVarOrDirectByte(0x80);
2003-05-09 00:57:10 +00:00
int bit_var = var + a;
int bit_offset = bit_var & 0x0f;
2003-04-27 09:39:52 +00:00
bit_var >>= 4;
2003-05-04 02:10:49 +00:00
if (getVarOrDirectByte(0x40))
_scummVars[bit_var] |= (1 << bit_offset);
else
_scummVars[bit_var] &= ~(1 << bit_offset);
}
void Scumm_v2::o2_getBitVar() {
getResultPos();
2003-05-09 00:57:10 +00:00
byte var = fetchScriptWord();
byte a = getVarOrDirectByte(0x80);
2003-05-09 00:57:10 +00:00
int bit_var = var + a;
int bit_offset = bit_var & 0x0f;
2003-04-27 09:39:52 +00:00
bit_var >>= 4;
setResult((_scummVars[bit_var] & (1 << bit_offset)) ? 1 : 0);
}
void Scumm_v2::ifStateCommon(byte type) {
int obj = getVarOrDirectWord(0x80);
if ((getState(obj) & type) == 0)
o5_jumpRelative();
else
ignoreScriptWord();
}
void Scumm_v2::ifNotStateCommon(byte type) {
int obj = getVarOrDirectWord(0x80);
if ((getState(obj) & type) != 0)
o5_jumpRelative();
else
ignoreScriptWord();
}
void Scumm_v2::o2_ifState08() {
ifStateCommon(0x08);
}
void Scumm_v2::o2_ifNotState08() {
ifNotStateCommon(0x08);
}
void Scumm_v2::o2_ifState04() {
ifStateCommon(0x04);
}
void Scumm_v2::o2_ifNotState04() {
ifNotStateCommon(0x04);
}
void Scumm_v2::o2_ifState02() {
ifStateCommon(0x02);
}
void Scumm_v2::o2_ifNotState02() {
ifNotStateCommon(0x02);
}
void Scumm_v2::o2_ifState01() {
ifStateCommon(0x01);
}
void Scumm_v2::o2_ifNotState01() {
ifNotStateCommon(0x01);
}
void Scumm_v2::o2_addIndirect() {
int a;
getResultPosIndirect();
a = getVarOrDirectWord(0x80);
_scummVars[_resultVarNumber] += a;
}
void Scumm_v2::o2_subIndirect() {
int a;
getResultPosIndirect();
a = getVarOrDirectWord(0x80);
_scummVars[_resultVarNumber] -= a;
}
void Scumm_v2::o2_waitForActor() {
2003-04-21 12:59:57 +00:00
if (derefActorSafe(getVarOrDirectByte(0x80), "o2_waitForActor")->moving) {
_scriptPointer -= 2;
o5_breakHere();
}
}
2003-05-04 17:39:25 +00:00
void Scumm_v2::o2_waitForMessage() {
if (VAR(VAR_HAVE_MSG)) {
2003-05-04 17:39:25 +00:00
_scriptPointer--;
o5_breakHere();
}
}
void Scumm_v2::o2_waitForSentence() {
if (_sentenceNum && !isScriptInUse(SENTENCE_SCRIPT))
2003-05-04 17:39:25 +00:00
return;
_scriptPointer--;
o5_breakHere();
}
2003-04-20 16:59:52 +00:00
void Scumm_v2::o2_actorSet() {
2003-04-20 17:07:25 +00:00
int act = getVarOrDirectByte(0x80);
int arg = getVarOrDirectByte(0x40);
Actor *a = derefActorSafe(act, "actorSet");
int i;
2003-04-20 17:07:25 +00:00
2003-05-04 02:10:49 +00:00
_opcode = fetchScriptByte();
if (!a) {
2003-04-20 17:07:25 +00:00
return;
}
2003-04-20 16:59:52 +00:00
2003-05-04 02:10:49 +00:00
switch (_opcode) {
2003-04-20 17:07:25 +00:00
case 1: // Actor Sound
a->sound[0] = arg;
2003-04-20 16:59:52 +00:00
break;
case 2: // Actor Set Color
i = fetchScriptByte();
a->palette[i] = arg;
a->needRedraw = true;
2003-04-20 16:59:52 +00:00
break;
2003-04-20 17:07:25 +00:00
case 3: // Actor Name
loadPtrToResource(rtActorName, a->number, NULL);
2003-04-20 16:59:52 +00:00
break;
2003-04-20 17:07:25 +00:00
case 4: // Actor Costume
a->setActorCostume(arg);
2003-04-20 16:59:52 +00:00
break;
2003-04-20 17:07:25 +00:00
case 5: // Talk Color
a->talkColor = arg;
2003-04-20 16:59:52 +00:00
break;
2003-05-04 02:10:49 +00:00
default:
warning("o2_actorSet: opcode %d not yet supported", _opcode);
2003-04-20 16:59:52 +00:00
}
}
void Scumm_v2::o2_restart() {
warning("o2_restart NYI");
}
2003-04-20 16:59:52 +00:00
void Scumm_v2::o2_drawObject() {
int obj, idx, i;
ObjectData *od;
uint16 x, y, w, h;
int xpos, ypos;
2003-04-20 16:59:52 +00:00
2003-05-09 01:01:53 +00:00
obj = getVarOrDirectWord(0x80);
2003-04-27 09:03:26 +00:00
xpos = getVarOrDirectByte(0x40);
ypos = getVarOrDirectByte(0x20);
idx = getObjectIndex(obj);
if (idx == -1)
return;
od = &_objs[idx];
if (xpos != 0xFF) {
od->walk_x += (xpos << 3) - od->x_pos;
od->x_pos = xpos << 3;
od->walk_y += (ypos << 3) - od->y_pos;
od->y_pos = ypos << 3;
}
addObjectToDrawQue(idx);
x = od->x_pos;
y = od->y_pos;
w = od->width;
h = od->height;
i = _numLocalObjects;
while (i--) {
if (_objs[i].obj_nr && _objs[i].x_pos == x && _objs[i].y_pos == y && _objs[i].width == w && _objs[i].height == h)
putState(_objs[i].obj_nr, getState(_objs[i].obj_nr) & ~0x08);
}
putState(obj, getState(_objs[obj].obj_nr) | 0x08);
}
2003-04-21 14:09:16 +00:00
void Scumm_v2::o2_resourceRoutines() {
const ResTypes resTypes[] = {
rtNumTypes, // Unknown / invalid
rtNumTypes, // Unknown / invalid
rtCostume,
rtRoom,
rtNumTypes, // Unknown / invalid
rtScript,
rtSound
};
int resid = getVarOrDirectByte(0x80);
int opcode = fetchScriptByte();
2003-04-21 14:09:16 +00:00
ResTypes type = rtNumTypes;
if (0 <= (opcode >> 4) && (opcode >> 4) < (int)ARRAYSIZE(resTypes))
type = resTypes[opcode >> 4];
if (type == rtNumTypes) {
warning("o2_resourceRoutines: unknown restype %d", (opcode >> 4));
return;
}
if (((opcode & 0x0f) == 0) || ((opcode & 0x0f) == 1)) {
if (opcode & 1) {
ensureResourceLoaded(type, resid);
} else {
// Seems the nuke opcodes do nothing?
warning("o2_resourceRoutines: nuking resType %d, id %d does nothing", type, resid);
}
} else {
if (opcode & 1) {
lock(type, resid);
} else {
unlock(type, resid);
}
}
2003-04-21 14:09:16 +00:00
}
void Scumm_v2::o2_verbOps() {
2003-05-14 12:26:23 +00:00
int verb = fetchScriptByte();
int slot, state;
2003-05-14 12:26:23 +00:00
switch (verb) {
2003-04-21 14:09:16 +00:00
case 0: // Delete Verb
2003-05-14 12:26:23 +00:00
slot = getVarOrDirectByte(0x80) + 1;
assert(0 < slot && slot < _maxVerbs);
2003-05-14 12:26:23 +00:00
//printf("o2_verbOps delete slot = %d\n", slot);
killVerb(slot);
break;
2003-04-21 14:09:16 +00:00
case 0xFF: // Verb On/Off
verb = fetchScriptByte();
2003-04-21 14:09:16 +00:00
state = fetchScriptByte();
slot = getVerbSlot(verb, 0);
2003-05-14 12:26:23 +00:00
//printf("o2_verbOps Verb On/Off: verb = %d, slot = %d, state = %d\n", verb, slot, state);
_verbs[slot].curmode = state;
break;
2003-04-21 14:09:16 +00:00
default: { // New Verb
int x = fetchScriptByte() << 3;
int y = fetchScriptByte() << 3;
2003-05-14 12:26:23 +00:00
slot = getVarOrDirectByte(0x80) + 1;
2003-05-14 13:30:52 +00:00
/*int unk =*/ fetchScriptByte(); // ?
2003-05-14 13:30:52 +00:00
//printf("o2_verbOps: verb = %d, slot = %d, x = %d, y = %d, unk = %d, name = %s\n",
// verb, slot, x, y, unk, _scriptPointer);
VerbSlot *vs;
2003-05-14 12:26:23 +00:00
assert(0 < slot && slot < _maxVerbs);
vs = &_verbs[slot];
vs->verbid = verb;
vs->color = 2;
vs->hicolor = 0;
vs->dimcolor = 8;
vs->type = kTextVerbType;
vs->charset_nr = _string[0].t_charset;
vs->curmode = 1;
vs->saveid = 0;
vs->key = 0;
vs->center = 0;
vs->imgindex = 0;
vs->x = x;
vs->y = y;
// It follows the verb name
loadPtrToResource(rtVerb, slot, NULL);
}
break;
2003-04-21 14:09:16 +00:00
}
// FIXME - hack!
drawVerb(slot, 0);
verbMouseOver(0);
2003-04-21 14:09:16 +00:00
}
void Scumm_v2::o2_doSentence() {
int a;
SentenceTab *st;
a = getVarOrDirectByte(0x80);
if (a == 0xFB) {
_sentenceNum = 0;
stopScriptNr(SENTENCE_SCRIPT);
clearClickedStatus();
return;
}
if (a == 0xFC) {
_sentenceNum--;
clearClickedStatus();
return;
}
st = &_sentence[_sentenceNum++];
st->verb = a;
st->unk4 = getVarOrDirectWord(0x40);
st->unk3 = getVarOrDirectWord(0x20);
st->freezeCount = 0;
// TODO
switch(fetchScriptByte()) {
case 1:
// Execute the sentence
_sentenceNum--;
warning("TODO o2_doSentence(%d, %d, %d): execute", st->verb, st->unk4, st->unk3);
// FIXME / TODO: The following is hackish, and probably incomplete, but it works somewhat.
_scummVars[8] = st->verb;
_scummVars[9] = st->unk4;
_scummVars[10] = st->unk3;
runVerbCode(st->unk4, st->verb, 0, 0, NULL);
break;
case 2:
// TODO - print the sentence
_sentenceNum--;
warning("TODO o2_doSentence(%d, %d, %d): print", st->verb, st->unk4, st->unk3);
break;
}
}
void Scumm_v2::o2_drawSentence() {
warning("TODO o2_drawSentence()");
}
void Scumm_v2::o2_ifClassOfIs() {
int act = getVarOrDirectWord(0x80);
int clsop = getVarOrDirectByte(0x40);
2003-04-21 15:28:18 +00:00
if (getObjectIndex(act) == -1) {
o5_jumpRelative();
return;
}
ObjectData *od = &_objs[getObjectIndex(act)];
byte cls = *(getResourceAddress(rtRoom, _currentRoom) + od->OBCDoffset + 10);
if ((cls & clsop) != clsop) {
o5_jumpRelative();
2003-04-27 11:38:38 +00:00
return;
}
2003-04-27 11:38:38 +00:00
ignoreScriptWord();
}
void Scumm_v2::o2_walkActorTo() {
int x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o2_walkActorTo");
x = getVarOrDirectByte(0x40) * 8;
y = getVarOrDirectByte(0x20) * 2;
assert(a);
a->ignoreBoxes = true; // FIXME: Disabling walkboxes
a->startWalkActor(x, y, -1); // for now, just to debug the intro
}
void Scumm_v2::o2_putActor() {
int x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o2_putActor");
x = getVarOrDirectByte(0x40) * 8;
y = getVarOrDirectByte(0x20) * 2;
assert(a);
a->putActor(x, y, a->room);
}
void Scumm_v2::o2_startScript() {
int script = getVarOrDirectByte(0x80);
2003-04-26 16:37:35 +00:00
runScript(script, 0, 0, 0);
}
void Scumm_v2::o2_panCameraTo() {
panCameraTo(getVarOrDirectByte(0x80) * 8, 0); // FIXME: I'm pretty sure we actually pan
// by strip, not X/Y, here. Hence *8
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_walkActorToObject() {
int obj;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o2_walkActorToObject");
2003-04-27 09:39:52 +00:00
obj = getVarOrDirectByte(0x40);
2003-04-26 16:37:35 +00:00
if (whereIsObject(obj) != WIO_NOT_FOUND) {
int x, y, dir;
getObjectXYPos(obj, x, y, dir);
a->startWalkActor(x, y, dir);
}
}
void Scumm_v2::o2_putActorAtObject() {
int obj, x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o2_putActorAtObject");
2003-04-27 09:39:52 +00:00
obj = getVarOrDirectByte(0x40);
2003-04-26 16:37:35 +00:00
if (whereIsObject(obj) != WIO_NOT_FOUND)
getObjectXYPos(obj, x, y);
else {
x = 240;
y = 120;
}
a->putActor(x, y, a->room);
}
2003-04-27 11:38:38 +00:00
void Scumm_v2::o2_setActorElevation() {
int act = getVarOrDirectByte(0x80);
int elevation = getVarOrDirectByte(0x40);
Actor *a = derefActorSafe(act, "o2_setActorElevation");
if (!a)
return;
a->elevation = elevation;
}
2003-04-26 16:37:35 +00:00
void Scumm_v2::o2_animateActor() {
int act = getVarOrDirectByte(0x80);
int anim = getVarOrDirectByte(0x40);
Actor *a = derefActorSafe(act, "o2_animateActor");
if (!a)
return;
a->animateActor(anim);
}
void Scumm_v2::o2_actorFromPos() {
int x, y;
getResultPos();
x = getVarOrDirectByte(0x80) * 8;
y = getVarOrDirectByte(0x40) * 2;
2003-04-30 11:15:11 +00:00
setResult(getActorFromPos(x, y));
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_findObject() {
getResultPos();
int x = getVarOrDirectByte(0x80) * 8;
int y = getVarOrDirectByte(0x40) * 2;
setResult(findObject(x, y));
}
2003-04-26 16:37:35 +00:00
void Scumm_v2::o2_saveLoadGame() {
getResultPos();
byte a = getVarOrDirectByte(0x80);
2003-04-26 16:43:18 +00:00
error("TODO: o2_saveLoadGame(%d)", a);
2003-04-30 11:15:11 +00:00
setResult(0);
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_getActorX() {
int a;
getResultPos();
a = getVarOrDirectByte(0x80);
2003-04-30 11:15:11 +00:00
setResult(getObjX(a));
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_getActorY() {
int a;
getResultPos();
a = getVarOrDirectByte(0x80);
2003-04-30 11:15:11 +00:00
setResult(getObjY(a));
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_loadRoomWithEgo() {
Actor *a;
int obj, room, x, y;
obj = getVarOrDirectWord(0x80);
room = getVarOrDirectByte(0x40);
a = derefActorSafe(VAR(VAR_EGO), "o2_loadRoomWithEgo");
2003-04-26 16:37:35 +00:00
a->putActor(0, 0, room);
_egoPositioned = false;
x = (int16)fetchScriptByte() * 8;
y = (int16)fetchScriptByte() * 2;
2003-04-26 16:37:35 +00:00
startScene(a->room, a, obj);
camera._dest.x = camera._cur.x = a->x;
setCameraAt(a->x, a->y);
setCameraFollows(a);
_fullRedraw = 1;
if (x != -1) {
a->startWalkActor(x, y, -1);
}
runScript(5, 0, 0, 0);
}
void Scumm_v2::o2_setOwnerOf() {
int obj, owner;
obj = getVarOrDirectWord(0x80);
owner = getVarOrDirectByte(0x40);
setOwnerOf(obj, owner);
runHook(0);
}
2003-05-04 00:41:52 +00:00
void Scumm_v2::o2_delay() {
int delay = fetchScriptByte();
delay |= fetchScriptByte() << 8;
delay |= fetchScriptByte() << 16;
delay = 0xFFFFFF - delay;
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = 1;
o5_breakHere();
}
2003-04-26 16:37:35 +00:00
void Scumm_v2::o2_matrixOps() {
int a, b;
a = getVarOrDirectByte(0x80);
b = fetchScriptByte();
setBoxFlags(a, b);
}
void Scumm_v2::o2_setCameraAt() {
setCameraAtEx(getVarOrDirectByte(0x80) * 8); // FIXME: I'm pretty sure we actually pan
// by strip, not X/Y, here. Hence *8
2003-04-26 16:37:35 +00:00
}
void Scumm_v2::o2_roomOps() {
int a = getVarOrDirectByte(0x80);
int b = getVarOrDirectByte(0x40);
_opcode = fetchScriptByte();
switch (_opcode & 0x1F) {
case 1: /* room scroll */
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;
2003-04-26 16:37:35 +00:00
break;
case 2: /* room color */
_shadowPalette[b] = a;
_fullRedraw = true;
break;
}
}
void Scumm_v2::o2_cutscene() {
2003-04-27 11:38:38 +00:00
warning("TODO o2_cutscene()");
2003-04-26 16:37:35 +00:00
}
2003-04-26 20:03:38 +00:00
void Scumm_v2::o2_endCutscene() {
2003-04-27 11:38:38 +00:00
warning("TODO o2_endCutscene()");
2003-04-26 20:03:38 +00:00
}
2003-04-26 16:37:35 +00:00
void Scumm_v2::o2_chainScript() {
int data = getVarOrDirectByte(0x80);
int cur = _currentScript;
vm.slot[cur].number = 0;
vm.slot[cur].status = 0;
_currentScript = 0xFF;
runScript(data, 0, 0, 0);
}
void Scumm_v2::o2_pickupObject() {
int obj = getVarOrDirectWord(0x80);
if (obj < 1) {
error("pickupObject received invalid index %d (script %d)", obj, vm.slot[_currentScript].number);
}
if (getObjectIndex(obj) == -1)
return;
if (whereIsObject(obj) == WIO_INVENTORY) /* Don't take an */
return; /* object twice */
addObjectToInventory(obj, _roomResource);
removeObjectFromRoom(obj);
putOwner(obj, VAR(VAR_EGO));
putState(obj, getState(obj) | 0xA);
2003-04-26 16:37:35 +00:00
clearDrawObjectQueue();
runHook(1);
}
void Scumm_v2::o2_setObjectName() {
int obj = getVarOrDirectWord(0x80);
int size;
int a;
int i = 0;
byte *name = NULL;
byte work[256];
// Read in new name
do {
a = fetchScriptByte();
work[i++] = a;
} while (a);
work[i] = 0;
if (obj < _numActors)
2003-04-26 16:37:35 +00:00
error("Can't set actor %d name with new-name-of", obj);
name = getObjOrActorName(obj);
byte *objptr;
byte offset = 0;
objptr = getOBCDFromObject(obj);
offset = *(objptr + 14);
2003-04-26 16:37:35 +00:00
size = READ_LE_UINT16(objptr) - offset;
if (i >= size) {
warning("New name of object %d too long (old *%s* new *%s*)", obj, name, work);
i = size - 1;
}
memcpy(name, work, i + 1);
runHook(0);
}
2003-04-26 20:03:38 +00:00
void Scumm_v2::o2_cursorCommand() {
2003-05-04 04:30:49 +00:00
int cmd = getVarOrDirectWord(0x80);
int a2 = cmd >> 8;
if (a2 & 4) {warning("TODO: o2_cursorCommand(userface)");} // Toggle verbs on/off, etc
2003-05-04 04:30:49 +00:00
if (a2 & 1) { // Freeze
if (a2 & 8)
freezeScripts(0);
else
unfreezeScripts();
}
if (a2 & 2) { // Cursor Show/Hide
if (a2 & 16)
_cursor.state = 1;
2003-05-04 04:30:49 +00:00
else
_cursor.state = 0;
verbMouseOver(0);
2003-05-04 04:30:49 +00:00
}
2003-04-26 20:03:38 +00:00
}
void Scumm_v2::o2_getActorWalkBox() {
Actor *a;
getResultPos();
a = derefActorSafe(getVarOrDirectByte(0x80), "o2_getActorWalkbox");
if (a)
2003-04-30 11:15:11 +00:00
setResult(a->walkbox);
2003-04-26 20:03:38 +00:00
else
2003-04-30 11:15:11 +00:00
setResult(0);
2003-04-26 20:03:38 +00:00
}
void Scumm_v2::o2_dummy() {
warning("o2_dummy invoked (opcode %d)", _opcode);
}