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,6 +124,8 @@ 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;
}
catch(Error::All&){};
try try
{ {
creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector");
@ -136,8 +138,6 @@ Creatures::Creatures(DFContextShared* _d)
catch(Error::All&){}; catch(Error::All&){};
} }
catch(Error::All&){}; catch(Error::All&){};
}
catch(Error::All&){};
d->Inited = true; d->Inited = true;
} }
@ -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,12 +191,12 @@ 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 // name
d->d->readName(furball.name,temp + offs.name_offset); d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff // basic stuff
p->readDWord (temp + offs.happiness_offset, furball.happiness);
p->readDWord (temp + offs.id_offset, furball.id); 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->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
p->readDWord (temp + offs.race_offset, furball.race); p->readDWord (temp + offs.race_offset, furball.race);
@ -204,6 +205,15 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
p->readWord (temp + offs.caste_offset, furball.caste); p->readWord (temp + offs.caste_offset, furball.caste);
p->readDWord (temp + offs.flags1_offset, furball.flags1.whole); p->readDWord (temp + offs.flags1_offset, furball.flags1.whole);
p->readDWord (temp + offs.flags2_offset, furball.flags2.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);
}
if(d->Ft_advanced)
{
// happiness
p->readDWord (temp + offs.happiness_offset, furball.happiness);
// physical attributes // physical attributes
p->read(temp + offs.physical_offset, p->read(temp + offs.physical_offset,
@ -215,50 +225,36 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
furball.mood_skill = p->readWord (temp + offs.mood_skill_offset); furball.mood_skill = p->readWord (temp + offs.mood_skill_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_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 // labors
p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.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;
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;;
}
furball.birth_year = p->readDWord (temp + offs.birth_year_offset ); furball.birth_year = p->readDWord (temp + offs.birth_year_offset );
furball.birth_time = p->readDWord (temp + offs.birth_time_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); * p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
*/
if (jobIdAddr) // appearance
{ DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset);
furball.current_job.active = true; furball.nbcolors = app.size();
furball.current_job.jobId = p->readByte (jobIdAddr + offs.creature_current_job_id_offset); if(furball.nbcolors>MAX_COLORS)
} furball.nbcolors = MAX_COLORS;
else for(uint32_t i = 0; i < furball.nbcolors; i++)
{ {
furball.current_job.active = false; furball.color[i] = app[i];
} }
*/
//likes
/* /*
p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); 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]);
}*/
}
if(d->Ft_soul)
{
/* /*
// enum soul pointer vector // enum soul pointer vector
DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset); DfVector <uint32_t> souls(p,temp + offs.creature_soul_vector_offset);
@ -294,25 +290,21 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
sizeof (uint16_t) * NUM_CREATURE_TRAITS, sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &furball.defaultSoul.traits); (uint8_t *) &furball.defaultSoul.traits);
} }
}
DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset); if(d->Ft_jobs)
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") );
} }
//likes else
/*
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]; furball.current_job.active = false;;
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,7 +402,8 @@ 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 */ /* color mod reading */
DfVector <uint32_t> p_colormod(p, caste_start + caste_colormod_offset); DfVector <uint32_t> p_colormod(p, caste_start + caste_colormod_offset);
sizecolormod = p_colormod.size(); sizecolormod = p_colormod.size();
@ -399,7 +419,6 @@ bool Materials::ReadCreatureTypesEx (void)
caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); 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 ); caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset );
} }
/* body parts */ /* body parts */
DfVector <uint32_t> p_bodypart(p, caste_start + caste_bodypart_offset); DfVector <uint32_t> p_bodypart(p, caste_start + caste_bodypart_offset);
caste.bodypart.empty(); caste.bodypart.empty();
@ -411,10 +430,8 @@ bool Materials::ReadCreatureTypesEx (void)
p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category)); p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category));
caste.bodypart.push_back(part); 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,7 +453,13 @@ 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())
{ {