From 873cbd8388ac2f2741d8aed7db515fb5699d0c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 20 Jul 2011 20:58:19 +0200 Subject: [PATCH] Make 'die' plugin a builtin, made the console interaction less confusing. --- library/Core.cpp | 83 ++++++++++++++++++++++----------------- library/PluginManager.cpp | 4 +- library/modules/Maps.cpp | 5 +-- plugins/CMakeLists.txt | 5 --- plugins/die.cpp | 47 ---------------------- 5 files changed, 51 insertions(+), 93 deletions(-) delete mode 100644 plugins/die.cpp diff --git a/library/Core.cpp b/library/Core.cpp index ff63a98ea..d3dcb1038 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -130,7 +130,8 @@ int fIOthread(void * iodata) con.printerr("Something horrible happened in Core's constructor...\n"); return 0; } - con.print("DFHack is ready. Have a nice day! Type in '?' or 'help' for help.\n"); + con.print("DFHack is ready. Have a nice day!\n" + "Type in '?' or 'help' for general help, 'ls' to see all commands.\n"); int clueless_counter = 0; while (true) { @@ -171,17 +172,18 @@ int fIOthread(void * iodata) "The console also has a command history - you can navigate it with Up and Down keys.\n" "On Windows, you may have to resize your console window. The appropriate menu is accessible\n" "by clicking on the program icon in the top bar of the window.\n\n" - "Available basic commands:\n" - " help|? [plugin] - This text or help specific to a plugin.\n" - " load plugin|all - Load a plugin by name or load all possible plugins.\n" - " unload plugin|all - Unload a plugin or all loaded plugins.\n" - " reload plugin|all - Reload a plugin or all loaded plugins.\n" - " listp - List plugins with their status.\n" - " listc [plugin] - List commands. Optionally of a single plugin.\n" - " lista - List all commands, sorted by plugin (verbose).\n" - " fpause - Force DF to pause without syncing.\n" + "Basic commands:\n" + " help|? - This text.\n" + " ls|dir [PLUGIN] - List available commands. Optionally for single plugin.\n" + " cls - Clear the console.\n" + " fpause - Force DF to pause.\n" " die - Force DF to close immediately\n" - " cls - Clear the console scrollback.\n" + "Plugin management (useful for developers):\n" + //" belongs COMMAND - Tell which plugin a command belongs to.\n" + " plug [PLUGIN|v] - List plugin state and description.\n" + " load PLUGIN|all - Load a plugin by name or load all possible plugins.\n" + " unload PLUGIN|all - Unload a plugin or all loaded plugins.\n" + " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" ); } else @@ -252,15 +254,7 @@ int fIOthread(void * iodata) } } } - else if(first == "listp") - { - for(int i = 0; i < plug_mgr->size();i++) - { - const Plugin * plug = (plug_mgr->operator[](i)); - con.print("%s\n", plug->getName().c_str()); - } - } - else if(first == "listc") + else if(first == "ls" || first == "dir") { if(parts.size()) { @@ -273,36 +267,47 @@ int fIOthread(void * iodata) else for (int j = 0; j < plug->size();j++) { const PluginCommand & pcmd = (plug->operator[](j)); - con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + con.print(" %-22s - %s\n",pcmd.name.c_str(), pcmd.description.c_str()); } } - else for(int i = 0; i < plug_mgr->size();i++) + else { - const Plugin * plug = (plug_mgr->operator[](i)); - if(!plug->size()) - continue; - for (int j = 0; j < plug->size();j++) + con.print( + "builtin:\n" + " help|? - This text or help specific to a plugin.\n" + " ls [PLUGIN] - List available commands. Optionally for single plugin.\n" + " cls - Clear the console.\n" + " fpause - Force DF to pause.\n" + " die - Force DF to close immediately\n" + " belongs COMMAND - Tell which plugin a command belongs to.\n" + " plug [PLUGIN|v] - List plugin state and detailed description.\n" + " load PLUGIN|all - Load a plugin by name or load all possible plugins.\n" + " unload PLUGIN|all - Unload a plugin or all loaded plugins.\n" + " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" + "\n" + "plugins:\n" + ); + for(int i = 0; i < plug_mgr->size();i++) { - const PluginCommand & pcmd = (plug->operator[](j)); - con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + const Plugin * plug = (plug_mgr->operator[](i)); + if(!plug->size()) + continue; + for (int j = 0; j < plug->size();j++) + { + const PluginCommand & pcmd = (plug->operator[](j)); + con.print(" %-22s- %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + } } } } - else if(first == "lista") + else if(first == "plug") { for(int i = 0; i < plug_mgr->size();i++) { const Plugin * plug = (plug_mgr->operator[](i)); if(!plug->size()) continue; - con.print("%s :\n", plug->getName().c_str()); - for (int j = 0; j < plug->size();j++) - { - const PluginCommand & pcmd = (plug->operator[](j)); - con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str()); - //con << setw(12) << pcmd.name << "| " << pcmd.description << endl; - } - //con.print("\n"); + con.print("%s\n", plug->getName().c_str()); } } else if(first == "fpause") @@ -315,6 +320,10 @@ int fIOthread(void * iodata) { con.clear(); } + else if(first == "die") + { + _exit(666); + } else { vector parts; diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 4caff02ea..99a01ea25 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -196,7 +196,7 @@ bool Plugin::load() plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate"); plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown"); - name = _PlugName(); + //name = _PlugName(); plugin_lib = plug; if(plugin_init(&c,commands) == CR_OK) { @@ -322,6 +322,8 @@ PluginManager::PluginManager(Core * core) { Plugin * p = new Plugin(core, path + filez[i], filez[i], this); all_plugins.push_back(p); + // make all plugins load by default (until a proper design emerges). + p->load(); } } } diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 55c5b35b8..362ccc043 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -234,9 +234,8 @@ bool Maps::Start() if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0) { cerr << hex << &mx << " " << &my << " " << &mz << endl; - cout << dec << mx << " "<< my << " "<< mz << endl; - // FIXME: this should be avoided! - throw Error::BadMapDimensions(mx, my); + cerr << dec << mx << " "<< my << " "<< mz << endl; + return false; } d->Started = true; diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 917ddcb9c..477dd57ea 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -108,11 +108,6 @@ if(BUILD_KITTENS) endif() IF(UNIX) - OPTION(BUILD_KILL_GAME "Build the kill game plugin." OFF) - if(BUILD_KILL_GAME) - DFHACK_PLUGIN(die die.cpp) - endif() - OPTION(BUILD_VECTORS "Build the vectors search plugin." OFF) if(BUILD_VECTORS) DFHACK_PLUGIN(vectors vectors.cpp) diff --git a/plugins/die.cpp b/plugins/die.cpp deleted file mode 100644 index 74e1186cd..000000000 --- a/plugins/die.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Since you can't do "Ctrl-Z kill -9 %1" from the console, instead just -// give the "die" command to terminate the game without saving. -// Linux only, since _exit() probably doesn't work on Windows. -// -// Need to set cmake option BUILD_KILL_GAME to ON to compile this -// plugin. - -#ifndef LINUX_BUILD - #error "This plugin only compiles on Linux" -#endif - -#include -#include -#include -#include -#include - -using std::vector; -using std::string; -using namespace DFHack; - -DFhackCExport command_result df_die (Core * c, vector & parameters); - -DFhackCExport const char * plugin_name ( void ) -{ - return "die"; -} - -DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) -{ - commands.clear(); - commands.push_back(PluginCommand("die", - "Kill game without saving", df_die)); - return CR_OK; -} - -DFhackCExport command_result plugin_shutdown ( Core * c ) -{ - return CR_OK; -} - -DFhackCExport command_result df_die (Core * c, vector & parameters) -{ - _exit(0); - - return CR_OK; -}