From a6dc645f48c834c3222c334347ca834d2502516c Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 5 May 2010 14:08:18 +0200 Subject: [PATCH] Creatures colors are now decodable ! --- dfhack/include/modules/Creatures.h | 9 +++++++-- dfhack/modules/Creatures.cpp | 14 ++++++++++++++ dfhack/shm/mod-creature2010.h | 2 ++ examples/creaturedump.cpp | 29 +++++++++++++++++++---------- examples/materialtest.cpp | 2 +- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/dfhack/include/modules/Creatures.h b/dfhack/include/modules/Creatures.h index af0014b8b..85910afdf 100644 --- a/dfhack/include/modules/Creatures.h +++ b/dfhack/include/modules/Creatures.h @@ -314,7 +314,9 @@ namespace DFHack t_attrib empathy; t_attrib social_awareness; }; - + +#define MAX_COLORS 15 + struct t_creature { uint32_t origin; @@ -349,10 +351,13 @@ namespace DFHack t_attrib recuperation; t_attrib disease_resistance; int32_t squad_leader_id; - uint8_t sex; // really a caste + uint8_t sex; + uint16_t caste; uint32_t pregnancy_timer; //Countdown timer to giving birth bool has_default_soul; t_soul defaultSoul; + uint32_t nbcolors; + uint32_t color[MAX_COLORS]; }; class APIPrivate; diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 55e86f18b..004233d66 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -81,6 +81,7 @@ Creatures::Creatures(APIPrivate* _d) creatures.flags2_offset = minfo->getOffset ("creature_flags2"); creatures.name_offset = minfo->getOffset ("creature_name"); creatures.sex_offset = minfo->getOffset ("creature_sex"); + creatures.caste_offset = minfo->getOffset ("creature_caste"); creatures.id_offset = minfo->getOffset ("creature_id"); creatures.labors_offset = minfo->getOffset ("creature_labors"); creatures.happiness_offset = minfo->getOffset ("creature_happiness"); @@ -97,6 +98,9 @@ Creatures::Creatures(APIPrivate* _d) creatures.soul_mental_offset = minfo->getOffset("soul_mental"); creatures.soul_traits_offset = minfo->getOffset("soul_traits"); + // appearance + creatures.appearance_vector_offset = minfo->getOffset("creature_appearance_vector"); + // name offsets for the creature module creatures.name_firstname_offset = minfo->getOffset("name_firstname"); creatures.name_nickname_offset = minfo->getOffset("name_nickname"); @@ -179,6 +183,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) p->readDWord (temp + offs.race_offset, furball.race); furball.civ = p->readDWord (temp + offs.civ_offset); p->readByte (temp + offs.sex_offset, furball.sex); + p->readWord (temp + offs.caste_offset, furball.caste); p->readDWord (temp + offs.flags1_offset, furball.flags1.whole); p->readDWord (temp + offs.flags2_offset, furball.flags2.whole); @@ -258,6 +263,15 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) // traits as well p->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits); } + + DfVector app(p, temp + offs.appearance_vector_offset); + furball.nbcolors = app.size(); + if(furball.nbcolors>MAX_COLORS) + furball.nbcolors = MAX_COLORS; + for(uint32_t i = 0; i < furball.nbcolors; i++) + { + furball.color[i] = app[i]; + } //likes /* DfVector likes(d->p, temp + offs.creature_likes_offset); diff --git a/dfhack/shm/mod-creature2010.h b/dfhack/shm/mod-creature2010.h index ae9c60ab7..93006d827 100644 --- a/dfhack/shm/mod-creature2010.h +++ b/dfhack/shm/mod-creature2010.h @@ -44,6 +44,7 @@ typedef struct uint32_t flags2_offset; uint32_t name_offset; uint32_t sex_offset; + uint32_t caste_offset; uint32_t id_offset; uint32_t labors_offset; uint32_t happiness_offset; @@ -63,6 +64,7 @@ typedef struct uint32_t name_words_offset; uint32_t soul_mental_offset; uint32_t soul_traits_offset; + uint32_t appearance_vector_offset; } creature_offsets; typedef struct diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 33a653819..50e716137 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -204,6 +204,22 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) } */ cout << endl; + cout << "Appearance : "; + for(unsigned int i = 0; iraceEx[creature.race].castes[creature.caste].ColorModifier[i].part << " "; + uint32_t color = Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].colorlist[creature.color[i]]; + if(colorcolor.size()) + cout << Materials->color[color].name << "[" + << (unsigned int) (Materials->color[color].r*255) << ":" + << (unsigned int) (Materials->color[color].v*255) << ":" + << (unsigned int) (Materials->color[color].b*255) << "]"; + else + cout << Materials->alldesc[color].id; + cout << " - "; + + } + cout << endl; cout << "happiness: " << creature.happiness << ", strength: " << creature.strength.level << ", agility: " << creature.agility.level @@ -359,6 +375,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) string artifact_name = Tran->TranslateName(creature.artifact_name,false); cout << "artifact: " << artifact_name << endl; } + + cout << endl; } @@ -405,16 +423,7 @@ int main (int numargs, char ** args) } mem = DF.getMemoryInfo(); - if(!Materials->ReadInorganicMaterials()) - { - cerr << "Can't get the inorganics types." << endl; - return 1; - } - if(!Materials->ReadCreatureTypesEx()) - { - cerr << "Can't get the creature types." << endl; - return 1; - } + Materials->ReadAllMaterials(); if(!Tran->Start()) { diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 4dc1b1088..0ebddf300 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -74,7 +74,7 @@ int main (int numargs, const char ** args) cout << i << ": " << Materials->color[i].id << " - " << Materials->color[i].name << "[" << (unsigned int) (Materials->color[i].r*255) << ":" << (unsigned int) (Materials->color[i].v*255) << ":" - << (unsigned int) (Materials->color[i].b*255) << ":" + << (unsigned int) (Materials->color[i].b*255) << "]" << endl; } cout << endl << "----==== All descriptors ====----" << endl;