diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 1f74c6faf..86330ed4e 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -56,6 +56,7 @@ DFHackAPIImpl::DFHackAPIImpl(const string path_to_xml) { xml = path_to_xml; constructionsInited = false; + creaturesInited = false; buildingsInited = false; vegetationInited = false; pm = NULL; @@ -378,6 +379,34 @@ bool DFHackAPIImpl::ReadPlantMatgloss(vector & plants) return true; } +bool DFHackAPIImpl::ReadCreatureMatgloss(vector & creatures) +{ + int matgloss_address = offset_descriptor->getAddress("matgloss"); + int matgloss_offset = offset_descriptor->getHexValue("matgloss_skip"); + DfVector p_matgloss = dm->readVector(matgloss_address + matgloss_offset*4, 4); + + creatures.clear(); + + // TODO: use green? + t_matgloss mat; + mat.fore = 7; + mat.back = 0; + mat.bright = 0; + for (uint32_t i = 0; i< p_matgloss.getSize();i++) + { + uint32_t temp; + + // read the matgloss pointer from the vector into temp + p_matgloss.read((uint32_t)i,(uint8_t *)&temp); + + // read the string pointed at by + fill_char_buf(mat.id, dm->readSTLString(temp)); // reads a C string given an address + creatures.push_back(mat); + } + return true; +} + + //vector v_geology[eBiomeCount]; bool DFHackAPIImpl::ReadGeology( vector < vector >& assign ) { @@ -565,7 +594,7 @@ uint32_t DFHackAPIImpl::InitReadVegetation() { vegetationInited = true; int vegetation = offset_descriptor->getAddress("vegetation"); - treeoffset = offset_descriptor->getOffset("tree_desc_offset"); + tree_offset = offset_descriptor->getOffset("tree_desc_offset"); assert(vegetation && treeoffset); p_veg = new DfVector(dm->readVector(vegetation,4)); return p_veg->getSize(); @@ -579,10 +608,10 @@ bool DFHackAPIImpl::ReadVegetation(const uint32_t &index, t_tree_desc & shrubber // read pointer from vector at position p_veg->read(index,(uint8_t *)&temp); //read construction from memory - Mread(temp + treeoffset, sizeof(t_tree_desc), (uint8_t *) &shrubbery); + Mread(temp + tree_offset, sizeof(t_tree_desc), (uint8_t *) &shrubbery); // FIXME: this is completely wrong. type isn't just tree/shrub but also different kinds of trees. stuff that grows around ponds has its own type ID if(shrubbery.material.type == 3) shrubbery.material.type = 2; - return true; + return true; } @@ -592,6 +621,36 @@ void DFHackAPIImpl::FinishReadVegetation() } +uint32_t DFHackAPIImpl::InitReadCreatures() +{ + creaturesInited = true; + int creatures = offset_descriptor->getAddress("creatures"); + creature_pos_offset = offset_descriptor->getOffset("creature_position"); + creature_type_offset = offset_descriptor->getOffset("creature_type"); + assert(creatures && creatureposoffset && creaturetypeoffset); + p_cre = new DfVector(dm->readVector(creatures, 4)); + return p_cre->getSize(); +} + + +bool DFHackAPIImpl::ReadCreature(const uint32_t &index, t_creature & furball) +{ + assert(vegetationInited); + uint32_t temp; + // read pointer from vector at position + p_cre->read(index,(uint8_t *)&temp); + //read creature from memory + Mread(temp + creature_pos_offset, 3 * sizeof(uint16_t), (uint8_t *) &(furball.x)); // xyz really + Mread(temp + creature_type_offset, sizeof(uint32_t), (uint8_t *) &furball.type); + return true; +} + + +void DFHackAPIImpl::FinishReadCreatures() +{ + creaturesInited = false; +} + bool DFHackAPIImpl::Attach() { // detach all processes, destroy manager diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index e7462c8b5..93e9faad5 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -75,6 +75,7 @@ public: virtual bool ReadWoodMatgloss (vector & output) = 0; virtual bool ReadMetalMatgloss(vector & output) = 0; virtual bool ReadPlantMatgloss(vector & output) = 0; + virtual bool ReadCreatureMatgloss(vector & output) = 0; // FIXME: add creatures for all the creature products // read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client) @@ -154,6 +155,10 @@ public: virtual uint32_t InitReadVegetation() = 0; virtual bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery) = 0; virtual void FinishReadVegetation() = 0; + + virtual uint32_t InitReadCreatures() = 0; + virtual bool ReadCreature(const uint32_t &index, t_creature & furball) = 0; + virtual void FinishReadCreatures() = 0; }; #ifdef BUILD_DFHACK_LIB @@ -179,6 +184,9 @@ private: uint32_t designation_offset; uint32_t occupancy_offset; + uint32_t creature_pos_offset; + uint32_t creature_type_offset; + ProcessManager* pm; Process* p; DataModel* dm; @@ -189,7 +197,9 @@ private: bool constructionsInited; bool buildingsInited; bool vegetationInited; - uint32_t treeoffset; + bool creaturesInited; + uint32_t tree_offset; + DfVector *p_cre; DfVector *p_cons; DfVector *p_bld; DfVector *p_veg; @@ -210,7 +220,7 @@ public: bool ReadWoodMatgloss (vector & output); bool ReadMetalMatgloss(vector & output); bool ReadPlantMatgloss(vector & output); - // FIXME: add creatures for all the creature products + bool ReadCreatureMatgloss(vector & output); // read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client) // returns an array of 9 vectors of indices into stone matgloss @@ -289,6 +299,10 @@ public: uint32_t InitReadVegetation(); bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery); void FinishReadVegetation(); + + uint32_t InitReadCreatures(); + bool ReadCreature(const uint32_t &index, t_creature & furball); + void FinishReadCreatures(); }; #endif diff --git a/library/DFTileTypes.cpp b/library/DFTileTypes.cpp index b671fdd02..9e178852a 100644 --- a/library/DFTileTypes.cpp +++ b/library/DFTileTypes.cpp @@ -1068,6 +1068,6 @@ DFHACKAPI int getVegetationType(int in) case 34: //shrub return SHRUB_OK; } - // ???? - return -1; + // ???? + return -1; } diff --git a/library/DFTypes.h b/library/DFTypes.h index 7177a8220..9220cb06b 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -129,6 +129,14 @@ struct t_tree_desc uint16_t z; }; +struct t_creature +{ + uint16_t x; + uint16_t y; + uint16_t z; + uint32_t type; +}; + /* case 10: ret += "leather"; diff --git a/output/Memory.xml b/output/Memory.xml index db960c573..bc7447ea4 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -65,6 +65,7 @@
0x0156F8B0
0x015838a0
0x01587A24
+
0x01583224
0x015C4D70
@@ -84,6 +85,10 @@ 0x0664 0x1D64 + + 0x94 + 0x8C + 0x70 @@ -210,6 +215,8 @@
0x014da5e0
0x014ee978
0x014F4B4C
+
0x014edfcc
+ 0x70 @@ -276,6 +283,7 @@
0x015A33B8
0x015B7750
0x015BD924
+
0x015B6DA4
0x015FACEC