diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index d9e548d89..fd6e07daf 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -142,3 +142,4 @@ DFHACK_PLUGIN(notes notes.cpp) DFHACK_PLUGIN(mode mode.cpp) #DFHACK_PLUGIN(tiles tiles.cpp) DFHACK_PLUGIN(liquids liquids.cpp) +DFHACK_PLUGIN(tubefill tubefill.cpp) diff --git a/tools/supported/dftubefill.cpp b/plugins/tubefill.cpp similarity index 67% rename from tools/supported/dftubefill.cpp rename to plugins/tubefill.cpp index 2e52d6801..ac58327ef 100644 --- a/tools/supported/dftubefill.cpp +++ b/plugins/tubefill.cpp @@ -1,20 +1,41 @@ // Adamantine tube filler. It fills the hollow ones. +#include #include -#include #include -#include -#include -#include -using namespace std; +#include +#include +#include +#include +#include +#include +#include +#include +#include +using MapExtras::MapCache; +using namespace DFHack; + +DFhackCExport command_result tubefill(DFHack::Core * c, std::vector & params); + +DFhackCExport const char * plugin_name ( void ) +{ + return "tubefill"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("tubefill","Fill in all the adamantine tubes again.",tubefill)); + return CR_OK; +} -#include -#include -#include +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} -int main (void) +DFhackCExport command_result tubefill(DFHack::Core * c, std::vector & params) { - bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::designations40d designations; DFHack::tiletypes40d tiles; @@ -24,39 +45,23 @@ int main (void) int dirty=0; - DFHack::ContextManager DFMgr("Memory.xml"); - DFHack::Context *DF = DFMgr.getSingleContext(); - - //Init - try - { - DF->Attach(); - } - catch (exception& e) - { - cerr << e.what() << endl; - if(temporary_terminal) - cin.ignore(); - return 1; - } - DFHack::Maps *Mapz = DF->getMaps(); + c->Suspend(); + DFHack::Maps *Mapz = c->getMaps(); // init the map if (!Mapz->Start()) { - cerr << "Can't init map." << endl; - if(temporary_terminal) - cin.ignore(); - return 1; + c->con.printerr("Can't init map.\n"); + c->Resume(); + return CR_FAILURE; } Mapz->getSize(x_max,y_max,z_max); if(!Mapz->StartFeatures()) { - cerr << "Can't get features." << endl; - if(temporary_terminal) - cin.ignore(); - return 1; + c->con.printerr("Can't get map features.\n"); + c->Resume(); + return CR_FAILURE; } // walk the map @@ -109,12 +114,7 @@ int main (void) } } } - DF->Detach(); - cout << "Found and changed " << count << " tiles." << endl; - if(temporary_terminal) - { - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - } - return 0; + c->Resume(); + c->con.print("Found and changed %d tiles.\n", count); + return CR_OK; }