From 6631f97a6a23a2532bd067f334a12825afa87582 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Wed, 20 Jul 2011 06:18:50 -0700 Subject: [PATCH] More info on inorganic materials Get value, wall tile, boulder tile, smelting info and strand extraction info for inorganic materials. Prospector uses this to separete out vein materials into ores, gems and other. Offsets provided for both Linux and Windows, but only tested on Linux. --- Memory.xml | 32 +++++++ library/include/dfhack/modules/Materials.h | 42 ++++++++- library/modules/Materials.cpp | 101 +++++++++++++++++++-- plugins/prospector.cpp | 73 +++++++++++++-- 4 files changed, 230 insertions(+), 18 deletions(-) diff --git a/Memory.xml b/Memory.xml index 0d3129ec7..2904ce038 100644 --- a/Memory.xml +++ b/Memory.xml @@ -928,6 +928,15 @@
+ + + + + + + + +
@@ -2254,6 +2263,17 @@ + + + + + + + + + + +
@@ -3027,6 +3047,7 @@ WORLD: 0x93f77a0 +
@@ -3041,6 +3062,17 @@ + + + + + + + + + + +
diff --git a/library/include/dfhack/modules/Materials.h b/library/include/dfhack/modules/Materials.h index da44f025e..c4c97a870 100644 --- a/library/include/dfhack/modules/Materials.h +++ b/library/include/dfhack/modules/Materials.h @@ -32,20 +32,58 @@ distribution. #include "dfhack/Export.h" #include "dfhack/Module.h" #include "dfhack/Types.h" + +#include + namespace DFHack { class DFContextShared; /** * \ingroup grp_materials */ - struct t_matgloss + class DFHACK_EXPORT t_matgloss { + public: char id[128]; //the id in the raws uint8_t fore; // Annoyingly the offset for this differs between types uint8_t back; uint8_t bright; char name[128]; //this is the name displayed ingame + + int32_t value; // Material value + uint16_t wall_tile; // Tile when a natural wall + uint16_t boulder_tile; // Tile when a dug-out stone; + + public: + t_matgloss(); }; + + class DFHACK_EXPORT t_matglossInorganic : public t_matgloss + { + public: + // Types of metals the ore will produce when smelted. Each number + // is an index into the inorganic matglass vector. + std::vector* ore_types; + + // Percent chance that the ore will produce each type of metal + // when smelted. + std::vector* ore_chances; + + // Types of metals the ore will produce from strand extraction. + // Each number is an index into the inorganic matglass vector. + std::vector* strand_types; + + // Percent chance that the ore will produce each type of metal + // fram strand extraction. + std::vector* strand_chances; + + public: + t_matglossInorganic(); + + bool isOre(); + bool isGem(); + }; + /** * \ingroup grp_materials */ @@ -178,7 +216,7 @@ namespace DFHack ~Materials(); bool Finish(); - std::vector inorganic; + std::vector inorganic; std::vector organic; std::vector tree; std::vector plant; diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 2d6247b31..d5072a792 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -58,6 +58,20 @@ class Materials::Private uint32_t vector_organic_trees; uint32_t vector_races; uint32_t vector_other; + + class t_inorganic_extras + { + public: + uint32_t offset_ore_types; + uint32_t offset_ore_chances; + uint32_t offset_strand_types; + uint32_t offset_strand_chances; + uint32_t offset_value; + uint32_t offset_wall_tile; + uint32_t offset_boulder_tile; + }; + + t_inorganic_extras i_ex; }; Materials::Materials() @@ -73,7 +87,18 @@ Materials::Materials() d->vector_organic_trees = OG_Materials->getAddress ("organics_trees"); d->vector_races = OG_Materials->getAddress("creature_type_vector"); } + OffsetGroup *OG_Offsets = OG_Materials->getGroup("inorganic_extras"); + { + d->i_ex.offset_ore_types = OG_Offsets->getOffset("ore_types"); + d->i_ex.offset_ore_chances = OG_Offsets->getOffset("ore_chances"); + d->i_ex.offset_strand_types = OG_Offsets->getOffset("strand_types"); + d->i_ex.offset_strand_chances = OG_Offsets->getOffset("strand_chances"); + d->i_ex.offset_value = OG_Offsets->getOffset("value"); + d->i_ex.offset_wall_tile = OG_Offsets->getOffset("wall_tile"); + d->i_ex.offset_boulder_tile = OG_Offsets->getOffset("boulder_tile"); + } } + Materials::~Materials() { delete d; @@ -119,6 +144,48 @@ bool API::ReadInorganicMaterials (vector & inorganic) } */ +t_matgloss::t_matgloss() +{ + name[0] = 0; + fore = 0; + back = 0; + bright = 0; + + value = 0; + wall_tile = 0; + boulder_tile = 0; +} + +t_matglossInorganic::t_matglossInorganic() +{ + ore_types = NULL; + ore_chances = NULL; + strand_types = NULL; + strand_chances = NULL; +} + +bool t_matglossInorganic::isOre() +{ + if (ore_chances != NULL && !ore_chances->empty()) + { + if ( (*ore_chances)[0] > 0) + return true; + } + + if (strand_chances != NULL && !strand_chances->empty()) + { + if ( (*strand_chances)[0] > 0) + return true; + } + + return false; +} + +bool t_matglossInorganic::isGem() +{ + return (wall_tile == 15 && boulder_tile == 7); +} + // good for now inline bool ReadNamesOnly(Process* p, uint32_t address, vector & names) { @@ -144,14 +211,36 @@ bool Materials::ReadInorganicMaterials (void) inorganic.reserve (size); for (uint32_t i = 0; i < size;i++) { - t_matgloss mat; + t_matglossInorganic mat; p->readSTLString (p_matgloss[i], mat.id, 128); //p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128); - mat.name[0] = 0; - mat.fore = 0; - mat.back = 0; - mat.bright = 0; + + uint32_t ptr = p_matgloss[i] + d->i_ex.offset_ore_types; + if ( *( (uint32_t*) ptr) != 0) + mat.ore_types = (std::vector*) ptr; + + ptr = p_matgloss[i] + d->i_ex.offset_ore_chances; + if ( *( (uint32_t*) ptr) != 0) + mat.ore_chances = (std::vector*) ptr; + + ptr = p_matgloss[i] + d->i_ex.offset_strand_types; + if ( *( (uint32_t*) ptr) != 0) + mat.strand_types = (std::vector*) ptr; + + ptr = p_matgloss[i] + d->i_ex.offset_strand_chances; + if ( *( (uint32_t*) ptr) != 0) + mat.strand_chances = (std::vector*) ptr; + + ptr = p_matgloss[i] + d->i_ex.offset_value; + mat.value = *( (int32_t*) ptr); + + ptr = p_matgloss[i] + d->i_ex.offset_wall_tile; + mat.wall_tile = *( (uint8_t*) ptr); + + ptr = p_matgloss[i] + d->i_ex.offset_boulder_tile; + mat.boulder_tile = *( (uint8_t*) ptr); + inorganic.push_back(mat); } return true; @@ -484,4 +573,4 @@ std::string Materials::getType(const t_material & mat) { return "organic"; } -} \ No newline at end of file +} diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index da8877e26..9b42aa705 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -30,6 +30,11 @@ typedef std::vector FeatureListPointer; typedef std::map FeatureMap; typedef std::vector PlantList; +#define TO_PTR_VEC(obj_vec, ptr_vec) \ + ptr_vec.clear(); \ + for (size_t i = 0; i < obj_vec.size(); i++) \ + ptr_vec.push_back(&obj_vec[i]) + template