2011-09-03 17:33:14 +02:00
|
|
|
/* Residual - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* Residual 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 library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/myst3/console.h"
|
2011-09-04 11:16:27 +02:00
|
|
|
#include "engines/myst3/variables.h"
|
2011-09-03 17:33:14 +02:00
|
|
|
|
|
|
|
namespace Myst3 {
|
|
|
|
|
|
|
|
Console::Console(Myst3Engine *vm) : GUI::Debugger(), _vm(vm) {
|
|
|
|
DCmd_Register("infos", WRAP_METHOD(Console, Cmd_Infos));
|
|
|
|
DCmd_Register("lookAt", WRAP_METHOD(Console, Cmd_LookAt));
|
2011-09-04 09:24:06 +02:00
|
|
|
DCmd_Register("initScript", WRAP_METHOD(Console, Cmd_InitScript));
|
2011-09-04 11:16:27 +02:00
|
|
|
DCmd_Register("var", WRAP_METHOD(Console, Cmd_Var));
|
2011-09-04 20:08:37 +02:00
|
|
|
DCmd_Register("listNodes", WRAP_METHOD(Console, Cmd_ListNodes));
|
2011-09-04 20:57:57 +02:00
|
|
|
DCmd_Register("run", WRAP_METHOD(Console, Cmd_Run));
|
2011-09-09 07:40:18 +02:00
|
|
|
DCmd_Register("go", WRAP_METHOD(Console, Cmd_Go));
|
2011-09-03 17:33:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console() {
|
|
|
|
}
|
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
void Console::describeScript(const Common::Array<Opcode> &script) {
|
2011-09-04 09:24:06 +02:00
|
|
|
Common::String d;
|
|
|
|
|
|
|
|
for(uint j = 0; j < script.size(); j++) {
|
|
|
|
const Opcode &opcode = script[j];
|
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
d = Common::String::format(" op %s ( ",
|
2011-09-04 09:24:06 +02:00
|
|
|
_vm->_scriptEngine->describeCommand(opcode.op).c_str());
|
|
|
|
|
|
|
|
for(uint k = 0; k < opcode.args.size(); k++) {
|
|
|
|
d += Common::String::format("%d ", opcode.args[k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
d += ")\n";
|
2011-09-04 20:08:37 +02:00
|
|
|
|
|
|
|
DebugPrintf("%s", d.c_str());
|
2011-09-04 09:24:06 +02:00
|
|
|
}
|
2011-09-04 20:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::String Console::describeCondition(int16 condition) {
|
|
|
|
uint16 unsignedCond = abs(condition);
|
|
|
|
uint16 var = unsignedCond & 2047;
|
|
|
|
int16 value = (unsignedCond >> 11) - 1;
|
|
|
|
|
|
|
|
if (value < 0)
|
|
|
|
value = 1;
|
2011-09-04 09:24:06 +02:00
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
return Common::String::format("var[%d] %s %d (%s)",
|
|
|
|
var, condition > 0 ? "==" : "!=", value,
|
|
|
|
_vm->_vars->evaluate(condition) ? "true" : "false");
|
2011-09-04 09:24:06 +02:00
|
|
|
}
|
|
|
|
|
2011-09-03 17:33:14 +02:00
|
|
|
bool Console::Cmd_Infos(int argc, const char **argv) {
|
|
|
|
|
2011-09-05 20:13:48 +02:00
|
|
|
uint16 nodeId = _vm->_currentNode;
|
2011-09-04 20:08:37 +02:00
|
|
|
uint16 roomId = 0;
|
2011-09-04 11:16:27 +02:00
|
|
|
|
|
|
|
if (argc >= 2) {
|
|
|
|
nodeId = atoi(argv[1]);
|
|
|
|
}
|
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
if (argc >= 3) {
|
2011-09-09 07:40:18 +02:00
|
|
|
roomId = _vm->_db->getRoomId(argv[2]);
|
|
|
|
|
|
|
|
if (roomId == 0) {
|
|
|
|
DebugPrintf("Unknown room name %s\n", argv[2]);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-04 20:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NodePtr nodeData = _vm->_db->getNodeData(nodeId, roomId);
|
2011-09-03 17:33:14 +02:00
|
|
|
|
|
|
|
char roomName[8];
|
2011-09-04 20:08:37 +02:00
|
|
|
_vm->_db->getRoomName(roomName, roomId);
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-09 07:40:18 +02:00
|
|
|
DebugPrintf("node: %s %d ", roomName, nodeId);
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 09:24:06 +02:00
|
|
|
for (uint i = 0; i < nodeData->hotspots.size(); i++) {
|
2011-09-04 20:08:37 +02:00
|
|
|
DebugPrintf("\nhotspot %d > condition: %s\n",
|
|
|
|
i, describeCondition(nodeData->hotspots[i].condition).c_str());
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 09:24:06 +02:00
|
|
|
for(uint j = 0; j < nodeData->hotspots[i].rects.size(); j++) {
|
|
|
|
PolarRect &rect = nodeData->hotspots[i].rects[j];
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 09:24:06 +02:00
|
|
|
DebugPrintf(" rect > pitch: %d heading: %d height: %d width: %d\n",
|
|
|
|
rect.centerPitch, rect.centerHeading, rect.width, rect.height);
|
|
|
|
}
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
describeScript(nodeData->hotspots[i].script);
|
2011-09-04 09:24:06 +02:00
|
|
|
}
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 09:24:06 +02:00
|
|
|
for (uint i = 0; i < nodeData->scripts.size(); i++) {
|
2011-09-04 20:08:37 +02:00
|
|
|
DebugPrintf("\nscript %d > condition: %s\n",
|
|
|
|
i, describeCondition(nodeData->scripts[i].condition).c_str());
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
describeScript(nodeData->scripts[i].script);
|
2011-09-04 09:24:06 +02:00
|
|
|
}
|
2011-09-03 17:33:14 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Cmd_LookAt(int argc, const char **argv) {
|
|
|
|
|
2011-09-09 07:40:18 +02:00
|
|
|
if (argc != 1 && argc != 3) {
|
2011-09-03 17:33:14 +02:00
|
|
|
DebugPrintf("Usage :\n");
|
|
|
|
DebugPrintf("lookAt pitch heading\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:40:18 +02:00
|
|
|
Common::Point lookAt = _vm->_scene->getMousePos();
|
|
|
|
DebugPrintf("pitch: %d heading: %d\n", lookAt.y, lookAt.x);
|
2011-09-03 17:33:14 +02:00
|
|
|
|
2011-09-09 07:40:18 +02:00
|
|
|
if (argc >= 3){
|
|
|
|
_vm->_scene->lookAt(atof(argv[1]), atof(argv[2]));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-09-03 17:33:14 +02:00
|
|
|
}
|
|
|
|
|
2011-09-04 09:24:06 +02:00
|
|
|
bool Console::Cmd_InitScript(int argc, const char **argv) {
|
2011-09-04 20:08:37 +02:00
|
|
|
describeScript(_vm->_db->getNodeInitScript());
|
2011-09-04 09:24:06 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-04 11:16:27 +02:00
|
|
|
|
|
|
|
bool Console::Cmd_Var(int argc, const char **argv) {
|
|
|
|
|
|
|
|
if (argc != 2 && argc != 3) {
|
|
|
|
DebugPrintf("Usage :\n");
|
|
|
|
DebugPrintf("var variable : Display var value\n");
|
|
|
|
DebugPrintf("var variable value : Change var value\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 var = atoi(argv[1]);
|
2011-09-04 20:08:37 +02:00
|
|
|
uint32 value = _vm->_vars->get(var);
|
2011-09-04 11:16:27 +02:00
|
|
|
|
|
|
|
if (argc == 3) {
|
|
|
|
value = atoi(argv[2]);
|
|
|
|
_vm->_vars->set(var, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugPrintf("var[%d] : %d\n", var, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-04 20:08:37 +02:00
|
|
|
bool Console::Cmd_ListNodes(int argc, const char **argv) {
|
|
|
|
|
|
|
|
uint16 roomID = 0;
|
|
|
|
|
|
|
|
if (argc == 2) {
|
2011-09-09 07:40:18 +02:00
|
|
|
roomID = _vm->_db->getRoomId(argv[1]);
|
|
|
|
|
|
|
|
if (roomID == 0) {
|
|
|
|
DebugPrintf("Unknown room name %s\n", argv[1]);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-04 20:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugPrintf("Nodes:\n");
|
|
|
|
|
|
|
|
Common::Array<uint16> list = _vm->_db->listRoomNodes(roomID);
|
|
|
|
for (uint i = 0; i < list.size(); i++) {
|
|
|
|
DebugPrintf("%d\n", list[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-04 20:57:57 +02:00
|
|
|
bool Console::Cmd_Run(int argc, const char **argv) {
|
2011-09-05 20:13:48 +02:00
|
|
|
uint16 nodeId = _vm->_currentNode;
|
2011-09-04 20:57:57 +02:00
|
|
|
uint16 roomId = 0;
|
|
|
|
|
|
|
|
if (argc >= 2) {
|
|
|
|
nodeId = atoi(argv[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc >= 3) {
|
2011-09-09 07:40:18 +02:00
|
|
|
roomId = _vm->_db->getRoomId(argv[2]);
|
|
|
|
|
|
|
|
if (roomId == 0) {
|
|
|
|
DebugPrintf("Unknown room name %s\n", argv[2]);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-04 20:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_vm->runScriptsFromNode(nodeId, roomId);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:40:18 +02:00
|
|
|
|
|
|
|
bool Console::Cmd_Go(int argc, const char **argv) {
|
|
|
|
if (argc != 3) {
|
|
|
|
DebugPrintf("Usage :\n");
|
|
|
|
DebugPrintf("go [room name] [node id] : Go to node\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 roomID = _vm->_db->getRoomId(argv[1]);
|
|
|
|
uint16 nodeId = atoi(argv[2]);
|
|
|
|
|
|
|
|
if (roomID == 0) {
|
|
|
|
DebugPrintf("Unknown room name %s\n", argv[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->goToNode(nodeId, roomID);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-03 17:33:14 +02:00
|
|
|
} /* namespace Myst3 */
|