More Creatures rework, this time with more memset

develop
Petr Mrázek 2010-09-03 03:01:37 +02:00
parent dc6aa19083
commit 5a5745590a
4 changed files with 185 additions and 165 deletions

@ -1737,13 +1737,15 @@
<Offset name="happiness" value="0x5AC" />
</Group>
</Group>
<!--
The vector is bad.
<Group name="soul" valid="verify">
<Offset name="name" value="0x0" />
<Offset name="mental" value="0x88" />
<Offset name="skills_vector" value="0x1C4" /> CHMOD
<Offset name="traits" value="0x1DC" />
</Group>
-->
<!--
<Group name="job">
<Offset name="id" value="0x0" /> Incrementaly assigned
@ -1770,6 +1772,8 @@
<Offset name="extract_vector" value="0x18f4" />
<Offset name="tile" value="0x20" />
<Offset name="tile_color" value="0x36" />
<!--
!!!! BOGUS !!!!
<Group name="caste">
<Offset name="bodypart_vector" value="0x51C" />
<Offset name="attributes" value="0x654" />
@ -1787,6 +1791,7 @@
<Offset name="singular_vector" value="0x78" />
<Offset name="plural_vector" value="0x90" />
</Group>
-->
</Group>
<Group name="descriptors">
<!--<Address name="vectors_start" value="" />--><!-- search: vector of object with first object having string "STAR" as first member -->

@ -124,16 +124,16 @@ Creatures::Creatures(DFContextShared* _d)
creatures.labors_offset = OG_creature_ex->getOffset ("labors");
creatures.happiness_offset = OG_creature_ex->getOffset ("happiness");
d->Ft_advanced = true;
try
{
creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector");
creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul");
creatures.soul_mental_offset = OG_soul->getOffset("mental");
creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector");
creatures.soul_traits_offset = OG_soul->getOffset("traits");
d->Ft_soul = true;
}
catch(Error::All&){};
}
catch(Error::All&){};
try
{
creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector");
creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul");
creatures.soul_mental_offset = OG_soul->getOffset("mental");
creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector");
creatures.soul_traits_offset = OG_soul->getOffset("traits");
d->Ft_soul = true;
}
catch(Error::All&){};
}
@ -169,6 +169,7 @@ bool Creatures::Finish()
bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
{
if(!d->Started) return false;
memset(&furball, 0, sizeof(t_creature));
// SHM fast path
Process * p = d->owner;
/*
@ -190,129 +191,120 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
Creatures2010::creature_offsets &offs = d->creatures;
//read creature from memory
// name
d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff
p->readDWord (temp + offs.happiness_offset, furball.happiness);
p->readDWord (temp + offs.id_offset, furball.id);
p->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
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);
// physical attributes
p->read(temp + offs.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&furball.strength);
// mood stuff
furball.mood = (int16_t) p->readWord (temp + offs.mood_offset);
furball.mood_skill = p->readWord (temp + offs.mood_skill_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset);
// custom profession
p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession));
//fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset));
// labors
p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
// profession
furball.profession = p->readByte (temp + offs.profession_offset);
furball.current_job.occupationPtr = p->readDWord (temp + offs.current_job_offset);
if(furball.current_job.occupationPtr)
if(d->Ft_basic)
{
furball.current_job.active = true;
furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") );
furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") );
// name
d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff
p->readDWord (temp + offs.id_offset, furball.id);
p->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
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);
// custom profession
p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession));
// profession
furball.profession = p->readByte (temp + offs.profession_offset);
}
else
if(d->Ft_advanced)
{
furball.current_job.active = false;;
}
furball.birth_year = p->readDWord (temp + offs.birth_year_offset );
furball.birth_time = p->readDWord (temp + offs.birth_time_offset );
// current job HACK: the job object isn't cleanly represented here
/*
uint32_t jobIdAddr = p->readDWord (temp + offs.creature_current_job_offset);
// happiness
p->readDWord (temp + offs.happiness_offset, furball.happiness);
// physical attributes
p->read(temp + offs.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&furball.strength);
// mood stuff
furball.mood = (int16_t) p->readWord (temp + offs.mood_offset);
furball.mood_skill = p->readWord (temp + offs.mood_skill_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset);
// labors
p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
furball.birth_year = p->readDWord (temp + offs.birth_year_offset );
furball.birth_time = p->readDWord (temp + offs.birth_time_offset );
/*
* p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
*/
// appearance
DfVector <uint32_t> 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];
}
if (jobIdAddr)
{
furball.current_job.active = true;
furball.current_job.jobId = p->readByte (jobIdAddr + offs.creature_current_job_id_offset);
//likes
/*
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
uint32_t temp2 = *(uint32_t *) likes[i];
p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}*/
}
else
if(d->Ft_soul)
{
furball.current_job.active = false;
}
*/
/*
p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
*/
/*
// enum soul pointer vector
DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset);
*/
uint32_t soul = p->readDWord(temp + offs.default_soul_offset);
furball.has_default_soul = false;
if(soul)
{
furball.has_default_soul = true;
// get first soul's skills
DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size();
/*
// enum soul pointer vector
DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset);
*/
uint32_t soul = p->readDWord(temp + offs.default_soul_offset);
furball.has_default_soul = false;
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 + offsetof(t_skill, rating));
furball.defaultSoul.skills[i].experience =
p->readWord (temp2 + offsetof(t_skill, experience));
}
if(soul)
{
furball.has_default_soul = true;
// get first soul's skills
DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size();
// mental attributes are part of the soul
p->read(soul + offs.soul_mental_offset,
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&furball.defaultSoul.analytical_ability);
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 + offsetof(t_skill, rating));
furball.defaultSoul.skills[i].experience =
p->readWord (temp2 + offsetof(t_skill, experience));
// traits as well
p->read(soul + offs.soul_traits_offset,
sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &furball.defaultSoul.traits);
}
// mental attributes are part of the soul
p->read(soul + offs.soul_mental_offset,
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&furball.defaultSoul.analytical_ability);
// traits as well
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);
furball.nbcolors = app.size();
if(furball.nbcolors>MAX_COLORS)
furball.nbcolors = MAX_COLORS;
for(uint32_t i = 0; i < furball.nbcolors; i++)
if(d->Ft_jobs)
{
furball.color[i] = app[i];
furball.current_job.occupationPtr = p->readDWord (temp + offs.current_job_offset);
if(furball.current_job.occupationPtr)
{
furball.current_job.active = true;
furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") );
furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") );
}
else
{
furball.current_job.active = false;;
}
}
//likes
/*
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
uint32_t temp2 = *(uint32_t *) likes[i];
p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}*/
return true;
}

@ -29,6 +29,7 @@ distribution.
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include <dfhack/DFError.h>
using namespace DFHack;
@ -335,20 +336,38 @@ bool Materials::ReadCreatureTypesEx (void)
uint32_t extract_vector_offset = OG_Creature->getOffset ("extract_vector");
uint32_t tile_offset = OG_Creature->getOffset ("tile");
uint32_t tile_color_offset = OG_Creature->getOffset ("tile_color");
bool have_advanced = false;
uint32_t caste_colormod_offset;
uint32_t caste_attributes_offset;
uint32_t caste_bodypart_offset;
uint32_t bodypart_id_offset;
uint32_t bodypart_category_offset;
uint32_t bodypart_layers_offset;
uint32_t bodypart_singular_offset;
uint32_t bodypart_plural_offset;
uint32_t color_modifier_part_offset;
uint32_t color_modifier_startdate_offset;
uint32_t color_modifier_enddate_offset;
try
{
OffsetGroup * OG_Caste = OG_Creature->getGroup("caste");
uint32_t caste_colormod_offset = OG_Caste->getOffset ("color_modifiers");
uint32_t caste_attributes_offset = OG_Caste->getOffset ("attributes");
uint32_t caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector");
caste_colormod_offset = OG_Caste->getOffset ("color_modifiers");
caste_attributes_offset = OG_Caste->getOffset ("attributes");
caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector");
OffsetGroup * OG_CasteBodyparts = OG_Creature->getGroup("caste_bodyparts");
uint32_t bodypart_id_offset = OG_CasteBodyparts->getOffset ("id");
uint32_t bodypart_category_offset = OG_CasteBodyparts->getOffset ("category");
uint32_t bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused
uint32_t bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused
uint32_t bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused
bodypart_id_offset = OG_CasteBodyparts->getOffset ("id");
bodypart_category_offset = OG_CasteBodyparts->getOffset ("category");
bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused
bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused
bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused
OffsetGroup * OG_CasteColorMods = OG_Creature->getGroup("caste_color_mods");
uint32_t color_modifier_part_offset = OG_CasteColorMods->getOffset ("part");
uint32_t color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate");
uint32_t color_modifier_enddate_offset = OG_CasteColorMods->getOffset ("enddate");
color_modifier_part_offset = OG_CasteColorMods->getOffset ("part");
color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate");
color_modifier_enddate_offset = OG_CasteColorMods->getOffset ("enddate");
have_advanced = true;
}
catch (Error::All &){};
uint32_t size = p_races.size();
uint32_t sizecas = 0;
@ -383,38 +402,36 @@ bool Materials::ReadCreatureTypesEx (void)
p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular));
p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural));
p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective));
/* color mod reading */
DfVector <uint32_t> p_colormod(p, caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size();
caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++)
{
DfVector <uint32_t> p_colorlist(p, p_colormod[k]);
sizecolorlist = p_colorlist.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++)
caste.ColorModifier[k].colorlist[l] = p_colorlist[l];
p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part));
caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset );
caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset );
}
/* body parts */
DfVector <uint32_t> p_bodypart(p, caste_start + caste_bodypart_offset);
caste.bodypart.empty();
sizebp = p_bodypart.size();
for(uint32_t k = 0; k < sizebp; k++)
if(have_advanced)
{
t_bodypart part;
p->readSTLString (p_bodypart[k] + bodypart_id_offset, part.id, sizeof(part.id));
p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category));
caste.bodypart.push_back(part);
/* color mod reading */
DfVector <uint32_t> p_colormod(p, caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size();
caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++)
{
DfVector <uint32_t> p_colorlist(p, p_colormod[k]);
sizecolorlist = p_colorlist.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++)
caste.ColorModifier[k].colorlist[l] = p_colorlist[l];
p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part));
caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset );
caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset );
}
/* body parts */
DfVector <uint32_t> p_bodypart(p, caste_start + caste_bodypart_offset);
caste.bodypart.empty();
sizebp = p_bodypart.size();
for(uint32_t k = 0; k < sizebp; k++)
{
t_bodypart part;
p->readSTLString (p_bodypart[k] + bodypart_id_offset, part.id, sizeof(part.id));
p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category));
caste.bodypart.push_back(part);
}
p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * (6+11), (uint8_t *)&caste.strength);
}
p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * (6+11), (uint8_t *)&caste.strength);
mat.castes.push_back(caste);
}
DfVector <uint32_t> p_extract(p, p_races[i] + extract_vector_offset);
@ -438,7 +455,7 @@ void Materials::ReadAllMaterials(void)
this->ReadCreatureTypes();
this->ReadCreatureTypesEx();
this->ReadDescriptorColors();
this->ReadOthers();
//this->ReadOthers();
}
std::string Materials::getDescription(t_material & mat)

@ -453,8 +453,14 @@ int main (int numargs, char ** args)
}
mem = DF->getMemoryInfo();
Materials->ReadAllMaterials();
Materials->ReadInorganicMaterials();
Materials->ReadOrganicMaterials();
Materials->ReadWoodMaterials();
Materials->ReadPlantMaterials();
Materials->ReadCreatureTypes();
Materials->ReadCreatureTypesEx();
Materials->ReadDescriptorColors();
if(!Tran->Start())
{
cerr << "Can't get name tables" << endl;