Kill the Maps module

develop
Quietust 2012-01-19 21:44:17 -06:00
parent e7dcd4c66a
commit e7ecda1434
17 changed files with 769 additions and 1072 deletions

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

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

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

@ -32,13 +32,15 @@ distribution.
#include <cstring>
#include "df/map_block.h"
#include "df/block_square_event_mineralst.h"
using namespace DFHack;
using namespace DFHack::Simple;
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));
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
for(uint32_t j = 0;j<16;j++)
{
@ -83,9 +85,8 @@ void SquashRocks ( std::vector< std::vector <uint16_t> > * layerassign, DFHack::
class Block
{
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_tiletypes = false;
dirty_temperatures = false;
@ -93,10 +94,10 @@ class Block
dirty_occupancies = false;
valid = false;
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);
SquashVeins(m,bcoord,raw,veinmats);
Maps::ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
SquashVeins(bcoord,raw,veinmats);
if(layerassign)
SquashRocks(layerassign,raw,basemats);
else
@ -202,28 +203,28 @@ class Block
if(!valid) return false;
if(dirty_designations)
{
m->WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation);
m->WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true);
Maps::WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation);
Maps::WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true);
dirty_designations = false;
}
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;
}
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;
}
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;
}
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;
}
return true;
@ -234,7 +235,6 @@ class Block
bool dirty_temperatures:1;
bool dirty_blockflags:1;
bool dirty_occupancies:1;
DFHack::Maps * m;
DFHack::mapblock40d raw;
DFHack::DFCoord bcoord;
DFHack::t_blockmaterials veinmats;
@ -246,12 +246,11 @@ class Block
class MapCache
{
public:
MapCache(DFHack::Maps * Maps)
MapCache()
{
valid = 0;
this->Maps = Maps;
Maps->getSize(x_bmax, y_bmax, z_max);
validgeo = Maps->ReadGeology( layerassign );
Maps::getSize(x_bmax, y_bmax, z_max);
validgeo = Maps::ReadGeology( layerassign );
valid = true;
};
~MapCache()
@ -278,9 +277,9 @@ class MapCache
{
Block * nblo;
if(validgeo)
nblo = new Block(Maps,blockcoord, &layerassign);
nblo = new Block(blockcoord, &layerassign);
else
nblo = new Block(Maps,blockcoord);
nblo = new Block(blockcoord);
blocks[blockcoord] = nblo;
return nblo;
}
@ -455,7 +454,6 @@ class MapCache
uint32_t y_tmax;
uint32_t z_max;
std::vector< std::vector <uint16_t> > layerassign;
DFHack::Maps * Maps;
std::map<DFHack::DFCoord, Block *> blocks;
};
}

@ -258,33 +258,31 @@ namespace DFHack
* \ingroup grp_modules
* \ingroup grp_maps
*/
class DFHACK_EXPORT Maps : public Module
namespace Simple
{
public:
Maps();
~Maps();
bool Start();
bool Finish();
namespace Maps
{
extern DFHACK_EXPORT bool IsValid();
// 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.
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
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
yourself.
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
the geology stuff (region -- array of vectors, depth -- vector).
I'm thinking about turning that Geology stuff into a two-dimensional array
with static size.
this is the algorithm for applying matgloss:
@code
* 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
* array is indexed by the BiomeOffset enum
*
* 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
* yourself.
*
* 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
* the geology stuff (region -- array of vectors, depth -- vector).
* I'm thinking about turning that Geology stuff into a two-dimensional array
* with static size.
*
* this is the algorithm for applying matgloss:
* @code
void DfMap::applyGeoMatgloss(Block * b)
{
// load layer matgloss
@ -299,107 +297,87 @@ namespace DFHack
}
}
}
@endcode
*/
bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
/**
* Initialize the map feature caches, if possible
*/
bool StartFeatures();
/**
* Free the feature cache
*/
bool StopFeatures();
/**
* 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.
* @endcode
*/
std::vector <t_feature *> * GetLocalFeatures(DFCoord coord);
extern DFHACK_EXPORT bool ReadGeology( std::vector < std::vector <uint16_t> >& assign );
/**
* 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
*/
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
*/
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
*/
bool ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global);
extern DFHACK_EXPORT bool ReadFeatures(mapblock40d * block, t_feature * local, t_feature * global);
/**
* @deprecated
* @todo: remove
* Read a specific global or local feature directly
*/
bool ReadGlobalFeatures( std::vector <t_feature> & features);
/**
* @deprecated
* @todo: remove
*/
bool ReadLocalFeatures( std::map <DFCoord, std::vector<t_feature *> > & local_features );
extern DFHACK_EXPORT bool GetGlobalFeature(t_feature &feature, int32_t index);
extern DFHACK_EXPORT bool GetLocalFeature(t_feature &feature, DFCoord coord, int32_t index);
/*
* BLOCK DATA
*/
/// 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
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
*/
df::map_block * getBlock (int32_t blockx, int32_t blocky, int32_t blockz);
df::map_block * getBlockAbs (int32_t x, int32_t y, int32_t z);
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)
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
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 ReadTileTypes(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
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 ReadDesignations(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
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 ReadTemperatures(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
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 ReadOccupancy(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
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 ReadDirtyBit(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
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 ReadBlockFlags(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
bool SetBlockLocalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t local = -1);
bool SetBlockGlobalFeature(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);
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
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);
/// sorts the block event vector into multiple vectors by type
/// 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<df::block_square_event_mineralst *>* veins,
std::vector<df::block_square_event_frozen_liquidst *>* ices = 0,
std::vector<df::block_square_event_material_spatterst *>* splatter = 0,
@ -408,14 +386,12 @@ namespace DFHack
);
/// remove a block event from the block by address
bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * 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
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

@ -45,16 +45,9 @@ using namespace std;
#include "df/world_underground_region.h"
#include "df/feature_init.h"
using df::global::world;
#define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized();
using namespace DFHack;
Module* DFHack::createMaps()
{
return new Maps();
}
using namespace DFHack::Simple;
using df::global::world;
const char * DFHack::sa_feature(df::feature_type index)
{
@ -85,78 +78,12 @@ const char * DFHack::sa_feature(df::feature_type index)
}
};
struct Maps::Private
{
uint32_t worldSizeX, worldSizeY;
uint32_t maps_module;
Process * owner;
bool Inited;
bool FeaturesStarted;
bool Started;
bool hasGeology;
bool hasFeatures;
bool hasVeggies;
// map between feature address and the read object
map <void *, t_feature> local_feature_store;
map <DFCoord, vector <t_feature *> > m_local_feature;
vector <t_feature> v_global_feature;
vector<uint16_t> v_geology[eBiomeCount];
};
Maps::Maps()
{
Core & c = Core::getInstance();
d = new Private;
Process *p = d->owner = c.p;
d->Inited = d->FeaturesStarted = d->Started = false;
DFHack::VersionInfo * mem = c.vinfo;
d->hasFeatures = d->hasGeology = d->hasVeggies = true;
d->Inited = true;
}
Maps::~Maps()
{
if(d->FeaturesStarted)
StopFeatures();
if(d->Started)
Finish();
delete d;
}
/*-----------------------------------*
* Init the mapblock pointer array *
*-----------------------------------*/
bool Maps::Start()
{
if(!d->Inited)
return false;
if(d->Started)
Finish();
Process *p = d->owner;
// get the size
int32_t & mx = world->map.x_count_block;
int32_t & my = world->map.y_count_block;
int32_t & mz = world->map.z_count_block;
// test for wrong map dimensions
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
bool Maps::IsValid ()
{
cerr << hex << &mx << " " << &my << " " << &mz << endl;
cerr << dec << mx << " "<< my << " "<< mz << endl;
return false;
return (world->map.block_index != NULL);
}
d->Started = true;
return true;
}
#define MAPS_GUARD if(!IsValid()) throw DFHack::Error::ModuleNotInitialized();
// getter for map size
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
@ -176,11 +103,6 @@ void Maps::getPosition (int32_t& x, int32_t& y, int32_t& z)
z = world->map.region_z;
}
bool Maps::Finish()
{
return true;
}
/*
* Block reading
*/
@ -206,7 +128,6 @@ df::map_block *Maps::getBlockAbs (int32_t x, int32_t y, int32_t z)
bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
{
MAPS_GUARD
Process *p = d->owner;
df::map_block * block = getBlock(x,y,z);
if (block)
{
@ -218,10 +139,7 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer
buffer->global_feature = block->global_feature;
buffer->local_feature = block->local_feature;
buffer->mystery = block->unk2;
// FIXME: not 64-bit safe
buffer->origin = &block;
//uint32_t addr_of_struct = p->readDWord(addr);
// FIXME: maybe truncates
buffer->blockflags.whole = block->flags;
return true;
}
@ -410,123 +328,61 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4
}
return false;
}
bool Maps::StopFeatures()
{
if(d->FeaturesStarted)
bool Maps::GetGlobalFeature(t_feature &feature, int32_t index)
{
d->local_feature_store.clear();
d->v_global_feature.clear();
d->m_local_feature.clear();
d->FeaturesStarted = false;
return true;
}
feature.type = (df::feature_type)-1;
MAPS_GUARD
if ((index < 0) || (index >= world->world_data->underground_regions.size()))
return false;
df::feature_init *f = world->world_data->underground_regions[index]->feature_init;
feature.discovered = false;
feature.origin = f;
feature.type = f->getType();
f->getMaterial(&feature.main_material, &feature.sub_material);
return true;
}
bool Maps::StartFeatures()
bool Maps::GetLocalFeature(t_feature &feature, DFCoord coord, int32_t index)
{
feature.type = (df::feature_type)-1;
MAPS_GUARD
if(d->FeaturesStarted) return true;
if(!d->hasFeatures) return false;
// regionX and regionY are in embark squares!
// we convert to full region tiles
// this also works in adventure mode
// region X coord - whole regions
for(uint32_t blockX = 0; blockX < world->map.x_count_block; blockX ++)
for(uint32_t blockY = 0; blockY < world->map.y_count_block; blockY ++)
{
// regionX and regionY are in embark squares!
// we convert to full region tiles
// this also works in adventure mode
// region X coord - whole regions
uint32_t region_x = ( (blockX / 3) + world->map.region_x ) / 16;
uint32_t region_x = ( (coord.x / 3) + world->map.region_x ) / 16;
// region Y coord - whole regions
uint32_t region_y = ( (blockY / 3) + world->map.region_y ) / 16;
uint32_t region_y = ( (coord.y / 3) + world->map.region_y ) / 16;
uint32_t bigregion_x = region_x / 16;
uint32_t bigregion_y = region_y / 16;
uint32_t sub_x = region_x % 16;
uint32_t sub_y = region_y % 16;
// megaregions = 16x16 squares of regions = 256x256 squares of embark squares
// base = pointer to local feature structure (inside world data struct)
// bigregion is 16x16 regions. for each bigregion in X dimension:
if (!world->world_data->unk_204[bigregion_x][bigregion_y].features)
return false;
if(world->world_data->unk_204[bigregion_x][bigregion_y].features)
{
vector <df::feature_init *> *features = &world->world_data->unk_204[bigregion_x][bigregion_y].features->feature_init[sub_x][sub_y];
uint32_t size = features->size();
DFCoord pc(blockX,blockY);
std::vector<t_feature *> tempvec;
for(uint32_t i = 0; i < size; i++)
{
df::feature_init * cur_ptr = features->at(i);
map <void *, t_feature>::iterator it;
it = d->local_feature_store.find(cur_ptr);
// do we already have the feature?
if(it != d->local_feature_store.end())
{
// push pointer to existing feature
tempvec.push_back(&((*it).second));
}
// no?
else
{
t_feature tftemp;
tftemp.discovered = false;
tftemp.origin = cur_ptr;
tftemp.type = cur_ptr->getType();
cur_ptr->getMaterial(&tftemp.main_material, &tftemp.sub_material);
d->local_feature_store[cur_ptr] = tftemp;
// push pointer
tempvec.push_back(&(d->local_feature_store[cur_ptr]));
}
}
d->m_local_feature[pc] = tempvec;
}
}
vector <df::feature_init *> &features = world->world_data->unk_204[bigregion_x][bigregion_y].features->feature_init[sub_x][sub_y];
if ((index < 0) || (index >= features.size()))
return false;
df::feature_init *f = features[index];
// enumerate global features
uint32_t size = world->world_data->underground_regions.size();
d->v_global_feature.clear();
d->v_global_feature.reserve(size);
for (uint32_t i = 0; i < size; i++)
{
t_feature temp;
df::feature_init * feat_ptr = world->world_data->underground_regions[i]->feature_init;
temp.origin = feat_ptr;
temp.discovered = false;
temp.type = feat_ptr->getType();
feat_ptr->getMaterial(&temp.main_material, &temp.sub_material);
d->v_global_feature.push_back(temp);
}
d->FeaturesStarted = true;
feature.discovered = false;
feature.origin = f;
feature.type = f->getType();
f->getMaterial(&feature.main_material, &feature.sub_material);
return true;
}
t_feature * Maps::GetGlobalFeature(int16_t index)
{
if(!d->FeaturesStarted) return 0;
if(index < 0 || uint16_t(index) >= d->v_global_feature.size())
return 0;
return &(d->v_global_feature[index]);
}
std::vector <t_feature *> * Maps::GetLocalFeatures(DFCoord coord)
{
if(!d->FeaturesStarted) return 0;
coord.z = 0; // just making sure
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(coord);
if(iter != d->m_local_feature.end())
{
return &((*iter).second);
}
return 0;
}
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int16_t & global)
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int32_t & local, int32_t & global)
{
MAPS_GUARD
df::map_block *block = getBlock(x,y,z);
@ -539,7 +395,7 @@ bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int
return false;
}
bool Maps::WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int16_t & local, const int16_t & global)
bool Maps::WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int32_t & local, const int32_t & global)
{
MAPS_GUARD
df::map_block *block = getBlock(x,y,z);
@ -552,55 +408,53 @@ bool Maps::WriteFeatures(uint32_t x, uint32_t y, uint32_t z, const int16_t & loc
return false;
}
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local, t_feature ** global)
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature *local, t_feature *global)
{
if(!d->FeaturesStarted) return false;
int16_t loc, glob;
if(!ReadFeatures(x,y,z,loc,glob)) return false;
MAPS_GUARD
if(global && glob != -1)
*global = &(d->v_global_feature[glob]);
else if (global)
*global = 0;
int32_t loc, glob;
if (!ReadFeatures(x, y, z, loc, glob))
return false;
if(local && loc != -1)
bool result = true;
if (global)
{
if (glob != -1)
result &= GetGlobalFeature(*global, glob);
else
global->type = (df::feature_type)-1;
}
if (local)
{
DFCoord foo(x,y,0);
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(foo);
if(iter != d->m_local_feature.end())
if (loc != -1)
{
*local = ((*iter).second)[loc];
DFCoord coord(x,y,0);
result &= GetLocalFeature(*local, coord, loc);
}
else *local = 0;
else
local->type = (df::feature_type)-1;
}
else if(local)
*local = 0;
return true;
return result;
}
bool Maps::ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global)
bool Maps::ReadFeatures(mapblock40d * block, t_feature * local, t_feature * global)
{
if(!block) return false;
if(!d->FeaturesStarted) return false;
DFCoord c = block->position;
c.z = 0;
*global = 0;
*local = 0;
if(block->global_feature != -1)
*global = &(d->v_global_feature[block->global_feature]);
if(local && block->local_feature != -1)
{
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(c);
if(iter != d->m_local_feature.end())
MAPS_GUARD
if (global)
{
*local = ((*iter).second)[block->local_feature];
if (block->global_feature != -1)
GetGlobalFeature(*global, block->global_feature);
}
else *local = 0;
if (local)
{
if (block->local_feature != -1)
GetLocalFeature(*local, block->position, block->local_feature);
}
return true;
}
bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local)
bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int32_t local)
{
MAPS_GUARD
df::map_block *block = getBlock(x,y,z);
@ -612,7 +466,7 @@ bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t loca
return false;
}
bool Maps::SetBlockGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global)
bool Maps::SetBlockGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int32_t global)
{
MAPS_GUARD
df::map_block *block = getBlock(x,y,z);
@ -635,19 +489,24 @@ bool Maps::SortBlockEvents(uint32_t x, uint32_t y, uint32_t z,
vector <df::block_square_event_world_constructionst *> *constructions)
{
MAPS_GUARD
Process* p = d->owner;
df::map_block * block = getBlock(x,y,z);
if(veins) veins->clear();
if(ices) ices->clear();
if(splatter) splatter->clear();
if(grass) grass->clear();
if(constructions) constructions->clear();
if (veins)
veins->clear();
if (ices)
ices->clear();
if (splatter)
splatter->clear();
if (grass)
grass->clear();
if (constructions)
constructions->clear();
df::map_block * block = getBlock(x,y,z);
if (!block)
return false;
uint32_t size = block->block_events.size();
// read all veins
// read all events
for (uint32_t i = 0; i < size;i++)
{
df::block_square_event *evt = block->block_events[i];
@ -681,21 +540,19 @@ bool Maps::SortBlockEvents(uint32_t x, uint32_t y, uint32_t z,
bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which)
{
MAPS_GUARD
Process* p = d->owner;
df::map_block * block = getBlock(x,y,z);
if(block)
{
for(int i = 0; i < block->block_events.size();i++)
if (!block)
return false;
for (uint32_t i = 0; i < block->block_events.size(); i++)
{
if (block->block_events[i] == which)
{
free(which);
delete which;
block->block_events.erase(block->block_events.begin() + i);
return true;
}
}
}
return false;
}
@ -705,8 +562,8 @@ bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{
MAPS_GUARD
if(!d->hasGeology) return false;
vector<uint16_t> v_geology[eBiomeCount];
// iterate over 8 surrounding regions + local region
for (int i = eNorthWest; i < eBiomeCount; i++)
{
@ -726,53 +583,27 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// geology blocks have a vector of layer descriptors
// get the vector with pointer to layers
vector <df::world_data::T_unk_190::T_unk_4 *> *geolayers = &world->world_data->unk_190[geoindex]->unk_4;
vector <df::world_data::T_unk_190::T_unk_4 *> &geolayers = world->world_data->unk_190[geoindex]->unk_4;
/// layer descriptor has a field that determines the type of stone/soil
d->v_geology[i].reserve (geolayers->size());
v_geology[i].reserve(geolayers.size());
// finally, read the layer matgloss
for (uint32_t j = 0;j < geolayers->size();j++)
{
d->v_geology[i].push_back (geolayers->at(j)->unk_4);
}
for (uint32_t j = 0; j < geolayers.size(); j++)
v_geology[i].push_back(geolayers[j]->unk_4);
}
assign.clear();
assign.reserve(eBiomeCount);
for (int i = 0; i < eBiomeCount; i++)
{
assign.push_back (d->v_geology[i]);
}
assign.push_back(v_geology[i]);
return true;
}
bool Maps::ReadLocalFeatures( std::map <DFCoord, std::vector<t_feature *> > & local_features )
{
StopFeatures();
StartFeatures();
if(d->FeaturesStarted)
{
local_features = d->m_local_feature;
return true;
}
return false;
}
bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features )
{
StopFeatures();
StartFeatures();
if(d->FeaturesStarted)
{
features = d->v_global_feature;
return true;
}
return false;
}
bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df_plant *>*& plants)
{
if(!d->hasVeggies || !d->Started)
return false;
MAPS_GUARD
df::map_block *block = getBlock(x,y,z);
if (!block)
return false;

@ -96,17 +96,14 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
DFHack::VersionInfo *mem = c->vinfo;
DFHack::Gui * Gui = c->getGui();
DFHack::Maps *Maps = c->getMaps();
std::size_t numItems = world->items.all.size();
// init the map
if(!Maps->Start())
if (!Maps::IsValid())
{
c->con.printerr("Can't initialize map.\n");
c->con.printerr("Map is not available!\n");
return CR_FAILURE;
}
MapCache MC (Maps);
std::size_t numItems = world->items.all.size();
MapCache MC;
int i = 0;
int dumped_total = 0;
@ -185,8 +182,8 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
{
// yes...
cerr << "Moving from block to block!" << endl;
df::map_block * bl_src = Maps->getBlock(itm->pos.x /16, itm->pos.y/16, itm->pos.z);
df::map_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz);
df::map_block * bl_src = Maps::getBlockAbs(itm->pos.x, itm->pos.y, itm->pos.z);
df::map_block * bl_tgt = Maps::getBlockAbs(cx, cy, cz);
if(bl_src)
{
std::remove(bl_src->items.begin(), bl_src->items.end(),itm->id);
@ -255,7 +252,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
// write map changes back to DF.
MC.WriteAll();
// 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");
return CR_OK;

@ -2,12 +2,9 @@
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include "modules/Maps.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/unit.h"
#include "df/unit_spatter.h"
@ -19,6 +16,7 @@
using std::vector;
using std::string;
using namespace DFHack;
using namespace DFHack::Simple;
using df::global::world;
using df::global::cursor;
@ -115,16 +113,6 @@ command_result cleanunits (Core * c)
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)
{
// 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");
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)
{
c->con.printerr("Invalid map block selected!\n");

@ -17,7 +17,7 @@ using MapExtras::MapCache;
using namespace DFHack;
//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
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 maxCoord = DFHack::DFCoord(0xFFFF, 0xFFFF, 0xFFFF));
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map);
void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map);
void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map);
void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map);
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allNormal(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allLow(DFHack::DFCoord coord, MapExtras::MapCache & map);
void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache & map);
DFhackCExport const char * plugin_name ( void )
{
@ -108,18 +108,16 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
//Initialization.
c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui();
// init the map
if(!Maps->Start())
if (!Maps::IsValid())
{
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();
return CR_FAILURE;
}
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 ty_max = y_max * 16;
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);
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
MapExtras::MapCache MCache;
df::tile_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy);
df::tile_designation des = MCache.designationAt(xy);
int16_t tt = MCache.tiletypeAt(xy);
df::tile_occupancy oc;
if (checkbuilding)
oc = MCache->occupancyAt(xy);
oc = MCache.occupancyAt(xy);
source = (df::tile_traffic)des.bits.traffic;
if(source == target)
{
c->con.printerr("This tile is already set to the target traffic type.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
@ -152,7 +149,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(DFHack::isWallTerrain(tt))
{
c->con.printerr("This tile is a wall. Please select a passable tile.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
@ -160,7 +156,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(checkpit && DFHack::isOpenTerrain(tt))
{
c->con.printerr("This tile is a hole. Please select a passable tile.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
@ -168,7 +163,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(checkbuilding && oc.bits.building)
{
c->con.printerr("This tile contains a building. Please select an empty tile.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
@ -184,25 +178,25 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
xy = flood.top();
flood.pop();
des = MCache->designationAt(xy);
des = MCache.designationAt(xy);
if (des.bits.traffic != source) continue;
tt = MCache->tiletypeAt(xy);
tt = MCache.tiletypeAt(xy);
if(DFHack::isWallTerrain(tt)) continue;
if(checkpit && DFHack::isOpenTerrain(tt)) continue;
if (checkbuilding)
{
oc = MCache->occupancyAt(xy);
oc = MCache.occupancyAt(xy);
if(oc.bits.building) continue;
}
//This tile is ready. Set its traffic level and add surrounding tiles.
if (MCache->testCoord(xy))
if (MCache.testCoord(xy))
{
des.bits.traffic = target;
MCache->setDesignationAt(xy,des);
MCache.setDesignationAt(xy,des);
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();
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)
{
void (*proc)(DFHack::DFCoord, MapExtras::MapCache *) = allNormal;
void (*proc)(DFHack::DFCoord, MapExtras::MapCache &) = allNormal;
//Loop through parameters
for(int i = 0; i < params.size();i++)
@ -289,19 +283,17 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
//Initialization.
c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui();
// init the map
if(!Maps->Start())
if (!Maps::IsValid())
{
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();
return CR_FAILURE;
}
//Maximum map size.
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 ty_max = y_max * 16;
@ -330,7 +322,7 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
return CR_FAILURE;
}
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
MapExtras::MapCache MCache;
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->Resume();
return CR_OK;
}
//Unconditionally set map to target traffic type
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map)
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache &map)
{
df::tile_designation des = map->designationAt(coord);
df::tile_designation des = map.designationAt(coord);
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)
{
df::tile_designation des = map->designationAt(coord);
df::tile_designation des = map.designationAt(coord);
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)
{
df::tile_designation des = map->designationAt(coord);
df::tile_designation des = map.designationAt(coord);
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)
{
df::tile_designation des = map->designationAt(coord);
df::tile_designation des = map.designationAt(coord);
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;
uint32_t x_max,y_max,z_max;
DFHack::Maps * Maps;
DFHack::Gui * Position;
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())
{
c->Suspend();
Maps = c->getMaps();
Maps->Start();
Maps->getSize(x_max,y_max,z_max);
Maps::getSize(x_max,y_max,z_max);
Position = c->getGui();
do
{
if(!Maps->Start())
if (!Maps::IsValid())
{
c->con << "Can't see any DF map loaded." << endl;
break;
break;;
}
if(!Position->getCursorCoords(x,y,z))
{
@ -377,7 +374,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
break;
}
c->con << "cursor coords: " << x << "/" << y << "/" << z << endl;
MapCache mcache(Maps);
MapCache mcache;
DFHack::DFCoord cursor(x,y,z);
coord_vec all_tiles = brush->points(mcache,cursor);
c->con << "working..." << endl;
@ -530,7 +527,6 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
c->con << "OK" << endl;
else
c->con << "Something failed horribly! RUN!" << endl;
Maps->Finish();
} while (0);
c->Resume();
}

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

@ -99,31 +99,28 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
DFHack::Gui *Gui = c->getGui();
DFHack::Materials *Materials = c->getMaterials();
DFHack::VersionInfo* mem = c->vinfo;
DFHack::Maps *Maps = c->getMaps();
std::vector<t_matglossInorganic> 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 (Maps);
MapExtras::MapCache mc;
int32_t regionX, regionY, regionZ;
Maps->getPosition(regionX,regionY,regionZ);
bool have_features = Maps->StartFeatures();
Maps::getPosition(regionX,regionY,regionZ);
int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
{
con.printerr("No cursor; place cursor over tile to probe.\n");
c->Resume();
return CR_FAILURE;
}
else
{
DFCoord cursor (cursorX,cursorY,cursorZ);
uint32_t blockX = cursorX / 16;
@ -132,9 +129,13 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
uint32_t tileY = cursorY % 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);
/*
if (showBlock)
@ -247,33 +248,25 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
DFCoord pc(blockX, blockY);
if(have_features)
{
t_feature * local = 0;
t_feature * global = 0;
Maps->ReadFeatures(&(b->raw),&local,&global);
t_feature local;
t_feature global;
Maps::ReadFeatures(&(b->raw),&local,&global);
PRINT_FLAG( bits.feature_local );
if(local)
if(local.type != -1)
{
con.print("%-16s", "");
con.print(" %4d", block.local_feature);
con.print(" (%2d)", local->type);
con.print(" addr 0x%X ", local->origin);
con.print(" %s\n", sa_feature(local->type));
con.print(" (%2d)", local.type);
con.print(" addr 0x%X ", local.origin);
con.print(" %s\n", sa_feature(local.type));
}
PRINT_FLAG( bits.feature_global );
if(global)
if(global.type != -1)
{
con.print("%-16s", "");
con.print(" %4d", block.global_feature);
con.print(" (%2d)", global->type);
con.print(" %s\n", sa_feature(global->type));
}
}
else
{
PRINT_FLAG( bits.feature_local );
PRINT_FLAG( bits.feature_global );
con.print(" (%2d)", global.type);
con.print(" %s\n", sa_feature(global.type));
}
#undef PRINT_FLAG
con << "local feature idx: " << block.local_feature
@ -282,13 +275,6 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
<< endl;
con << "mystery: " << block.mystery << endl;
con << std::endl;
}
else
{
con.printerr("No data.\n");
}
}
}
c->Resume();
return CR_OK;
}

@ -68,9 +68,6 @@ bool operator>(const matdata & q1, const matdata & q2)
typedef std::map<int16_t, matdata> MatMap;
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;
#define TO_PTR_VEC(obj_vec, ptr_vec) \
@ -221,15 +218,14 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
}
uint32_t x_max = 0, y_max = 0, z_max = 0;
c->Suspend();
DFHack::Maps *maps = c->getMaps();
if (!maps->Start())
if (!Maps::IsValid())
{
con.printerr("Cannot get map info!\n");
c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE;
}
maps->getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps);
Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map;
DFHack::Materials *mats = c->getMaterials();
if (!mats->df_inorganic)
@ -244,10 +240,8 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
showPlants = false;
}
FeatureList globalFeatures;
FeatureMap localFeatures;
DFHack::t_feature *blockFeatureGlobal = 0;
DFHack::t_feature *blockFeatureLocal = 0;
DFHack::t_feature blockFeatureGlobal;
DFHack::t_feature blockFeatureLocal;
bool hasAquifer = false;
bool hasDemonTemple = false;
@ -262,16 +256,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
matdata liquidMagma;
matdata aquiferTiles;
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;
DFHack::Vegetation *veg = c->getVegetation();
if (showPlants && !veg->Start())
@ -294,23 +278,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
}
{ // Find features
uint16_t index = b->raw.global_feature;
if (index != -1 && index < globalFeatures.size())
{
blockFeatureGlobal = &globalFeatures[index];
}
uint32_t index = b->raw.global_feature;
if (index != -1)
Maps::GetGlobalFeature(blockFeatureGlobal, index);
index = b->raw.local_feature;
FeatureMap::const_iterator it = localFeatures.find(blockCoord);
if (it != localFeatures.end())
{
FeatureListPointer features = it->second;
if (index != -1 && index < features.size())
{
blockFeatureLocal = features[index];
}
}
if (index != -1)
Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index);
}
int global_z = df::global::world->map.region_z + z;
@ -386,25 +360,25 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
veinMats[b->veinMaterialAt(coord)].add(global_z);
break;
case DFHack::FEATSTONE:
if (blockFeatureLocal && des.bits.feature_local)
if (blockFeatureLocal.type != -1 && des.bits.feature_local)
{
if (blockFeatureLocal->type == df::feature_type::deep_special_tube
&& blockFeatureLocal->main_material == 0) // stone
if (blockFeatureLocal.type == df::feature_type::deep_special_tube
&& blockFeatureLocal.main_material == 0) // stone
{
veinMats[blockFeatureLocal->sub_material].add(global_z);
veinMats[blockFeatureLocal.sub_material].add(global_z);
}
else if (showTemple
&& blockFeatureLocal->type == df::feature_type::deep_surface_portal)
&& blockFeatureLocal.type == df::feature_type::deep_surface_portal)
{
hasDemonTemple = true;
}
}
if (showSlade && blockFeatureGlobal && des.bits.feature_global
&& blockFeatureGlobal->type == df::feature_type::feature_underworld_from_layer
&& blockFeatureGlobal->main_material == 0) // stone
if (showSlade && blockFeatureGlobal.type != -1 && des.bits.feature_global
&& blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer
&& blockFeatureGlobal.main_material == 0) // stone
{
layerMats[blockFeatureGlobal->sub_material].add(global_z);
layerMats[blockFeatureGlobal.sub_material].add(global_z);
}
break;
case DFHack::OBSIDIAN:
@ -419,7 +393,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
if (showPlants)
{
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++)
{
@ -508,7 +482,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
veg->Finish();
}
mats->Finish();
maps->Finish();
c->Resume();
con << std::endl;
return CR_OK;

@ -16,21 +16,20 @@ using namespace DFHack;
/*
* Anything that might reveal Hell is unsafe.
*/
bool isSafe(uint32_t x, uint32_t y, uint32_t z, DFHack::Maps *Maps)
bool isSafe(uint32_t x, uint32_t y, uint32_t z)
{
DFHack::t_feature *local_feature = NULL;
DFHack::t_feature *global_feature = NULL;
DFHack::t_feature local_feature;
DFHack::t_feature global_feature;
// get features of block
// error -> obviously not safe to manipulate
if(!Maps->ReadFeatures(x,y,z,&local_feature,&global_feature))
{
if(!Maps::ReadFeatures(x,y,z,&local_feature,&global_feature))
return false;
}
// Adamantine tubes and temples lead to Hell
if (local_feature && (local_feature->type == df::feature_type::deep_special_tube || local_feature->type == df::feature_type::deep_surface_portal))
if (local_feature.type == df::feature_type::deep_special_tube || local_feature.type == df::feature_type::deep_surface_portal)
return false;
// And Hell *is* Hell.
if (global_feature && global_feature->type == df::feature_type::feature_underworld_from_layer)
if (global_feature.type == df::feature_type::feature_underworld_from_layer)
return false;
// otherwise it's safe.
return true;
@ -160,7 +159,6 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
}
c->Suspend();
DFHack::Maps *Maps =c->getMaps();
DFHack::World *World =c->getWorld();
t_gamemodes gm;
World->ReadGameMode(gm);
@ -170,21 +168,14 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
c->Resume();
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();
return CR_FAILURE;
}
if(no_hell && !Maps->StartFeatures())
{
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);
Maps::getSize(x_max,y_max,z_max);
hidesaved.reserve(x_max * y_max * z_max);
for(uint32_t x = 0; x< x_max;x++)
{
@ -192,11 +183,11 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
{
for(uint32_t z = 0; z< z_max;z++)
{
df::map_block *block = Maps->getBlock(x,y,z);
df::map_block *block = Maps::getBlock(x,y,z);
if(block)
{
// 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(x, y, z))
continue;
hideblock hb;
hb.x = x;
@ -255,7 +246,7 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE;
}
c->Suspend();
DFHack::Maps *Maps =c->getMaps();
DFHack::World *World =c->getWorld();
t_gamemodes gm;
World->ReadGameMode(gm);
@ -265,17 +256,16 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
c->Resume();
return CR_FAILURE;
}
Maps = c->getMaps();
if(!Maps->Start())
if (!Maps::IsValid())
{
con.printerr("Can't init map.\n");
c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE;
}
// Sanity check: map size
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)
{
con.printerr("The map is not of the same size...\n");
@ -288,7 +278,7 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
for(size_t i = 0; i < hidesaved.size();i++)
{
hideblock & hb = hidesaved[i];
df::map_block * b = Maps->getBlock(hb.x,hb.y,hb.z);
df::map_block * b = Maps::getBlock(hb.x,hb.y,hb.z);
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{
b->designation[i][j].bits.hidden = hb.hiddens[i][j];
@ -336,13 +326,11 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
}
c->Suspend();
uint32_t x_max,y_max,z_max;
Maps * Maps = c->getMaps();
Gui * Gui = c->getGui();
World * World = c->getWorld();
// init the map
if(!Maps->Start())
if (!Maps::IsValid())
{
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();
return CR_FAILURE;
}
@ -361,7 +349,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE;
}
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 ty_max = y_max * 16;
@ -373,7 +361,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE;
}
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
MapCache * MCache = new MapCache(Maps);
MapCache * MCache = new MapCache;
int16_t tt = MCache->tiletypeAt(xy);
if(isWallTerrain(tt))
{
@ -383,7 +371,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_FAILURE;
}
// 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++)
{
@ -391,7 +379,7 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
{
for(uint32_t z = 0; z< z_max;z++)
{
df::map_block * b = Maps->getBlock(x,y,z);
df::map_block * b = Maps::getBlock(x,y,z);
if(b)
{
// change the hidden flag to 0

@ -641,7 +641,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
uint32_t x_max = 0, y_max = 0, z_max = 0;
int32_t x = 0, y = 0, z = 0;
DFHack::Maps *maps;
DFHack::Gui *gui;
for(int i = 0; i < parameters.size();i++)
{
@ -755,15 +754,14 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
}
c->Suspend();
maps = c->getMaps();
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();
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)))
{
@ -774,7 +772,7 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z);
DFHack::DFCoord cursor(x,y,z);
MapExtras::MapCache map(maps);
MapExtras::MapCache map;
coord_vec all_tiles = brush->points(map, cursor);
c->con.print("working...\n");
@ -892,7 +890,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
{
c->con.printerr("Something failed horribly! RUN!\n");
}
maps->Finish();
c->Resume();
}
}

@ -55,23 +55,14 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
}
}
c->Suspend();
DFHack::Maps *Mapz = c->getMaps();
// init the map
if (!Mapz->Start())
if (!Maps::IsValid())
{
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();
return CR_FAILURE;
}
Maps::getSize(x_max,y_max,z_max);
// walk the map
for (uint32_t x = 0; x< x_max;x++)
@ -80,17 +71,17 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
{
for (uint32_t z = 0; z< z_max;z++)
{
DFHack::t_feature * locf = 0;
DFHack::t_feature * glof = 0;
if (Mapz->ReadFeatures(x,y,z,&locf,&glof))
DFHack::t_feature locf;
DFHack::t_feature glof;
if (Maps::ReadFeatures(x,y,z,&locf,&glof))
{
// we're looking for addy tubes
if(!locf) continue;
if(locf->type != df::feature_type::deep_special_tube) continue;
if(locf.type == -1) continue;
if(locf.type != df::feature_type::deep_special_tube) continue;
dirty=0;
Mapz->ReadDesignations(x,y,z, &designations);
Mapz->ReadTileTypes(x,y,z, &tiles);
Maps::ReadDesignations(x,y,z, &designations);
Maps::ReadTileTypes(x,y,z, &tiles);
for (uint32_t ty=0;ty<16;++ty)
{
@ -117,7 +108,7 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
//If anything was changed, write it all.
if (dirty)
{
Mapz->WriteTileTypes(x,y,z, &tiles);
Maps::WriteTileTypes(x,y,z, &tiles);
}
}
}

@ -275,18 +275,17 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
int32_t cx, cy, cz;
c->Suspend();
Gui * gui = c->getGui();
Maps * maps = c->getMaps();
if(!maps->Start())
if (!Maps::IsValid())
{
c->con.printerr("Map is not available!\n");
c->Resume();
c->con.printerr("Can't init the map...\n");
return CR_FAILURE;
}
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)
{
c->Resume();
@ -726,13 +725,12 @@ enum explo_what
EXPLO_DESIGNATED,
};
bool stamp_pattern (DFHack::Maps * maps,
uint32_t bx, uint32_t by, int z_level,
bool stamp_pattern (uint32_t bx, uint32_t by, int z_level,
digmask & dm, explo_how how, explo_what what,
int x_max, int y_max
)
{
df::map_block * bl = maps->getBlock(bx,by,z_level);
df::map_block * bl = Maps::getBlock(bx,by,z_level);
if(!bl)
return false;
int x = 0,mx = 16;
@ -854,15 +852,14 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
}
c->Suspend();
Gui * gui = c->getGui();
Maps * maps = c->getMaps();
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->con.printerr("Can't init the map...\n");
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;
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++)
{
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);
}
}
@ -891,7 +888,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
for(int32_t y = 0 ; y < y_max; y++)
{
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);
}
}
@ -904,7 +901,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
which = x % 3;
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);
}
}
@ -917,7 +914,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
which = y % 3;
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);
}
}
@ -927,7 +924,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
// middle + recentering for the image
int xmid = x_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 y = 0; y < 16; y++)
{
@ -952,7 +949,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
{
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);
}
}
@ -983,17 +980,15 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
Console & con = c->con;
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui();
// init the map
if(!Maps->Start())
if (!Maps::IsValid())
{
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;
}
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 ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz);
@ -1008,7 +1003,7 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
con.printerr("I won't dig the borders. That would be cheating!\n");
return CR_FAILURE;
}
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
MapExtras::MapCache * MCache = new MapExtras::MapCache;
df::tile_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy);
int16_t veinmat = MCache->veinMaterialAt(xy);