2009-09-13 18:02:46 -06:00
|
|
|
// produces a list of vein materials available on the map. can be run with '-a' modifier to show even unrevealed minerals deep underground
|
|
|
|
// with -b modifier, it will show base layer materials too
|
|
|
|
|
|
|
|
// TODO: use material colors to make the output prettier
|
|
|
|
// TODO: needs the tiletype filter!
|
|
|
|
// TODO: tile override materials
|
|
|
|
// TODO: material types, trees, ice, constructions
|
|
|
|
// TODO: GUI
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string.h> // for memset
|
2009-10-04 07:08:20 -06:00
|
|
|
#include <string>
|
2009-09-13 18:02:46 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2010-03-31 09:31:49 -06:00
|
|
|
#include <stdio.h>
|
2010-06-20 16:31:43 -06:00
|
|
|
#include <algorithm>
|
2009-09-13 18:02:46 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2010-05-26 04:24:45 -06:00
|
|
|
#include <dfhack/DFTileTypes.h>
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2010-06-20 16:31:43 -06:00
|
|
|
template<template <typename> class P = std::less >
|
|
|
|
struct compare_pair_first
|
|
|
|
{
|
|
|
|
template<class T1, class T2>
|
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T1>()(left.first, right.first);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<template <typename> class P = std::less >
|
|
|
|
struct compare_pair_second
|
|
|
|
{
|
|
|
|
template<class T1, class T2>
|
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T2>()(left.second, right.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
int main (int argc, const char* argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
bool showhidden = false;
|
|
|
|
bool showbaselayers = false;
|
|
|
|
for(int i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
string test = argv[i];
|
|
|
|
if(test == "-a")
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
}
|
|
|
|
else if(test == "-b")
|
|
|
|
{
|
|
|
|
showbaselayers = true;
|
|
|
|
}
|
|
|
|
else if(test == "-ab" || test == "-ba")
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
showbaselayers = true;
|
|
|
|
}
|
|
|
|
}
|
2009-09-14 15:19:33 -06:00
|
|
|
// let's be more useful when double-clicked on windows
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
showhidden = true;
|
|
|
|
#endif
|
2009-09-13 18:02:46 -06:00
|
|
|
uint32_t x_max,y_max,z_max;
|
2010-04-23 17:15:15 -06:00
|
|
|
/*
|
2010-03-25 14:37:09 -06:00
|
|
|
DFHack::tiletypes40d tiletypes;
|
|
|
|
DFHack::designations40d designations;
|
|
|
|
DFHack::biome_indices40d regionoffsets;
|
2010-04-23 17:15:15 -06:00
|
|
|
*/
|
|
|
|
DFHack::mapblock40d Block;
|
2009-09-13 18:02:46 -06:00
|
|
|
map <int16_t, uint32_t> materials;
|
|
|
|
materials.clear();
|
2010-04-23 17:15:15 -06:00
|
|
|
vector<DFHack::t_feature> global_features;
|
|
|
|
std::map <DFHack::planecoord, std::vector<DFHack::t_feature *> > local_features;
|
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
vector< vector <uint16_t> > layerassign;
|
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context *DF;
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
cerr << e.what() << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-09-13 18:02:46 -06:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::Maps * Maps = DF->getMaps();
|
|
|
|
DFHack::Materials * Mats = DF->getMaterials();
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
// init the map
|
2010-04-04 16:48:19 -06:00
|
|
|
if(!Maps->Start())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
|
|
|
cerr << "Can't init map." << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
2010-04-04 16:48:19 -06:00
|
|
|
Maps->getSize(x_max,y_max,z_max);
|
2010-05-22 05:20:58 -06:00
|
|
|
|
2010-04-23 17:15:15 -06:00
|
|
|
if(!Maps->ReadGlobalFeatures(global_features))
|
|
|
|
{
|
|
|
|
cerr << "Can't get global features." << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!Maps->ReadLocalFeatures(local_features))
|
|
|
|
{
|
|
|
|
cerr << "Can't get local features." << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 1;
|
2010-05-22 05:20:58 -06:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
// get stone matgloss mapping
|
2010-04-28 10:09:32 -06:00
|
|
|
if(!Mats->ReadInorganicMaterials())
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
//DF.DestroyMap();
|
|
|
|
cerr << "Can't get the materials." << endl;
|
2010-03-26 06:01:46 -06:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-09-13 18:02:46 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-05-22 12:14:17 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
// get region geology
|
2010-04-04 21:29:46 -06:00
|
|
|
if(!Maps->ReadGeology( layerassign ))
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
cerr << "Can't get region geology." << endl;
|
2010-03-26 06:01:46 -06:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-09-13 18:02:46 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-05-22 12:14:17 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
int16_t tempvein [16][16];
|
2009-12-12 17:47:58 -07:00
|
|
|
vector <DFHack::t_vein> veins;
|
2010-03-31 09:31:49 -06:00
|
|
|
uint32_t maximum_regionoffset = 0;
|
|
|
|
uint32_t num_overflows = 0;
|
2009-09-13 18:02:46 -06:00
|
|
|
// walk the map!
|
|
|
|
for(uint32_t x = 0; x< x_max;x++)
|
|
|
|
{
|
|
|
|
for(uint32_t y = 0; y< y_max;y++)
|
|
|
|
{
|
|
|
|
for(uint32_t z = 0; z< z_max;z++)
|
|
|
|
{
|
2010-04-04 16:48:19 -06:00
|
|
|
if(!Maps->isValidBlock(x,y,z))
|
2009-09-13 18:02:46 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// read data
|
2010-04-23 17:15:15 -06:00
|
|
|
Maps->ReadBlock40d(x,y,z, &Block);
|
|
|
|
//Maps->ReadTileTypes(x,y,z, &tiletypes);
|
|
|
|
//Maps->ReadDesignations(x,y,z, &designations);
|
2009-09-13 18:02:46 -06:00
|
|
|
|
|
|
|
memset(tempvein, -1, sizeof(tempvein));
|
|
|
|
veins.clear();
|
2010-04-10 18:08:21 -06:00
|
|
|
Maps->ReadVeins(x,y,z,&veins);
|
2010-04-04 21:29:46 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
if(showbaselayers)
|
|
|
|
{
|
2010-04-23 17:15:15 -06:00
|
|
|
//Maps->ReadRegionOffsets(x,y,z, ®ionoffsets);
|
2009-09-13 18:02:46 -06:00
|
|
|
// get the layer materials
|
|
|
|
for(uint32_t xx = 0;xx<16;xx++)
|
|
|
|
{
|
|
|
|
for (uint32_t yy = 0; yy< 16;yy++)
|
|
|
|
{
|
2010-04-23 17:15:15 -06:00
|
|
|
uint8_t test = Block.designation[xx][yy].bits.biome;
|
2010-03-31 09:31:49 -06:00
|
|
|
if(test > maximum_regionoffset)
|
|
|
|
maximum_regionoffset = test;
|
2010-04-23 17:15:15 -06:00
|
|
|
if( test >= sizeof(Block.biome_indices))
|
2010-03-31 09:31:49 -06:00
|
|
|
{
|
|
|
|
num_overflows++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
tempvein[xx][yy] =
|
|
|
|
layerassign
|
2010-04-23 17:15:15 -06:00
|
|
|
[Block.biome_indices[test]]
|
|
|
|
[Block.designation[xx][yy].bits.geolayer_index];
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-04 21:29:46 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
// for each vein
|
2009-10-04 07:08:20 -06:00
|
|
|
for(int i = 0; i < (int)veins.size();i++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
//iterate through vein rows
|
|
|
|
for(uint32_t j = 0;j<16;j++)
|
|
|
|
{
|
|
|
|
//iterate through the bits
|
|
|
|
for (uint32_t k = 0; k< 16;k++)
|
|
|
|
{
|
|
|
|
// and the bit array with a one-bit mask, check if the bit is set
|
2009-10-04 07:08:20 -06:00
|
|
|
bool set = !!(((1 << k) & veins[i].assignment[j]) >> k);
|
2009-09-13 18:02:46 -06:00
|
|
|
if(set)
|
|
|
|
{
|
|
|
|
// store matgloss
|
|
|
|
tempvein[k][j] = veins[i].type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-23 17:15:15 -06:00
|
|
|
|
|
|
|
// 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(Block.designation[xi][yi].bits.feature_global)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
if( idx != -1 )
|
|
|
|
{
|
|
|
|
DFHack::planecoord pc;
|
|
|
|
pc.dim.x = x;
|
|
|
|
pc.dim.y = y;
|
|
|
|
std::map <DFHack::planecoord, std::vector<DFHack::t_feature *> >::iterator it;
|
|
|
|
it = local_features.find(pc);
|
|
|
|
if(it != local_features.end())
|
|
|
|
{
|
|
|
|
std::vector<DFHack::t_feature *>& vectr = (*it).second;
|
|
|
|
if(uint16_t(idx) < vectr.size() && vectr[idx]->type == DFHack::feature_Adamantine_Tube)
|
|
|
|
for(uint32_t xi = 0 ; xi< 16 ; xi++) for(uint32_t yi = 0 ; yi< 16 ; yi++)
|
|
|
|
{
|
2010-04-25 16:51:45 -06:00
|
|
|
if(Block.designation[xi][yi].bits.feature_local && DFHack::isWallTerrain(Block.tiletypes[xi][yi]))
|
2010-04-23 17:15:15 -06:00
|
|
|
{
|
|
|
|
if(vectr[idx]->main_material == 0) // stone
|
|
|
|
{
|
|
|
|
tempvein[xi][yi] = vectr[idx]->sub_material;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempvein[xi][yi] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
// count the material types
|
|
|
|
for(uint32_t xi = 0 ; xi< 16 ; xi++)
|
|
|
|
{
|
|
|
|
for(uint32_t yi = 0 ; yi< 16 ; yi++)
|
|
|
|
{
|
|
|
|
// hidden tiles are ignored unless '-a' is provided on the command line
|
|
|
|
// non-wall tiles are ignored
|
2010-04-23 17:15:15 -06:00
|
|
|
if( (Block.designation[xi][yi].bits.hidden && !showhidden) || !DFHack::isWallTerrain(Block.tiletypes[xi][yi]))
|
2009-09-13 18:02:46 -06:00
|
|
|
continue;
|
|
|
|
if(tempvein[xi][yi] < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(materials.count(tempvein[xi][yi]))
|
|
|
|
{
|
|
|
|
materials[tempvein[xi][yi]] += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
materials[tempvein[xi][yi]] = 1;
|
|
|
|
}
|
2009-11-05 18:04:17 -07:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// print report
|
2010-03-31 09:31:49 -06:00
|
|
|
cout << "Maximal regionoffset seen: " << maximum_regionoffset << ".";
|
2010-04-23 17:15:15 -06:00
|
|
|
if(maximum_regionoffset >= sizeof(Block.biome_indices) )
|
2010-03-31 09:31:49 -06:00
|
|
|
{
|
|
|
|
cout << " This is above the regionoffsets array size!" << endl;
|
|
|
|
cout << "Number of overflows: " << num_overflows;
|
|
|
|
}
|
|
|
|
cout << endl;
|
2010-06-20 16:31:43 -06:00
|
|
|
vector <pair <int16_t, uint32_t> > matss;
|
2009-09-13 18:02:46 -06:00
|
|
|
map<int16_t, uint32_t>::iterator p;
|
|
|
|
for(p = materials.begin(); p != materials.end(); p++)
|
|
|
|
{
|
2010-04-23 17:15:15 -06:00
|
|
|
if(p->first == -1)
|
|
|
|
{
|
|
|
|
cout << "Non-stone" << " : " << p->second << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-20 16:31:43 -06:00
|
|
|
matss.push_back( pair<int16_t,uint32_t>(p->first, p->second) );
|
2010-04-23 17:15:15 -06:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2010-06-20 16:31:43 -06:00
|
|
|
std::sort(matss.begin(), matss.end(), compare_pair_second<>());
|
|
|
|
for(int i = 0; i < matss.size();i++)
|
|
|
|
{
|
2010-08-28 07:43:53 -06:00
|
|
|
if(matss[i].first >= Mats->inorganic.size())
|
|
|
|
{
|
|
|
|
cerr << "Error, material out of bounds: " << matss[i].first << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-20 16:31:43 -06:00
|
|
|
cout << Mats->inorganic[matss[i].first].id << " : " << matss[i].second << endl;
|
|
|
|
}
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Detach();
|
2009-11-05 18:04:17 -07:00
|
|
|
#ifndef LINUX_BUILD
|
2010-03-26 06:01:46 -06:00
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
2009-11-05 18:04:17 -07:00
|
|
|
#endif
|
2009-09-13 18:02:46 -06:00
|
|
|
return 0;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|