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(cleanowned cleanowned.cpp)
DFHACK_PLUGIN(deramp deramp.cpp)
DFHACK_PLUGIN(flows flows.cpp)

@ -2,52 +2,65 @@
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <string.h>
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>
#include <dfhack/extra/termutil.h>
int main (void)
DFhackCExport command_result df_flows (Core * c, vector <string> & parameters);
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;
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;
}