From 6bd3454ae531d1c704fb5195f39bdbb873774926 Mon Sep 17 00:00:00 2001 From: Paweł Kołodziejski Date: Sat, 26 Apr 2003 16:37:35 +0000 Subject: update for scumm v2 svn-id: r7137 --- scumm/script_v2.cpp | 675 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 556 insertions(+), 119 deletions(-) (limited to 'scumm/script_v2.cpp') diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp index ef8aeab486..8984c74d05 100644 --- a/scumm/script_v2.cpp +++ b/scumm/script_v2.cpp @@ -35,126 +35,126 @@ void Scumm_v2::setupOpcodes() { /* 00 */ OPCODE(o5_stopObjectCode), OPCODE(o2_putActor), - OPCODE(o5_startMusic), - OPCODE(o5_getActorRoom), + OPCODE(o2_startMusic), + OPCODE(o2_getActorRoom), /* 04 */ OPCODE(o2_isGreaterEqual), OPCODE(o2_drawObject), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_setState08), /* 08 */ - OPCODE(o5_isNotEqual), - OPCODE(o5_faceActor), + OPCODE(o2_isNotEqual), + OPCODE(o2_faceActor), OPCODE(o2_assignVarWordDirect), OPCODE(o2_setObjY), /* 0C */ OPCODE(o2_resourceRoutines), - OPCODE(o5_walkActorToActor), - OPCODE(o5_putActorAtObject), + OPCODE(o2_walkActorToActor), + OPCODE(o2_putActorAtObject), OPCODE(o2_ifNotState08), /* 10 */ - OPCODE(o5_getObjectOwner), - OPCODE(o5_animateActor), - OPCODE(o5_panCameraTo), + OPCODE(o2_getObjectOwner), + OPCODE(o2_animateActor), + OPCODE(o2_panCameraTo), OPCODE(o2_actorSet), /* 14 */ - OPCODE(o5_print), - OPCODE(o5_actorFromPos), - OPCODE(o5_getRandomNr), + OPCODE(o2_print), + OPCODE(o2_actorFromPos), + OPCODE(o2_getRandomNr), OPCODE(o2_setState04), /* 18 */ OPCODE(o5_jumpRelative), - OPCODE(o5_doSentence), - OPCODE(o5_move), + OPCODE(o2_doSentence), + OPCODE(o2_move), OPCODE(o2_setBitVar), /* 1C */ - OPCODE(o5_startSound), + OPCODE(o2_startSound), OPCODE(o2_ifClassOfIs), - OPCODE(o5_walkActorTo), + OPCODE(o2_walkActorTo), OPCODE(o2_ifState02), /* 20 */ OPCODE(o5_stopMusic), OPCODE(o2_putActor), - OPCODE(o5_getAnimCounter), - OPCODE(o5_getActorY), + OPCODE(o2_saveLoadGame), + OPCODE(o2_getActorY), /* 24 */ - OPCODE(o5_loadRoomWithEgo), - OPCODE(o5_pickupObject), - OPCODE(o5_setVarRange), + OPCODE(o2_loadRoomWithEgo), + OPCODE(o2_drawObject), + OPCODE(o2_setVarRange), OPCODE(o2_ifNotState04), /* 28 */ OPCODE(o2_equalZero), - OPCODE(o5_setOwnerOf), + OPCODE(o2_setOwnerOf), OPCODE(o2_addDirect), - OPCODE(o5_delayVariable), + OPCODE(o2_delayVariable), /* 2C */ - OPCODE(o2_ifNotState04), - OPCODE(o5_putActorInRoom), - OPCODE(o5_delay), OPCODE(o2_assignVarByte), + OPCODE(o2_putActorInRoom), + OPCODE(o5_delay), + OPCODE(o2_ifNotState04), /* 30 */ - OPCODE(o5_matrixOps), + OPCODE(o2_matrixOps), OPCODE(o2_getBitVar), - OPCODE(o5_setCameraAt), - OPCODE(o5_roomOps), + OPCODE(o2_setCameraAt), + OPCODE(o2_roomOps), /* 34 */ - OPCODE(o5_getDist), - OPCODE(o5_findObject), - OPCODE(o5_walkActorToObject), + OPCODE(o2_getDist), + OPCODE(o2_findObject), + OPCODE(o2_walkActorToObject), OPCODE(o2_setState01), /* 38 */ OPCODE(o2_lessOrEqual), - OPCODE(o5_doSentence), - OPCODE(o5_subtract), + OPCODE(o2_doSentence), + OPCODE(o2_subtract), OPCODE(o2_waitForActor), /* 3C */ OPCODE(o5_stopSound), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_walkActorTo), OPCODE(o2_ifNotState01), /* 40 */ - OPCODE(o5_cutscene), + OPCODE(o2_cutscene), OPCODE(o2_putActor), OPCODE(o2_startScript), - OPCODE(o5_getActorX), + OPCODE(o2_getActorX), /* 44 */ OPCODE(o2_isLess), OPCODE(o2_drawObject), - OPCODE(o5_increment), + OPCODE(o2_increment), OPCODE(o2_setState08), /* 48 */ OPCODE(o2_isEqual), - OPCODE(o5_faceActor), - OPCODE(o5_chainScript), + OPCODE(o2_faceActor), + OPCODE(o2_chainScript), OPCODE(o2_setObjY), /* 4C */ OPCODE(o2_waitForSentence), - OPCODE(o5_walkActorToActor), - OPCODE(o5_putActorAtObject), + OPCODE(o2_walkActorToActor), + OPCODE(o2_putActorAtObject), OPCODE(o2_ifState08), /* 50 */ - OPCODE(o5_pickupObjectOld), - OPCODE(o5_animateActor), - OPCODE(o5_actorFollowCamera), + OPCODE(o2_pickupObject), + OPCODE(o2_animateActor), + OPCODE(o2_actorFollowCamera), OPCODE(o2_actorSet), /* 54 */ - OPCODE(o5_setObjectName), - OPCODE(o5_actorFromPos), - OPCODE(o5_getActorMoving), + OPCODE(o2_setObjectName), + OPCODE(o2_actorFromPos), + OPCODE(o2_getActorMoving), OPCODE(o2_setState02), /* 58 */ OPCODE(beginOverride), - OPCODE(o5_doSentence), - OPCODE(o5_add), + OPCODE(o2_doSentence), + OPCODE(o2_add), OPCODE(o2_setBitVar), /* 5C */ - OPCODE(o5_oldRoomEffect), + OPCODE(o5_dummy), OPCODE(o2_ifClassOfIs), OPCODE(o2_walkActorTo), OPCODE(o2_ifNotState02), /* 60 */ OPCODE(o5_cursorCommand), - OPCODE(o5_putActor), + OPCODE(o2_putActor), OPCODE(o5_stopScript), OPCODE(o5_getActorFacing), /* 64 */ @@ -164,71 +164,71 @@ void Scumm_v2::setupOpcodes() { OPCODE(o2_clearState04), /* 68 */ OPCODE(o5_isScriptRunning), - OPCODE(o5_setOwnerOf), + OPCODE(o2_setOwnerOf), OPCODE(o2_subDirect), OPCODE(o5_dummy), /* 6C */ OPCODE(o2_getObjY), - OPCODE(o5_putActorInRoom), + OPCODE(o2_putActorInRoom), OPCODE(o5_dummy), OPCODE(o2_ifState04), /* 70 */ OPCODE(o5_lights), OPCODE(o5_getActorCostume), OPCODE(o5_loadRoom), - OPCODE(o5_roomOps), + OPCODE(o2_roomOps), /* 74 */ - OPCODE(o5_getDist), - OPCODE(o5_findObject), - OPCODE(o5_walkActorToObject), + OPCODE(o2_getDist), + OPCODE(o2_findObject), + OPCODE(o2_walkActorToObject), OPCODE(o2_clearState01), /* 78 */ OPCODE(o2_isGreater), - OPCODE(o5_doSentence), + OPCODE(o2_doSentence), OPCODE(o2_verbOps), OPCODE(o5_getActorWalkBox), /* 7C */ OPCODE(o5_isSoundRunning), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_walkActorTo), OPCODE(o2_ifNotState01), /* 80 */ OPCODE(o5_breakHere), OPCODE(o2_putActor), - OPCODE(o5_startMusic), - OPCODE(o5_getActorRoom), + OPCODE(o2_startMusic), + OPCODE(o2_getActorRoom), /* 84 */ OPCODE(o2_isGreaterEqual), OPCODE(o2_drawObject), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_setState08), /* 88 */ OPCODE(o2_isNotEqual), - OPCODE(o5_faceActor), + OPCODE(o2_faceActor), OPCODE(o2_assignVarWordDirect), OPCODE(o2_setObjY), /* 8C */ OPCODE(o2_resourceRoutines), - OPCODE(o5_walkActorToActor), - OPCODE(o5_putActorAtObject), + OPCODE(o2_walkActorToActor), + OPCODE(o2_putActorAtObject), OPCODE(o2_ifNotState08), /* 90 */ - OPCODE(o5_getObjectOwner), - OPCODE(o5_animateActor), - OPCODE(o5_panCameraTo), + OPCODE(o2_getObjectOwner), + OPCODE(o2_animateActor), + OPCODE(o2_panCameraTo), OPCODE(o2_actorSet), /* 94 */ - OPCODE(o5_print), - OPCODE(o5_actorFromPos), - OPCODE(o5_getRandomNr), + OPCODE(o2_print), + OPCODE(o2_actorFromPos), + OPCODE(o2_getRandomNr), OPCODE(o2_setState02), /* 98 */ OPCODE(o2_restart), - OPCODE(o5_doSentence), + OPCODE(o2_doSentence), OPCODE(o2_assignVarWord), OPCODE(o2_setBitVar), /* 9C */ - OPCODE(o5_startSound), + OPCODE(o2_startSound), OPCODE(o2_ifClassOfIs), OPCODE(o2_walkActorTo), OPCODE(o2_ifState02), @@ -236,47 +236,47 @@ void Scumm_v2::setupOpcodes() { OPCODE(o5_stopObjectCode), OPCODE(o2_putActor), OPCODE(o5_getAnimCounter), - OPCODE(o5_getActorY), + OPCODE(o2_getActorY), /* A4 */ OPCODE(o5_loadRoomWithEgo), OPCODE(o5_pickupObject), - OPCODE(o5_setVarRange), + OPCODE(o2_setVarRange), OPCODE(o2_setState04), /* A8 */ OPCODE(o2_notEqualZero), - OPCODE(o5_setOwnerOf), + OPCODE(o2_setOwnerOf), OPCODE(o2_addDirect), OPCODE(o5_dummy), /* AC */ OPCODE(o5_delay), - OPCODE(o5_putActorInRoom), + OPCODE(o2_putActorInRoom), OPCODE(o2_waitForSentence), OPCODE(o2_ifNotState04), /* B0 */ - OPCODE(o5_matrixOps), + OPCODE(o2_matrixOps), OPCODE(o2_getBitVar), - OPCODE(o5_setCameraAt), - OPCODE(o5_roomOps), + OPCODE(o2_setCameraAt), + OPCODE(o2_roomOps), /* B4 */ - OPCODE(o5_getDist), - OPCODE(o5_findObject), - OPCODE(o5_walkActorToObject), + OPCODE(o2_getDist), + OPCODE(o2_findObject), + OPCODE(o2_walkActorToObject), OPCODE(o2_setState02), /* B8 */ OPCODE(o2_lessOrEqual), - OPCODE(o5_doSentence), - OPCODE(o5_subtract), + OPCODE(o2_doSentence), + OPCODE(o2_subtract), OPCODE(o2_waitForActor), /* BC */ OPCODE(o5_stopSound), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_walkActorTo), OPCODE(o2_ifNotState01), /* C0 */ OPCODE(o5_endCutscene), OPCODE(o2_putActor), OPCODE(o2_startScript), - OPCODE(o5_getActorX), + OPCODE(o2_getActorX), /* C4 */ OPCODE(o2_isLess), OPCODE(o2_drawObject), @@ -284,31 +284,31 @@ void Scumm_v2::setupOpcodes() { OPCODE(o2_clearState08), /* C8 */ OPCODE(o2_isEqual), - OPCODE(o5_faceActor), - OPCODE(o5_chainScript), + OPCODE(o2_faceActor), + OPCODE(o2_chainScript), OPCODE(o2_setObjY), /* CC */ OPCODE(o5_pseudoRoom), - OPCODE(o5_walkActorToActor), - OPCODE(o5_putActorAtObject), + OPCODE(o2_walkActorToActor), + OPCODE(o2_putActorAtObject), OPCODE(o2_ifState08), /* D0 */ - OPCODE(o5_pickupObjectOld), - OPCODE(o5_animateActor), - OPCODE(o5_actorFollowCamera), + OPCODE(o2_pickupObject), + OPCODE(o2_animateActor), + OPCODE(o2_actorFollowCamera), OPCODE(o2_actorSet), /* D4 */ - OPCODE(o5_setObjectName), - OPCODE(o5_actorFromPos), - OPCODE(o5_getActorMoving), + OPCODE(o2_setObjectName), + OPCODE(o2_actorFromPos), + OPCODE(o2_getActorMoving), OPCODE(o2_setState02), /* D8 */ OPCODE(o2_printEgo), - OPCODE(o5_doSentence), - OPCODE(o5_add), + OPCODE(o2_doSentence), + OPCODE(o2_add), OPCODE(o5_divide), /* DC */ - OPCODE(o5_oldRoomEffect), + OPCODE(o5_dummy), OPCODE(o2_ifClassOfIs), OPCODE(o2_walkActorTo), OPCODE(o2_ifNotState02), @@ -324,32 +324,32 @@ void Scumm_v2::setupOpcodes() { OPCODE(o2_clearState04), /* E8 */ OPCODE(o5_isScriptRunning), - OPCODE(o5_setOwnerOf), + OPCODE(o2_setOwnerOf), OPCODE(o2_subDirect), OPCODE(o5_dummy), /* EC */ OPCODE(o2_getObjY), - OPCODE(o5_putActorInRoom), + OPCODE(o2_putActorInRoom), OPCODE(o5_dummy), OPCODE(o2_ifState04), /* F0 */ OPCODE(o5_lights), OPCODE(o5_getActorCostume), OPCODE(o5_loadRoom), - OPCODE(o5_roomOps), + OPCODE(o2_roomOps), /* F4 */ - OPCODE(o5_getDist), - OPCODE(o5_findObject), - OPCODE(o5_walkActorToObject), + OPCODE(o2_getDist), + OPCODE(o2_findObject), + OPCODE(o2_walkActorToObject), OPCODE(o2_clearState01), /* F8 */ OPCODE(o2_isGreater), - OPCODE(o5_doSentence), + OPCODE(o2_doSentence), OPCODE(o2_verbOps), OPCODE(o5_getActorWalkBox), /* FC */ OPCODE(o5_isSoundRunning), - OPCODE(o5_getActorElevation), + OPCODE(o2_getActorElevation), OPCODE(o2_walkActorTo), OPCODE(o2_ifState01) }; @@ -746,7 +746,7 @@ void Scumm_v2::o2_verbOps() { } void Scumm_v2::o2_isEqual() { - int a = readVar(fetchScriptByte()); + int a = getVar(); int b = getVarOrDirectWord(0x80); if (b == a) @@ -757,7 +757,7 @@ void Scumm_v2::o2_isEqual() { } void Scumm_v2::o2_isGreater() { - int16 a = readVar(fetchScriptByte()); + int16 a = getVar(); int16 b = getVarOrDirectWord(0x80); if (b > a) @@ -767,7 +767,7 @@ void Scumm_v2::o2_isGreater() { } void Scumm_v2::o2_isGreaterEqual() { - int16 a = readVar(fetchScriptByte()); + int16 a = getVar(); int16 b = getVarOrDirectWord(0x80); if (b >= a) @@ -777,7 +777,7 @@ void Scumm_v2::o2_isGreaterEqual() { } void Scumm_v2::o2_isLess() { - int16 a = readVar(fetchScriptByte()); + int16 a = getVar(); int16 b = getVarOrDirectWord(0x80); if (b < a) @@ -787,7 +787,7 @@ void Scumm_v2::o2_isLess() { } void Scumm_v2::o2_lessOrEqual() { - int16 a = readVar(fetchScriptByte()); + int16 a = getVar(); int16 b = getVarOrDirectWord(0x80); if (b <= a) @@ -797,7 +797,7 @@ void Scumm_v2::o2_lessOrEqual() { } void Scumm_v2::o2_isNotEqual() { - int16 a = readVar(fetchScriptByte()); + int16 a = getVar(); int16 b = getVarOrDirectWord(0x80); if (b != a) @@ -807,7 +807,7 @@ void Scumm_v2::o2_isNotEqual() { } void Scumm_v2::o2_notEqualZero() { - int a = readVar(fetchScriptByte()); + int a = getVar(); if (a != 0) ignoreScriptWord(); @@ -816,7 +816,7 @@ void Scumm_v2::o2_notEqualZero() { } void Scumm_v2::o2_equalZero() { - int a = readVar(fetchScriptByte()); + int a = getVar(); if (a == 0) ignoreScriptWord(); @@ -907,5 +907,442 @@ void Scumm_v2::o2_putActor() { void Scumm_v2::o2_startScript() { int script = getVarOrDirectByte(0x80); - runScript(script, 0, 0, 0); // FIXME: Need to confirm runScript parameters/mode + runScript(script, 0, 0, 0); +} + +void Scumm_v2::o2_panCameraTo() { + panCameraTo(getVarOrDirectByte(0x80), 0); +} + +void Scumm_v2::o2_move() { + getResultPos(); + _vars[_resultVarNumber] = getVarOrDirectWord(0x80); +} + +void Scumm_v2::o2_startMusic() { + _sound->addSoundToQueue(getVarOrDirectByte(0x80)); +} + +void Scumm_v2::o2_getActorRoom() { + int act; + Actor *a; + getResultPos(); + act = getVarOrDirectByte(0x80); + + a = derefActorSafe(act, "o2_getActorRoom"); + if (!a) { + warning("Invalid actor %d in o2_getActorRoom", act); + return; + } + + _vars[_resultVarNumber] = a->room; +} + +void Scumm_v2::o2_getActorElevation() { + int act; + Actor *a; + getResultPos(); + act = getVarOrDirectByte(0x80); + + a = derefActorSafe(act, "o2_getActorElevation"); + if (!a) { + warning("Invalid actor %d in o2_getActorElevation", act); + return; + } + + _vars[_resultVarNumber] = a->elevation; +} + +void Scumm_v2::o2_walkActorToActor() { + int b, x, y; + Actor *a, *a2; + int nr; + int nr2 = getVarOrDirectByte(0x80); + a = derefActorSafe(nr2, "o2_walkActorToActor"); + if (!a) + return; + + if (!a->isInCurrentRoom()) { + getVarOrDirectByte(0x40); + fetchScriptByte(); + return; + } + + nr = getVarOrDirectByte(0x40); + a2 = derefActorSafe(nr, "o2_walkActorToActor(2)"); + if (!a2) + return; + + if (!a2->isInCurrentRoom()) { + fetchScriptByte(); + return; + } + b = fetchScriptByte(); /* distance from actor */ + if (b == 0xFF) { + b = a2->scalex * a->width / 0xFF; + b = b + b / 2; + } + x = a2->x; + y = a2->y; + if (x < a->x) + x += b; + else + x -= b; + + a->startWalkActor(x, y, -1); +} + +void Scumm_v2::o2_walkActorToObject() { + int obj; + Actor *a; + + a = derefActorSafe(getVarOrDirectByte(0x80), "o2_walkActorToObject"); + obj = getVarOrDirectWord(0x40); + if (whereIsObject(obj) != WIO_NOT_FOUND) { + int x, y, dir; + getObjectXYPos(obj, x, y, dir); + a->startWalkActor(x, y, dir); + } +} + +void Scumm_v2::o2_faceActor() { + int act, obj; + Actor *a; + act = getVarOrDirectByte(0x80); + obj = getVarOrDirectWord(0x40); + + a = derefActorSafe(act, "o2_faceActor"); + assert(a); + + a->faceToObject(obj); +} + +void Scumm_v2::o2_putActorAtObject() { + int obj, x, y; + Actor *a; + + a = derefActorSafe(getVarOrDirectByte(0x80), "o2_putActorAtObject"); + obj = getVarOrDirectWord(0x40); + if (whereIsObject(obj) != WIO_NOT_FOUND) + getObjectXYPos(obj, x, y); + else { + x = 240; + y = 120; + } + a->putActor(x, y, a->room); +} + +void Scumm_v2::o2_getObjectOwner() { + getResultPos(); + _vars[_resultVarNumber] = getOwner(getVarOrDirectWord(0x80)); +} + +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_print() { + _actorToPrintStrFor = getVarOrDirectByte(0x80); + decodeParseString(); +} + +void Scumm_v2::o2_actorFromPos() { + int x, y; + getResultPos(); + x = getVarOrDirectByte(0x80); + y = getVarOrDirectByte(0x40); + _vars[_resultVarNumber] = getActorFromPos(x, y); +} + +void Scumm_v2::o2_getRandomNr() { + getResultPos(); + _vars[_resultVarNumber] = _rnd.getRandomNumber(getVarOrDirectByte(0x80)); +} + +void Scumm_v2::o2_isScriptRunning() { + getResultPos(); + _vars[_resultVarNumber] = isScriptRunning(getVarOrDirectByte(0x80)); +} + +void Scumm_v2::o2_getVerbEntrypoint() { + int a, b; + getResultPos(); + a = getVarOrDirectWord(0x80); + b = getVarOrDirectWord(0x40); + + _vars[_resultVarNumber] = getVerbEntrypoint(a, b); +} + +void Scumm_v2::o2_startSound() { + _vars[VAR_MUSIC_FLAG] = 0; + _sound->addSoundToQueue(getVarOrDirectByte(0x80)); } + +void Scumm_v2::o2_saveLoadGame() { + getResultPos(); + byte a = getVarOrDirectByte(0x80); + + error("TODO: o2_saveLoadGame()"); + _vars[_resultVarNumber] = 0; +} + +void Scumm_v2::o2_getActorX() { + int a; + getResultPos(); + + a = getVarOrDirectByte(0x80); + _vars[_resultVarNumber] = getObjX(a); +} + +void Scumm_v2::o2_getActorY() { + int a; + getResultPos(); + + a = getVarOrDirectByte(0x80); + _vars[_resultVarNumber] = getObjY(a); +} + +void Scumm_v2::o2_loadRoomWithEgo() { + Actor *a; + int obj, room, x, y; + + obj = getVarOrDirectWord(0x80); + room = getVarOrDirectByte(0x40); + + a = derefActorSafe(_vars[VAR_EGO], "o2_loadRoomWithEgo"); + + a->putActor(0, 0, room); + _egoPositioned = false; + + x = (int16)fetchScriptByte(); + y = (int16)fetchScriptByte(); + + 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_setVarRange() { + int a, b; + + getResultPos(); + a = fetchScriptByte(); + do { + if (_opcode & 0x80) + b = fetchScriptWord(); + else + b = fetchScriptByte(); + + _vars[_resultVarNumber++] = b; + } while (--a); +} + +void Scumm_v2::o2_setOwnerOf() { + int obj, owner; + + obj = getVarOrDirectWord(0x80); + owner = getVarOrDirectByte(0x40); + + setOwnerOf(obj, owner); + runHook(0); +} + +void Scumm_v2::o2_delayVariable() { + vm.slot[_currentScript].delay = getVar(); + vm.slot[_currentScript].status = 1; + o5_breakHere(); +} + +void Scumm_v2::o2_putActorInRoom() { + int room; + Actor *a; + + a = derefActorSafe(getVarOrDirectByte(0x80), "o2_putActorInRoom"); + room = getVarOrDirectByte(0x40); + + if (a == NULL) + return; + + a->room = room; + if (!room) + a->putActor(0, 0, 0); +} + +void Scumm_v2::o2_matrixOps() { + int a, b; + + a = getVarOrDirectByte(0x80); + b = fetchScriptByte(); + setBoxFlags(a, b); +} + +void Scumm_v2::o2_setCameraAt() { + setCameraAtEx(getVarOrDirectByte(0x80)); +} + +void Scumm_v2::o2_roomOps() { + int a = getVarOrDirectByte(0x80); + int b = getVarOrDirectByte(0x40); + + _opcode = fetchScriptByte(); + switch (_opcode & 0x1F) { + case 1: /* room scroll */ + if (a < (_realWidth / 2)) + a = (_realWidth / 2); + if (b < (_realWidth / 2)) + b = (_realWidth / 2); + if (a > _scrWidth - (_realWidth / 2)) + a = _scrWidth - (_realWidth / 2); + if (b > _scrWidth - (_realWidth / 2)) + b = _scrWidth - (_realWidth / 2); + _vars[VAR_CAMERA_MIN_X] = a; + _vars[VAR_CAMERA_MAX_X] = b; + break; + case 2: /* room color */ + _shadowPalette[b] = a; + _fullRedraw = true; + break; + } +} + +void Scumm_v2::o2_getDist() { + getResultPos(); + int o1 = getVarOrDirectWord(0x80); + int o2 = getVarOrDirectWord(0x40); + _vars[_resultVarNumber] = getObjActToObjActDist(o1, o2); +} + +void Scumm_v2::o2_findObject() { + getResultPos(); + int x = getVarOrDirectWord(0x80); + int y = getVarOrDirectWord(0x40); + _vars[_resultVarNumber] = findObject(x, y); +} + +void Scumm_v2::o2_subtract() { + int a; + getResultPos(); + a = getVarOrDirectWord(0x80); + _vars[_resultVarNumber] -= a; +} + +void Scumm_v2::o2_cutscene() { + // TODO +} + +void Scumm_v2::o2_increment() { + getResultPos(); + _vars[_resultVarNumber]++; +} + +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, _vars[VAR_EGO]); + putClass(obj, 32, 1); + putState(obj, 1); + clearDrawObjectQueue(); + runHook(1); +} + +void Scumm_v2::o2_actorFollowCamera() { + actorFollowCamera(getVarOrDirectByte(0x80)); +} + +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 < NUM_ACTORS) + 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 + 18); + 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); +} + +void Scumm_v2::o2_getActorMoving() { + int act; + Actor *a; + getResultPos(); + act = getVarOrDirectByte(0x80); + + a = derefActorSafe(act, "o2_getActorMoving"); + if (!a) { + warning("Invalid actor %d in o2_getActorMoving", act); + return; + } + + _vars[_resultVarNumber] = a->moving; +} + +void Scumm_v2::o2_add() { + int a; + getResultPos(); + a = getVarOrDirectWord(0x80); + _vars[_resultVarNumber] += a; +} + -- cgit v1.2.3