scummvm/engines/myst3/console.cpp

218 lines
5.4 KiB
C++
Raw Normal View History

/* 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.
*
2012-01-05 10:07:48 +01: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.
2012-01-05 10:07:48 +01:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-01-05 10:07:48 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2012-01-05 10:07:48 +01:00
* 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/myst3/console.h"
2011-09-04 11:16:27 +02:00
#include "engines/myst3/variables.h"
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));
DCmd_Register("go", WRAP_METHOD(Console, Cmd_Go));
}
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
for(uint j = 0; j < script.size(); j++) {
DebugPrintf("%s", _vm->_scriptEngine->describeOpcode(script[j]).c_str());
2011-09-04 09:24:06 +02:00
}
2011-09-04 20:08:37 +02:00
}
bool Console::Cmd_Infos(int argc, const char **argv) {
uint16 nodeId = _vm->_vars->getLocationNode();
uint32 roomId = _vm->_vars->getLocationRoom();
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) {
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);
if (!nodeData) {
DebugPrintf("No node with id %d\n", nodeId);
return true;
}
char roomName[8];
2011-09-04 20:08:37 +02:00
_vm->_db->getRoomName(roomName, roomId);
DebugPrintf("node: %s %d ", roomName, nodeId);
2011-09-04 09:24:06 +02:00
for (uint i = 0; i < nodeData->hotspots.size(); i++) {
DebugPrintf("\nhotspot %d > %s (%s)\n", i,
_vm->_vars->describeCondition(nodeData->hotspots[i].condition).c_str(),
_vm->_vars->evaluate(nodeData->hotspots[i].condition) ? "true" : "false");
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-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-04 20:08:37 +02:00
describeScript(nodeData->hotspots[i].script);
2011-09-04 09:24:06 +02:00
}
2011-09-04 09:24:06 +02:00
for (uint i = 0; i < nodeData->scripts.size(); i++) {
DebugPrintf("\nscript %d > %s (%s)\n", i,
_vm->_vars->describeCondition(nodeData->scripts[i].condition).c_str(),
_vm->_vars->evaluate(nodeData->scripts[i].condition) ? "true" : "false");
2011-09-04 20:08:37 +02:00
describeScript(nodeData->scripts[i].script);
2011-09-04 09:24:06 +02:00
}
return true;
}
bool Console::Cmd_LookAt(int argc, const char **argv) {
if (argc != 1 && argc != 3) {
DebugPrintf("Usage :\n");
DebugPrintf("lookAt pitch heading\n");
return true;
}
Common::Point lookAt = _vm->_scene->getMousePos();
DebugPrintf("pitch: %d heading: %d\n", lookAt.y, lookAt.x);
if (argc >= 3){
_vm->_scene->lookAt(atof(argv[1]), atof(argv[2]));
return false;
}
return true;
}
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("%s: %d\n", _vm->_vars->describeVar(var).c_str(), value);
2011-09-04 11:16:27 +02:00
return true;
}
2011-09-04 20:08:37 +02:00
bool Console::Cmd_ListNodes(int argc, const char **argv) {
uint32 roomID = 0;
2011-09-04 20:08:37 +02:00
if (argc == 2) {
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) {
uint16 nodeId = _vm->_vars->getLocationNode();
uint32 roomId = 0;
2011-09-04 20:57:57 +02:00
if (argc >= 2) {
nodeId = atoi(argv[1]);
}
if (argc >= 3) {
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;
}
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;
}
uint32 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;
}
} /* namespace Myst3 */