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/World.h"
#include <stdio.h>
#include <iomanip>
using namespace DFHack;
void cheap_tokenise(string const& input, vector<string> &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 == "" )
{

@ -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;
}

@ -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 <PluginCommand> commands;
std::string filename;

@ -18,6 +18,9 @@ using namespace std;
#include <dfhack/extra/termutil.h>
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/PluginManager.h>
using namespace DFHack;
typedef std::map<int16_t, unsigned int> MatMap;
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::map<DFHack::DFCoord, FeatureListPointer> FeatureMap;
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 >
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;
}
DFhackCExport command_result prospector (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "prospector";
}
DFhackCExport int plugin_run (DFHack::Core * c)
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
bool showHidden = true;
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 = false;
bool showPlants = true;
bool showSlade = true;
bool showTemple = true;
/*
if (!parseOptions(argc, argv, showHidden, showPlants, showSlade, showTemple))
if(parameters.size() && parameters[0] == "all")
{
return -1;
showHidden = true;
}
*/
uint32_t x_max = 0, y_max = 0, z_max = 0;
c->Suspend();
DFHack::Maps *maps = c->getMaps();
@ -128,7 +100,7 @@ DFhackCExport int plugin_run (DFHack::Core * c)
{
dfout << "Cannot get map info!" << std::endl;
c->Resume();
return 1;
return CR_FAILURE;
}
maps->getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps);
@ -138,7 +110,7 @@ DFhackCExport int plugin_run (DFHack::Core * c)
{
dfout << "Unable to read inorganic material definitons!" << std::endl;
c->Resume();
return 1;
return CR_FAILURE;
}
if (showPlants && !mats->ReadOrganicMaterials())
{
@ -378,5 +350,5 @@ DFhackCExport int plugin_run (DFHack::Core * c)
maps->Finish();
c->Resume();
dfout << std::endl;
return 0;
return CR_OK;
}