Ported flows tool.

develop
Petr Mrázek 2011-08-09 02:07:29 +02:00
parent cc19180ac0
commit f54e5ef4f1
2 changed files with 49 additions and 36 deletions

@ -134,3 +134,4 @@ DFHACK_PLUGIN(tubefill tubefill.cpp)
DFHACK_PLUGIN(autodump autodump.cpp) DFHACK_PLUGIN(autodump autodump.cpp)
DFHACK_PLUGIN(cleanowned cleanowned.cpp) DFHACK_PLUGIN(cleanowned cleanowned.cpp)
DFHACK_PLUGIN(deramp deramp.cpp) DFHACK_PLUGIN(deramp deramp.cpp)
DFHACK_PLUGIN(flows flows.cpp)

@ -2,52 +2,65 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <map>
#include <stddef.h>
#include <string.h>
using namespace std; using namespace std;
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
using namespace DFHack;
#include <DFHack.h> DFhackCExport command_result df_flows (Core * c, vector <string> & parameters);
#include <dfhack/extra/termutil.h>
int main (void) DFhackCExport const char * plugin_name ( void )
{
return "flows";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &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 <string> & parameters)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
DFHack::Maps *Maps; DFHack::Maps *Maps;
try
{ c->Suspend();
DF = DFMgr.getSingleContext();
DF->Attach();
Maps = DF->getMaps();
}
catch (exception& e)
{
cerr << e.what() << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
// init the map // init the map
if(!Maps->Start()) if(!Maps->Start())
{ {
cerr << "Can't init map." << endl; c->con.printerr("Can't init map.\n");
if(temporary_terminal) c->Resume();
cin.ignore(); return CR_FAILURE;
return 1;
} }
DFHack::t_blockflags bflags; DFHack::t_blockflags bflags;
Maps->getSize(x_max,y_max,z_max); Maps->getSize(x_max,y_max,z_max);
// walk the map, count flowing tiles, magma, water // walk the map, count flowing tiles, magma, water
uint32_t flow1=0, flow2=0, flowboth=0, water=0, magma=0; 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 x = 0; x< x_max;x++)
{ {
for(uint32_t y = 0; y< y_max;y++) for(uint32_t y = 0; y< y_max;y++)
{ {
for(uint32_t z = 0; z< z_max;z++) 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->ReadBlockFlags(x, y, z, bflags);
Maps->ReadDesignations(x, y, z, &designations); Maps->ReadDesignations(x, y, z, &designations);
@ -68,14 +81,13 @@ int main (void)
} }
} }
} }
cout << "Blocks with liquid_1=true: " << flow1 << endl; c->con.print("Blocks with liquid_1=true: %d\n"
cout << "Blocks with liquid_2=true: " << flow2 << endl; "Blocks with liquid_2=true: %d\n"
cout << "Blocks with both: " << flowboth << endl; "Blocks with both: %d\n"
cout << "Water tiles: " << water << endl; "Water tiles: %d\n"
cout << "Magma tiles: " << magma << endl; "Magma tiles: %d\n"
,flow1, flow2, flowboth, water, magma
cout << endl << "Done." << endl; );
if(temporary_terminal) c->Resume();
cin.ignore(); return CR_OK;
return 0;
} }