Merge remote-tracking branch 'quietust/master'

develop
Mike Stewart 2012-01-20 09:47:32 -08:00
commit 9b0b0d53f9
21 changed files with 1037 additions and 2002 deletions

@ -1090,7 +1090,6 @@ TYPE * Core::get##TYPE() \
MODULE_GETTER(Units); MODULE_GETTER(Units);
MODULE_GETTER(Engravings); MODULE_GETTER(Engravings);
MODULE_GETTER(Maps);
MODULE_GETTER(Gui); MODULE_GETTER(Gui);
MODULE_GETTER(World); MODULE_GETTER(World);
MODULE_GETTER(Materials); MODULE_GETTER(Materials);

@ -54,7 +54,6 @@ namespace DFHack
class Module; class Module;
class Units; class Units;
class Engravings; class Engravings;
class Maps;
class Gui; class Gui;
class World; class World;
class Materials; class Materials;
@ -102,8 +101,6 @@ namespace DFHack
Units * getUnits(); Units * getUnits();
/// get the engravings module /// get the engravings module
Engravings * getEngravings(); Engravings * getEngravings();
/// get the maps module
Maps * getMaps();
/// get the gui module /// get the gui module
Gui * getGui(); Gui * getGui();
/// get the world module /// get the world module
@ -166,7 +163,6 @@ namespace DFHack
{ {
Units * pUnits; Units * pUnits;
Engravings * pEngravings; Engravings * pEngravings;
Maps * pMaps;
Gui * pGui; Gui * pGui;
World * pWorld; World * pWorld;
Materials * pMaterials; Materials * pMaterials;

@ -39,7 +39,6 @@ namespace DFHack
Module* createVegetation(); Module* createVegetation();
Module* createBuildings(); Module* createBuildings();
Module* createConstructions(); Module* createConstructions();
Module* createMaps();
Module* createNotes(); Module* createNotes();
Module* createGraphic(); Module* createGraphic();
} }

@ -0,0 +1,19 @@
inline bool getassignment( const df::coord2d &xy )
{
return getassignment(xy.x,xy.y);
}
inline bool getassignment( int x, int y )
{
return (tile_bitmask[y] & (1 << x));
}
inline void setassignment( const df::coord2d &xy, bool bit )
{
return setassignment(xy.x,xy.y, bit);
}
inline void setassignment( int x, int y, bool bit )
{
if(bit)
tile_bitmask[y] |= (1 << x);
else
tile_bitmask[y] &= 0xFFFF ^ (1 << x);
}

@ -30,13 +30,17 @@ distribution.
#include "TileTypes.h" #include "TileTypes.h"
#include <stdint.h> #include <stdint.h>
#include <cstring> #include <cstring>
#include "df/map_block.h"
#include "df/block_square_event_mineralst.h"
using namespace DFHack;
using namespace DFHack::Simple;
namespace MapExtras namespace MapExtras
{ {
void SquashVeins (DFHack::Maps *m, DFHack::DFCoord bcoord, DFHack::mapblock40d & mb, DFHack::t_blockmaterials & materials) void SquashVeins (DFCoord bcoord, mapblock40d & mb, t_blockmaterials & materials)
{ {
memset(materials,-1,sizeof(materials)); memset(materials,-1,sizeof(materials));
std::vector <DFHack::t_vein *> veins; std::vector <df::block_square_event_mineralst *> veins;
m->SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,&veins); Maps::SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,&veins);
//iterate through block rows //iterate through block rows
for(uint32_t j = 0;j<16;j++) for(uint32_t j = 0;j<16;j++)
{ {
@ -48,9 +52,9 @@ void SquashVeins (DFHack::Maps *m, DFHack::DFCoord bcoord, DFHack::mapblock40d &
{ {
for(int i = (int) veins.size() - 1; i >= 0;i--) for(int i = (int) veins.size() - 1; i >= 0;i--)
{ {
if(!!(((1 << k) & veins[i]->assignment[j]) >> k)) if(!!(((1 << k) & veins[i]->tile_bitmask[j]) >> k))
{ {
materials[k][j] = veins[i]->type; materials[k][j] = veins[i]->inorganic_mat;
i = -1; i = -1;
} }
} }
@ -81,9 +85,8 @@ void SquashRocks ( std::vector< std::vector <uint16_t> > * layerassign, DFHack::
class Block class Block
{ {
public: public:
Block(DFHack::Maps *_m, DFHack::DFCoord _bcoord, std::vector< std::vector <uint16_t> > * layerassign = 0) Block(DFHack::DFCoord _bcoord, std::vector< std::vector <uint16_t> > * layerassign = 0)
{ {
m = _m;
dirty_designations = false; dirty_designations = false;
dirty_tiletypes = false; dirty_tiletypes = false;
dirty_temperatures = false; dirty_temperatures = false;
@ -91,10 +94,10 @@ class Block
dirty_occupancies = false; dirty_occupancies = false;
valid = false; valid = false;
bcoord = _bcoord; bcoord = _bcoord;
if(m->ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw)) if(Maps::ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw))
{ {
m->ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2); Maps::ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
SquashVeins(m,bcoord,raw,veinmats); SquashVeins(bcoord,raw,veinmats);
if(layerassign) if(layerassign)
SquashRocks(layerassign,raw,basemats); SquashRocks(layerassign,raw,basemats);
else else
@ -102,24 +105,24 @@ class Block
valid = true; valid = true;
} }
} }
int16_t veinMaterialAt(DFHack::DFCoord p) int16_t veinMaterialAt(df::coord2d p)
{ {
return veinmats[p.x][p.y]; return veinmats[p.x][p.y];
} }
int16_t baseMaterialAt(DFHack::DFCoord p) int16_t baseMaterialAt(df::coord2d p)
{ {
return basemats[p.x][p.y]; return basemats[p.x][p.y];
} }
void ClearMaterialAt(DFHack::DFCoord p) void ClearMaterialAt(df::coord2d p)
{ {
veinmats[p.x][p.y] = -1; veinmats[p.x][p.y] = -1;
} }
uint16_t TileTypeAt(DFHack::DFCoord p) uint16_t TileTypeAt(df::coord2d p)
{ {
return raw.tiletypes[p.x][p.y]; return raw.tiletypes[p.x][p.y];
} }
bool setTiletypeAt(DFHack::DFCoord p, uint16_t tiletype) bool setTiletypeAt(df::coord2d p, uint16_t tiletype)
{ {
if(!valid) return false; if(!valid) return false;
dirty_tiletypes = true; dirty_tiletypes = true;
@ -128,11 +131,11 @@ class Block
return true; return true;
} }
uint16_t temperature1At(DFHack::DFCoord p) uint16_t temperature1At(df::coord2d p)
{ {
return temp1[p.x][p.y]; return temp1[p.x][p.y];
} }
bool setTemp1At(DFHack::DFCoord p, uint16_t temp) bool setTemp1At(df::coord2d p, uint16_t temp)
{ {
if(!valid) return false; if(!valid) return false;
dirty_temperatures = true; dirty_temperatures = true;
@ -140,11 +143,11 @@ class Block
return true; return true;
} }
uint16_t temperature2At(DFHack::DFCoord p) uint16_t temperature2At(df::coord2d p)
{ {
return temp2[p.x][p.y]; return temp2[p.x][p.y];
} }
bool setTemp2At(DFHack::DFCoord p, uint16_t temp) bool setTemp2At(df::coord2d p, uint16_t temp)
{ {
if(!valid) return false; if(!valid) return false;
dirty_temperatures = true; dirty_temperatures = true;
@ -152,11 +155,11 @@ class Block
return true; return true;
} }
DFHack::t_designation DesignationAt(DFHack::DFCoord p) df::tile_designation DesignationAt(df::coord2d p)
{ {
return raw.designation[p.x][p.y]; return raw.designation[p.x][p.y];
} }
bool setDesignationAt(DFHack::DFCoord p, DFHack::t_designation des) bool setDesignationAt(df::coord2d p, df::tile_designation des)
{ {
if(!valid) return false; if(!valid) return false;
dirty_designations = true; dirty_designations = true;
@ -170,11 +173,11 @@ class Block
return true; return true;
} }
DFHack::t_occupancy OccupancyAt(DFHack::DFCoord p) df::tile_occupancy OccupancyAt(df::coord2d p)
{ {
return raw.occupancy[p.x][p.y]; return raw.occupancy[p.x][p.y];
} }
bool setOccupancyAt(DFHack::DFCoord p, DFHack::t_occupancy des) bool setOccupancyAt(df::coord2d p, df::tile_occupancy des)
{ {
if(!valid) return false; if(!valid) return false;
dirty_occupancies = true; dirty_occupancies = true;
@ -200,28 +203,28 @@ class Block
if(!valid) return false; if(!valid) return false;
if(dirty_designations) if(dirty_designations)
{ {
m->WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation); Maps::WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation);
m->WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true); Maps::WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true);
dirty_designations = false; dirty_designations = false;
} }
if(dirty_tiletypes) if(dirty_tiletypes)
{ {
m->WriteTileTypes(bcoord.x,bcoord.y,bcoord.z, &raw.tiletypes); Maps::WriteTileTypes(bcoord.x,bcoord.y,bcoord.z, &raw.tiletypes);
dirty_tiletypes = false; dirty_tiletypes = false;
} }
if(dirty_temperatures) if(dirty_temperatures)
{ {
m->WriteTemperatures(bcoord.x,bcoord.y,bcoord.z, &temp1, &temp2); Maps::WriteTemperatures(bcoord.x,bcoord.y,bcoord.z, &temp1, &temp2);
dirty_temperatures = false; dirty_temperatures = false;
} }
if(dirty_blockflags) if(dirty_blockflags)
{ {
m->WriteBlockFlags(bcoord.x,bcoord.y,bcoord.z,raw.blockflags); Maps::WriteBlockFlags(bcoord.x,bcoord.y,bcoord.z,raw.blockflags);
dirty_blockflags = false; dirty_blockflags = false;
} }
if(dirty_occupancies) if(dirty_occupancies)
{ {
m->WriteOccupancy(bcoord.x,bcoord.y,bcoord.z,&raw.occupancy); Maps::WriteOccupancy(bcoord.x,bcoord.y,bcoord.z,&raw.occupancy);
dirty_occupancies = false; dirty_occupancies = false;
} }
return true; return true;
@ -232,7 +235,6 @@ class Block
bool dirty_temperatures:1; bool dirty_temperatures:1;
bool dirty_blockflags:1; bool dirty_blockflags:1;
bool dirty_occupancies:1; bool dirty_occupancies:1;
DFHack::Maps * m;
DFHack::mapblock40d raw; DFHack::mapblock40d raw;
DFHack::DFCoord bcoord; DFHack::DFCoord bcoord;
DFHack::t_blockmaterials veinmats; DFHack::t_blockmaterials veinmats;
@ -244,12 +246,11 @@ class Block
class MapCache class MapCache
{ {
public: public:
MapCache(DFHack::Maps * Maps) MapCache()
{ {
valid = 0; valid = 0;
this->Maps = Maps; Maps::getSize(x_bmax, y_bmax, z_max);
Maps->getSize(x_bmax, y_bmax, z_max); validgeo = Maps::ReadGeology( layerassign );
validgeo = Maps->ReadGeology( layerassign );
valid = true; valid = true;
}; };
~MapCache() ~MapCache()
@ -276,9 +277,9 @@ class MapCache
{ {
Block * nblo; Block * nblo;
if(validgeo) if(validgeo)
nblo = new Block(Maps,blockcoord, &layerassign); nblo = new Block(blockcoord, &layerassign);
else else
nblo = new Block(Maps,blockcoord); nblo = new Block(blockcoord);
blocks[blockcoord] = nblo; blocks[blockcoord] = nblo;
return nblo; return nblo;
} }
@ -294,7 +295,7 @@ class MapCache
} }
return 0; return 0;
} }
bool setTiletypeAt(DFHack::DFCoord& tilecoord, uint16_t tiletype) bool setTiletypeAt(DFHack::DFCoord tilecoord, uint16_t tiletype)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
@ -314,7 +315,7 @@ class MapCache
} }
return 0; return 0;
} }
bool setTemp1At(DFHack::DFCoord& tilecoord, uint16_t temperature) bool setTemp1At(DFHack::DFCoord tilecoord, uint16_t temperature)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
@ -334,7 +335,7 @@ class MapCache
} }
return 0; return 0;
} }
bool setTemp2At(DFHack::DFCoord& tilecoord, uint16_t temperature) bool setTemp2At(DFHack::DFCoord tilecoord, uint16_t temperature)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
@ -373,18 +374,18 @@ class MapCache
return 0; return 0;
} }
DFHack::t_designation designationAt (DFHack::DFCoord tilecoord) df::tile_designation designationAt (DFHack::DFCoord tilecoord)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
{ {
return b->DesignationAt(tilecoord % 16); return b->DesignationAt(tilecoord % 16);
} }
DFHack:: t_designation temp; df::tile_designation temp;
temp.whole = 0; temp.whole = 0;
return temp; return temp;
} }
bool setDesignationAt (DFHack::DFCoord tilecoord, DFHack::t_designation des) bool setDesignationAt (DFHack::DFCoord tilecoord, df::tile_designation des)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
@ -395,18 +396,18 @@ class MapCache
return false; return false;
} }
DFHack::t_occupancy occupancyAt (DFHack::DFCoord tilecoord) df::tile_occupancy occupancyAt (DFHack::DFCoord tilecoord)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
{ {
return b->OccupancyAt(tilecoord % 16); return b->OccupancyAt(tilecoord % 16);
} }
DFHack:: t_occupancy temp; df::tile_occupancy temp;
temp.whole = 0; temp.whole = 0;
return temp; return temp;
} }
bool setOccupancyAt (DFHack::DFCoord tilecoord, DFHack::t_occupancy occ) bool setOccupancyAt (DFHack::DFCoord tilecoord, df::tile_occupancy occ)
{ {
Block * b= BlockAt(tilecoord / 16); Block * b= BlockAt(tilecoord / 16);
if(b && b->valid) if(b && b->valid)
@ -453,7 +454,6 @@ class MapCache
uint32_t y_tmax; uint32_t y_tmax;
uint32_t z_max; uint32_t z_max;
std::vector< std::vector <uint16_t> > layerassign; std::vector< std::vector <uint16_t> > layerassign;
DFHack::Maps * Maps;
std::map<DFHack::DFCoord, Block *> blocks; std::map<DFHack::DFCoord, Block *> blocks;
}; };
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit d5abec61f72f113e023219fed19c4022363de953 Subproject commit 8f9f7cf3bc4cff3dc721dc9e0ba51bc54b069587

@ -96,17 +96,14 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
DFHack::VersionInfo *mem = c->vinfo; DFHack::VersionInfo *mem = c->vinfo;
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
DFHack::Maps *Maps = c->getMaps(); if (!Maps::IsValid())
std::size_t numItems = world->items.all.size();
// init the map
if(!Maps->Start())
{ {
c->con.printerr("Can't initialize map.\n"); c->con.printerr("Map is not available!\n");
return CR_FAILURE; return CR_FAILURE;
} }
MapCache MC (Maps); std::size_t numItems = world->items.all.size();
MapCache MC;
int i = 0; int i = 0;
int dumped_total = 0; int dumped_total = 0;
@ -185,8 +182,8 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
{ {
// yes... // yes...
cerr << "Moving from block to block!" << endl; cerr << "Moving from block to block!" << endl;
df_block * bl_src = Maps->getBlock(itm->pos.x /16, itm->pos.y/16, itm->pos.z); df::map_block * bl_src = Maps::getBlockAbs(itm->pos.x, itm->pos.y, itm->pos.z);
df_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz); df::map_block * bl_tgt = Maps::getBlockAbs(cx, cy, cz);
if(bl_src) if(bl_src)
{ {
std::remove(bl_src->items.begin(), bl_src->items.end(),itm->id); std::remove(bl_src->items.begin(), bl_src->items.end(),itm->id);
@ -234,7 +231,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
{ {
if(it->second == 0) if(it->second == 0)
{ {
t_occupancy occ = MC.occupancyAt(it->first); df::tile_occupancy occ = MC.occupancyAt(it->first);
occ.bits.item = false; occ.bits.item = false;
MC.setOccupancyAt(it->first, occ); MC.setOccupancyAt(it->first, occ);
} }
@ -247,7 +244,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
Block * b = MC.BlockAt(pos_cursor / 16); Block * b = MC.BlockAt(pos_cursor / 16);
if(b) if(b)
{ {
t_occupancy occ = MC.occupancyAt(pos_cursor); df::tile_occupancy occ = MC.occupancyAt(pos_cursor);
occ.bits.item = 1; occ.bits.item = 1;
MC.setOccupancyAt(pos_cursor,occ); MC.setOccupancyAt(pos_cursor,occ);
} }
@ -255,7 +252,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
// write map changes back to DF. // write map changes back to DF.
MC.WriteAll(); MC.WriteAll();
// Is this necessary? Is "forbid" a dirtyable attribute like "dig" is? // Is this necessary? Is "forbid" a dirtyable attribute like "dig" is?
Maps->WriteDirtyBit(cx/16, cy/16, cz, true); Maps::WriteDirtyBit(cx/16, cy/16, cz, true);
} }
c->con.print("Done. %d items %s.\n", dumped_total, destroy ? "marked for destruction" : "quickdumped"); c->con.print("Done. %d items %s.\n", dumped_total, destroy ? "marked for destruction" : "quickdumped");
return CR_OK; return CR_OK;

@ -2,12 +2,9 @@
#include "Console.h" #include "Console.h"
#include "Export.h" #include "Export.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Maps.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h"
#include "df/map_block.h"
#include "df/block_square_event.h"
#include "df/block_square_event_material_spatterst.h"
#include "df/item_actual.h" #include "df/item_actual.h"
#include "df/unit.h" #include "df/unit.h"
#include "df/unit_spatter.h" #include "df/unit_spatter.h"
@ -19,6 +16,7 @@
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
using df::global::world; using df::global::world;
using df::global::cursor; using df::global::cursor;
@ -115,16 +113,6 @@ command_result cleanunits (Core * c)
return CR_OK; return CR_OK;
} }
// 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)
{
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 spotclean (Core * c, vector <string> & parameters) DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
{ {
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
@ -133,7 +121,7 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
c->con.printerr("The cursor is not active.\n"); c->con.printerr("The cursor is not active.\n");
return CR_FAILURE; return CR_FAILURE;
} }
df::map_block *block = getBlock(cursor->x, cursor->y, cursor->z); df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
if (block == NULL) if (block == NULL)
{ {
c->con.printerr("Invalid map block selected!\n"); c->con.printerr("Invalid map block selected!\n");

@ -14,7 +14,6 @@ using namespace std;
#include "PluginManager.h" #include "PluginManager.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include "modules/Maps.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Units.h" #include "modules/Units.h"
#include "modules/Materials.h" #include "modules/Materials.h"

@ -6,9 +6,7 @@
#include "PluginManager.h" #include "PluginManager.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "modules/Maps.h"
#include "df/map_block.h"
#include "df/tile_dig_designation.h"
#include "TileTypes.h" #include "TileTypes.h"
using std::vector; using std::vector;
@ -17,16 +15,7 @@ using namespace DFHack;
using df::global::world; using df::global::world;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
// 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)
{
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) DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
{ {
@ -51,7 +40,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
for (int i = 0; i < blocks_total; i++) for (int i = 0; i < blocks_total; i++)
{ {
df::map_block *block = world->map.map_blocks[i]; df::map_block *block = world->map.map_blocks[i];
df::map_block *above = getBlock(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1); df::map_block *above = Maps::getBlockAbs(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1);
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {

@ -17,7 +17,7 @@ using MapExtras::MapCache;
using namespace DFHack; using namespace DFHack;
//Function pointer type for whole-map tile checks. //Function pointer type for whole-map tile checks.
typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache *); typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache &);
//Forward Declarations for Commands //Forward Declarations for Commands
DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::string> & params); DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::string> & params);
@ -28,10 +28,10 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
DFHack::DFCoord minCoord = DFHack::DFCoord(0, 0, 0), DFHack::DFCoord minCoord = DFHack::DFCoord(0, 0, 0),
DFHack::DFCoord maxCoord = DFHack::DFCoord(0xFFFF, 0xFFFF, 0xFFFF)); DFHack::DFCoord maxCoord = DFHack::DFCoord(0xFFFF, 0xFFFF, 0xFFFF));
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map); void allHigh(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map); void allNormal(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map); void allLow(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map); void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache & map);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
{ {
@ -57,8 +57,8 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
//Maximum map size. //Maximum map size.
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
//Source and target traffic types. //Source and target traffic types.
e_traffic source = traffic_normal; df::tile_traffic source = df::tile_traffic::Normal;
e_traffic target = traffic_normal; df::tile_traffic target = df::tile_traffic::Normal;
//Option flags //Option flags
bool updown = false; bool updown = false;
bool checkpit = true; bool checkpit = true;
@ -89,13 +89,13 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
switch (toupper(params[i][0])) switch (toupper(params[i][0]))
{ {
case 'H': case 'H':
target = traffic_high; break; target = df::tile_traffic::High; break;
case 'N': case 'N':
target = traffic_normal; break; target = df::tile_traffic::Normal; break;
case 'L': case 'L':
target = traffic_low; break; target = df::tile_traffic::Low; break;
case 'R': case 'R':
target = traffic_restricted; break; target = df::tile_traffic::Restricted; break;
case 'X': case 'X':
updown = true; break; updown = true; break;
case 'B': case 'B':
@ -108,18 +108,16 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
//Initialization. //Initialization.
c->Suspend(); c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
// init the map if (!Maps::IsValid())
if(!Maps->Start())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16; uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16; uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz); Gui->getCursorCoords(cx,cy,cz);
@ -131,20 +129,19 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
} }
DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); MapExtras::MapCache MCache;
DFHack::t_designation des = MCache->designationAt(xy); df::tile_designation des = MCache.designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy); int16_t tt = MCache.tiletypeAt(xy);
DFHack::t_occupancy oc; df::tile_occupancy oc;
if (checkbuilding) if (checkbuilding)
oc = MCache->occupancyAt(xy); oc = MCache.occupancyAt(xy);
source = des.bits.traffic; source = (df::tile_traffic)des.bits.traffic;
if(source == target) if(source == target)
{ {
c->con.printerr("This tile is already set to the target traffic type.\n"); c->con.printerr("This tile is already set to the target traffic type.\n");
delete MCache;
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -152,7 +149,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(DFHack::isWallTerrain(tt)) if(DFHack::isWallTerrain(tt))
{ {
c->con.printerr("This tile is a wall. Please select a passable tile.\n"); c->con.printerr("This tile is a wall. Please select a passable tile.\n");
delete MCache;
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -160,7 +156,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(checkpit && DFHack::isOpenTerrain(tt)) if(checkpit && DFHack::isOpenTerrain(tt))
{ {
c->con.printerr("This tile is a hole. Please select a passable tile.\n"); c->con.printerr("This tile is a hole. Please select a passable tile.\n");
delete MCache;
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -168,7 +163,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(checkbuilding && oc.bits.building) if(checkbuilding && oc.bits.building)
{ {
c->con.printerr("This tile contains a building. Please select an empty tile.\n"); c->con.printerr("This tile contains a building. Please select an empty tile.\n");
delete MCache;
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -184,25 +178,25 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
xy = flood.top(); xy = flood.top();
flood.pop(); flood.pop();
des = MCache->designationAt(xy); des = MCache.designationAt(xy);
if (des.bits.traffic != source) continue; if (des.bits.traffic != source) continue;
tt = MCache->tiletypeAt(xy); tt = MCache.tiletypeAt(xy);
if(DFHack::isWallTerrain(tt)) continue; if(DFHack::isWallTerrain(tt)) continue;
if(checkpit && DFHack::isOpenTerrain(tt)) continue; if(checkpit && DFHack::isOpenTerrain(tt)) continue;
if (checkbuilding) if (checkbuilding)
{ {
oc = MCache->occupancyAt(xy); oc = MCache.occupancyAt(xy);
if(oc.bits.building) continue; if(oc.bits.building) continue;
} }
//This tile is ready. Set its traffic level and add surrounding tiles. //This tile is ready. Set its traffic level and add surrounding tiles.
if (MCache->testCoord(xy)) if (MCache.testCoord(xy))
{ {
des.bits.traffic = target; des.bits.traffic = target;
MCache->setDesignationAt(xy,des); MCache.setDesignationAt(xy,des);
if (xy.x > 0) if (xy.x > 0)
{ {
@ -236,7 +230,7 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
} }
} }
MCache->WriteAll(); MCache.WriteAll();
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
@ -245,7 +239,7 @@ enum e_checktype {no_check, check_equal, check_nequal};
DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector<std::string> & params) DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector<std::string> & params)
{ {
void (*proc)(DFHack::DFCoord, MapExtras::MapCache *) = allNormal; void (*proc)(DFHack::DFCoord, MapExtras::MapCache &) = allNormal;
//Loop through parameters //Loop through parameters
for(int i = 0; i < params.size();i++) for(int i = 0; i < params.size();i++)
@ -289,26 +283,24 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
//Initialization. //Initialization.
c->Suspend(); c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
// init the map if (!Maps::IsValid())
if(!Maps->Start())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
//Maximum map size. //Maximum map size.
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
Maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16; uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16; uint32_t ty_max = y_max * 16;
//Ensure maximum coordinate is within map. Truncate to map edge. //Ensure maximum coordinate is within map. Truncate to map edge.
maxCoord.x = std::min((uint32_t) maxCoord.x, tx_max); maxCoord.x = std::min((uint32_t) maxCoord.x, tx_max);
maxCoord.y = std::min((uint32_t) maxCoord.y, ty_max); maxCoord.y = std::min((uint32_t) maxCoord.y, ty_max);
maxCoord.z = std::min(maxCoord.z, z_max); maxCoord.z = std::min((uint32_t) maxCoord.z, z_max);
//Check minimum co-ordinates against maximum map size //Check minimum co-ordinates against maximum map size
if (minCoord.x > maxCoord.x) if (minCoord.x > maxCoord.x)
@ -330,7 +322,7 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
return CR_FAILURE; return CR_FAILURE;
} }
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); MapExtras::MapCache MCache;
c->con.print("Setting traffic...\n"); c->con.print("Setting traffic...\n");
@ -347,34 +339,34 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
} }
} }
MCache->WriteAll(); MCache.WriteAll();
c->con.print("Complete!\n"); c->con.print("Complete!\n");
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
//Unconditionally set map to target traffic type //Unconditionally set map to target traffic type
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map) void allHigh(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
DFHack::t_designation des = map->designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = traffic_high; des.bits.traffic = df::tile_traffic::High;
map->setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map) void allNormal(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
DFHack::t_designation des = map->designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = traffic_normal; des.bits.traffic = df::tile_traffic::Normal;
map->setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map) void allLow(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
DFHack::t_designation des = map->designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = traffic_low; des.bits.traffic = df::tile_traffic::Low;
map->setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map) void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
DFHack::t_designation des = map->designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = traffic_restricted; des.bits.traffic = df::tile_traffic::Restricted;
map->setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }

@ -169,7 +169,6 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
int32_t x,y,z; int32_t x,y,z;
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::Maps * Maps;
DFHack::Gui * Position; DFHack::Gui * Position;
for(int i = 0; i < parameters.size();i++) for(int i = 0; i < parameters.size();i++)
{ {
@ -360,16 +359,14 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
else if(command.empty()) else if(command.empty())
{ {
c->Suspend(); c->Suspend();
Maps = c->getMaps(); Maps::getSize(x_max,y_max,z_max);
Maps->Start();
Maps->getSize(x_max,y_max,z_max);
Position = c->getGui(); Position = c->getGui();
do do
{ {
if(!Maps->Start()) if (!Maps::IsValid())
{ {
c->con << "Can't see any DF map loaded." << endl; c->con << "Can't see any DF map loaded." << endl;
break; break;;
} }
if(!Position->getCursorCoords(x,y,z)) if(!Position->getCursorCoords(x,y,z))
{ {
@ -377,7 +374,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
break; break;
} }
c->con << "cursor coords: " << x << "/" << y << "/" << z << endl; c->con << "cursor coords: " << x << "/" << y << "/" << z << endl;
MapCache mcache(Maps); MapCache mcache;
DFHack::DFCoord cursor(x,y,z); DFHack::DFCoord cursor(x,y,z);
coord_vec all_tiles = brush->points(mcache,cursor); coord_vec all_tiles = brush->points(mcache,cursor);
c->con << "working..." << endl; c->con << "working..." << endl;
@ -389,7 +386,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
mcache.setTiletypeAt(*iter, 331); mcache.setTiletypeAt(*iter, 331);
mcache.setTemp1At(*iter,10015); mcache.setTemp1At(*iter,10015);
mcache.setTemp2At(*iter,10015); mcache.setTemp2At(*iter,10015);
DFHack::t_designation des = mcache.designationAt(*iter); df::tile_designation des = mcache.designationAt(*iter);
des.bits.flow_size = 0; des.bits.flow_size = 0;
mcache.setDesignationAt(*iter, des); mcache.setDesignationAt(*iter, des);
iter ++; iter ++;
@ -411,8 +408,8 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
{ {
mcache.setTiletypeAt(*iter, 90); mcache.setTiletypeAt(*iter, 90);
DFHack::t_designation a = mcache.designationAt(*iter); df::tile_designation a = mcache.designationAt(*iter);
a.bits.liquid_type = DFHack::liquid_water; a.bits.liquid_type = df::tile_liquid::Water;
a.bits.liquid_static = false; a.bits.liquid_static = false;
a.bits.flow_size = 7; a.bits.flow_size = 7;
mcache.setTemp1At(*iter,10015); mcache.setTemp1At(*iter,10015);
@ -434,7 +431,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
while (iter != all_tiles.end()) while (iter != all_tiles.end())
{ {
DFHack::DFCoord current = *iter; DFHack::DFCoord current = *iter;
DFHack::t_designation des = mcache.designationAt(current); df::tile_designation des = mcache.designationAt(current);
des.bits.water_salt = false; des.bits.water_salt = false;
des.bits.water_stagnant = false; des.bits.water_stagnant = false;
mcache.setDesignationAt(current,des); mcache.setDesignationAt(current,des);
@ -455,9 +452,8 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
iter ++; iter ++;
continue; continue;
} }
DFHack::t_designation des = mcache.designationAt(current); df::tile_designation des = mcache.designationAt(current);
uint16_t tt = mcache.tiletypeAt(current); uint16_t tt = mcache.tiletypeAt(current);
DFHack::naked_designation & flow = des.bits;
// don't put liquids into places where they don't belong... // don't put liquids into places where they don't belong...
if(!DFHack::FlowPassable(tt)) if(!DFHack::FlowPassable(tt))
{ {
@ -468,27 +464,27 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
{ {
if(setmode == "s.") if(setmode == "s.")
{ {
flow.flow_size = amount; des.bits.flow_size = amount;
} }
else if(setmode == "s+") else if(setmode == "s+")
{ {
if(flow.flow_size < amount) if(des.bits.flow_size < amount)
flow.flow_size = amount; des.bits.flow_size = amount;
} }
else if(setmode == "s-") else if(setmode == "s-")
{ {
if (flow.flow_size > amount) if (des.bits.flow_size > amount)
flow.flow_size = amount; des.bits.flow_size = amount;
} }
if(amount != 0 && mode == "magma") if(amount != 0 && mode == "magma")
{ {
flow.liquid_type = DFHack::liquid_magma; des.bits.liquid_type = df::tile_liquid::Magma;
mcache.setTemp1At(current,12000); mcache.setTemp1At(current,12000);
mcache.setTemp2At(current,12000); mcache.setTemp2At(current,12000);
} }
else if(amount != 0 && mode == "water") else if(amount != 0 && mode == "water")
{ {
flow.liquid_type = DFHack::liquid_water; des.bits.liquid_type = df::tile_liquid::Water;
mcache.setTemp1At(current,10015); mcache.setTemp1At(current,10015);
mcache.setTemp2At(current,10015); mcache.setTemp2At(current,10015);
} }
@ -531,7 +527,6 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
c->con << "OK" << endl; c->con << "OK" << endl;
else else
c->con << "Something failed horribly! RUN!" << endl; c->con << "Something failed horribly! RUN!" << endl;
Maps->Finish();
} while (0); } while (0);
c->Resume(); c->Resume();
} }

@ -99,17 +99,16 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
return CR_OK; return CR_OK;
} }
c->Suspend(); c->Suspend();
DFHack::Maps *maps = c->getMaps(); if (!Maps::IsValid())
if (!maps->Start())
{ {
c->con.printerr( "Cannot get map info!\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
uint32_t x_max, y_max, z_max; uint32_t x_max, y_max, z_max;
maps->getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps); MapExtras::MapCache map;
DFHack::Vegetation *veg = c->getVegetation(); DFHack::Vegetation *veg = c->getVegetation();
if (!veg->all_plants) if (!veg->all_plants)
{ {
@ -138,7 +137,7 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
if(Gui->getCursorCoords(x,y,z)) if(Gui->getCursorCoords(x,y,z))
{ {
vector<DFHack::df_plant *> * alltrees; vector<DFHack::df_plant *> * alltrees;
if(maps->ReadVegetation(x/16,y/16,z,alltrees)) if(Maps::ReadVegetation(x/16,y/16,z,alltrees))
{ {
bool didit = false; bool didit = false;
for(size_t i = 0 ; i < alltrees->size(); i++) for(size_t i = 0 ; i < alltrees->size(); i++)
@ -168,7 +167,6 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
} }
// Cleanup // Cleanup
veg->Finish(); veg->Finish();
maps->Finish();
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
@ -212,16 +210,14 @@ DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
} }
} }
c->Suspend(); c->Suspend();
DFHack::Maps *maps = c->getMaps();
Console & con = c->con; Console & con = c->con;
if (!maps->Start()) if (!Maps::IsValid())
{ {
con.printerr("Cannot get map info!\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
//maps->getSize(x_max, y_max, z_max); MapExtras::MapCache map;
MapExtras::MapCache map(maps);
DFHack::Vegetation *veg = c->getVegetation(); DFHack::Vegetation *veg = c->getVegetation();
if (!veg->all_plants) if (!veg->all_plants)
{ {
@ -234,7 +230,7 @@ DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
if(Gui->getCursorCoords(x,y,z)) if(Gui->getCursorCoords(x,y,z))
{ {
vector<DFHack::df_plant *> * alltrees; vector<DFHack::df_plant *> * alltrees;
if(maps->ReadVegetation(x/16,y/16,z,alltrees)) if(Maps::ReadVegetation(x/16,y/16,z,alltrees))
{ {
for(size_t i = 0 ; i < alltrees->size(); i++) for(size_t i = 0 ; i < alltrees->size(); i++)
{ {
@ -266,7 +262,6 @@ DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
// Cleanup // Cleanup
veg->Finish(); veg->Finish();
maps->Finish();
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }

@ -99,196 +99,182 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
DFHack::Gui *Gui = c->getGui(); DFHack::Gui *Gui = c->getGui();
DFHack::Materials *Materials = c->getMaterials(); DFHack::Materials *Materials = c->getMaterials();
DFHack::VersionInfo* mem = c->vinfo; DFHack::VersionInfo* mem = c->vinfo;
DFHack::Maps *Maps = c->getMaps();
std::vector<t_matglossInorganic> inorganic; std::vector<t_matglossInorganic> inorganic;
bool hasmats = Materials->CopyInorganicMaterials(inorganic); bool hasmats = Materials->CopyInorganicMaterials(inorganic);
if(!Maps->Start()) if (!Maps::IsValid())
{ {
con.printerr("Unable to access map data!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE;
} }
else MapExtras::MapCache mc;
{
MapExtras::MapCache mc (Maps);
int32_t regionX, regionY, regionZ; int32_t regionX, regionY, regionZ;
Maps->getPosition(regionX,regionY,regionZ); Maps::getPosition(regionX,regionY,regionZ);
bool have_features = Maps->StartFeatures(); int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
int32_t cursorX, cursorY, cursorZ; if(cursorX == -30000)
Gui->getCursorCoords(cursorX,cursorY,cursorZ); {
if(cursorX == -30000) con.printerr("No cursor; place cursor over tile to probe.\n");
{ c->Resume();
con.printerr("No cursor; place cursor over tile to probe.\n"); return CR_FAILURE;
} }
else DFCoord cursor (cursorX,cursorY,cursorZ);
{
DFCoord cursor (cursorX,cursorY,cursorZ);
uint32_t blockX = cursorX / 16; uint32_t blockX = cursorX / 16;
uint32_t tileX = cursorX % 16; uint32_t tileX = cursorX % 16;
uint32_t blockY = cursorY / 16; uint32_t blockY = cursorY / 16;
uint32_t tileY = cursorY % 16; uint32_t tileY = cursorY % 16;
MapExtras::Block * b = mc.BlockAt(cursor/16); MapExtras::Block * b = mc.BlockAt(cursor/16);
mapblock40d & block = b->raw; if(!b && !b->valid)
if(b && b->valid) {
{ con.printerr("No data.\n");
con.print("block addr: 0x%x\n\n", block.origin); c->Resume();
return CR_OK;
}
mapblock40d & block = b->raw;
con.print("block addr: 0x%x\n\n", block.origin);
/* /*
if (showBlock) if (showBlock)
{ {
con.print("block flags:\n"); con.print("block flags:\n");
print_bits<uint32_t>(block.blockflags.whole,con); print_bits<uint32_t>(block.blockflags.whole,con);
con.print("\n\n"); con.print("\n\n");
} }
*/ */
int16_t tiletype = mc.tiletypeAt(cursor); int16_t tiletype = mc.tiletypeAt(cursor);
naked_designation &des = block.designation[tileX][tileY].bits; df::tile_designation &des = block.designation[tileX][tileY];
/* /*
if(showDesig) if(showDesig)
{ {
con.print("designation\n"); con.print("designation\n");
print_bits<uint32_t>(block.designation[tileX][tileY].whole, print_bits<uint32_t>(block.designation[tileX][tileY].whole,
con); con);
con.print("\n\n"); con.print("\n\n");
} }
if(showOccup) if(showOccup)
{ {
con.print("occupancy\n"); con.print("occupancy\n");
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole, print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
con); con);
con.print("\n\n"); con.print("\n\n");
} }
*/ */
// tiletype // tiletype
con.print("tiletype: %d", tiletype); con.print("tiletype: %d", tiletype);
if(tileName(tiletype)) if(tileName(tiletype))
con.print(" = %s",tileName(tiletype)); con.print(" = %s",tileName(tiletype));
con.print("\n"); con.print("\n");
DFHack::TileShape shape = tileShape(tiletype); DFHack::TileShape shape = tileShape(tiletype);
DFHack::TileMaterial material = tileMaterial(tiletype); DFHack::TileMaterial material = tileMaterial(tiletype);
DFHack::TileSpecial special = tileSpecial(tiletype); DFHack::TileSpecial special = tileSpecial(tiletype);
con.print("%-10s: %4d %s\n","Class" ,shape, con.print("%-10s: %4d %s\n","Class" ,shape,
TileShapeString[ shape ]); TileShapeString[ shape ]);
con.print("%-10s: %4d %s\n","Material" , con.print("%-10s: %4d %s\n","Material" ,
material,TileMaterialString[ material ]); material,TileMaterialString[ material ]);
con.print("%-10s: %4d %s\n","Special" , con.print("%-10s: %4d %s\n","Special" ,
special, TileSpecialString[ special ]); special, TileSpecialString[ special ]);
con.print("%-10s: %4d\n" ,"Variant" , con.print("%-10s: %4d\n" ,"Variant" ,
tileVariant(tiletype)); tileVariant(tiletype));
con.print("%-10s: %s\n" ,"Direction", con.print("%-10s: %s\n" ,"Direction",
tileDirection(tiletype).getStr()); tileDirection(tiletype).getStr());
con.print("\n"); con.print("\n");
con.print("temperature1: %d U\n",mc.temperature1At(cursor)); con.print("temperature1: %d U\n",mc.temperature1At(cursor));
con.print("temperature2: %d U\n",mc.temperature2At(cursor)); con.print("temperature2: %d U\n",mc.temperature2At(cursor));
// biome, geolayer // biome, geolayer
con << "biome: " << des.biome << std::endl; con << "biome: " << des.bits.biome << std::endl;
con << "geolayer: " << des.geolayer_index con << "geolayer: " << des.bits.geolayer_index
<< std::endl; << std::endl;
int16_t base_rock = mc.baseMaterialAt(cursor); int16_t base_rock = mc.baseMaterialAt(cursor);
if(base_rock != -1) if(base_rock != -1)
{ {
con << "Layer material: " << dec << base_rock; con << "Layer material: " << dec << base_rock;
if(hasmats) if(hasmats)
con << " / " << inorganic[base_rock].id con << " / " << inorganic[base_rock].id
<< " / " << " / "
<< inorganic[base_rock].name << inorganic[base_rock].name
<< endl; << endl;
else else
con << endl; con << endl;
} }
int16_t vein_rock = mc.veinMaterialAt(cursor); int16_t vein_rock = mc.veinMaterialAt(cursor);
if(vein_rock != -1) if(vein_rock != -1)
{ {
con << "Vein material (final): " << dec << vein_rock; con << "Vein material (final): " << dec << vein_rock;
if(hasmats) if(hasmats)
con << " / " << inorganic[vein_rock].id con << " / " << inorganic[vein_rock].id
<< " / " << " / "
<< inorganic[vein_rock].name << inorganic[vein_rock].name
<< endl; << endl;
else else
con << endl; con << endl;
} }
// liquids // liquids
if(des.flow_size) if(des.bits.flow_size)
{ {
if(des.liquid_type == DFHack::liquid_magma) if(des.bits.liquid_type == df::tile_liquid::Magma)
con <<"magma: "; con <<"magma: ";
else con <<"water: "; else con <<"water: ";
con << des.flow_size << std::endl; con << des.bits.flow_size << std::endl;
} }
if(des.flow_forbid) if(des.bits.flow_forbid)
con << "flow forbid" << std::endl; con << "flow forbid" << std::endl;
if(des.pile) if(des.bits.pile)
con << "stockpile?" << std::endl; con << "stockpile?" << std::endl;
if(des.rained) if(des.bits.rained)
con << "rained?" << std::endl; con << "rained?" << std::endl;
if(des.smooth) if(des.bits.smooth)
con << "smooth?" << std::endl; con << "smooth?" << std::endl;
if(des.water_salt) if(des.bits.water_salt)
con << "salty" << endl; con << "salty" << endl;
if(des.water_stagnant) if(des.bits.water_stagnant)
con << "stagnant" << endl; con << "stagnant" << endl;
#define PRINT_FLAG( X ) con.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) ) #define PRINT_FLAG( X ) con.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
PRINT_FLAG( hidden ); PRINT_FLAG( bits.hidden );
PRINT_FLAG( light ); PRINT_FLAG( bits.light );
PRINT_FLAG( skyview ); PRINT_FLAG( bits.outside );
PRINT_FLAG( subterranean ); PRINT_FLAG( bits.subterranean );
PRINT_FLAG( water_table ); PRINT_FLAG( bits.water_table );
PRINT_FLAG( rained ); PRINT_FLAG( bits.rained );
DFCoord pc(blockX, blockY); df::coord2d pc(blockX, blockY);
if(have_features) t_feature local;
{ t_feature global;
t_feature * local = 0; Maps::ReadFeatures(&(b->raw),&local,&global);
t_feature * global = 0; PRINT_FLAG( bits.feature_local );
Maps->ReadFeatures(&(b->raw),&local,&global); if(local.type != -1)
PRINT_FLAG( feature_local ); {
if(local) con.print("%-16s", "");
{ con.print(" %4d", block.local_feature);
con.print("%-16s", ""); con.print(" (%2d)", local.type);
con.print(" %4d", block.local_feature); con.print(" addr 0x%X ", local.origin);
con.print(" (%2d)", local->type); con.print(" %s\n", sa_feature(local.type));
con.print(" addr 0x%X ", local->origin); }
con.print(" %s\n", sa_feature(local->type)); PRINT_FLAG( bits.feature_global );
} if(global.type != -1)
PRINT_FLAG( feature_global ); {
if(global) con.print("%-16s", "");
{ con.print(" %4d", block.global_feature);
con.print("%-16s", ""); con.print(" (%2d)", global.type);
con.print(" %4d", block.global_feature); con.print(" %s\n", sa_feature(global.type));
con.print(" (%2d)", global->type);
con.print(" %s\n", sa_feature(global->type));
}
}
else
{
PRINT_FLAG( feature_local );
PRINT_FLAG( feature_global );
}
#undef PRINT_FLAG
con << "local feature idx: " << block.local_feature
<< endl;
con << "global feature idx: " << block.global_feature
<< endl;
con << "mystery: " << block.mystery << endl;
con << std::endl;
}
else
{
con.printerr("No data.\n");
}
}
} }
#undef PRINT_FLAG
con << "local feature idx: " << block.local_feature
<< endl;
con << "global feature idx: " << block.global_feature
<< endl;
con << "mystery: " << block.mystery << endl;
con << std::endl;
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }

@ -68,9 +68,6 @@ bool operator>(const matdata & q1, const matdata & q2)
typedef std::map<int16_t, matdata> MatMap; typedef std::map<int16_t, matdata> MatMap;
typedef std::vector< pair<int16_t, matdata> > MatSorter; typedef std::vector< pair<int16_t, matdata> > MatSorter;
typedef std::vector<DFHack::t_feature> FeatureList;
typedef std::vector<DFHack::t_feature*> FeatureListPointer;
typedef std::map<DFHack::DFCoord, FeatureListPointer> FeatureMap;
typedef std::vector<DFHack::df_plant *> PlantList; typedef std::vector<DFHack::df_plant *> PlantList;
#define TO_PTR_VEC(obj_vec, ptr_vec) \ #define TO_PTR_VEC(obj_vec, ptr_vec) \
@ -196,6 +193,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
bool showSlade = true; bool showSlade = true;
bool showTemple = true; bool showTemple = true;
bool showValue = false; bool showValue = false;
bool showTube = false;
Console & con = c->con; Console & con = c->con;
for(int i = 0; i < parameters.size();i++) for(int i = 0; i < parameters.size();i++)
{ {
@ -203,10 +201,14 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
{ {
showHidden = true; showHidden = true;
} }
if (parameters[i] == "value") else if (parameters[i] == "value")
{ {
showValue = true; showValue = true;
} }
else if (parameters[i] == "hell")
{
showHidden = showTube = true;
}
else if(parameters[i] == "help" || parameters[i] == "?") else if(parameters[i] == "help" || parameters[i] == "?")
{ {
c->con.print("Prints a big list of all the present minerals.\n" c->con.print("Prints a big list of all the present minerals.\n"
@ -215,21 +217,21 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
"Options:\n" "Options:\n"
"all - Scan the whole map, as if it was revealed.\n" "all - Scan the whole map, as if it was revealed.\n"
"value - Show material value in the output.\n" "value - Show material value in the output.\n"
"hell - Show the Z range of HFS tubes.\n"
); );
return CR_OK; return CR_OK;
} }
} }
uint32_t x_max = 0, y_max = 0, z_max = 0; uint32_t x_max = 0, y_max = 0, z_max = 0;
c->Suspend(); c->Suspend();
DFHack::Maps *maps = c->getMaps(); if (!Maps::IsValid())
if (!maps->Start())
{ {
con.printerr("Cannot get map info!\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
maps->getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps); MapExtras::MapCache map;
DFHack::Materials *mats = c->getMaterials(); DFHack::Materials *mats = c->getMaterials();
if (!mats->df_inorganic) if (!mats->df_inorganic)
@ -244,10 +246,8 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
showPlants = false; showPlants = false;
} }
FeatureList globalFeatures; DFHack::t_feature blockFeatureGlobal;
FeatureMap localFeatures; DFHack::t_feature blockFeatureLocal;
DFHack::t_feature *blockFeatureGlobal = 0;
DFHack::t_feature *blockFeatureLocal = 0;
bool hasAquifer = false; bool hasAquifer = false;
bool hasDemonTemple = false; bool hasDemonTemple = false;
@ -261,16 +261,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
matdata liquidWater; matdata liquidWater;
matdata liquidMagma; matdata liquidMagma;
matdata aquiferTiles; matdata aquiferTiles;
matdata tubeTiles;
if (!(showSlade && maps->ReadGlobalFeatures(globalFeatures)))
{
con.printerr("Unable to read global features; slade won't be listed!\n");
}
if (!maps->ReadLocalFeatures(localFeatures))
{
con.printerr("Unable to read local features; adamantine and demon temples won't be listed.\n" );
}
uint32_t vegCount = 0; uint32_t vegCount = 0;
DFHack::Vegetation *veg = c->getVegetation(); DFHack::Vegetation *veg = c->getVegetation();
@ -286,7 +277,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
for(uint32_t b_x = 0; b_x < x_max; b_x++) for(uint32_t b_x = 0; b_x < x_max; b_x++)
{ {
// Get the map block // Get the map block
DFHack::DFCoord blockCoord(b_x, b_y); df::coord2d blockCoord(b_x, b_y);
MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z)); MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z));
if (!b || !b->valid) if (!b || !b->valid)
{ {
@ -294,23 +285,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
} }
{ // Find features { // Find features
uint16_t index = b->raw.global_feature; uint32_t index = b->raw.global_feature;
if (index != -1 && index < globalFeatures.size()) if (index != -1)
{ Maps::GetGlobalFeature(blockFeatureGlobal, index);
blockFeatureGlobal = &globalFeatures[index];
}
index = b->raw.local_feature; index = b->raw.local_feature;
FeatureMap::const_iterator it = localFeatures.find(blockCoord); if (index != -1)
if (it != localFeatures.end()) Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index);
{
FeatureListPointer features = it->second;
if (index != -1 && index < features.size())
{
blockFeatureLocal = features[index];
}
}
} }
int global_z = df::global::world->map.region_z + z; int global_z = df::global::world->map.region_z + z;
@ -320,9 +301,9 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
{ {
for(uint32_t x = 0; x < 16; x++) for(uint32_t x = 0; x < 16; x++)
{ {
DFHack::DFCoord coord(x, y); df::coord2d coord(x, y);
DFHack::t_designation des = b->DesignationAt(coord); df::tile_designation des = b->DesignationAt(coord);
DFHack::t_occupancy occ = b->OccupancyAt(coord); df::tile_occupancy occ = b->OccupancyAt(coord);
// Skip hidden tiles // Skip hidden tiles
if (!showHidden && des.bits.hidden) if (!showHidden && des.bits.hidden)
@ -346,7 +327,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
// Check for liquid // Check for liquid
if (des.bits.flow_size) if (des.bits.flow_size)
{ {
if (des.bits.liquid_type == liquid_magma) if (des.bits.liquid_type == df::tile_liquid::Magma)
liquidMagma.add(global_z); liquidMagma.add(global_z);
else else
liquidWater.add(global_z); liquidWater.add(global_z);
@ -368,6 +349,16 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
case DFHack::PILLAR: case DFHack::PILLAR:
case DFHack::FORTIFICATION: case DFHack::FORTIFICATION:
break; break;
case DFHack::EMPTY:
/* A heuristic: tubes inside adamantine have EMPTY:AIR tiles which
still have feature_local set. Also check the unrevealed status,
so as to exclude any holes mined by the player. */
if (info->material == DFHack::AIR &&
des.bits.feature_local && des.bits.hidden &&
blockFeatureLocal.type == df::feature_type::deep_special_tube)
{
tubeTiles.add(global_z);
}
default: default:
continue; continue;
} }
@ -386,25 +377,25 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
veinMats[b->veinMaterialAt(coord)].add(global_z); veinMats[b->veinMaterialAt(coord)].add(global_z);
break; break;
case DFHack::FEATSTONE: case DFHack::FEATSTONE:
if (blockFeatureLocal && des.bits.feature_local) if (blockFeatureLocal.type != -1 && des.bits.feature_local)
{ {
if (blockFeatureLocal->type == DFHack::feature_Adamantine_Tube if (blockFeatureLocal.type == df::feature_type::deep_special_tube
&& blockFeatureLocal->main_material == 0) // stone && blockFeatureLocal.main_material == 0) // stone
{ {
veinMats[blockFeatureLocal->sub_material].add(global_z); veinMats[blockFeatureLocal.sub_material].add(global_z);
} }
else if (showTemple else if (showTemple
&& blockFeatureLocal->type == DFHack::feature_Hell_Temple) && blockFeatureLocal.type == df::feature_type::deep_surface_portal)
{ {
hasDemonTemple = true; hasDemonTemple = true;
} }
} }
if (showSlade && blockFeatureGlobal && des.bits.feature_global if (showSlade && blockFeatureGlobal.type != -1 && des.bits.feature_global
&& blockFeatureGlobal->type == DFHack::feature_Underworld && blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer
&& blockFeatureGlobal->main_material == 0) // stone && blockFeatureGlobal.main_material == 0) // stone
{ {
layerMats[blockFeatureGlobal->sub_material].add(global_z); layerMats[blockFeatureGlobal.sub_material].add(global_z);
} }
break; break;
case DFHack::OBSIDIAN: case DFHack::OBSIDIAN:
@ -419,12 +410,12 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
if (showPlants) if (showPlants)
{ {
PlantList * plants; PlantList * plants;
if (maps->ReadVegetation(b_x, b_y, z, plants)) if (Maps::ReadVegetation(b_x, b_y, z, plants))
{ {
for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++) for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++)
{ {
const DFHack::df_plant & plant = *(*it); const DFHack::df_plant & plant = *(*it);
DFHack::DFCoord loc(plant.x, plant.y); df::coord2d loc(plant.x, plant.y);
loc = loc % 16; loc = loc % 16;
if (showHidden || !b->DesignationAt(loc).bits.hidden) if (showHidden || !b->DesignationAt(loc).bits.hidden)
{ {
@ -492,6 +483,12 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
con << std::endl; con << std::endl;
} }
if (showTube && tubeTiles.count)
{
con << "Has HFS tubes : ";
printMatdata(con, tubeTiles);
}
if (hasDemonTemple) if (hasDemonTemple)
{ {
con << "Has demon temple" << std::endl; con << "Has demon temple" << std::endl;
@ -508,7 +505,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
veg->Finish(); veg->Finish();
} }
mats->Finish(); mats->Finish();
maps->Finish();
c->Resume(); c->Resume();
con << std::endl; con << std::endl;
return CR_OK; return CR_OK;

@ -12,25 +12,25 @@
#include "modules/Gui.h" #include "modules/Gui.h"
using MapExtras::MapCache; using MapExtras::MapCache;
using namespace DFHack; using namespace DFHack;
using df::global::world;
/* /*
* Anything that might reveal Hell is unsafe. * Anything that might reveal Hell is unsafe.
*/ */
bool isSafe(uint32_t x, uint32_t y, uint32_t z, DFHack::Maps *Maps) bool isSafe(df::coord c)
{ {
DFHack::t_feature *local_feature = NULL; DFHack::t_feature local_feature;
DFHack::t_feature *global_feature = NULL; DFHack::t_feature global_feature;
// get features of block // get features of block
// error -> obviously not safe to manipulate // error -> obviously not safe to manipulate
if(!Maps->ReadFeatures(x,y,z,&local_feature,&global_feature)) if(!Maps::ReadFeatures(c.x >> 4,c.y >> 4,c.z,&local_feature,&global_feature))
{
return false; return false;
}
// Adamantine tubes and temples lead to Hell // Adamantine tubes and temples lead to Hell
if (local_feature && local_feature->type != DFHack::feature_Other) if (local_feature.type == df::feature_type::deep_special_tube || local_feature.type == df::feature_type::deep_surface_portal)
return false; return false;
// And Hell *is* Hell. // And Hell *is* Hell.
if (global_feature && global_feature->type == DFHack::feature_Underworld) if (global_feature.type == df::feature_type::feature_underworld_from_layer)
return false; return false;
// otherwise it's safe. // otherwise it's safe.
return true; return true;
@ -38,9 +38,7 @@ bool isSafe(uint32_t x, uint32_t y, uint32_t z, DFHack::Maps *Maps)
struct hideblock struct hideblock
{ {
uint32_t x; df::coord c;
uint32_t y;
uint32_t z;
uint8_t hiddens [16][16]; uint8_t hiddens [16][16];
}; };
@ -160,7 +158,6 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
} }
c->Suspend(); c->Suspend();
DFHack::Maps *Maps =c->getMaps();
DFHack::World *World =c->getWorld(); DFHack::World *World =c->getWorld();
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
@ -170,51 +167,33 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(!Maps->Start()) if (!Maps::IsValid())
{ {
con.printerr("Can't init map.\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(no_hell && !Maps->StartFeatures()) Maps::getSize(x_max,y_max,z_max);
{
con.printerr("Unable to read local features; can't reveal map safely.\n");
c->Resume();
return CR_FAILURE;
}
Maps->getSize(x_max,y_max,z_max);
hidesaved.reserve(x_max * y_max * z_max); hidesaved.reserve(x_max * y_max * z_max);
for(uint32_t x = 0; x< x_max;x++) for (uint32_t i = 0; i < world->map.map_blocks.size(); i++)
{ {
for(uint32_t y = 0; y< y_max;y++) df::map_block *block = world->map.map_blocks[i];
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
if (no_hell && !isSafe(block->map_pos))
continue;
hideblock hb;
hb.c = block->map_pos;
DFHack::designations40d & designations = block->designation;
// for each tile in block
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
{ {
for(uint32_t z = 0; z< z_max;z++) // save hidden state of tile
{ hb.hiddens[x][y] = designations[x][y].bits.hidden;
df_block *block = Maps->getBlock(x,y,z); // set to revealed
if(block) designations[x][y].bits.hidden = 0;
{
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
if (no_hell && !isSafe(x, y, z, Maps))
continue;
hideblock hb;
hb.x = x;
hb.y = y;
hb.z = z;
DFHack::designations40d & designations = block->designation;
// for each tile in block
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
// save hidden state of tile
hb.hiddens[i][j] = designations[i][j].bits.hidden;
// set to revealed
designations[i][j].bits.hidden = 0;
}
hidesaved.push_back(hb);
}
}
} }
hidesaved.push_back(hb);
} }
if(no_hell) if(no_hell)
{ {
@ -255,7 +234,7 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE; return CR_FAILURE;
} }
c->Suspend(); c->Suspend();
DFHack::Maps *Maps =c->getMaps();
DFHack::World *World =c->getWorld(); DFHack::World *World =c->getWorld();
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
@ -265,17 +244,16 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
Maps = c->getMaps(); if (!Maps::IsValid())
if(!Maps->Start())
{ {
con.printerr("Can't init map.\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
// Sanity check: map size // Sanity check: map size
uint32_t x_max_b, y_max_b, z_max_b; uint32_t x_max_b, y_max_b, z_max_b;
Maps->getSize(x_max_b,y_max_b,z_max_b); Maps::getSize(x_max_b,y_max_b,z_max_b);
if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b) if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b)
{ {
con.printerr("The map is not of the same size...\n"); con.printerr("The map is not of the same size...\n");
@ -283,15 +261,13 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE; return CR_FAILURE;
} }
// FIXME: add more sanity checks / MAP ID
for(size_t i = 0; i < hidesaved.size();i++) for(size_t i = 0; i < hidesaved.size();i++)
{ {
hideblock & hb = hidesaved[i]; hideblock & hb = hidesaved[i];
df_block * b = Maps->getBlock(hb.x,hb.y,hb.z); df::map_block * b = Maps::getBlockAbs(hb.c.x,hb.c.y,hb.c.z);
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++) for (uint32_t x = 0; x < 16;x++) for (uint32_t y = 0; y < 16;y++)
{ {
b->designation[i][j].bits.hidden = hb.hiddens[i][j]; b->designation[x][y].bits.hidden = hb.hiddens[x][y];
} }
} }
// give back memory. // give back memory.
@ -336,13 +312,11 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
} }
c->Suspend(); c->Suspend();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
Maps * Maps = c->getMaps();
Gui * Gui = c->getGui(); Gui * Gui = c->getGui();
World * World = c->getWorld(); World * World = c->getWorld();
// init the map if (!Maps::IsValid())
if(!Maps->Start())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -361,7 +335,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16; uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16; uint32_t ty_max = y_max * 16;
@ -373,7 +347,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE; return CR_FAILURE;
} }
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
MapCache * MCache = new MapCache(Maps); MapCache * MCache = new MapCache;
int16_t tt = MCache->tiletypeAt(xy); int16_t tt = MCache->tiletypeAt(xy);
if(isWallTerrain(tt)) if(isWallTerrain(tt))
{ {
@ -383,24 +357,15 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE; return CR_FAILURE;
} }
// hide all tiles, flush cache // hide all tiles, flush cache
Maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
for(uint32_t x = 0; x< x_max;x++) for(uint32_t i = 0; i < world->map.map_blocks.size(); i++)
{ {
for(uint32_t y = 0; y< y_max;y++) df::map_block * b = world->map.map_blocks[i];
// change the hidden flag to 0
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
{ {
for(uint32_t z = 0; z< z_max;z++) b->designation[x][y].bits.hidden = 1;
{
df_block * b = Maps->getBlock(x,y,z);
if(b)
{
// change the hidden flag to 0
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
b->designation[i][j].bits.hidden = 1;
}
}
}
} }
} }
MCache->trash(); MCache->trash();
@ -419,7 +384,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
if(!MCache->testCoord(current)) if(!MCache->testCoord(current))
continue; continue;
int16_t tt = MCache->tiletypeAt(current); int16_t tt = MCache->tiletypeAt(current);
t_designation des = MCache->designationAt(current); df::tile_designation des = MCache->designationAt(current);
if(!des.bits.hidden) if(!des.bits.hidden)
{ {
continue; continue;

@ -19,6 +19,7 @@ using std::set;
#include "modules/Gui.h" #include "modules/Gui.h"
#include "TileTypes.h" #include "TileTypes.h"
#include "modules/MapCache.h" #include "modules/MapCache.h"
#include "df/tile_dig_designation.h"
using namespace MapExtras; using namespace MapExtras;
using namespace DFHack; using namespace DFHack;
@ -640,7 +641,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
uint32_t x_max = 0, y_max = 0, z_max = 0; uint32_t x_max = 0, y_max = 0, z_max = 0;
int32_t x = 0, y = 0, z = 0; int32_t x = 0, y = 0, z = 0;
DFHack::Maps *maps;
DFHack::Gui *gui; DFHack::Gui *gui;
for(int i = 0; i < parameters.size();i++) for(int i = 0; i < parameters.size();i++)
{ {
@ -754,15 +754,14 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
} }
c->Suspend(); c->Suspend();
maps = c->getMaps();
gui = c->getGui(); gui = c->getGui();
if (!maps->Start()) if (!Maps::IsValid())
{ {
c->con.printerr("Cannot get map info!\n"); c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
maps->getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
if (!(gui->Start() && gui->getCursorCoords(x,y,z))) if (!(gui->Start() && gui->getCursorCoords(x,y,z)))
{ {
@ -773,20 +772,20 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z); c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z);
DFHack::DFCoord cursor(x,y,z); DFHack::DFCoord cursor(x,y,z);
MapExtras::MapCache map(maps); MapExtras::MapCache map;
coord_vec all_tiles = brush->points(map, cursor); coord_vec all_tiles = brush->points(map, cursor);
c->con.print("working...\n"); c->con.print("working...\n");
for (coord_vec::iterator iter = all_tiles.begin(); iter != all_tiles.end(); ++iter) for (coord_vec::iterator iter = all_tiles.begin(); iter != all_tiles.end(); ++iter)
{ {
const DFHack::TileRow *source = DFHack::getTileRow(map.tiletypeAt(*iter)); const DFHack::TileRow *source = DFHack::getTileRow(map.tiletypeAt(*iter));
DFHack::t_designation des = map.designationAt(*iter); df::tile_designation des = map.designationAt(*iter);
if ((filter.shape > -1 && filter.shape != source->shape) if ((filter.shape > -1 && filter.shape != source->shape)
|| (filter.material > -1 && filter.material != source->material) || (filter.material > -1 && filter.material != source->material)
|| (filter.special > -1 && filter.special != source->special) || (filter.special > -1 && filter.special != source->special)
|| (filter.variant > -1 && filter.variant != source->variant) || (filter.variant > -1 && filter.variant != source->variant)
|| (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != DFHack::designation_no)) || (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != df::tile_dig_designation::No))
) )
{ {
continue; continue;
@ -865,7 +864,7 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
if (paint.skyview > -1) if (paint.skyview > -1)
{ {
des.bits.skyview = paint.skyview; des.bits.outside = paint.skyview;
} }
// Remove liquid from walls, etc // Remove liquid from walls, etc
@ -891,7 +890,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
{ {
c->con.printerr("Something failed horribly! RUN!\n"); c->con.printerr("Something failed horribly! RUN!\n");
} }
maps->Finish();
c->Resume(); c->Resume();
} }
} }

@ -10,10 +10,12 @@
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Maps.h" #include "modules/Maps.h"
#include "modules/World.h" #include "modules/World.h"
#include "modules/MapCache.h"
#include "modules/Gui.h" #include "modules/Gui.h"
using MapExtras::MapCache; #include "TileTypes.h"
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
using df::global::world;
DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params); DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params);
@ -36,14 +38,8 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params) DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params)
{ {
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
DFHack::tiletypes40d tiles;
int32_t oldT, newT;
uint64_t count = 0; uint64_t count = 0;
int dirty=0;
for(int i = 0; i < params.size();i++) for(int i = 0; i < params.size();i++)
{ {
if(params[i] == "help" || params[i] == "?") if(params[i] == "help" || params[i] == "?")
@ -55,71 +51,58 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
} }
} }
c->Suspend(); c->Suspend();
DFHack::Maps *Mapz = c->getMaps(); if (!Maps::IsValid())
// init the map
if (!Mapz->Start())
{ {
c->con.printerr("Can't init map.\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE;
}
Mapz->getSize(x_max,y_max,z_max);
if(!Mapz->StartFeatures())
{
c->con.printerr("Can't get map features.\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
// walk the map // walk the map
for (uint32_t x = 0; x< x_max;x++) for (uint32_t i = 0; i < world->map.map_blocks.size(); i++)
{ {
for (uint32_t y = 0; y< y_max;y++) df::map_block *block = world->map.map_blocks[i];
df::map_block *above = Maps::getBlockAbs(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1);
if (block->local_feature == -1)
continue;
DFHack::t_feature feature;
DFCoord coord(block->map_pos.x >> 4, block->map_pos.y >> 4, block->map_pos.z);
if (!Maps::GetLocalFeature(feature, coord, block->local_feature))
continue;
if (feature.type != df::feature_type::deep_special_tube)
continue;
for (uint32_t x = 0; x < 16; x++)
{ {
for (uint32_t z = 0; z< z_max;z++) for (uint32_t y = 0; y < 16; y++)
{ {
DFHack::t_feature * locf = 0; if (!block->designation[x][y].bits.feature_local)
DFHack::t_feature * glof = 0; continue;
if (Mapz->ReadFeatures(x,y,z,&locf,&glof))
{
// we're looking for addy tubes
if(!locf) continue;
if(locf->type != DFHack::feature_Adamantine_Tube) continue;
dirty=0; // Is the tile already a wall?
Mapz->ReadDesignations(x,y,z, &designations); if (tileShape(block->tiletype[x][y]) == WALL)
Mapz->ReadTileTypes(x,y,z, &tiles); continue;
for (uint32_t ty=0;ty<16;++ty) // Does the tile contain liquid?
{ if (block->designation[x][y].bits.flow_size)
for (uint32_t tx=0;tx<16;++tx) continue;
{
if(!designations[tx][ty].bits.feature_local) continue;
oldT = tiles[tx][ty];
if ( DFHack::tileShape(oldT) != DFHack::WALL )
{
//Current tile is not a wall.
//Set current tile, as accurately as can be expected
//newT = DFHack::findSimilarTileType(oldT,DFHack::WALL);
newT = DFHack::findTileType( DFHack::WALL, DFHack::FEATSTONE, DFHack::tilevariant_invalid, DFHack::TILE_NORMAL, DFHack::TileDirection() );
//If no change, skip it (couldn't find a good tile type) // Set current tile, as accurately as can be expected
if ( oldT == newT) continue; // block->tiletype[x][y] = findSimilarTileType(block->tiletype[x][y], WALL);
//Set new tile type, clear designation
tiles[tx][ty] = newT; // Check the tile above this one, in case we need to add a floor
dirty=1; if (above)
++count; {
} if ((tileShape(above->tiletype[x][y]) == EMPTY) || (tileShape(above->tiletype[x][y]) == RAMP_TOP))
}
}
//If anything was changed, write it all.
if (dirty)
{ {
Mapz->WriteTileTypes(x,y,z, &tiles); // if this tile isn't a local feature, it's likely the tile underneath was originally just a floor
// it's also possible there was just solid non-feature stone above, but we don't care enough to check
if (!above->designation[x][y].bits.feature_local)
continue;
above->tiletype[x][y] = findTileType(FLOOR, FEATSTONE, tilevariant_invalid, TILE_NORMAL, TileDirection());
} }
} }
block->tiletype[x][y] = findTileType(WALL, FEATSTONE, tilevariant_invalid, TILE_NORMAL, TileDirection());
++count;
} }
} }
} }

@ -70,7 +70,7 @@ enum circle_what
bool dig (MapExtras::MapCache & MCache, bool dig (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
e_designation type, df::tile_dig_designation type,
int32_t x, int32_t y, int32_t z, int32_t x, int32_t y, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
@ -90,7 +90,7 @@ bool dig (MapExtras::MapCache & MCache,
return false; return false;
} }
uint16_t tt = MCache.tiletypeAt(at); uint16_t tt = MCache.tiletypeAt(at);
t_designation des = MCache.designationAt(at); df::tile_designation des = MCache.designationAt(at);
// could be potentially used to locate hidden constructions? // could be potentially used to locate hidden constructions?
if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden) if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
return false; return false;
@ -107,7 +107,7 @@ bool dig (MapExtras::MapCache & MCache,
break; break;
} }
if(isFloorTerrain(tt) if(isFloorTerrain(tt)
&& (type == designation_d_stair || type == designation_channel) && (type == df::tile_dig_designation::DownStair || type == df::tile_dig_designation::Channel)
&& ts != TREE_OK && ts != TREE_OK
&& ts != TREE_DEAD && ts != TREE_DEAD
) )
@ -115,7 +115,7 @@ bool dig (MapExtras::MapCache & MCache,
std::cerr << "allowing tt" << tt << ", is floor\n"; std::cerr << "allowing tt" << tt << ", is floor\n";
break; break;
} }
if(isStairTerrain(tt) && type == designation_channel ) if(isStairTerrain(tt) && type == df::tile_dig_designation::Channel )
break; break;
return false; return false;
} }
@ -124,25 +124,25 @@ bool dig (MapExtras::MapCache & MCache,
switch(what) switch(what)
{ {
case circle_set: case circle_set:
if(des.bits.dig == designation_no) if(des.bits.dig == df::tile_dig_designation::No)
{ {
des.bits.dig = type; des.bits.dig = type;
} }
break; break;
case circle_unset: case circle_unset:
if (des.bits.dig != designation_no) if (des.bits.dig != df::tile_dig_designation::No)
{ {
des.bits.dig = designation_no; des.bits.dig = df::tile_dig_designation::No;
} }
break; break;
case circle_invert: case circle_invert:
if(des.bits.dig == designation_no) if(des.bits.dig == df::tile_dig_designation::No)
{ {
des.bits.dig = type; des.bits.dig = type;
} }
else else
{ {
des.bits.dig = designation_no; des.bits.dig = df::tile_dig_designation::No;
} }
break; break;
} }
@ -153,7 +153,7 @@ bool dig (MapExtras::MapCache & MCache,
bool lineX (MapExtras::MapCache & MCache, bool lineX (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
e_designation type, df::tile_dig_designation type,
int32_t y1, int32_t y2, int32_t x, int32_t z, int32_t y1, int32_t y2, int32_t x, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
@ -167,7 +167,7 @@ bool lineX (MapExtras::MapCache & MCache,
bool lineY (MapExtras::MapCache & MCache, bool lineY (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
e_designation type, df::tile_dig_designation type,
int32_t x1, int32_t x2, int32_t y, int32_t z, int32_t x1, int32_t x2, int32_t y, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
@ -183,7 +183,7 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
{ {
static bool filled = false; static bool filled = false;
static circle_what what = circle_set; static circle_what what = circle_set;
static e_designation type = designation_default; static df::tile_dig_designation type = df::tile_dig_designation::Default;
static int diameter = 0; static int diameter = 0;
auto saved_d = diameter; auto saved_d = diameter;
bool force_help = false; bool force_help = false;
@ -215,27 +215,27 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
} }
else if(parameters[i] == "dig") else if(parameters[i] == "dig")
{ {
type = designation_default; type = df::tile_dig_designation::Default;
} }
else if(parameters[i] == "ramp") else if(parameters[i] == "ramp")
{ {
type = designation_ramp; type = df::tile_dig_designation::Ramp;
} }
else if(parameters[i] == "dstair") else if(parameters[i] == "dstair")
{ {
type = designation_d_stair; type = df::tile_dig_designation::DownStair;
} }
else if(parameters[i] == "ustair") else if(parameters[i] == "ustair")
{ {
type = designation_u_stair; type = df::tile_dig_designation::UpStair;
} }
else if(parameters[i] == "xstair") else if(parameters[i] == "xstair")
{ {
type = designation_ud_stair; type = df::tile_dig_designation::UpDownStair;
} }
else if(parameters[i] == "chan") else if(parameters[i] == "chan")
{ {
type = designation_channel; type = df::tile_dig_designation::Channel;
} }
else if (!from_string(diameter,parameters[i], std::dec)) else if (!from_string(diameter,parameters[i], std::dec))
{ {
@ -275,18 +275,17 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
int32_t cx, cy, cz; int32_t cx, cy, cz;
c->Suspend(); c->Suspend();
Gui * gui = c->getGui(); Gui * gui = c->getGui();
Maps * maps = c->getMaps(); if (!Maps::IsValid())
if(!maps->Start())
{ {
c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
c->con.printerr("Can't init the map...\n");
return CR_FAILURE; return CR_FAILURE;
} }
uint32_t x_max, y_max, z_max; uint32_t x_max, y_max, z_max;
maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
MapExtras::MapCache MCache (maps); MapExtras::MapCache MCache;
if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000) if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000)
{ {
c->Resume(); c->Resume();
@ -726,13 +725,12 @@ enum explo_what
EXPLO_DESIGNATED, EXPLO_DESIGNATED,
}; };
bool stamp_pattern (DFHack::Maps * maps, bool stamp_pattern (uint32_t bx, uint32_t by, int z_level,
uint32_t bx, uint32_t by, int z_level,
digmask & dm, explo_how how, explo_what what, digmask & dm, explo_how how, explo_what what,
int x_max, int y_max int x_max, int y_max
) )
{ {
df_block * bl = maps->getBlock(bx,by,z_level); df::map_block * bl = Maps::getBlock(bx,by,z_level);
if(!bl) if(!bl)
return false; return false;
int x = 0,mx = 16; int x = 0,mx = 16;
@ -749,34 +747,34 @@ bool stamp_pattern (DFHack::Maps * maps,
my = 15; my = 15;
for(; y < my; y++) for(; y < my; y++)
{ {
naked_designation & des = bl->designation[x][y].bits; df::tile_designation & des = bl->designation[x][y];
short unsigned int tt = bl->tiletype[x][y]; short unsigned int tt = bl->tiletype[x][y];
// could be potentially used to locate hidden constructions? // could be potentially used to locate hidden constructions?
if(tileMaterial(tt) == CONSTRUCTED && !des.hidden) if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
continue; continue;
if(!isWallTerrain(tt) && !des.hidden) if(!isWallTerrain(tt) && !des.bits.hidden)
continue; continue;
if(how == EXPLO_CLEAR) if(how == EXPLO_CLEAR)
{ {
des.dig = designation_no; des.bits.dig = df::tile_dig_designation::No;
continue; continue;
} }
if(dm[y][x]) if(dm[y][x])
{ {
if(what == EXPLO_ALL if(what == EXPLO_ALL
|| des.dig == designation_default && what == EXPLO_DESIGNATED || des.bits.dig == df::tile_dig_designation::Default && what == EXPLO_DESIGNATED
|| des.hidden && what == EXPLO_HIDDEN) || des.bits.hidden && what == EXPLO_HIDDEN)
{ {
des.dig = designation_default; des.bits.dig = df::tile_dig_designation::Default;
} }
} }
else if(what == EXPLO_DESIGNATED) else if(what == EXPLO_DESIGNATED)
{ {
des.dig = designation_no; des.bits.dig = df::tile_dig_designation::No;
} }
} }
} }
bl->flags.set(BLOCK_DESIGNATED); bl->flags.set(df::block_flags::Designated);
return true; return true;
}; };
@ -854,15 +852,14 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
} }
c->Suspend(); c->Suspend();
Gui * gui = c->getGui(); Gui * gui = c->getGui();
Maps * maps = c->getMaps();
uint32_t x_max, y_max, z_max; uint32_t x_max, y_max, z_max;
if(!maps->Start()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n");
c->Resume(); c->Resume();
c->con.printerr("Can't init the map...\n");
return CR_FAILURE; return CR_FAILURE;
} }
maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
int32_t xzzz,yzzz,z_level; int32_t xzzz,yzzz,z_level;
if(!gui->getViewCoords(xzzz,yzzz,z_level)) if(!gui->getViewCoords(xzzz,yzzz,z_level))
{ {
@ -878,7 +875,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
for(int32_t y = 0 ; y < y_max; y++) for(int32_t y = 0 ; y < y_max; y++)
{ {
which = (4*x + y) % 5; which = (4*x + y) % 5;
stamp_pattern(maps, x,y_max - 1 - y, z_level, diag5[which], stamp_pattern(x,y_max - 1 - y, z_level, diag5[which],
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
@ -891,7 +888,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
for(int32_t y = 0 ; y < y_max; y++) for(int32_t y = 0 ; y < y_max; y++)
{ {
which = (4*x + 1000-y) % 5; which = (4*x + 1000-y) % 5;
stamp_pattern(maps, x,y_max - 1 - y, z_level, diag5r[which], stamp_pattern(x,y_max - 1 - y, z_level, diag5r[which],
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
@ -904,7 +901,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
which = x % 3; which = x % 3;
for(int32_t y = 0 ; y < y_max; y++) for(int32_t y = 0 ; y < y_max; y++)
{ {
stamp_pattern(maps, x, y, z_level, ladder[which], stamp_pattern(x, y, z_level, ladder[which],
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
@ -917,7 +914,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
which = y % 3; which = y % 3;
for(uint32_t x = 0; x < x_max; x++) for(uint32_t x = 0; x < x_max; x++)
{ {
stamp_pattern(maps, x, y, z_level, ladderr[which], stamp_pattern(x, y, z_level, ladderr[which],
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
@ -927,7 +924,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
// middle + recentering for the image // middle + recentering for the image
int xmid = x_max * 8 - 8; int xmid = x_max * 8 - 8;
int ymid = y_max * 8 - 8; int ymid = y_max * 8 - 8;
MapExtras::MapCache mx (maps); MapExtras::MapCache mx;
for(int x = 0; x < 16; x++) for(int x = 0; x < 16; x++)
for(int y = 0; y < 16; y++) for(int y = 0; y < 16; y++)
{ {
@ -935,14 +932,14 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
short unsigned int tt = mx.tiletypeAt(pos); short unsigned int tt = mx.tiletypeAt(pos);
if(tt == 0) if(tt == 0)
continue; continue;
t_designation des = mx.designationAt(pos); df::tile_designation des = mx.designationAt(pos);
if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden) if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
continue; continue;
if(!isWallTerrain(tt) && !des.bits.hidden) if(!isWallTerrain(tt) && !des.bits.hidden)
continue; continue;
if(cross[y][x]) if(cross[y][x])
{ {
des.bits.dig = designation_default; des.bits.dig = df::tile_dig_designation::Default;
mx.setDesignationAt(pos,des); mx.setDesignationAt(pos,des);
} }
} }
@ -952,7 +949,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
{ {
for(int32_t y = 0 ; y < y_max; y++) for(int32_t y = 0 ; y < y_max; y++)
{ {
stamp_pattern(maps, x, y, z_level, all_tiles, stamp_pattern(x, y, z_level, all_tiles,
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
@ -983,17 +980,15 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
Console & con = c->con; Console & con = c->con;
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
// init the map if (!Maps::IsValid())
if(!Maps->Start())
{ {
con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Map is not available!\n");
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16; uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16; uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz); Gui->getCursorCoords(cx,cy,cz);
@ -1008,8 +1003,8 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
con.printerr("I won't dig the borders. That would be cheating!\n"); con.printerr("I won't dig the borders. That would be cheating!\n");
return CR_FAILURE; return CR_FAILURE;
} }
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); MapExtras::MapCache * MCache = new MapExtras::MapCache;
DFHack::t_designation des = MCache->designationAt(xy); df::tile_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy); int16_t tt = MCache->tiletypeAt(xy);
int16_t veinmat = MCache->veinMaterialAt(xy); int16_t veinmat = MCache->veinMaterialAt(xy);
if( veinmat == -1 ) if( veinmat == -1 )
@ -1034,9 +1029,9 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
continue; continue;
// found a good tile, dig+unset material // found a good tile, dig+unset material
DFHack::t_designation des = MCache->designationAt(current); df::tile_designation des = MCache->designationAt(current);
DFHack::t_designation des_minus; df::tile_designation des_minus;
DFHack::t_designation des_plus; df::tile_designation des_plus;
des_plus.whole = des_minus.whole = 0; des_plus.whole = des_minus.whole = 0;
int16_t vmat_minus = -1; int16_t vmat_minus = -1;
int16_t vmat_plus = -1; int16_t vmat_plus = -1;
@ -1095,32 +1090,32 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
{ {
flood.push(current-1); flood.push(current-1);
if(des_minus.bits.dig == DFHack::designation_d_stair) if(des_minus.bits.dig == df::tile_dig_designation::DownStair)
des_minus.bits.dig = DFHack::designation_ud_stair; des_minus.bits.dig = df::tile_dig_designation::UpDownStair;
else else
des_minus.bits.dig = DFHack::designation_u_stair; des_minus.bits.dig = df::tile_dig_designation::UpStair;
MCache->setDesignationAt(current-1,des_minus); MCache->setDesignationAt(current-1,des_minus);
des.bits.dig = DFHack::designation_d_stair; des.bits.dig = df::tile_dig_designation::DownStair;
} }
if(current.z < z_max - 1 && above && vmat_plus == vmat2) if(current.z < z_max - 1 && above && vmat_plus == vmat2)
{ {
flood.push(current+ 1); flood.push(current+ 1);
if(des_plus.bits.dig == DFHack::designation_u_stair) if(des_plus.bits.dig == df::tile_dig_designation::UpStair)
des_plus.bits.dig = DFHack::designation_ud_stair; des_plus.bits.dig = df::tile_dig_designation::UpDownStair;
else else
des_plus.bits.dig = DFHack::designation_d_stair; des_plus.bits.dig = df::tile_dig_designation::DownStair;
MCache->setDesignationAt(current+1,des_plus); MCache->setDesignationAt(current+1,des_plus);
if(des.bits.dig == DFHack::designation_d_stair) if(des.bits.dig == df::tile_dig_designation::DownStair)
des.bits.dig = DFHack::designation_ud_stair; des.bits.dig = df::tile_dig_designation::UpDownStair;
else else
des.bits.dig = DFHack::designation_u_stair; des.bits.dig = df::tile_dig_designation::UpStair;
} }
} }
if(des.bits.dig == DFHack::designation_no) if(des.bits.dig == df::tile_dig_designation::No)
des.bits.dig = DFHack::designation_default; des.bits.dig = df::tile_dig_designation::Default;
MCache->setDesignationAt(current,des); MCache->setDesignationAt(current,des);
} }
} }