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;
}; };
} }

@ -36,7 +36,20 @@ distribution.
#include <vector> #include <vector>
#include "Virtual.h" #include "Virtual.h"
#include "BitArray.h" #include "BitArray.h"
#include "Materials.h" #include "modules/Materials.h"
#include "df/world.h"
#include "df/feature_type.h"
#include "df/map_block.h"
#include "df/block_square_event.h"
#include "df/block_square_event_mineralst.h"
#include "df/block_square_event_frozen_liquidst.h"
#include "df/block_square_event_world_constructionst.h"
#include "df/block_square_event_material_spatterst.h"
#include "df/block_square_event_grassst.h"
#include "df/tile_liquid.h"
#include "df/tile_dig_designation.h"
#include "df/tile_traffic.h"
/** /**
* \defgroup grp_maps Maps module and its types * \defgroup grp_maps Maps module and its types
@ -48,91 +61,13 @@ namespace DFHack
/*************************************************************************** /***************************************************************************
T Y P E S T Y P E S
***************************************************************************/ ***************************************************************************/
/**
* \ingroup grp_maps
*/
enum e_feature
{
feature_Other,
feature_Adamantine_Tube,
feature_Underworld,
feature_Hell_Temple
};
/** /**
* Function for translating feature index to its name * Function for translating feature index to its name
* \ingroup grp_maps * \ingroup grp_maps
*/ */
extern DFHACK_EXPORT const char * sa_feature(e_feature index); extern DFHACK_EXPORT const char * sa_feature(df::feature_type index);
/** typedef df::coord DFCoord;
* Class for holding a world coordinate. Can do math with coordinates and can be used as an index for std::map
* \ingroup grp_maps
*/
class DFCoord
{
public:
DFCoord(uint16_t _x, uint16_t _y, uint16_t _z = 0): x(_x), y(_y), z(_z) {}
DFCoord()
{
comparate = 0;
}
bool operator==(const DFCoord &other) const
{
return (other.comparate == comparate);
}
bool operator!=(const DFCoord &other) const
{
return (other.comparate != comparate);
}
// FIXME: <tomprince> peterix_: you could probably get away with not defining operator< if you defined a std::less specialization for Vertex.
bool operator<(const DFCoord &other) const
{
return comparate < other.comparate;
}
DFCoord operator/(int number) const
{
return DFCoord(x/number, y/number, z);
}
DFCoord operator*(int number) const
{
return DFCoord(x*number, y*number, z);
}
DFCoord operator%(int number) const
{
return DFCoord(x%number, y%number, z);
}
DFCoord operator-(int number) const
{
return DFCoord(x,y,z-number);
}
DFCoord operator+(int number) const
{
return DFCoord(x,y,z+number);
}
// this is a hack. beware.
// x,y,z share the same space with comparate. comparate can be used for fast comparisons
union
{
// new shiny DFCoord struct. notice the ludicrous space for Z-levels
struct
{
uint16_t x;
uint16_t y;
uint32_t z;
};
// old planeccord struct for compatibility
struct
{
uint16_t x;
uint16_t y;
} dim;
// comparing thing
uint64_t comparate;
};
};
/**
* \ingroup grp_maps
*/
typedef DFCoord planecoord; typedef DFCoord planecoord;
/** /**
@ -141,7 +76,7 @@ namespace DFHack
*/ */
struct t_feature struct t_feature
{ {
e_feature type; df::feature_type type;
/// main material type - decides between stuff like bodily fluids, inorganics, vomit, amber, etc. /// main material type - decides between stuff like bodily fluids, inorganics, vomit, amber, etc.
int16_t main_material; int16_t main_material;
/// generally some index to a vector of material types. /// generally some index to a vector of material types.
@ -152,97 +87,6 @@ namespace DFHack
void * origin; void * origin;
}; };
/**
* mineral vein object - bitmap with a material type
* \ingroup grp_maps
*/
struct t_vein : public t_virtual
{
/// index into the inorganic material vector
int32_t type;
/// bit mask describing how the vein maps to the map block
/// assignment[y] & (1 << x) describes the tile (x, y) of the block
int16_t assignment[16];
uint32_t flags; // FIXME: figure those out
//zilpin: Functions to more conveniently check the assignment flags of the vein.
//Coordinates are given in tile within the block.
//Important to make these inline.
inline bool getassignment( DFCoord & xy )
{
return getassignment(xy.x,xy.y);
}
inline bool getassignment( int x, int y )
{
return (assignment[y] & (1 << x));
}
inline void setassignment( DFCoord & xy, bool bit )
{
return setassignment(xy.x,xy.y, bit);
}
inline void setassignment( int x, int y, bool bit )
{
if(bit)
assignment[y] |= (1 << x);
else
assignment[y] &= 0xFFFF ^ (1 << x);
}
};
/**
* stores what tiles should appear when the ice melts - bitmap of material types
* \ingroup grp_maps
*/
struct t_frozenliquidvein : public t_virtual
{
/// a 16x16 array of the original tile types
int16_t tiles[16][16];
};
/**
* a 'spattervein' defines what coverings the individual map tiles have (snow, blood, etc)
* bitmap of intensity with matrial type
* \ingroup grp_maps
* @see PrintSplatterType
*/
struct t_spattervein : public t_virtual
{
/// generic material.
t_materialType mat1;
/// material vector index
t_materialIndex mat2;
/**
* matter state - liquid/solid/etc.
* @ref e_matter_state
*/
uint16_t matter_state;
/// 16x16 array of covering 'intensity'
uint8_t intensity[16][16];
};
/**
* a 'grass vein' defines the grass coverage of a map block
* bitmap of density (max = 100) with plant material type
* \ingroup grp_maps
*/
struct t_grassvein : public t_virtual
{
/// material vector index
t_materialIndex material;
/// 16x16 array of covering 'intensity'
uint8_t intensity[16][16];
};
/**
* defines the world constructions present. The material member is a mystery.
* \ingroup grp_maps
*/
struct t_worldconstruction : public t_virtual
{
/// material vector index
uint32_t material;
/// 16x16 array of bits
uint16_t assignment[16];
};
/** /**
* \ingroup grp_maps * \ingroup grp_maps
*/ */
@ -260,184 +104,6 @@ namespace DFHack
eBiomeCount eBiomeCount
}; };
/**
* \ingroup grp_maps
*/
enum e_traffic
{
traffic_normal,
traffic_low,
traffic_high,
traffic_restricted
};
/**
* type of a designation for a tile
* \ingroup grp_maps
*/
enum e_designation
{
/// no designation
designation_no,
/// dig walls, remove stairs and ramps, gather plants, fell trees. depends on tile type
designation_default,
/// dig up/down stairs
designation_ud_stair,
/// dig a channel
designation_channel,
/// dig ramp out of a wall
designation_ramp,
/// dig a stair down
designation_d_stair,
/// dig a stair up
designation_u_stair,
/// whatever. for completenes I guess
designation_7
};
/**
* type of liquid in a tile
* \ingroup grp_maps
*/
enum e_liquidtype
{
liquid_water,
liquid_magma
};
/**
* designation bit field
* \ingroup grp_maps
*/
struct naked_designation
{
unsigned int flow_size : 3; // how much liquid is here?
unsigned int pile : 1; // stockpile?
/// All the different dig designations
e_designation dig : 3;
unsigned int smooth : 2;
unsigned int hidden : 1;
/**
* This one is rather involved, but necessary to retrieve the base layer matgloss index
* @see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284
*/
unsigned int geolayer_index :4;
unsigned int light : 1;
unsigned int subterranean : 1; // never seen the light of day?
unsigned int skyview : 1; // sky is visible now, it rains in here when it rains
/**
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
* we don't use this yet
*/
unsigned int biome : 4;
/**
* 0 = water
* 1 = magma
*/
e_liquidtype liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
e_traffic traffic : 2;
/// the tile is not evaluated when calculating flows?
unsigned int flow_forbid : 1;
/// no liquid spreading
unsigned int liquid_static : 1;
/// this tile is a part of a local feature. can be combined with 'featstone' tiles
unsigned int feature_local : 1;
/// this tile is a part of a global feature. can be combined with 'featstone' tiles
unsigned int feature_global : 1;
unsigned int water_stagnant : 1;
unsigned int water_salt : 1;
};
/**
* designation bit field wrapper
* \ingroup grp_maps
*/
union t_designation
{
uint32_t whole;
naked_designation bits;
};
/**
* occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
* \ingroup grp_maps
*/
struct naked_occupancy
{
/// 0-2: building type... should be an enum.
unsigned int building : 3;// 0-2
/// 3: the tile contains a standing creature
unsigned int unit : 1; // 3
/// 4: the tile contains a prone creature
unsigned int unit_grounded : 1;
/// 5: the tile contains an item
unsigned int item : 1;
/// 6: set on magma sea tiles, cavern lake tiles, rivers. not set on pools. probably something like 'inhibit growth'?
unsigned int unk6 : 1;
/// 7: mossy!
unsigned int moss : 1;
/// 8-11: arrow color. 0 = no arrow
unsigned int arrow_color : 4;
/// 12: arrow orientaton
unsigned int broken_arrows_variant : 1;
/// 13
unsigned int unk13 : 1;
/// 14: A monster lair. Items placed won't be moved.
unsigned int monster_lair : 1;
/**
* 15: seems to be set on terrain tiles where grass growth is impossible
* pebbles, boulders, rock floors in the middle of grass. also shrubs. but not trees
*/
unsigned int no_grow : 1;
/// 16
unsigned int unk16 : 1;
/// 17
unsigned int unk17 : 1;
/// 18
unsigned int unk18 : 1;
/// 19
unsigned int unk19 : 1;
/// 20
unsigned int unk20 : 1;
/// 21
unsigned int unk21 : 1;
/// 22
unsigned int unk22 : 1;
/// 23
unsigned int unk23 : 1;
/// 24
unsigned int unk24 : 1;
/// 25
unsigned int unk25 : 1;
/// 26
unsigned int unk26 : 1;
/// 27
unsigned int unk27 : 1;
/// 28
unsigned int unk28 : 1;
/// 29
unsigned int unk29 : 1;
/// 30
unsigned int unk30 : 1;
/// 31
unsigned int unk31 : 1;
};
/**
* occupancy flags (rat,dwarf,horse,built wall,not build wall,etc) wrapper
* \ingroup grp_maps
*/
union t_occupancy
{
uint32_t whole;
naked_occupancy bits;
};
/** /**
* map block flags * map block flags
* \ingroup grp_maps * \ingroup grp_maps
@ -454,16 +120,6 @@ namespace DFHack
/// rest of the flags is completely unknown /// rest of the flags is completely unknown
unsigned int unk_2: 4; unsigned int unk_2: 4;
}; };
enum e_block_flags
{
/// designated for jobs (digging and stuff like that)
BLOCK_DESIGNATED,
/// possibly related to the designated flag
BLOCK_UNKN1,
/// two flags required for liquid flow.
BLOCK_LIQUIDFLOW_1,
BLOCK_LIQUIDFLOW_2,
};
/** /**
* map block flags wrapper * map block flags wrapper
* \ingroup grp_maps * \ingroup grp_maps
@ -488,12 +144,12 @@ namespace DFHack
* 16x16 array of designation flags * 16x16 array of designation flags
* \ingroup grp_maps * \ingroup grp_maps
*/ */
typedef DFHack::t_designation designations40d [16][16]; typedef df::tile_designation designations40d [16][16];
/** /**
* 16x16 array of occupancy flags * 16x16 array of occupancy flags
* \ingroup grp_maps * \ingroup grp_maps
*/ */
typedef DFHack::t_occupancy occupancies40d [16][16]; typedef df::tile_occupancy occupancies40d [16][16];
/** /**
* array of 16 biome indexes valid for the block * array of 16 biome indexes valid for the block
* \ingroup grp_maps * \ingroup grp_maps
@ -520,142 +176,45 @@ namespace DFHack
/// values used for geology/biome assignment /// values used for geology/biome assignment
biome_indices40d biome_indices; biome_indices40d biome_indices;
/// the address where the block came from /// the address where the block came from
uint32_t origin; void * origin;
t_blockflags blockflags; t_blockflags blockflags;
/// index into the global feature vector /// index into the global feature vector
int16_t global_feature; int32_t global_feature;
/// index into the local feature vector... complicated /// index into the local feature vector... complicated
int16_t local_feature; int32_t local_feature;
int32_t mystery; int32_t mystery;
} mapblock40d; } mapblock40d;
// A raw DF block.
// one of the vector is the 'effects' vector. another should be item id/index vector
struct df_block
{
BitArray <e_block_flags> flags;
// how to handle this virtual mess?
std::vector <t_virtual *> block_events;
// no idea what these are
long unk1;
long unk2;
long unk3;
// feature indexes
signed long local_feature; // local feature index, -1 = no local feature
signed long global_feature; // global feature index, -1 = no global feature
signed long mystery; // no idea. couldn't manage to catch its use in debugger.
// more mysterious numbers
long unk4;
long unk5;
long unk6;
std::vector <unsigned long> items; // item related - probly item IDs
std::vector <void *> effects;
signed long unk7; // -1 most of the time, another index?
unsigned long unk8; // again, index?
std::vector<df_plant *> plants;
unsigned short map_x;
unsigned short map_y;
unsigned short map_z;
unsigned short region_x;
unsigned short region_y;
unsigned short tiletype[16][16]; // weird 2-byte alignment here
t_designation designation[16][16];
t_occupancy occupancy[16][16];
// following is uncertain, but total length should be fixed.
unsigned char unk9[16][16];
unsigned long pathfinding[16][16];
unsigned short unk10[16][16];
unsigned short unk11[16][16];
unsigned short unk12[16][16];
// end uncertain section
unsigned short temperature_1[16][16];
unsigned short temperature_2[16][16];
// no idea again. needs research...
unsigned short unk13[16][16];
unsigned short unk14[16][16];
unsigned char region_offset[9];
};
template <typename T>
struct df_array
{
inline T& operator[] (uint32_t index)
{
return array[index];
};
T * array;
};
template <typename T>
struct df_2darray
{
inline df_array<T>& operator[] (uint32_t index)
{
return array[index];
};
df_array <T> * array;
};
template <typename T>
struct df_3darray
{
inline df_2darray<T>& operator[] (uint32_t index)
{
return array[index];
};
inline bool operator! ()
{
return !array;
}
df_2darray <T> * array;
};
struct map_data
{
df_3darray<df_block *> map;
std::vector <void *> unk1;
void * unk2;
uint32_t x_size_blocks;
uint32_t y_size_blocks;
uint32_t z_size_blocks;
uint32_t x_size;
uint32_t y_size;
uint32_t z_size;
int32_t x_area_offset;
int32_t y_area_offset;
int32_t z_area_offset;
};
/** /**
* The Maps module * The Maps module
* \ingroup grp_modules * \ingroup grp_modules
* \ingroup grp_maps * \ingroup grp_maps
*/ */
class DFHACK_EXPORT Maps : public Module namespace Simple
{
namespace Maps
{ {
public:
// the map data of DF, as we know it.
map_data * mdata;
Maps(); extern DFHACK_EXPORT bool IsValid();
~Maps();
bool Start();
bool Finish();
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss
/** /**
Method for reading the geological surrounding of the currently loaded region. * Method for reading the geological surrounding of the currently loaded region.
assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data * assign is a reference to an array of nine vectors of unsigned words that are to be filled with the data
array is indexed by the BiomeOffset enum * array is indexed by the BiomeOffset enum
*
I omitted resolving the layer matgloss in this API, because it would * I omitted resolving the layer matgloss in this API, because it would
introduce overhead by calling some method for each tile. You have to do it * introduce overhead by calling some method for each tile. You have to do it
yourself. * yourself.
*
First get the stuff from ReadGeology and then for each block get the RegionOffsets. * First get the stuff from ReadGeology and then for each block get the RegionOffsets.
For each tile get the real region from RegionOffsets and cross-reference it with * For each tile get the real region from RegionOffsets and cross-reference it with
the geology stuff (region -- array of vectors, depth -- vector). * the geology stuff (region -- array of vectors, depth -- vector).
I'm thinking about turning that Geology stuff into a two-dimensional array * I'm thinking about turning that Geology stuff into a two-dimensional array
with static size. * with static size.
*
this is the algorithm for applying matgloss: * this is the algorithm for applying matgloss:
@code * @code
void DfMap::applyGeoMatgloss(Block * b) void DfMap::applyGeoMatgloss(Block * b)
{ {
// load layer matgloss // load layer matgloss
@ -670,122 +229,101 @@ namespace DFHack
} }
} }
} }
@endcode
*/
bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
/** * @endcode
* Initialize the map feature caches, if possible
*/
bool StartFeatures();
/**
* Free the feature cache
*/ */
bool StopFeatures(); extern DFHACK_EXPORT bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
/**
* Get a global feature with the given index.
*/
t_feature * GetGlobalFeature(int16_t index);
/**
* Get all valid local features for a x/y block coord.
*/
std::vector <t_feature *> * GetLocalFeatures(DFCoord coord);
/** /**
* Get the feature indexes of a block * Get the feature indexes of a block
*/ */
bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int16_t & global); extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int32_t & local, int32_t & global);
/** /**
* Set the feature indexes of a block * Set the feature indexes of a block
*/ */
bool WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int16_t & local, const int16_t & global); extern DFHACK_EXPORT bool WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int32_t & local, const int32_t & global);
/** /**
* Get pointers to features of a block * Get pointers to features of a block
*/ */
bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local, t_feature ** global); extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature * local, t_feature * global);
/** /**
* Get pointers to features of an already read block * Get pointers to features of an already read block
*/ */
bool ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global); extern DFHACK_EXPORT bool ReadFeatures(mapblock40d * block, t_feature * local, t_feature * global);
/** /**
* @deprecated * Read a specific global or local feature directly
* @todo: remove
*/ */
bool ReadGlobalFeatures( std::vector <t_feature> & features); extern DFHACK_EXPORT bool GetGlobalFeature(t_feature &feature, int32_t index);
/** extern DFHACK_EXPORT bool GetLocalFeature(t_feature &feature, df::coord2d coord, int32_t index);
* @deprecated
* @todo: remove
*/
bool ReadLocalFeatures( std::map <DFCoord, std::vector<t_feature *> > & local_features );
/* /*
* BLOCK DATA * BLOCK DATA
*/ */
/// get size of the map in tiles /// get size of the map in tiles
void getSize(uint32_t& x, uint32_t& y, uint32_t& z); extern DFHACK_EXPORT void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
/// get the position of the map on world map /// get the position of the map on world map
void getPosition(int32_t& x, int32_t& y, int32_t& z); extern DFHACK_EXPORT void getPosition(int32_t& x, int32_t& y, int32_t& z);
/** /**
* Get the map block or NULL if block is not valid * Get the map block or NULL if block is not valid
*/ */
df_block * getBlock (uint32_t blockx, uint32_t blocky, uint32_t blockz); extern DFHACK_EXPORT df::map_block * getBlock (int32_t blockx, int32_t blocky, int32_t blockz);
extern DFHACK_EXPORT df::map_block * getBlockAbs (int32_t x, int32_t y, int32_t z);
/// copy the whole map block at block coords (see DFTypes.h for the block structure) /// copy the whole map block at block coords (see DFTypes.h for the block structure)
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer); extern DFHACK_EXPORT bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer);
/// copy/write block tile types /// copy/write block tile types
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer); extern DFHACK_EXPORT bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer); extern DFHACK_EXPORT bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
/// copy/write block designations /// copy/write block designations
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); extern DFHACK_EXPORT bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer); extern DFHACK_EXPORT bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
/// copy/write temperatures /// copy/write temperatures
bool ReadTemperatures(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2); extern DFHACK_EXPORT bool ReadTemperatures(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2);
bool WriteTemperatures (uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2); extern DFHACK_EXPORT bool WriteTemperatures (uint32_t blockx, uint32_t blocky, uint32_t blockz, t_temperatures *temp1, t_temperatures *temp2);
/// copy/write block occupancies /// copy/write block occupancies
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); extern DFHACK_EXPORT bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer); extern DFHACK_EXPORT bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
/// copy/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging /// copy/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit); extern DFHACK_EXPORT bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit); extern DFHACK_EXPORT bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// copy/write the block flags /// copy/write the block flags
bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags &blockflags); extern DFHACK_EXPORT bool ReadBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags &blockflags);
bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags blockflags); extern DFHACK_EXPORT bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz, t_blockflags blockflags);
/// copy/write features /// copy/write features
bool SetBlockLocalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t local = -1); extern DFHACK_EXPORT bool SetBlockLocalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int32_t local = -1);
bool SetBlockGlobalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t local = -1); extern DFHACK_EXPORT bool SetBlockGlobalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int32_t global = -1);
/// copy region offsets of a block - used for determining layer stone matgloss /// copy region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, extern DFHACK_EXPORT bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz,
biome_indices40d *buffer); biome_indices40d *buffer);
/// sorts the block event vector into multiple vectors by type /// sorts the block event vector into multiple vectors by type
/// mineral veins, what's under ice, blood smears and mud /// mineral veins, what's under ice, blood smears and mud
bool SortBlockEvents(uint32_t x, uint32_t y, uint32_t z, extern DFHACK_EXPORT bool SortBlockEvents(uint32_t x, uint32_t y, uint32_t z,
std::vector<t_vein *>* veins, std::vector<df::block_square_event_mineralst *>* veins,
std::vector<t_frozenliquidvein *>* ices = 0, std::vector<df::block_square_event_frozen_liquidst *>* ices = 0,
std::vector<t_spattervein *>* splatter = 0, std::vector<df::block_square_event_material_spatterst *>* splatter = 0,
std::vector<t_grassvein *>* grass = 0, std::vector<df::block_square_event_grassst *>* grass = 0,
std::vector<t_worldconstruction *>* constructions = 0 std::vector<df::block_square_event_world_constructionst *>* constructions = 0
); );
/// remove a block event from the block by address /// remove a block event from the block by address
bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, t_virtual * which ); extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which );
/// read all plants in this block /// read all plants in this block
bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df_plant *>*& plants); extern DFHACK_EXPORT bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df_plant *>*& plants);
private: }
struct Private; }
Private *d;
};
} }
#endif #endif

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,31 +99,28 @@ 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; int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ); Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000) if(cursorX == -30000)
{ {
con.printerr("No cursor; place cursor over tile to probe.\n"); con.printerr("No cursor; place cursor over tile to probe.\n");
c->Resume();
return CR_FAILURE;
} }
else
{
DFCoord cursor (cursorX,cursorY,cursorZ); DFCoord cursor (cursorX,cursorY,cursorZ);
uint32_t blockX = cursorX / 16; uint32_t blockX = cursorX / 16;
@ -132,9 +129,13 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
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");
c->Resume();
return CR_OK;
}
mapblock40d & block = b->raw;
con.print("block addr: 0x%x\n\n", block.origin); con.print("block addr: 0x%x\n\n", block.origin);
/* /*
if (showBlock) if (showBlock)
@ -145,7 +146,7 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
} }
*/ */
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)
{ {
@ -189,8 +190,8 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
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)
@ -217,63 +218,55 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
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("%-16s", "");
con.print(" %4d", block.local_feature); con.print(" %4d", block.local_feature);
con.print(" (%2d)", local->type); con.print(" (%2d)", local.type);
con.print(" addr 0x%X ", local->origin); con.print(" addr 0x%X ", local.origin);
con.print(" %s\n", sa_feature(local->type)); con.print(" %s\n", sa_feature(local.type));
} }
PRINT_FLAG( feature_global ); PRINT_FLAG( bits.feature_global );
if(global) if(global.type != -1)
{ {
con.print("%-16s", ""); con.print("%-16s", "");
con.print(" %4d", block.global_feature); con.print(" %4d", block.global_feature);
con.print(" (%2d)", global->type); con.print(" (%2d)", global.type);
con.print(" %s\n", sa_feature(global->type)); con.print(" %s\n", sa_feature(global.type));
}
}
else
{
PRINT_FLAG( feature_local );
PRINT_FLAG( feature_global );
} }
#undef PRINT_FLAG #undef PRINT_FLAG
con << "local feature idx: " << block.local_feature con << "local feature idx: " << block.local_feature
@ -282,13 +275,6 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
<< endl; << endl;
con << "mystery: " << block.mystery << endl; con << "mystery: " << block.mystery << endl;
con << std::endl; con << std::endl;
}
else
{
con.printerr("No data.\n");
}
}
}
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,52 +167,34 @@ 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++)
{
for(uint32_t z = 0; z< z_max;z++)
{
df_block *block = Maps->getBlock(x,y,z);
if(block)
{ {
df::map_block *block = world->map.map_blocks[i];
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine // in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
if (no_hell && !isSafe(x, y, z, Maps)) if (no_hell && !isSafe(block->map_pos))
continue; continue;
hideblock hb; hideblock hb;
hb.x = x; hb.c = block->map_pos;
hb.y = y;
hb.z = z;
DFHack::designations40d & designations = block->designation; DFHack::designations40d & designations = block->designation;
// for each tile in block // for each tile in block
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++)
{ {
// save hidden state of tile // save hidden state of tile
hb.hiddens[i][j] = designations[i][j].bits.hidden; hb.hiddens[x][y] = designations[x][y].bits.hidden;
// set to revealed // set to revealed
designations[i][j].bits.hidden = 0; designations[x][y].bits.hidden = 0;
} }
hidesaved.push_back(hb); hidesaved.push_back(hb);
} }
}
}
}
if(no_hell) if(no_hell)
{ {
revealed = SAFE_REVEALED; revealed = SAFE_REVEALED;
@ -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++)
{
for(uint32_t z = 0; z< z_max;z++)
{
df_block * b = Maps->getBlock(x,y,z);
if(b)
{ {
df::map_block * b = world->map.map_blocks[i];
// change the hidden flag to 0 // change the hidden flag to 0
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 = 1; b->designation[x][y].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);
for (uint32_t z = 0; z< z_max;z++) if (block->local_feature == -1)
{ continue;
DFHack::t_feature * locf = 0; DFHack::t_feature feature;
DFHack::t_feature * glof = 0; DFCoord coord(block->map_pos.x >> 4, block->map_pos.y >> 4, block->map_pos.z);
if (Mapz->ReadFeatures(x,y,z,&locf,&glof)) if (!Maps::GetLocalFeature(feature, coord, block->local_feature))
{ continue;
// we're looking for addy tubes if (feature.type != df::feature_type::deep_special_tube)
if(!locf) continue; continue;
if(locf->type != DFHack::feature_Adamantine_Tube) continue; for (uint32_t x = 0; x < 16; x++)
{
for (uint32_t y = 0; y < 16; y++)
{
if (!block->designation[x][y].bits.feature_local)
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;
// Does the tile contain liquid?
if (block->designation[x][y].bits.flow_size)
continue;
for (uint32_t ty=0;ty<16;++ty)
{
for (uint32_t tx=0;tx<16;++tx)
{
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 // Set current tile, as accurately as can be expected
//newT = DFHack::findSimilarTileType(oldT,DFHack::WALL); // block->tiletype[x][y] = findSimilarTileType(block->tiletype[x][y], 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) // Check the tile above this one, in case we need to add a floor
if ( oldT == newT) continue; if (above)
//Set new tile type, clear designation
tiles[tx][ty] = newT;
dirty=1;
++count;
}
}
}
//If anything was changed, write it all.
if (dirty)
{ {
Mapz->WriteTileTypes(x,y,z, &tiles); if ((tileShape(above->tiletype[x][y]) == EMPTY) || (tileShape(above->tiletype[x][y]) == RAMP_TOP))
{
// 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);
} }
} }