Magic number cleaning

develop
Simon Jackson 2010-06-16 00:55:12 +01:00
parent cc05fd4a70
commit 00cd96884e
2 changed files with 22 additions and 9 deletions

@ -280,6 +280,8 @@ namespace DFHack
// FIXME: define in Memory.xml instead? // FIXME: define in Memory.xml instead?
#define NUM_CREATURE_TRAITS 30 #define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102 #define NUM_CREATURE_LABORS 102
#define NUM_CREATURE_MENTAL_ATTRIBUTES 13
#define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6
struct t_soul struct t_soul
{ {

@ -195,7 +195,9 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
p->readDWord (temp + offs.flags2_offset, furball.flags2.whole); p->readDWord (temp + offs.flags2_offset, furball.flags2.whole);
// physical attributes // physical attributes
p->read(temp + offs.physical_offset, sizeof(t_attrib) * 6, (uint8_t *)&furball.strength); p->read(temp + offs.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&furball.strength);
// mood stuff // mood stuff
furball.mood = (int16_t) p->readWord (temp + offs.mood_offset); furball.mood = (int16_t) p->readWord (temp + offs.mood_offset);
@ -252,25 +254,34 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
*/ */
uint32_t soul = p->readDWord(temp + offs.default_soul_offset); uint32_t soul = p->readDWord(temp + offs.default_soul_offset);
furball.has_default_soul = false; furball.has_default_soul = false;
if(soul) if(soul)
{ {
furball.has_default_soul = true; furball.has_default_soul = true;
// get first soul's skills // get first soul's skills
DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset); DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size(); furball.defaultSoul.numSkills = skills.size();
for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++)
{ {
uint32_t temp2 = skills[i]; uint32_t temp2 = skills[i];
// a byte: this gives us 256 skills maximum. ??? // a byte: this gives us 256 skills maximum. ???
furball.defaultSoul.skills[i].id = p->readDWord (temp2); furball.defaultSoul.skills[i].id = p->readDWord (temp2);
furball.defaultSoul.skills[i].rating = p->readDWord (temp2 + 4); furball.defaultSoul.skills[i].rating =
furball.defaultSoul.skills[i].experience = p->readDWord (temp2 + 8); p->readDWord (temp2 + offsetof(t_skill, rating));
furball.defaultSoul.skills[i].experience =
p->readDWord (temp2 + offsetof(t_skill, experience));
} }
// mental attributes are part of the soul // mental attributes are part of the soul
p->read(soul + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability); p->read(soul + offs.soul_mental_offset,
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&furball.defaultSoul.analytical_ability);
// traits as well // traits as well
p->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits); p->read(soul + offs.soul_traits_offset,
sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &furball.defaultSoul.traits);
} }
DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset); DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset);
@ -402,8 +413,8 @@ bool Creatures::WriteSkills(const uint32_t index, const t_soul &soul)
for (uint32_t i=0; i<soul.numSkills; i++) for (uint32_t i=0; i<soul.numSkills; i++)
{ {
uint32_t temp2 = skills[i]; uint32_t temp2 = skills[i];
p->writeDWord(temp2 + 4, soul.skills[i].rating); p->writeDWord(temp2 + offsetof(t_skill, rating), soul.skills[i].rating);
p->writeDWord(temp2 + 8, soul.skills[i].experience); p->writeDWord(temp2 + offsetof(t_skill, experiance), soul.skills[i].experience);
} }
return true; return true;
@ -423,12 +434,12 @@ bool Creatures::WriteAttributes(const uint32_t index, const t_creature &creature
// physical attributes // physical attributes
p->write(temp + d->creatures.physical_offset, p->write(temp + d->creatures.physical_offset,
sizeof(t_attrib) * 6, sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&creature.strength); (uint8_t *)&creature.strength);
// mental attributes are part of the soul // mental attributes are part of the soul
p->write(souloff + d->creatures.soul_mental_offset, p->write(souloff + d->creatures.soul_mental_offset,
sizeof(t_attrib) * 13, sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&creature.defaultSoul.analytical_ability); (uint8_t *)&creature.defaultSoul.analytical_ability);
return true; return true;