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
#include <string>
#include <stdint.h>
//forwards
class MD5;

@ -292,12 +292,20 @@ namespace DFHack
int32_t SOAP_LEVEL;
std::string PREFIX;
// etc...
bool isGem()
{
return mat_flags.is_set(MATERIAL_IS_GEM);
};
bool isStone()
{
mat_flags.is_set(MATERIAL_IS_STONE);
};
};
/// Research by Quietust
struct df_inorganic_base
struct df_inorganic_type
{
std::string Inorganic_ID;
std::string ID;
BitArray<inorganic_flags> inorg_flags;
std::vector <uint32_t> empty1;
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 <int8_t> ENVIRONMENT_prob;
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.
* \ingroup grp_materials
@ -691,14 +707,10 @@ namespace DFHack
GRIME
};
std::vector<df_inorganic_material*>* df_inorganic;
std::vector<t_matglossInorganic> inorganic;
std::vector<df_inorganic_type*>* df_inorganic;
std::vector<df_plant_type*>* df_organic;
std::vector<t_matgloss> organic;
std::vector<df_plant_type*>* df_trees;
std::vector<t_matgloss> tree;
std::vector<df_plant_type*>* df_plants;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
@ -706,10 +718,11 @@ namespace DFHack
std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic);
bool CopyOrganicMaterials (std::vector<t_matgloss> & organic);
bool CopyWoodMaterials (std::vector<t_matgloss> & tree);
bool CopyPlantMaterials (std::vector<t_matgloss> & plant);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);

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

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

@ -88,8 +88,8 @@ struct compare_pair_second
// printMats() accepts a vector of pointers to t_matgloss so that it can
// deal t_matgloss and all subclasses.
void printMats(DFHack::Console & con, MatMap &mat,
std::vector<DFHack::t_matgloss*> &materials)
template <typename T>
void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials)
{
unsigned int total = 0;
MatSorter sorting_vector;
@ -108,8 +108,8 @@ void printMats(DFHack::Console & con, MatMap &mat,
<< materials.size() << endl;
continue;
}
DFHack::t_matgloss* mat = materials[it->first];
con << std::setw(25) << mat->id << " : "
T* mat = materials[it->first];
con << std::setw(25) << mat->ID << " : "
<< std::setw(9) << it->second.count;
if(it->second.lower_z != it->second.upper_z)
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;
}
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,
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)
{
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;
else if (gloss.isOre())
else if (gloss->isOre())
ores[it->first] = it->second;
else
rest[it->first] = it->second;
}
std::vector<DFHack::t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << "Ores:" << std::endl;
printMats(con, ores, ptr_vec);
printMats(con, ores, *mats->df_inorganic);
con << "Gems:" << std::endl;
printMats(con, gems, ptr_vec);
printMats(con, gems, *mats->df_inorganic);
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);
@ -217,13 +206,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
MapExtras::MapCache map(maps);
DFHack::Materials *mats = c->getMaterials();
if (!mats->ReadInorganicMaterials())
if (!mats->df_inorganic)
{
con << "Unable to read inorganic material definitons!" << std::endl;
c->Resume();
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;
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;
}
std::vector<t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << std::endl << "Layer materials:" << std::endl;
printMats(con, layerMats, ptr_vec);
printMats(con, layerMats, *mats->df_inorganic);
printVeins(con, veinMats, mats);
if (showPlants)
{
con << "Shrubs:" << std::endl;
printMats(con, plantMats, mats->organic);
printMats(con, plantMats, *mats->df_organic);
con << "Wood in trees:" << std::endl;
printMats(con, treeMats, mats->organic);
printMats(con, treeMats, *mats->df_organic);
}
if (hasAquifer)

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