From ab3a842fdb90f1840e6201127da0b6b6e6afe69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 14 Apr 2010 22:12:02 +0200 Subject: [PATCH] Support for creature castes --- dfhack/include/modules/Materials.h | 15 +++++++++++++++ dfhack/modules/Materials.cpp | 31 ++++++++++++++++++++++++++++++ examples/creaturedump.cpp | 4 ++-- examples/materialtest.cpp | 19 ++++++++++++++---- output/Memory.xml | 10 ++++++---- 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/dfhack/include/modules/Materials.h b/dfhack/include/modules/Materials.h index 83a4f203b..0161d02a1 100644 --- a/dfhack/include/modules/Materials.h +++ b/dfhack/include/modules/Materials.h @@ -29,6 +29,20 @@ namespace DFHack char extract_name[128]; }; + struct t_creaturecaste + { + char rawname[128]; + char singular[128]; + char plural[128]; + char adjective[128]; + }; + + struct t_creaturetype + { + char rawname[128]; + vector castes; + }; + class DFHACK_EXPORT Materials { public: @@ -45,6 +59,7 @@ namespace DFHack // TODO: maybe move to creatures? bool ReadCreatureTypes (std::vector & output); + bool ReadCreatureTypesEx (vector & creatures); private: APIPrivate* d; }; diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 265f5074c..4e2059705 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -212,3 +212,34 @@ bool Materials::ReadCreatureTypes (vector & creatures) return ReadNamesOnly(d->p, d->offset_descriptor->getAddress ("creature_type_vector"), creatures ); return true; } + +bool Materials::ReadCreatureTypesEx (vector & creatures) +{ + DfVector p_races (g_pProcess, d->offset_descriptor->getAddress ("creature_type_vector"), 4); + uint32_t castes_vector_offset = d->offset_descriptor->getOffset ("creature_type_caste_vector"); + uint32_t sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string"); + uint32_t size = p_races.getSize(); + uint32_t sizecas = 0; + creatures.clear(); + creatures.reserve (size); + for (uint32_t i = 0; i < size;i++) + { + t_creaturetype mat; + g_pProcess->readSTLString (*(uint32_t *) p_races[i], mat.rawname, sizeof(mat.rawname)); + DfVector p_castes(g_pProcess,(*(uint32_t *) p_races[i]) + castes_vector_offset, 4); + sizecas = p_castes.getSize(); + for (uint32_t j = 0; j < sizecas;j++) + { + t_creaturecaste caste; + uint32_t caste_start = *(uint32_t *)p_castes[j]; + g_pProcess->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname)); + g_pProcess->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular)); + g_pProcess->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural)); + g_pProcess->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective)); + mat.castes.push_back(caste); + } + creatures.push_back(mat); + } + return true; +} + diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 5f216e92b..5bd8de0a8 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -407,7 +407,7 @@ int main (void) { DFHack::t_creature temp; Creatures->ReadCreature(i,temp); - if(string(creaturestypes[temp.race].id) == "DWARF") + if(string(creaturestypes[temp.race].id) == "HORSE") { cout << "index " << i << " "; @@ -415,7 +415,7 @@ int main (void) addrs.push_back(temp.origin); } } - //interleave_hex(DF,addrs,200); + interleave_hex(DF,addrs,200); /* uint32_t currentIdx; DFHack::t_creature currentCreature; diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 9bc466c2b..1f397df41 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -69,11 +69,22 @@ int main (int numargs, const char ** args) cout << i << ": " << matgloss[i].id << endl; } cout << endl << "----==== Creature types ====----" << endl; - vector creature; - Materials->ReadCreatureTypes (matgloss); - for(uint32_t i = 0; i < matgloss.size();i++) + vector creature; + Materials->ReadCreatureTypesEx (creature); + for(uint32_t i = 0; i < creature.size();i++) { - cout << i << ": " << matgloss[i].id << endl ; + cout << i << ": " << creature[i].rawname << endl; + vector & castes = creature[i].castes; + for(uint32_t j = 0; j < castes.size();j++) + { + cout << " [" + << castes[j].rawname << ":" + << castes[j].singular << ":" + << castes[j].plural << ":" + << castes[j].adjective << "] "; + cout << endl; + } + cout << endl; } #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; diff --git a/output/Memory.xml b/output/Memory.xml index 6189e55c6..ed726a1d9 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1191,9 +1191,10 @@ map_data_1b60_offset 0x1B9c just wood, WORLD + 0x54BDC
0x16afd64
- creature types actually used for creatures, WORLD + 0x54CD0 + creature types actually used for creatures, + WORLD + 0x54CD0
0x016AFE58
- + 0x138 + + 0x28C + 0x290 0x464