Messing with materials.

develop
Petr Mrázek 2011-11-03 04:30:59 +01:00
parent 550cde83f3
commit 4f0695a6d5
6 changed files with 66 additions and 69 deletions

@ -22,6 +22,7 @@
//basic includes //basic includes
#include <string> #include <string>
#include <stdint.h>
//forwards //forwards
class MD5; class MD5;

@ -292,12 +292,20 @@ namespace DFHack
int32_t SOAP_LEVEL; int32_t SOAP_LEVEL;
std::string PREFIX; std::string PREFIX;
// etc... // etc...
bool isGem()
{
return mat_flags.is_set(MATERIAL_IS_GEM);
};
bool isStone()
{
mat_flags.is_set(MATERIAL_IS_STONE);
};
}; };
/// Research by Quietust /// Research by Quietust
struct df_inorganic_base struct df_inorganic_type
{ {
std::string Inorganic_ID; std::string ID;
BitArray<inorganic_flags> inorg_flags; BitArray<inorganic_flags> inorg_flags;
std::vector <uint32_t> empty1; std::vector <uint32_t> empty1;
std::vector <int16_t> METAL_ORE_matID; // Vector of indexes of metals produced when ore is smelted std::vector <int16_t> METAL_ORE_matID; // Vector of indexes of metals produced when ore is smelted
@ -314,8 +322,16 @@ namespace DFHack
std::vector <int16_t> ENVIRONMENT_inclusion_type; std::vector <int16_t> ENVIRONMENT_inclusion_type;
std::vector <int8_t> ENVIRONMENT_prob; std::vector <int8_t> ENVIRONMENT_prob;
int32_t unknown_in_2; int32_t unknown_in_2;
df_material mat;
bool isOre()
{
if(!METAL_ORE_matID.empty())
return true;
if(!THREAD_METAL_matID.empty())
return true;
return false;
}
}; };
struct df_inorganic_material:public df_inorganic_base, public df_material {};
/** /**
* A copy of the game's material data. * A copy of the game's material data.
* \ingroup grp_materials * \ingroup grp_materials
@ -691,14 +707,10 @@ namespace DFHack
GRIME GRIME
}; };
std::vector<df_inorganic_material*>* df_inorganic; std::vector<df_inorganic_type*>* df_inorganic;
std::vector<t_matglossInorganic> inorganic;
std::vector<df_plant_type*>* df_organic; std::vector<df_plant_type*>* df_organic;
std::vector<t_matgloss> organic;
std::vector<df_plant_type*>* df_trees; std::vector<df_plant_type*>* df_trees;
std::vector<t_matgloss> tree;
std::vector<df_plant_type*>* df_plants; std::vector<df_plant_type*>* df_plants;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race; std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx; std::vector<t_creaturetype> raceEx;
@ -706,10 +718,11 @@ namespace DFHack
std::vector<t_matglossOther> other; std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc; std::vector<t_matgloss> alldesc;
bool ReadInorganicMaterials (void); bool CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic);
bool ReadOrganicMaterials (void); bool CopyOrganicMaterials (std::vector<t_matgloss> & organic);
bool ReadWoodMaterials (void); bool CopyWoodMaterials (std::vector<t_matgloss> & tree);
bool ReadPlantMaterials (void); bool CopyPlantMaterials (std::vector<t_matgloss> & plant);
bool ReadCreatureTypes (void); bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void); bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void); bool ReadDescriptorColors(void);

@ -126,7 +126,7 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
return true; return true;
} }
bool Materials::ReadInorganicMaterials (void) bool Materials::CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic)
{ {
Process * p = d->owner; Process * p = d->owner;
if(!df_inorganic) if(!df_inorganic)
@ -136,41 +136,41 @@ bool Materials::ReadInorganicMaterials (void)
inorganic.reserve (size); inorganic.reserve (size);
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
df_inorganic_material * orig = df_inorganic->at(i); df_inorganic_type * orig = df_inorganic->at(i);
t_matglossInorganic mat; t_matglossInorganic mat;
mat.id = orig->Inorganic_ID; mat.id = orig->ID;
mat.name = orig->STONE_NAME; mat.name = orig->mat.STONE_NAME;
mat.ore_types = orig->METAL_ORE_matID; mat.ore_types = orig->METAL_ORE_matID;
mat.ore_chances = orig->METAL_ORE_prob; mat.ore_chances = orig->METAL_ORE_prob;
mat.strand_types = orig->THREAD_METAL_matID; mat.strand_types = orig->THREAD_METAL_matID;
mat.strand_chances = orig->THREAD_METAL_prob; mat.strand_chances = orig->THREAD_METAL_prob;
mat.value = orig->MATERIAL_VALUE; mat.value = orig->mat.MATERIAL_VALUE;
mat.wall_tile = orig->TILE; mat.wall_tile = orig->mat.TILE;
mat.boulder_tile = orig->ITEM_SYMBOL; mat.boulder_tile = orig->mat.ITEM_SYMBOL;
mat.bright = orig->BASIC_COLOR_bright; mat.bright = orig->mat.BASIC_COLOR_bright;
mat.fore = orig->BASIC_COLOR_foreground; mat.fore = orig->mat.BASIC_COLOR_foreground;
mat.is_gem = orig->mat_flags.is_set(MATERIAL_IS_GEM); mat.is_gem = orig->mat.mat_flags.is_set(MATERIAL_IS_GEM);
inorganic.push_back(mat); inorganic.push_back(mat);
} }
return true; return true;
} }
bool Materials::ReadOrganicMaterials (void) bool Materials::CopyOrganicMaterials (std::vector<t_matgloss> & organic)
{ {
if(df_organic) if(df_organic)
return ReadNamesOnly(d->owner, (uint32_t) df_organic, organic ); return ReadNamesOnly(d->owner, (uint32_t) df_organic, organic );
else return false; else return false;
} }
bool Materials::ReadWoodMaterials (void) bool Materials::CopyWoodMaterials (std::vector<t_matgloss> & tree)
{ {
if(df_trees) if(df_trees)
return ReadNamesOnly(d->owner, (uint32_t) df_trees, tree ); return ReadNamesOnly(d->owner, (uint32_t) df_trees, tree );
else return false; else return false;
} }
bool Materials::ReadPlantMaterials (void) bool Materials::CopyPlantMaterials (std::vector<t_matgloss> & plant)
{ {
if(df_plants) if(df_plants)
return ReadNamesOnly(d->owner, (uint32_t) df_plants, plant ); return ReadNamesOnly(d->owner, (uint32_t) df_plants, plant );
@ -353,10 +353,6 @@ bool Materials::ReadCreatureTypesEx (void)
bool Materials::ReadAllMaterials(void) bool Materials::ReadAllMaterials(void)
{ {
bool ok = true; bool ok = true;
ok &= this->ReadInorganicMaterials();
ok &= this->ReadOrganicMaterials();
ok &= this->ReadWoodMaterials();
ok &= this->ReadPlantMaterials();
ok &= this->ReadCreatureTypes(); ok &= this->ReadCreatureTypes();
ok &= this->ReadCreatureTypesEx(); ok &= this->ReadCreatureTypesEx();
ok &= this->ReadDescriptorColors(); ok &= this->ReadDescriptorColors();
@ -385,7 +381,7 @@ std::string Materials::getDescription(const t_material & mat)
if(mat.material<0) if(mat.material<0)
return "any inorganic"; return "any inorganic";
else else
return this->inorganic[mat.material].id; return this->df_inorganic->at(mat.material)->ID;
} }
if(mat.material<0) if(mat.material<0)
return "any"; return "any";
@ -404,8 +400,8 @@ std::string Materials::getDescription(const t_material & mat)
else else
if(mat.index<0) if(mat.index<0)
return "any inorganic"; return "any inorganic";
else if (mat.index < inorganic.size()) else if (mat.index < df_inorganic->size())
return this->inorganic[mat.index].id; return this->df_inorganic->at(mat.index)->ID;
else else
return "INDEX OUT OF BOUNDS!"; return "INDEX OUT OF BOUNDS!";
} }
@ -424,7 +420,7 @@ std::string Materials::getDescription(const t_material & mat)
} }
else else
{ {
return this->organic[mat.index].id; return this->df_organic->at(mat.material)->ID;
} }
return out; return out;
} }

@ -103,7 +103,8 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
DFHack::Materials *Materials = c->getMaterials(); DFHack::Materials *Materials = c->getMaterials();
DFHack::VersionInfo* mem = c->vinfo; DFHack::VersionInfo* mem = c->vinfo;
DFHack::Maps *Maps = c->getMaps(); DFHack::Maps *Maps = c->getMaps();
bool hasmats = Materials->ReadInorganicMaterials(); std::vector<t_matglossInorganic> inorganic;
bool hasmats = Materials->CopyInorganicMaterials(inorganic);
if(!Maps->Start()) if(!Maps->Start())
{ {
@ -199,9 +200,9 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
{ {
con << "Layer material: " << dec << base_rock; con << "Layer material: " << dec << base_rock;
if(hasmats) if(hasmats)
con << " / " << Materials->inorganic[base_rock].id con << " / " << inorganic[base_rock].id
<< " / " << " / "
<< Materials->inorganic[base_rock].name << inorganic[base_rock].name
<< endl; << endl;
else else
con << endl; con << endl;
@ -211,9 +212,9 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
{ {
con << "Vein material (final): " << dec << vein_rock; con << "Vein material (final): " << dec << vein_rock;
if(hasmats) if(hasmats)
con << " / " << Materials->inorganic[vein_rock].id con << " / " << inorganic[vein_rock].id
<< " / " << " / "
<< Materials->inorganic[vein_rock].name << inorganic[vein_rock].name
<< endl; << endl;
else else
con << endl; con << endl;

@ -88,8 +88,8 @@ struct compare_pair_second
// printMats() accepts a vector of pointers to t_matgloss so that it can // printMats() accepts a vector of pointers to t_matgloss so that it can
// deal t_matgloss and all subclasses. // deal t_matgloss and all subclasses.
void printMats(DFHack::Console & con, MatMap &mat, template <typename T>
std::vector<DFHack::t_matgloss*> &materials) void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials)
{ {
unsigned int total = 0; unsigned int total = 0;
MatSorter sorting_vector; MatSorter sorting_vector;
@ -108,8 +108,8 @@ void printMats(DFHack::Console & con, MatMap &mat,
<< materials.size() << endl; << materials.size() << endl;
continue; continue;
} }
DFHack::t_matgloss* mat = materials[it->first]; T* mat = materials[it->first];
con << std::setw(25) << mat->id << " : " con << std::setw(25) << mat->ID << " : "
<< std::setw(9) << it->second.count; << std::setw(9) << it->second.count;
if(it->second.lower_z != it->second.upper_z) if(it->second.lower_z != it->second.upper_z)
con <<" Z:" << std::setw(4) << it->second.lower_z << ".." << it->second.upper_z << std::endl; con <<" Z:" << std::setw(4) << it->second.lower_z << ".." << it->second.upper_z << std::endl;
@ -121,14 +121,6 @@ void printMats(DFHack::Console & con, MatMap &mat,
con << ">>> TOTAL = " << total << std::endl << std::endl; con << ">>> TOTAL = " << total << std::endl << std::endl;
} }
void printMats(DFHack::Console & con, MatMap &mat,
std::vector<DFHack::t_matgloss> &materials)
{
std::vector<DFHack::t_matgloss*> ptr_vec;
TO_PTR_VEC(materials, ptr_vec);
printMats(con, mat, ptr_vec);
}
void printVeins(DFHack::Console & con, MatMap &mat_map, void printVeins(DFHack::Console & con, MatMap &mat_map,
DFHack::Materials* mats) DFHack::Materials* mats)
{ {
@ -138,27 +130,24 @@ void printVeins(DFHack::Console & con, MatMap &mat_map,
for (MatMap::const_iterator it = mat_map.begin(); it != mat_map.end(); ++it) for (MatMap::const_iterator it = mat_map.begin(); it != mat_map.end(); ++it)
{ {
DFHack::t_matglossInorganic &gloss = mats->inorganic[it->first]; DFHack::df_inorganic_type *gloss = mats->df_inorganic->at(it->first);
if (gloss.isGem()) if (gloss->mat.isGem())
gems[it->first] = it->second; gems[it->first] = it->second;
else if (gloss.isOre()) else if (gloss->isOre())
ores[it->first] = it->second; ores[it->first] = it->second;
else else
rest[it->first] = it->second; rest[it->first] = it->second;
} }
std::vector<DFHack::t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << "Ores:" << std::endl; con << "Ores:" << std::endl;
printMats(con, ores, ptr_vec); printMats(con, ores, *mats->df_inorganic);
con << "Gems:" << std::endl; con << "Gems:" << std::endl;
printMats(con, gems, ptr_vec); printMats(con, gems, *mats->df_inorganic);
con << "Other vein stone:" << std::endl; con << "Other vein stone:" << std::endl;
printMats(con, rest, ptr_vec); printMats(con, rest, *mats->df_inorganic);
} }
DFhackCExport command_result prospector (Core * c, vector <string> & parameters); DFhackCExport command_result prospector (Core * c, vector <string> & parameters);
@ -217,13 +206,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
MapExtras::MapCache map(maps); MapExtras::MapCache map(maps);
DFHack::Materials *mats = c->getMaterials(); DFHack::Materials *mats = c->getMaterials();
if (!mats->ReadInorganicMaterials()) if (!mats->df_inorganic)
{ {
con << "Unable to read inorganic material definitons!" << std::endl; con << "Unable to read inorganic material definitons!" << std::endl;
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (showPlants && !mats->ReadOrganicMaterials()) if (showPlants && !mats->df_organic)
{ {
con << "Unable to read organic material definitons; plants won't be listed!" << std::endl; con << "Unable to read organic material definitons; plants won't be listed!" << std::endl;
showPlants = false; showPlants = false;
@ -423,20 +412,17 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
con << std::setw(25) << DFHack::TileMaterialString[it->first] << " : " << it->second.count << std::endl; con << std::setw(25) << DFHack::TileMaterialString[it->first] << " : " << it->second.count << std::endl;
} }
std::vector<t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << std::endl << "Layer materials:" << std::endl; con << std::endl << "Layer materials:" << std::endl;
printMats(con, layerMats, ptr_vec); printMats(con, layerMats, *mats->df_inorganic);
printVeins(con, veinMats, mats); printVeins(con, veinMats, mats);
if (showPlants) if (showPlants)
{ {
con << "Shrubs:" << std::endl; con << "Shrubs:" << std::endl;
printMats(con, plantMats, mats->organic); printMats(con, plantMats, *mats->df_organic);
con << "Wood in trees:" << std::endl; con << "Wood in trees:" << std::endl;
printMats(con, treeMats, mats->organic); printMats(con, treeMats, *mats->df_organic);
} }
if (hasAquifer) if (hasAquifer)

@ -103,8 +103,8 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
core.Suspend(); core.Suspend();
DFHack::Materials& materialsModule = *core.getMaterials(); DFHack::Materials& materialsModule = *core.getMaterials();
materialsModule.ReadOrganicMaterials(); std::vector<DFHack::t_matgloss> organics;
std::vector<DFHack::t_matgloss>& organics = materialsModule.organic; materialsModule.CopyOrganicMaterials(organics);
std::map<std::string, t_materialIndex> materialsReverser; std::map<std::string, t_materialIndex> materialsReverser;
for(std::size_t i = 0; i < organics.size(); ++i) for(std::size_t i = 0; i < organics.size(); ++i)