2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2004-04-12 21:40:49 +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.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Scripting module: Script resource handling functions
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/gfx.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/script.h"
|
2004-12-15 00:24:12 +00:00
|
|
|
#include "saga/stream.h"
|
2005-01-08 20:30:07 +00:00
|
|
|
#include "saga/interface.h"
|
2005-01-28 12:54:09 +00:00
|
|
|
#include "saga/itedata.h"
|
2005-01-15 20:12:49 +00:00
|
|
|
#include "saga/scene.h"
|
|
|
|
#include "saga/events.h"
|
|
|
|
#include "saga/actor.h"
|
|
|
|
#include "saga/objectmap.h"
|
2005-02-26 17:37:16 +00:00
|
|
|
#include "saga/isomap.h"
|
2005-07-19 19:05:52 +00:00
|
|
|
#include "saga/rscfile.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Initializes the scripting module.
|
|
|
|
// Loads script resource look-up table, initializes script data system
|
2005-07-19 19:05:52 +00:00
|
|
|
Script::Script(SagaEngine *vm) : _vm(vm) {
|
|
|
|
ResourceContext *resourceContext;
|
2005-01-21 21:55:54 +00:00
|
|
|
byte *resourcePointer;
|
|
|
|
size_t resourceLength;
|
2004-05-04 03:33:03 +00:00
|
|
|
int prevTell;
|
|
|
|
int i, j;
|
2005-01-08 20:30:07 +00:00
|
|
|
byte *stringsPointer;
|
|
|
|
size_t stringsLength;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-01 22:48:40 +00:00
|
|
|
//initialize member variables
|
2004-10-27 02:27:54 +00:00
|
|
|
_abortEnabled = true;
|
|
|
|
_skipSpeeches = false;
|
2005-01-17 20:17:06 +00:00
|
|
|
_conversingThread = NULL;
|
2004-12-22 21:04:50 +00:00
|
|
|
|
2005-01-17 07:21:08 +00:00
|
|
|
_firstObjectSet = false;
|
|
|
|
_secondObjectNeeded = false;
|
2006-01-13 20:20:01 +00:00
|
|
|
_pendingVerb = getVerbType(kVerbNone);
|
|
|
|
_currentVerb = getVerbType(kVerbNone);
|
|
|
|
_stickyVerb = getVerbType(kVerbWalkTo);
|
|
|
|
_leftButtonVerb = getVerbType(kVerbNone);
|
|
|
|
_rightButtonVerb = getVerbType(kVerbNone);
|
2005-06-10 13:56:51 +00:00
|
|
|
_pointerObject = ID_NOTHING;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
_staticSize = 0;
|
|
|
|
_commonBufferSize = COMMON_BUFFER_SIZE;
|
|
|
|
_commonBuffer = (byte*)malloc(_commonBufferSize);
|
|
|
|
memset(_commonBuffer, 0, _commonBufferSize);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(8, "Initializing scripting subsystem");
|
2004-05-01 14:05:10 +00:00
|
|
|
// Load script resource file context
|
2005-07-19 19:05:52 +00:00
|
|
|
_scriptContext = _vm->_resource->getContext(GAME_SCRIPTFILE);
|
2004-11-15 03:03:48 +00:00
|
|
|
if (_scriptContext == NULL) {
|
2005-07-19 19:05:52 +00:00
|
|
|
error("Script::Script() script context not found");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
resourceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
|
2005-01-21 21:55:54 +00:00
|
|
|
if (resourceContext == NULL) {
|
2005-07-19 19:05:52 +00:00
|
|
|
error("Script::Script() resource context not found");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(3, "Loading module LUT from resource %i", _vm->getResourceDescription()->moduleLUTResourceId);
|
|
|
|
_vm->_resource->loadResource(resourceContext, _vm->getResourceDescription()->moduleLUTResourceId, resourcePointer, resourceLength);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Create logical script LUT from resource
|
2005-01-21 21:55:54 +00:00
|
|
|
if (resourceLength % S_LUT_ENTRYLEN_ITECD == 0) {
|
|
|
|
_modulesLUTEntryLen = S_LUT_ENTRYLEN_ITECD;
|
|
|
|
} else if (resourceLength % S_LUT_ENTRYLEN_ITEDISK == 0) {
|
|
|
|
_modulesLUTEntryLen = S_LUT_ENTRYLEN_ITEDISK;
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2006-03-08 11:37:25 +00:00
|
|
|
error("Script::Script() Invalid script lookup table length (%i)", (int)resourceLength);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Calculate number of entries
|
2005-01-21 21:55:54 +00:00
|
|
|
_modulesCount = resourceLength / _modulesLUTEntryLen;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(3, "LUT has %i entries", _modulesCount);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Allocate space for logical LUT
|
2005-01-21 21:55:54 +00:00
|
|
|
_modules = (ModuleData *)malloc(_modulesCount * sizeof(*_modules));
|
|
|
|
if (_modules == NULL) {
|
|
|
|
memoryError("Script::Script()");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Convert LUT resource to logical LUT
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, resourceContext->isBigEndian);
|
2005-01-21 21:55:54 +00:00
|
|
|
for (i = 0; i < _modulesCount; i++) {
|
|
|
|
memset(&_modules[i], 0, sizeof(ModuleData));
|
|
|
|
|
2004-08-22 18:28:42 +00:00
|
|
|
prevTell = scriptS.pos();
|
2005-01-21 21:55:54 +00:00
|
|
|
_modules[i].scriptResourceId = scriptS.readUint16();
|
|
|
|
_modules[i].stringsResourceId = scriptS.readUint16();
|
|
|
|
_modules[i].voicesResourceId = scriptS.readUint16();
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Skip the unused portion of the structure
|
2005-01-21 21:55:54 +00:00
|
|
|
for (j = scriptS.pos(); j < prevTell + _modulesLUTEntryLen; j++) {
|
2004-08-22 18:28:42 +00:00
|
|
|
if (scriptS.readByte() != 0)
|
2004-10-09 07:39:46 +00:00
|
|
|
warning("Unused scriptLUT part isn't really unused for LUT %d (pos: %d)", i, j);
|
2004-08-22 18:28:42 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
free(resourcePointer);
|
2005-06-08 13:49:56 +00:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
//
|
|
|
|
// In ITE, the "main strings" resource contains both the verb strings
|
|
|
|
// and the object names.
|
|
|
|
//
|
2005-10-08 21:28:14 +00:00
|
|
|
// In IHNM, the "main strings" contains the verb strings, but not the
|
2005-10-08 21:33:31 +00:00
|
|
|
// object names. At least, I think that's the case.
|
2005-06-08 13:49:56 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_resource->loadResource(resourceContext, _vm->getResourceDescription()->mainStringsResourceId, stringsPointer, stringsLength);
|
2005-01-08 20:30:07 +00:00
|
|
|
|
|
|
|
_vm->loadStrings(_mainStrings, stringsPointer, stringsLength);
|
2005-07-19 19:05:52 +00:00
|
|
|
free(stringsPointer);
|
2005-01-08 20:30:07 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
setupScriptFuncList();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Shut down script module gracefully; free all allocated module resources
|
2004-08-01 22:48:40 +00:00
|
|
|
Script::~Script() {
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(8, "Shutting down scripting subsystem.");
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-08 20:30:07 +00:00
|
|
|
_mainStrings.freeMem();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
freeModules();
|
|
|
|
free(_modules);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
free(_commonBuffer);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-12-22 21:04:50 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
void Script::loadModule(int scriptModuleNumber) {
|
|
|
|
byte *resourcePointer;
|
|
|
|
size_t resourceLength;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Validate script number
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((scriptModuleNumber < 0) || (scriptModuleNumber >= _modulesCount)) {
|
|
|
|
error("Script::loadScript() Invalid script module number");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (_modules[scriptModuleNumber].loaded) {
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
// Initialize script data structure
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(3, "Loading script module #%d", scriptModuleNumber);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].scriptResourceId, resourcePointer, resourceLength);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
loadModuleBase(_modules[scriptModuleNumber], resourcePointer, resourceLength);
|
2005-07-19 19:05:52 +00:00
|
|
|
free(resourcePointer);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].stringsResourceId, resourcePointer, resourceLength);
|
2005-06-08 13:49:56 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
_vm->loadStrings(_modules[scriptModuleNumber].strings, resourcePointer, resourceLength);
|
2005-07-19 19:05:52 +00:00
|
|
|
free(resourcePointer);
|
2005-01-08 20:30:07 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (_modules[scriptModuleNumber].voicesResourceId > 0) {
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_resource->loadResource(_scriptContext, _modules[scriptModuleNumber].voicesResourceId, resourcePointer, resourceLength);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-09 16:01:04 +00:00
|
|
|
loadVoiceLUT(_modules[scriptModuleNumber].voiceLUT, resourcePointer, resourceLength);
|
2005-07-19 19:05:52 +00:00
|
|
|
free(resourcePointer);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
_modules[scriptModuleNumber].staticOffset = _staticSize;
|
|
|
|
_staticSize += _modules[scriptModuleNumber].staticSize;
|
|
|
|
if (_staticSize > _commonBufferSize) {
|
|
|
|
error("Script::loadModule() _staticSize > _commonBufferSize");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-01-21 21:55:54 +00:00
|
|
|
_modules[scriptModuleNumber].loaded = true;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
void Script::freeModules() {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < _modulesCount; i++) {
|
|
|
|
if (_modules[i].loaded) {
|
|
|
|
_modules[i].freeMem();
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-01-21 21:55:54 +00:00
|
|
|
_staticSize = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
void Script::loadModuleBase(ModuleData &module, const byte *resourcePointer, size_t resourceLength) {
|
|
|
|
int i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(3, "Loading module base...");
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
module.moduleBase = (byte*)malloc(resourceLength);
|
|
|
|
module.moduleBaseSize = resourceLength;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
memcpy(module.moduleBase, resourcePointer, resourceLength);
|
2004-05-04 03:33:03 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian scriptS(module.moduleBase, module.moduleBaseSize, _scriptContext->isBigEndian);
|
2005-01-21 21:55:54 +00:00
|
|
|
|
|
|
|
module.entryPointsCount = scriptS.readUint16();
|
2004-12-15 00:24:12 +00:00
|
|
|
scriptS.readUint16(); //skip
|
2005-01-21 21:55:54 +00:00
|
|
|
module.entryPointsTableOffset = scriptS.readUint16();
|
2004-12-15 00:24:12 +00:00
|
|
|
scriptS.readUint16(); //skip
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((module.moduleBaseSize - module.entryPointsTableOffset) < (module.entryPointsCount * SCRIPT_TBLENTRY_LEN)) {
|
|
|
|
error("Script::loadModuleBase() Invalid table offset");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (module.entryPointsCount > SCRIPT_MAX) {
|
|
|
|
error("Script::loadModuleBase()Script limit exceeded");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
module.entryPoints = (EntryPoint *)malloc(module.entryPointsCount * sizeof(*module.entryPoints));
|
|
|
|
if (module.entryPoints == NULL) {
|
|
|
|
memoryError("Script::loadModuleBase");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Read in the entrypoint table
|
2005-07-29 17:58:00 +00:00
|
|
|
|
|
|
|
module.staticSize = scriptS.readUint16();
|
2005-01-21 21:55:54 +00:00
|
|
|
while (scriptS.pos() < module.entryPointsTableOffset)
|
2004-08-22 18:28:42 +00:00
|
|
|
scriptS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
for (i = 0; i < module.entryPointsCount; i++) {
|
2004-05-01 14:05:10 +00:00
|
|
|
// First uint16 is the offset of the entrypoint name from the start
|
2005-07-29 17:58:00 +00:00
|
|
|
// of the bytecode resource, second uint16 is the offset of the
|
2004-05-01 14:05:10 +00:00
|
|
|
// bytecode itself for said entrypoint
|
2005-01-21 21:55:54 +00:00
|
|
|
module.entryPoints[i].nameOffset = scriptS.readUint16();
|
|
|
|
module.entryPoints[i].offset = scriptS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 14:05:10 +00:00
|
|
|
// Perform a simple range check on offset values
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((module.entryPoints[i].nameOffset >= module.moduleBaseSize) || (module.entryPoints[i].offset >= module.moduleBaseSize)) {
|
|
|
|
error("Script::loadModuleBase() Invalid offset encountered in script entrypoint table");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-09 16:01:04 +00:00
|
|
|
void Script::loadVoiceLUT(VoiceLUT &voiceLUT, const byte *resourcePointer, size_t resourceLength) {
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-09 16:01:04 +00:00
|
|
|
voiceLUT.voicesCount = resourceLength / 2;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-09 16:01:04 +00:00
|
|
|
voiceLUT.voices = (uint16 *)malloc(voiceLUT.voicesCount * sizeof(*voiceLUT.voices));
|
|
|
|
if (voiceLUT.voices == NULL) {
|
|
|
|
error("Script::loadVoiceLUT() not enough memory");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian scriptS(resourcePointer, resourceLength, _scriptContext->isBigEndian);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-09 16:01:04 +00:00
|
|
|
for (i = 0; i < voiceLUT.voicesCount; i++) {
|
|
|
|
voiceLUT.voices[i] = scriptS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-08 20:30:07 +00:00
|
|
|
// verb
|
2005-04-18 20:03:14 +00:00
|
|
|
void Script::showVerb(int statusColor) {
|
2005-01-08 20:30:07 +00:00
|
|
|
const char *verbName;
|
|
|
|
const char *object1Name;
|
|
|
|
const char *object2Name;
|
|
|
|
char statusString[STATUS_TEXT_LEN];
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_leftButtonVerb == getVerbType(kVerbNone)) {
|
2005-01-08 20:30:07 +00:00
|
|
|
_vm->_interface->setStatusText("");
|
|
|
|
return;
|
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2007-05-27 11:49:08 +00:00
|
|
|
if (_vm->getGameType() == GType_ITE)
|
|
|
|
verbName = _mainStrings.getString(_leftButtonVerb - 1);
|
|
|
|
else
|
|
|
|
verbName = _mainStrings.getString(_leftButtonVerb + 1);
|
2005-01-08 20:30:07 +00:00
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
if (objectTypeId(_currentObject[0]) == kGameObjectNone) {
|
2005-04-18 20:03:14 +00:00
|
|
|
_vm->_interface->setStatusText(verbName, statusColor);
|
2005-01-08 20:30:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
object1Name = _vm->getObjectName(_currentObject[0]);
|
|
|
|
|
|
|
|
if (!_secondObjectNeeded) {
|
|
|
|
snprintf(statusString, STATUS_TEXT_LEN, "%s %s", verbName, object1Name);
|
2005-04-18 20:03:14 +00:00
|
|
|
_vm->_interface->setStatusText(statusString, statusColor);
|
2005-01-08 20:30:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
if (objectTypeId(_currentObject[1]) != kGameObjectNone) {
|
2005-01-08 20:30:07 +00:00
|
|
|
object2Name = _vm->getObjectName(_currentObject[1]);
|
|
|
|
} else {
|
|
|
|
object2Name = "";
|
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_leftButtonVerb == getVerbType(kVerbGive)) {
|
2005-08-16 19:04:51 +00:00
|
|
|
snprintf(statusString, STATUS_TEXT_LEN, _vm->getTextString(kTextGiveTo), object1Name, object2Name);
|
2005-04-18 20:03:14 +00:00
|
|
|
_vm->_interface->setStatusText(statusString, statusColor);
|
2005-01-08 20:30:07 +00:00
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_leftButtonVerb == getVerbType(kVerbUse)) {
|
2005-08-16 19:04:51 +00:00
|
|
|
snprintf(statusString, STATUS_TEXT_LEN, _vm->getTextString(kTextUseWidth), object1Name, object2Name);
|
2005-04-18 20:03:14 +00:00
|
|
|
_vm->_interface->setStatusText(statusString, statusColor);
|
2005-01-08 20:30:07 +00:00
|
|
|
} else {
|
|
|
|
snprintf(statusString, STATUS_TEXT_LEN, "%s %s", verbName, object1Name);
|
2005-04-18 20:03:14 +00:00
|
|
|
_vm->_interface->setStatusText(statusString, statusColor);
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
int Script::getVerbType(VerbTypes verbType) {
|
|
|
|
if (_vm->getGameType() == GType_ITE) {
|
|
|
|
switch (verbType) {
|
|
|
|
case kVerbNone:
|
|
|
|
return kVerbITENone;
|
|
|
|
case kVerbWalkTo:
|
|
|
|
return kVerbITEWalkTo;
|
|
|
|
case kVerbGive:
|
|
|
|
return kVerbITEGive;
|
|
|
|
case kVerbUse:
|
|
|
|
return kVerbITEUse;
|
|
|
|
case kVerbEnter:
|
|
|
|
return kVerbITEEnter;
|
|
|
|
case kVerbLookAt:
|
|
|
|
return kVerbITELookAt;
|
|
|
|
case kVerbPickUp:
|
|
|
|
return kVerbITEPickUp;
|
|
|
|
case kVerbOpen:
|
|
|
|
return kVerbITEOpen;
|
|
|
|
case kVerbClose:
|
|
|
|
return kVerbITEClose;
|
|
|
|
case kVerbTalkTo:
|
|
|
|
return kVerbITETalkTo;
|
|
|
|
case kVerbWalkOnly:
|
|
|
|
return kVerbITEWalkOnly;
|
|
|
|
case kVerbLookOnly:
|
|
|
|
return kVerbITELookOnly;
|
|
|
|
case kVerbOptions:
|
|
|
|
return kVerbITEOptions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-05-27 23:30:21 +00:00
|
|
|
// TODO: This is ugly and needs rewriting, but
|
|
|
|
// it works for now
|
2006-01-13 20:20:01 +00:00
|
|
|
switch (verbType) {
|
|
|
|
case kVerbNone:
|
|
|
|
return kVerbIHNMNone;
|
|
|
|
case kVerbWalkTo:
|
|
|
|
return kVerbIHNMWalk;
|
|
|
|
case kVerbLookAt:
|
|
|
|
return kVerbIHNMLookAt;
|
|
|
|
case kVerbPickUp:
|
|
|
|
return kVerbIHNMTake;
|
2007-05-27 11:49:08 +00:00
|
|
|
case kVerbUse:
|
|
|
|
return kVerbIHNMUse;
|
|
|
|
case kVerbTalkTo:
|
|
|
|
return kVerbIHNMTalkTo;
|
2006-01-13 20:20:01 +00:00
|
|
|
case kVerbOpen:
|
2007-05-27 23:30:21 +00:00
|
|
|
return kVerbIHNMSwallow;
|
2007-05-27 11:49:08 +00:00
|
|
|
case kVerbGive:
|
|
|
|
return kVerbIHNMGive;
|
2006-01-13 20:20:01 +00:00
|
|
|
case kVerbClose:
|
2007-05-27 23:30:21 +00:00
|
|
|
return kVerbIHNMPush;
|
2007-05-27 11:49:08 +00:00
|
|
|
case kVerbEnter:
|
|
|
|
return kVerbIHNMEnter;
|
2006-01-13 20:20:01 +00:00
|
|
|
case kVerbWalkOnly:
|
|
|
|
return kVerbIHNMWalkOnly;
|
|
|
|
case kVerbLookOnly:
|
|
|
|
return kVerbIHNMLookOnly;
|
|
|
|
case kVerbOptions:
|
|
|
|
return kVerbIHNMOptions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error("Script::getVerbType() unknown verb type %d", verbType);
|
|
|
|
}
|
|
|
|
|
2005-01-08 20:30:07 +00:00
|
|
|
void Script::setVerb(int verb) {
|
|
|
|
_pendingObject[0] = ID_NOTHING;
|
|
|
|
_currentObject[0] = ID_NOTHING;
|
|
|
|
_pendingObject[1] = ID_NOTHING;
|
|
|
|
_currentObject[1] = ID_NOTHING;
|
|
|
|
_firstObjectSet = false;
|
|
|
|
_secondObjectNeeded = false;
|
|
|
|
|
2005-06-10 13:56:51 +00:00
|
|
|
// The pointer object will be updated again immediately. This way the
|
|
|
|
// new verb will be applied to it. It's not exactly how the original
|
|
|
|
// engine did it, but it appears to work.
|
|
|
|
_pointerObject = ID_NOTHING;
|
|
|
|
|
2005-01-08 20:30:07 +00:00
|
|
|
setLeftButtonVerb( verb );
|
|
|
|
showVerb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Script::setLeftButtonVerb(int verb) {
|
2005-01-13 22:42:49 +00:00
|
|
|
int oldVerb = _currentVerb;
|
|
|
|
|
|
|
|
_currentVerb = _leftButtonVerb = verb;
|
|
|
|
|
|
|
|
if ((_currentVerb != oldVerb) && (_vm->_interface->getMode() == kPanelMain)){
|
2006-01-13 20:20:01 +00:00
|
|
|
if (oldVerb > getVerbType(kVerbNone))
|
2005-04-22 14:11:04 +00:00
|
|
|
_vm->_interface->setVerbState(oldVerb, 2);
|
2005-01-13 22:42:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_currentVerb > getVerbType(kVerbNone))
|
2005-04-22 14:11:04 +00:00
|
|
|
_vm->_interface->setVerbState(_currentVerb, 2);
|
2005-01-13 22:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Script::setRightButtonVerb(int verb) {
|
2005-01-18 15:01:21 +00:00
|
|
|
int oldVerb = _rightButtonVerb;
|
2005-01-13 22:42:49 +00:00
|
|
|
|
|
|
|
_rightButtonVerb = verb;
|
|
|
|
|
|
|
|
if ((_rightButtonVerb != oldVerb) && (_vm->_interface->getMode() == kPanelMain)){
|
2006-01-13 20:20:01 +00:00
|
|
|
if (oldVerb > getVerbType(kVerbNone))
|
2005-04-22 14:11:04 +00:00
|
|
|
_vm->_interface->setVerbState(oldVerb, 2);
|
2005-01-13 22:42:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_rightButtonVerb > getVerbType(kVerbNone))
|
2005-04-22 14:11:04 +00:00
|
|
|
_vm->_interface->setVerbState(_rightButtonVerb, 2);
|
2005-01-13 22:42:49 +00:00
|
|
|
}
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Script::doVerb() {
|
2005-01-15 20:12:49 +00:00
|
|
|
int scriptEntrypointNumber = 0;
|
|
|
|
int scriptModuleNumber = 0;
|
|
|
|
int objectType;
|
2005-08-10 14:11:22 +00:00
|
|
|
Event event;
|
2005-01-15 20:12:49 +00:00
|
|
|
const char *excuseText;
|
|
|
|
int excuseSampleResourceId;
|
2005-01-18 15:01:21 +00:00
|
|
|
const HitZone *hitZone;
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
objectType = objectTypeId(_pendingObject[0]);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb == getVerbType(kVerbGive)) {
|
2005-01-18 21:13:44 +00:00
|
|
|
scriptEntrypointNumber = _vm->_actor->getObjectScriptEntrypointNumber(_pendingObject[1]);
|
|
|
|
if (_vm->_actor->getObjectFlags(_pendingObject[1]) & (kFollower|kProtagonist|kExtended)) {
|
2005-01-15 20:12:49 +00:00
|
|
|
scriptModuleNumber = 0;
|
|
|
|
} else {
|
|
|
|
scriptModuleNumber = _vm->_scene->getScriptModuleNumber();
|
|
|
|
}
|
2007-06-08 14:45:25 +00:00
|
|
|
// IHNM never sets scriptModuleNumber to 0
|
|
|
|
if (_vm->getGameType() == GType_IHNM)
|
|
|
|
scriptModuleNumber = _vm->_scene->getScriptModuleNumber();
|
2005-01-15 20:12:49 +00:00
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb == getVerbType(kVerbUse)) {
|
2005-01-18 15:01:21 +00:00
|
|
|
if ((objectTypeId(_pendingObject[1]) > kGameObjectNone) && (objectType < objectTypeId(_pendingObject[1]))) {
|
2005-01-15 20:12:49 +00:00
|
|
|
SWAP(_pendingObject[0], _pendingObject[1]);
|
2005-01-18 15:01:21 +00:00
|
|
|
objectType = objectTypeId(_pendingObject[0]);
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:38:43 +00:00
|
|
|
if (objectType == 0)
|
2007-06-05 15:04:25 +00:00
|
|
|
return;
|
|
|
|
else if (objectType == kGameObjectHitZone) {
|
2005-01-15 20:12:49 +00:00
|
|
|
scriptModuleNumber = _vm->_scene->getScriptModuleNumber();
|
2005-01-18 15:01:21 +00:00
|
|
|
hitZone = _vm->_scene->_objectMap->getHitZone(objectIdToIndex(_pendingObject[0]));
|
2007-06-06 16:37:10 +00:00
|
|
|
|
|
|
|
if (hitZone == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
if ((hitZone->getFlags() & kHitZoneExit) == 0) {
|
|
|
|
scriptEntrypointNumber = hitZone->getScriptNumber();
|
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
} else {
|
|
|
|
if (objectType & (kGameObjectActor | kGameObjectObject)) {
|
2005-01-18 21:13:44 +00:00
|
|
|
scriptEntrypointNumber = _vm->_actor->getObjectScriptEntrypointNumber(_pendingObject[0]);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2005-01-18 21:13:44 +00:00
|
|
|
if ((objectType == kGameObjectActor) && !(_vm->_actor->getObjectFlags(_pendingObject[0]) & (kFollower|kProtagonist|kExtended))) {
|
2005-01-15 20:12:49 +00:00
|
|
|
scriptModuleNumber = _vm->_scene->getScriptModuleNumber();
|
|
|
|
} else {
|
|
|
|
scriptModuleNumber = 0;
|
|
|
|
}
|
2007-06-08 14:45:25 +00:00
|
|
|
// IHNM never sets scriptModuleNumber to 0
|
|
|
|
if (_vm->getGameType() == GType_IHNM)
|
|
|
|
scriptModuleNumber = _vm->_scene->getScriptModuleNumber();
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scriptEntrypointNumber > 0) {
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2007-06-05 15:04:25 +00:00
|
|
|
event.type = kEvTOneshot;
|
|
|
|
event.code = kScriptEvent;
|
|
|
|
event.op = kEventExecNonBlocking;
|
|
|
|
event.time = 0;
|
|
|
|
event.param = scriptModuleNumber;
|
|
|
|
event.param2 = scriptEntrypointNumber;
|
|
|
|
event.param3 = _pendingVerb; // Action
|
|
|
|
event.param4 = _pendingObject[0]; // Object
|
|
|
|
event.param5 = _pendingObject[1]; // With Object
|
|
|
|
event.param6 = (objectType == kGameObjectActor) ? _pendingObject[0] : ID_PROTAG; // Actor
|
|
|
|
|
|
|
|
_vm->_events->queue(&event);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
_vm->getExcuseInfo(_pendingVerb, excuseText, excuseSampleResourceId);
|
2005-08-11 15:28:08 +00:00
|
|
|
if (excuseText) {
|
|
|
|
// In Floppy versions we don't have excuse texts
|
|
|
|
if (!(_vm->getFeatures() & GF_CD_FX))
|
|
|
|
excuseSampleResourceId = -1;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
_vm->_actor->actorSpeech(ID_PROTAG, &excuseText, 1, excuseSampleResourceId, 0);
|
2005-08-11 15:28:08 +00:00
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbWalkTo)) || (_currentVerb == getVerbType(kVerbLookAt))) {
|
2005-01-15 20:12:49 +00:00
|
|
|
_stickyVerb = _currentVerb;
|
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
_pendingVerb = getVerbType(kVerbNone);
|
2005-01-15 20:12:49 +00:00
|
|
|
_currentObject[0] = _currentObject[1] = ID_NOTHING;
|
|
|
|
setLeftButtonVerb(_stickyVerb);
|
|
|
|
|
|
|
|
setPointerVerb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Script::setPointerVerb() {
|
|
|
|
if (_vm->_interface->isActive()) {
|
|
|
|
_pointerObject = ID_PROTAG;
|
2005-04-18 20:03:14 +00:00
|
|
|
whichObject(_vm->mousePos());
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 23:46:43 +00:00
|
|
|
void Script::hitObject(bool leftButton) {
|
|
|
|
int verb;
|
|
|
|
verb = leftButton ? _leftButtonVerb : _rightButtonVerb;
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (verb > getVerbType(kVerbNone)) {
|
2005-01-15 23:46:43 +00:00
|
|
|
if (_firstObjectSet) {
|
|
|
|
if (_secondObjectNeeded) {
|
|
|
|
_pendingObject[0] = _currentObject[0];
|
|
|
|
_pendingObject[1] = _currentObject[1];
|
|
|
|
_pendingVerb = verb;
|
|
|
|
|
|
|
|
_leftButtonVerb = verb;
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb > getVerbType(kVerbNone))
|
2005-01-19 11:29:29 +00:00
|
|
|
showVerb(kITEColorBrightWhite);
|
|
|
|
else
|
|
|
|
showVerb();
|
2005-01-15 23:46:43 +00:00
|
|
|
|
|
|
|
_secondObjectNeeded = false;
|
|
|
|
_firstObjectSet = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if (verb == getVerbType(kVerbGive)) {
|
2005-01-15 23:46:43 +00:00
|
|
|
_secondObjectNeeded = true;
|
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if (verb == getVerbType(kVerbUse)) {
|
2005-01-15 23:46:43 +00:00
|
|
|
|
|
|
|
if (_currentObjectFlags[0] & kObjUseWith) {
|
|
|
|
_secondObjectNeeded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_secondObjectNeeded) {
|
|
|
|
_pendingObject[0] = _currentObject[0];
|
|
|
|
_pendingObject[1] = ID_NOTHING;
|
|
|
|
_pendingVerb = verb;
|
|
|
|
|
|
|
|
_secondObjectNeeded = false;
|
|
|
|
_firstObjectSet = false;
|
|
|
|
} else {
|
|
|
|
_firstObjectSet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_leftButtonVerb = verb;
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb > getVerbType(kVerbNone))
|
2005-01-19 11:29:29 +00:00
|
|
|
showVerb(kITEColorBrightWhite);
|
|
|
|
else
|
|
|
|
showVerb();
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Script::playfieldClick(const Point& mousePoint, bool leftButton) {
|
|
|
|
Location pickLocation;
|
|
|
|
const HitZone *hitZone;
|
2005-01-18 15:01:21 +00:00
|
|
|
Point specialPoint;
|
2005-01-15 23:46:43 +00:00
|
|
|
|
2007-06-06 19:46:10 +00:00
|
|
|
_vm->incrementMouseClickCount();
|
2005-01-15 23:46:43 +00:00
|
|
|
_vm->_actor->abortSpeech();
|
|
|
|
|
2005-08-10 14:53:17 +00:00
|
|
|
if ((_vm->_actor->_protagonist->_currentAction != kActionWait) &&
|
|
|
|
(_vm->_actor->_protagonist->_currentAction != kActionFreeze) &&
|
|
|
|
(_vm->_actor->_protagonist->_currentAction != kActionWalkToLink) &&
|
|
|
|
(_vm->_actor->_protagonist->_currentAction != kActionWalkToPoint)) {
|
2005-01-15 23:46:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb > getVerbType(kVerbNone)) {
|
|
|
|
setLeftButtonVerb(getVerbType(kVerbWalkTo));
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_pointerObject != ID_NOTHING) {
|
|
|
|
hitObject( leftButton );
|
|
|
|
} else {
|
|
|
|
_pendingObject[0] = ID_NOTHING;
|
|
|
|
_pendingObject[1] = ID_NOTHING;
|
2006-01-13 20:20:01 +00:00
|
|
|
_pendingVerb = getVerbType(kVerbWalkTo);
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// tiled stuff
|
|
|
|
if (_vm->_scene->getFlags() & kSceneFlagISO) {
|
2005-02-26 17:37:16 +00:00
|
|
|
_vm->_isoMap->screenPointToTileCoords(mousePoint, pickLocation);
|
2005-01-15 23:46:43 +00:00
|
|
|
} else {
|
|
|
|
pickLocation.fromScreenPoint(mousePoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hitZone = NULL;
|
|
|
|
|
2007-06-06 00:51:07 +00:00
|
|
|
if (objectTypeId(_pendingObject[0]) == kGameObjectHitZone) {
|
2005-01-18 15:01:21 +00:00
|
|
|
hitZone = _vm->_scene->_objectMap->getHitZone(objectIdToIndex(_pendingObject[0]));
|
2005-01-15 23:46:43 +00:00
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_pendingVerb == getVerbType(kVerbUse)) && (objectTypeId(_pendingObject[1]) == kGameObjectHitZone)) {
|
2005-07-29 17:58:00 +00:00
|
|
|
hitZone = _vm->_scene->_objectMap->getHitZone(objectIdToIndex(_pendingObject[1]));
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hitZone != NULL) {
|
|
|
|
if (hitZone->getFlags() & kHitZoneNoWalk) {
|
2005-07-29 17:58:00 +00:00
|
|
|
_vm->_actor->actorFaceTowardsPoint(ID_PROTAG, pickLocation);
|
2005-01-15 23:46:43 +00:00
|
|
|
doVerb();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hitZone->getFlags() & kHitZoneProject) {
|
2005-01-18 15:01:21 +00:00
|
|
|
if (!hitZone->getSpecialPoint(specialPoint)) {
|
2005-08-12 19:43:39 +00:00
|
|
|
// Original behaved this way and this prevents from crash
|
|
|
|
// at ruins. See bug #1257459
|
|
|
|
specialPoint.x = specialPoint.y = 0;
|
2005-01-18 15:01:21 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
// tiled stuff
|
|
|
|
if (_vm->_scene->getFlags() & kSceneFlagISO) {
|
2005-02-26 17:37:16 +00:00
|
|
|
pickLocation.u() = specialPoint.x;
|
|
|
|
pickLocation.v() = specialPoint.y;
|
2005-08-10 14:53:17 +00:00
|
|
|
pickLocation.z = _vm->_actor->_protagonist->_location.z;
|
2005-01-18 15:01:21 +00:00
|
|
|
} else {
|
|
|
|
pickLocation.fromScreenPoint(specialPoint);
|
|
|
|
}
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_pendingVerb == getVerbType(kVerbWalkTo)) ||
|
|
|
|
(_pendingVerb == getVerbType(kVerbPickUp)) ||
|
|
|
|
(_pendingVerb == getVerbType(kVerbOpen)) ||
|
|
|
|
(_pendingVerb == getVerbType(kVerbClose)) ||
|
|
|
|
(_pendingVerb == getVerbType(kVerbUse))) {
|
2005-01-15 23:46:43 +00:00
|
|
|
_vm->_actor->actorWalkTo(ID_PROTAG, pickLocation);
|
2006-01-13 20:20:01 +00:00
|
|
|
} else {
|
|
|
|
if (_pendingVerb == getVerbType(kVerbLookAt)) {
|
|
|
|
if (objectTypeId(_pendingObject[0]) != kGameObjectActor ) {
|
|
|
|
_vm->_actor->actorWalkTo(ID_PROTAG, pickLocation);
|
|
|
|
} else {
|
|
|
|
doVerb();
|
|
|
|
}
|
2005-03-09 07:29:15 +00:00
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_pendingVerb == getVerbType(kVerbTalkTo)) ||
|
|
|
|
(_pendingVerb == getVerbType(kVerbGive))) {
|
|
|
|
doVerb();
|
|
|
|
}
|
2005-03-09 07:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-15 23:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Script::whichObject(const Point& mousePoint) {
|
2005-01-15 20:12:49 +00:00
|
|
|
uint16 objectId;
|
|
|
|
int16 objectFlags;
|
|
|
|
int newRightButtonVerb;
|
|
|
|
uint16 newObjectId;
|
|
|
|
ActorData *actor;
|
2005-04-22 14:11:04 +00:00
|
|
|
ObjectData *obj;
|
2005-03-18 17:11:37 +00:00
|
|
|
Point pickPoint;
|
2005-01-15 20:12:49 +00:00
|
|
|
Location pickLocation;
|
2005-01-18 15:01:21 +00:00
|
|
|
int hitZoneIndex;
|
|
|
|
const HitZone * hitZone;
|
2005-04-22 14:11:04 +00:00
|
|
|
PanelButton * panelButton;
|
2005-01-15 20:12:49 +00:00
|
|
|
|
|
|
|
objectId = ID_NOTHING;
|
|
|
|
objectFlags = 0;
|
|
|
|
_leftButtonVerb = _currentVerb;
|
2006-01-13 20:20:01 +00:00
|
|
|
newRightButtonVerb = getVerbType(kVerbNone);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2005-08-10 14:53:17 +00:00
|
|
|
if (_vm->_actor->_protagonist->_currentAction != kActionWalkDir) {
|
2005-10-08 15:20:11 +00:00
|
|
|
if (_vm->_scene->getHeight() >= mousePoint.y) {
|
2005-04-22 14:11:04 +00:00
|
|
|
newObjectId = _vm->_actor->hitTest(mousePoint, true);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2005-04-22 14:11:04 +00:00
|
|
|
if (newObjectId != ID_NOTHING) {
|
|
|
|
if (objectTypeId(newObjectId) == kGameObjectObject) {
|
|
|
|
objectId = newObjectId;
|
|
|
|
objectFlags = 0;
|
2006-01-13 20:20:01 +00:00
|
|
|
newRightButtonVerb = getVerbType(kVerbLookAt);
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbTalkTo)) || ((_currentVerb == getVerbType(kVerbGive)) && _firstObjectSet)) {
|
2005-04-22 14:11:04 +00:00
|
|
|
objectId = ID_NOTHING;
|
|
|
|
newObjectId = ID_NOTHING;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actor = _vm->_actor->getActor(newObjectId);
|
|
|
|
objectId = newObjectId;
|
|
|
|
objectFlags = kObjUseWith;
|
2006-01-13 20:20:01 +00:00
|
|
|
newRightButtonVerb = getVerbType(kVerbTalkTo);
|
2005-04-22 14:11:04 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbPickUp)) ||
|
|
|
|
(_currentVerb == getVerbType(kVerbOpen)) ||
|
|
|
|
(_currentVerb == getVerbType(kVerbClose)) ||
|
|
|
|
((_currentVerb == getVerbType(kVerbGive)) && !_firstObjectSet) ||
|
|
|
|
((_currentVerb == getVerbType(kVerbUse)) && !(actor->_flags & kFollower))) {
|
2007-06-05 16:31:58 +00:00
|
|
|
if (_vm->getGameType() == GType_ITE) {
|
|
|
|
objectId = ID_NOTHING;
|
|
|
|
newObjectId = ID_NOTHING;
|
|
|
|
}
|
2005-04-22 14:11:04 +00:00
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
if (newObjectId == ID_NOTHING) {
|
2005-03-18 17:11:37 +00:00
|
|
|
|
2005-04-22 14:11:04 +00:00
|
|
|
pickPoint = mousePoint;
|
2005-03-18 17:11:37 +00:00
|
|
|
|
2005-04-22 14:11:04 +00:00
|
|
|
if (_vm->_scene->getFlags() & kSceneFlagISO) {
|
2005-08-10 14:53:17 +00:00
|
|
|
pickPoint.y -= _vm->_actor->_protagonist->_location.z;
|
2005-04-22 14:11:04 +00:00
|
|
|
_vm->_isoMap->screenPointToTileCoords(pickPoint, pickLocation);
|
|
|
|
pickLocation.toScreenPointUV(pickPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
hitZoneIndex = _vm->_scene->_objectMap->hitTest(pickPoint);
|
|
|
|
|
|
|
|
if ((hitZoneIndex != -1)) {
|
|
|
|
hitZone = _vm->_scene->_objectMap->getHitZone(hitZoneIndex);
|
|
|
|
objectId = hitZone->getHitZoneId();
|
|
|
|
objectFlags = 0;
|
|
|
|
newRightButtonVerb = hitZone->getRightButtonVerb() & 0x7f;
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_vm->getGameType() == GType_ITE) {
|
|
|
|
|
|
|
|
if (newRightButtonVerb == getVerbType(kVerbWalkOnly)) {
|
2005-04-22 14:11:04 +00:00
|
|
|
if (_firstObjectSet) {
|
|
|
|
objectId = ID_NOTHING;
|
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
newRightButtonVerb = _leftButtonVerb = getVerbType(kVerbWalkTo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (newRightButtonVerb == getVerbType(kVerbLookOnly)) {
|
|
|
|
if (_firstObjectSet) {
|
|
|
|
objectId = ID_NOTHING;
|
|
|
|
} else {
|
|
|
|
newRightButtonVerb = _leftButtonVerb = getVerbType(kVerbLookAt);
|
|
|
|
}
|
2005-04-22 14:11:04 +00:00
|
|
|
}
|
2005-04-03 15:32:04 +00:00
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if (newRightButtonVerb >= getVerbType(kVerbOptions)) {
|
|
|
|
newRightButtonVerb = getVerbType(kVerbNone);
|
|
|
|
}
|
2005-04-22 14:11:04 +00:00
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbTalkTo)) || ((_currentVerb == getVerbType(kVerbGive)) && _firstObjectSet)) {
|
2005-04-22 14:11:04 +00:00
|
|
|
objectId = ID_NOTHING;
|
|
|
|
newObjectId = ID_NOTHING;
|
|
|
|
}
|
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_leftButtonVerb == getVerbType(kVerbUse)) && (hitZone->getRightButtonVerb() & 0x80)) {
|
2005-04-22 14:11:04 +00:00
|
|
|
objectFlags = kObjUseWith;
|
2005-07-29 17:58:00 +00:00
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
2005-04-22 14:11:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbTalkTo)) || ((_currentVerb == getVerbType(kVerbGive)) && _firstObjectSet)) {
|
2005-04-22 14:11:04 +00:00
|
|
|
// no way
|
|
|
|
} else {
|
|
|
|
panelButton = _vm->_interface->inventoryHitTest(mousePoint);
|
|
|
|
if (panelButton) {
|
2005-07-29 17:58:00 +00:00
|
|
|
objectId = _vm->_interface->getInventoryContentByPanelButton(panelButton);
|
2005-04-22 14:11:04 +00:00
|
|
|
if (objectId != 0) {
|
|
|
|
obj = _vm->_actor->getObj(objectId);
|
2006-01-13 20:20:01 +00:00
|
|
|
newRightButtonVerb = getVerbType(kVerbLookAt);
|
2005-08-10 14:53:17 +00:00
|
|
|
if (obj->_interactBits & kObjUseWith) {
|
2005-04-22 14:11:04 +00:00
|
|
|
objectFlags = kObjUseWith;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-15 20:12:49 +00:00
|
|
|
|
2006-01-13 20:20:01 +00:00
|
|
|
if ((_currentVerb == getVerbType(kVerbPickUp)) || (_currentVerb == getVerbType(kVerbTalkTo)) || (_currentVerb == getVerbType(kVerbWalkTo))) {
|
|
|
|
_leftButtonVerb = getVerbType(kVerbLookAt);
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectId != _pointerObject) {
|
|
|
|
_pointerObject = objectId;
|
|
|
|
_currentObject[_firstObjectSet ? 1 : 0] = objectId;
|
|
|
|
_currentObjectFlags[_firstObjectSet ? 1 : 0] = objectFlags;
|
2006-01-13 20:20:01 +00:00
|
|
|
if (_pendingVerb == getVerbType(kVerbNone)) {
|
2005-01-15 20:12:49 +00:00
|
|
|
showVerb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newRightButtonVerb != _rightButtonVerb) {
|
|
|
|
setRightButtonVerb(newRightButtonVerb);
|
|
|
|
}
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
} // End of namespace Saga
|