From b1d41630952a856f73dc2beb33f96f9246a356fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 27 Jun 2011 04:49:56 +0200 Subject: [PATCH] Fixed prospector, added the command list back, removed the plugin init console spam. --- library/Core.cpp | 15 ++++- library/PluginManager.cpp | 6 +- library/include/dfhack/PluginManager.h | 10 +++- plugins/prospector.cpp | 76 ++++++++------------------ 4 files changed, 49 insertions(+), 58 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index e4e18d1e3..83c818db0 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -47,6 +47,7 @@ using namespace std; #include "dfhack/modules/Maps.h" #include "dfhack/modules/World.h" #include +#include using namespace DFHack; void cheap_tokenise(string const& input, vector &output) @@ -86,7 +87,19 @@ int fIOthread(void * iodata) } if(command=="help" || command == "?") { - dfout << "Available commands:" << endl; + dfout << "Available commands" << endl; + dfout << "------------------" << endl; + for(int i = 0; i < plug_mgr->size();i++) + { + const Plugin * plug = (plug_mgr->operator[](i)); + dfout << "Plugin " << plug->getName() << " :" << std::endl; + for (int j = 0; j < plug->size();j++) + { + const PluginCommand & pcmd = (plug->operator[](j)); + dfout << setw(12) << pcmd.name << "| " << pcmd.description << endl; + } + dfout << endl; + } } else if( command == "" ) { diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index bde021ba5..85d48a564 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -104,13 +104,15 @@ Plugin::Plugin(Core * core, const std::string & file) name = _PlugName(); plugin_lib = plug; loaded = true; - dfout << "Found plugin " << name << endl; + //dfout << "Found plugin " << name << endl; if(plugin_init(core,commands) == CR_OK) { + /* for(int i = 0; i < commands.size();i++) { dfout << commands[i].name << " : " << commands[i].description << std::endl; } + */ } else { @@ -127,7 +129,7 @@ Plugin::~Plugin() } } -bool Plugin::isLoaded() +bool Plugin::isLoaded() const { return loaded; } diff --git a/library/include/dfhack/PluginManager.h b/library/include/dfhack/PluginManager.h index ad87382d7..398c62e2f 100644 --- a/library/include/dfhack/PluginManager.h +++ b/library/include/dfhack/PluginManager.h @@ -66,15 +66,19 @@ namespace DFHack public: Plugin(DFHack::Core* core, const std::string& file); ~Plugin(); - bool isLoaded (); - const PluginCommand& operator[] (std::size_t index) + bool isLoaded () const; + const PluginCommand& operator[] (std::size_t index) const { return commands[index]; }; - std::size_t size() + std::size_t size() const { return commands.size(); } + const std::string & getName() const + { + return name; + } private: std::vector commands; std::string filename; diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index aaef2f96e..c2c4d614b 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -18,6 +18,9 @@ using namespace std; #include #include #include +#include + +using namespace DFHack; typedef std::map MatMap; typedef std::vector< pair > MatSorter; @@ -26,49 +29,7 @@ typedef std::vector FeatureList; typedef std::vector FeatureListPointer; typedef std::map FeatureMap; typedef std::vector PlantList; -/* -bool parseOptions(int argc, char **argv, bool &showHidden, bool &showPlants, - bool &showSlade, bool &showTemple) -{ - char c; - xgetopt opt(argc, argv, "apst"); - opt.opterr = 0; - while ((c = opt()) != -1) - { - switch (c) - { - case 'a': - showHidden = true; - break; - case 'p': - showPlants = false; - break; - case 's': - showSlade = false; - break; - case 't': - showTemple = false; - break; - case '?': - switch (opt.optopt) - { - // For when we take arguments - default: - if (isprint(opt.optopt)) - std::cerr << "Unknown option -" << opt.optopt << "!" - << std::endl; - else - std::cerr << "Unknown option character " << (int) opt.optopt << "!" - << std::endl; - } - default: - // Um..... - return false; - } - } - return true; -} -*/ + template