/* 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. * */ #include "asylum/console.h" #include "asylum/puzzles/puzzles.h" #include "asylum/resources/actor.h" #include "asylum/resources/encounters.h" #include "asylum/resources/object.h" #include "asylum/resources/script.h" #include "asylum/resources/worldstats.h" #include "asylum/system/cursor.h" #include "asylum/system/graphics.h" #include "asylum/system/screen.h" #include "asylum/views/scene.h" #include "asylum/views/video.h" #include "asylum/asylum.h" #include "asylum/respack.h" #include "common/debug-channels.h" namespace Asylum { extern int g_debugActors; extern int g_debugDrawRects; extern int g_debugObjects; extern int g_debugPolygons; extern int g_debugSceneRects; extern int g_debugScrolling; const ResourcePackId puzzleToScenes[17] = { kResourcePackTowerCells, // VCR kResourcePackCourtyardAndChapel, // Pipes kResourcePackInnocentAbandoned, // TicTacToe kResourcePackInnocentAbandoned, // Lock kResourcePackInvalid, // Puzzle 5 has no event handler kResourcePackLaboratory, // Wheel kResourcePackLaboratory, // Board Salvation kResourcePackLaboratory, // Board Youth kResourcePackLaboratory, // Board Key Hides To kResourcePackMorgueAndCemetery, // Writings kResourcePackInvalid, // ?? (11) kResourcePackMorgueAndCemetery, // Morgue Door kResourcePackMansion, // Clock kResourcePackMorgueAndCemetery, // Time Machine kResourcePackLostVillage, // Fisherman kResourcePackHive, // Hive Machine kResourcePackHive // Hive Control }; static const struct EncounterData { int32 index; uint32 objectId1; uint32 objectId2; ActorIndex actorIndex; } encounterData[13][20] = { // TowerCells { { 0, kObjectPreAlphaNut, kObjectPreAlphaNut, kActorMax}, { 1, kObjectPreAlphaNut2, kObjectPreAlphaNut2, kActorMax}, { 2, kObjectRocker, kObjectRocker, kActorMax}, {-1, kObjectNone, kObjectNone, kActorMax} }, // InnocentAbandoned { { 3, 1072, 1091, kActorMax}, { 4, 1061, 1072, kActorMax}, { 5, 1200, 1199, kActorMax}, { 7, 1105, 991, kActorMax}, { 9, 1012, 1011, kActorMax}, {10, 993, 993, kActorMax}, {11, 1013, 1013, kActorMax}, {12, 1082, 1084, kActorMax}, {13, 1001, 1001, kActorMax}, {14, 1587, 2280, kActorMax}, {74, 2992, 2992, kActorMax}, {76, 2990, 2990, kActorMax}, {77, 2990, 2990, kActorMax}, {78, 2990, 2990, kActorMax}, {-1, kObjectNone, kObjectNone, kActorMax} }, // CourtyardAndChapel { {36, 820, 820, kActorMax}, {37, 863, 863, kActorMax}, {38, 862, 1038, kActorMax}, {39, 844, 844, kActorMax}, {40, 845, 845, kActorMax}, {41, 846, 846, kActorMax}, {43, 873, 801, kActorMax}, {-1, kObjectNone, kObjectNone, kActorMax} }, // CircusOfFools { {-1, kObjectNone, kObjectNone, kActorMax} }, // Laboratory { {-1, kObjectNone, kObjectNone, kActorMax} }, // Hive { {-1, kObjectNone, kObjectNone, kActorMax} }, // MorgueAndCemetery { {-1, kObjectNone, kObjectNone, kActorMax} }, // LostVillage { {-1, kObjectNone, kObjectNone, kActorMax} }, // Gauntlet { {-1, kObjectNone, kObjectNone, kActorMax} }, // Mansion { {-1, kObjectNone, kObjectNone, kActorMax} }, // Cave { {-1, kObjectNone, kObjectNone, kActorMax} }, // Maze { {-1, kObjectNone, kObjectNone, kActorMax} }, // MorgansLastGame { {-1, kObjectNone, kObjectNone, kActorMax} } }; 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("world", WRAP_METHOD(Console, cmdShowWorldStats)); DCmd_Register("video", WRAP_METHOD(Console, cmdPlayVideo)); DCmd_Register("script", WRAP_METHOD(Console, cmdRunScript)); DCmd_Register("scene", WRAP_METHOD(Console, cmdChangeScene)); DCmd_Register("encounter", WRAP_METHOD(Console, cmdRunEncounter)); DCmd_Register("puzzle", WRAP_METHOD(Console, cmdRunPuzzle)); DCmd_Register("palette", WRAP_METHOD(Console, cmdSetPalette)); DCmd_Register("draw", WRAP_METHOD(Console, cmdDrawResource)); DCmd_Register("toggle_flag", WRAP_METHOD(Console, cmdToggleFlag)); // Variables DVar_Register("show_actors", &g_debugActors, DVAR_INT, 0); DVar_Register("show_drawrects", &g_debugDrawRects, DVAR_INT, 0); DVar_Register("show_objects", &g_debugObjects, DVAR_INT, 0); DVar_Register("show_polygons", &g_debugPolygons, DVAR_INT, 0); DVar_Register("show_scenerects", &g_debugSceneRects, 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_actors - Show actors\n"); DebugPrintf(" show_objects - Show objects\n"); DebugPrintf(" show_polygons - Show polygons\n"); DebugPrintf(" show_drawrects - Show drawing rects\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(" actions - show action information\n"); DebugPrintf(" flags - show flags\n"); DebugPrintf(" object - inspect a particular object\n"); DebugPrintf(" objects - show objects information\n"); DebugPrintf(" world - show worldstats\n"); DebugPrintf("\n"); DebugPrintf(" video - play a video\n"); DebugPrintf(" script - run a script\n"); DebugPrintf(" scene - change the scene\n"); DebugPrintf(" encounter - run an encounter\n"); DebugPrintf(" puzzle - run an puzzle\n"); DebugPrintf("\n"); DebugPrintf(" palette - set the screen palette\n"); DebugPrintf(" draw - draw a resource\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 (maxIndex == -1) { DebugPrintf("[error] No actions are present!\n"); return true; } 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 && argc != 4) { 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 if (argc == 2 || argc == 4) { 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; } if (argc == 2) { DebugPrintf("%s\n", getWorld()->actors[index]->toString(false).c_str()); return true; } // Adjust actor coordinates int16 x = (int16)atoi(argv[2]); int16 y = (int16)atoi(argv[3]); // TODO add error handling *getWorld()->actors[index]->getPoint1() = Common::Point(x, y); } 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 { int32 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) == (bool)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::cmdShowWorldStats(int32, const char **) { DebugPrintf("WorldStats\n"); DebugPrintf("----------\n"); DebugPrintf("%s", getWorld()->toString().c_str()); 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()); } } DebugPrintf("Total: %d\n", getWorld()->objects.size()); } else if (Common::String(argv[1]) == "*"){ for (uint32 i = 0; i < getWorld()->objects.size(); i++) DebugPrintf("%s", getWorld()->objects[i]->toString().c_str()); DebugPrintf("Total: %d\n", getWorld()->objects.size()); } 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