scummvm/engines/scumm/script.cpp

1393 lines
35 KiB
C++
Raw Normal View History

2001-10-09 14:30:12 +00:00
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
2006-01-18 17:39:49 +00:00
* Copyright (C) 2001-2006 The ScummVM project
2001-10-09 14:30:12 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2001-10-09 14:30:12 +00:00
*
* $URL$
* $Id$
2001-10-09 14:30:12 +00:00
*
*/
#include "common/stdafx.h"
#include "common/config-manager.h"
2003-09-11 10:32:15 +00:00
#include "common/util.h"
2003-09-11 10:32:15 +00:00
#include "scumm/actor.h"
#include "scumm/intern.h"
2003-09-11 10:32:15 +00:00
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/util.h"
2003-09-11 10:32:15 +00:00
#include "scumm/scumm.h"
#include "scumm/verbs.h"
2001-10-09 14:30:12 +00:00
namespace Scumm {
/* Start executing script 'script' with the given parameters */
void ScummEngine::runScript(int script, bool freezeResistant, bool recursive, int *lvarptr, int cycle) {
ScriptSlot *s;
2001-10-09 14:30:12 +00:00
byte *scriptPtr;
uint32 scriptOffs;
byte scriptType;
int slot;
if (!script)
2001-10-09 14:30:12 +00:00
return;
if (!recursive)
stopScript(script);
2001-10-16 10:01:48 +00:00
if (script < _numGlobalScripts) {
scriptPtr = getResourceAddress(rtScript, script);
2002-04-11 15:22:02 +00:00
scriptOffs = _resourceHeaderSize;
scriptType = WIO_GLOBAL;
debugC(DEBUG_SCRIPTS, "runScript(Global-%d) from %d-%d", script,
vm.slot[_currentScript].number, _roomResource);
2001-10-09 14:30:12 +00:00
} else {
scriptOffs = _localScriptOffsets[script - _numGlobalScripts];
2001-10-09 14:30:12 +00:00
if (scriptOffs == 0)
error("Local script %d is not in room %d", script, _roomResource);
scriptType = WIO_LOCAL;
debugC(DEBUG_SCRIPTS, "runScript(%d) from %d-%d", script,
vm.slot[_currentScript].number, _roomResource);
2001-10-09 14:30:12 +00:00
}
if (cycle == 0)
cycle = (_game.heversion >= 90) ? VAR(VAR_SCRIPT_CYCLE) : 1;
2001-10-09 14:30:12 +00:00
slot = getScriptSlot();
s = &vm.slot[slot];
s->number = script;
s->offs = scriptOffs;
2002-12-09 01:27:40 +00:00
s->status = ssRunning;
s->where = scriptType;
s->freezeResistant = freezeResistant;
s->recursive = recursive;
2001-10-09 14:30:12 +00:00
s->freezeCount = 0;
2002-08-25 11:35:13 +00:00
s->delayFrameCount = 0;
s->cycle = cycle;
2001-10-09 14:30:12 +00:00
initializeLocals(slot, lvarptr);
2001-10-09 14:30:12 +00:00
runScriptNested(slot);
}
void ScummEngine::runObjectScript(int object, int entry, bool freezeResistant, bool recursive, int *vars, int slot, int cycle) {
ScriptSlot *s;
uint32 obcd;
int where, offs;
if (!object)
return;
if (!recursive && (_game.version >= 3))
stopObjectScript(object);
where = whereIsObject(object);
if (where == WIO_NOT_FOUND) {
warning("Code for object %d not in room %d", object, _roomResource);
return;
}
obcd = getOBCDOffs(object);
// Find a free object slot, unless one was specified
if (slot == -1)
slot = getScriptSlot();
offs = getVerbEntrypoint(object, entry);
if (offs == 0)
return;
if (cycle == 0)
cycle = (_game.heversion >= 90) ? VAR(VAR_SCRIPT_CYCLE) : 1;
s = &vm.slot[slot];
s->number = object;
s->offs = obcd + offs;
s->status = ssRunning;
s->where = where;
s->freezeResistant = freezeResistant;
s->recursive = recursive;
s->freezeCount = 0;
s->delayFrameCount = 0;
s->cycle = cycle;
initializeLocals(slot, vars);
runScriptNested(slot);
}
void ScummEngine::initializeLocals(int slot, int *vars) {
int i;
if (!vars) {
for (i = 0; i < 25; i++)
vm.localvar[slot][i] = 0;
} else {
for (i = 0; i < 25; i++)
vm.localvar[slot][i] = vars[i];
}
}
int ScummEngine::getVerbEntrypoint(int obj, int entry) {
2003-05-28 20:01:47 +00:00
const byte *objptr, *verbptr;
int verboffs;
// WORKAROUND for bug #1555938: Disallow pulling the rope if it's
// already in the player's inventory.
if (_game.id == GID_MONKEY2 && obj == 1047 && entry == 6 && whereIsObject(obj) == WIO_INVENTORY) {
return 0;
}
if (whereIsObject(obj) == WIO_NOT_FOUND)
return 0;
objptr = getOBCDFromObject(obj);
assert(objptr);
if (_game.version == 0)
verbptr = objptr + 14;
else if (_game.version <= 2)
verbptr = objptr + 15;
else if (_game.features & GF_OLD_BUNDLE)
verbptr = objptr + 17;
else if (_game.features & GF_SMALL_HEADER)
verbptr = objptr + 19;
else
verbptr = findResource(MKID_BE('VERB'), objptr);
assert(verbptr);
verboffs = verbptr - objptr;
if (!(_game.features & GF_SMALL_HEADER))
verbptr += _resourceHeaderSize;
if (_game.version == 8) {
2003-05-28 20:01:47 +00:00
const uint32 *ptr = (const uint32 *)verbptr;
uint32 verb;
do {
verb = READ_LE_UINT32(ptr);
if (!verb)
return 0;
if (verb == (uint32)entry || verb == 0xFFFFFFFF)
break;
ptr += 2;
} while (1);
return verboffs + 8 + READ_LE_UINT32(ptr + 1);
} else if (_game.version <= 2) {
do {
if (!*verbptr)
return 0;
if (*verbptr == entry || *verbptr == 0xFF)
break;
verbptr += 2;
} while (1);
return *(verbptr + 1);
} else {
do {
if (!*verbptr)
return 0;
if (*verbptr == entry || *verbptr == 0xFF)
break;
verbptr += 3;
} while (1);
if (_game.features & GF_SMALL_HEADER)
return READ_LE_UINT16(verbptr + 1);
else
return verboffs + READ_LE_UINT16(verbptr + 1);
}
}
/* Stop script 'script' */
void ScummEngine::stopScript(int script) {
2001-10-09 14:30:12 +00:00
ScriptSlot *ss;
int i;
2001-10-09 14:30:12 +00:00
if (script == 0)
2001-10-09 14:30:12 +00:00
return;
ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
if (script == ss->number && ss->status != ssDead &&
2003-05-18 23:19:43 +00:00
(ss->where == WIO_GLOBAL || ss->where == WIO_LOCAL)) {
if (ss->cutsceneOverride)
if (_game.version >= 5)
error("Script %d stopped with active cutscene/override", script);
ss->number = 0;
ss->status = ssDead;
nukeArrays(i);
if (_currentScript == i)
_currentScript = 0xFF;
}
2001-10-09 14:30:12 +00:00
}
for (i = 0; i < vm.numNestedScripts; ++i) {
if (vm.nest[i].number == script &&
(vm.nest[i].where == WIO_GLOBAL || vm.nest[i].where == WIO_LOCAL)) {
nukeArrays(vm.nest[i].slot);
vm.nest[i].number = 0xFF;
vm.nest[i].slot = 0xFF;
vm.nest[i].where = 0xFF;
2001-10-09 14:30:12 +00:00
}
2003-09-10 14:43:42 +00:00
}
2001-10-09 14:30:12 +00:00
}
/* Stop an object script 'script'*/
void ScummEngine::stopObjectScript(int script) {
2001-10-09 14:30:12 +00:00
ScriptSlot *ss;
NestedScript *nest;
int i, num;
2001-10-09 14:30:12 +00:00
if (script == 0)
2001-10-09 14:30:12 +00:00
return;
ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
2002-12-25 19:06:31 +00:00
if (script == ss->number && ss->status != ssDead &&
(ss->where == WIO_ROOM || ss->where == WIO_INVENTORY || ss->where == WIO_FLOBJECT)) {
2001-10-16 10:01:48 +00:00
if (ss->cutsceneOverride)
if (_game.version >= 5)
error("Object %d stopped with active cutscene/override", script);
2001-10-16 10:01:48 +00:00
ss->number = 0;
ss->status = ssDead;
nukeArrays(i);
2001-10-16 10:01:48 +00:00
if (_currentScript == i)
_currentScript = 0xFF;
}
2001-10-09 14:30:12 +00:00
}
2003-05-18 21:03:57 +00:00
nest = vm.nest;
2003-09-11 10:32:15 +00:00
num = vm.numNestedScripts;
2001-10-09 14:30:12 +00:00
2003-09-10 14:43:42 +00:00
while (num > 0) {
if (nest->number == script &&
(nest->where == WIO_ROOM || nest->where == WIO_INVENTORY || nest->where == WIO_FLOBJECT)) {
nukeArrays(nest->slot);
2001-10-16 10:01:48 +00:00
nest->number = 0xFF;
2001-10-09 14:30:12 +00:00
nest->slot = 0xFF;
nest->where = 0xFF;
2001-10-09 14:30:12 +00:00
}
2003-09-10 14:43:42 +00:00
nest++;
num--;
}
2001-10-09 14:30:12 +00:00
}
/* Return a free script slot */
int ScummEngine::getScriptSlot() {
ScriptSlot *s;
2001-10-09 14:30:12 +00:00
int i;
for (i = 1; i < NUM_SCRIPT_SLOT; i++) {
s = &vm.slot[i];
if (s->status == ssDead)
2001-10-09 14:30:12 +00:00
return i;
}
2001-10-26 17:34:50 +00:00
error("Too many scripts running, %d max", NUM_SCRIPT_SLOT);
2002-05-05 18:10:29 +00:00
return -1;
2001-10-09 14:30:12 +00:00
}
/* Run script 'script' nested - eg, within the parent script.*/
void ScummEngine::runScriptNested(int script) {
2001-10-09 14:30:12 +00:00
NestedScript *nest;
ScriptSlot *slot;
updateScriptPtr();
2003-09-11 10:32:15 +00:00
nest = &vm.nest[vm.numNestedScripts];
2001-10-09 14:30:12 +00:00
if (_currentScript == 0xFF) {
2001-10-09 14:30:12 +00:00
nest->number = 0xFF;
nest->where = 0xFF;
2001-10-09 14:30:12 +00:00
} else {
2003-06-25 20:16:47 +00:00
// Store information about the currently running script
2001-10-09 14:30:12 +00:00
slot = &vm.slot[_currentScript];
nest->number = slot->number;
nest->where = slot->where;
2001-10-09 14:30:12 +00:00
nest->slot = _currentScript;
}
2003-09-11 10:32:15 +00:00
vm.numNestedScripts++;
2003-09-11 10:32:15 +00:00
if (vm.numNestedScripts > ARRAYSIZE(vm.nest))
2001-10-09 14:30:12 +00:00
error("Too many nested scripts");
_currentScript = script;
getScriptBaseAddress();
getScriptEntryPoint();
executeScript();
if (vm.numNestedScripts != 0)
vm.numNestedScripts--;
2001-10-09 14:30:12 +00:00
if (nest->number != 0xFF) {
2003-06-25 20:16:47 +00:00
// Try to resume the script which called us, if its status has not changed
// since it invoked us. In particular, we only resume it if it hasn't been
// stopped in the meantime, and if it did not already move on.
2001-10-09 14:30:12 +00:00
slot = &vm.slot[nest->slot];
if (slot->number == nest->number && slot->where == nest->where &&
slot->status != ssDead && (slot->freezeCount == 0 ||
_game.version <= 2)) {
2001-10-09 14:30:12 +00:00
_currentScript = nest->slot;
getScriptBaseAddress();
getScriptEntryPoint();
return;
}
}
_currentScript = 0xFF;
}
void ScummEngine::updateScriptPtr() {
2001-10-09 14:30:12 +00:00
if (_currentScript == 0xFF)
return;
vm.slot[_currentScript].offs = _scriptPointer - _scriptOrgPointer;
}
/* Nuke arrays based on script */
void ScummEngine::nukeArrays(byte scriptSlot) {
int i;
if (_game.heversion == 0 || scriptSlot == 0)
return;
for (i = 1; i < _numArray; i++) {
if (_arraySlot[i] == scriptSlot) {
_res->nukeResource(rtString, i);
2004-08-02 07:47:05 +00:00
_arraySlot[i] = 0;
}
}
}
/* Get the code pointer to a script */
void ScummEngine::getScriptBaseAddress() {
2001-10-09 14:30:12 +00:00
ScriptSlot *ss;
int idx;
2001-10-09 14:30:12 +00:00
if (_currentScript == 0xFF)
return;
ss = &vm.slot[_currentScript];
switch (ss->where) {
case WIO_INVENTORY: /* inventory script * */
for (idx = 0; idx < _numInventory; idx++)
if (_inventory[idx] == ss->number)
break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory);
_lastCodePtr = &_res->address[rtInventory][idx];
2001-10-09 14:30:12 +00:00
break;
2003-09-11 10:32:15 +00:00
case WIO_LOCAL:
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
assert(_roomResource < _res->num[rtRoomScripts]);
_lastCodePtr = &_res->address[rtRoomScripts][_roomResource];
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms);
_lastCodePtr = &_res->address[rtRoom][_roomResource];
}
2001-10-09 14:30:12 +00:00
break;
case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts);
_lastCodePtr = &_res->address[rtScript][ss->number];
2001-10-09 14:30:12 +00:00
break;
case WIO_FLOBJECT: /* flobject script */
idx = getObjectIndex(ss->number);
assert(idx != -1);
idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject);
_lastCodePtr = &_res->address[rtFlObject][idx];
2001-10-09 14:30:12 +00:00
break;
default:
error("Bad type while getting base address");
}
// The following fixes bug #1202487. Confirmed against disasm.
if (_game.version <= 2 && _scriptOrgPointer == NULL) {
ss->status = ssDead;
_currentScript = 0xFF;
}
2001-10-09 14:30:12 +00:00
}
void ScummEngine::getScriptEntryPoint() {
2001-10-09 14:30:12 +00:00
if (_currentScript == 0xFF)
return;
_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
}
/* Execute a script - Read opcode, and execute it from the table */
void ScummEngine::executeScript() {
int c;
2001-10-09 14:30:12 +00:00
while (_currentScript != 0xFF) {
if (_showStack == 1) {
printf("Stack:");
for (c=0; c < _scummStackPos; c++) {
printf(" %d", _vmStack[c]);
}
printf("\n");
}
2001-10-09 14:30:12 +00:00
_opcode = fetchScriptByte();
if (_game.version > 2) // V0-V2 games didn't use the didexec flag
vm.slot[_currentScript].didexec = true;
debugC(DEBUG_OPCODES, "Script %d, offset 0x%x: [%X] %s()",
vm.slot[_currentScript].number,
_scriptPointer - _scriptOrgPointer,
_opcode,
getOpcodeDesc(_opcode));
if (_hexdumpScripts == true) {
for (c= -1; c < 15; c++) {
printf(" %02x", *(_scriptPointer + c));
}
printf("\n");
}
executeOpcode(_opcode);
2001-10-09 14:30:12 +00:00
}
}
2001-10-09 14:30:12 +00:00
byte ScummEngine::fetchScriptByte() {
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
long oldoffs = _scriptPointer - _scriptOrgPointer;
2001-10-09 14:30:12 +00:00
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
}
return *_scriptPointer++;
}
uint ScummEngine::fetchScriptWord() {
2001-10-09 14:30:12 +00:00
int a;
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
long oldoffs = _scriptPointer - _scriptOrgPointer;
2001-10-09 14:30:12 +00:00
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
}
a = READ_LE_UINT16(_scriptPointer);
_scriptPointer += 2;
return a;
}
int ScummEngine::fetchScriptWordSigned() {
return (int16)fetchScriptWord();
}
uint ScummEngine::fetchScriptDWord() {
int a;
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
}
a = READ_LE_UINT32(_scriptPointer);
_scriptPointer += 4;
return a;
}
int ScummEngine::fetchScriptDWordSigned() {
return (int32)fetchScriptDWord();
}
int ScummEngine::readVar(uint var) {
2001-10-09 14:30:12 +00:00
int a;
2003-05-04 12:02:37 +00:00
debugC(DEBUG_VARS, "readvar(%d)", var);
2003-05-04 12:02:37 +00:00
if ((var & 0x2000) && (_game.version <= 5)) {
2003-05-04 12:02:37 +00:00
a = fetchScriptWord();
if (a & 0x2000)
var += readVar(a & ~0x2000);
else
var += a & 0xFFF;
var &= ~0x2000;
}
if (!(var & 0xF000)) {
if (!_copyProtection) {
if (var == 490 && _game.id == GID_MONKEY2) {
var = 518;
}
}
if (VAR_SUBTITLES != 0xFF && var == VAR_SUBTITLES) {
return ConfMan.getBool("subtitles");
}
if (VAR_NOSUBTITLES != 0xFF && var == VAR_NOSUBTITLES) {
return !ConfMan.getBool("subtitles");
}
assertRange(0, var, _numVariables - 1, "variable (reading)");
return _scummVars[var];
2001-10-09 14:30:12 +00:00
}
if (var & 0x8000) {
if (_game.heversion >= 80) {
var &= 0xFFF;
assertRange(0, var, _numRoomVariables - 1, "room variable (reading)");
return _roomVars[var];
} else if (_game.version <= 3 && !(_game.id == GID_INDY3 && (_game.platform == Common::kPlatformFMTowns))) {
2003-05-04 12:02:37 +00:00
int bit = var & 0xF;
var = (var >> 4) & 0xFF;
if (!_copyProtection) {
if (_game.id == GID_LOOM && (_game.platform == Common::kPlatformFMTowns) && var == 214 && bit == 15) {
return 0;
} else if (_game.id == GID_ZAK && (_game.platform == Common::kPlatformFMTowns) && var == 151 && bit == 8) {
return 0;
}
2003-05-04 12:02:37 +00:00
}
assertRange(0, var, _numVariables - 1, "variable (reading)");
return (_scummVars[ var ] & ( 1 << bit ) ) ? 1 : 0;
2003-05-04 12:02:37 +00:00
} else {
var &= 0x7FFF;
if (!_copyProtection) {
if (_game.id == GID_INDY3 && (_game.platform == Common::kPlatformFMTowns) && var == 1508)
return 0;
}
assertRange(0, var, _numBitVariables - 1, "variable (reading)");
2003-05-04 12:02:37 +00:00
return (_bitVars[var >> 3] & (1 << (var & 7))) ? 1 : 0;
}
2001-10-09 14:30:12 +00:00
}
if (var & 0x4000) {
if (_game.features & GF_FEW_LOCALS) {
var &= 0xF;
} else {
var &= 0xFFF;
}
if (_game.heversion >= 80)
assertRange(0, var, 25, "local variable (reading)");
else
assertRange(0, var, 20, "local variable (reading)");
return vm.localvar[_currentScript][var];
2001-10-09 14:30:12 +00:00
}
error("Illegal varbits (r)");
2002-05-05 18:10:29 +00:00
return -1;
2001-10-09 14:30:12 +00:00
}
void ScummEngine::writeVar(uint var, int value) {
debugC(DEBUG_VARS, "writeVar(%d, %d)", var, value);
if (!(var & 0xF000)) {
assertRange(0, var, _numVariables - 1, "variable (writing)");
if (VAR_SUBTITLES != 0xFF && var == VAR_SUBTITLES) {
2005-11-17 10:49:39 +00:00
// Ignore default setting in HE72-73 games
if (_game.heversion <= 73 && vm.slot[_currentScript].number == 1)
return;
assert(value == 0 || value == 1);
ConfMan.setBool("subtitles", (value != 0));
}
if (VAR_NOSUBTITLES != 0xFF && var == VAR_NOSUBTITLES) {
2005-11-17 10:49:39 +00:00
// Ignore default setting in HE60-71 games
if (_game.heversion >= 60 && vm.slot[_currentScript].number == 1)
return;
assert(value == 0 || value == 1);
ConfMan.setBool("subtitles", !value);
}
if (var == VAR_CHARINC) {
if (ConfMan.hasKey("talkspeed")) {
value = getTalkspeed();
} else {
// Save the new talkspeed value to ConfMan
setTalkspeed(value);
}
}
_scummVars[var] = value;
if ((_varwatch == (int)var) || (_varwatch == 0)) {
if (vm.slot[_currentScript].number < 100)
debug(1, "vars[%d] = %d (via script-%d)", var, value, vm.slot[_currentScript].number);
else
debug(1, "vars[%d] = %d (via room-%d-%d)", var, value, _currentRoom,
vm.slot[_currentScript].number);
}
2001-10-09 14:30:12 +00:00
return;
}
if (var & 0x8000) {
if (_game.heversion >= 80) {
var &= 0xFFF;
assertRange(0, var, _numRoomVariables - 1, "room variable (writing)");
_roomVars[var] = value;
} else if (_game.version <= 3 && !(_game.id == GID_INDY3 && (_game.platform == Common::kPlatformFMTowns))) {
2003-05-04 12:02:37 +00:00
// In the old games, the bit variables were using the same memory
// as the normal variables!
int bit = var & 0xF;
var = (var >> 4) & 0xFF;
assertRange(0, var, _numVariables - 1, "variable (writing)");
if (value)
_scummVars[var] |= ( 1 << bit );
else
_scummVars[var] &= ~( 1 << bit );
2003-05-04 12:02:37 +00:00
} else {
var &= 0x7FFF;
assertRange(0, var, _numBitVariables - 1, "bit variable (writing)");
2003-05-04 12:02:37 +00:00
if (value)
_bitVars[var >> 3] |= (1 << (var & 7));
else
_bitVars[var >> 3] &= ~(1 << (var & 7));
}
2001-10-09 14:30:12 +00:00
return;
}
if (var & 0x4000) {
if (_game.features & GF_FEW_LOCALS) {
var &= 0xF;
} else {
var &= 0xFFF;
}
if (_game.heversion >= 80)
assertRange(0, var, 25, "local variable (writing)");
else
assertRange(0, var, 20, "local variable (writing)");
vm.localvar[_currentScript][var] = value;
2001-10-09 14:30:12 +00:00
return;
}
2001-10-16 10:01:48 +00:00
error("Illegal varbits (w)");
2001-10-09 14:30:12 +00:00
}
void ScummEngine::getResultPos() {
2001-10-09 14:30:12 +00:00
int a;
2001-10-16 10:01:48 +00:00
_resultVarNumber = fetchScriptWord();
if (_resultVarNumber & 0x2000) {
2001-10-16 10:01:48 +00:00
a = fetchScriptWord();
if (a & 0x2000) {
_resultVarNumber += readVar(a & ~0x2000);
2001-10-09 14:30:12 +00:00
} else {
_resultVarNumber += a & 0xFFF;
2001-10-09 14:30:12 +00:00
}
_resultVarNumber &= ~0x2000;
2001-10-09 14:30:12 +00:00
}
}
void ScummEngine::setResult(int value) {
2001-10-16 10:01:48 +00:00
writeVar(_resultVarNumber, value);
2001-10-09 14:30:12 +00:00
}
void ScummEngine::push(int a) {
assert(_scummStackPos >= 0 && _scummStackPos < ARRAYSIZE(_vmStack));
debug(9, "push %d", a);
_vmStack[_scummStackPos++] = a;
}
int ScummEngine::pop() {
if (_scummStackPos < 1 || _scummStackPos > ARRAYSIZE(_vmStack)) {
2002-12-27 14:04:25 +00:00
error("No items on stack to pop() for %s (0x%X) at [%d-%d]", getOpcodeDesc(_opcode), _opcode, _roomResource, vm.slot[_currentScript].number);
}
--_scummStackPos;
debug(9, "pop %d", _vmStack[_scummStackPos]);
return _vmStack[_scummStackPos];
}
2003-03-06 17:58:13 +00:00
void ScummEngine::stopObjectCode() {
2001-10-16 10:01:48 +00:00
ScriptSlot *ss;
2001-10-09 14:30:12 +00:00
2001-10-16 10:01:48 +00:00
ss = &vm.slot[_currentScript];
if (ss->cutsceneOverride == 255) { /* FIXME: What does this? */
warning("Cutscene for script %d has overflown. Resetting.", ss->number);
ss->cutsceneOverride = 0;
}
2001-10-09 14:30:12 +00:00
if (ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL) {
if (ss->cutsceneOverride) {
if (_game.version >= 5)
warning("Object %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
ss->cutsceneOverride = 0;
}
2001-10-16 10:01:48 +00:00
} else {
if (ss->cutsceneOverride) {
if (_game.version >= 5)
warning("Script %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
ss->cutsceneOverride = 0;
}
2001-10-16 10:01:48 +00:00
}
nukeArrays(_currentScript);
2001-10-16 10:01:48 +00:00
ss->number = 0;
2002-12-09 01:27:40 +00:00
ss->status = ssDead;
2001-10-16 10:01:48 +00:00
_currentScript = 0xFF;
2001-10-09 14:30:12 +00:00
}
void ScummEngine::runInventoryScript(int i) {
int args[24];
memset(args, 0, sizeof(args));
args[0] = i;
if (VAR(VAR_INVENTORY_SCRIPT)) {
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformMacintosh) {
inventoryScript();
} else {
runScript(VAR(VAR_INVENTORY_SCRIPT), 0, 0, args);
}
}
}
void ScummEngine::inventoryScript() {
VerbSlot *vs;
int args[24];
int j, slot;
memset(args, 0, sizeof(args));
if (VAR(67) < 0) {
VAR(67) = 0;
}
args[5] = getInventoryCount(VAR(VAR_EGO));
if (args[5] <= 6) {
VAR(67) = 0;
}
if (args[5] >= 6) {
args[5] -= 6;
}
args[6] = 0;
if (VAR(67) >= args[5]) {
VAR(67) = args[5];
args[4] = args[5];
args[5] /= 2;
args[5] *= 2;
args[4] -= args[5];
if (args[4]) {
VAR(67)++;
}
args[6]++;
}
args[2] = 1;
for (j = 1; j < 7; j++) {
args[1] = (VAR(67) + args[2]);
args[3] = findInventory(VAR(VAR_EGO),args[1]);
VAR(82 + args[2]) = args[3];
args[2]++;
}
byte tmp[6];
tmp[0] = 0xFF;
tmp[1] = 0x06;
tmp[3] = 0x00;
tmp[4] = 0x00;
for (j = 0; j < 6; j++) {
tmp[2] = 0x53 + j;
slot = getVerbSlot(101 + j, 0);
vs = &_verbs[slot];
loadPtrToResource(rtVerb, slot, tmp);
vs->type = kTextVerbType;
vs->imgindex = 0;
vs->curmode = 1;
drawVerb(slot, 0);
}
args[5] = getInventoryCount(VAR(VAR_EGO));
if (args[5] > 6) {
slot = getVerbSlot(107, 0);
if (VAR(67)) {
vs = &_verbs[slot];
vs->curmode = 1;
} else {
vs = &_verbs[slot];
vs->curmode = 0;
}
drawVerb(slot, 0);
slot = getVerbSlot(108, 0);
if (!args[6]) {
vs = &_verbs[slot];
vs->curmode = 1;
} else {
vs = &_verbs[slot];
vs->curmode = 0;
}
drawVerb(slot, 0);
} else {
slot = getVerbSlot(107, 0);
vs = &_verbs[slot];
vs->curmode = 0;
drawVerb(slot, 0);
slot = getVerbSlot(108, 0);
vs = &_verbs[slot];
vs->curmode = 0;
drawVerb(slot, 0);
2001-10-09 14:30:12 +00:00
}
verbMouseOver(0);
2001-10-09 14:30:12 +00:00
}
void ScummEngine::freezeScripts(int flag) {
2001-10-09 14:30:12 +00:00
int i;
if (_game.version <= 2) {
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
if (_currentScript != i && vm.slot[i].status != ssDead && !vm.slot[i].freezeResistant) {
vm.slot[i].status |= 0x80;
vm.slot[i].freezeCount = 1;
}
}
return;
}
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
if (_currentScript != i && vm.slot[i].status != ssDead && (!vm.slot[i].freezeResistant || flag >= 0x80)) {
2001-10-09 14:30:12 +00:00
vm.slot[i].status |= 0x80;
vm.slot[i].freezeCount++;
}
}
2003-05-18 23:46:30 +00:00
for (i = 0; i < NUM_SENTENCE; i++)
2002-12-09 01:27:40 +00:00
_sentence[i].freezeCount++;
2001-10-09 14:30:12 +00:00
if (vm.cutSceneScriptIndex != 0xFF) {
vm.slot[vm.cutSceneScriptIndex].status &= 0x7F;
vm.slot[vm.cutSceneScriptIndex].freezeCount = 0;
2001-10-09 14:30:12 +00:00
}
}
void ScummEngine::unfreezeScripts() {
2001-10-09 14:30:12 +00:00
int i;
if (_game.version <= 2) {
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
vm.slot[i].status &= 0x7F;
vm.slot[i].freezeCount = 0;
}
return;
}
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
if (vm.slot[i].status & 0x80) {
2001-10-09 14:30:12 +00:00
if (!--vm.slot[i].freezeCount) {
vm.slot[i].status &= 0x7F;
2001-10-09 14:30:12 +00:00
}
}
}
2003-05-18 23:46:30 +00:00
for (i = 0; i < NUM_SENTENCE; i++) {
2002-12-09 01:27:40 +00:00
if (_sentence[i].freezeCount > 0)
_sentence[i].freezeCount--;
2001-10-09 14:30:12 +00:00
}
}
void ScummEngine::runAllScripts() {
2001-10-09 14:30:12 +00:00
int i;
for (i = 0; i < NUM_SCRIPT_SLOT; i++)
vm.slot[i].didexec = false;
2001-10-09 14:30:12 +00:00
_currentScript = 0xFF;
int numCycles = (_game.heversion >= 90) ? VAR(VAR_NUM_SCRIPT_CYCLES) : 1;
for (int cycle = 1; cycle <= numCycles; cycle++) {
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
_currentScript = (byte)i;
getScriptBaseAddress();
getScriptEntryPoint();
executeScript();
}
2001-10-09 14:30:12 +00:00
}
}
}
void ScummEngine::runExitScript() {
2006-03-15 05:59:30 +00:00
if (VAR_EXIT_SCRIPT != 0xFF && VAR(VAR_EXIT_SCRIPT))
runScript(VAR(VAR_EXIT_SCRIPT), 0, 0, 0);
2001-10-09 14:30:12 +00:00
if (_EXCD_offs) {
int slot = getScriptSlot();
vm.slot[slot].status = ssRunning;
2001-10-09 14:30:12 +00:00
vm.slot[slot].number = 10001;
vm.slot[slot].where = WIO_ROOM;
vm.slot[slot].offs = _EXCD_offs;
vm.slot[slot].freezeResistant = false;
vm.slot[slot].recursive = false;
2001-10-09 14:30:12 +00:00
vm.slot[slot].freezeCount = 0;
2002-08-25 11:35:13 +00:00
vm.slot[slot].delayFrameCount = 0;
vm.slot[slot].cycle = 1;
// FIXME: the exit script of room 7 in indy3 only seems to have a size
// and tag not actual data not even a 00 (stop code). Maybe we should
// be limiting ourselves to strictly reading the size from the header?
if (_game.id == GID_INDY3 && !(_game.features & GF_OLD_BUNDLE)) {
byte *roomptr = getResourceAddress(rtRoom, _roomResource);
const byte *excd = findResourceData(MKID_BE('EXCD'), roomptr) - _resourceHeaderSize;
if (!excd || (getResourceDataSize(excd) < 1)) {
debug(2, "Exit-%d is empty", _roomResource);
return;
}
}
initializeLocals(slot, 0);
runScriptNested(slot);
2001-10-09 14:30:12 +00:00
}
2006-03-15 05:59:30 +00:00
if (VAR_EXIT_SCRIPT2 != 0xFF && VAR(VAR_EXIT_SCRIPT2))
runScript(VAR(VAR_EXIT_SCRIPT2), 0, 0, 0);
2001-10-09 14:30:12 +00:00
}
void ScummEngine::runEntryScript() {
2006-03-15 05:59:30 +00:00
if (VAR_ENTRY_SCRIPT != 0xFF && VAR(VAR_ENTRY_SCRIPT))
runScript(VAR(VAR_ENTRY_SCRIPT), 0, 0, 0);
2001-10-09 14:30:12 +00:00
if (_ENCD_offs) {
int slot = getScriptSlot();
vm.slot[slot].status = ssRunning;
2001-10-09 14:30:12 +00:00
vm.slot[slot].number = 10002;
vm.slot[slot].where = WIO_ROOM;
vm.slot[slot].offs = _ENCD_offs;
vm.slot[slot].freezeResistant = false;
vm.slot[slot].recursive = false;
2001-10-09 14:30:12 +00:00
vm.slot[slot].freezeCount = 0;
2002-08-25 11:35:13 +00:00
vm.slot[slot].delayFrameCount = 0;
vm.slot[slot].cycle = 1;
initializeLocals(slot, 0);
2001-10-09 14:30:12 +00:00
runScriptNested(slot);
}
2006-03-15 05:59:30 +00:00
if (VAR_ENTRY_SCRIPT2 != 0xFF && VAR(VAR_ENTRY_SCRIPT2))
runScript(VAR(VAR_ENTRY_SCRIPT2), 0, 0, 0);
2001-10-09 14:30:12 +00:00
}
void ScummEngine::killScriptsAndResources() {
2001-10-09 14:30:12 +00:00
ScriptSlot *ss;
int i;
ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
if (ss->where == WIO_ROOM || ss->where == WIO_FLOBJECT) {
if (ss->cutsceneOverride) {
if (_game.version >= 5)
warning("Object %d stopped with active cutscene/override in exit", ss->number);
ss->cutsceneOverride = 0;
}
nukeArrays(i);
2002-12-09 01:27:40 +00:00
ss->status = ssDead;
} else if (ss->where == WIO_LOCAL) {
if (ss->cutsceneOverride) {
if (_game.version >= 5)
warning("Script %d stopped with active cutscene/override in exit", ss->number);
ss->cutsceneOverride = 0;
}
nukeArrays(i);
2002-12-09 01:27:40 +00:00
ss->status = ssDead;
2001-10-09 14:30:12 +00:00
}
}
/* Nuke local object names */
if (_newNames) {
for (i = 0; i < _numNewNames; i++) {
const int obj = _newNames[i];
if (obj) {
const int owner = getOwner(obj);
// We can delete custom name resources if either the object is
// no longer in use (i.e. not owned by anyone anymore); or if
// it is an object which is owned by a room.
if (owner == 0 || (_game.version < 7 && owner == OF_OWNER_ROOM)) {
// WORKAROUND for a problem mentioned in bug report #941275:
// In FOA in the sentry room, in the chest plate of the statue,
// the pegs may be renamed to mouth: this custom name is lost
// when leaving the room; this hack prevents this).
if (owner == OF_OWNER_ROOM && _game.id == GID_INDY4 && 336 <= obj && obj <= 340)
continue;
_newNames[i] = 0;
_res->nukeResource(rtObjectName, i);
}
}
}
}
2001-10-09 14:30:12 +00:00
}
void ScummEngine::killAllScriptsExceptCurrent() {
for (int i = 0; i < NUM_SCRIPT_SLOT; i++) {
2004-02-16 03:53:03 +00:00
if (i != _currentScript) {
vm.slot[i].status = ssDead;
if (_game.version == 6)
2004-02-16 03:53:03 +00:00
vm.slot[i].cutsceneOverride = 0;
}
}
}
void ScummEngine::doSentence(int verb, int objectA, int objectB) {
SentenceTab *st;
if (_game.version >= 7) {
2003-05-20 15:41:07 +00:00
if (objectA == objectB)
return;
if (_sentenceNum > 0) {
2003-05-20 15:41:07 +00:00
st = &_sentence[_sentenceNum - 1];
2003-05-20 15:41:07 +00:00
// Check if this doSentence request is identical to the previous one;
// if yes, ignore this invocation.
if (_sentenceNum && st->verb == verb && st->objectA == objectA && st->objectB == objectB)
return;
}
}
assert(_sentenceNum < NUM_SENTENCE);
2003-05-20 15:41:07 +00:00
st = &_sentence[_sentenceNum++];
st->verb = verb;
st->objectA = objectA;
st->objectB = objectB;
st->preposition = (objectB != 0);
st->freezeCount = 0;
}
void ScummEngine::checkAndRunSentenceScript() {
2001-10-09 14:30:12 +00:00
int i;
int localParamList[24];
const ScriptSlot *ss;
int sentenceScript;
if (_game.version <= 2)
sentenceScript = 2;
else
sentenceScript = VAR(VAR_SENTENCE_SCRIPT);
2001-10-09 14:30:12 +00:00
2003-09-11 10:32:15 +00:00
memset(localParamList, 0, sizeof(localParamList));
if (isScriptInUse(sentenceScript)) {
2001-10-09 14:30:12 +00:00
ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
if (ss->number == sentenceScript && ss->status != ssDead && ss->freezeCount == 0)
2001-10-09 14:30:12 +00:00
return;
}
2002-12-09 01:27:40 +00:00
if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
2001-10-09 14:30:12 +00:00
return;
_sentenceNum--;
SentenceTab &st = _sentence[_sentenceNum];
if (_game.version < 7)
if (st.preposition && st.objectB == st.objectA)
return;
2001-10-09 14:30:12 +00:00
if (_game.version <= 2) {
VAR(VAR_ACTIVE_VERB) = st.verb;
VAR(VAR_ACTIVE_OBJECT1) = st.objectA;
VAR(VAR_ACTIVE_OBJECT2) = st.objectB;
VAR(VAR_VERB_ALLOWED) = (0 != getVerbEntrypoint(st.objectA, st.verb));
} else {
localParamList[0] = st.verb;
localParamList[1] = st.objectA;
localParamList[2] = st.objectB;
if (_game.id == GID_FT && !isValidActor(localParamList[1]) && !isValidActor(localParamList[2])) {
// WORKAROUND for bug #1407789. The buggy script clearly
// assumes that one of the two objects is an actor. If that's
// not the case, fall back on the default sentence script.
// FIXME: We do not yet have all necessary information, but the
// following is known:
//
// * The US PC version uses scripts 28 and 103 and has 456 scripts.
// * The French PC version uses scripts 29 and 104 and has 467 scripts.
// * The German Mac version uses scripts 29 and 104 and has 469 scripts.
// * The German, Italian, Portuguese and Spanish PC versions
// use script 29. The other script is not currently known.
// * The US Mac demo uses script 28.
//
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
if (_res->num[rtScript] > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {
if (sentenceScript == 103)
sentenceScript = 28;
}
}
}
2001-10-09 14:30:12 +00:00
_currentScript = 0xFF;
if (sentenceScript)
2003-09-11 10:32:15 +00:00
runScript(sentenceScript, 0, 0, localParamList);
2001-10-09 14:30:12 +00:00
}
void ScummEngine_v2::runInputScript(int a, int cmd, int mode) {
int args[24];
2003-05-17 06:18:34 +00:00
int verbScript;
verbScript = 4;
VAR(VAR_CLICK_AREA) = a;
switch (a) {
case 1: // Verb clicked
VAR(VAR_CLICK_VERB) = cmd;
break;
case 3: // Inventory clicked
VAR(VAR_CLICK_OBJECT) = cmd;
break;
2003-05-21 23:54:39 +00:00
}
2003-05-17 06:18:34 +00:00
memset(args, 0, sizeof(args));
args[0] = a;
args[1] = cmd;
args[2] = mode;
if (verbScript)
runScript(verbScript, 0, 0, args);
}
void ScummEngine::runInputScript(int a, int cmd, int mode) {
int args[24];
int verbScript;
verbScript = VAR(VAR_VERB_SCRIPT);
memset(args, 0, sizeof(args));
args[0] = a;
args[1] = cmd;
args[2] = mode;
// All HE 72+ games but only some HE 71 games.
if (_game.heversion >= 71) {
args[3] = VAR(VAR_VIRT_MOUSE_X);
args[4] = VAR(VAR_VIRT_MOUSE_Y);
}
// Macintosh verison of indy3ega used different interface, so adjust values.
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformMacintosh) {
if (a == 1 && (cmd >= 101 && cmd <= 108)) {
if (cmd == 107) {
VAR(67) -= 2;
inventoryScript();
return;
} else if (cmd == 108) {
VAR(67) += 2;
inventoryScript();
return;
} else {
args[0] = 3;
args[1] = VAR(83 + (cmd - 101));
}
}
}
2003-05-17 06:18:34 +00:00
if (verbScript)
runScript(verbScript, 0, 0, args);
2001-10-09 14:30:12 +00:00
}
void ScummEngine::decreaseScriptDelay(int amount) {
ScriptSlot *ss = vm.slot;
2001-10-09 14:30:12 +00:00
int i;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
2002-12-09 01:27:40 +00:00
if (ss->status == ssPaused) {
2001-10-09 14:30:12 +00:00
ss->delay -= amount;
if (ss->delay < 0) {
2002-12-09 01:27:40 +00:00
ss->status = ssRunning;
2001-10-09 14:30:12 +00:00
ss->delay = 0;
}
}
}
}
bool ScummEngine::isScriptInUse(int script) const {
int i;
const ScriptSlot *ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
if (ss->number == script)
return true;
return false;
}
bool ScummEngine::isScriptRunning(int script) const {
2001-10-16 10:01:48 +00:00
int i;
const ScriptSlot *ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
2002-12-09 01:27:40 +00:00
if (ss->number == script && (ss->where == WIO_GLOBAL || ss->where == WIO_LOCAL) && ss->status != ssDead)
return true;
return false;
2001-10-16 10:01:48 +00:00
}
bool ScummEngine::isRoomScriptRunning(int script) const {
int i;
const ScriptSlot *ss = vm.slot;
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
2002-12-09 01:27:40 +00:00
if (ss->number == script && ss->where == WIO_ROOM && ss->status != ssDead)
return true;
return false;
}
void ScummEngine::copyScriptString(byte *dst) {
int len = resStrLen(_scriptPointer) + 1;
while (len--)
*dst++ = fetchScriptByte();
*dst = 0;
2001-10-16 10:01:48 +00:00
}
//
// Given a pointer to a Scumm string, this function returns the total byte length
// of the string data in that resource. To do so it has to understand certain
// special characters embedded into the string. The reason for this function is that
// sometimes this embedded data contains zero bytes, thus we can't just use strlen.
//
int ScummEngine::resStrLen(const byte *src) const {
int num = 0;
byte chr;
if (src == NULL)
src = _scriptPointer;
while ((chr = *src++) != 0) {
num++;
if (_game.heversion <= 71 && chr == 0xFF) {
chr = *src++;
num++;
// WORKAROUND for bug #985948, a script bug in Indy3. See also
// the corresponding code in ScummEngine::convertMessageToString().
if (_game.id == GID_INDY3 && chr == 0x2E) {
continue;
}
if (chr != 1 && chr != 2 && chr != 3 && chr != 8) {
if (_game.version == 8) {
src += 4;
num += 4;
} else {
src += 2;
num += 2;
}
}
}
}
return num;
2001-10-16 10:01:48 +00:00
}
void ScummEngine::beginCutscene(int *args) {
int scr = _currentScript;
vm.slot[scr].cutsceneOverride++;
2003-05-18 21:03:57 +00:00
if (++vm.cutSceneStackPointer > ARRAYSIZE(vm.cutSceneData))
error("Cutscene stack overflow");
vm.cutSceneData[vm.cutSceneStackPointer] = args[0];
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
vm.cutSceneScriptIndex = scr;
if (VAR(VAR_CUTSCENE_START_SCRIPT))
runScript(VAR(VAR_CUTSCENE_START_SCRIPT), 0, 0, args);
vm.cutSceneScriptIndex = 0xFF;
}
void ScummEngine::endCutscene() {
ScriptSlot *ss = &vm.slot[_currentScript];
int args[16];
if (ss->cutsceneOverride > 0) // Only terminate if active
ss->cutsceneOverride--;
2005-03-25 00:40:58 +00:00
memset(args, 0, sizeof(args));
args[0] = vm.cutSceneData[vm.cutSceneStackPointer];
2005-03-25 00:40:58 +00:00
VAR(VAR_OVERRIDE) = 0;
if (vm.cutScenePtr[vm.cutSceneStackPointer] && (ss->cutsceneOverride > 0)) // Only terminate if active
ss->cutsceneOverride--;
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
vm.cutSceneStackPointer--;
if (VAR(VAR_CUTSCENE_END_SCRIPT))
runScript(VAR(VAR_CUTSCENE_END_SCRIPT), 0, 0, args);
}
void ScummEngine::abortCutscene() {
2005-03-25 00:40:58 +00:00
const int idx = vm.cutSceneStackPointer;
assert(0 <= idx && idx < 5);
uint32 offs = vm.cutScenePtr[idx];
if (offs) {
2005-03-25 00:40:58 +00:00
ScriptSlot *ss = &vm.slot[vm.cutSceneScript[idx]];
ss->offs = offs;
2002-12-09 01:27:40 +00:00
ss->status = ssRunning;
ss->freezeCount = 0;
if (ss->cutsceneOverride > 0)
ss->cutsceneOverride--;
2005-09-14 10:36:18 +00:00
VAR(VAR_OVERRIDE) = 1;
2005-03-25 00:40:58 +00:00
vm.cutScenePtr[idx] = 0;
// HACK to fix issues with SMUSH and the way it does keyboard handling.
// In particular, normally abortCutscene() is being called while no
// scripts are active. But SMUSH runs from *inside* the script engine.
// And it calls abortCutscene() if ESC is pressed... not good.
// Proper fix might be to let SMUSH/INSANE run from outside the script
// engine but that would require lots of changes and may actually have
// negative effects, too. So we cheat here, to fix bug #751670.
if (_game.version == 7)
getScriptEntryPoint();
}
}
void ScummEngine::beginOverride() {
2005-03-25 00:40:58 +00:00
const int idx = vm.cutSceneStackPointer;
assert(0 <= idx && idx < 5);
vm.cutScenePtr[idx] = _scriptPointer - _scriptOrgPointer;
vm.cutSceneScript[idx] = _currentScript;
// Skip the jump instruction following the override instruction
// (the jump is responsible for "skipping" cutscenes, and the reason
// why we record the current script position in vm.cutScenePtr).
fetchScriptByte();
fetchScriptWord();
if (_game.version >= 5)
VAR(VAR_OVERRIDE) = 0;
}
void ScummEngine::endOverride() {
2005-03-25 00:40:58 +00:00
const int idx = vm.cutSceneStackPointer;
assert(0 <= idx && idx < 5);
vm.cutScenePtr[idx] = 0;
vm.cutSceneScript[idx] = 0;
if (_game.version >= 4)
VAR(VAR_OVERRIDE) = 0;
}
} // End of namespace Scumm