Fixed prospector, added the command list back, removed the plugin init console spam.

develop
Petr Mrázek 2011-06-27 04:49:56 +02:00
parent 00ddb45dbd
commit b1d4163095
4 changed files with 49 additions and 58 deletions

@ -47,6 +47,7 @@ using namespace std;
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
#include <stdio.h> #include <stdio.h>
#include <iomanip>
using namespace DFHack; using namespace DFHack;
void cheap_tokenise(string const& input, vector<string> &output) void cheap_tokenise(string const& input, vector<string> &output)
@ -86,7 +87,19 @@ int fIOthread(void * iodata)
} }
if(command=="help" || command == "?") 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 == "" ) else if( command == "" )
{ {

@ -104,13 +104,15 @@ Plugin::Plugin(Core * core, const std::string & file)
name = _PlugName(); name = _PlugName();
plugin_lib = plug; plugin_lib = plug;
loaded = true; loaded = true;
dfout << "Found plugin " << name << endl; //dfout << "Found plugin " << name << endl;
if(plugin_init(core,commands) == CR_OK) if(plugin_init(core,commands) == CR_OK)
{ {
/*
for(int i = 0; i < commands.size();i++) for(int i = 0; i < commands.size();i++)
{ {
dfout << commands[i].name << " : " << commands[i].description << std::endl; dfout << commands[i].name << " : " << commands[i].description << std::endl;
} }
*/
} }
else else
{ {
@ -127,7 +129,7 @@ Plugin::~Plugin()
} }
} }
bool Plugin::isLoaded() bool Plugin::isLoaded() const
{ {
return loaded; return loaded;
} }

@ -66,15 +66,19 @@ namespace DFHack
public: public:
Plugin(DFHack::Core* core, const std::string& file); Plugin(DFHack::Core* core, const std::string& file);
~Plugin(); ~Plugin();
bool isLoaded (); bool isLoaded () const;
const PluginCommand& operator[] (std::size_t index) const PluginCommand& operator[] (std::size_t index) const
{ {
return commands[index]; return commands[index];
}; };
std::size_t size() std::size_t size() const
{ {
return commands.size(); return commands.size();
} }
const std::string & getName() const
{
return name;
}
private: private:
std::vector <PluginCommand> commands; std::vector <PluginCommand> commands;
std::string filename; std::string filename;

@ -18,6 +18,9 @@ using namespace std;
#include <dfhack/extra/termutil.h> #include <dfhack/extra/termutil.h>
#include <dfhack/Core.h> #include <dfhack/Core.h>
#include <dfhack/Console.h> #include <dfhack/Console.h>
#include <dfhack/PluginManager.h>
using namespace DFHack;
typedef std::map<int16_t, unsigned int> MatMap; typedef std::map<int16_t, unsigned int> MatMap;
typedef std::vector< pair<int16_t, unsigned int> > MatSorter; typedef std::vector< pair<int16_t, unsigned int> > MatSorter;
@ -26,49 +29,7 @@ typedef std::vector<DFHack::t_feature> FeatureList;
typedef std::vector<DFHack::t_feature*> FeatureListPointer; typedef std::vector<DFHack::t_feature*> FeatureListPointer;
typedef std::map<DFHack::DFCoord, FeatureListPointer> FeatureMap; typedef std::map<DFHack::DFCoord, FeatureListPointer> FeatureMap;
typedef std::vector<DFHack::df_plant *> PlantList; typedef std::vector<DFHack::df_plant *> 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<template <typename> class P = std::greater > template<template <typename> class P = std::greater >
struct compare_pair_second struct compare_pair_second
{ {
@ -103,24 +64,35 @@ void printMats(MatMap &mat, std::vector<DFHack::t_matgloss> &materials)
dfout << ">>> TOTAL = " << total << std::endl << std::endl; dfout << ">>> TOTAL = " << total << std::endl << std::endl;
} }
DFhackCExport command_result prospector (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
{ {
return "prospector"; return "prospector";
} }
DFhackCExport int plugin_run (DFHack::Core * c) DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("prospector","Show stats of available raw resources. Use parameter 'all' to show hidden resources.",prospector));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & parameters)
{ {
bool showHidden = true; bool showHidden = false;
bool showPlants = true; bool showPlants = true;
bool showSlade = true; bool showSlade = true;
bool showTemple = true; bool showTemple = true;
/* if(parameters.size() && parameters[0] == "all")
if (!parseOptions(argc, argv, showHidden, showPlants, showSlade, showTemple))
{ {
return -1; showHidden = true;
} }
*/
uint32_t x_max = 0, y_max = 0, z_max = 0; uint32_t x_max = 0, y_max = 0, z_max = 0;
c->Suspend(); c->Suspend();
DFHack::Maps *maps = c->getMaps(); DFHack::Maps *maps = c->getMaps();
@ -128,7 +100,7 @@ DFhackCExport int plugin_run (DFHack::Core * c)
{ {
dfout << "Cannot get map info!" << std::endl; dfout << "Cannot get map info!" << std::endl;
c->Resume(); c->Resume();
return 1; return CR_FAILURE;
} }
maps->getSize(x_max, y_max, z_max); maps->getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps); MapExtras::MapCache map(maps);
@ -138,7 +110,7 @@ DFhackCExport int plugin_run (DFHack::Core * c)
{ {
dfout << "Unable to read inorganic material definitons!" << std::endl; dfout << "Unable to read inorganic material definitons!" << std::endl;
c->Resume(); c->Resume();
return 1; return CR_FAILURE;
} }
if (showPlants && !mats->ReadOrganicMaterials()) if (showPlants && !mats->ReadOrganicMaterials())
{ {
@ -378,5 +350,5 @@ DFhackCExport int plugin_run (DFHack::Core * c)
maps->Finish(); maps->Finish();
c->Resume(); c->Resume();
dfout << std::endl; dfout << std::endl;
return 0; return CR_OK;
} }