diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4ba24544a..228b82bb4 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -134,3 +134,4 @@ DFHACK_PLUGIN(tubefill tubefill.cpp) DFHACK_PLUGIN(autodump autodump.cpp) DFHACK_PLUGIN(cleanowned cleanowned.cpp) DFHACK_PLUGIN(deramp deramp.cpp) +DFHACK_PLUGIN(flows flows.cpp) diff --git a/plugins/flows.cpp b/plugins/flows.cpp index 7368cf6d6..7343360e0 100644 --- a/plugins/flows.cpp +++ b/plugins/flows.cpp @@ -2,52 +2,65 @@ #include #include +#include +#include +#include using namespace std; +#include +#include +#include +#include +#include +using namespace DFHack; -#include -#include -int main (void) +DFhackCExport command_result df_flows (Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "flows"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("flows", + "De-ramp. All ramps marked for removal are replaced with floors.", + df_flows)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +DFhackCExport command_result df_flows (Core * c, vector & parameters) { - bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::designations40d designations; - - DFHack::ContextManager DFMgr("Memory.xml"); - DFHack::Context * DF; DFHack::Maps *Maps; - try - { - DF = DFMgr.getSingleContext(); - DF->Attach(); - Maps = DF->getMaps(); - } - catch (exception& e) - { - cerr << e.what() << endl; - if(temporary_terminal) - cin.ignore(); - return 1; - } + + c->Suspend(); + // init the map if(!Maps->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; } DFHack::t_blockflags bflags; Maps->getSize(x_max,y_max,z_max); // walk the map, count flowing tiles, magma, water uint32_t flow1=0, flow2=0, flowboth=0, water=0, magma=0; - cout << "Counting flows and liquids ..."; + c->con.print("Counting flows and liquids ...\n"); for(uint32_t x = 0; x< x_max;x++) { for(uint32_t y = 0; y< y_max;y++) { for(uint32_t z = 0; z< z_max;z++) { - if(Maps->isValidBlock(x,y,z)) + if(Maps->getBlock(x,y,z)) { Maps->ReadBlockFlags(x, y, z, bflags); Maps->ReadDesignations(x, y, z, &designations); @@ -68,14 +81,13 @@ int main (void) } } } - cout << "Blocks with liquid_1=true: " << flow1 << endl; - cout << "Blocks with liquid_2=true: " << flow2 << endl; - cout << "Blocks with both: " << flowboth << endl; - cout << "Water tiles: " << water << endl; - cout << "Magma tiles: " << magma << endl; - - cout << endl << "Done." << endl; - if(temporary_terminal) - cin.ignore(); - return 0; + c->con.print("Blocks with liquid_1=true: %d\n" + "Blocks with liquid_2=true: %d\n" + "Blocks with both: %d\n" + "Water tiles: %d\n" + "Magma tiles: %d\n" + ,flow1, flow2, flowboth, water, magma + ); + c->Resume(); + return CR_OK; }