/* ScummVM - Graphic Adventure Engine * * 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. * * 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. * * $URL$ * $Id$ * */ #include "asylum/console.h" #include "asylum/resources/actionlist.h" #include "asylum/resources/actor.h" #include "asylum/resources/object.h" #include "asylum/resources/worldstats.h" #include "asylum/system/screen.h" #include "asylum/views/scene.h" #include "asylum/asylum.h" #include "common/debug-channels.h" namespace Asylum { extern int32 g_debugPolygons; extern int32 g_debugObjects; extern int32 g_debugScrolling; Console::Console(AsylumEngine *engine) : _vm(engine) { // Commands DCmd_Register("help", WRAP_METHOD(Console, cmdHelp)); DCmd_Register("ls", WRAP_METHOD(Console, cmdListFiles)); DCmd_Register("actions", WRAP_METHOD(Console, cmdListActions)); DCmd_Register("actors", WRAP_METHOD(Console, cmdListActors)); DCmd_Register("flags", WRAP_METHOD(Console, cmdListFlags)); DCmd_Register("object", WRAP_METHOD(Console, cmdShowObject)); DCmd_Register("objects", WRAP_METHOD(Console, cmdListObjects)); DCmd_Register("video", WRAP_METHOD(Console, cmdPlayVideo)); DCmd_Register("script", WRAP_METHOD(Console, cmdRunScript)); DCmd_Register("scene", WRAP_METHOD(Console, cmdChangeScene)); DCmd_Register("toggle_flag", WRAP_METHOD(Console, cmdToggleFlag)); // Variables DVar_Register("show_polygons", &g_debugPolygons, DVAR_INT, 0); DVar_Register("show_objects", &g_debugObjects, DVAR_INT, 0); DVar_Register("use_scrolling", &g_debugScrolling, DVAR_INT, 0); } Console::~Console() { DebugMan.clearAllDebugChannels(); // Zero passed pointers _vm = NULL; } ////////////////////////////////////////////////////////////////////////// // Help ////////////////////////////////////////////////////////////////////////// bool Console::cmdHelp(int, const char **) { DebugPrintf("Debug flags\n"); DebugPrintf("-----------\n"); DebugPrintf(" debugflag_list - Lists the available debug flags and their status\n"); DebugPrintf(" debugflag_enable - Enables a debug flag\n"); DebugPrintf(" debugflag_disable - Disables a debug flag\n"); DebugPrintf(" show_polygons - Show polygons\n"); DebugPrintf(" show_objects - Show objects\n"); DebugPrintf(" use_scrolling - Use scrolling\n"); DebugPrintf("\n"); DebugPrintf("Commands\n"); DebugPrintf("--------\n"); DebugPrintf(" ls - list engine files\n"); DebugPrintf("\n"); DebugPrintf(" actors - show actors information\n"); DebugPrintf(" action - show action information\n"); DebugPrintf(" flags - show flags\n"); DebugPrintf(" object - inspect a particular object\n"); DebugPrintf(" objects - show objects information\n"); DebugPrintf("\n"); DebugPrintf(" video - play a video\n"); DebugPrintf(" script - run a script\n"); DebugPrintf(" scene - change the scene\n"); DebugPrintf("\n"); DebugPrintf(" toggle_flag - toggle a flag\n"); DebugPrintf("\n"); return true; } ////////////////////////////////////////////////////////////////////////// // List commands ////////////////////////////////////////////////////////////////////////// bool Console::cmdListFiles(int argc, const char **argv) { if (argc != 2) { DebugPrintf("Syntax: %s (use * for all)\n", argv[0]); return true; } Common::String filter(const_cast(argv[1])); Common::ArchiveMemberList list; int count = SearchMan.listMatchingMembers(list, filter); DebugPrintf("Number of matches: %d\n", count); for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) DebugPrintf(" %s\n", (*it)->getName().c_str()); return true; } bool Console::cmdListActions(int32 argc, const char **argv) { if (argc != 1 && argc != 2) { DebugPrintf("Syntax: %s (use nothing for all)\n", argv[0]); return true; } if (argc == 1) { for (uint32 i = 0; i < getWorld()->actions.size(); i++) DebugPrintf("%s\n", getWorld()->actions[i]->toString().c_str()); } else { int index = atoi(argv[1]); int maxIndex = getWorld()->actions.size() - 1; if (index < 0 || index > maxIndex) { DebugPrintf("[error] index should be between 0 and %d\n", maxIndex); return true; } DebugPrintf("%s\n", getWorld()->actions[index]->toString().c_str()); } return true; } bool Console::cmdListActors(int32 argc, const char **argv) { if (argc != 1 && argc != 2) { DebugPrintf("Syntax: %s (use nothing for all)\n", argv[0]); return true; } if (argc == 1) { for (uint32 i = 0; i < getWorld()->actors.size(); i++) DebugPrintf("%s\n", getWorld()->actors[i]->toString().c_str()); } else { int index = atoi(argv[1]); int maxIndex = getWorld()->actors.size() - 1; if (index < 0 || index > maxIndex) { DebugPrintf("[error] index should be between 0 and %d\n", maxIndex); return true; } DebugPrintf("%s\n", getWorld()->actors[index]->toString().c_str()); } return true; } bool Console::cmdListFlags(int32 argc, const char **argv) { if (argc != 1 && argc != 2) { DebugPrintf("Syntax: %s (nothing: all - 1: show set flags - 0: show unset flags)\n", argv[0]); return true; } // Show all flags if (argc == 1) { for (int32 i = 0; i < 1512; i++) { DebugPrintf("%04d: %d ", i, _vm->isGameFlagSet((GameFlag)i)); if ((i + 1) % 10 == 0) DebugPrintf("\n"); } DebugPrintf("\n"); } else { bool type = atoi(argv[1]); if (type != 0 && type != 1) { DebugPrintf("Syntax: %s (nothing: all - 1: show set flags - 0: show unset flags)\n", argv[0]); return true; } // Show only set/unset flags int count = 0; for (int32 i = 0; i < 1512; i++) { if (_vm->isGameFlagSet((GameFlag)i) == type) { DebugPrintf("%04d: %d ", i, _vm->isGameFlagSet((GameFlag)i)); ++count; } if ((count + 1) % 10 == 0) DebugPrintf("\n"); } DebugPrintf("\n\n%s flags: %d\n", (type ? "Set" : "Unset"), count); } return true; } bool Console::cmdShowObject(int32 argc, const char **argv) { if (argc != 3) { DebugPrintf("Syntax: %s [id|idx] \n", argv[0]); return true; } if (Common::String(argv[1]) == "id") { int id = atoi(argv[2]); for (uint32 i = 0; i < getWorld()->objects.size(); i++) { if (getWorld()->objects[i]->getId() == id) { DebugPrintf("%s", getWorld()->objects[i]->toString(false).c_str()); return true; } } DebugPrintf("No object with id %d found\n", id); } else if (Common::String(argv[1]) == "idx") { int index = atoi(argv[2]); int maxIndex = getWorld()->objects.size() - 1; if (index < 0 || index > maxIndex) { DebugPrintf("[error] index should be between 0 and %d\n", maxIndex); return true; } DebugPrintf("%s", getWorld()->objects[index]->toString(false).c_str()); } else { DebugPrintf("[error] valid options are 'id' and 'idx'\n"); } return true; } bool Console::cmdListObjects(int32 argc, const char **argv) { if (argc != 2) { DebugPrintf("Syntax: %s [onscreen|*]\n", argv[0]); return true; } if (argc == 2) { if (Common::String(argv[1]) == "onscreen") { for (uint32 i = 0; i < getWorld()->objects.size(); i++) { if (getWorld()->objects[i]->isOnScreen()) { DebugPrintf("%s", getWorld()->objects[i]->toString().c_str()); } } } else if (Common::String(argv[1]) == "*"){ for (uint32 i = 0; i < getWorld()->objects.size(); i++) DebugPrintf("%s", getWorld()->objects[i]->toString().c_str()); } else { DebugPrintf("[error] valid options are 'onscreen' and '*'\n"); } } return true; } ////////////////////////////////////////////////////////////////////////// // Video / Scene / Script commands ////////////////////////////////////////////////////////////////////////// bool Console::cmdPlayVideo(int32 argc, const char **argv) { if (argc != 2) { DebugPrintf("Syntax: %s