Conflicts:
	plugins/autodump.cpp
	plugins/cleaners.cpp
develop
Petr Mrázek 2012-01-15 19:51:34 +01:00
commit d972b07d57
14 changed files with 165 additions and 242 deletions

@ -43,7 +43,7 @@ namespace DFHack
{
class Core;
class PluginManager;
struct virtual_identity;
class virtual_identity;
enum command_result
{

@ -355,6 +355,7 @@ bool MaterialInfo::matches(const df::dfhack_material_category &cat)
TEST(glass, IS_GLASS);
if (cat.bits.clay && linear_index(material->reaction_product.id, std::string("FIRED_MAT")) >= 0)
return true;
return false;
}
#undef TEST

@ -190,8 +190,6 @@ bool Translation::readName(t_name & name, df_name * source)
bool Translation::copyName(df_name * source, df_name * target)
{
uint8_t buf[28];
if (source == target)
return true;
Core & c = Core::getInstance();

@ -136,7 +136,6 @@ int32_t Units::GetCreatureInBox (int32_t index, df_unit ** furball,
return -1;
Process *p = d->owner;
uint16_t coords[3];
uint32_t size = creatures->size();
while (uint32_t(index) < size)
{
@ -575,7 +574,6 @@ bool Units::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & ite
bool Units::ReadOwnedItemsByPtr(const df_unit * temp, std::vector<int32_t> & items)
{
unsigned int i;
if(!d->Started) return false;
items = temp->owned_items;
return true;

@ -94,8 +94,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
return CR_OK;
}
}
DFHack::occupancies40d * occupancies;
c->Suspend();
DFHack::VersionInfo *mem = c->vinfo;
DFHack::Gui * Gui = c->getGui();
DFHack::Items * Items = c->getItems();

@ -12,10 +12,8 @@
#include "df/unit.h"
#include "df/matter_state.h"
#include "df/cursor.h"
#include "df/builtin_mats.h"
#include "df/contaminant.h"
#include "df/unit_spatter.h"
#include "modules/Materials.h"
using std::vector;
using std::string;
@ -50,12 +48,12 @@ command_result cleanmap (Core * c, bool snow, bool mud)
// filter snow
if(!snow
&& spatter->mat_type == DFHack::Materials::WATER
&& spatter->mat_type == df::builtin_mats::WATER
&& spatter->mat_state == df::matter_state::Powder)
continue;
// filter mud
if(!mud
&& spatter->mat_type == DFHack::Materials::MUD
&& spatter->mat_type == df::builtin_mats::MUD
&& spatter->mat_state == df::matter_state::Solid)
continue;
@ -123,8 +121,7 @@ df::map_block *getBlock (int32_t x, int32_t y, int32_t z)
return NULL;
if ((x >= world->map.x_count) || (y >= world->map.y_count) || (z >= world->map.z_count))
return NULL;
// block_index isn't declared correctly - needs one more level of indirection
return ((df::map_block ****)world->map.block_index)[x >> 4][y >> 4][z];
return world->map.block_index[x >> 4][y >> 4][z];
}
DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
@ -199,7 +196,7 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
"snow - also remove snow\n"
"mud - also remove mud\n"
"Example: clean all mud snow\n"
"This removes all spatter, including mud and snow from map tiles."
"This removes all spatter, including mud and snow from map tiles.\n"
);
return CR_OK;
}

@ -120,7 +120,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
int32_t owner = Items->getItemOwnerID(item);
if (owner >= 0)
{
c->con.print("Fixing a misflagged item: ");
c->con.print("Fixing a misflagged item: \t");
confiscate = true;
}
else

@ -1,56 +1,35 @@
// De-ramp. All ramps marked for removal are replaced with given tile (presently, normal floor).
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <assert.h>
#include <string.h>
using namespace std;
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <modules/Maps.h>
#include <TileTypes.h>
using namespace DFHack;
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters);
#include "DataDefs.h"
#include "df/world.h"
#include "df/map_block.h"
#include "df/tile_dig_designation.h"
#include <TileTypes.h>
DFhackCExport const char * plugin_name ( void )
{
return "deramp";
}
using std::vector;
using std::string;
using namespace DFHack;
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("deramp",
"De-ramp. All ramps marked for removal are replaced with floors.",
df_deramp));
return CR_OK;
}
using df::global::world;
using namespace DFHack;
DFhackCExport command_result plugin_shutdown ( Core * c )
// This is slightly different from what's in the Maps module - it takes tile coordinates rather than block coordinates
df::map_block *getBlock (int32_t x, int32_t y, int32_t z)
{
return CR_OK;
if ((x < 0) || (y < 0) || (z < 0))
return NULL;
if ((x >= world->map.x_count) || (y >= world->map.y_count) || (z >= world->map.z_count))
return NULL;
return world->map.block_index[x >> 4][y >> 4][z];
}
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
{
uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0;
uint32_t bytes_read = 0;
DFHack::designations40d designations;
DFHack::tiletypes40d tiles;
DFHack::tiletypes40d tilesAbove;
//DFHack::TileRow *ptile;
int32_t oldT, newT;
bool dirty= false;
int count=0;
int countbad=0;
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "help" || parameters[i] == "?")
@ -62,97 +41,74 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
return CR_OK;
}
}
c->Suspend();
DFHack::Maps *Mapz = c->getMaps();
// init the map
if (!Mapz->Start())
{
c->con.printerr("Can't init map.\n");
c->Resume();
return CR_FAILURE;
}
Mapz->getSize(x_max,y_max,z_max);
CoreSuspender suspend(c);
uint8_t zeroes [16][16] = {0};
int count = 0;
int countbad = 0;
// walk the map
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 (Mapz->getBlock(x,y,z))
{
dirty= false;
Mapz->ReadDesignations(x,y,z, &designations);
Mapz->ReadTileTypes(x,y,z, &tiles);
if (Mapz->getBlock(x,y,z+1))
int num_blocks = 0, blocks_total = world->map.map_blocks.size();
for (int i = 0; i < blocks_total; i++)
{
Mapz->ReadTileTypes(x,y,z+1, &tilesAbove);
}
else
{
memset(&tilesAbove,0,sizeof(tilesAbove));
}
df::map_block *block = world->map.map_blocks[i];
df::map_block *above = getBlock(block->map_x, block->map_y, block->map_z + 1);
for (uint32_t ty=0;ty<16;++ty)
for (int x = 0; x < 16; x++)
{
for (uint32_t tx=0;tx<16;++tx)
for (int y = 0; y < 16; y++)
{
//Only the remove ramp designation (ignore channel designation, etc)
oldT = tiles[tx][ty];
if ( DFHack::designation_default == designations[tx][ty].bits.dig
&& DFHack::RAMP==DFHack::tileShape(oldT))
int16_t oldT = block->tiletype[x][y];
if ((tileShape(oldT) == RAMP) &&
(block->designation[x][y].bits.dig == df::tile_dig_designation::Default))
{
// Current tile is a ramp.
// Set current tile, as accurately as can be expected
newT = DFHack::findSimilarTileType(oldT,DFHack::FLOOR);
int16_t newT = findSimilarTileType(oldT, FLOOR);
// If no change, skip it (couldn't find a good tile type)
if ( oldT == newT) continue;
if (oldT == newT)
continue;
// Set new tile type, clear designation
tiles[tx][ty] = newT;
designations[tx][ty].bits.dig = DFHack::designation_no;
block->tiletype[x][y] = newT;
block->designation[x][y].bits.dig = df::tile_dig_designation::No;
// Check the tile above this one, in case a downward slope needs to be removed.
if ( DFHack::RAMP_TOP == DFHack::tileShape(tilesAbove[tx][ty]) )
{
tilesAbove[tx][ty] = 32;
}
dirty= true;
++count;
if ((above) && (tileShape(above->tiletype[x][y]) == RAMP_TOP))
above->tiletype[x][y] = 32; // open space
count++;
}
// ramp fixer
else if(DFHack::RAMP!=DFHack::tileShape(oldT) && DFHack::RAMP_TOP == DFHack::tileShape(tilesAbove[tx][ty]))
else if ((tileShape(oldT) != RAMP)
&& (above) && (tileShape(above->tiletype[x][y]) == RAMP_TOP))
{
tilesAbove[tx][ty] = 32;
above->tiletype[x][y] = 32; // open space
countbad++;
dirty = true;
}
}
}
//If anything was changed, write it all.
if (dirty)
{
Mapz->WriteDesignations(x,y,z, &designations);
Mapz->WriteTileTypes(x,y,z, &tiles);
if (Mapz->getBlock(x,y,z+1))
{
Mapz->WriteTileTypes(x,y,z+1, &tilesAbove);
}
dirty = false;
}
}
}
}
}
c->Resume();
if (count)
c->con.print("Found and changed %d tiles.\n", count);
if (countbad)
c->con.print("Fixed %d bad down ramps.\n", countbad);
return CR_OK;
}
DFhackCExport const char * plugin_name ( void )
{
return "deramp";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("deramp",
"De-ramp. All ramps marked for removal are replaced with floors.",
df_deramp));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}

@ -8,8 +8,7 @@
#include <DataDefs.h>
#include "df/world.h"
#include "df/item.h"
#include "modules/Materials.h"
#include "df/builtin_mats.h"
using std::string;
using std::vector;
@ -28,7 +27,7 @@ DFhackCExport command_result df_drybuckets (Core * c, vector <string> & paramete
for (int i = 0; i < world->items.all.size(); i++)
{
df::item *item = world->items.all[i];
if ((item->getType() == df::item_type::LIQUID_MISC) && (item->getMaterial() == DFHack::Materials::WATER))
if ((item->getType() == df::item_type::LIQUID_MISC) && (item->getMaterial() == df::builtin_mats::WATER))
{
item->flags.bits.garbage_colect = 1;
dried_total++;

@ -1,21 +1,20 @@
// foo
// vi:expandtab:sw=4
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <assert.h>
#include <string.h>
using namespace std;
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <VersionInfo.h>
#include <modules/Units.h>
#include <DataDefs.h>
#include "df/ui.h"
#include "df/world.h"
#include "df/unit.h"
using std::string;
using std::vector;
using namespace DFHack;
using df::global::world;
using df::global::ui;
// dfhack interface
DFhackCExport const char * plugin_name ( void )
{
@ -33,22 +32,16 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
{
if (!enable_fastdwarf)
return CR_OK;
df_unit *cre;
DFHack::Units * cr = c->getUnits();
static vector <df_unit*> *v = cr->creatures;
uint32_t race = cr->GetDwarfRaceIndex();
uint32_t civ = cr->GetDwarfCivId();
if (!v)
{
c->con.printerr("Unable to locate creature vector. Fastdwarf cancelled.\n");
}
int32_t race = ui->race_id;
int32_t civ = ui->civ_id;
for (unsigned i=0 ; i<v->size() ; ++i)
for (int i = 0; i < world->units.all.size(); i++)
{
cre = v->at(i);
if (cre->race == race && cre->civ == civ && cre->job_counter > 0)
cre->job_counter = 0;
// could also patch the cre->current_job->counter
df::unit *unit = world->units.all[i];
if (unit->race == race && unit->civ_id == civ && unit->counters.job_counter > 0)
unit->counters.job_counter = 0;
// could also patch the unit->job.current_job->completion_timer
}
return CR_OK;
}
@ -65,7 +58,9 @@ static command_result fastdwarf (Core * c, vector <string> & parameters)
}
else
{
c->con.print("Makes your minions move at ludicrous speeds.\nActivate with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\nCurrent state: %d.\n", enable_fastdwarf);
c->con.print("Makes your minions move at ludicrous speeds.\n"
"Activate with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\n"
"Current state: %d.\n", enable_fastdwarf);
}
return CR_OK;

@ -1,93 +1,75 @@
// This tool counts static tiles and active flows of water and magma.
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <string.h>
using namespace std;
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <modules/Maps.h>
using namespace DFHack;
DFhackCExport command_result df_flows (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "flows";
}
#include <DataDefs.h>
#include "df/world.h"
#include "df/map_block.h"
#include "df/tile_liquid.h"
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("flows",
"Counts map blocks with flowing liquids.",
df_flows));
return CR_OK;
}
using std::string;
using std::vector;
using namespace DFHack;
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
using df::global::world;
DFhackCExport command_result df_flows (Core * c, vector <string> & parameters)
{
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
DFHack::Maps *Maps;
CoreSuspender suspend(c);
c->Suspend();
Maps = c->getMaps();
// init the map
if(!Maps->Start())
{
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;
int flow1 = 0, flow2 = 0, flowboth = 0, water = 0, magma = 0;
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->getBlock(x,y,z))
for (int i = 0; i < world->map.map_blocks.size(); i++)
{
Maps->ReadBlockFlags(x, y, z, bflags);
Maps->ReadDesignations(x, y, z, &designations);
if (bflags.bits.liquid_1)
df::map_block *cur = world->map.map_blocks[i];
if (cur->flags.is_set(df::block_flags::UpdateLiquid))
flow1++;
if (bflags.bits.liquid_2)
if (cur->flags.is_set(df::block_flags::UpdateLiquidTwice))
flow2++;
if (bflags.bits.liquid_1 && bflags.bits.liquid_2)
if (cur->flags.is_set(df::block_flags::UpdateLiquid) && cur->flags.is_set(df::block_flags::UpdateLiquidTwice))
flowboth++;
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
for (int x = 0; x < 16; x++)
{
if (designations[i][j].bits.liquid_type == DFHack::liquid_magma)
for (int y = 0; y < 16; y++)
{
// only count tiles with actual liquid in them
if (cur->designation[x][y].bits.flow_size == 0)
continue;
if (cur->designation[x][y].bits.liquid_type == df::tile_liquid::Magma)
magma++;
if (designations[i][j].bits.liquid_type == DFHack::liquid_water)
if (cur->designation[x][y].bits.liquid_type == df::tile_liquid::Water)
water++;
}
}
}
c->con.print("Blocks with liquid_1=true: %d\n", flow1);
c->con.print("Blocks with liquid_2=true: %d\n", flow2);
c->con.print("Blocks with both: %d\n", flowboth);
c->con.print("Water tiles: %d\n", water);
c->con.print("Magma tiles: %d\n", magma);
return CR_OK;
}
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.",
df_flows));
return CR_OK;
}
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();
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}

@ -166,7 +166,7 @@ DFhackCExport command_result mode (Core * c, vector <string> & parameters)
c->Suspend();
world->WriteGameMode(gm);
c->Resume();
cout << endl;
c->con << endl;
}
return CR_OK;
}

@ -54,7 +54,6 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
{
Console & con = c->con;
BEGIN_PROBE:
c->Suspend();
DFHack::Gui *Gui = c->getGui();
DFHack::Units * cr = c->getUnits();

@ -7,16 +7,15 @@
#include <PluginManager.h>
#include <DataDefs.h>
#include "df/world.h"
#include "df/map_block.h"
#include <TileTypes.h>
#include <df/world.h>
#include <df/map_block.h>
using std::string;
using std::vector;
using namespace DFHack;
using df::global::world;
using df::map_block;
DFhackCExport command_result df_regrass (Core * c, vector <string> & parameters)
{
@ -28,7 +27,7 @@ DFhackCExport command_result df_regrass (Core * c, vector <string> & parameters)
int count = 0;
for (int i = 0; i < world->map.map_blocks.size(); i++)
{
map_block *cur = world->map.map_blocks[i];
df::map_block *cur = world->map.map_blocks[i];
for (int x = 0; x < 16; x++)
{
for (int y = 0; y < 16; y++)