Attribute writing added

develop
Simon Jackson 2010-06-16 07:19:19 +08:00 committed by Petr Mrázek
parent 8fb05f24db
commit 77d2343742
2 changed files with 36 additions and 10 deletions

@ -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;

@ -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; i<soul.numSkills; i++)
{
uint32_t temp2 = skills[i];
p->writeByte(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;