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" /> <Offset name="happiness" value="0x5AC" />
</Group> </Group>
</Group> </Group>
<!--
The vector is bad.
<Group name="soul" valid="verify"> <Group name="soul" valid="verify">
<Offset name="name" value="0x0" /> <Offset name="name" value="0x0" />
<Offset name="mental" value="0x88" /> <Offset name="mental" value="0x88" />
<Offset name="skills_vector" value="0x1C4" /> CHMOD <Offset name="skills_vector" value="0x1C4" /> CHMOD
<Offset name="traits" value="0x1DC" /> <Offset name="traits" value="0x1DC" />
</Group> </Group>
-->
<!-- <!--
<Group name="job"> <Group name="job">
<Offset name="id" value="0x0" /> Incrementaly assigned <Offset name="id" value="0x0" /> Incrementaly assigned
@ -1770,6 +1772,8 @@
<Offset name="extract_vector" value="0x18f4" /> <Offset name="extract_vector" value="0x18f4" />
<Offset name="tile" value="0x20" /> <Offset name="tile" value="0x20" />
<Offset name="tile_color" value="0x36" /> <Offset name="tile_color" value="0x36" />
<!--
!!!! BOGUS !!!!
<Group name="caste"> <Group name="caste">
<Offset name="bodypart_vector" value="0x51C" /> <Offset name="bodypart_vector" value="0x51C" />
<Offset name="attributes" value="0x654" /> <Offset name="attributes" value="0x654" />
@ -1787,6 +1791,7 @@
<Offset name="singular_vector" value="0x78" /> <Offset name="singular_vector" value="0x78" />
<Offset name="plural_vector" value="0x90" /> <Offset name="plural_vector" value="0x90" />
</Group> </Group>
-->
</Group> </Group>
<Group name="descriptors"> <Group name="descriptors">
<!--<Address name="vectors_start" value="" />--><!-- search: vector of object with first object having string "STAR" as first member --> <!--<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.labors_offset = OG_creature_ex->getOffset ("labors");
creatures.happiness_offset = OG_creature_ex->getOffset ("happiness"); creatures.happiness_offset = OG_creature_ex->getOffset ("happiness");
d->Ft_advanced = true; d->Ft_advanced = true;
try }
{ catch(Error::All&){};
creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); try
creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul"); {
creatures.soul_mental_offset = OG_soul->getOffset("mental"); creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector");
creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector"); creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul");
creatures.soul_traits_offset = OG_soul->getOffset("traits"); creatures.soul_mental_offset = OG_soul->getOffset("mental");
d->Ft_soul = true; creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector");
} creatures.soul_traits_offset = OG_soul->getOffset("traits");
catch(Error::All&){}; d->Ft_soul = true;
} }
catch(Error::All&){}; catch(Error::All&){};
} }
@ -169,6 +169,7 @@ bool Creatures::Finish()
bool Creatures::ReadCreature (const int32_t index, t_creature & furball) bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
{ {
if(!d->Started) return false; if(!d->Started) return false;
memset(&furball, 0, sizeof(t_creature));
// SHM fast path // SHM fast path
Process * p = d->owner; Process * p = d->owner;
/* /*
@ -190,129 +191,120 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
Creatures2010::creature_offsets &offs = d->creatures; Creatures2010::creature_offsets &offs = d->creatures;
//read creature from memory //read creature from memory
if(d->Ft_basic)
// 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)
{ {
furball.current_job.active = true; // name
furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") ); d->d->readName(furball.name,temp + offs.name_offset);
furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") );
// 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;; // happiness
} p->readDWord (temp + offs.happiness_offset, furball.happiness);
furball.birth_year = p->readDWord (temp + offs.birth_year_offset ); // physical attributes
furball.birth_time = p->readDWord (temp + offs.birth_time_offset ); p->read(temp + offs.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
// current job HACK: the job object isn't cleanly represented here (uint8_t *)&furball.strength);
/*
uint32_t jobIdAddr = p->readDWord (temp + offs.creature_current_job_offset); // 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) //likes
{ /*
furball.current_job.active = true; DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
furball.current_job.jobId = p->readByte (jobIdAddr + offs.creature_current_job_id_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; /*
} // 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);
p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); 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();
/* for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++)
// enum soul pointer vector {
DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset); uint32_t temp2 = skills[i];
*/ // a byte: this gives us 256 skills maximum.
uint32_t soul = p->readDWord(temp + offs.default_soul_offset); furball.defaultSoul.skills[i].id = p->readByte (temp2);
furball.has_default_soul = false; 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) // mental attributes are part of the soul
{ p->read(soul + offs.soul_mental_offset,
furball.has_default_soul = true; sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
// get first soul's skills (uint8_t *)&furball.defaultSoul.analytical_ability);
DfVector <uint32_t> skills(p, soul + offs.soul_skills_vector_offset);
furball.defaultSoul.numSkills = skills.size();
for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) // traits as well
{ p->read(soul + offs.soul_traits_offset,
uint32_t temp2 = skills[i]; sizeof (uint16_t) * NUM_CREATURE_TRAITS,
// a byte: this gives us 256 skills maximum. (uint8_t *) &furball.defaultSoul.traits);
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));
} }
// 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);
} }
if(d->Ft_jobs)
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]; 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; return true;
} }

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

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