|
|
@ -33,251 +33,167 @@ distribution.
|
|
|
|
#include "df/map_block.h"
|
|
|
|
#include "df/map_block.h"
|
|
|
|
#include "df/block_square_event_mineralst.h"
|
|
|
|
#include "df/block_square_event_mineralst.h"
|
|
|
|
#include "df/construction.h"
|
|
|
|
#include "df/construction.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapExtras
|
|
|
|
namespace MapExtras
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void SquashVeins (DFCoord bcoord, mapblock40d & mb, t_blockmaterials & materials)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
memset(materials,-1,sizeof(materials));
|
|
|
|
|
|
|
|
std::vector <df::block_square_event_mineralst *> veins;
|
|
|
|
|
|
|
|
Maps::SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,&veins);
|
|
|
|
|
|
|
|
for (uint32_t x = 0;x<16;x++) for (uint32_t y = 0; y< 16;y++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
|
|
|
|
if (tileMaterial(tt) == tiletype_material::MINERAL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t i = 0; i < veins.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (veins[i]->getassignment(x,y))
|
|
|
|
|
|
|
|
materials[x][y] = veins[i]->inorganic_mat;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SquashFrozenLiquids (DFCoord bcoord, mapblock40d & mb, tiletypes40d & frozen)
|
|
|
|
class DFHACK_EXPORT MapCache;
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector <df::block_square_event_frozen_liquidst *> ices;
|
|
|
|
|
|
|
|
Maps::SortBlockEvents(bcoord.x,bcoord.y,bcoord.z,NULL,&ices);
|
|
|
|
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
|
|
|
|
frozen[x][y] = tiletype::Void;
|
|
|
|
|
|
|
|
if (tileMaterial(tt) == tiletype_material::FROZEN_LIQUID)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ices.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
df::tiletype tt2 = ices[i]->tiles[x][y];
|
|
|
|
|
|
|
|
if (tt2 != tiletype::Void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
frozen[x][y] = tt2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SquashConstructions (DFCoord bcoord, mapblock40d & mb, tiletypes40d & constructions)
|
|
|
|
template<class R, class T> inline R index_tile(T &v, df::coord2d p) {
|
|
|
|
{
|
|
|
|
return v[p.x&15][p.y&15];
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
df::tiletype tt = mb.tiletypes[x][y];
|
|
|
|
|
|
|
|
constructions[x][y] = tiletype::Void;
|
|
|
|
|
|
|
|
if (tileMaterial(tt) == tiletype_material::CONSTRUCTION)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DFCoord coord(bcoord.x*16 + x, bcoord.y*16 + y, bcoord.z);
|
|
|
|
|
|
|
|
df::construction *con = df::construction::find(coord);
|
|
|
|
|
|
|
|
if (con)
|
|
|
|
|
|
|
|
constructions[x][y] = con->original_tile;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SquashRocks ( std::vector< std::vector <uint16_t> > * layerassign, mapblock40d & mb, t_blockmaterials & materials)
|
|
|
|
class DFHACK_EXPORT Block
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// get the layer materials
|
|
|
|
public:
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
Block(MapCache *parent, DFCoord _bcoord);
|
|
|
|
{
|
|
|
|
|
|
|
|
materials[x][y] = -1;
|
|
|
|
|
|
|
|
uint8_t test = mb.designation[x][y].bits.biome;
|
|
|
|
|
|
|
|
if ((test < sizeof(mb.biome_indices)) && (mb.biome_indices[test] < layerassign->size()))
|
|
|
|
|
|
|
|
materials[x][y] = layerassign->at(mb.biome_indices[test])[mb.designation[x][y].bits.geolayer_index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Block
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
* All coordinates are taken mod 16.
|
|
|
|
public:
|
|
|
|
*/
|
|
|
|
Block(DFCoord _bcoord, std::vector< std::vector <uint16_t> > * layerassign = 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
//Arbitrary tag field for flood fills etc.
|
|
|
|
dirty_designations = false;
|
|
|
|
int16_t &tag(df::coord2d p) {
|
|
|
|
dirty_tiletypes = false;
|
|
|
|
return index_tile<int16_t&>(tags, p);
|
|
|
|
dirty_temperatures = false;
|
|
|
|
|
|
|
|
dirty_blockflags = false;
|
|
|
|
|
|
|
|
dirty_occupancies = false;
|
|
|
|
|
|
|
|
valid = false;
|
|
|
|
|
|
|
|
bcoord = _bcoord;
|
|
|
|
|
|
|
|
if(Maps::ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Maps::ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2);
|
|
|
|
|
|
|
|
SquashVeins(bcoord,raw,veinmats);
|
|
|
|
|
|
|
|
SquashConstructions(bcoord, raw, contiles);
|
|
|
|
|
|
|
|
SquashFrozenLiquids(bcoord, raw, icetiles);
|
|
|
|
|
|
|
|
if(layerassign)
|
|
|
|
|
|
|
|
SquashRocks(layerassign,raw,basemats);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
memset(basemats,-1,sizeof(basemats));
|
|
|
|
|
|
|
|
valid = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t veinMaterialAt(df::coord2d p)
|
|
|
|
int16_t veinMaterialAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return veinmats[p.x][p.y];
|
|
|
|
return index_tile<int16_t>(veinmats,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int16_t baseMaterialAt(df::coord2d p)
|
|
|
|
int16_t baseMaterialAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return basemats[p.x][p.y];
|
|
|
|
return index_tile<int16_t>(basemats,p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the clear methods are used by the floodfill in digv and digl to mark tiles which were processed
|
|
|
|
|
|
|
|
void ClearBaseMaterialAt(df::coord2d p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
basemats[p.x][p.y] = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearVeinMaterialAt(df::coord2d p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
veinmats[p.x][p.y] = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tiletype BaseTileTypeAt(df::coord2d p)
|
|
|
|
df::tiletype BaseTileTypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (contiles[p.x][p.y] != tiletype::Void)
|
|
|
|
auto tt = index_tile<df::tiletype>(contiles,p);
|
|
|
|
return contiles[p.x][p.y];
|
|
|
|
if (tt != tiletype::Void) return tt;
|
|
|
|
else if (icetiles[p.x][p.y] != tiletype::Void)
|
|
|
|
tt = index_tile<df::tiletype>(icetiles,p);
|
|
|
|
return icetiles[p.x][p.y];
|
|
|
|
if (tt != tiletype::Void) return tt;
|
|
|
|
else
|
|
|
|
return index_tile<df::tiletype>(rawtiles,p);
|
|
|
|
return raw.tiletypes[p.x][p.y];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
df::tiletype TileTypeAt(df::coord2d p)
|
|
|
|
df::tiletype TileTypeAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return raw.tiletypes[p.x][p.y];
|
|
|
|
return index_tile<df::tiletype>(rawtiles,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTiletypeAt(df::coord2d p, df::tiletype tiletype)
|
|
|
|
bool setTiletypeAt(df::coord2d p, df::tiletype tiletype)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_tiletypes = true;
|
|
|
|
dirty_tiletypes = true;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.tiletypes[p.x][p.y] = tiletype;
|
|
|
|
index_tile<df::tiletype&>(rawtiles,p) = tiletype;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t temperature1At(df::coord2d p)
|
|
|
|
uint16_t temperature1At(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return temp1[p.x][p.y];
|
|
|
|
return index_tile<uint16_t>(temp1,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTemp1At(df::coord2d 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;
|
|
|
|
temp1[p.x][p.y] = temp;
|
|
|
|
index_tile<uint16_t&>(temp1,p) = temp;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t temperature2At(df::coord2d p)
|
|
|
|
uint16_t temperature2At(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return temp2[p.x][p.y];
|
|
|
|
return index_tile<uint16_t>(temp2,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTemp2At(df::coord2d 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;
|
|
|
|
temp2[p.x][p.y] = temp;
|
|
|
|
index_tile<uint16_t&>(temp2,p) = temp;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_designation DesignationAt(df::coord2d p)
|
|
|
|
df::tile_designation DesignationAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return raw.designation[p.x][p.y];
|
|
|
|
return index_tile<df::tile_designation>(designation,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setDesignationAt(df::coord2d p, df::tile_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;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.designation[p.x][p.y] = des;
|
|
|
|
index_tile<df::tile_designation&>(designation,p) = des;
|
|
|
|
if(des.bits.dig)
|
|
|
|
if(des.bits.dig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
dirty_blockflags = true;
|
|
|
|
dirty_blockflags = true;
|
|
|
|
raw.blockflags.bits.designated = true;
|
|
|
|
blockflags.bits.designated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_occupancy OccupancyAt(df::coord2d p)
|
|
|
|
df::tile_occupancy OccupancyAt(df::coord2d p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return raw.occupancy[p.x][p.y];
|
|
|
|
return index_tile<df::tile_occupancy>(occupancy,p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setOccupancyAt(df::coord2d p, df::tile_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;
|
|
|
|
raw.occupancy[p.x][p.y] = des;
|
|
|
|
index_tile<df::tile_occupancy&>(occupancy,p) = des;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
t_blockflags BlockFlags()
|
|
|
|
t_blockflags BlockFlags()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return raw.blockflags;
|
|
|
|
return blockflags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setBlockFlags(t_blockflags des)
|
|
|
|
bool setBlockFlags(t_blockflags des)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!valid) return false;
|
|
|
|
if(!valid) return false;
|
|
|
|
dirty_blockflags = true;
|
|
|
|
dirty_blockflags = true;
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
|
|
|
|
raw.blockflags = des;
|
|
|
|
blockflags = des;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Write ()
|
|
|
|
bool Write();
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!valid) return false;
|
|
|
|
int16_t GeoIndexAt(df::coord2d p);
|
|
|
|
if(dirty_designations)
|
|
|
|
|
|
|
|
{
|
|
|
|
bool GetGlobalFeature(t_feature *out);
|
|
|
|
Maps::WriteDesignations(bcoord.x,bcoord.y,bcoord.z, &raw.designation);
|
|
|
|
bool GetLocalFeature(t_feature *out);
|
|
|
|
Maps::WriteDirtyBit(bcoord.x,bcoord.y,bcoord.z,true);
|
|
|
|
|
|
|
|
dirty_designations = false;
|
|
|
|
bool is_valid() { return valid; }
|
|
|
|
}
|
|
|
|
df::map_block *getRaw() { return block; }
|
|
|
|
if(dirty_tiletypes)
|
|
|
|
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
Maps::WriteTileTypes(bcoord.x,bcoord.y,bcoord.z, &raw.tiletypes);
|
|
|
|
friend class MapCache;
|
|
|
|
dirty_tiletypes = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
MapCache *parent;
|
|
|
|
if(dirty_temperatures)
|
|
|
|
df::map_block *block;
|
|
|
|
{
|
|
|
|
|
|
|
|
Maps::WriteTemperatures(bcoord.x,bcoord.y,bcoord.z, &temp1, &temp2);
|
|
|
|
static void SquashVeins(df::map_block *mb, t_blockmaterials & materials);
|
|
|
|
dirty_temperatures = false;
|
|
|
|
static void SquashFrozenLiquids (df::map_block *mb, tiletypes40d & frozen);
|
|
|
|
}
|
|
|
|
static void SquashConstructions (df::map_block *mb, tiletypes40d & constructions);
|
|
|
|
if(dirty_blockflags)
|
|
|
|
static void SquashRocks (df::map_block *mb, t_blockmaterials & materials,
|
|
|
|
{
|
|
|
|
std::vector< std::vector <int16_t> > * layerassign);
|
|
|
|
Maps::WriteBlockFlags(bcoord.x,bcoord.y,bcoord.z,raw.blockflags);
|
|
|
|
|
|
|
|
dirty_blockflags = false;
|
|
|
|
bool valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dirty_occupancies)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Maps::WriteOccupancy(bcoord.x,bcoord.y,bcoord.z,&raw.occupancy);
|
|
|
|
|
|
|
|
dirty_occupancies = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid:1;
|
|
|
|
|
|
|
|
bool dirty_designations:1;
|
|
|
|
bool dirty_designations:1;
|
|
|
|
bool dirty_tiletypes:1;
|
|
|
|
bool dirty_tiletypes:1;
|
|
|
|
bool dirty_temperatures:1;
|
|
|
|
bool dirty_temperatures:1;
|
|
|
|
bool dirty_blockflags:1;
|
|
|
|
bool dirty_blockflags:1;
|
|
|
|
bool dirty_occupancies:1;
|
|
|
|
bool dirty_occupancies:1;
|
|
|
|
mapblock40d raw;
|
|
|
|
|
|
|
|
DFCoord bcoord;
|
|
|
|
DFCoord bcoord;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int16_t tags[16][16];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tiletypes40d rawtiles;
|
|
|
|
|
|
|
|
designations40d designation;
|
|
|
|
|
|
|
|
occupancies40d occupancy;
|
|
|
|
|
|
|
|
t_blockflags blockflags;
|
|
|
|
|
|
|
|
|
|
|
|
t_blockmaterials veinmats;
|
|
|
|
t_blockmaterials veinmats;
|
|
|
|
t_blockmaterials basemats;
|
|
|
|
t_blockmaterials basemats;
|
|
|
|
t_temperatures temp1;
|
|
|
|
t_temperatures temp1;
|
|
|
@ -286,14 +202,15 @@ class Block
|
|
|
|
tiletypes40d icetiles; // what's underneath ice
|
|
|
|
tiletypes40d icetiles; // what's underneath ice
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MapCache
|
|
|
|
class DFHACK_EXPORT MapCache
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
MapCache()
|
|
|
|
MapCache()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
valid = 0;
|
|
|
|
valid = 0;
|
|
|
|
Maps::getSize(x_bmax, y_bmax, z_max);
|
|
|
|
Maps::getSize(x_bmax, y_bmax, z_max);
|
|
|
|
validgeo = Maps::ReadGeology( layerassign );
|
|
|
|
x_tmax = x_bmax*16; y_tmax = y_bmax*16;
|
|
|
|
|
|
|
|
validgeo = Maps::ReadGeology(&layer_mats, &geoidx);
|
|
|
|
valid = true;
|
|
|
|
valid = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
~MapCache()
|
|
|
|
~MapCache()
|
|
|
@ -304,192 +221,107 @@ class MapCache
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return valid;
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// get the map block at a *block* coord. Block coord = tile coord / 16
|
|
|
|
/// get the map block at a *block* coord. Block coord = tile coord / 16
|
|
|
|
Block * BlockAt (DFCoord blockcoord)
|
|
|
|
Block *BlockAt(DFCoord blockcoord);
|
|
|
|
{
|
|
|
|
/// get the map block at a tile coord.
|
|
|
|
if(!valid)
|
|
|
|
Block *BlockAtTile(DFCoord coord) {
|
|
|
|
return 0;
|
|
|
|
return BlockAt(df::coord(coord.x>>4,coord.y>>4,coord.z));
|
|
|
|
std::map <DFCoord, Block*>::iterator iter = blocks.find(blockcoord);
|
|
|
|
|
|
|
|
if(iter != blocks.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return (*iter).second;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(blockcoord.x >= 0 && blockcoord.x < x_bmax &&
|
|
|
|
|
|
|
|
blockcoord.y >= 0 && blockcoord.y < y_bmax &&
|
|
|
|
|
|
|
|
blockcoord.z >= 0 && blockcoord.z < z_max)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Block * nblo;
|
|
|
|
|
|
|
|
if(validgeo)
|
|
|
|
|
|
|
|
nblo = new Block(blockcoord, &layerassign);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nblo = new Block(blockcoord);
|
|
|
|
|
|
|
|
blocks[blockcoord] = nblo;
|
|
|
|
|
|
|
|
return nblo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tiletype baseTiletypeAt (DFCoord tilecoord)
|
|
|
|
df::tiletype baseTiletypeAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->BaseTileTypeAt(tilecoord) : tiletype::Void;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->BaseTileTypeAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tiletype::Void;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
df::tiletype tiletypeAt (DFCoord tilecoord)
|
|
|
|
df::tiletype tiletypeAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->TileTypeAt(tilecoord) : tiletype::Void;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->TileTypeAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tiletype::Void;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTiletypeAt(DFCoord tilecoord, df::tiletype tiletype)
|
|
|
|
bool setTiletypeAt(DFCoord tilecoord, df::tiletype tiletype)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
if(b && b->valid)
|
|
|
|
return b->setTiletypeAt(tilecoord, tiletype);
|
|
|
|
{
|
|
|
|
|
|
|
|
b->setTiletypeAt(tilecoord % 16, tiletype);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t temperature1At (DFCoord tilecoord)
|
|
|
|
uint16_t temperature1At (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->temperature1At(tilecoord) : 0;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->temperature1At(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTemp1At(DFCoord tilecoord, uint16_t temperature)
|
|
|
|
bool setTemp1At(DFCoord tilecoord, uint16_t temperature)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
if(b && b->valid)
|
|
|
|
return b->setTemp1At(tilecoord, temperature);
|
|
|
|
{
|
|
|
|
|
|
|
|
b->setTemp1At(tilecoord % 16, temperature);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t temperature2At (DFCoord tilecoord)
|
|
|
|
uint16_t temperature2At (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->temperature2At(tilecoord) : 0;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->temperature2At(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setTemp2At(DFCoord tilecoord, uint16_t temperature)
|
|
|
|
bool setTemp2At(DFCoord tilecoord, uint16_t temperature)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
if(b && b->valid)
|
|
|
|
return b->setTemp2At(tilecoord, temperature);
|
|
|
|
{
|
|
|
|
|
|
|
|
b->setTemp2At(tilecoord % 16, temperature);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t veinMaterialAt (DFCoord tilecoord)
|
|
|
|
int16_t veinMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->veinMaterialAt(tilecoord) : -1;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->veinMaterialAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int16_t baseMaterialAt (DFCoord tilecoord)
|
|
|
|
int16_t baseMaterialAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->baseMaterialAt(tilecoord) : -1;
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->baseMaterialAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool clearVeinMaterialAt (DFCoord tilecoord)
|
|
|
|
|
|
|
|
{
|
|
|
|
int16_t tagAt(DFCoord tilecoord)
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
|
|
|
|
if(b && b->valid)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
b->ClearVeinMaterialAt(tilecoord % 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
|
|
|
|
return b ? b->tag(tilecoord) : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
void setTagAt(DFCoord tilecoord, int16_t val)
|
|
|
|
}
|
|
|
|
|
|
|
|
bool clearBaseMaterialAt (DFCoord tilecoord)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
|
|
|
|
if(b && b->valid)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
b->ClearBaseMaterialAt(tilecoord % 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
}
|
|
|
|
if (b) b->tag(tilecoord) = val;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_designation designationAt (DFCoord tilecoord)
|
|
|
|
df::tile_designation designationAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->DesignationAt(tilecoord) : df::tile_designation(0);
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->DesignationAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
df::tile_designation temp;
|
|
|
|
|
|
|
|
temp.whole = 0;
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des)
|
|
|
|
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if(Block * b= BlockAtTile(tilecoord))
|
|
|
|
if(b && b->valid)
|
|
|
|
return b->setDesignationAt(tilecoord, des);
|
|
|
|
{
|
|
|
|
|
|
|
|
b->setDesignationAt(tilecoord % 16, des);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_occupancy occupancyAt (DFCoord tilecoord)
|
|
|
|
df::tile_occupancy occupancyAt (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return b ? b->OccupancyAt(tilecoord) : df::tile_occupancy(0);
|
|
|
|
{
|
|
|
|
|
|
|
|
return b->OccupancyAt(tilecoord % 16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
df::tile_occupancy temp;
|
|
|
|
|
|
|
|
temp.whole = 0;
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setOccupancyAt (DFCoord tilecoord, df::tile_occupancy occ)
|
|
|
|
bool setOccupancyAt (DFCoord tilecoord, df::tile_occupancy occ)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
if (Block * b= BlockAtTile(tilecoord))
|
|
|
|
if(b && b->valid)
|
|
|
|
return b->setOccupancyAt(tilecoord, occ);
|
|
|
|
{
|
|
|
|
|
|
|
|
b->setOccupancyAt(tilecoord % 16, occ);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool testCoord (DFCoord tilecoord)
|
|
|
|
bool testCoord (DFCoord tilecoord)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Block * b= BlockAt(tilecoord / 16);
|
|
|
|
Block * b= BlockAtTile(tilecoord);
|
|
|
|
if(b && b->valid)
|
|
|
|
return (b && b->valid);
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WriteAll()
|
|
|
|
bool WriteAll()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::map<DFCoord, Block *>::iterator p;
|
|
|
|
std::map<DFCoord, Block *>::iterator p;
|
|
|
@ -508,15 +340,25 @@ class MapCache
|
|
|
|
}
|
|
|
|
}
|
|
|
|
blocks.clear();
|
|
|
|
blocks.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
volatile bool valid;
|
|
|
|
uint32_t maxBlockX() { return x_bmax; }
|
|
|
|
volatile bool validgeo;
|
|
|
|
uint32_t maxBlockY() { return y_bmax; }
|
|
|
|
|
|
|
|
uint32_t maxTileX() { return x_tmax; }
|
|
|
|
|
|
|
|
uint32_t maxTileY() { return y_tmax; }
|
|
|
|
|
|
|
|
uint32_t maxZ() { return z_max; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend class Block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
bool validgeo;
|
|
|
|
uint32_t x_bmax;
|
|
|
|
uint32_t x_bmax;
|
|
|
|
uint32_t y_bmax;
|
|
|
|
uint32_t y_bmax;
|
|
|
|
uint32_t x_tmax;
|
|
|
|
uint32_t x_tmax;
|
|
|
|
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<int16_t> geoidx;
|
|
|
|
|
|
|
|
std::vector< std::vector <int16_t> > layer_mats;
|
|
|
|
std::map<DFCoord, Block *> blocks;
|
|
|
|
std::map<DFCoord, Block *> blocks;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|