From cc05fd4a70daebdc99afcc1931abb883f27a8962 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Wed, 16 Jun 2010 00:19:19 +0100 Subject: [PATCH] Attribute writing added --- library/include/dfhack/modules/Creatures.h | 7 ++-- library/modules/Creatures.cpp | 39 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/library/include/dfhack/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h index 07d457d1b..9d58ec12d 100644 --- a/library/include/dfhack/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -256,9 +256,9 @@ namespace DFHack struct t_skill { - uint16_t id; + uint32_t id; uint32_t experience; - uint16_t rating; + uint32_t rating; }; struct t_job { @@ -381,7 +381,8 @@ namespace DFHack bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]); bool WriteHappiness(const uint32_t index, const uint32_t happinessValue); bool WriteFlags(const uint32_t index, const uint32_t flags1, const uint32_t flags2); - bool WriteSkills(const uint32_t index, t_soul &soul); + bool WriteSkills(const uint32_t index, const t_soul &soul); + bool WriteAttributes(const uint32_t index, const t_creature &creature); private: struct Private; diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index 467ddcd15..c47201ffc 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -261,10 +261,10 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) { uint32_t temp2 = skills[i]; - // a byte: this gives us 256 skills maximum. - furball.defaultSoul.skills[i].id = p->readByte (temp2); - furball.defaultSoul.skills[i].rating = p->readByte (temp2 + 4); - furball.defaultSoul.skills[i].experience = p->readWord (temp2 + 8); + // a byte: this gives us 256 skills maximum. ??? + furball.defaultSoul.skills[i].id = p->readDWord (temp2); + furball.defaultSoul.skills[i].rating = p->readDWord (temp2 + 4); + furball.defaultSoul.skills[i].experience = p->readDWord (temp2 + 8); } // mental attributes are part of the soul p->read(soul + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability); @@ -385,7 +385,7 @@ bool Creatures::WriteFlags(const uint32_t index, return true; } -bool Creatures::WriteSkills(const uint32_t index, t_soul &soul) +bool Creatures::WriteSkills(const uint32_t index, const t_soul &soul) { if(!d->Started) return false; @@ -402,13 +402,38 @@ bool Creatures::WriteSkills(const uint32_t index, t_soul &soul) for (uint32_t i=0; iwriteByte(temp2 + 4, soul.skills[i].rating); - p->writeWord(temp2 + 8, soul.skills[i].experience); + p->writeDWord(temp2 + 4, soul.skills[i].rating); + p->writeDWord(temp2 + 8, soul.skills[i].experience); } return true; } +bool Creatures::WriteAttributes(const uint32_t index, const t_creature &creature) +{ + if(!d->Started) + return false; + + uint32_t temp = d->p_cre->at (index); + Process * p = d->owner; + uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset); + + if(!souloff) + return false; + + // physical attributes + p->write(temp + d->creatures.physical_offset, + sizeof(t_attrib) * 6, + (uint8_t *)&creature.strength); + + // mental attributes are part of the soul + p->write(souloff + d->creatures.soul_mental_offset, + sizeof(t_attrib) * 13, + (uint8_t *)&creature.defaultSoul.analytical_ability); + + return true; +} + uint32_t Creatures::GetDwarfRaceIndex() { if(!d->Inited) return 0;