2014-12-27 11:21:30 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/resources/command.h"
|
2015-01-07 20:34:38 +01:00
|
|
|
|
2014-12-27 11:21:30 +01:00
|
|
|
#include "engines/stark/debug.h"
|
2015-01-14 18:10:09 +01:00
|
|
|
#include "engines/stark/formats/xrc.h"
|
2015-01-07 20:34:38 +01:00
|
|
|
#include "engines/stark/resources/bookmark.h"
|
2015-01-11 15:25:43 +01:00
|
|
|
#include "engines/stark/resources/dialog.h"
|
2015-01-07 20:34:38 +01:00
|
|
|
#include "engines/stark/resources/item.h"
|
2015-01-10 10:27:32 +01:00
|
|
|
#include "engines/stark/resources/knowledge.h"
|
|
|
|
#include "engines/stark/resources/script.h"
|
2015-01-14 20:43:09 +01:00
|
|
|
#include "engines/stark/resources/sound.h"
|
2014-12-27 12:34:01 +01:00
|
|
|
#include "engines/stark/resourcereference.h"
|
2015-01-11 15:25:43 +01:00
|
|
|
#include "engines/stark/services/services.h"
|
|
|
|
#include "engines/stark/services/dialogplayer.h"
|
2015-01-16 09:35:47 +01:00
|
|
|
#include "engines/stark/services/resourceprovider.h"
|
2014-12-27 11:21:30 +01:00
|
|
|
|
|
|
|
namespace Stark {
|
2015-02-13 11:10:44 +01:00
|
|
|
namespace Resources {
|
2014-12-27 11:21:30 +01:00
|
|
|
|
|
|
|
Command::~Command() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::Command(Resource *parent, byte subType, uint16 index, const Common::String &name) :
|
|
|
|
Resource(parent, subType, index, name) {
|
2015-01-04 15:03:09 +01:00
|
|
|
_type = TYPE;
|
2014-12-27 11:21:30 +01:00
|
|
|
}
|
|
|
|
|
2015-01-06 21:31:16 +01:00
|
|
|
Command *Command::execute(uint32 callMode, Script *script) {
|
2015-01-07 20:34:38 +01:00
|
|
|
switch (_subType) {
|
2015-01-16 13:41:47 +01:00
|
|
|
case kCommandBegin:
|
|
|
|
return opScriptBegin();
|
2015-01-11 15:25:43 +01:00
|
|
|
case kDialogCall:
|
|
|
|
return opDialogCall(script, _arguments[1].referenceValue, _arguments[2].intValue);
|
|
|
|
case kLocationGoTo:
|
2015-01-16 09:35:47 +01:00
|
|
|
return opLocationGoTo(_arguments[0].stringValue, _arguments[1].stringValue, _arguments[2].referenceValue, _arguments[3].intValue);
|
2015-01-11 15:25:43 +01:00
|
|
|
case kScriptPause:
|
2015-01-16 09:38:35 +01:00
|
|
|
return opScriptPause(script, _arguments[1].referenceValue);
|
2015-01-07 21:18:44 +01:00
|
|
|
case kItem3DPlaceOn:
|
2015-01-16 09:38:35 +01:00
|
|
|
return opItem3DPlaceOn(_arguments[1].referenceValue, _arguments[2].referenceValue);
|
2015-01-07 21:18:44 +01:00
|
|
|
case kItemEnable:
|
2015-01-16 09:38:35 +01:00
|
|
|
return opItemEnable(_arguments[1].referenceValue, _arguments[2].intValue);
|
2015-01-14 20:43:09 +01:00
|
|
|
case kSoundPlay:
|
|
|
|
return opSoundPlay(script, _arguments[1].referenceValue, _arguments[2].intValue);
|
2015-01-07 21:18:44 +01:00
|
|
|
case kItemPlaceDirection:
|
2015-01-16 09:38:35 +01:00
|
|
|
return opItemPlaceDirection(_arguments[1].referenceValue, _arguments[2].intValue);
|
2015-01-07 20:34:38 +01:00
|
|
|
default:
|
2015-01-16 09:35:47 +01:00
|
|
|
warning("Unimplemented command %d - %s", _subType, _name.c_str());
|
|
|
|
printData();
|
2015-01-07 20:34:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextCommand();
|
|
|
|
}
|
|
|
|
|
2015-01-16 13:41:47 +01:00
|
|
|
Command *Command::opScriptBegin() {
|
|
|
|
return nextCommand();
|
|
|
|
}
|
|
|
|
|
2015-01-11 15:25:43 +01:00
|
|
|
Command *Command::opDialogCall(Script *script, const ResourceReference &dialogRef, int32 suspend) {
|
|
|
|
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer;
|
|
|
|
|
|
|
|
Dialog *dialog = dialogRef.resolve<Dialog>();
|
|
|
|
dialogPlayer->run(dialog);
|
|
|
|
|
|
|
|
if (suspend) {
|
|
|
|
script->suspend(dialog);
|
|
|
|
return this; // Stay on the same command while suspended
|
|
|
|
} else {
|
|
|
|
return nextCommand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 09:35:47 +01:00
|
|
|
Command *Command::opLocationGoTo(const Common::String &level, const Common::String &location, const ResourceReference &bookmarkRef, int32 direction) {
|
|
|
|
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider;
|
|
|
|
|
|
|
|
uint levelIndex = strtol(level.c_str(), nullptr, 16);
|
|
|
|
uint locationIndex = strtol(location.c_str(), nullptr, 16);
|
|
|
|
resourceProvider->requestLocationChange(levelIndex, locationIndex);
|
|
|
|
resourceProvider->setNextLocationPosition(bookmarkRef, direction);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-16 09:38:35 +01:00
|
|
|
Command *Command::opScriptPause(Script *script, const ResourceReference &durationRef) {
|
2015-01-10 10:27:32 +01:00
|
|
|
Knowledge *duration = durationRef.resolve<Knowledge>();
|
|
|
|
script->pause(duration->getIntegerValue());
|
2015-01-16 09:38:35 +01:00
|
|
|
|
|
|
|
return this; // Stay on this command while the script is suspended
|
2015-01-10 10:27:32 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 09:38:35 +01:00
|
|
|
Command *Command::opItem3DPlaceOn(const ResourceReference &itemRef, const ResourceReference &targetRef) {
|
2015-01-07 20:34:38 +01:00
|
|
|
ItemSub5610 *item = itemRef.resolve<ItemSub5610>();
|
|
|
|
Resource *target = targetRef.resolve<Resource>();
|
|
|
|
|
|
|
|
switch (target->getType().get()) {
|
|
|
|
case ResourceType::kBookmark:
|
|
|
|
item->placeOnBookmark(Resource::cast<Bookmark>(target));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("Unimplemented op3DPlaceOn target type %s", target->getType().getName());
|
|
|
|
}
|
2015-01-16 09:38:35 +01:00
|
|
|
|
|
|
|
return nextCommand();
|
2015-01-07 20:34:38 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 09:38:35 +01:00
|
|
|
Command *Command::opItemEnable(const ResourceReference &itemRef, int32 enable) {
|
2015-01-07 21:18:44 +01:00
|
|
|
Item *item = itemRef.resolve<Item>();
|
|
|
|
|
|
|
|
bool previousState = item->isEnabled();
|
|
|
|
|
|
|
|
switch (enable) {
|
|
|
|
case 0:
|
|
|
|
item->setEnabled(false);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!previousState) {
|
|
|
|
item->setEnabled(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
item->setEnabled(!previousState);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-16 09:38:35 +01:00
|
|
|
|
|
|
|
return nextCommand();
|
2015-01-07 21:18:44 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 20:43:09 +01:00
|
|
|
Command *Command::opSoundPlay(Script *script, const ResourceReference &soundRef, int32 suspend) {
|
|
|
|
Sound *sound = soundRef.resolve<Sound>();
|
|
|
|
sound->play();
|
|
|
|
|
|
|
|
if (suspend) {
|
|
|
|
script->suspend(sound);
|
|
|
|
return this; // Stay on the same command while suspended
|
|
|
|
} else {
|
|
|
|
return nextCommand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 09:38:35 +01:00
|
|
|
Command *Command::opItemPlaceDirection(const ResourceReference &itemRef, int32 direction) {
|
2015-01-07 20:34:38 +01:00
|
|
|
ItemSub5610 *item = itemRef.resolve<ItemSub5610>();
|
|
|
|
|
|
|
|
item->setDirection(abs(direction) % 360);
|
2015-01-16 09:38:35 +01:00
|
|
|
|
|
|
|
return nextCommand();
|
2015-01-07 20:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Command *Command::nextCommand() {
|
|
|
|
assert(!_arguments.empty());
|
2015-01-11 08:53:29 +01:00
|
|
|
assert(_arguments[0].type == Argument::kTypeInteger1);
|
2015-01-07 20:34:38 +01:00
|
|
|
|
|
|
|
return resolveArgumentSiblingReference(_arguments[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Command *Command::nextCommandIf(bool predicate) {
|
|
|
|
assert(!_arguments.size() >= 2);
|
|
|
|
|
|
|
|
if (predicate) {
|
|
|
|
return resolveArgumentSiblingReference(_arguments[1]);
|
|
|
|
} else {
|
|
|
|
return resolveArgumentSiblingReference(_arguments[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command *Command::resolveArgumentSiblingReference(const Argument &argument) {
|
|
|
|
return _parent->findChildWithIndex<Command>(argument.intValue);
|
2015-01-06 21:31:16 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 11:21:30 +01:00
|
|
|
void Command::readData(XRCReadStream *stream) {
|
|
|
|
uint32 count = stream->readUint32LE();
|
|
|
|
for (uint i = 0; i < count; i++) {
|
|
|
|
Argument argument;
|
|
|
|
argument.type = stream->readUint32LE();
|
|
|
|
|
|
|
|
switch (argument.type) {
|
|
|
|
case Argument::kTypeInteger1:
|
|
|
|
case Argument::kTypeInteger2:
|
|
|
|
argument.intValue = stream->readUint32LE();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Argument::kTypeResourceReference:
|
|
|
|
argument.referenceValue = stream->readResourceReference();
|
|
|
|
break;
|
|
|
|
case Argument::kTypeString:
|
|
|
|
argument.stringValue = stream->readString();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown argument type %d", argument.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
_arguments.push_back(argument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::printData() {
|
|
|
|
for (uint i = 0; i < _arguments.size(); i++) {
|
|
|
|
switch (_arguments[i].type) {
|
|
|
|
case Argument::kTypeInteger1:
|
|
|
|
case Argument::kTypeInteger2:
|
|
|
|
debug("%d: %d", i, _arguments[i].intValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Argument::kTypeResourceReference: {
|
2014-12-27 12:43:16 +01:00
|
|
|
debug("%d: %s", i, _arguments[i].referenceValue.describe().c_str());
|
2014-12-27 11:21:30 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Argument::kTypeString:
|
|
|
|
debug("%d: %s", i, _arguments[i].stringValue.c_str());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown argument type %d", _arguments[i].type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-13 11:10:44 +01:00
|
|
|
} // End of namespace Resources
|
2014-12-27 11:21:30 +01:00
|
|
|
} // End of namespace Stark
|