2007-05-30 21:56:52 +00:00
|
|
|
/* 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-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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-12-27 15:22:59 +00:00
|
|
|
#include "common/config-manager.h"
|
2003-09-11 10:32:15 +00:00
|
|
|
#include "common/util.h"
|
2009-07-29 20:35:50 +00:00
|
|
|
#include "common/system.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
|
2003-09-11 10:32:15 +00:00
|
|
|
#include "scumm/actor.h"
|
|
|
|
#include "scumm/object.h"
|
|
|
|
#include "scumm/resource.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
#include "scumm/util.h"
|
2012-01-08 22:51:13 +00:00
|
|
|
#include "scumm/scumm_v0.h"
|
2009-03-20 16:33:58 +00:00
|
|
|
#include "scumm/scumm_v2.h"
|
2012-01-08 19:11:22 +00:00
|
|
|
#include "scumm/sound.h"
|
2005-10-01 13:02:35 +00:00
|
|
|
#include "scumm/verbs.h"
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
namespace Scumm {
|
|
|
|
|
2003-05-19 11:31:35 +00:00
|
|
|
/* Start executing script 'script' with the given parameters */
|
2005-02-28 13:23:10 +00:00
|
|
|
void ScummEngine::runScript(int script, bool freezeResistant, bool recursive, int *lvarptr, int cycle) {
|
2003-05-19 11:31:35 +00:00
|
|
|
ScriptSlot *s;
|
2011-05-14 21:50:18 +00:00
|
|
|
//byte *scriptPtr;
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 scriptOffs;
|
|
|
|
byte scriptType;
|
2001-11-07 18:10:52 +00:00
|
|
|
int slot;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2003-05-19 11:31:35 +00:00
|
|
|
if (!script)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-05-19 11:31:35 +00:00
|
|
|
if (!recursive)
|
2003-05-20 20:58:26 +00:00
|
|
|
stopScript(script);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
if (script < _numGlobalScripts) {
|
2011-05-14 21:50:18 +00:00
|
|
|
// Call getResourceAddress to ensure the resource is loaded & its usage count reset
|
|
|
|
/*scriptPtr =*/ getResourceAddress(rtScript, script);
|
2002-04-11 15:22:02 +00:00
|
|
|
scriptOffs = _resourceHeaderSize;
|
2001-11-12 20:50:36 +00:00
|
|
|
scriptType = WIO_GLOBAL;
|
2004-01-10 05:20:15 +00:00
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
debugC(DEBUG_SCRIPTS, "runScript(Global-%d) from %d-%d", script,
|
2004-01-10 05:20:15 +00:00
|
|
|
vm.slot[_currentScript].number, _roomResource);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2005-01-29 15:49:57 +00:00
|
|
|
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);
|
2001-11-12 20:50:36 +00:00
|
|
|
scriptType = WIO_LOCAL;
|
2004-01-10 05:20:15 +00:00
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
debugC(DEBUG_SCRIPTS, "runScript(%d) from %d-%d", script,
|
2004-01-10 05:20:15 +00:00
|
|
|
vm.slot[_currentScript].number, _roomResource);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 13:23:10 +00:00
|
|
|
if (cycle == 0)
|
2006-02-20 16:51:30 +00:00
|
|
|
cycle = (_game.heversion >= 90) ? VAR(VAR_SCRIPT_CYCLE) : 1;
|
2005-02-28 13:23:10 +00:00
|
|
|
|
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;
|
2001-11-12 20:50:36 +00:00
|
|
|
s->where = scriptType;
|
2003-05-19 11:31:35 +00:00
|
|
|
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;
|
2005-02-28 13:23:10 +00:00
|
|
|
s->cycle = cycle;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
initializeLocals(slot, lvarptr);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
runScriptNested(slot);
|
|
|
|
}
|
|
|
|
|
2005-02-28 13:23:10 +00:00
|
|
|
void ScummEngine::runObjectScript(int object, int entry, bool freezeResistant, bool recursive, int *vars, int slot, int cycle) {
|
2003-05-20 20:42:28 +00:00
|
|
|
ScriptSlot *s;
|
|
|
|
uint32 obcd;
|
2003-09-10 17:15:44 +00:00
|
|
|
int where, offs;
|
2003-05-20 20:42:28 +00:00
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (!recursive && (_game.version >= 3))
|
2003-05-20 20:42:28 +00:00
|
|
|
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);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-10 17:15:44 +00:00
|
|
|
// Find a free object slot, unless one was specified
|
|
|
|
if (slot == -1)
|
|
|
|
slot = getScriptSlot();
|
2003-05-20 20:42:28 +00:00
|
|
|
|
|
|
|
offs = getVerbEntrypoint(object, entry);
|
|
|
|
if (offs == 0)
|
|
|
|
return;
|
|
|
|
|
2005-02-28 13:23:10 +00:00
|
|
|
if (cycle == 0)
|
2006-02-20 16:51:30 +00:00
|
|
|
cycle = (_game.heversion >= 90) ? VAR(VAR_SCRIPT_CYCLE) : 1;
|
2005-02-28 13:23:10 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
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;
|
2005-02-28 13:23:10 +00:00
|
|
|
s->cycle = cycle;
|
2003-05-20 20:42:28 +00:00
|
|
|
|
|
|
|
initializeLocals(slot, vars);
|
|
|
|
|
|
|
|
runScriptNested(slot);
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::initializeLocals(int slot, int *vars) {
|
2003-05-20 20:42:28 +00:00
|
|
|
int i;
|
|
|
|
if (!vars) {
|
2004-10-16 05:10:15 +00:00
|
|
|
for (i = 0; i < 25; i++)
|
2003-05-20 20:42:28 +00:00
|
|
|
vm.localvar[slot][i] = 0;
|
|
|
|
} else {
|
2004-10-16 05:10:15 +00:00
|
|
|
for (i = 0; i < 25; i++)
|
2003-05-20 20:42:28 +00:00
|
|
|
vm.localvar[slot][i] = vars[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getVerbEntrypoint(int obj, int entry) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *objptr, *verbptr;
|
2003-05-20 20:42:28 +00:00
|
|
|
int verboffs;
|
|
|
|
|
2006-10-02 21:38:39 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
if (whereIsObject(obj) == WIO_NOT_FOUND)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
objptr = getOBCDFromObject(obj);
|
|
|
|
assert(objptr);
|
|
|
|
|
2006-05-29 12:45:11 +00:00
|
|
|
if (_game.version == 0)
|
2005-09-14 05:31:18 +00:00
|
|
|
verbptr = objptr + 14;
|
2006-02-20 16:51:30 +00:00
|
|
|
else if (_game.version <= 2)
|
2003-05-20 20:42:28 +00:00
|
|
|
verbptr = objptr + 15;
|
2007-03-03 23:02:54 +00:00
|
|
|
else if ((_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine) ||
|
|
|
|
_game.features & GF_OLD_BUNDLE)
|
2003-05-20 20:42:28 +00:00
|
|
|
verbptr = objptr + 17;
|
2006-02-20 16:51:30 +00:00
|
|
|
else if (_game.features & GF_SMALL_HEADER)
|
2003-05-20 20:42:28 +00:00
|
|
|
verbptr = objptr + 19;
|
|
|
|
else
|
2011-04-12 14:53:15 +00:00
|
|
|
verbptr = findResource(MKTAG('V','E','R','B'), objptr);
|
2003-05-20 20:42:28 +00:00
|
|
|
|
|
|
|
assert(verbptr);
|
|
|
|
|
|
|
|
verboffs = verbptr - objptr;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (!(_game.features & GF_SMALL_HEADER))
|
2003-05-20 20:42:28 +00:00
|
|
|
verbptr += _resourceHeaderSize;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version == 8) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const uint32 *ptr = (const uint32 *)verbptr;
|
2003-05-20 20:42:28 +00:00
|
|
|
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);
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_game.version <= 2) {
|
2003-05-20 20:42:28 +00:00
|
|
|
do {
|
2012-01-08 22:51:13 +00:00
|
|
|
const int kFallbackEntry = (_game.version == 0 ? 0x0F : 0xFF);
|
2012-01-09 22:21:08 +00:00
|
|
|
if (!*verbptr)
|
|
|
|
return 0;
|
2012-01-08 22:51:13 +00:00
|
|
|
if (*verbptr == entry || *verbptr == kFallbackEntry)
|
2003-05-20 20:42:28 +00:00
|
|
|
break;
|
|
|
|
verbptr += 2;
|
|
|
|
} while (1);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
return *(verbptr + 1);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (!*verbptr)
|
|
|
|
return 0;
|
|
|
|
if (*verbptr == entry || *verbptr == 0xFF)
|
|
|
|
break;
|
|
|
|
verbptr += 3;
|
|
|
|
} while (1);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2009-10-22 11:33:05 +00:00
|
|
|
if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine) {
|
|
|
|
verbptr += READ_LE_UINT16(verbptr + 1) + 3;
|
|
|
|
return verbptr - objptr;
|
|
|
|
} else if (_game.features & GF_SMALL_HEADER)
|
2003-05-20 20:42:28 +00:00
|
|
|
return READ_LE_UINT16(verbptr + 1);
|
|
|
|
else
|
|
|
|
return verboffs + READ_LE_UINT16(verbptr + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Stop script 'script' */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::stopScript(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
2006-10-29 18:42:28 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (script == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-05-18 20:57:32 +00:00
|
|
|
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)) {
|
2003-05-18 20:57:32 +00:00
|
|
|
if (ss->cutsceneOverride)
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version >= 5)
|
2004-08-03 04:26:30 +00:00
|
|
|
error("Script %d stopped with active cutscene/override", script);
|
2003-05-18 20:57:32 +00:00
|
|
|
ss->number = 0;
|
|
|
|
ss->status = ssDead;
|
2005-04-05 11:06:03 +00:00
|
|
|
nukeArrays(i);
|
2003-05-18 20:57:32 +00:00
|
|
|
if (_currentScript == i)
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 18:42:28 +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);
|
2012-05-31 08:53:47 +00:00
|
|
|
vm.nest[i].number = 0;
|
2006-10-29 18:42:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Stop an object script 'script'*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::stopObjectScript(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
2011-04-05 11:43:54 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (script == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-05-18 20:57:32 +00:00
|
|
|
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)
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version >= 5)
|
2004-08-03 04:26:30 +00:00
|
|
|
error("Object %d stopped with active cutscene/override", script);
|
2001-10-16 10:01:48 +00:00
|
|
|
ss->number = 0;
|
2002-03-16 18:03:28 +00:00
|
|
|
ss->status = ssDead;
|
2005-04-05 11:06:03 +00:00
|
|
|
nukeArrays(i);
|
2001-10-16 10:01:48 +00:00
|
|
|
if (_currentScript == i)
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2011-04-05 11:43:54 +00:00
|
|
|
for (i = 0; i < vm.numNestedScripts; ++i) {
|
|
|
|
if (vm.nest[i].number == script &&
|
|
|
|
(vm.nest[i].where == WIO_ROOM || vm.nest[i].where == WIO_INVENTORY || vm.nest[i].where == WIO_FLOBJECT)) {
|
|
|
|
nukeArrays(vm.nest[i].slot);
|
2012-05-31 08:53:47 +00:00
|
|
|
vm.nest[i].number = 0;
|
2011-04-05 11:43:54 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Return a free script slot */
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getScriptSlot() {
|
2005-04-05 11:06:03 +00:00
|
|
|
ScriptSlot *s;
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2005-04-05 11:06:03 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Run script 'script' nested - eg, within the parent script.*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::runScriptNested(int script) {
|
2001-10-09 14:30:12 +00:00
|
|
|
NestedScript *nest;
|
|
|
|
ScriptSlot *slot;
|
|
|
|
|
|
|
|
updateScriptPtr();
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2011-04-05 09:13:08 +00:00
|
|
|
if (vm.numNestedScripts >= kMaxScriptNesting)
|
|
|
|
error("Too many nested scripts");
|
|
|
|
|
2003-09-11 10:32:15 +00:00
|
|
|
nest = &vm.nest[vm.numNestedScripts];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_currentScript == 0xFF) {
|
2012-05-30 14:05:05 +00:00
|
|
|
nest->number = 0;
|
2001-11-12 20:50:36 +00:00
|
|
|
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;
|
2001-11-12 20:50:36 +00:00
|
|
|
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++;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = script;
|
|
|
|
getScriptBaseAddress();
|
2010-10-18 18:43:13 +00:00
|
|
|
resetScriptPointer();
|
2001-10-09 14:30:12 +00:00
|
|
|
executeScript();
|
|
|
|
|
2006-06-17 05:48:43 +00:00
|
|
|
if (vm.numNestedScripts != 0)
|
|
|
|
vm.numNestedScripts--;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2012-05-30 14:05:05 +00:00
|
|
|
if (nest->number) {
|
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];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (slot->number == nest->number && slot->where == nest->where &&
|
2006-11-19 00:38:37 +00:00
|
|
|
slot->status != ssDead && slot->freezeCount == 0) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = nest->slot;
|
|
|
|
getScriptBaseAddress();
|
2010-10-18 18:43:13 +00:00
|
|
|
resetScriptPointer();
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::updateScriptPtr() {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vm.slot[_currentScript].offs = _scriptPointer - _scriptOrgPointer;
|
|
|
|
}
|
|
|
|
|
2004-08-01 13:57:00 +00:00
|
|
|
/* Nuke arrays based on script */
|
2005-04-05 11:06:03 +00:00
|
|
|
void ScummEngine::nukeArrays(byte scriptSlot) {
|
2004-08-01 13:57:00 +00:00
|
|
|
int i;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion == 0 || scriptSlot == 0)
|
2004-08-28 04:14:33 +00:00
|
|
|
return;
|
|
|
|
|
2004-08-01 13:57:00 +00:00
|
|
|
for (i = 1; i < _numArray; i++) {
|
2005-04-05 11:06:03 +00:00
|
|
|
if (_arraySlot[i] == scriptSlot) {
|
2006-09-17 20:36:48 +00:00
|
|
|
_res->nukeResource(rtString, i);
|
2004-08-02 07:47:05 +00:00
|
|
|
_arraySlot[i] = 0;
|
|
|
|
}
|
2004-08-01 13:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-16 18:03:28 +00:00
|
|
|
/* Get the code pointer to a script */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::getScriptBaseAddress() {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
2002-03-08 08:42:11 +00:00
|
|
|
int idx;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ss = &vm.slot[_currentScript];
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (ss->where) {
|
|
|
|
case WIO_INVENTORY: /* inventory script * */
|
2003-12-26 23:11:35 +00:00
|
|
|
for (idx = 0; idx < _numInventory; idx++)
|
2003-05-22 15:27:44 +00:00
|
|
|
if (_inventory[idx] == ss->number)
|
|
|
|
break;
|
2002-03-08 08:42:11 +00:00
|
|
|
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
|
2003-12-26 23:11:35 +00:00
|
|
|
assert(idx < _numInventory);
|
2011-05-13 12:48:01 +00:00
|
|
|
_lastCodePtr = &_res->_types[rtInventory][idx]._address;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2003-09-11 10:32:15 +00:00
|
|
|
case WIO_LOCAL:
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_ROOM: /* room script */
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version == 8) {
|
2002-12-24 23:26:37 +00:00
|
|
|
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
|
2011-05-13 12:48:01 +00:00
|
|
|
assert(_roomResource < (int)_res->_types[rtRoomScripts].size());
|
|
|
|
_lastCodePtr = &_res->_types[rtRoomScripts][_roomResource]._address;
|
2002-12-24 23:26:37 +00:00
|
|
|
} else {
|
|
|
|
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
|
2003-12-26 23:11:35 +00:00
|
|
|
assert(_roomResource < _numRooms);
|
2011-05-13 12:48:01 +00:00
|
|
|
_lastCodePtr = &_res->_types[rtRoom][_roomResource]._address;
|
2002-12-24 23:26:37 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_GLOBAL: /* global script */
|
2001-11-05 19:21:49 +00:00
|
|
|
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
|
2003-12-26 23:11:35 +00:00
|
|
|
assert(ss->number < _numScripts);
|
2011-05-13 12:48:01 +00:00
|
|
|
_lastCodePtr = &_res->_types[rtScript][ss->number]._address;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case WIO_FLOBJECT: /* flobject script */
|
2002-03-08 08:42:11 +00:00
|
|
|
idx = getObjectIndex(ss->number);
|
2004-09-01 07:59:30 +00:00
|
|
|
assert(idx != -1);
|
|
|
|
idx = _objs[idx].fl_object_index;
|
|
|
|
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
|
|
|
|
assert(idx < _numFlObject);
|
2011-05-13 12:48:01 +00:00
|
|
|
_lastCodePtr = &_res->_types[rtFlObject][idx]._address;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Bad type while getting base address");
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-06-04 18:08:05 +00:00
|
|
|
// The following fixes bug #1202487. Confirmed against disasm.
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version <= 2 && _scriptOrgPointer == NULL) {
|
2005-06-04 18:08:05 +00:00
|
|
|
ss->status = ssDead;
|
|
|
|
_currentScript = 0xFF;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 18:43:13 +00:00
|
|
|
void ScummEngine::resetScriptPointer() {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_currentScript == 0xFF)
|
|
|
|
return;
|
|
|
|
_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
|
|
|
|
}
|
|
|
|
|
2010-10-18 18:43:13 +00:00
|
|
|
/**
|
|
|
|
* This method checks whether the resource that contains the active script
|
|
|
|
* moved, and if so, updates the script pointer accordingly.
|
|
|
|
*
|
|
|
|
* The script resource may have moved because it might have been garbage
|
|
|
|
* collected by ResourceManager::expireResources.
|
|
|
|
*/
|
|
|
|
void ScummEngine::refreshScriptPointer() {
|
2011-05-11 16:06:30 +00:00
|
|
|
if (*_lastCodePtr != _scriptOrgPointer) {
|
2010-10-18 18:43:13 +00:00
|
|
|
long oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
|
|
getScriptBaseAddress();
|
|
|
|
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 09:27:02 +00:00
|
|
|
/** Execute a script - Read opcode, and execute it from the table */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::executeScript() {
|
2003-04-20 08:04:27 +00:00
|
|
|
int c;
|
2001-10-09 14:30:12 +00:00
|
|
|
while (_currentScript != 0xFF) {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-04-20 14:28:25 +00:00
|
|
|
if (_showStack == 1) {
|
2010-11-01 21:37:47 +00:00
|
|
|
debugN("Stack:");
|
2009-04-16 09:27:02 +00:00
|
|
|
for (c = 0; c < _scummStackPos; c++) {
|
2010-11-01 21:37:47 +00:00
|
|
|
debugN(" %d", _vmStack[c]);
|
2003-04-20 08:04:27 +00:00
|
|
|
}
|
2010-11-01 21:37:47 +00:00
|
|
|
debugN("\n");
|
2003-04-20 08:04:27 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
_opcode = fetchScriptByte();
|
2006-10-29 18:42:28 +00:00
|
|
|
if (_game.version > 2) // V0-V2 games didn't use the didexec flag
|
|
|
|
vm.slot[_currentScript].didexec = true;
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_OPCODES, "Script %d, offset 0x%x: [%X] %s()",
|
2002-12-23 18:37:56 +00:00
|
|
|
vm.slot[_currentScript].number,
|
2009-07-04 18:54:27 +00:00
|
|
|
(uint)(_scriptPointer - _scriptOrgPointer),
|
2002-12-23 18:37:56 +00:00
|
|
|
_opcode,
|
|
|
|
getOpcodeDesc(_opcode));
|
2003-04-20 08:04:27 +00:00
|
|
|
if (_hexdumpScripts == true) {
|
2009-04-16 09:27:02 +00:00
|
|
|
for (c = -1; c < 15; c++) {
|
2010-11-01 21:37:47 +00:00
|
|
|
debugN(" %02x", *(_scriptPointer + c));
|
2003-04-20 08:04:27 +00:00
|
|
|
}
|
2010-11-01 21:37:47 +00:00
|
|
|
debugN("\n");
|
2003-04-20 08:04:27 +00:00
|
|
|
}
|
2006-01-28 16:30:39 +00:00
|
|
|
|
2002-12-16 12:12:31 +00:00
|
|
|
executeOpcode(_opcode);
|
2006-01-28 16:30:39 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-16 12:12:31 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2009-04-16 09:26:37 +00:00
|
|
|
void ScummEngine::executeOpcode(byte i) {
|
2009-04-16 09:27:02 +00:00
|
|
|
if (_opcodes[i].proc && _opcodes[i].proc->isValid())
|
|
|
|
(*_opcodes[i].proc)();
|
|
|
|
else {
|
|
|
|
error("Invalid opcode '%x' at %lx", i, (long)(_scriptPointer - _scriptOrgPointer));
|
|
|
|
}
|
2009-04-16 09:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ScummEngine::getOpcodeDesc(byte i) {
|
2011-05-17 13:50:11 +00:00
|
|
|
#ifndef REDUCE_MEMORY_USAGE
|
2009-04-16 09:26:37 +00:00
|
|
|
return _opcodes[i].desc;
|
2011-05-17 13:50:11 +00:00
|
|
|
#else
|
|
|
|
return "";
|
|
|
|
#endif
|
2009-04-16 09:26:37 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
byte ScummEngine::fetchScriptByte() {
|
2010-10-18 18:43:13 +00:00
|
|
|
refreshScriptPointer();
|
2001-10-09 14:30:12 +00:00
|
|
|
return *_scriptPointer++;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
uint ScummEngine::fetchScriptWord() {
|
2010-10-18 18:43:13 +00:00
|
|
|
refreshScriptPointer();
|
2008-11-20 13:50:53 +00:00
|
|
|
uint a = READ_LE_UINT16(_scriptPointer);
|
2001-10-09 14:30:12 +00:00
|
|
|
_scriptPointer += 2;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::fetchScriptWordSigned() {
|
2002-12-23 00:23:36 +00:00
|
|
|
return (int16)fetchScriptWord();
|
|
|
|
}
|
|
|
|
|
2006-02-11 00:44:04 +00:00
|
|
|
uint ScummEngine::fetchScriptDWord() {
|
2010-10-18 18:43:13 +00:00
|
|
|
refreshScriptPointer();
|
2008-11-20 13:50:53 +00:00
|
|
|
uint a = READ_LE_UINT32(_scriptPointer);
|
2006-02-11 00:44:04 +00:00
|
|
|
_scriptPointer += 4;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScummEngine::fetchScriptDWordSigned() {
|
|
|
|
return (int32)fetchScriptDWord();
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::readVar(uint var) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int a;
|
2003-05-04 12:02:37 +00:00
|
|
|
|
2004-07-24 07:18:18 +00:00
|
|
|
debugC(DEBUG_VARS, "readvar(%d)", var);
|
2003-05-04 12:02:37 +00:00
|
|
|
|
2006-02-20 16:51:30 +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;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(var & 0xF000)) {
|
2003-12-11 06:08:43 +00:00
|
|
|
if (!_copyProtection) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (var == 490 && _game.id == GID_MONKEY2) {
|
2003-12-11 06:08:43 +00:00
|
|
|
var = 518;
|
|
|
|
}
|
2002-11-19 09:16:46 +00:00
|
|
|
}
|
2003-12-11 06:08:43 +00:00
|
|
|
|
2005-05-09 02:38:58 +00:00
|
|
|
if (VAR_SUBTITLES != 0xFF && var == VAR_SUBTITLES) {
|
|
|
|
return ConfMan.getBool("subtitles");
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2005-05-09 02:59:45 +00:00
|
|
|
if (VAR_NOSUBTITLES != 0xFF && var == VAR_NOSUBTITLES) {
|
2005-07-30 21:11:48 +00:00
|
|
|
return !ConfMan.getBool("subtitles");
|
2003-06-12 16:38:43 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numVariables - 1, "variable (reading)");
|
2003-05-08 15:48:50 +00:00
|
|
|
return _scummVars[var];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x8000) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 80) {
|
2004-08-26 23:15:39 +00:00
|
|
|
var &= 0xFFF;
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numRoomVariables - 1, "room variable (reading)");
|
2004-08-26 23:15:39 +00:00
|
|
|
return _roomVars[var];
|
|
|
|
|
2007-03-04 00:44:04 +00:00
|
|
|
} else if (_game.version <= 3 && !(_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns) &&
|
|
|
|
!(_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine)) {
|
2003-05-04 12:02:37 +00:00
|
|
|
int bit = var & 0xF;
|
|
|
|
var = (var >> 4) & 0xFF;
|
|
|
|
|
2003-12-11 06:08:43 +00:00
|
|
|
if (!_copyProtection) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_LOOM && (_game.platform == Common::kPlatformFMTowns) && var == 214 && bit == 15) {
|
2004-07-24 07:18:18 +00:00
|
|
|
return 0;
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_game.id == GID_ZAK && (_game.platform == Common::kPlatformFMTowns) && var == 151 && bit == 8) {
|
2004-07-24 07:18:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-04 12:02:37 +00:00
|
|
|
}
|
2003-12-11 06:08:43 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numVariables - 1, "variable (reading)");
|
2003-05-08 15:48:50 +00:00
|
|
|
return (_scummVars[ var ] & ( 1 << bit ) ) ? 1 : 0;
|
2003-05-04 12:02:37 +00:00
|
|
|
} else {
|
|
|
|
var &= 0x7FFF;
|
2003-12-11 06:08:43 +00:00
|
|
|
if (!_copyProtection) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_INDY3 && (_game.platform == Common::kPlatformFMTowns) && var == 1508)
|
2003-12-11 06:08:43 +00:00
|
|
|
return 0;
|
2003-07-18 05:49:21 +00:00
|
|
|
}
|
2003-12-11 06:08:43 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numBitVariables - 1, "variable (reading)");
|
2003-05-04 12:02:37 +00:00
|
|
|
return (_bitVars[var >> 3] & (1 << (var & 7))) ? 1 : 0;
|
2002-07-30 15:20:30 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x4000) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.features & GF_FEW_LOCALS) {
|
2002-11-03 15:12:39 +00:00
|
|
|
var &= 0xF;
|
|
|
|
} else {
|
|
|
|
var &= 0xFFF;
|
|
|
|
}
|
2003-06-01 10:15:31 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 80)
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, 25, "local variable (reading)");
|
2004-08-26 23:15:39 +00:00
|
|
|
else
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, 20, "local variable (reading)");
|
2001-11-07 18:10:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::writeVar(uint var, int value) {
|
2004-07-24 07:18:18 +00:00
|
|
|
debugC(DEBUG_VARS, "writeVar(%d, %d)", var, value);
|
2004-04-05 22:02:58 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(var & 0xF000)) {
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numVariables - 1, "variable (writing)");
|
2002-05-05 20:08:41 +00:00
|
|
|
|
2005-05-09 02:38:58 +00:00
|
|
|
if (VAR_SUBTITLES != 0xFF && var == VAR_SUBTITLES) {
|
2010-01-28 00:28:08 +00:00
|
|
|
// Ignore default setting in HE72-74 games
|
|
|
|
if (_game.heversion <= 74 && vm.slot[_currentScript].number == 1)
|
2005-11-15 22:42:33 +00:00
|
|
|
return;
|
2005-05-09 02:38:58 +00:00
|
|
|
assert(value == 0 || value == 1);
|
2006-05-09 14:16:43 +00:00
|
|
|
ConfMan.setBool("subtitles", (value != 0));
|
2005-05-09 02:38:58 +00:00
|
|
|
}
|
|
|
|
if (VAR_NOSUBTITLES != 0xFF && var == VAR_NOSUBTITLES) {
|
2005-11-17 10:49:39 +00:00
|
|
|
// Ignore default setting in HE60-71 games
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 60 && vm.slot[_currentScript].number == 1)
|
2005-05-09 02:59:45 +00:00
|
|
|
return;
|
2005-05-09 02:38:58 +00:00
|
|
|
assert(value == 0 || value == 1);
|
2006-04-16 19:23:14 +00:00
|
|
|
ConfMan.setBool("subtitles", !value);
|
2005-05-09 02:38:58 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 03:51:17 +00:00
|
|
|
if (var == VAR_CHARINC) {
|
2008-11-15 13:54:16 +00:00
|
|
|
// Did the user override the talkspeed manually? Then use that.
|
|
|
|
// Otherwise, use the value specified by the game script.
|
|
|
|
// Note: To determine whether there was a user override, we only
|
|
|
|
// look at the target specific settings, assuming that any global
|
|
|
|
// value is likely to be bogus. See also bug #2251765.
|
|
|
|
if (ConfMan.hasKey("talkspeed", _targetName)) {
|
2009-02-13 10:04:17 +00:00
|
|
|
value = getTalkSpeed();
|
2006-06-03 03:51:17 +00:00
|
|
|
} else {
|
|
|
|
// Save the new talkspeed value to ConfMan
|
2009-02-13 10:04:17 +00:00
|
|
|
setTalkSpeed(value);
|
2006-06-03 03:51:17 +00:00
|
|
|
}
|
2003-12-27 15:22:59 +00:00
|
|
|
}
|
2003-06-12 16:38:43 +00:00
|
|
|
|
2006-06-03 04:10:14 +00:00
|
|
|
_scummVars[var] = value;
|
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if ((_varwatch == (int)var) || (_varwatch == 0)) {
|
|
|
|
if (vm.slot[_currentScript].number < 100)
|
2002-12-23 16:17:23 +00:00
|
|
|
debug(1, "vars[%d] = %d (via script-%d)", var, value, vm.slot[_currentScript].number);
|
2002-04-26 14:13:39 +00:00
|
|
|
else
|
2002-12-23 16:17:23 +00:00
|
|
|
debug(1, "vars[%d] = %d (via room-%d-%d)", var, value, _currentRoom,
|
2002-07-07 13:14:34 +00:00
|
|
|
vm.slot[_currentScript].number);
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x8000) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 80) {
|
2004-08-26 23:15:39 +00:00
|
|
|
var &= 0xFFF;
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numRoomVariables - 1, "room variable (writing)");
|
2004-08-26 23:15:39 +00:00
|
|
|
_roomVars[var] = value;
|
|
|
|
|
2007-03-04 00:44:04 +00:00
|
|
|
} else if (_game.version <= 3 && !(_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns) &&
|
|
|
|
!(_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine)) {
|
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;
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numVariables - 1, "variable (writing)");
|
2003-06-07 00:49:36 +00:00
|
|
|
if (value)
|
2003-05-08 15:48:50 +00:00
|
|
|
_scummVars[var] |= ( 1 << bit );
|
2002-07-30 15:20:30 +00:00
|
|
|
else
|
2003-05-08 15:48:50 +00:00
|
|
|
_scummVars[var] &= ~( 1 << bit );
|
2003-05-04 12:02:37 +00:00
|
|
|
} else {
|
|
|
|
var &= 0x7FFF;
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, _numBitVariables - 1, "bit variable (writing)");
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-04 12:02:37 +00:00
|
|
|
if (value)
|
|
|
|
_bitVars[var >> 3] |= (1 << (var & 7));
|
|
|
|
else
|
|
|
|
_bitVars[var >> 3] &= ~(1 << (var & 7));
|
2002-07-30 15:20:30 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (var & 0x4000) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.features & GF_FEW_LOCALS) {
|
2002-11-03 15:12:39 +00:00
|
|
|
var &= 0xF;
|
|
|
|
} else {
|
|
|
|
var &= 0xFFF;
|
|
|
|
}
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 80)
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, 25, "local variable (writing)");
|
2004-08-26 23:15:39 +00:00
|
|
|
else
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, var, 20, "local variable (writing)");
|
2004-08-26 23:15:39 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::push(int a) {
|
2004-01-08 20:37:26 +00:00
|
|
|
assert(_scummStackPos >= 0 && _scummStackPos < ARRAYSIZE(_vmStack));
|
|
|
|
_vmStack[_scummStackPos++] = a;
|
2002-12-16 12:12:31 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::pop() {
|
2008-11-20 13:50:53 +00:00
|
|
|
assert(_scummStackPos >= 1 && _scummStackPos <= ARRAYSIZE(_vmStack));
|
|
|
|
return _vmStack[--_scummStackPos];
|
2002-12-16 12:12:31 +00:00
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-10-02 22:42:03 +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];
|
2006-11-20 03:21:09 +00:00
|
|
|
if (_game.version <= 2) {
|
|
|
|
if (ss->where == WIO_GLOBAL || ss->where == WIO_LOCAL) {
|
|
|
|
stopScript(ss->number);
|
|
|
|
} else {
|
|
|
|
ss->number = 0;
|
|
|
|
ss->status = ssDead;
|
|
|
|
}
|
|
|
|
} else if (_game.version <= 5) {
|
|
|
|
if (ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL) {
|
|
|
|
stopObjectScript(ss->number);
|
|
|
|
} else {
|
|
|
|
if (_game.version >= 4 && ss->cutsceneOverride)
|
|
|
|
error("Script %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2006-11-20 03:21:09 +00:00
|
|
|
ss->number = 0;
|
|
|
|
ss->status = ssDead;
|
2002-04-06 03:43:54 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
} else {
|
2006-11-20 03:21:09 +00:00
|
|
|
if (ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL) {
|
|
|
|
if (ss->cutsceneOverride)
|
|
|
|
error("Object %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
|
|
|
|
} else {
|
|
|
|
if (ss->cutsceneOverride)
|
|
|
|
error("Script %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
|
2002-04-06 03:43:54 +00:00
|
|
|
}
|
2006-11-20 03:21:09 +00:00
|
|
|
ss->number = 0;
|
|
|
|
ss->status = ssDead;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2006-11-20 03:21:09 +00:00
|
|
|
|
2005-04-05 11:06:03 +00:00
|
|
|
nukeArrays(_currentScript);
|
2001-10-16 10:01:48 +00:00
|
|
|
_currentScript = 0xFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::runInventoryScript(int i) {
|
2005-04-20 23:53:29 +00:00
|
|
|
int args[24];
|
|
|
|
memset(args, 0, sizeof(args));
|
|
|
|
args[0] = i;
|
|
|
|
if (VAR(VAR_INVENTORY_SCRIPT)) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformMacintosh) {
|
2008-08-06 09:13:57 +00:00
|
|
|
inventoryScriptIndy3Mac();
|
2005-10-01 13:02:35 +00:00
|
|
|
} else {
|
|
|
|
runScript(VAR(VAR_INVENTORY_SCRIPT), 0, 0, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-06 09:13:57 +00:00
|
|
|
void ScummEngine::inventoryScriptIndy3Mac() {
|
2009-07-29 11:48:20 +00:00
|
|
|
int slot;
|
2005-10-01 13:02:35 +00:00
|
|
|
|
2009-07-29 11:48:20 +00:00
|
|
|
// VAR(67) controls the scroll offset of the inventory in Indy3 for Macintosh.
|
|
|
|
// The inventory consists of two columns with three items visible in each,
|
|
|
|
// so a maximum of six items are visible at once.
|
2005-10-02 01:26:53 +00:00
|
|
|
|
2009-07-29 11:48:20 +00:00
|
|
|
// The scroll offset must be non-negative and if there are six or less items
|
|
|
|
// in the inventory, the inventory is fixed in the top position.
|
|
|
|
const int invCount = getInventoryCount(VAR(VAR_EGO));
|
|
|
|
if (VAR(67) < 0 || invCount <= 6) {
|
2005-10-01 13:02:35 +00:00
|
|
|
VAR(67) = 0;
|
|
|
|
}
|
2009-07-29 11:48:20 +00:00
|
|
|
|
|
|
|
// If there are more than six items in the inventory, clamp the scroll position
|
|
|
|
// to be at most invCount-6, rounded up to the next even integer.
|
|
|
|
bool scrolledToBottom = false;
|
|
|
|
if (invCount > 6 && VAR(67) >= invCount - 6) {
|
|
|
|
VAR(67) = invCount - 6;
|
|
|
|
// Odd number of inventory items? -> increment VAR(67) to make it even
|
|
|
|
if (invCount & 1) {
|
2005-10-01 13:02:35 +00:00
|
|
|
VAR(67)++;
|
|
|
|
}
|
2009-07-29 11:48:20 +00:00
|
|
|
scrolledToBottom = true;
|
2005-10-01 13:02:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 11:48:20 +00:00
|
|
|
// Now update var 83 till 89 to contain the inventory IDs of the
|
|
|
|
// corresponding inventory slots.
|
|
|
|
// Also setup fake verbs for the inventory
|
|
|
|
byte tmp[6] = { 0xFF, 0x06, 0x52, 0x00, 0x00, 0x00 };
|
|
|
|
for (int j = 1; j < 7; j++) {
|
|
|
|
int tmpA = (VAR(67) + j);
|
|
|
|
int tmpB = findInventory(VAR(VAR_EGO), tmpA);
|
|
|
|
VAR(82 + j) = tmpB;
|
|
|
|
|
|
|
|
// Setup fake verb
|
|
|
|
tmp[2] = 0x52 + j;
|
|
|
|
slot = getVerbSlot(100 + j, 0);
|
2005-10-01 13:02:35 +00:00
|
|
|
loadPtrToResource(rtVerb, slot, tmp);
|
2009-07-29 11:48:20 +00:00
|
|
|
|
|
|
|
VerbSlot *vs = &_verbs[slot];
|
2005-10-01 13:02:35 +00:00
|
|
|
vs->type = kTextVerbType;
|
|
|
|
vs->imgindex = 0;
|
|
|
|
vs->curmode = 1;
|
|
|
|
drawVerb(slot, 0);
|
|
|
|
}
|
|
|
|
|
2009-07-29 11:48:20 +00:00
|
|
|
// Enable up arrow if there are more than six items and we are not already
|
|
|
|
// scrolled all the way up.
|
|
|
|
slot = getVerbSlot(107, 0);
|
|
|
|
_verbs[slot].curmode = (invCount > 6 && VAR(67)) ? 1 : 0;
|
|
|
|
drawVerb(slot, 0);
|
|
|
|
|
|
|
|
// Enable down arrow if there are more than six items and we are not already
|
|
|
|
// scrolled all the way down.
|
|
|
|
slot = getVerbSlot(108, 0);
|
|
|
|
_verbs[slot].curmode = (invCount > 6 && !scrolledToBottom) ? 1 : 0;
|
|
|
|
drawVerb(slot, 0);
|
2005-10-01 13:02:35 +00:00
|
|
|
|
2009-07-29 11:48:20 +00:00
|
|
|
// Redraw!
|
2005-10-01 13:02:35 +00:00
|
|
|
verbMouseOver(0);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::freezeScripts(int flag) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version <= 2) {
|
2003-05-29 10:14:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-18 20:57:32 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
|
2003-05-19 11:31:35 +00:00
|
|
|
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
|
|
|
|
2002-04-11 17:19:16 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::unfreezeScripts() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2003-05-29 10:14:53 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version <= 2) {
|
2003-05-29 10:14:53 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
|
|
|
|
vm.slot[i].status &= 0x7F;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-05-18 20:57:32 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vm.slot[i].status & 0x80) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (!--vm.slot[i].freezeCount) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-29 10:14:53 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::runAllScripts() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++)
|
2006-10-29 18:42:28 +00:00
|
|
|
vm.slot[i].didexec = false;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = 0xFF;
|
2006-02-20 16:51:30 +00:00
|
|
|
int numCycles = (_game.heversion >= 90) ? VAR(VAR_NUM_SCRIPT_CYCLES) : 1;
|
2005-02-28 13:23:10 +00:00
|
|
|
|
|
|
|
for (int cycle = 1; cycle <= numCycles; cycle++) {
|
2006-01-10 21:39:14 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++) {
|
2006-10-29 18:42:28 +00:00
|
|
|
if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
|
2006-01-10 21:39:14 +00:00
|
|
|
_currentScript = (byte)i;
|
2005-02-28 13:23:10 +00:00
|
|
|
getScriptBaseAddress();
|
2010-10-18 18:43:13 +00:00
|
|
|
resetScriptPointer();
|
2005-02-28 13:23:10 +00:00
|
|
|
executeScript();
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::runExitScript() {
|
2006-03-15 05:59:30 +00:00
|
|
|
if (VAR_EXIT_SCRIPT != 0xFF && VAR(VAR_EXIT_SCRIPT))
|
2003-05-08 15:48:50 +00:00
|
|
|
runScript(VAR(VAR_EXIT_SCRIPT), 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_EXCD_offs) {
|
|
|
|
int slot = getScriptSlot();
|
2002-03-16 18:03:28 +00:00
|
|
|
vm.slot[slot].status = ssRunning;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].number = 10001;
|
2001-11-12 20:50:36 +00:00
|
|
|
vm.slot[slot].where = WIO_ROOM;
|
2001-12-27 17:51:58 +00:00
|
|
|
vm.slot[slot].offs = _EXCD_offs;
|
2003-05-19 11:31:35 +00:00
|
|
|
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;
|
2005-07-07 09:52:04 +00:00
|
|
|
vm.slot[slot].cycle = 1;
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2003-08-06 12:04:27 +00:00
|
|
|
// 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?
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_INDY3 && !(_game.features & GF_OLD_BUNDLE)) {
|
2002-11-08 18:06:08 +00:00
|
|
|
byte *roomptr = getResourceAddress(rtRoom, _roomResource);
|
2011-04-12 14:53:15 +00:00
|
|
|
const byte *excd = findResourceData(MKTAG('E','X','C','D'), roomptr) - _resourceHeaderSize;
|
2002-11-08 18:06:08 +00:00
|
|
|
if (!excd || (getResourceDataSize(excd) < 1)) {
|
|
|
|
debug(2, "Exit-%d is empty", _roomResource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-29 11:54:51 +00:00
|
|
|
initializeLocals(slot, 0);
|
2002-11-08 18:06:08 +00:00
|
|
|
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))
|
2003-05-08 15:48:50 +00:00
|
|
|
runScript(VAR(VAR_EXIT_SCRIPT2), 0, 0, 0);
|
2012-01-08 19:11:22 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
|
|
|
// WORKAROUND: The spider lair (room 44) will optionally play the sound
|
|
|
|
// of trickling water (sound 215), but it never stops it. The same sound
|
|
|
|
// effect is also used in room 33, so let's do the same fade out that it
|
|
|
|
// does in that room's exit script.
|
|
|
|
if (_game.id == GID_DIG && _currentRoom == 44) {
|
2012-01-14 08:25:52 +00:00
|
|
|
int scriptCmds[] = { 14, 215, 0x600, 0, 30, 0, 0, 0 };
|
2012-01-08 19:11:22 +00:00
|
|
|
_sound->soundKludge(scriptCmds, ARRAYSIZE(scriptCmds));
|
|
|
|
}
|
|
|
|
#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::runEntryScript() {
|
2006-03-15 05:59:30 +00:00
|
|
|
if (VAR_ENTRY_SCRIPT != 0xFF && VAR(VAR_ENTRY_SCRIPT))
|
2003-05-08 15:48:50 +00:00
|
|
|
runScript(VAR(VAR_ENTRY_SCRIPT), 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_ENCD_offs) {
|
|
|
|
int slot = getScriptSlot();
|
2002-03-16 18:03:28 +00:00
|
|
|
vm.slot[slot].status = ssRunning;
|
2001-10-09 14:30:12 +00:00
|
|
|
vm.slot[slot].number = 10002;
|
2001-11-12 20:50:36 +00:00
|
|
|
vm.slot[slot].where = WIO_ROOM;
|
2001-12-27 17:51:58 +00:00
|
|
|
vm.slot[slot].offs = _ENCD_offs;
|
2003-05-19 11:31:35 +00:00
|
|
|
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;
|
2005-07-07 09:52:04 +00:00
|
|
|
vm.slot[slot].cycle = 1;
|
2005-05-29 11:54:51 +00:00
|
|
|
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))
|
2003-05-08 15:48:50 +00:00
|
|
|
runScript(VAR(VAR_ENTRY_SCRIPT2), 0, 0, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::killScriptsAndResources() {
|
2001-10-09 14:30:12 +00:00
|
|
|
ScriptSlot *ss;
|
|
|
|
int i;
|
|
|
|
|
2003-05-18 20:57:32 +00:00
|
|
|
ss = vm.slot;
|
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ss->where == WIO_ROOM || ss->where == WIO_FLOBJECT) {
|
2004-08-03 04:26:30 +00:00
|
|
|
if (ss->cutsceneOverride) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version >= 5)
|
2004-08-03 04:26:30 +00:00
|
|
|
warning("Object %d stopped with active cutscene/override in exit", ss->number);
|
2003-06-02 05:38:45 +00:00
|
|
|
ss->cutsceneOverride = 0;
|
|
|
|
}
|
2004-08-01 13:57:00 +00:00
|
|
|
nukeArrays(i);
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssDead;
|
2002-04-11 17:19:16 +00:00
|
|
|
} else if (ss->where == WIO_LOCAL) {
|
2004-08-03 04:26:30 +00:00
|
|
|
if (ss->cutsceneOverride) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version >= 5)
|
2004-08-03 04:26:30 +00:00
|
|
|
warning("Script %d stopped with active cutscene/override in exit", ss->number);
|
2003-06-02 05:38:45 +00:00
|
|
|
ss->cutsceneOverride = 0;
|
|
|
|
}
|
2004-08-01 13:57:00 +00:00
|
|
|
nukeArrays(i);
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssDead;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
/* Nuke local object names */
|
|
|
|
if (_newNames) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < _numNewNames; i++) {
|
2004-07-31 23:34:07 +00:00
|
|
|
const int obj = _newNames[i];
|
|
|
|
if (obj) {
|
2012-02-04 13:49:44 +00:00
|
|
|
const int owner = getOwner((_game.version != 0 ? obj : OBJECT_V0_ID(obj)));
|
2004-07-31 23:34:07 +00:00
|
|
|
// 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.
|
2006-02-20 16:51:30 +00:00
|
|
|
if (owner == 0 || (_game.version < 7 && owner == OF_OWNER_ROOM)) {
|
2004-07-31 23:34:07 +00:00
|
|
|
// 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).
|
2006-02-20 16:51:30 +00:00
|
|
|
if (owner == OF_OWNER_ROOM && _game.id == GID_INDY4 && 336 <= obj && obj <= 340)
|
2004-07-31 23:34:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
_newNames[i] = 0;
|
2006-09-17 20:36:48 +00:00
|
|
|
_res->nukeResource(rtObjectName, i);
|
2004-07-31 23:34:07 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::killAllScriptsExceptCurrent() {
|
2003-05-18 20:57:32 +00:00
|
|
|
for (int i = 0; i < NUM_SCRIPT_SLOT; i++) {
|
2004-02-16 03:53:03 +00:00
|
|
|
if (i != _currentScript) {
|
2002-12-25 20:29:40 +00:00
|
|
|
vm.slot[i].status = ssDead;
|
2009-02-17 09:41:21 +00:00
|
|
|
vm.slot[i].cutsceneOverride = 0;
|
2004-02-16 03:53:03 +00:00
|
|
|
}
|
2002-12-25 20:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::doSentence(int verb, int objectA, int objectB) {
|
2003-01-01 18:22:41 +00:00
|
|
|
SentenceTab *st;
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version >= 7) {
|
2003-01-01 18:22:41 +00:00
|
|
|
|
2003-05-20 15:41:07 +00:00
|
|
|
if (objectA == objectB)
|
2003-01-01 18:22:41 +00:00
|
|
|
return;
|
|
|
|
|
2006-08-21 10:04:04 +00:00
|
|
|
if (_sentenceNum > 0) {
|
2003-05-20 15:41:07 +00:00
|
|
|
st = &_sentence[_sentenceNum - 1];
|
2005-07-30 21:11:48 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2003-01-01 18:22:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-08-21 10:04:04 +00:00
|
|
|
assert(_sentenceNum < NUM_SENTENCE);
|
2003-05-20 15:41:07 +00:00
|
|
|
st = &_sentence[_sentenceNum++];
|
|
|
|
|
|
|
|
st->verb = verb;
|
|
|
|
st->objectA = objectA;
|
|
|
|
st->objectB = objectB;
|
2003-05-24 17:07:50 +00:00
|
|
|
st->preposition = (objectB != 0);
|
2003-01-01 18:22:41 +00:00
|
|
|
st->freezeCount = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::checkAndRunSentenceScript() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2004-10-16 05:10:15 +00:00
|
|
|
int localParamList[24];
|
2003-07-12 21:28:04 +00:00
|
|
|
const ScriptSlot *ss;
|
2003-05-08 15:58:30 +00:00
|
|
|
int sentenceScript;
|
2006-08-21 10:04:04 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version <= 2)
|
2003-05-08 15:58:30 +00:00
|
|
|
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));
|
2003-05-08 15:58:30 +00:00
|
|
|
if (isScriptInUse(sentenceScript)) {
|
2001-10-09 14:30:12 +00:00
|
|
|
ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
|
2003-05-08 15:58:30 +00:00
|
|
|
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;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
|
|
|
_sentenceNum--;
|
2006-08-21 10:04:04 +00:00
|
|
|
SentenceTab &st = _sentence[_sentenceNum];
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version < 7)
|
2006-08-21 10:04:04 +00:00
|
|
|
if (st.preposition && st.objectB == st.objectA)
|
2002-03-05 23:41:41 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version <= 2) {
|
2006-08-21 10:04:04 +00:00
|
|
|
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));
|
2003-05-17 18:42:31 +00:00
|
|
|
} else {
|
2006-08-21 10:04:04 +00:00
|
|
|
localParamList[0] = st.verb;
|
|
|
|
localParamList[1] = st.objectA;
|
|
|
|
localParamList[2] = st.objectB;
|
2006-01-18 11:53:07 +00:00
|
|
|
|
|
|
|
|
2006-03-02 09:34:48 +00:00
|
|
|
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.
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2011-05-13 12:48:01 +00:00
|
|
|
if (_res->_types[rtScript].size() > 460) {
|
2006-03-02 09:34:48 +00:00
|
|
|
if (sentenceScript == 104)
|
|
|
|
sentenceScript = 29;
|
|
|
|
} else {
|
|
|
|
if (sentenceScript == 103)
|
|
|
|
sentenceScript = 28;
|
|
|
|
}
|
2006-01-18 11:53:07 +00:00
|
|
|
}
|
2003-05-17 18:42:31 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = 0xFF;
|
2003-05-08 15:58:30 +00:00
|
|
|
if (sentenceScript)
|
2003-09-11 10:32:15 +00:00
|
|
|
runScript(sentenceScript, 0, 0, localParamList);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 22:51:13 +00:00
|
|
|
void ScummEngine_v0::walkToActorOrObject(int object) {
|
|
|
|
int x, y, dir;
|
2012-02-04 17:34:08 +00:00
|
|
|
Actor_v0 *a = (Actor_v0 *)derefActor(VAR(VAR_EGO), "walkToObject");
|
2012-01-08 22:51:13 +00:00
|
|
|
|
|
|
|
_walkToObject = object;
|
2012-01-22 22:13:58 +00:00
|
|
|
_walkToObjectState = kWalkToObjectStateWalk;
|
2012-01-08 22:51:13 +00:00
|
|
|
|
2012-01-15 19:11:30 +00:00
|
|
|
if (OBJECT_V0_TYPE(object) == kObjectV0TypeActor) {
|
2012-01-16 21:32:46 +00:00
|
|
|
walkActorToActor(VAR(VAR_EGO), OBJECT_V0_ID(object), 4);
|
2012-01-08 22:51:13 +00:00
|
|
|
x = a->getRealPos().x;
|
|
|
|
y = a->getRealPos().y;
|
|
|
|
} else {
|
|
|
|
walkActorToObject(VAR(VAR_EGO), object);
|
|
|
|
getObjectXYPos(object, x, y, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
VAR(6) = x;
|
|
|
|
VAR(7) = y;
|
|
|
|
|
2012-01-22 22:10:46 +00:00
|
|
|
// actor must not move if frozen
|
|
|
|
if (a->_miscflags & kActorMiscFlagFreeze)
|
|
|
|
a->stopActorMoving();
|
2012-01-22 22:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScummEngine_v0::checkPendingWalkAction() {
|
|
|
|
// before a sentence script is executed, it might be necessary to walk to
|
|
|
|
// and pickup objects before. Check if such an action is pending and handle
|
|
|
|
// it if available.
|
|
|
|
if (_walkToObjectState == kWalkToObjectStateDone)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int actor = VAR(VAR_EGO);
|
2012-02-04 17:34:08 +00:00
|
|
|
Actor_v0 *a = (Actor_v0 *)derefActor(actor, "checkPendingWalkAction");
|
2012-01-22 22:13:58 +00:00
|
|
|
|
|
|
|
// wait until walking or turning action is finished
|
|
|
|
if (a->_moving)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// after walking and turning finally execute the script
|
|
|
|
if (_walkToObjectState == kWalkToObjectStateTurn) {
|
|
|
|
runSentenceScript();
|
|
|
|
// change actor facing
|
2012-01-28 20:15:05 +00:00
|
|
|
} else {
|
|
|
|
int x, y, distX, distY;
|
|
|
|
if (objIsActor(_walkToObject)) {
|
|
|
|
Actor *b = derefActor(objToActor(_walkToObject), "checkPendingWalkAction(2)");
|
|
|
|
x = b->getRealPos().x;
|
|
|
|
y = b->getRealPos().y;
|
|
|
|
if (x < a->getRealPos().x)
|
|
|
|
x += 4;
|
|
|
|
else
|
|
|
|
x -= 4;
|
|
|
|
} else {
|
|
|
|
getObjectXYPos(_walkToObject, x, y);
|
|
|
|
}
|
|
|
|
AdjustBoxResult abr = a->adjustXYToBeInBox(x, y);
|
|
|
|
distX = ABS(a->getRealPos().x - abr.x);
|
|
|
|
distY = ABS(a->getRealPos().y - abr.y);
|
|
|
|
|
|
|
|
if (distX <= 4 && distY <= 8) {
|
|
|
|
if (objIsActor(_walkToObject)) { // walk to actor finished
|
|
|
|
// make actors turn to each other
|
|
|
|
a->faceToObject(_walkToObject);
|
|
|
|
int otherActor = objToActor(_walkToObject);
|
|
|
|
// ignore the plant
|
|
|
|
if (otherActor != 19) {
|
|
|
|
Actor *b = derefActor(otherActor, "checkPendingWalkAction(3)");
|
|
|
|
b->faceToObject(actorToObj(actor));
|
|
|
|
}
|
|
|
|
} else { // walk to object finished
|
2012-02-04 10:18:14 +00:00
|
|
|
int tmpX, tmpY, dir;
|
|
|
|
getObjectXYPos(_walkToObject, tmpX, tmpY, dir);
|
2012-01-28 20:15:05 +00:00
|
|
|
a->turnToDirection(dir);
|
2012-01-22 22:13:58 +00:00
|
|
|
}
|
2012-01-28 20:15:05 +00:00
|
|
|
_walkToObjectState = kWalkToObjectStateTurn;
|
|
|
|
return true;
|
2012-01-22 22:13:58 +00:00
|
|
|
}
|
2012-01-08 22:51:13 +00:00
|
|
|
}
|
2012-01-22 22:13:58 +00:00
|
|
|
|
|
|
|
_walkToObjectState = kWalkToObjectStateDone;
|
|
|
|
return false;
|
2012-01-08 22:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine_v0::checkAndRunSentenceScript() {
|
2012-01-22 22:13:58 +00:00
|
|
|
if (checkPendingWalkAction())
|
2012-01-08 22:51:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_sentenceNum || _sentence[_sentenceNum - 1].freezeCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SentenceTab &st = _sentence[_sentenceNum - 1];
|
|
|
|
|
2012-01-10 22:39:13 +00:00
|
|
|
if (st.preposition && st.objectB == st.objectA) {
|
|
|
|
_sentenceNum--;
|
2012-01-08 22:51:13 +00:00
|
|
|
return;
|
2012-01-10 22:39:13 +00:00
|
|
|
}
|
2012-01-08 22:51:13 +00:00
|
|
|
|
2012-01-22 22:20:27 +00:00
|
|
|
_currentScript = 0xFF;
|
2012-01-08 22:51:13 +00:00
|
|
|
|
2012-01-15 20:43:21 +00:00
|
|
|
assert(st.objectA);
|
2012-01-08 22:51:13 +00:00
|
|
|
|
|
|
|
// If two objects are involved, at least one must be in the actors inventory
|
2012-01-15 20:43:21 +00:00
|
|
|
if (st.objectB &&
|
|
|
|
(OBJECT_V0_TYPE(st.objectA) != kObjectV0TypeFG || _objectOwnerTable[st.objectA] != VAR(VAR_EGO)) &&
|
2012-02-04 13:49:44 +00:00
|
|
|
(OBJECT_V0_TYPE(st.objectB) != kObjectV0TypeFG || _objectOwnerTable[st.objectB] != VAR(VAR_EGO)))
|
2012-01-08 22:51:13 +00:00
|
|
|
{
|
|
|
|
if (getVerbEntrypoint(st.objectA, kVerbPickUp))
|
|
|
|
doSentence(kVerbPickUp, st.objectA, 0);
|
|
|
|
else if (getVerbEntrypoint(st.objectB, kVerbPickUp))
|
|
|
|
doSentence(kVerbPickUp, st.objectB, 0);
|
|
|
|
else
|
|
|
|
_sentenceNum--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cmdVerb = st.verb;
|
2012-01-15 20:43:21 +00:00
|
|
|
_cmdObject = st.objectA;
|
|
|
|
_cmdObject2 = st.objectB;
|
2012-01-08 22:51:13 +00:00
|
|
|
_sentenceNum--;
|
|
|
|
|
2012-01-22 22:20:27 +00:00
|
|
|
// abort sentence execution if the number of nested scripts is too high.
|
|
|
|
// This might happen for instance if the sentence command depends on an
|
|
|
|
// object that the actor has to pick-up in a nested doSentence() call.
|
|
|
|
// If the actor is not able to pick-up the object (e.g. because it is not
|
|
|
|
// reachable or pickupable) a nested pick-up command is triggered again
|
|
|
|
// and again, so the actual sentence command will never be executed.
|
|
|
|
// In this case the sentence command has to be aborted.
|
|
|
|
_sentenceNestedCount++;
|
|
|
|
if (_sentenceNestedCount > 6) {
|
|
|
|
_sentenceNestedCount = 0;
|
|
|
|
_sentenceNum = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-01-08 22:51:13 +00:00
|
|
|
|
|
|
|
if (whereIsObject(st.objectA) != WIO_INVENTORY) {
|
|
|
|
if (_currentMode != kModeKeypad) {
|
|
|
|
walkToActorOrObject(st.objectA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (st.objectB && whereIsObject(st.objectB) != WIO_INVENTORY) {
|
|
|
|
walkToActorOrObject(st.objectB);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
runSentenceScript();
|
|
|
|
if (_currentMode == kModeKeypad) {
|
2012-01-22 22:13:58 +00:00
|
|
|
_walkToObjectState = kWalkToObjectStateDone;
|
2012-01-08 22:51:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine_v0::runSentenceScript() {
|
2012-01-21 13:06:19 +00:00
|
|
|
_redrawSentenceLine = true;
|
2012-01-10 22:15:53 +00:00
|
|
|
|
2012-01-15 20:43:21 +00:00
|
|
|
if (getVerbEntrypoint(_cmdObject, _cmdVerb) != 0) {
|
2012-01-09 22:21:08 +00:00
|
|
|
// do not read in the dark
|
|
|
|
if (!(_cmdVerb == kVerbRead && _currentLights == 0)) {
|
2012-01-16 21:32:46 +00:00
|
|
|
VAR(VAR_ACTIVE_OBJECT2) = OBJECT_V0_ID(_cmdObject2);
|
2012-01-15 20:43:21 +00:00
|
|
|
runObjectScript(_cmdObject, _cmdVerb, false, false, NULL);
|
2012-01-08 22:51:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_cmdVerb == kVerbGive) {
|
2012-01-09 22:21:08 +00:00
|
|
|
// no "give to"-script: give to other kid or ignore
|
2012-01-16 21:32:46 +00:00
|
|
|
int actor = OBJECT_V0_ID(_cmdObject2);
|
2012-01-15 20:43:21 +00:00
|
|
|
if (actor < 8)
|
|
|
|
setOwnerOf(_cmdObject, actor);
|
2012-01-08 22:51:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 22:21:08 +00:00
|
|
|
|
|
|
|
if (_cmdVerb != kVerbWalkTo) {
|
|
|
|
// perform verb's fallback action
|
|
|
|
VAR(VAR_ACTIVE_VERB) = _cmdVerb;
|
|
|
|
runScript(3, 0, 0, 0);
|
|
|
|
}
|
2012-01-08 22:51:13 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 23:08:15 +00:00
|
|
|
void ScummEngine_v2::runInputScript(int clickArea, int val, int mode) {
|
2004-10-16 05:10:15 +00:00
|
|
|
int args[24];
|
2003-05-17 06:18:34 +00:00
|
|
|
int verbScript;
|
|
|
|
|
2006-03-02 01:17:41 +00:00
|
|
|
verbScript = 4;
|
2007-06-29 23:08:15 +00:00
|
|
|
VAR(VAR_CLICK_AREA) = clickArea;
|
|
|
|
switch (clickArea) {
|
|
|
|
case kVerbClickArea: // Verb clicked
|
|
|
|
VAR(VAR_CLICK_VERB) = val;
|
2006-03-02 01:17:41 +00:00
|
|
|
break;
|
2007-06-29 23:08:15 +00:00
|
|
|
case kInventoryClickArea: // Inventory clicked
|
|
|
|
VAR(VAR_CLICK_OBJECT) = val;
|
2006-03-02 01:17:41 +00:00
|
|
|
break;
|
2003-05-21 23:54:39 +00:00
|
|
|
}
|
2003-05-17 06:18:34 +00:00
|
|
|
|
2006-03-02 01:17:41 +00:00
|
|
|
memset(args, 0, sizeof(args));
|
2007-06-29 23:08:15 +00:00
|
|
|
args[0] = clickArea;
|
|
|
|
args[1] = val;
|
2006-03-02 01:17:41 +00:00
|
|
|
args[2] = mode;
|
|
|
|
|
|
|
|
if (verbScript)
|
|
|
|
runScript(verbScript, 0, 0, args);
|
|
|
|
}
|
|
|
|
|
2007-06-29 23:08:15 +00:00
|
|
|
void ScummEngine::runInputScript(int clickArea, int val, int mode) {
|
2006-03-02 01:17:41 +00:00
|
|
|
int args[24];
|
|
|
|
int verbScript;
|
|
|
|
|
|
|
|
verbScript = VAR(VAR_VERB_SCRIPT);
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
memset(args, 0, sizeof(args));
|
2007-06-29 23:08:15 +00:00
|
|
|
args[0] = clickArea;
|
|
|
|
args[1] = val;
|
2001-11-26 19:57:57 +00:00
|
|
|
args[2] = mode;
|
2004-08-29 06:40:03 +00:00
|
|
|
// All HE 72+ games but only some HE 71 games.
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.heversion >= 71) {
|
2004-08-29 06:40:03 +00:00
|
|
|
args[3] = VAR(VAR_VIRT_MOUSE_X);
|
|
|
|
args[4] = VAR(VAR_VIRT_MOUSE_Y);
|
|
|
|
}
|
2005-10-02 01:26:53 +00:00
|
|
|
|
2009-07-29 18:35:34 +00:00
|
|
|
// Macintosh version of indy3ega used different interface, so adjust values.
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformMacintosh) {
|
2007-06-29 23:08:15 +00:00
|
|
|
if (clickArea == kVerbClickArea && (val >= 101 && val <= 108)) {
|
|
|
|
if (val == 107) {
|
2005-10-02 01:26:53 +00:00
|
|
|
VAR(67) -= 2;
|
2008-08-06 09:13:57 +00:00
|
|
|
inventoryScriptIndy3Mac();
|
2005-10-02 01:26:53 +00:00
|
|
|
return;
|
2007-06-29 23:08:15 +00:00
|
|
|
} else if (val == 108) {
|
2005-10-02 01:26:53 +00:00
|
|
|
VAR(67) += 2;
|
2008-08-06 09:13:57 +00:00
|
|
|
inventoryScriptIndy3Mac();
|
2005-10-02 01:26:53 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2009-07-29 11:48:20 +00:00
|
|
|
args[0] = kInventoryClickArea;
|
|
|
|
args[1] = VAR(82 + (val - 100));
|
2005-10-02 01:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-29 20:35:50 +00:00
|
|
|
|
|
|
|
// Clicks are handled differently in Indy3 mac: param 2 of the
|
|
|
|
// input script is set to 0 for normal clicks, and to 1 for double clicks.
|
2012-12-14 23:28:44 +00:00
|
|
|
// The EGA DOS version of Loom also checks that the second click happens
|
|
|
|
// close enough to the first one, but that seems like overkill.
|
2009-07-29 20:35:50 +00:00
|
|
|
uint32 time = _system->getMillis();
|
|
|
|
args[2] = (time < _lastInputScriptTime + 500); // 500 ms double click delay
|
|
|
|
_lastInputScriptTime = time;
|
2012-12-14 23:28:44 +00:00
|
|
|
} else if (_game.id == GID_LOOM && _game.platform == Common::kPlatformMacintosh) {
|
|
|
|
uint32 time = _system->getMillis();
|
|
|
|
VAR(52) = (time < _lastInputScriptTime + 500); // 500 ms double click delay
|
|
|
|
_lastInputScriptTime = time;
|
2005-10-02 01:26:53 +00:00
|
|
|
}
|
|
|
|
|
2003-05-17 06:18:34 +00:00
|
|
|
if (verbScript)
|
|
|
|
runScript(verbScript, 0, 0, args);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::decreaseScriptDelay(int amount) {
|
2003-05-18 20:57:32 +00:00
|
|
|
ScriptSlot *ss = vm.slot;
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
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;
|
2002-04-11 17:19:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
bool ScummEngine::isScriptInUse(int script) const {
|
2003-05-20 20:58:26 +00:00
|
|
|
int i;
|
2003-06-25 23:25:52 +00:00
|
|
|
const ScriptSlot *ss = vm.slot;
|
2003-05-20 20:58:26 +00:00
|
|
|
for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
|
|
|
|
if (ss->number == script)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
bool ScummEngine::isScriptRunning(int script) const {
|
2001-10-16 10:01:48 +00:00
|
|
|
int i;
|
2003-06-25 23:25:52 +00:00
|
|
|
const ScriptSlot *ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
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)
|
2001-11-26 19:57:57 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
bool ScummEngine::isRoomScriptRunning(int script) const {
|
2001-11-26 19:57:57 +00:00
|
|
|
int i;
|
2003-06-25 23:25:52 +00:00
|
|
|
const ScriptSlot *ss = vm.slot;
|
2002-04-11 17:19:16 +00:00
|
|
|
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)
|
2001-11-26 19:57:57 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-05 09:36:51 +00:00
|
|
|
void ScummEngine::copyScriptString(byte *dst) {
|
|
|
|
int len = resStrLen(_scriptPointer) + 1;
|
2010-10-18 18:55:24 +00:00
|
|
|
memcpy(dst, _scriptPointer, len);
|
|
|
|
_scriptPointer += len;
|
|
|
|
dst += len;
|
2004-08-30 11:52:33 +00:00
|
|
|
*dst = 0;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 18:55:24 +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) {
|
2002-12-28 01:57:19 +00:00
|
|
|
int num = 0;
|
|
|
|
byte chr;
|
2010-10-18 18:55:24 +00:00
|
|
|
if (src == NULL) {
|
|
|
|
refreshScriptPointer();
|
2002-12-28 01:57:19 +00:00
|
|
|
src = _scriptPointer;
|
2010-10-18 18:55:24 +00:00
|
|
|
}
|
2002-12-28 01:57:19 +00:00
|
|
|
while ((chr = *src++) != 0) {
|
|
|
|
num++;
|
2006-09-02 12:47:29 +00:00
|
|
|
if (_game.heversion <= 71 && chr == 0xFF) {
|
2002-12-28 01:57:19 +00:00
|
|
|
chr = *src++;
|
|
|
|
num++;
|
|
|
|
|
2004-08-02 20:55:35 +00:00
|
|
|
// WORKAROUND for bug #985948, a script bug in Indy3. See also
|
2005-05-26 14:14:32 +00:00
|
|
|
// the corresponding code in ScummEngine::convertMessageToString().
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_INDY3 && chr == 0x2E) {
|
2004-08-02 20:55:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-12-28 01:57:19 +00:00
|
|
|
if (chr != 1 && chr != 2 && chr != 3 && chr != 8) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.version == 8) {
|
2002-12-28 01:57:19 +00:00
|
|
|
src += 4;
|
|
|
|
num += 4;
|
|
|
|
} else {
|
|
|
|
src += 2;
|
|
|
|
num += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2001-11-09 18:54:15 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::beginCutscene(int *args) {
|
2003-01-01 18:22:41 +00:00
|
|
|
int scr = _currentScript;
|
|
|
|
vm.slot[scr].cutsceneOverride++;
|
|
|
|
|
2011-04-04 07:56:50 +00:00
|
|
|
++vm.cutSceneStackPointer;
|
2011-04-05 09:13:08 +00:00
|
|
|
if (vm.cutSceneStackPointer >= kMaxCutsceneNum)
|
2003-01-01 18:22:41 +00:00
|
|
|
error("Cutscene stack overflow");
|
|
|
|
|
|
|
|
vm.cutSceneData[vm.cutSceneStackPointer] = args[0];
|
|
|
|
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
|
|
|
|
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
|
|
|
|
|
|
|
|
vm.cutSceneScriptIndex = scr;
|
2003-05-08 15:48:50 +00:00
|
|
|
if (VAR(VAR_CUTSCENE_START_SCRIPT))
|
|
|
|
runScript(VAR(VAR_CUTSCENE_START_SCRIPT), 0, 0, args);
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutSceneScriptIndex = 0xFF;
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::endCutscene() {
|
2003-01-01 18:22:41 +00:00
|
|
|
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));
|
2003-01-01 18:22:41 +00:00
|
|
|
args[0] = vm.cutSceneData[vm.cutSceneStackPointer];
|
2005-03-25 00:40:58 +00:00
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
VAR(VAR_OVERRIDE) = 0;
|
2003-01-01 18:22:41 +00:00
|
|
|
|
|
|
|
if (vm.cutScenePtr[vm.cutSceneStackPointer] && (ss->cutsceneOverride > 0)) // Only terminate if active
|
|
|
|
ss->cutsceneOverride--;
|
|
|
|
|
|
|
|
vm.cutSceneScript[vm.cutSceneStackPointer] = 0;
|
|
|
|
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
|
2011-04-04 07:56:50 +00:00
|
|
|
|
|
|
|
if (0 == vm.cutSceneStackPointer)
|
|
|
|
error("Cutscene stack underflow");
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutSceneStackPointer--;
|
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
if (VAR(VAR_CUTSCENE_END_SCRIPT))
|
|
|
|
runScript(VAR(VAR_CUTSCENE_END_SCRIPT), 0, 0, args);
|
2003-01-01 18:22:41 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::abortCutscene() {
|
2005-03-25 00:40:58 +00:00
|
|
|
const int idx = vm.cutSceneStackPointer;
|
2011-04-05 09:13:08 +00:00
|
|
|
assert(0 <= idx && idx < kMaxCutsceneNum);
|
2005-03-25 00:40:58 +00:00
|
|
|
|
|
|
|
uint32 offs = vm.cutScenePtr[idx];
|
2001-11-09 18:54:15 +00:00
|
|
|
if (offs) {
|
2005-03-25 00:40:58 +00:00
|
|
|
ScriptSlot *ss = &vm.slot[vm.cutSceneScript[idx]];
|
2001-11-09 18:54:15 +00:00
|
|
|
ss->offs = offs;
|
2002-12-09 01:27:40 +00:00
|
|
|
ss->status = ssRunning;
|
2001-11-09 18:54:15 +00:00
|
|
|
ss->freezeCount = 0;
|
2002-04-05 16:41:02 +00:00
|
|
|
|
|
|
|
if (ss->cutsceneOverride > 0)
|
2002-04-11 17:19:16 +00:00
|
|
|
ss->cutsceneOverride--;
|
2002-04-05 16:41:02 +00:00
|
|
|
|
2005-09-14 10:36:18 +00:00
|
|
|
VAR(VAR_OVERRIDE) = 1;
|
2005-03-25 00:40:58 +00:00
|
|
|
vm.cutScenePtr[idx] = 0;
|
2001-11-09 18:54:15 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::beginOverride() {
|
2005-03-25 00:40:58 +00:00
|
|
|
const int idx = vm.cutSceneStackPointer;
|
2011-04-05 09:13:08 +00:00
|
|
|
assert(0 <= idx && idx < kMaxCutsceneNum);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutScenePtr[idx] = _scriptPointer - _scriptOrgPointer;
|
|
|
|
vm.cutSceneScript[idx] = _currentScript;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
// 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();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-03-15 06:29:28 +00:00
|
|
|
if (_game.version >= 5)
|
|
|
|
VAR(VAR_OVERRIDE) = 0;
|
2003-01-01 18:22:41 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::endOverride() {
|
2005-03-25 00:40:58 +00:00
|
|
|
const int idx = vm.cutSceneStackPointer;
|
2011-04-05 09:13:08 +00:00
|
|
|
assert(0 <= idx && idx < kMaxCutsceneNum);
|
2002-09-22 01:17:53 +00:00
|
|
|
|
2003-01-01 18:22:41 +00:00
|
|
|
vm.cutScenePtr[idx] = 0;
|
|
|
|
vm.cutSceneScript[idx] = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-03-15 06:29:28 +00:00
|
|
|
if (_game.version >= 4)
|
2003-05-21 21:41:27 +00:00
|
|
|
VAR(VAR_OVERRIDE) = 0;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
} // End of namespace Scumm
|