2003-10-31 13:46:45 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2003-2004 The ScummVM project
|
2003-10-31 13:46:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "queen/command.h"
|
2003-12-11 22:16:35 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
#include "queen/display.h"
|
|
|
|
#include "queen/input.h"
|
|
|
|
#include "queen/graphics.h"
|
2004-01-08 14:10:32 +00:00
|
|
|
#include "queen/grid.h"
|
2003-10-31 13:46:45 +00:00
|
|
|
#include "queen/logic.h"
|
2003-12-11 22:16:35 +00:00
|
|
|
#include "queen/queen.h"
|
2003-11-15 21:33:04 +00:00
|
|
|
#include "queen/sound.h"
|
2003-12-11 10:03:35 +00:00
|
|
|
#include "queen/state.h"
|
2003-11-06 08:44:33 +00:00
|
|
|
#include "queen/talk.h"
|
2003-10-31 13:46:45 +00:00
|
|
|
#include "queen/walk.h"
|
|
|
|
|
|
|
|
namespace Queen {
|
|
|
|
|
|
|
|
|
|
|
|
void CmdText::clear() {
|
|
|
|
memset(_command, 0, sizeof(_command));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CmdText::display(uint8 color) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textCurrentColor(color);
|
|
|
|
_vm->graphics()->textSetCentered(COMMAND_Y_POS, _command, false);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
void CmdText::displayTemp(uint8 color, bool locked, Verb v, const char *name) {
|
2003-10-31 13:46:45 +00:00
|
|
|
char temp[MAX_COMMAND_LEN];
|
|
|
|
if (locked) {
|
2003-12-12 10:33:34 +00:00
|
|
|
sprintf(temp, "%s%s", _vm->logic()->joeResponse(39), _vm->logic()->verbName(v));
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-12 10:33:34 +00:00
|
|
|
strcpy(temp, _vm->logic()->verbName(v));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
if (name != NULL) {
|
|
|
|
strcat(temp, " ");
|
|
|
|
strcat(temp, name);
|
|
|
|
}
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textCurrentColor(color);
|
|
|
|
_vm->graphics()->textSetCentered(COMMAND_Y_POS, temp, false);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CmdText::displayTemp(uint8 color, const char *name) {
|
|
|
|
char temp[MAX_COMMAND_LEN];
|
|
|
|
sprintf(temp, "%s %s", _command, name);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textCurrentColor(color);
|
|
|
|
_vm->graphics()->textSetCentered(COMMAND_Y_POS, temp, false);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
void CmdText::setVerb(Verb v) {
|
|
|
|
strcpy(_command, _vm->logic()->verbName(v));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
void CmdText::addLinkWord(Verb v) {
|
2003-10-31 13:46:45 +00:00
|
|
|
strcat(_command, " ");
|
2003-12-12 10:33:34 +00:00
|
|
|
strcat(_command, _vm->logic()->verbName(v));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CmdText::addObject(const char *objName) {
|
|
|
|
strcat(_command, " ");
|
|
|
|
strcat(_command, objName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CmdText::isEmpty() const {
|
|
|
|
return _command[0] == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
void CmdState::init() {
|
2003-11-03 19:52:14 +00:00
|
|
|
commandLevel = 1;
|
2003-12-12 10:33:34 +00:00
|
|
|
oldVerb = verb = action = VERB_NONE;
|
2003-12-13 20:05:28 +00:00
|
|
|
oldNoun = noun = subject[0] = subject[1] = 0;
|
2003-11-03 19:52:14 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
selAction = defaultVerb = VERB_NONE;
|
|
|
|
selNoun = 0;
|
2003-11-03 19:52:14 +00:00
|
|
|
}
|
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
Command::Command(QueenEngine *vm)
|
|
|
|
: _vm(vm) {
|
2003-12-29 20:18:31 +00:00
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
_cmdText._vm = vm;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::clear(bool clearTexts) {
|
|
|
|
_cmdText.clear();
|
|
|
|
if (clearTexts) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
_parse = false;
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.init();
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
void Command::executeCurrentAction() {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->entryObj(0);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
// if (_state.commandLevel == 2 && _mouseKey == Input::MOUSE_RBUTTON) {
|
|
|
|
// _mouseKey = Input::MOUSE_LBUTTON;
|
|
|
|
// }
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_mouseKey == Input::MOUSE_RBUTTON && _state.subject[0] > 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
ObjectData *od = _vm->logic()->objectData(_state.subject[0]);
|
|
|
|
if (od == NULL || od->name <= 0) {
|
|
|
|
cleanupCurrentAction();
|
|
|
|
return;
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = State::findDefaultVerb(od->state);
|
2003-12-15 12:59:43 +00:00
|
|
|
_state.selAction = (_state.verb == VERB_NONE) ? VERB_WALK_TO : _state.verb;
|
|
|
|
_cmdText.setVerb(_state.selAction);
|
|
|
|
_cmdText.addObject(_vm->logic()->objectName(od->name));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that command is always highlighted when actioned!
|
|
|
|
_cmdText.display(INK_CMD_SELECT);
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.selNoun = _state.noun;
|
|
|
|
_state.commandLevel = 1;
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (handleWrongAction()) {
|
2003-10-31 13:46:45 +00:00
|
|
|
cleanupCurrentAction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-04 13:51:36 +00:00
|
|
|
// get the commands associated with object/item
|
|
|
|
uint16 comMax = 0;
|
|
|
|
uint16 matchingCmds[MAX_MATCHING_CMDS];
|
|
|
|
CmdListData *cmdList = &_cmdList[1];
|
2003-12-02 16:49:56 +00:00
|
|
|
uint16 i;
|
2003-11-04 13:51:36 +00:00
|
|
|
for (i = 1; i <= _numCmdList; ++i, ++cmdList) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if (cmdList->match(_state.selAction, _state.subject[0], _state.subject[1])) {
|
2003-11-04 13:51:36 +00:00
|
|
|
matchingCmds[comMax] = i;
|
|
|
|
++comMax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::executeCurrentAction() - comMax=%d subj1=%X subj2=%X", comMax, _state.subject[0], _state.subject[1]);
|
2003-12-13 20:05:28 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
if (comMax == 0) {
|
2003-12-13 20:05:28 +00:00
|
|
|
sayInvalidAction(_state.selAction, _state.subject[0], _state.subject[1]);
|
2003-10-31 13:46:45 +00:00
|
|
|
cleanupCurrentAction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-08 23:45:45 +00:00
|
|
|
// process each associated command for the Object, until all done
|
|
|
|
// or one of the Gamestate tests fails...
|
2003-10-31 13:46:45 +00:00
|
|
|
int16 cond = 0;
|
2003-11-03 20:48:27 +00:00
|
|
|
CmdListData *com = &_cmdList[0];
|
2003-10-31 13:46:45 +00:00
|
|
|
uint16 comId = 0;
|
2003-11-04 13:51:36 +00:00
|
|
|
for (i = 1; i <= comMax; ++i) {
|
|
|
|
|
|
|
|
comId = matchingCmds[i - 1];
|
|
|
|
com = &_cmdList[comId];
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// check the Gamestates and set them if necessary
|
|
|
|
cond = 0;
|
|
|
|
if (com->setConditions) {
|
2003-11-04 13:51:36 +00:00
|
|
|
cond = setConditions(comId, (i == comMax));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 13:51:36 +00:00
|
|
|
if (cond == -1 && i == comMax) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// only exit on a condition fail if at last command
|
|
|
|
// Joe hasnt spoken, so do normal LOOK command
|
2003-12-02 16:49:56 +00:00
|
|
|
break;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (cond == -2 && i == comMax) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// only exit on a condition fail if at last command
|
|
|
|
// Joe has spoken, so skip LOOK command
|
|
|
|
cleanupCurrentAction();
|
|
|
|
return;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (cond >= 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// we've had a successful Gamestate check, so we must now exit
|
2003-12-02 19:58:31 +00:00
|
|
|
cond = executeCommand(comId, cond);
|
2003-10-31 13:46:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (cond <= 0 && _state.selAction == VERB_LOOK_AT) {
|
|
|
|
lookAtSelectedObject();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-02 16:49:56 +00:00
|
|
|
// only play song if it's a PLAY AFTER type
|
|
|
|
if (com->song < 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->sound()->playSong(-com->song);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-02 16:49:56 +00:00
|
|
|
clear(true);
|
2003-11-08 23:45:45 +00:00
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
cleanupCurrentAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
void Command::updatePlayer() {
|
|
|
|
if (_vm->logic()->joeWalk() != JWM_MOVE) {
|
2003-12-28 21:18:03 +00:00
|
|
|
int16 cx = _vm->input()->mousePosX();
|
|
|
|
int16 cy = _vm->input()->mousePosY();
|
|
|
|
lookForCurrentObject(cx, cy);
|
|
|
|
lookForCurrentIcon(cx, cy);
|
2003-12-13 20:05:28 +00:00
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
if (_vm->input()->keyVerb() != VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
if (_vm->input()->keyVerb() == VERB_USE_JOURNAL) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->input()->clearKeyVerb();
|
|
|
|
_vm->logic()->useJournal();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_vm->input()->keyVerb() != VERB_SKIP_TEXT) {
|
2003-12-14 21:39:52 +00:00
|
|
|
_state.verb = _vm->input()->keyVerb();
|
|
|
|
if (isVerbInv(_state.verb)) {
|
|
|
|
_state.noun = _state.selNoun = 0;
|
|
|
|
// Clear old noun and old verb in case we're pointing at an
|
|
|
|
// object (noun) or item (verb) and we want to use an item
|
|
|
|
// on it. This was the command will be redisplayed with the
|
|
|
|
// object/item that the cursor is currently on.
|
|
|
|
_state.oldNoun = 0;
|
|
|
|
_state.oldVerb = VERB_NONE;
|
|
|
|
grabSelectedItem();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-14 21:39:52 +00:00
|
|
|
grabSelectedVerb();
|
|
|
|
}
|
|
|
|
_vm->input()->clearKeyVerb();
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
_mouseKey = _vm->input()->mouseButton();
|
|
|
|
_vm->input()->clearMouseButton();
|
2003-10-31 13:46:45 +00:00
|
|
|
if (_mouseKey > 0) {
|
|
|
|
grabCurrentSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::readCommandsFrom(byte *&ptr) {
|
|
|
|
uint16 i;
|
|
|
|
|
|
|
|
_numCmdList = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_cmdList = new CmdListData[_numCmdList + 1];
|
|
|
|
memset(&_cmdList[0], 0, sizeof(CmdListData));
|
|
|
|
for (i = 1; i <= _numCmdList; i++) {
|
2003-12-28 01:17:29 +00:00
|
|
|
_cmdList[i].readFromBE(ptr);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_numCmdArea = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_cmdArea = new CmdArea[_numCmdArea + 1];
|
2003-12-30 21:06:22 +00:00
|
|
|
if (_numCmdArea == 0) {
|
|
|
|
_cmdArea[0].readFromBE(ptr);
|
|
|
|
} else {
|
|
|
|
memset(&_cmdArea[0], 0, sizeof(CmdArea));
|
|
|
|
for (i = 1; i <= _numCmdArea; i++) {
|
|
|
|
_cmdArea[i].readFromBE(ptr);
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
_numCmdObject = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_cmdObject = new CmdObject[_numCmdObject + 1];
|
2003-12-30 21:06:22 +00:00
|
|
|
if (_numCmdObject == 0) {
|
|
|
|
_cmdObject[0].readFromBE(ptr);
|
|
|
|
} else {
|
|
|
|
memset(&_cmdObject[0], 0, sizeof(CmdObject));
|
|
|
|
for (i = 1; i <= _numCmdObject; i++) {
|
|
|
|
_cmdObject[i].readFromBE(ptr);
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_numCmdInventory = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_cmdInventory = new CmdInventory[_numCmdInventory + 1];
|
2003-12-30 21:06:22 +00:00
|
|
|
if (_numCmdInventory == 0) {
|
|
|
|
_cmdInventory[0].readFromBE(ptr);
|
|
|
|
} else {
|
|
|
|
memset(&_cmdInventory[0], 0, sizeof(CmdInventory));
|
|
|
|
for (i = 1; i <= _numCmdInventory; i++) {
|
|
|
|
_cmdInventory[i].readFromBE(ptr);
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
_numCmdGameState = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_cmdGameState = new CmdGameState[_numCmdGameState + 1];
|
2003-12-30 21:06:22 +00:00
|
|
|
if (_numCmdGameState == 0) {
|
|
|
|
_cmdGameState[0].readFromBE(ptr);
|
|
|
|
} else {
|
|
|
|
memset(&_cmdGameState[0], 0, sizeof(CmdGameState));
|
|
|
|
for (i = 1; i <= _numCmdGameState; i++) {
|
|
|
|
_cmdGameState[i].readFromBE(ptr);
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
ObjectData *Command::findObjectData(uint16 objRoomNum) const {
|
|
|
|
ObjectData *od = NULL;
|
|
|
|
if (objRoomNum != 0) {
|
|
|
|
objRoomNum += _vm->logic()->currentRoomData();
|
|
|
|
od = _vm->logic()->objectData(objRoomNum);
|
|
|
|
}
|
|
|
|
return od;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ItemData *Command::findItemData(Verb invNum) const {
|
|
|
|
ItemData *id = NULL;
|
|
|
|
uint16 itNum = _vm->logic()->findInventoryItem(invNum - VERB_INV_FIRST);
|
|
|
|
if (itNum != 0) {
|
|
|
|
id = _vm->logic()->itemData(itNum);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-02 19:58:31 +00:00
|
|
|
int16 Command::executeCommand(uint16 comId, int16 condResult) {
|
2003-12-02 16:49:56 +00:00
|
|
|
// execute.c l.313-452
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::executeCommand() - cond = %X, com = %X", condResult, comId);
|
2003-12-02 16:49:56 +00:00
|
|
|
|
|
|
|
CmdListData *com = &_cmdList[comId];
|
|
|
|
|
|
|
|
if (com->setAreas) {
|
|
|
|
setAreas(comId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't grab if action is TALK or WALK
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.selAction != VERB_TALK_TO && _state.selAction != VERB_WALK_TO) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
int16 obj = _state.subject[i];
|
|
|
|
if (obj > 0) {
|
|
|
|
_vm->logic()->joeGrab(State::findGrab(_vm->logic()->objectData(obj)->state));
|
|
|
|
}
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cutDone = false;
|
|
|
|
if (condResult > 0) {
|
|
|
|
// as we don't handle the pinnacle room exactly like the original,
|
|
|
|
// the hack described on l.334-339 in execute.c became useless
|
|
|
|
|
|
|
|
// check for cutaway/dialogs before updating Objects
|
2003-12-11 22:16:35 +00:00
|
|
|
const char *desc = _vm->logic()->objectTextualDescription(condResult);
|
2003-12-02 16:49:56 +00:00
|
|
|
if (executeIfCutaway(desc)) {
|
|
|
|
condResult = 0;
|
|
|
|
cutDone = true;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (executeIfDialog(desc)) {
|
2003-12-02 16:49:56 +00:00
|
|
|
condResult = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 oldImage = 0;
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.subject[0] > 0) {
|
2003-12-02 16:49:56 +00:00
|
|
|
// an object (not an item)
|
2003-12-13 20:05:28 +00:00
|
|
|
oldImage = _vm->logic()->objectData(_state.subject[0])->image;
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (com->setObjects) {
|
|
|
|
setObjects(comId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (com->setItems) {
|
|
|
|
setItems(comId);
|
|
|
|
}
|
|
|
|
|
2003-12-14 14:47:00 +00:00
|
|
|
if (com->imageOrder != 0 && _state.subject[0] > 0) {
|
2003-12-13 20:05:28 +00:00
|
|
|
ObjectData *od = _vm->logic()->objectData(_state.subject[0]);
|
2003-12-02 16:49:56 +00:00
|
|
|
// we must update the graphic image of the object
|
|
|
|
if (com->imageOrder < 0) {
|
|
|
|
// instead of setting to -1 or -2, flag as negative
|
|
|
|
if (od->image > 0) {
|
|
|
|
// make sure that object is not already updated
|
|
|
|
od->image = -(od->image + 10);
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-02 16:49:56 +00:00
|
|
|
od->image = com->imageOrder;
|
|
|
|
}
|
2004-01-08 22:46:42 +00:00
|
|
|
_vm->graphics()->refreshObject(_state.subject[0]);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-02 16:49:56 +00:00
|
|
|
// this object is not being updated by command list, see if
|
|
|
|
// it has another image copied to it
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.subject[0] > 0) {
|
2003-12-02 16:49:56 +00:00
|
|
|
// an object (not an item)
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_vm->logic()->objectData(_state.subject[0])->image != oldImage) {
|
2004-01-08 22:46:42 +00:00
|
|
|
_vm->graphics()->refreshObject(_state.subject[0]);
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't play music on an OPEN/CLOSE command - in case the command fails
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.selAction != VERB_OPEN && _state.selAction != VERB_CLOSE) {
|
2003-12-02 16:49:56 +00:00
|
|
|
// only play song if it's a PLAY BEFORE type
|
|
|
|
if (com->song > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->sound()->playSong(com->song);
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do a special hardcoded section
|
|
|
|
// l.419-452 execute.c
|
|
|
|
switch (com->specialSection) {
|
|
|
|
case 1:
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->useJournal();
|
2003-12-02 19:58:31 +00:00
|
|
|
return condResult;
|
2003-12-02 16:49:56 +00:00
|
|
|
case 2:
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeUseDress(true);
|
2003-12-02 16:49:56 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeUseClothes(true);
|
2003-12-02 16:49:56 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeUseUnderwear();
|
2003-12-02 16:49:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-29 20:18:31 +00:00
|
|
|
if (_state.subject[0] > 0)
|
2003-12-14 20:24:29 +00:00
|
|
|
changeObjectState(_state.selAction, _state.subject[0], com->song, cutDone);
|
2003-12-02 16:49:56 +00:00
|
|
|
|
|
|
|
// execute.c l.533-548
|
|
|
|
// FIXME: useless test, as .dog has already been played
|
2003-12-13 20:05:28 +00:00
|
|
|
// if (_state.selAction == VERB_TALK_TO && cond > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
// if (executeIfDialog(_vm->logic()->objectTextualDescription(cond))) {
|
2003-12-02 16:49:56 +00:00
|
|
|
// cleanupCurrentAction();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// execute.c l.550-589
|
|
|
|
// FIXME: the EXECUTE_EXIT1 stuff can be omitted as it is
|
|
|
|
// more or less redundant code
|
|
|
|
if (condResult > 0) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(condResult, true);
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
2003-12-02 19:58:31 +00:00
|
|
|
return condResult;
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
int16 Command::makeJoeWalkTo(int16 x, int16 y, int16 objNum, Verb v, bool mustWalk) {
|
2003-11-03 19:52:14 +00:00
|
|
|
// Check to see if object is actually an exit to another
|
|
|
|
// room. If so, then set up new room
|
2003-12-11 22:16:35 +00:00
|
|
|
ObjectData *objData = _vm->logic()->objectData(objNum);
|
2003-11-03 19:52:14 +00:00
|
|
|
if (objData->x != 0 || objData->y != 0) {
|
|
|
|
x = objData->x;
|
|
|
|
y = objData->y;
|
|
|
|
}
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
if (v == VERB_WALK_TO) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->entryObj(objData->entryObj);
|
2003-12-13 20:05:28 +00:00
|
|
|
if (objData->entryObj != 0) {
|
|
|
|
_vm->logic()->newRoom(_vm->logic()->objectData(objData->entryObj)->room);
|
2003-11-03 19:52:14 +00:00
|
|
|
// because this is an exit object, see if there is
|
|
|
|
// a walk off point and set (x,y) accordingly
|
2003-12-11 22:16:35 +00:00
|
|
|
WalkOffData *wod = _vm->logic()->walkOffPointForObject(objNum);
|
2003-11-03 19:52:14 +00:00
|
|
|
if (wod != NULL) {
|
|
|
|
x = wod->x;
|
|
|
|
y = wod->y;
|
|
|
|
}
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->entryObj(0);
|
|
|
|
_vm->logic()->newRoom(0);
|
2003-11-03 19:52:14 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::makeJoeWalkTo() - x=%d y=%d newRoom=%d", x, y, _vm->logic()->newRoom());
|
2003-11-03 19:52:14 +00:00
|
|
|
|
|
|
|
int16 p = 0;
|
|
|
|
if (mustWalk) {
|
|
|
|
// determine which way for Joe to face Object
|
|
|
|
uint16 facing = State::findDirection(objData->state);
|
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
BobSlot *bobJoe = _vm->graphics()->bob(0);
|
2003-11-03 19:52:14 +00:00
|
|
|
if (x == bobJoe->x && y == bobJoe->y) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeFacing(facing);
|
|
|
|
_vm->logic()->joeFace();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
p = _vm->walk()->moveJoe(facing, x, y, false);
|
2003-12-02 16:49:56 +00:00
|
|
|
if (p != 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->newRoom(0); // cancel makeJoeWalkTo, that should be equivalent to cr10 fix
|
2003-12-02 16:49:56 +00:00
|
|
|
// XXX if(P != 0) P = FIND_VERB
|
2003-12-13 20:05:28 +00:00
|
|
|
warning("Command::makeJoeWalkTo() - p is %d but findVerb() is not called", p);
|
2003-12-02 16:49:56 +00:00
|
|
|
}
|
2003-11-03 19:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
void Command::grabCurrentSelection() {
|
2003-12-11 22:16:35 +00:00
|
|
|
_selPosX = _vm->input()->mousePosX();
|
|
|
|
_selPosY = _vm->input()->mousePosY();
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2004-01-08 14:10:32 +00:00
|
|
|
uint16 zone = _vm->grid()->findObjectUnderCursor(_selPosX, _selPosY);
|
|
|
|
_state.noun = _vm->grid()->findObjectNumber(zone);
|
|
|
|
_state.verb = _vm->grid()->findVerbUnderCursor(_selPosX, _selPosY);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
_selPosX += _vm->display()->horizontalScroll();
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.verb == VERB_SCROLL_UP || _state.verb == VERB_SCROLL_DOWN) {
|
|
|
|
// move through inventory (by four if right mouse button)
|
|
|
|
uint16 scroll = (_mouseKey == Input::MOUSE_RBUTTON) ? 4 : 1;
|
|
|
|
_vm->logic()->inventoryScroll(scroll, _state.verb == VERB_SCROLL_UP);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (isVerbAction(_state.verb)) {
|
2003-10-31 13:46:45 +00:00
|
|
|
grabSelectedVerb();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (isVerbInv(_state.verb)) {
|
2003-10-31 13:46:45 +00:00
|
|
|
grabSelectedItem();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_state.noun != 0) { // 0 && _state.noun <= _vm->logic()->currentRoomObjMax()) {
|
2003-10-31 13:46:45 +00:00
|
|
|
grabSelectedNoun();
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_selPosY < ROOM_ZONE_HEIGHT && _state.verb == VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// select without a command, do a WALK
|
|
|
|
clear(true);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeWalk(JWM_EXECUTE);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-03 19:52:14 +00:00
|
|
|
void Command::grabSelectedObject(int16 objNum, uint16 objState, uint16 objName) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.action != VERB_NONE) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_cmdText.addObject(_vm->logic()->objectName(objName));
|
2003-11-03 19:52:14 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
|
|
|
|
_state.subject[_state.commandLevel - 1] = objNum;
|
2003-11-03 19:52:14 +00:00
|
|
|
|
2003-11-08 23:45:45 +00:00
|
|
|
// if first noun and it's a 2 level command then set up action word
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.action == VERB_USE && _state.commandLevel == 1) {
|
2003-11-03 19:52:14 +00:00
|
|
|
if (State::findUse(objState) == STATE_USE_ON) {
|
2003-12-13 20:05:28 +00:00
|
|
|
// object supports 2 levels, command not fully constructed
|
|
|
|
_state.commandLevel = 2;
|
2003-12-12 10:33:34 +00:00
|
|
|
_cmdText.addLinkWord(VERB_PREP_WITH);
|
2003-11-03 19:52:14 +00:00
|
|
|
_cmdText.display(INK_CMD_NORMAL);
|
|
|
|
_parse = false;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
// _cmdText.display(INK_CMD_SELECT);
|
2003-11-03 19:52:14 +00:00
|
|
|
_parse = true;
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_state.action == VERB_GIVE && _state.commandLevel == 1) {
|
2003-12-13 20:05:28 +00:00
|
|
|
// command not fully constructed
|
|
|
|
_state.commandLevel = 2;
|
|
|
|
_cmdText.addLinkWord(VERB_PREP_TO);
|
2003-11-03 19:52:14 +00:00
|
|
|
_cmdText.display(INK_CMD_NORMAL);
|
|
|
|
_parse = false;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
// _cmdText.display(INK_CMD_SELECT);
|
2003-11-03 19:52:14 +00:00
|
|
|
_parse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_parse) {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_NONE;
|
|
|
|
// _vm->logic()->newRoom(0);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeWalk(JWM_EXECUTE);
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.selAction = _state.action;
|
|
|
|
_state.action = VERB_NONE;
|
2003-11-03 19:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
void Command::grabSelectedItem() {
|
2003-12-13 20:05:28 +00:00
|
|
|
// _parse = true;
|
|
|
|
|
|
|
|
ItemData *id = findItemData(_state.verb);
|
|
|
|
if (id == NULL || id->name <= 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-15 12:59:43 +00:00
|
|
|
int16 item = _vm->logic()->findInventoryItem(_state.verb - VERB_INV_FIRST);
|
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
// If we've selected via keyboard, and there is no VERB then do
|
|
|
|
// the ITEMs default, otherwise keep constructing!
|
|
|
|
|
2003-12-14 21:39:52 +00:00
|
|
|
if (_mouseKey == Input::MOUSE_LBUTTON ||
|
|
|
|
(_vm->input()->keyVerb() != VERB_NONE && _state.verb != VERB_NONE)) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.action == VERB_NONE) {
|
2003-12-14 21:39:52 +00:00
|
|
|
if (_vm->input()->keyVerb() != VERB_NONE) {
|
|
|
|
// We've selected via the keyboard, no command is being
|
|
|
|
// constructed, so we shall find the item's default
|
|
|
|
_state.verb = State::findDefaultVerb(id->state);
|
|
|
|
if (_state.verb == VERB_NONE) {
|
|
|
|
// set to Look At
|
|
|
|
_state.verb = VERB_LOOK_AT;
|
|
|
|
_cmdText.setVerb(VERB_LOOK_AT);
|
|
|
|
}
|
|
|
|
_state.action = _state.verb;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// Action>0 ONLY if command has been constructed
|
|
|
|
// Left Mouse Button pressed just do Look At
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.action = VERB_LOOK_AT;
|
2003-12-12 10:33:34 +00:00
|
|
|
_cmdText.setVerb(VERB_LOOK_AT);
|
2003-12-14 21:39:52 +00:00
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_NONE;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
// if (_vm->logic()->joeWalk() == JWM_MOVE) {
|
|
|
|
// _cmdText.clear();
|
|
|
|
// _state.commandLevel = 1;
|
|
|
|
// _vm->logic()->joeWalk(JWM_NORMAL);
|
|
|
|
// _state.action = VERB_NONE;
|
|
|
|
// lookForCurrentIcon();
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
State::alterDefaultVerb(&id->state, _state.defaultVerb);
|
|
|
|
_state.defaultVerb = VERB_NONE;
|
2003-10-31 13:46:45 +00:00
|
|
|
clear(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cmdText.isEmpty()) {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_LOOK_AT;
|
|
|
|
_state.action = VERB_LOOK_AT;
|
2003-12-12 10:33:34 +00:00
|
|
|
_cmdText.setVerb(VERB_LOOK_AT);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
|
|
|
if (_state.commandLevel == 2 && _parse)
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = _state.action;
|
2003-12-29 20:18:31 +00:00
|
|
|
else
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = State::findDefaultVerb(id->state);
|
|
|
|
if (_state.verb == VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// No match made, so command not yet completed. Redefine as LOOK AT
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.action = VERB_LOOK_AT;
|
2003-12-12 10:33:34 +00:00
|
|
|
_cmdText.setVerb(VERB_LOOK_AT);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.action = _state.verb;
|
2003-11-15 15:44:50 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_NONE;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
grabSelectedObject(-item, id->state, id->name);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::grabSelectedNoun() {
|
|
|
|
// if the NOUN has been selected from screen then it is positive
|
|
|
|
// otherwise it has been selected from inventory and is negative
|
2003-11-08 23:45:45 +00:00
|
|
|
// set PARSE to TRUE, default FALSE if command half complete
|
|
|
|
// click object without a command, if DEFAULT then
|
|
|
|
// do that, otherwise do a WALK!
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
ObjectData *od = findObjectData(_state.noun);
|
|
|
|
if (od == NULL || od->name <= 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// selected a turned off object, so just walk
|
|
|
|
clear(true);
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.noun = 0;
|
|
|
|
// _vm->logic()->newRoom(0);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeWalk(JWM_EXECUTE);
|
2003-10-31 13:46:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.verb == VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (_mouseKey == Input::MOUSE_LBUTTON) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if ((_state.commandLevel != 2 && _state.action == VERB_NONE) ||
|
|
|
|
(_state.commandLevel == 2 && _parse)) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// action2 > 0 only if command has been constructed
|
|
|
|
// lmb pressed, just walk
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_WALK_TO;
|
|
|
|
_state.action = VERB_WALK_TO;
|
2003-12-12 10:33:34 +00:00
|
|
|
_cmdText.setVerb(VERB_WALK_TO);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_mouseKey == Input::MOUSE_RBUTTON) {
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// rmb pressed, do default if one exists
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
// change default of command
|
|
|
|
State::alterDefaultVerb(&od->state, _state.defaultVerb);
|
|
|
|
_state.defaultVerb = VERB_NONE;
|
2003-10-31 13:46:45 +00:00
|
|
|
clear(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cmdText.isEmpty()) {
|
2003-11-08 23:45:45 +00:00
|
|
|
// Ensures that Right Mkey will select correct default
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = State::findDefaultVerb(od->state);
|
2003-12-15 12:59:43 +00:00
|
|
|
_state.selAction = (_state.verb == VERB_NONE) ? VERB_WALK_TO : _state.verb;
|
2003-12-13 20:05:28 +00:00
|
|
|
_cmdText.setVerb(_state.selAction);
|
2003-12-15 12:59:43 +00:00
|
|
|
_cmdText.addObject(_vm->logic()->objectName(od->name));
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_NONE;
|
|
|
|
if ((_state.commandLevel == 2 && !_parse) || _state.action != VERB_NONE) {
|
|
|
|
_state.verb = _state.action;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = State::findDefaultVerb(od->state);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-15 12:59:43 +00:00
|
|
|
_state.action = (_state.verb == VERB_NONE) ? VERB_WALK_TO : _state.verb;
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.verb = VERB_NONE;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.selNoun = 0;
|
|
|
|
int16 objNum = _vm->logic()->currentRoomData() + _state.noun;
|
|
|
|
grabSelectedObject(objNum, od->state, od->name);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
void Command::grabSelectedVerb() {
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.action = _state.verb;
|
|
|
|
_state.subject[0] = 0;
|
|
|
|
_state.subject[1] = 0;
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
// if right mouse key selected, then store command VERB
|
|
|
|
if (_mouseKey == Input::MOUSE_RBUTTON) {
|
|
|
|
_state.defaultVerb = _state.verb;
|
|
|
|
_cmdText.displayTemp(11, true, _state.verb);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_state.defaultVerb = VERB_NONE;
|
|
|
|
if (_vm->logic()->joeWalk() == JWM_MOVE && _state.verb != VERB_NONE) {
|
|
|
|
_vm->logic()->joeWalk(JWM_NORMAL);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.commandLevel = 1;
|
|
|
|
_state.oldVerb = VERB_NONE;
|
|
|
|
_state.oldNoun = 0;
|
|
|
|
_cmdText.setVerb(_state.verb);
|
|
|
|
_cmdText.display(INK_CMD_NORMAL);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Command::executeIfCutaway(const char *description) {
|
2003-11-02 16:46:12 +00:00
|
|
|
if (strlen(description) > 4 &&
|
|
|
|
scumm_stricmp(description + strlen(description) - 4, ".cut") == 0) {
|
2003-11-12 10:50:05 +00:00
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-11-26 21:46:29 +00:00
|
|
|
|
2003-11-03 14:47:22 +00:00
|
|
|
char nextCutaway[20];
|
|
|
|
memset(nextCutaway, 0, sizeof(nextCutaway));
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->playCutaway(description, nextCutaway);
|
2003-11-03 14:47:22 +00:00
|
|
|
while (nextCutaway[0] != '\0') {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->playCutaway(nextCutaway, nextCutaway);
|
2003-11-03 14:47:22 +00:00
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Command::executeIfDialog(const char *description) {
|
2003-11-06 08:53:09 +00:00
|
|
|
if (strlen(description) > 4 &&
|
2003-11-26 21:08:36 +00:00
|
|
|
scumm_stricmp(description + strlen(description) - 4, ".dog") == 0) {
|
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-11-26 21:46:29 +00:00
|
|
|
|
2003-11-06 08:53:09 +00:00
|
|
|
char cutaway[20];
|
2003-11-26 21:08:36 +00:00
|
|
|
memset(cutaway, 0, sizeof(cutaway));
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->startDialogue(description, _state.selNoun, cutaway);
|
2003-11-06 08:44:33 +00:00
|
|
|
|
2003-11-06 08:53:09 +00:00
|
|
|
while (cutaway[0] != '\0') {
|
|
|
|
char currentCutaway[20];
|
|
|
|
strcpy(currentCutaway, cutaway);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->playCutaway(currentCutaway, cutaway);
|
2003-11-06 08:53:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
bool Command::handleWrongAction() {
|
2003-10-31 13:46:45 +00:00
|
|
|
// l.96-141 execute.c
|
2004-01-08 14:10:32 +00:00
|
|
|
uint16 objMax = _vm->grid()->objMax(_vm->logic()->currentRoom());
|
2003-12-11 22:16:35 +00:00
|
|
|
uint16 roomData = _vm->logic()->currentRoomData();
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// select without a command or WALK TO ; do a WALK
|
2003-12-13 20:05:28 +00:00
|
|
|
if ((_state.selAction == VERB_WALK_TO || _state.selAction == VERB_NONE) &&
|
|
|
|
(_state.selNoun > objMax || _state.selNoun == 0)) {
|
|
|
|
if (_state.selAction == VERB_NONE) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-12 20:26:20 +00:00
|
|
|
_vm->walk()->moveJoe(0, _selPosX, _selPosY, false);
|
2003-10-31 13:46:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
// check to see if one of the objects is hidden
|
2003-12-13 20:05:28 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
int16 obj = _state.subject[i];
|
|
|
|
if (obj > 0 && _vm->logic()->objectData(obj)->name <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
|
2003-11-08 23:45:45 +00:00
|
|
|
// check for USE command on exists
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.selAction == VERB_USE &&
|
|
|
|
_state.subject[0] > 0 && _vm->logic()->objectData(_state.subject[0])->entryObj > 0) {
|
|
|
|
_state.selAction = VERB_WALK_TO;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
|
|
|
|
if (_state.selNoun > 0 && _state.selNoun <= objMax) {
|
|
|
|
uint16 objNum = roomData + _state.selNoun;
|
|
|
|
if (makeJoeWalkTo(_selPosX, _selPosY, objNum, _state.selAction, true) != 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.selAction == VERB_WALK_TO && _vm->logic()->objectData(objNum)->entryObj < 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
void Command::sayInvalidAction(Verb action, int16 subj1, int16 subj2) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// l.158-272 execute.c
|
2003-12-12 10:33:34 +00:00
|
|
|
switch (action) {
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
case VERB_LOOK_AT:
|
2003-12-13 20:05:28 +00:00
|
|
|
lookAtSelectedObject();
|
2003-10-31 13:46:45 +00:00
|
|
|
break;
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
case VERB_OPEN:
|
|
|
|
// 'it doesn't seem to open'
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(1);
|
2003-10-31 13:46:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VERB_USE:
|
|
|
|
if (subj1 < 0) {
|
2003-12-13 20:05:28 +00:00
|
|
|
uint16 k = _vm->logic()->itemData(-subj1)->sfxDescription;
|
2003-10-31 13:46:45 +00:00
|
|
|
if (k > 0) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(k, true);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(2);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(2);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
case VERB_TALK_TO:
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(24 + _vm->randomizer.getRandomNumber(2));
|
2003-10-31 13:46:45 +00:00
|
|
|
break;
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
case VERB_CLOSE:
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(2);
|
2003-10-31 13:46:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VERB_MOVE:
|
|
|
|
// 'I can't move it'
|
|
|
|
if (subj1 > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
int16 img = _vm->logic()->objectData(subj1)->image;
|
2003-10-31 13:46:45 +00:00
|
|
|
if (img == -4 || img == -3) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(18);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(3);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(3);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERB_GIVE:
|
|
|
|
// 'I can't give the subj1 to subj2'
|
|
|
|
if (subj1 < 0) {
|
|
|
|
if (subj2 > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
int16 img = _vm->logic()->objectData(subj2)->image;
|
2003-10-31 13:46:45 +00:00
|
|
|
if (img == -4 || img == -3) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(27 + _vm->randomizer.getRandomNumber(2));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(11);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(12);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERB_PICK_UP:
|
|
|
|
if (subj1 < 0) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(14);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-11 22:16:35 +00:00
|
|
|
int16 img = _vm->logic()->objectData(subj2)->image;
|
2003-10-31 13:46:45 +00:00
|
|
|
if (img == -4 || img == -3) {
|
|
|
|
// Trying to get a person
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(20);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-06 13:13:13 +00:00
|
|
|
// 5 : 'I can't pick that up'
|
|
|
|
// 6 : 'I don't think I need that'
|
|
|
|
// 7 : 'I'd rather leave it here'
|
|
|
|
// 8 : 'I don't think I'd have any use for that'
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(5 + _vm->randomizer.getRandomNumber(3));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
void Command::changeObjectState(Verb action, int16 obj, int16 song, bool cutDone) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// l.456-533 execute.c
|
2003-12-11 22:16:35 +00:00
|
|
|
ObjectData *objData = _vm->logic()->objectData(obj);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
if (action == VERB_OPEN && !cutDone) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (State::findOn(objData->state) == STATE_ON_ON) {
|
|
|
|
State::alterOn(&objData->state, STATE_ON_OFF);
|
2003-12-12 10:33:34 +00:00
|
|
|
State::alterDefaultVerb(&objData->state, VERB_NONE);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// play music if it exists... (or SFX for open/close door)
|
|
|
|
if (song != 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->sound()->playSong(ABS(song));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objData->entryObj != 0) {
|
2003-11-08 23:45:45 +00:00
|
|
|
// if it's a door, then update door that it links to
|
2003-12-03 10:33:14 +00:00
|
|
|
openOrCloseAssociatedObject(action, ABS(objData->entryObj));
|
2003-10-31 13:46:45 +00:00
|
|
|
objData->entryObj = ABS(objData->entryObj);
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// 'it's already open !'
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(9);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (action == VERB_CLOSE && !cutDone) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (State::findOn(objData->state) == STATE_ON_OFF) {
|
|
|
|
State::alterOn(&objData->state, STATE_ON_ON);
|
2003-12-12 10:33:34 +00:00
|
|
|
State::alterDefaultVerb(&objData->state, VERB_OPEN);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// play music if it exists... (or SFX for open/close door)
|
|
|
|
if (song != 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->sound()->playSong(ABS(song));
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objData->entryObj != 0) {
|
2003-11-08 23:45:45 +00:00
|
|
|
// if it's a door, then update door that it links to
|
2003-12-03 10:33:14 +00:00
|
|
|
openOrCloseAssociatedObject(action, ABS(objData->entryObj));
|
2003-10-31 13:46:45 +00:00
|
|
|
objData->entryObj = -ABS(objData->entryObj);
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// 'it's already closed !'
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(10);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (action == VERB_MOVE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
State::alterOn(&objData->state, STATE_ON_OFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::cleanupCurrentAction() {
|
|
|
|
// l.595-597 execute.c
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeFace();
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.oldNoun = 0;
|
|
|
|
_state.oldVerb = VERB_NONE;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
void Command::openOrCloseAssociatedObject(Verb action, int16 otherObj) {
|
2003-10-31 13:46:45 +00:00
|
|
|
CmdListData *cmdList = &_cmdList[1];
|
|
|
|
uint16 com = 0;
|
|
|
|
uint16 i;
|
2003-12-03 10:33:14 +00:00
|
|
|
for (i = 1; i <= _numCmdList; ++i, ++cmdList) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (cmdList->match(action, otherObj, 0)) {
|
|
|
|
if (cmdList->setConditions) {
|
2003-12-03 10:33:14 +00:00
|
|
|
warning("using Command::openOrCloseAssociatedObject() with setConditions");
|
2003-10-31 13:46:45 +00:00
|
|
|
CmdGameState *cmdGs = _cmdGameState;
|
|
|
|
uint16 j;
|
|
|
|
for (j = 1; j <= _numCmdGameState; ++j) {
|
2003-12-13 20:05:28 +00:00
|
|
|
// FIXME: weird, why using cmdGs[i] instead of cmdGs[j] ?
|
2003-10-31 13:46:45 +00:00
|
|
|
if (cmdGs[j].id == i && cmdGs[i].gameStateSlot > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
if (_vm->logic()->gameState(cmdGs[i].gameStateSlot) == cmdGs[i].gameStateValue) {
|
2003-10-31 13:46:45 +00:00
|
|
|
com = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
com = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::openOrCloseAssociatedObject() - com=%X", com);
|
2003-12-03 10:33:14 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
if (com != 0) {
|
|
|
|
|
|
|
|
cmdList = &_cmdList[com];
|
2003-12-11 22:16:35 +00:00
|
|
|
ObjectData *objData = _vm->logic()->objectData(otherObj);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
if (cmdList->imageOrder != 0) {
|
|
|
|
objData->image = cmdList->imageOrder;
|
|
|
|
}
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
if (action == VERB_OPEN) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (State::findOn(objData->state) == STATE_ON_ON) {
|
|
|
|
State::alterOn(&objData->state, STATE_ON_OFF);
|
2003-12-12 10:33:34 +00:00
|
|
|
State::alterDefaultVerb(&objData->state, VERB_NONE);
|
2003-10-31 13:46:45 +00:00
|
|
|
objData->entryObj = ABS(objData->entryObj);
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (action == VERB_CLOSE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
if (State::findOn(objData->state) == STATE_ON_OFF) {
|
|
|
|
State::alterOn(&objData->state, STATE_ON_ON);
|
2003-12-12 10:33:34 +00:00
|
|
|
State::alterDefaultVerb(&objData->state, VERB_OPEN);
|
2003-10-31 13:46:45 +00:00
|
|
|
objData->entryObj = -ABS(objData->entryObj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-08 23:45:45 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
int16 Command::setConditions(uint16 command, bool lastCmd) {
|
|
|
|
debug(9, "Command::setConditions(%d, %d)", command, lastCmd);
|
|
|
|
// Test conditions, if FAIL write && exit, Return -1
|
|
|
|
// if(Joe speaks before he returns, -2 is returned
|
|
|
|
// This way a -1 return will allow Joe to speak normal description
|
|
|
|
|
|
|
|
uint16 temp[21];
|
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
uint16 tempInd = 0;
|
|
|
|
|
|
|
|
int16 ret = 0;
|
|
|
|
uint16 i;
|
|
|
|
CmdGameState *cmdGs = &_cmdGameState[1];
|
|
|
|
for (i = 1; i <= _numCmdGameState; ++i, ++cmdGs) {
|
|
|
|
if (cmdGs->id == command) {
|
|
|
|
if (cmdGs->gameStateSlot > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
if (_vm->logic()->gameState(cmdGs->gameStateSlot) != cmdGs->gameStateValue) {
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::setConditions() - GS[%d] == %d (should be %d)", cmdGs->gameStateSlot, _vm->logic()->gameState(cmdGs->gameStateSlot), cmdGs->gameStateValue);
|
2003-10-31 13:46:45 +00:00
|
|
|
// failed test
|
|
|
|
ret = i;
|
|
|
|
break;
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
temp[tempInd] = i;
|
|
|
|
++tempInd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
// we've failed, so see if we need to make Joe speak
|
|
|
|
cmdGs = &_cmdGameState[ret];
|
2003-11-05 10:09:54 +00:00
|
|
|
if (cmdGs->speakValue > 0 && lastCmd) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// check to see if fail state is in fact a cutaway
|
2003-12-11 22:16:35 +00:00
|
|
|
const char *objDesc = _vm->logic()->objectTextualDescription(cmdGs->speakValue);
|
2003-10-31 13:46:45 +00:00
|
|
|
if (!executeIfCutaway(objDesc) && !executeIfDialog(objDesc)) {
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(cmdGs->speakValue, true);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
ret = -2;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
ret = 0;
|
|
|
|
// all tests were okay, now set gamestates
|
|
|
|
for (i = 0; i < tempInd; ++i) {
|
|
|
|
cmdGs = &_cmdGameState[temp[i]];
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->gameState(ABS(cmdGs->gameStateSlot), cmdGs->gameStateValue);
|
2003-10-31 13:46:45 +00:00
|
|
|
// set return value for Joe to say something
|
|
|
|
ret = cmdGs->speakValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::setAreas(uint16 command) {
|
|
|
|
debug(9, "Command::setAreas(%d)", command);
|
|
|
|
|
|
|
|
CmdArea *cmdArea = &_cmdArea[1];
|
|
|
|
uint16 i;
|
|
|
|
for (i = 1; i <= _numCmdArea; ++i, ++cmdArea) {
|
|
|
|
if (cmdArea->id == command) {
|
|
|
|
uint16 areaNum = ABS(cmdArea->area);
|
2004-01-08 14:10:32 +00:00
|
|
|
Area *area = _vm->grid()->area(cmdArea->room, areaNum);
|
2003-10-31 13:46:45 +00:00
|
|
|
if (cmdArea->area > 0) {
|
|
|
|
// turn on area
|
|
|
|
area->mapNeighbours = ABS(area->mapNeighbours);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// turn off area
|
|
|
|
area->mapNeighbours = -ABS(area->mapNeighbours);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::setObjects(uint16 command) {
|
|
|
|
debug(9, "Command::setObjects(%d)", command);
|
|
|
|
|
|
|
|
CmdObject *cmdObj = &_cmdObject[1];
|
|
|
|
uint16 i;
|
|
|
|
for (i = 1; i <= _numCmdObject; ++i, ++cmdObj) {
|
|
|
|
if (cmdObj->id == command) {
|
|
|
|
|
|
|
|
// found an object
|
|
|
|
uint16 dstObj = ABS(cmdObj->dstObj);
|
2003-12-11 22:16:35 +00:00
|
|
|
ObjectData *objData = _vm->logic()->objectData(dstObj);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::setObjects() - dstObj=%X srcObj=%X _state.subject[0]=%X", cmdObj->dstObj, cmdObj->srcObj, _state.subject[0]);
|
2003-11-20 09:38:54 +00:00
|
|
|
|
2003-10-31 13:46:45 +00:00
|
|
|
if (cmdObj->dstObj > 0) {
|
|
|
|
// show the object
|
|
|
|
objData->name = ABS(objData->name);
|
|
|
|
// test that the object has not already been deleted
|
|
|
|
// by checking if it is not equal to zero
|
|
|
|
if (cmdObj->srcObj == -1 && objData->name != 0) {
|
|
|
|
// delete object by setting its name to 0 and
|
|
|
|
// turning off graphic image
|
|
|
|
objData->name = 0;
|
2003-12-11 22:16:35 +00:00
|
|
|
if (objData->room == _vm->logic()->currentRoom()) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if (dstObj != _state.subject[0]) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// if the new object we have updated is on screen and is not the
|
|
|
|
// current object, then we can update. This is because we turn
|
|
|
|
// current object off ourselves by COM_LIST(com, 8)
|
|
|
|
if (objData->image != -3 && objData->image != -4) {
|
|
|
|
// it is a normal object (not a person)
|
|
|
|
// turn the graphic image off for the object
|
|
|
|
objData->image = -(objData->image + 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// invalidate object area
|
2003-12-11 22:16:35 +00:00
|
|
|
uint16 objZone = dstObj - _vm->logic()->currentRoomData();
|
2004-01-08 14:10:32 +00:00
|
|
|
_vm->grid()->setZone(GS_ROOM, objZone, 0, 0, 1, 1);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmdObj->srcObj > 0) {
|
|
|
|
// copy data from dummy object to object
|
|
|
|
int16 image1 = objData->image;
|
2003-12-11 22:16:35 +00:00
|
|
|
int16 image2 = _vm->logic()->objectData(cmdObj->srcObj)->image;
|
|
|
|
_vm->logic()->objectCopy(cmdObj->srcObj, dstObj);
|
|
|
|
if (image1 != 0 && image2 == 0 && objData->room == _vm->logic()->currentRoom()) {
|
|
|
|
uint16 bobNum = _vm->logic()->findBob(dstObj);
|
2003-10-31 13:46:45 +00:00
|
|
|
if (bobNum != 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->bobClear(bobNum);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (dstObj != _state.subject[0]) {
|
2003-10-31 13:46:45 +00:00
|
|
|
// if the new object we have updated is on screen and
|
|
|
|
// is not current object then update it
|
2004-01-08 22:46:42 +00:00
|
|
|
_vm->graphics()->refreshObject(dstObj);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// hide the object
|
|
|
|
if (objData->name > 0) {
|
|
|
|
objData->name = -objData->name;
|
|
|
|
// may need to turn BOBs off for objects to be hidden on current
|
|
|
|
// screen ! if the new object we have updated is on screen and
|
|
|
|
// is not current object then update it
|
2004-01-08 22:46:42 +00:00
|
|
|
_vm->graphics()->refreshObject(dstObj);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Command::setItems(uint16 command) {
|
|
|
|
debug(9, "Command::setItems(%d)", command);
|
|
|
|
|
|
|
|
CmdInventory *cmdInv = &_cmdInventory[1];
|
2003-12-11 22:16:35 +00:00
|
|
|
ItemData *items = _vm->logic()->itemData(0);
|
2003-10-31 13:46:45 +00:00
|
|
|
uint16 i;
|
|
|
|
for (i = 1; i <= _numCmdInventory; ++i, ++cmdInv) {
|
|
|
|
if (cmdInv->id == command) {
|
|
|
|
uint16 dstItem = ABS(cmdInv->dstItem);
|
|
|
|
// found an item
|
|
|
|
if (cmdInv->dstItem > 0) {
|
|
|
|
// add item to inventory
|
|
|
|
if (cmdInv->srcItem > 0) {
|
2003-12-29 20:18:31 +00:00
|
|
|
// copy data from source item to item, then enable it
|
2003-10-31 13:46:45 +00:00
|
|
|
items[dstItem] = items[cmdInv->srcItem];
|
|
|
|
items[dstItem].name = ABS(items[dstItem].name);
|
|
|
|
}
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->inventoryInsertItem(cmdInv->dstItem);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-10-31 13:46:45 +00:00
|
|
|
// delete item
|
|
|
|
if (items[dstItem].name > 0) {
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->inventoryDeleteItem(dstItem);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
if (cmdInv->srcItem > 0) {
|
2003-12-29 20:18:31 +00:00
|
|
|
// copy data from source item to item, then disable it
|
2003-10-31 13:46:45 +00:00
|
|
|
items[dstItem] = items[cmdInv->srcItem];
|
|
|
|
items[dstItem].name = -ABS(items[dstItem].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16 Command::nextObjectDescription(ObjectDescription* objDesc, uint16 firstDesc) {
|
|
|
|
// l.69-103 select.c
|
|
|
|
uint16 i;
|
|
|
|
uint16 diff = objDesc->lastDescription - firstDesc;
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::nextObjectDescription() - diff = %d, type = %d", diff, objDesc->type);
|
2003-10-31 13:46:45 +00:00
|
|
|
switch (objDesc->type) {
|
|
|
|
case 0:
|
|
|
|
// random type, start with first description
|
|
|
|
if (objDesc->lastSeenNumber == 0) {
|
|
|
|
// first time look at called
|
|
|
|
objDesc->lastSeenNumber = firstDesc;
|
2003-12-28 21:18:03 +00:00
|
|
|
break;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-28 21:18:03 +00:00
|
|
|
// already displayed first, do a random
|
2003-10-31 13:46:45 +00:00
|
|
|
case 1:
|
|
|
|
i = objDesc->lastSeenNumber;
|
|
|
|
while (i == objDesc->lastSeenNumber) {
|
2003-12-11 22:16:35 +00:00
|
|
|
i = firstDesc + _vm->randomizer.getRandomNumber(diff);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
objDesc->lastSeenNumber = i;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// sequential, but loop
|
|
|
|
++objDesc->lastSeenNumber;
|
|
|
|
if (objDesc->lastSeenNumber > objDesc->lastDescription) {
|
|
|
|
objDesc->lastSeenNumber = firstDesc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// sequential without looping
|
|
|
|
if (objDesc->lastSeenNumber != objDesc->lastDescription) {
|
|
|
|
++objDesc->lastSeenNumber;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return objDesc->lastSeenNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
void Command::lookAtSelectedObject() {
|
2003-12-15 12:59:43 +00:00
|
|
|
// if (_state.selNoun > 0 && _state.selNoun <= _vm->logic()->currentRoomObjMax()) {
|
|
|
|
// uint16 objNum = _vm->logic()->currentRoomData() + _state.selNoun;
|
|
|
|
// if (_vm->logic()->objectData(objNum)->entryObj == 0) {
|
|
|
|
// if (makeJoeWalkTo(_selPosX, _selPosY, objNum, _state.selAction, false) == -2) {
|
|
|
|
// // 'I can't get close enough to have a look.'
|
2004-01-07 15:45:24 +00:00
|
|
|
// _vm->logic()->makeJoeSpeak(13);
|
2003-12-15 12:59:43 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
uint16 desc;
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.subject[0] < 0) {
|
|
|
|
desc = _vm->logic()->itemData(-_state.subject[0])->description;
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
ObjectData *objData = _vm->logic()->objectData(_state.subject[0]);
|
|
|
|
if (objData->name <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
desc = objData->description;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 21:05:33 +00:00
|
|
|
debug(6, "Command::lookAtSelectedObject() - desc = %X, _state.subject[0] = %X", desc, _state.subject[0]);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
|
|
|
// check to see if the object/item has a series of description
|
2003-12-11 22:16:35 +00:00
|
|
|
ObjectDescription *objDesc = _vm->logic()->objectDescription(1);
|
2003-10-31 13:46:45 +00:00
|
|
|
uint16 i;
|
2003-12-11 22:16:35 +00:00
|
|
|
for (i = 1; i <= _vm->logic()->objectDescriptionCount(); ++i, ++objDesc) {
|
2003-12-13 20:05:28 +00:00
|
|
|
if (objDesc->object == _state.subject[0]) {
|
2003-10-31 13:46:45 +00:00
|
|
|
desc = nextObjectDescription(objDesc, desc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-07 15:45:24 +00:00
|
|
|
_vm->logic()->makeJoeSpeak(desc, true);
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->logic()->joeFace();
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
//void Command::lookForCurrentItem() {
|
|
|
|
//
|
|
|
|
// if (isVerbInv(_state.verb)) {
|
|
|
|
// ItemData *id = findItemData(_state.verb);
|
|
|
|
// if (id != NULL && id->name > 0) {
|
|
|
|
// if (_state.action == VERB_NONE) {
|
|
|
|
// Verb v = State::findDefaultVerb(id->state);
|
|
|
|
// _cmdText.setVerb((v == VERB_NONE) ? VERB_LOOK_AT : v);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// const char *name = _vm->logic()->objectName(id->name);
|
|
|
|
// if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
// _cmdText.displayTemp(INK_CMD_LOCK, true, _state.defaultVerb, name);
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// _cmdText.displayTemp(INK_CMD_NORMAL, name);
|
|
|
|
// }
|
|
|
|
// _state.oldVerb = _state.verb;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
2003-12-28 21:18:03 +00:00
|
|
|
void Command::lookForCurrentObject(int16 cx, int16 cy) {
|
2004-01-08 14:10:32 +00:00
|
|
|
uint16 obj = _vm->grid()->findObjectUnderCursor(cx, cy);
|
|
|
|
_state.noun = _vm->grid()->findObjectNumber(obj);
|
2003-12-13 20:05:28 +00:00
|
|
|
|
|
|
|
if (_state.oldNoun == _state.noun) {
|
2003-10-31 13:46:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if pointing at an Area then exit
|
|
|
|
// if the AREA is linked to an object, then dont exit. Find
|
|
|
|
// the object its linked to && store in AOBJ
|
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
// if (_state.noun > _vm->logic()->currentRoomObjMax()) {
|
|
|
|
// if (_state.oldNoun != 0) {
|
|
|
|
// if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
// _cmdText.displayTemp(INK_CMD_LOCK, true, _state.defaultVerb);
|
|
|
|
// }
|
|
|
|
// else if (_state.action != VERB_NONE) {
|
|
|
|
// _cmdText.display(INK_CMD_NORMAL);
|
|
|
|
// }
|
|
|
|
// _state.oldNoun = 0;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
ObjectData *od = findObjectData(_state.noun);
|
|
|
|
if (od == NULL || od->name <= 0) {
|
|
|
|
_state.oldNoun = _state.noun;
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
_cmdText.displayTemp(INK_CMD_LOCK, true, _state.defaultVerb);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_state.action != VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
_cmdText.display(INK_CMD_NORMAL);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no command yet selected, then use DEFAULT command, if any
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.action == VERB_NONE) {
|
|
|
|
Verb v = State::findDefaultVerb(od->state);
|
|
|
|
_cmdText.setVerb((v == VERB_NONE) ? VERB_WALK_TO : v);
|
|
|
|
if (_state.noun == 0) {
|
2003-10-31 13:46:45 +00:00
|
|
|
_cmdText.clear();
|
|
|
|
}
|
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
const char *name = _vm->logic()->objectName(od->name);
|
|
|
|
if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
_cmdText.displayTemp(INK_CMD_LOCK, true, _state.defaultVerb, name);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
_cmdText.displayTemp(INK_CMD_NORMAL, name);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.oldNoun = _state.noun;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-28 21:18:03 +00:00
|
|
|
void Command::lookForCurrentIcon(int16 cx, int16 cy) {
|
2004-01-08 14:10:32 +00:00
|
|
|
_state.verb = _vm->grid()->findVerbUnderCursor(cx, cy);
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.oldVerb != _state.verb) {
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (_state.action == VERB_NONE) {
|
2003-10-31 13:46:45 +00:00
|
|
|
_cmdText.clear();
|
|
|
|
}
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->graphics()->textClear(CmdText::COMMAND_Y_POS, CmdText::COMMAND_Y_POS);
|
2003-10-31 13:46:45 +00:00
|
|
|
|
2003-12-13 20:05:28 +00:00
|
|
|
if (isVerbInv(_state.verb)) {
|
|
|
|
ItemData *id = findItemData(_state.verb);
|
|
|
|
if (id != NULL && id->name > 0) {
|
|
|
|
if (_state.action == VERB_NONE) {
|
|
|
|
Verb v = State::findDefaultVerb(id->state);
|
|
|
|
_cmdText.setVerb((v == VERB_NONE) ? VERB_LOOK_AT : v);
|
|
|
|
}
|
|
|
|
const char *name = _vm->logic()->objectName(id->name);
|
|
|
|
if (_state.defaultVerb != VERB_NONE) {
|
|
|
|
_cmdText.displayTemp(INK_CMD_LOCK, true, _state.defaultVerb, name);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else {
|
2003-12-13 20:05:28 +00:00
|
|
|
_cmdText.displayTemp(INK_CMD_NORMAL, name);
|
|
|
|
}
|
|
|
|
}
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (isVerbAction(_state.verb)) {
|
2003-12-13 20:05:28 +00:00
|
|
|
_cmdText.displayTemp(INK_CMD_NORMAL, false, _state.verb);
|
2003-12-29 20:18:31 +00:00
|
|
|
} else if (_state.verb == VERB_NONE) {
|
2003-12-13 20:05:28 +00:00
|
|
|
_cmdText.display(INK_CMD_NORMAL);
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
2003-12-13 20:05:28 +00:00
|
|
|
_state.oldVerb = _state.verb;
|
2003-10-31 13:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-12 10:33:34 +00:00
|
|
|
|
2003-12-02 16:49:56 +00:00
|
|
|
} // End of namespace Queen
|