dfhack/plugins/flows.cpp

94 lines
2.8 KiB
C++

2010-05-25 19:22:17 -06:00
// This tool counts static tiles and active flows of water and magma.
2010-05-03 20:47:06 -06:00
#include <iostream>
#include <vector>
2011-08-08 18:07:29 -06:00
#include <map>
#include <stddef.h>
#include <string.h>
2010-05-03 20:47:06 -06:00
using namespace std;
2011-12-31 04:48:42 -07:00
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <modules/Maps.h>
2011-08-08 18:07:29 -06:00
using namespace DFHack;
2010-05-03 20:47:06 -06:00
2011-08-08 18:07:29 -06:00
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",
"Counts map blocks with flowing liquids.",
2011-08-08 18:07:29 -06:00
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)
2010-05-03 20:47:06 -06:00
{
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
2010-05-23 15:06:10 -06:00
DFHack::Maps *Maps;
2011-08-08 18:07:29 -06:00
c->Suspend();
Maps = c->getMaps();
2010-05-03 20:47:06 -06:00
// init the map
if(!Maps->Start())
{
2011-08-08 18:07:29 -06:00
c->con.printerr("Can't init map.\n");
c->Resume();
return CR_FAILURE;
2010-05-03 20:47:06 -06:00
}
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;
2011-08-08 18:07:29 -06:00
c->con.print("Counting flows and liquids ...\n");
2010-05-03 20:47:06 -06:00
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++)
{
2011-08-08 18:07:29 -06:00
if(Maps->getBlock(x,y,z))
2010-05-03 20:47:06 -06:00
{
Maps->ReadBlockFlags(x, y, z, bflags);
Maps->ReadDesignations(x, y, z, &designations);
if (bflags.bits.liquid_1)
flow1++;
if (bflags.bits.liquid_2)
flow2++;
if (bflags.bits.liquid_1 && bflags.bits.liquid_2)
flowboth++;
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
if (designations[i][j].bits.liquid_type == DFHack::liquid_magma)
magma++;
if (designations[i][j].bits.liquid_type == DFHack::liquid_water)
water++;
}
}
}
}
}
2011-08-08 18:07:29 -06:00
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;
2010-05-03 20:47:06 -06:00
}