From 4f0695a6d560eae69e270e9a46fa09f898a096cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 3 Nov 2011 04:30:59 +0100 Subject: [PATCH] Messing with materials. --- library/depends/md5/md5wrapper.h | 1 + library/include/dfhack/modules/Materials.h | 37 ++++++++++++------ library/modules/Materials.cpp | 38 +++++++++---------- plugins/probe.cpp | 11 +++--- plugins/prospector.cpp | 44 ++++++++-------------- plugins/seedwatch.cpp | 4 +- 6 files changed, 66 insertions(+), 69 deletions(-) diff --git a/library/depends/md5/md5wrapper.h b/library/depends/md5/md5wrapper.h index 537961b8d..38197faf1 100644 --- a/library/depends/md5/md5wrapper.h +++ b/library/depends/md5/md5wrapper.h @@ -22,6 +22,7 @@ //basic includes #include +#include //forwards class MD5; diff --git a/library/include/dfhack/modules/Materials.h b/library/include/dfhack/modules/Materials.h index 9adf7613f..efa0770bf 100644 --- a/library/include/dfhack/modules/Materials.h +++ b/library/include/dfhack/modules/Materials.h @@ -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 inorg_flags; std::vector empty1; std::vector METAL_ORE_matID; // Vector of indexes of metals produced when ore is smelted @@ -314,8 +322,16 @@ namespace DFHack std::vector ENVIRONMENT_inclusion_type; std::vector 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; - std::vector inorganic; + std::vector* df_inorganic; std::vector* df_organic; - std::vector organic; std::vector* df_trees; - std::vector tree; std::vector* df_plants; - std::vector plant; std::vector race; std::vector raceEx; @@ -706,10 +718,11 @@ namespace DFHack std::vector other; std::vector alldesc; - bool ReadInorganicMaterials (void); - bool ReadOrganicMaterials (void); - bool ReadWoodMaterials (void); - bool ReadPlantMaterials (void); + bool CopyInorganicMaterials (std::vector & inorganic); + bool CopyOrganicMaterials (std::vector & organic); + bool CopyWoodMaterials (std::vector & tree); + bool CopyPlantMaterials (std::vector & plant); + bool ReadCreatureTypes (void); bool ReadCreatureTypesEx (void); bool ReadDescriptorColors(void); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 07432421a..0c4b6f46b 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -126,7 +126,7 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector & nam return true; } -bool Materials::ReadInorganicMaterials (void) +bool Materials::CopyInorganicMaterials (std::vector & 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 & 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 & 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 & 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; } diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 6006e77ef..2289f1d00 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -103,7 +103,8 @@ DFhackCExport command_result df_probe (Core * c, vector & parameters) DFHack::Materials *Materials = c->getMaterials(); DFHack::VersionInfo* mem = c->vinfo; DFHack::Maps *Maps = c->getMaps(); - bool hasmats = Materials->ReadInorganicMaterials(); + std::vector inorganic; + bool hasmats = Materials->CopyInorganicMaterials(inorganic); if(!Maps->Start()) { @@ -199,9 +200,9 @@ DFhackCExport command_result df_probe (Core * c, vector & 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 & 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; diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 078db73cf..ba20dad2d 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -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 &materials) +template +void printMats(DFHack::Console & con, MatMap &mat, std::vector &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 &materials) -{ - std::vector 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 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 & parameters); @@ -217,13 +206,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & 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 & par con << std::setw(25) << DFHack::TileMaterialString[it->first] << " : " << it->second.count << std::endl; } - std::vector 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) diff --git a/plugins/seedwatch.cpp b/plugins/seedwatch.cpp index 9f8afae03..418398e3d 100755 --- a/plugins/seedwatch.cpp +++ b/plugins/seedwatch.cpp @@ -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& organics = materialsModule.organic; + std::vector organics; + materialsModule.CopyOrganicMaterials(organics); std::map materialsReverser; for(std::size_t i = 0; i < organics.size(); ++i)