Split veinlook output into layer vein and base type, fix issue with bad counts of materials.

develop
Petr Mrázek 2011-04-17 15:51:52 +02:00
parent cf3534bc42
commit 189f31e084
1 changed files with 127 additions and 48 deletions

@ -67,8 +67,10 @@ int main (int argc, const char* argv[])
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::mapblock40d Block; DFHack::mapblock40d Block;
map <int16_t, uint32_t> materials; map <int16_t, uint32_t> hardcoded_m;
materials.clear(); map <int16_t, uint32_t> layer_m;
map <int16_t, uint32_t> vein_m;
vector<DFHack::t_feature> global_features; vector<DFHack::t_feature> global_features;
std::map <DFHack::DFCoord, std::vector<DFHack::t_feature *> > local_features; std::map <DFHack::DFCoord, std::vector<DFHack::t_feature *> > local_features;
@ -160,11 +162,26 @@ int main (int argc, const char* argv[])
Maps->ReadBlock40d(x,y,z, &Block); Maps->ReadBlock40d(x,y,z, &Block);
DFHack::tiletypes40d & tt = Block.tiletypes; DFHack::tiletypes40d & tt = Block.tiletypes;
memset(tempvein, -1, sizeof(tempvein)); // hardcoded materials
veins.clear(); for(uint32_t xx = 0;xx<16;xx++)
Maps->ReadVeins(x,y,z,&veins); {
for (uint32_t yy = 0; yy< 16;yy++)
{
DFHack::TileMaterial mat = DFHack::tileMaterial(tt[xx][yy]);
if(!DFHack::isWallTerrain(tt[xx][yy]))
continue;
if(hardcoded_m.count(mat))
{
hardcoded_m[mat] += 1;
}
else
{
hardcoded_m[mat] = 1;
}
}
}
// layer stone and soil
if(showbaselayers) if(showbaselayers)
{ {
// get the layer materials // get the layer materials
@ -173,8 +190,11 @@ int main (int argc, const char* argv[])
for (uint32_t yy = 0; yy< 16;yy++) for (uint32_t yy = 0; yy< 16;yy++)
{ {
DFHack::TileMaterial mat = DFHack::tileMaterial(tt[xx][yy]); DFHack::TileMaterial mat = DFHack::tileMaterial(tt[xx][yy]);
DFHack::TileShape shape = DFHack::TileShape(tt[xx][yy]);
if(mat != DFHack::SOIL && mat != DFHack::STONE) if(mat != DFHack::SOIL && mat != DFHack::STONE)
continue; continue;
if(!DFHack::isWallTerrain(tt[xx][yy]))
continue;
uint8_t test = Block.designation[xx][yy].bits.biome; uint8_t test = Block.designation[xx][yy].bits.biome;
if(test > maximum_regionoffset) if(test > maximum_regionoffset)
maximum_regionoffset = test; maximum_regionoffset = test;
@ -183,14 +203,49 @@ int main (int argc, const char* argv[])
num_overflows++; num_overflows++;
continue; continue;
} }
tempvein[xx][yy] = uint16_t mat2 = layerassign [Block.biome_indices[test]] [Block.designation[xx][yy].bits.geolayer_index];
layerassign if(layer_m.count(mat2))
[Block.biome_indices[test]] {
[Block.designation[xx][yy].bits.geolayer_index]; layer_m[mat2] += 1;
}
else
{
layer_m[mat2] = 1;
}
}
}
}
// global feature overrides
int16_t idx = Block.global_feature;
if( idx != -1 && uint16_t(idx) < global_features.size() && global_features[idx].type == DFHack::feature_Underworld)
{
for(uint32_t xi = 0 ; xi< 16 ; xi++) for(uint32_t yi = 0 ; yi< 16 ; yi++)
{
if(!DFHack::isWallTerrain(tt[xi][yi]))
continue;
DFHack::TileMaterial mat = DFHack::tileMaterial(tt[xi][yi]);
if(Block.designation[xi][yi].bits.feature_global && mat == DFHack::FEATSTONE)
{
if(global_features[idx].main_material == 0) // stone
{
int32_t mat2 = global_features[idx].sub_material;
if(layer_m.count(mat2))
{
layer_m[mat2] += 1;
}
else
{
layer_m[mat2] = 1;
}
}
} }
} }
} }
// vein stones
memset(tempvein, 0xff, sizeof(tempvein));
veins.clear();
Maps->ReadVeins(x,y,z,&veins);
// for each vein // for each vein
for(int i = 0; i < (int)veins.size();i++) for(int i = 0; i < (int)veins.size();i++)
{ {
@ -214,27 +269,6 @@ int main (int argc, const char* argv[])
} }
} }
// global feature overrides
int16_t idx = Block.global_feature;
if( idx != -1 && uint16_t(idx) < global_features.size() && global_features[idx].type == DFHack::feature_Underworld)
{
for(uint32_t xi = 0 ; xi< 16 ; xi++) for(uint32_t yi = 0 ; yi< 16 ; yi++)
{
DFHack::TileMaterial mat = DFHack::tileMaterial(tt[xi][yi]);
if(Block.designation[xi][yi].bits.feature_global && mat == DFHack::FEATSTONE)
{
if(global_features[idx].main_material == 0) // stone
{
tempvein[xi][yi] = global_features[idx].sub_material;
}
else
{
tempvein[xi][yi] = -1;
}
}
}
}
idx = Block.local_feature; idx = Block.local_feature;
if( idx != -1 ) if( idx != -1 )
{ {
@ -265,25 +299,28 @@ int main (int argc, const char* argv[])
} }
} }
// count the material types // count the vein material types
for(uint32_t xi = 0 ; xi< 16 ; xi++) for(uint32_t xi = 0 ; xi< 16 ; xi++)
{ {
for(uint32_t yi = 0 ; yi< 16 ; yi++) for(uint32_t yi = 0 ; yi< 16 ; yi++)
{ {
// hidden tiles are ignored unless '-a' is provided on the command line // hidden tiles are ignored unless '-a' is provided on the command line
// non-wall tiles are ignored // non-wall tiles are ignored
if( (Block.designation[xi][yi].bits.hidden && !showhidden) || !DFHack::isWallTerrain(Block.tiletypes[xi][yi])) if( (Block.designation[xi][yi].bits.hidden && !showhidden)
|| !DFHack::isWallTerrain(Block.tiletypes[xi][yi])
)
continue; continue;
// ignore stuff that isn't a vein
if(tempvein[xi][yi] < 0) if(tempvein[xi][yi] < 0)
continue; continue;
if(materials.count(tempvein[xi][yi])) if(vein_m.count(tempvein[xi][yi]))
{ {
materials[tempvein[xi][yi]] += 1; vein_m[tempvein[xi][yi]] += 1;
} }
else else
{ {
materials[tempvein[xi][yi]] = 1; vein_m[tempvein[xi][yi]] = 1;
} }
} }
} }
@ -291,16 +328,34 @@ int main (int argc, const char* argv[])
} }
} }
// print report // print report
cout << "Maximal regionoffset seen: " << maximum_regionoffset << ".";
// some layer/geology debug stuff
if(maximum_regionoffset >= sizeof(Block.biome_indices) ) if(maximum_regionoffset >= sizeof(Block.biome_indices) )
{ {
cout << " This is above the regionoffsets array size!" << endl; cerr << "Maximal regionoffset seen: " << maximum_regionoffset << ".";
cout << "Number of overflows: " << num_overflows; cerr << " This is above the regionoffsets array size!" << endl;
cerr << "Number of overflows: " << num_overflows;
cerr << endl;
} }
cout << endl;
vector <pair <int16_t, uint32_t> > matss; vector <pair <int16_t, uint32_t> > veins_sort;
vector <pair <int16_t, uint32_t> > layers_sort;
vector <pair <int16_t, uint32_t> > hardcoded_sort;
map<int16_t, uint32_t>::iterator p; map<int16_t, uint32_t>::iterator p;
for(p = materials.begin(); p != materials.end(); p++) // HARDCODED
cout << endl << "Base materials:" << endl;
for(p = hardcoded_m.begin(); p != hardcoded_m.end(); p++)
{
hardcoded_sort.push_back( pair<int16_t,uint32_t>(p->first, p->second) );
}
std::sort(hardcoded_sort.begin(), hardcoded_sort.end(), compare_pair_second<>());
for(size_t i = 0; i < hardcoded_sort.size();i++)
{
cout << DFHack::TileMaterialString[hardcoded_sort[i].first] << " : " << hardcoded_sort[i].second << endl;
}
// LAYERS
cout << endl << "Layer materials:" << endl;
for(p = layer_m.begin(); p != layer_m.end(); p++)
{ {
if(p->first == -1) if(p->first == -1)
{ {
@ -308,19 +363,43 @@ int main (int argc, const char* argv[])
} }
else else
{ {
matss.push_back( pair<int16_t,uint32_t>(p->first, p->second) ); layers_sort.push_back( pair<int16_t,uint32_t>(p->first, p->second) );
} }
} }
std::sort(matss.begin(), matss.end(), compare_pair_second<>()); std::sort(layers_sort.begin(), layers_sort.end(), compare_pair_second<>());
for(size_t i = 0; i < matss.size();i++) for(size_t i = 0; i < layers_sort.size();i++)
{ {
if(matss[i].first >= Mats->inorganic.size()) if(layers_sort[i].first >= Mats->inorganic.size())
{ {
cerr << "Error, material out of bounds: " << matss[i].first << endl; cerr << "Error, material out of bounds: " << layers_sort[i].first << endl;
continue; continue;
} }
cout << Mats->inorganic[matss[i].first].id << " : " << matss[i].second << endl; cout << Mats->inorganic[layers_sort[i].first].id << " : " << layers_sort[i].second << endl;
}
// VEINS
cout << endl << "Vein materials:" << endl;
for(p = vein_m.begin(); p != vein_m.end(); p++)
{
if(p->first == -1)
{
cout << "Non-stone" << " : " << p->second << endl;
} }
else
{
veins_sort.push_back( pair<int16_t,uint32_t>(p->first, p->second) );
}
}
std::sort(veins_sort.begin(), veins_sort.end(), compare_pair_second<>());
for(size_t i = 0; i < veins_sort.size();i++)
{
if(veins_sort[i].first >= Mats->inorganic.size())
{
cerr << "Error, material out of bounds: " << veins_sort[i].first << endl;
continue;
}
cout << Mats->inorganic[veins_sort[i].first].id << " : " << veins_sort[i].second << endl;
}
DF->Detach(); DF->Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;