summaryrefslogtreecommitdiff
path: root/plugins/flows.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2011-08-09 02:07:29 +0200
committerPetr Mrázek2011-08-09 02:07:29 +0200
commitf54e5ef4f1915a21fcfade8c645ab52d41c08fad (patch)
tree55779975bbf8a22a62700b69d67a522897b39527 /plugins/flows.cpp
parentcc19180ac00c767abe164ad275fab6ab4aeb0888 (diff)
downloaddfhack-f54e5ef4f1915a21fcfade8c645ab52d41c08fad.tar.gz
dfhack-f54e5ef4f1915a21fcfade8c645ab52d41c08fad.tar.bz2
dfhack-f54e5ef4f1915a21fcfade8c645ab52d41c08fad.tar.xz
Ported flows tool.
Diffstat (limited to 'plugins/flows.cpp')
-rw-r--r--plugins/flows.cpp84
1 files changed, 48 insertions, 36 deletions
diff --git a/plugins/flows.cpp b/plugins/flows.cpp
index 7368cf6d..7343360e 100644
--- a/plugins/flows.cpp
+++ b/plugins/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;
}