/* 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 "common/debug-channels.h" #include "asylum/console.h" #include "asylum/puzzles/puzzles.h" #include "asylum/resources/actor.h" #include "asylum/resources/encounters.h" #include "asylum/resources/inventory.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/system/text.h" #include "asylum/views/scene.h" #include "asylum/views/video.h" #include "asylum/asylum.h" #include "asylum/respack.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}, {73, kObjectNone, kObjectNone, 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} } }; static const int32 itemIndices[][16] = { {61, 69}, {107, 134, 104, 113, 110, 112, 117, 109, 108, 111, 106}, {170, 182, 181, 172, 171, 169}, {61, 64, 66, 67, 68, 69, 70, 78, 77}, {197}, {59, 81, 60, 84, 88, 54, 74, 139, 97, 121}, {239, 234, 249, 250, 251, 263, 237, 253}, {58, 59, 60, 111, 75, 76, 77, 78}, {284, 285, 286, 329, 330, 331, 332, 322, 465}, {91, 92, 93, 94, 95}, {69, 70, 78} }; Console::Console(AsylumEngine *engine) : _vm(engine) { // Commands registerCmd("help", WRAP_METHOD(Console, cmdHelp)); registerCmd("ls", WRAP_METHOD(Console, cmdListFiles)); registerCmd("action", WRAP_METHOD(Console, cmdShowAction)); registerCmd("actions", WRAP_METHOD(Console, cmdListActions)); registerCmd("actors", WRAP_METHOD(Console, cmdListActors)); registerCmd("flags", WRAP_METHOD(Console, cmdListFlags)); registerCmd("object", WRAP_METHOD(Console, cmdShowObject)); registerCmd("objects", WRAP_METHOD(Console, cmdListObjects)); registerCmd("world", WRAP_METHOD(Console, cmdShowWorldStats)); registerCmd("video", WRAP_METHOD(Console, cmdPlayVideo)); registerCmd("script", WRAP_METHOD(Console, cmdRunScript)); registerCmd("show_script", WRAP_METHOD(Console, cmdShowScript)); registerCmd("kill_script", WRAP_METHOD(Console, cmdKillScript)); registerCmd("scene", WRAP_METHOD(Console, cmdChangeScene)); registerCmd("puzzle", WRAP_METHOD(Console, cmdRunPuzzle)); registerCmd("get_status", WRAP_METHOD(Console, cmdGetStatus)); registerCmd("set_status", WRAP_METHOD(Console, cmdSetStatus)); registerCmd("encounter", WRAP_METHOD(Console, cmdRunEncounter)); registerCmd("show_enc", WRAP_METHOD(Console, cmdShowEncounter)); registerCmd("items", WRAP_METHOD(Console, cmdListItems)); registerCmd("grab", WRAP_METHOD(Console, cmdAddToInventory)); registerCmd("throw", WRAP_METHOD(Console, cmdRemoveFromInventory)); registerCmd("palette", WRAP_METHOD(Console, cmdSetPalette)); registerCmd("draw", WRAP_METHOD(Console, cmdDrawResource)); registerCmd("toggle_flag", WRAP_METHOD(Console, cmdToggleFlag)); // Variables registerVar("show_actors", &g_debugActors); registerVar("show_drawrects", &g_debugDrawRects); registerVar("show_objects", &g_debugObjects); registerVar("show_polygons", &g_debugPolygons); registerVar("show_scenerects", &g_debugSceneRects); registerVar("use_scrolling", &g_debugScrolling); } Console::~Console() { } ////////////////////////////////////////////////////////////////////////// // 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("\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 - Scroll scene using the mouse\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(" actions - list actions 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(" show_script - show script commands\n"); debugPrintf(" kill_script - terminate a script\n"); debugPrintf(" puzzle - run an puzzle\n"); debugPrintf("\n"); debugPrintf(" get_status - get actor's status\n"); debugPrintf(" set_status - set actor's status\n"); debugPrintf("\n"); debugPrintf(" encounter - run an encounter\n"); debugPrintf(" show_enc - show encounter commands\n"); debugPrintf("\n"); debugPrintf(" items - list all grabbable objects\n"); debugPrintf(" grab - add an item to inventory\n"); debugPrintf(" throw - remove an item from inventory\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(int 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(int 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) { Actor *player = getScene()->getActor(); for (uint32 i = 0; i < getWorld()->actors.size(); i++) { Actor *actor = getWorld()->actors[i]; debugPrintf("%c", actor == player ? '*' : ' '); debugPrintf("%s\n", actor->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(int 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(int, const char **) { debugPrintf("WorldStats\n"); debugPrintf("----------\n"); debugPrintf("%s", getWorld()->toString().c_str()); return true; } bool Console::cmdShowObject(int 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::cmdShowAction(int 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()->actions.size(); i++) { if (getWorld()->actions[i]->id == id) { debugPrintf("%s", getWorld()->actions[i]->toString().c_str()); return true; } } debugPrintf("No action with id %d found\n", id); } else if (Common::String(argv[1]) == "idx") { int index = atoi(argv[2]); 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", getWorld()->actions[index]->toString().c_str()); } else { debugPrintf("[error] valid options are 'id' and 'idx'\n"); } return true; } bool Console::cmdListObjects(int 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(int argc, const char **argv) { if (argc != 2) { debugPrintf("Syntax: %s