From b630e93c5a24c534cc5fed7554ca26e96ccd386e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Apr 2011 17:01:58 +0200 Subject: [PATCH] Added base layer material support to map cache, material display to dfprobe. --- library/include/dfhack/extra/MapExtras.h | 50 ++++++++++++++++++++++-- tools/supported/probe.cpp | 24 +++++++++++- tools/supported/prospector.cpp | 1 - 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/library/include/dfhack/extra/MapExtras.h b/library/include/dfhack/extra/MapExtras.h index 60dee4881..003138060 100644 --- a/library/include/dfhack/extra/MapExtras.h +++ b/library/include/dfhack/extra/MapExtras.h @@ -36,10 +36,29 @@ void SquashVeins (DFHack::Maps *m, DFHack::DFCoord bcoord, DFHack::mapblock40d & } } +void SquashRocks ( vector< vector > * layerassign, DFHack::mapblock40d & mb, DFHack::t_blockmaterials & materials) +{ + // get the layer materials + for(uint32_t xx = 0;xx<16;xx++) + { + for (uint32_t yy = 0; yy< 16;yy++) + { + uint8_t test = mb.designation[xx][yy].bits.biome; + if( test >= sizeof(mb.biome_indices)) + { + materials[xx][yy] = -1; + continue; + } + materials[xx][yy] = + layerassign->at(mb.biome_indices[test])[mb.designation[xx][yy].bits.geolayer_index]; + } + } +} + class Block { public: - Block(DFHack::Maps *_m, DFHack::DFCoord _bcoord) + Block(DFHack::Maps *_m, DFHack::DFCoord _bcoord, vector< vector > * layerassign = 0) { m = _m; dirty_designations = false; @@ -50,15 +69,23 @@ class Block bcoord = _bcoord; if(m->ReadBlock40d(bcoord.x,bcoord.y,bcoord.z,&raw)) { + m->ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2); SquashVeins(m,bcoord,raw,veinmats); + if(layerassign) + SquashRocks(layerassign,raw,basemats); + else + memset(basemats,-1,sizeof(basemats)); valid = true; } - m->ReadTemperatures(bcoord.x,bcoord.y, bcoord.z,&temp1,&temp2); } int16_t veinMaterialAt(DFHack::DFCoord p) { return veinmats[p.x][p.y]; } + int16_t baseMaterialAt(DFHack::DFCoord p) + { + return basemats[p.x][p.y]; + } void ClearMaterialAt(DFHack::DFCoord p) { veinmats[p.x][p.y] = -1; @@ -162,6 +189,7 @@ class Block DFHack::mapblock40d raw; DFHack::DFCoord bcoord; DFHack::t_blockmaterials veinmats; + DFHack::t_blockmaterials basemats; DFHack::t_temperatures temp1; DFHack::t_temperatures temp2; }; @@ -174,6 +202,7 @@ class MapCache valid = 0; this->Maps = Maps; Maps->getSize(x_bmax, y_bmax, z_max); + validgeo = Maps->ReadGeology( layerassign ); valid = true; }; ~MapCache() @@ -203,7 +232,11 @@ class MapCache { if(blockcoord.x < x_bmax && blockcoord.y < y_bmax && blockcoord.z < z_max) { - Block * nblo = new Block(Maps,blockcoord); + Block * nblo; + if(validgeo) + nblo = new Block(Maps,blockcoord, &layerassign); + else + nblo = new Block(Maps,blockcoord); blocks[blockcoord] = nblo; return nblo; } @@ -279,6 +312,15 @@ class MapCache } return 0; } + int16_t baseMaterialAt (DFHack::DFCoord tilecoord) + { + Block * b= BlockAt(tilecoord / 16); + if(b && b->valid) + { + return b->baseMaterialAt(tilecoord % 16); + } + return 0; + } bool clearMaterialAt (DFHack::DFCoord tilecoord) { Block * b= BlockAt(tilecoord / 16); @@ -331,11 +373,13 @@ class MapCache } private: volatile bool valid; + volatile bool validgeo; uint32_t x_bmax; uint32_t y_bmax; uint32_t x_tmax; uint32_t y_tmax; uint32_t z_max; + vector< vector > layerassign; DFHack::Maps * Maps; map blocks; }; diff --git a/tools/supported/probe.cpp b/tools/supported/probe.cpp index 219e59e64..a5ac7c295 100644 --- a/tools/supported/probe.cpp +++ b/tools/supported/probe.cpp @@ -7,6 +7,7 @@ #include #include #include +using namespace std; #define DFHACK_WANT_MISCUTILS 1 #define DFHACK_WANT_TILETYPES 1 @@ -37,13 +38,15 @@ int main (int numargs, const char ** args) DFHack::Gui *Gui = DF->getGui(); + DFHack::Materials *Materials = DF->getMaterials(); DFHack::VersionInfo* mem = DF->getMemoryInfo(); DFHack::Maps *Maps = DF->getMaps(); DFHack::Process * p = DF->getProcess(); + bool hasmats = Materials->ReadInorganicMaterials(); if(!Maps->Start()) { - cerr << "Unable to access map data!" << endl; + std::cerr << "Unable to access map data!" << std::endl; } else { @@ -122,7 +125,24 @@ int main (int numargs, const char ** args) // biome, geolayer std::cout << "biome: " << des.biome << std::endl; std::cout << "geolayer: " << des.geolayer_index << std::endl; - + int16_t base_rock = mc.baseMaterialAt(cursor); + if(base_rock != -1) + { + cout << "Layer material: " << dec << base_rock; + if(hasmats) + cout << " / " << Materials->inorganic[base_rock].id << " / " << Materials->inorganic[base_rock].name << endl; + else + cout << endl; + } + int16_t vein_rock = mc.veinMaterialAt(cursor); + if(vein_rock != -1) + { + cout << "Vein material (final): " << dec << vein_rock; + if(hasmats) + cout << " / " << Materials->inorganic[vein_rock].id << " / " << Materials->inorganic[vein_rock].name << endl; + else + cout << endl; + } // liquids if(des.flow_size) { diff --git a/tools/supported/prospector.cpp b/tools/supported/prospector.cpp index fc19d7bec..1c99a8b2c 100644 --- a/tools/supported/prospector.cpp +++ b/tools/supported/prospector.cpp @@ -167,7 +167,6 @@ int main (int argc, const char* argv[]) if(showbaselayers) { - //Maps->ReadRegionOffsets(x,y,z, ®ionoffsets); // get the layer materials for(uint32_t xx = 0;xx<16;xx++) {