diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 39debc14f..1e09bfd20 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -766,7 +766,7 @@ uint32_t API::InitReadCreatures() return false; } } - +/* //This code was mostly adapted fromh dwarftherapist by chmod string API::Private::getLastNameByAddress(const uint32_t &address, bool use_generic) { @@ -920,13 +920,12 @@ void API::Private::getSkillsByAddress(const uint32_t &address, vector & tempSkill.name = offset_descriptor->getSkill(tempSkill.id); tempSkill.experience = MreadWord(temp+8); tempSkill.rating = MreadByte(temp+4); - /* - add up all the experience per level - for (int j = 0; j < tempSkill.rating; ++j) - { - tempSkill.experience += 500 + (j * 100); - } - */ +// add up all the experience per level +// for (int j = 0; j < tempSkill.rating; ++j) +// { +// tempSkill.experience += 500 + (j * 100); +// } +// skills.push_back(tempSkill); } } @@ -954,7 +953,7 @@ void API::Private::getLaborsByAddress(const uint32_t &address, vector & tempLabor.value = laborArray[i]; labors.push_back(tempLabor); } -} +}*/ bool API::ReadCreature(const uint32_t &index, t_creature & furball) { assert(d->creaturesInited); @@ -966,27 +965,32 @@ bool API::ReadCreature(const uint32_t &index, t_creature & furball) MreadDWord(temp + d->creature_type_offset, furball.type); MreadDWord(temp + d->creature_flags1_offset, furball.flags1.whole); MreadDWord(temp + d->creature_flags2_offset, furball.flags2.whole); - // names - furball.first_name = d->dm->readSTLString(temp+d->creature_first_name_offset); - furball.nick_name = d->dm->readSTLString(temp+d->creature_nick_name_offset); - furball.trans_name = d->getLastNameByAddress(temp+d->creature_last_name_offset); - furball.generic_name = d->getLastNameByAddress(temp+d->creature_last_name_offset,true); - furball.generic_squad_name = d->getSquadNameByAddress(temp+d->creature_squad_name_offset, true); - furball.trans_squad_name = d->getSquadNameByAddress(temp+d->creature_squad_name_offset, false); - furball.custom_profession = d->dm->readSTLString(temp+d->creature_custom_profession_offset); + // normal names + fill_char_buf(furball.first_name, d->dm->readSTLString(temp+d->creature_first_name_offset)); + fill_char_buf(furball.nick_name, d->dm->readSTLString(temp+d->creature_nick_name_offset)); + // crazy composited names + Mread(temp + d->creature_last_name_offset,sizeof(t_lastname), (uint8_t *) &furball.last_name ); + Mread(temp + d->creature_squad_name_offset,sizeof(t_squadname), (uint8_t *) &furball.squad_name ); + // custom profession + fill_char_buf(furball.custom_profession, d->dm->readSTLString(temp+d->creature_first_name_offset)); + + /* + furball.profession = d->getProfessionByAddress(temp+d->creature_profession_offset); furball.current_job = d->getCurrentJobByAddress(temp+d->creature_current_job_offset); + d->getSkillsByAddress(temp+d->creature_skills_offset,furball.skills); d->getTraitsByAddress(temp+d->creature_traits_offset,furball.traits); d->getLaborsByAddress(temp+d->creature_labors_offset,furball.labors); - + */ + MreadDWord(temp + d->creature_happiness_offset, furball.happiness); MreadDWord(temp + d->creature_id_offset, furball.id); MreadDWord(temp + d->creature_agility_offset, furball.agility); MreadDWord(temp + d->creature_strength_offset, furball.strength); MreadDWord(temp + d->creature_toughness_offset, furball.toughness); MreadDWord(temp + d->creature_money_offset, furball.money); - furball.squad_leader_id = int32_t(MreadDWord(temp + d->creature_squad_leader_id_offset)); + furball.squad_leader_id = (int32_t) MreadDWord(temp + d->creature_squad_leader_id_offset); MreadByte(temp + d->creature_sex_offset, furball.sex); return true; } diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index af48bba4f..59afc4344 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -180,7 +180,7 @@ public: bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z); - + /* // FIXME: add a real creature class, move these string getLastName(const uint32_t &index, bool); string getSquadName(const uint32_t &index, bool); @@ -189,7 +189,7 @@ public: vector getSkills(const uint32_t &index); vector getTraits(const uint32_t &index); vector getLabors(const uint32_t &index); - + */ void InitReadNameTables(); void FinishReadNameTables(); }; diff --git a/library/DFMemInfo.cpp b/library/DFMemInfo.cpp index 3338a3460..4b63c4c48 100644 --- a/library/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -442,40 +442,52 @@ string memory_info::getSkill (uint32_t key) return string("Skill is not Defined"); } -string memory_info::getTrait (uint32_t key, uint32_t absVal) -{ - if(traits.size() > key){ - int diff = abs(absVal-50); - if(diff < 10){ - return string(""); - } - if (absVal >= 91) - return traits[key][5]; - else if (absVal >= 76) - return traits[key][4]; - else if (absVal >= 61) - return traits[key][3]; - else if (absVal >= 25) - return traits[key][2]; - else if (absVal >= 10) - return traits[key][1]; - else - return traits[key][0]; - } - return string("Trait is not Defined"); +// FIXME: ugly hack that needs to die +int absolute (int number) +{ + if (number < 0) + return -number; + return number; +} + +string memory_info::getTrait (uint32_t traitIdx, uint32_t traitValue) +{ + if(traits.size() > traitIdx) + { + int diff = absolute(traitValue-50); + if(diff < 10) + { + return string(""); + } + if (traitValue >= 91) + return traits[traitIdx][5]; + else if (traitValue >= 76) + return traits[traitIdx][4]; + else if (traitValue >= 61) + return traits[traitIdx][3]; + else if (traitValue >= 25) + return traits[traitIdx][2]; + else if (traitValue >= 10) + return traits[traitIdx][1]; + else + return traits[traitIdx][0]; + } + return string("Trait is not Defined"); } string memory_info::getTraitName(uint32_t key) { - if(traits.size() > key){ - return traits[key][traits[key].size()-1]; - } - return string("Trait is not Defined"); + if(traits.size() > key) + { + return traits[key][traits[key].size()-1]; + } + return string("Trait is not Defined"); } string memory_info::getLabor (uint32_t key) { - if(labors.count(key)){ + if(labors.count(key)) + { return labors[key]; } return string(""); diff --git a/library/DFTypes.h b/library/DFTypes.h index 300595787..701d2b074 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -396,7 +396,6 @@ struct t_labor value=b.value; return *this; } - }; struct t_skill { @@ -448,6 +447,16 @@ struct t_trait } }; +struct t_lastname +{ + int names[7]; +}; + +struct t_squadname +{ + int names[6]; +}; + struct t_creature { uint16_t x; @@ -456,16 +465,15 @@ struct t_creature uint32_t type; t_creaturflags1 flags1; t_creaturflags2 flags2; - string first_name; - string nick_name; + char first_name [128]; + char nick_name [128]; + t_lastname last_name; + t_squadname squad_name; + char custom_profession[128]; + /* //string last_name; - string trans_name; - string generic_name; - string generic_squad_name; - string trans_squad_name; - string profession; - string custom_profession; string current_job; + */ uint32_t happiness; uint32_t id; uint32_t agility; @@ -474,6 +482,8 @@ struct t_creature uint32_t money; int32_t squad_leader_id; uint8_t sex; + uint8_t profession; + /* vector skills; vector traits; vector labors; @@ -542,7 +552,7 @@ struct t_creature skills = b.skills; traits = b.traits; return *this; - } + }*/ }; // TODO: research this further? consult DF hacker wizards? diff --git a/tools/creaturedump.cpp b/tools/creaturedump.cpp index 82da82d26..515fd9ea9 100644 --- a/tools/creaturedump.cpp +++ b/tools/creaturedump.cpp @@ -46,16 +46,17 @@ int main (void) DF.ReadCreature(i, temp); cout << "creature type " << creaturestypes[temp.type].id << ", position:" << temp.x << " " << temp.y << " "<< temp.z << endl; bool addendl = false; - if(!temp.first_name.empty()) + if(temp.first_name[0]) { cout << "first name: " << temp.first_name; addendl = true; } - if(!temp.nick_name.empty()) + if(temp.nick_name[0]) { cout << ", nick name: " << temp.nick_name; addendl = true; } + /* if(!temp.trans_name.empty()){ cout << ", trans name: " << temp.trans_name; addendl =true; @@ -64,11 +65,13 @@ int main (void) cout << ", generic name: " << temp.generic_name; addendl=true; } + */ if(addendl) { cout << endl; addendl = false; } + /* if(!temp.profession.empty()){ cout << ", profession: " << temp.profession; addendl = false; @@ -81,6 +84,7 @@ int main (void) cout << ", current job: " << temp.current_job; addendl = false; } + */ if(addendl) { cout << endl; @@ -99,7 +103,7 @@ int main (void) cout <<", Male"; } cout << endl; - +/* //skills for(unsigned int i = 0; i < temp.skills.size();i++){ if(i > 0){ @@ -107,7 +111,7 @@ int main (void) } cout << temp.skills[i].name << ": " << temp.skills[i].rating; } - +*/ /* * FLAGS 1 */